From 76b1a19f331efaa2ea13856dacb342b6c7bb4823 Mon Sep 17 00:00:00 2001 From: benweet Date: Fri, 12 Sep 2014 13:01:40 +0100 Subject: [PATCH 1/2] Increased couchdb update time permissiveness --- couchdb/setup-db.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/couchdb/setup-db.js b/couchdb/setup-db.js index 00565dc4..abb9d841 100644 --- a/couchdb/setup-db.js +++ b/couchdb/setup-db.js @@ -21,7 +21,7 @@ var validate = function(newDoc) { if(toString.call(newDoc.updated) !== '[object Number]') { throw({forbidden: 'Update time must be an integer.'}); } - if(newDoc.updated > Date.now() + 60000) { + if(newDoc.updated > Date.now() + 300000) { throw({forbidden: 'Update time is in the future, please check your clock!'}); } if(toString.call(newDoc.title) !== '[object String]') { From 9dce63013b526cd7d754eb8a88b894f904befc65 Mon Sep 17 00:00:00 2001 From: benweet Date: Fri, 12 Sep 2014 21:05:21 +0100 Subject: [PATCH 2/2] Fixed couchdb tag support --- public/res/constants.js | 2 +- public/res/helpers/couchdbHelper.js | 4 ++-- public/res/html/bodyEditor.html | 8 ++++---- public/res/providers/couchdbProvider.js | 23 ++++++++++++++++------- public/res/synchronizer.js | 16 +++++++++++++++- 5 files changed, 38 insertions(+), 15 deletions(-) diff --git a/public/res/constants.js b/public/res/constants.js index 77ea43b0..0e8e6675 100644 --- a/public/res/constants.js +++ b/public/res/constants.js @@ -27,7 +27,7 @@ define([], function() { constants.PICASA_IMPORT_IMG_URL = "/picasaImportImg"; constants.SSH_PUBLISH_URL = '/sshPublish'; constants.PDF_EXPORT_URL = "/pdfExport"; - constants.COUCHDB_URL = 'http://localhost:5984/documents'; + constants.COUCHDB_URL = 'https://stackedit.couchappy.com/documents'; // Site dependent constants.BASE_URL = "http://localhost/"; diff --git a/public/res/helpers/couchdbHelper.js b/public/res/helpers/couchdbHelper.js index 34b55f33..475a193d 100644 --- a/public/res/helpers/couchdbHelper.js +++ b/public/res/helpers/couchdbHelper.js @@ -168,9 +168,9 @@ define([ tag, updated || [] ]) : updated; - var endKey = tag && JSON.stringify([ + var endKey = tag ? JSON.stringify([ tag - ]); + ]) : undefined; $.ajax({ url: constants.COUCHDB_URL + ddoc, data: { diff --git a/public/res/html/bodyEditor.html b/public/res/html/bodyEditor.html index ec971711..52655210 100644 --- a/public/res/html/bodyEditor.html +++ b/public/res/html/bodyEditor.html @@ -559,8 +559,8 @@

- - +

The following documents will be removed from CouchDB:

diff --git a/public/res/providers/couchdbProvider.js b/public/res/providers/couchdbProvider.js index f0b59faf..9dc1d2bd 100644 --- a/public/res/providers/couchdbProvider.js +++ b/public/res/providers/couchdbProvider.js @@ -19,6 +19,9 @@ define([ var PROVIDER_COUCHDB = "couchdb"; var couchdbProvider = new Provider(PROVIDER_COUCHDB, "CouchDB"); + couchdbProvider.importPreferencesInputIds = [ + PROVIDER_COUCHDB + "-tag" + ]; function createSyncIndex(id) { return "sync." + PROVIDER_COUCHDB + "." + id; @@ -250,15 +253,17 @@ define([ $(modalElt.querySelectorAll('.delete-mode')).toggleClass('hide', mode != 'delete'); $(modalElt.querySelectorAll('.byid-mode')).toggleClass('hide', mode != 'byid'); } - function updateDocumentList() { + + var updateDocumentList = _.debounce(function() { $pleaseWaitElt.removeClass('hide'); $noDocumentElt.addClass('hide'); $moreDocumentsElt.addClass('hide'); - couchdbHelper.listDocuments(undefined, lastDocument && lastDocument.updated, function(err, result) { + couchdbHelper.listDocuments($selectTagElt.val(), lastDocument && lastDocument.updated, function(err, result) { + $pleaseWaitElt.addClass('hide'); if(err) { + $moreDocumentsElt.removeClass('hide'); return; } - $pleaseWaitElt.addClass('hide'); if(result.length === 3) { $moreDocumentsElt.removeClass('hide'); lastDocument = result.pop(); @@ -277,10 +282,14 @@ define([ } }); setMode('list'); - } + }, 10, true); var tagList = utils.retrieveIgnoreError(PROVIDER_COUCHDB + '.tagList') || []; - var $selectTagElt = $('#select-sync-import-couchdb-tag'); + var $selectTagElt = $('#input-sync-import-couchdb-tag') + .on('change', function() { + clear(); + updateDocumentList(); + }); function updateTagList() { $selectTagElt.empty().append(crel('option', { value: '' @@ -293,12 +302,12 @@ define([ }, tag)); }); } + updateTagList(); $(modalElt) .on('show.bs.modal', function() { + clear(); updateDocumentList(); - updateTagList(); }) - .on('hidden.bs.modal', clear) .on('click', '.document-list .document', function() { $(this).toggleClass('active'); doSelect(); diff --git a/public/res/synchronizer.js b/public/res/synchronizer.js index c22397be..0a01342b 100644 --- a/public/res/synchronizer.js +++ b/public/res/synchronizer.js @@ -282,7 +282,7 @@ define([ utils.resetModalInputs(); var preferences = utils.retrieveIgnoreError(provider.providerId + '.' + action + 'Preferences'); if(preferences) { - _.each(provider.exportPreferencesInputIds, function(inputId) { + _.each(provider[action + 'PreferencesInputIds'], function(inputId) { var exportPreferenceValue = preferences[inputId]; var setValue = utils.setInputValue; if(_.isBoolean(exportPreferenceValue)) { @@ -328,6 +328,20 @@ define([ // Provider's import button $(".action-sync-import-" + provider.providerId).click(function(event) { provider.importFiles(event); + + // Store input values as preferences for next time we open the + // import dialog + var importPreferences = {}; + _.each(provider.importPreferencesInputIds, function(inputId) { + var inputElt = document.getElementById("input-sync-import-" + inputId); + if(inputElt.type == 'checkbox') { + importPreferences[inputId] = inputElt.checked; + } + else { + importPreferences[inputId] = inputElt.value; + } + }); + storage[provider.providerId + ".importPreferences"] = JSON.stringify(importPreferences); }); // Provider's import dialog action $(".action-sync-import-dialog-" + provider.providerId).click(function() {