history snaphost time interval is now configurable in settings

This commit is contained in:
azivner 2017-09-24 20:50:14 -04:00
parent 08064b181d
commit c12161feba
4 changed files with 39 additions and 3 deletions

View File

@ -10,7 +10,7 @@ from flask_login import login_required
from sql import delete from sql import delete
from sql import execute, insert, commit from sql import execute, insert, commit
from sql import getResults, getSingleResult from sql import getResults, getSingleResult, getOption
notes_api = Blueprint('notes_api', __name__) notes_api = Blueprint('notes_api', __name__)
@ -44,7 +44,9 @@ def updateNote(note_id):
now = math.floor(time.time()) now = math.floor(time.time())
history_cutoff = now - 600 history_snapshot_time_interval = getOption('history_snapshot_time_interval')
history_cutoff = now - history_snapshot_time_interval
history = getSingleResult("select id from notes_history where note_id = ? and date_modified >= ?", [note_id, history_cutoff]) history = getSingleResult("select id from notes_history where note_id = ? and date_modified >= ?", [note_id, history_cutoff])

View File

@ -5,7 +5,7 @@ import sql
settings_api = Blueprint('settings_api', __name__) settings_api = Blueprint('settings_api', __name__)
allowed_options = [ 'encryption_session_timeout' ] allowed_options = [ 'encryption_session_timeout', 'history_snapshot_time_interval' ]
@settings_api.route('/settings', methods = ['GET']) @settings_api.route('/settings', methods = ['GET'])
@login_required @login_required

View File

@ -121,6 +121,7 @@
<ul> <ul>
<li><a href="#changePassword">Change password</a></li> <li><a href="#changePassword">Change password</a></li>
<li><a href="#encryptionTimeout">Encryption timeout</a></li> <li><a href="#encryptionTimeout">Encryption timeout</a></li>
<li><a href="#historySnapshotTimeInterval">History snapshots</a></li>
</ul> </ul>
<div id="changePassword"> <div id="changePassword">
<form id="changePasswordForm"> <form id="changePasswordForm">
@ -152,6 +153,18 @@
<input class="form-control" id="encryptionTimeoutInSeconds" type="number"> <input class="form-control" id="encryptionTimeoutInSeconds" type="number">
</div> </div>
<button class="btn btn-sm">Save</button>
</form>
</div>
<div id="historySnapshotTimeInterval">
<p>History snapshot time interval is time in seconds after which new history record will be created for the note.</p>
<form id="historySnapshotTimeIntervalForm">
<div class="form-group">
<label for="historySnapshotTimeIntervalInSeconds">History snapshot time interval (in seconds)</label>
<input class="form-control" id="historySnapshotTimeIntervalInSeconds" type="number">
</div>
<button class="btn btn-sm">Save</button> <button class="btn btn-sm">Save</button>
</form> </form>
</div> </div>

View File

@ -4,6 +4,7 @@ function displaySettings() {
type: 'GET', type: 'GET',
success: function (result) { success: function (result) {
$("#encryptionTimeoutInSeconds").val(result['encryption_session_timeout']); $("#encryptionTimeoutInSeconds").val(result['encryption_session_timeout']);
$("#historySnapshotTimeIntervalInSeconds").val(result['history_snapshot_time_interval']);
}, },
error: () => alert("Error getting settings.") error: () => alert("Error getting settings.")
}); });
@ -78,5 +79,25 @@ $("#encryptionTimeoutForm").submit(() => {
error: () => alert("Error occurred during changing encryption timeout.") error: () => alert("Error occurred during changing encryption timeout.")
}); });
return false;
});
$("#historySnapshotTimeIntervalForm").submit(() => {
const historySnapshotTimeInterval = $("#historySnapshotTimeIntervalInSeconds").val();
$.ajax({
url: baseUrl + 'settings',
type: 'POST',
data: JSON.stringify({
name: 'history_snapshot_time_interval',
value: historySnapshotTimeInterval
}),
contentType: "application/json",
success: function () {
alert("History snapshot time interval has been changed.");
},
error: () => alert("Error occurred during changing history snapshot time interval.")
});
return false; return false;
}); });