2017-11-05 07:38:50 +08:00
|
|
|
"use strict";
|
|
|
|
|
2018-03-26 09:16:57 +08:00
|
|
|
import protectedSessionHolder from '../services/protected_session_holder.js';
|
2018-03-26 01:02:39 +08:00
|
|
|
import utils from '../services/utils.js';
|
|
|
|
import server from '../services/server.js';
|
2017-09-13 11:04:17 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
const $dialog = $("#settings-dialog");
|
|
|
|
const $tabs = $("#settings-tabs");
|
2017-11-05 02:31:53 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
const settingModules = [];
|
2017-09-11 11:10:32 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
function addModule(module) {
|
|
|
|
settingModules.push(module);
|
|
|
|
}
|
2017-11-05 05:03:15 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
async function showDialog() {
|
|
|
|
glob.activeDialog = $dialog;
|
2017-09-11 11:10:32 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
const settings = await server.get('settings');
|
2017-09-13 10:23:57 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
$dialog.dialog({
|
|
|
|
modal: true,
|
|
|
|
width: 900
|
|
|
|
});
|
2017-09-13 10:23:57 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
$tabs.tabs();
|
|
|
|
|
|
|
|
for (const module of settingModules) {
|
|
|
|
if (module.settingsLoaded) {
|
|
|
|
module.settingsLoaded(settings);
|
2017-11-05 02:31:53 +08:00
|
|
|
}
|
|
|
|
}
|
2018-03-25 23:09:17 +08:00
|
|
|
}
|
2017-11-05 02:31:53 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
async function saveSettings(settingName, settingValue) {
|
|
|
|
await server.post('settings', {
|
|
|
|
name: settingName,
|
|
|
|
value: settingValue
|
|
|
|
});
|
2017-11-29 09:52:38 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
utils.showMessage("Settings change have been saved.");
|
|
|
|
}
|
2017-11-05 02:31:53 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
export default {
|
|
|
|
showDialog,
|
2018-03-26 07:49:33 +08:00
|
|
|
saveSettings
|
2018-03-25 23:09:17 +08:00
|
|
|
};
|
2017-11-05 02:31:53 +08:00
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
addModule((function() {
|
2018-02-10 21:44:34 +08:00
|
|
|
const $form = $("#change-password-form");
|
|
|
|
const $oldPassword = $("#old-password");
|
|
|
|
const $newPassword1 = $("#new-password1");
|
|
|
|
const $newPassword2 = $("#new-password2");
|
2017-11-05 02:31:53 +08:00
|
|
|
|
|
|
|
function settingsLoaded(settings) {
|
2017-09-13 10:23:57 +08:00
|
|
|
}
|
|
|
|
|
2018-02-10 21:44:34 +08:00
|
|
|
$form.submit(() => {
|
|
|
|
const oldPassword = $oldPassword.val();
|
|
|
|
const newPassword1 = $newPassword1.val();
|
|
|
|
const newPassword2 = $newPassword2.val();
|
2017-11-05 02:31:53 +08:00
|
|
|
|
2018-02-10 21:44:34 +08:00
|
|
|
$oldPassword.val('');
|
|
|
|
$newPassword1.val('');
|
|
|
|
$newPassword2.val('');
|
2017-11-05 02:31:53 +08:00
|
|
|
|
|
|
|
if (newPassword1 !== newPassword2) {
|
|
|
|
alert("New passwords are not the same.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-29 09:52:38 +08:00
|
|
|
server.post('password/change', {
|
|
|
|
'current_password': oldPassword,
|
|
|
|
'new_password': newPassword1
|
|
|
|
}).then(result => {
|
|
|
|
if (result.success) {
|
|
|
|
alert("Password has been changed. Trilium will be reloaded after you press OK.");
|
|
|
|
|
|
|
|
// password changed so current protected session is invalid and needs to be cleared
|
2018-03-26 09:16:57 +08:00
|
|
|
protectedSessionHolder.resetProtectedSession();
|
2017-11-29 09:52:38 +08:00
|
|
|
}
|
|
|
|
else {
|
2018-03-25 11:37:55 +08:00
|
|
|
utils.showError(result.message);
|
2017-11-29 09:52:38 +08:00
|
|
|
}
|
2017-11-05 02:31:53 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
return false;
|
2017-09-13 10:23:57 +08:00
|
|
|
});
|
2017-09-11 11:10:32 +08:00
|
|
|
|
2017-11-05 02:31:53 +08:00
|
|
|
return {
|
|
|
|
settingsLoaded
|
|
|
|
};
|
|
|
|
})());
|
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
addModule((function() {
|
2018-02-10 21:44:34 +08:00
|
|
|
const $form = $("#protected-session-timeout-form");
|
|
|
|
const $protectedSessionTimeout = $("#protected-session-timeout-in-seconds");
|
2017-11-15 11:44:45 +08:00
|
|
|
const settingName = 'protected_session_timeout';
|
2017-09-13 11:04:17 +08:00
|
|
|
|
2017-11-05 02:31:53 +08:00
|
|
|
function settingsLoaded(settings) {
|
2018-02-10 21:44:34 +08:00
|
|
|
$protectedSessionTimeout.val(settings[settingName]);
|
2017-11-05 02:31:53 +08:00
|
|
|
}
|
2017-09-13 11:04:17 +08:00
|
|
|
|
2018-02-10 21:44:34 +08:00
|
|
|
$form.submit(() => {
|
|
|
|
const protectedSessionTimeout = $protectedSessionTimeout.val();
|
2017-09-23 22:59:36 +08:00
|
|
|
|
2017-11-15 11:44:45 +08:00
|
|
|
settings.saveSettings(settingName, protectedSessionTimeout).then(() => {
|
2018-03-26 09:16:57 +08:00
|
|
|
protectedSessionHolder.setProtectedSessionTimeout(protectedSessionTimeout);
|
2017-11-05 02:31:53 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
return false;
|
2017-09-13 11:04:17 +08:00
|
|
|
});
|
|
|
|
|
2017-11-05 02:31:53 +08:00
|
|
|
return {
|
|
|
|
settingsLoaded
|
|
|
|
};
|
|
|
|
})());
|
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
addModule((function () {
|
2018-03-26 08:52:38 +08:00
|
|
|
const $form = $("#note-revision-snapshot-time-interval-form");
|
|
|
|
const $timeInterval = $("#note-revision-snapshot-time-interval-in-seconds");
|
|
|
|
const settingName = 'note_revision_snapshot_time_interval';
|
2017-11-05 02:31:53 +08:00
|
|
|
|
|
|
|
function settingsLoaded(settings) {
|
2018-02-10 21:44:34 +08:00
|
|
|
$timeInterval.val(settings[settingName]);
|
2017-11-05 02:31:53 +08:00
|
|
|
}
|
|
|
|
|
2018-02-10 21:44:34 +08:00
|
|
|
$form.submit(() => {
|
|
|
|
settings.saveSettings(settingName, $timeInterval.val());
|
2017-11-05 02:31:53 +08:00
|
|
|
|
|
|
|
return false;
|
2017-09-25 08:50:14 +08:00
|
|
|
});
|
|
|
|
|
2017-11-14 12:35:23 +08:00
|
|
|
return {
|
|
|
|
settingsLoaded
|
|
|
|
};
|
|
|
|
})());
|
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
addModule((async function () {
|
2018-02-10 21:44:34 +08:00
|
|
|
const $appVersion = $("#app-version");
|
|
|
|
const $dbVersion = $("#db-version");
|
|
|
|
const $buildDate = $("#build-date");
|
|
|
|
const $buildRevision = $("#build-revision");
|
2017-11-14 12:35:23 +08:00
|
|
|
|
2017-11-29 09:52:38 +08:00
|
|
|
const appInfo = await server.get('app-info');
|
2017-11-14 12:35:23 +08:00
|
|
|
|
2018-02-10 21:44:34 +08:00
|
|
|
$appVersion.html(appInfo.app_version);
|
|
|
|
$dbVersion.html(appInfo.db_version);
|
|
|
|
$buildDate.html(appInfo.build_date);
|
|
|
|
$buildRevision.html(appInfo.build_revision);
|
|
|
|
$buildRevision.attr('href', 'https://github.com/zadam/trilium/commit/' + appInfo.build_revision);
|
2017-11-21 13:25:53 +08:00
|
|
|
|
2017-12-14 12:03:48 +08:00
|
|
|
return {};
|
|
|
|
})());
|
|
|
|
|
2018-03-25 23:09:17 +08:00
|
|
|
addModule((async function () {
|
2018-02-10 21:44:34 +08:00
|
|
|
const $forceFullSyncButton = $("#force-full-sync-button");
|
|
|
|
const $fillSyncRowsButton = $("#fill-sync-rows-button");
|
|
|
|
const $anonymizeButton = $("#anonymize-button");
|
|
|
|
const $cleanupSoftDeletedButton = $("#cleanup-soft-deleted-items-button");
|
|
|
|
const $cleanupUnusedImagesButton = $("#cleanup-unused-images-button");
|
|
|
|
const $vacuumDatabaseButton = $("#vacuum-database-button");
|
|
|
|
|
|
|
|
$forceFullSyncButton.click(async () => {
|
2017-12-14 12:03:48 +08:00
|
|
|
await server.post('sync/force-full-sync');
|
|
|
|
|
2018-03-25 11:37:55 +08:00
|
|
|
utils.showMessage("Full sync triggered");
|
2017-12-14 12:03:48 +08:00
|
|
|
});
|
|
|
|
|
2018-02-10 21:44:34 +08:00
|
|
|
$fillSyncRowsButton.click(async () => {
|
2017-12-20 11:04:51 +08:00
|
|
|
await server.post('sync/fill-sync-rows');
|
|
|
|
|
2018-03-25 11:37:55 +08:00
|
|
|
utils.showMessage("Sync rows filled successfully");
|
2017-12-20 11:04:51 +08:00
|
|
|
});
|
|
|
|
|
2017-12-16 13:05:37 +08:00
|
|
|
|
2018-02-10 21:44:34 +08:00
|
|
|
$anonymizeButton.click(async () => {
|
2017-12-16 13:05:37 +08:00
|
|
|
await server.post('anonymization/anonymize');
|
|
|
|
|
2018-03-25 11:37:55 +08:00
|
|
|
utils.showMessage("Created anonymized database");
|
2017-12-16 13:05:37 +08:00
|
|
|
});
|
|
|
|
|
2018-02-10 21:44:34 +08:00
|
|
|
$cleanupSoftDeletedButton.click(async () => {
|
2017-12-23 22:35:00 +08:00
|
|
|
if (confirm("Do you really want to clean up soft-deleted items?")) {
|
|
|
|
await server.post('cleanup/cleanup-soft-deleted-items');
|
|
|
|
|
2018-03-25 11:37:55 +08:00
|
|
|
utils.showMessage("Soft deleted items have been cleaned up");
|
2017-12-23 22:35:00 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-02-10 21:44:34 +08:00
|
|
|
$cleanupUnusedImagesButton.click(async () => {
|
2018-01-08 03:07:59 +08:00
|
|
|
if (confirm("Do you really want to clean up unused images?")) {
|
|
|
|
await server.post('cleanup/cleanup-unused-images');
|
|
|
|
|
2018-03-25 11:37:55 +08:00
|
|
|
utils.showMessage("Unused images have been cleaned up");
|
2018-01-08 03:07:59 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-02-10 21:44:34 +08:00
|
|
|
$vacuumDatabaseButton.click(async () => {
|
2017-12-23 22:35:00 +08:00
|
|
|
await server.post('cleanup/vacuum-database');
|
|
|
|
|
2018-03-25 11:37:55 +08:00
|
|
|
utils.showMessage("Database has been vacuumed");
|
2017-12-23 22:35:00 +08:00
|
|
|
});
|
|
|
|
|
2017-11-21 13:25:53 +08:00
|
|
|
return {};
|
2017-11-05 02:31:53 +08:00
|
|
|
})());
|