Merge branch 'couch' of bitbucket.org:benweet/stackedit into couch

This commit is contained in:
benweet 2014-09-13 00:48:45 +01:00
commit b009900fcd
6 changed files with 39 additions and 16 deletions

View File

@ -30,7 +30,7 @@ var validate = function(newDoc) {
if(toString.call(newDoc.updated) !== '[object Number]') { if(toString.call(newDoc.updated) !== '[object Number]') {
throw({forbidden: 'Update time must be an integer.'}); 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!'}); throw({forbidden: 'Update time is in the future, please check your clock!'});
} }
if(toString.call(newDoc.title) !== '[object String]') { if(toString.call(newDoc.title) !== '[object String]') {

View File

@ -27,7 +27,7 @@ define([], function() {
constants.PICASA_IMPORT_IMG_URL = "/picasaImportImg"; constants.PICASA_IMPORT_IMG_URL = "/picasaImportImg";
constants.SSH_PUBLISH_URL = '/sshPublish'; constants.SSH_PUBLISH_URL = '/sshPublish';
constants.PDF_EXPORT_URL = "/pdfExport"; constants.PDF_EXPORT_URL = "/pdfExport";
constants.COUCHDB_URL = 'http://localhost:5984/documents'; constants.COUCHDB_URL = 'https://stackedit.couchappy.com/documents';
// Site dependent // Site dependent
constants.BASE_URL = "http://localhost/"; constants.BASE_URL = "http://localhost/";

View File

@ -168,9 +168,9 @@ define([
tag, tag,
updated || [] updated || []
]) : updated; ]) : updated;
var endKey = tag && JSON.stringify([ var endKey = tag ? JSON.stringify([
tag tag
]); ]) : undefined;
$.ajax({ $.ajax({
url: constants.COUCHDB_URL + ddoc, url: constants.COUCHDB_URL + ddoc,
data: { data: {

View File

@ -559,8 +559,8 @@
<div class="form-horizontal list-mode"> <div class="form-horizontal list-mode">
<br> <br>
<div class="form-group form-inline"> <div class="form-group form-inline">
<label for="select-sync-import-couchdb-tag" class="col-sm-3 control-label">Filter by tag</label> <label for="input-sync-import-couchdb-tag" class="col-sm-3 control-label">Filter by tag</label>
<select id="select-sync-import-couchdb-tag" class="col-sm-4 form-control"> <select id="input-sync-import-couchdb-tag" class="col-sm-4 form-control">
</select> </select>
<span class="col-sm-5"> <span class="col-sm-5">
<a class="btn btn-link action-add-tag"><i class="icon-tag"></i> Add <a class="btn btn-link action-add-tag"><i class="icon-tag"></i> Add
@ -600,10 +600,10 @@
<p class="list-mode"> <p class="list-mode">
</p> </p>
<div class="list-group document-list list-mode"></div> <div class="list-group document-list list-mode"></div>
<div class="list-mode"> <div class="list-mode text-center">
<div class="please-wait"><b>Please wait...</b></div> <div class="please-wait"><b>Please wait...</b></div>
<div class="no-document"><b>No document.</b></div> <div class="no-document"><b>No document.</b></div>
<button class="more-documents btn btn-link">More documents!</button> <button class="more-documents btn btn-link"><i class="icon-angle-double-down"></i> More documents!</button>
</div> </div>
<p class="delete-mode hide">The following documents will be <p class="delete-mode hide">The following documents will be
removed from CouchDB:</p> removed from CouchDB:</p>

View File

@ -19,6 +19,9 @@ define([
var PROVIDER_COUCHDB = "couchdb"; var PROVIDER_COUCHDB = "couchdb";
var couchdbProvider = new Provider(PROVIDER_COUCHDB, "CouchDB"); var couchdbProvider = new Provider(PROVIDER_COUCHDB, "CouchDB");
couchdbProvider.importPreferencesInputIds = [
PROVIDER_COUCHDB + "-tag"
];
function createSyncIndex(id) { function createSyncIndex(id) {
return "sync." + PROVIDER_COUCHDB + "." + id; return "sync." + PROVIDER_COUCHDB + "." + id;
@ -250,15 +253,17 @@ define([
$(modalElt.querySelectorAll('.delete-mode')).toggleClass('hide', mode != 'delete'); $(modalElt.querySelectorAll('.delete-mode')).toggleClass('hide', mode != 'delete');
$(modalElt.querySelectorAll('.byid-mode')).toggleClass('hide', mode != 'byid'); $(modalElt.querySelectorAll('.byid-mode')).toggleClass('hide', mode != 'byid');
} }
function updateDocumentList() {
var updateDocumentList = _.debounce(function() {
$pleaseWaitElt.removeClass('hide'); $pleaseWaitElt.removeClass('hide');
$noDocumentElt.addClass('hide'); $noDocumentElt.addClass('hide');
$moreDocumentsElt.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) { if(err) {
$moreDocumentsElt.removeClass('hide');
return; return;
} }
$pleaseWaitElt.addClass('hide');
if(result.length === 3) { if(result.length === 3) {
$moreDocumentsElt.removeClass('hide'); $moreDocumentsElt.removeClass('hide');
lastDocument = result.pop(); lastDocument = result.pop();
@ -277,10 +282,14 @@ define([
} }
}); });
setMode('list'); setMode('list');
} }, 10, true);
var tagList = utils.retrieveIgnoreError(PROVIDER_COUCHDB + '.tagList') || []; 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() { function updateTagList() {
$selectTagElt.empty().append(crel('option', { $selectTagElt.empty().append(crel('option', {
value: '' value: ''
@ -293,12 +302,12 @@ define([
}, tag)); }, tag));
}); });
} }
updateTagList();
$(modalElt) $(modalElt)
.on('show.bs.modal', function() { .on('show.bs.modal', function() {
clear();
updateDocumentList(); updateDocumentList();
updateTagList();
}) })
.on('hidden.bs.modal', clear)
.on('click', '.document-list .document', function() { .on('click', '.document-list .document', function() {
$(this).toggleClass('active'); $(this).toggleClass('active');
doSelect(); doSelect();

View File

@ -282,7 +282,7 @@ define([
utils.resetModalInputs(); utils.resetModalInputs();
var preferences = utils.retrieveIgnoreError(provider.providerId + '.' + action + 'Preferences'); var preferences = utils.retrieveIgnoreError(provider.providerId + '.' + action + 'Preferences');
if(preferences) { if(preferences) {
_.each(provider.exportPreferencesInputIds, function(inputId) { _.each(provider[action + 'PreferencesInputIds'], function(inputId) {
var exportPreferenceValue = preferences[inputId]; var exportPreferenceValue = preferences[inputId];
var setValue = utils.setInputValue; var setValue = utils.setInputValue;
if(_.isBoolean(exportPreferenceValue)) { if(_.isBoolean(exportPreferenceValue)) {
@ -328,6 +328,20 @@ define([
// Provider's import button // Provider's import button
$(".action-sync-import-" + provider.providerId).click(function(event) { $(".action-sync-import-" + provider.providerId).click(function(event) {
provider.importFiles(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 // Provider's import dialog action
$(".action-sync-import-dialog-" + provider.providerId).click(function() { $(".action-sync-import-dialog-" + provider.providerId).click(function() {