From 31067d6bf3d2ee130a34cc94582792d923fe962b Mon Sep 17 00:00:00 2001 From: antelle Date: Sat, 30 Jul 2016 13:38:37 +0300 Subject: [PATCH] fix #220: option to preload webdav config --- app/index.html | 2 +- app/scripts/app.js | 2 +- app/scripts/models/app-model.js | 26 ++++++++++++++++--- release-notes.md | 2 +- util/config-example.json | 44 +++++++++++++++++++++++++++++++++ 5 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 util/config-example.json diff --git a/app/index.html b/app/index.html index 1a0f62aa..543b1b91 100644 --- a/app/index.html +++ b/app/index.html @@ -4,7 +4,7 @@ KeeWeb - + diff --git a/app/scripts/app.js b/app/scripts/app.js index a52086ec..79d95ba4 100644 --- a/app/scripts/app.js +++ b/app/scripts/app.js @@ -83,7 +83,7 @@ $(() => { function getConfigParam() { let metaConfig = document.head.querySelector('meta[name=kw-config]'); - if (metaConfig && metaConfig.content) { + if (metaConfig && metaConfig.content && metaConfig.content[0] !== '(') { return metaConfig.content; } var match = location.search.match(/[?&]config=([^&]+)/i); diff --git a/app/scripts/models/app-model.js b/app/scripts/models/app-model.js index 8b7113d7..e71257de 100644 --- a/app/scripts/models/app-model.js +++ b/app/scripts/models/app-model.js @@ -56,8 +56,12 @@ var AppModel = Backbone.Model.extend({ this.appLogger.error('Error loading app config', xhr.statusText); return callback(true); } + if (!xhr.response.settings) { + this.appLogger.error('Invalid app config, no settings section', xhr.response); + return callback(true); + } this.appLogger.info('Loaded app config from', configLocation, this.appLogger.ts(ts)); - this.settings.set(xhr.response); + this.applyUserConfig(xhr.response); callback(); }); xhr.addEventListener('error', () => { @@ -66,6 +70,22 @@ var AppModel = Backbone.Model.extend({ }); }, + applyUserConfig(config) { + this.settings.set(config.settings); + if (config.file && config.file.storage && config.file.name && config.file.path) { + if (!this.fileInfos.getMatch(config.file.storage, config.file.name, config.file.path)) { + var fileInfo = new FileInfoModel({ + id: IdGenerator.uuid(), + name: config.file.name, + storage: config.file.storage, + path: config.file.path, + opts: config.file.options + }); + this.fileInfos.unshift(fileInfo); + } + } + }, + addFile: function(file) { if (this.files.get(file.id)) { return false; @@ -328,10 +348,10 @@ var AppModel = Backbone.Model.extend({ } else if (!params.storage) { logger.info('Open file from cache as main storage'); this.openFileFromCache(params, callback, fileInfo); - } else if (fileInfo && fileInfo.get('rev') === params.rev && fileInfo.get('storage') !== 'file') { + } else if (fileInfo && fileInfo.openDate && fileInfo.get('rev') === params.rev && fileInfo.get('storage') !== 'file') { logger.info('Open file from cache because it is latest'); this.openFileFromCache(params, callback, fileInfo); - } else if (!fileInfo || params.storage === 'file') { + } else if (!fileInfo || !fileInfo.openDate || params.storage === 'file') { logger.info('Open file from storage', params.storage); var storage = Storage[params.storage]; var storageLoad = function() { diff --git a/release-notes.md b/release-notes.md index cc354861..41ff1cfc 100644 --- a/release-notes.md +++ b/release-notes.md @@ -5,7 +5,7 @@ Release notes `+` context menu `+` solarized themes `+` select field contents on search hotkey -`+` option to preload default config +`+` option to preload default config and file `+` save displayed table columns `-` fix app redraw in background diff --git a/util/config-example.json b/util/config-example.json new file mode 100644 index 00000000..f0fff109 --- /dev/null +++ b/util/config-example.json @@ -0,0 +1,44 @@ +{ + "settings": { + "theme": "fb", + "expandGroups": true, + "listViewWidth": null, + "menuViewWidth": null, + "tagsViewHeight": null, + "autoUpdate": "install", + "clipboardSeconds": 0, + "autoSave": true, + "rememberKeyFiles": false, + "idleMinutes": 15, + "minimizeOnClose": false, + "tableView": false, + "colorfulIcons": false, + "lockOnMinimize": true, + "lockOnCopy": false, + "helpTipCopyShown": false, + "skipOpenLocalWarn": false, + "hideEmptyFields": false, + "skipHttpsWarning": false, + "demoOpened": false, + "fontSize": 0, + "tableViewColumns": null, + + "dropbox": true, + "dropboxFolder": null, + "dropboxAppKey": null, + + "webdav": true, + + "gdrive": true, + "gdriveClientId": null, + + "onedrive": true, + "onedriveClientId": null + }, + "file": { + "storage": "webdav", + "name": "", + "path": "", + "options": { "user": "", "password": "" } + } +}