Fixed couchdb tag support

This commit is contained in:
benweet 2014-09-12 21:05:21 +01:00
parent 71875df50e
commit 9dce63013b
5 changed files with 38 additions and 15 deletions

View File

@ -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/";

View File

@ -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: {

View File

@ -559,8 +559,8 @@
<div class="form-horizontal list-mode">
<br>
<div class="form-group form-inline">
<label for="select-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">
<label for="input-sync-import-couchdb-tag" class="col-sm-3 control-label">Filter by tag</label>
<select id="input-sync-import-couchdb-tag" class="col-sm-4 form-control">
</select>
<span class="col-sm-5">
<button class="btn btn-link action-add-tag"><i class="icon-tag"></i> Add
@ -600,10 +600,10 @@
<p class="list-mode">
</p>
<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="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>
<p class="delete-mode hide">The following documents will be
removed from CouchDB:</p>

View File

@ -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();

View File

@ -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() {