Skip to content

TagSpaces is an offline, open source, document manager with tagging support

refining the logic for saving meta information in sidecar files

uggrockb52047aedb1e
diff --git a/data/js/meta.js b/data/js/meta.js
index c6fc43b0a..54a029b20 100644
--- a/data/js/meta.js
+++ b/data/js/meta.js
@@ -178,10 +178,10 @@ define(function(require, exports, module) {
tags.forEach(function(element) {
var newTag = {
"title": element,
- "type":"plain",
- "titleUI": element,
- "icon":"",
- "style":""
+ "type":"sidecar",
+ //"description": "",
+ //"icon":"",
+ //"style":""
};
var isNewTag = true;
metaObj.metaData.tags.forEach(function(oldTag) {
@@ -197,7 +197,7 @@ define(function(require, exports, module) {
saveMetaData(filePath, metaObj.metaData);
}
- function reanmeMetaTag(filePath, oldTag, newTag) {
+ function renameMetaTag(filePath, oldTag, newTag) {
var metaObj = findMetaObjectFromFileList(filePath);
if (metaObj.metaData) {
metaObj.metaData.tags.forEach(function(tag , index) {
@@ -234,6 +234,6 @@ define(function(require, exports, module) {
exports.getTagsFromMetaFile = getTagsFromMetaFile;
//tag utils
exports.addMetaTags = addMetaTags;
- exports.reanmeMetaTag = reanmeMetaTag;
+ exports.renameMetaTag = renameMetaTag;
exports.removeMetaTag = removeMetaTag;
});
\ No newline at end of file
diff --git a/data/js/options.ui.js b/data/js/options.ui.js
index 2f9e2a09a..b82440452 100644
--- a/data/js/options.ui.js
+++ b/data/js/options.ui.js
@@ -120,7 +120,7 @@ define(function(require, exports, module) {
$('#documentPropertiesKeyBinding').val(TSCORE.Config.getPropertiesDocumentKeyBinding());
$('#showSearchKeyBinding').val(TSCORE.Config.getSearchKeyBinding());
$('#perspectiveList').empty();
- $('#writeTagsToFiles').attr('checked', TSCORE.Config.getWriteTagsToFile());
+ $('#writeMetaToSidecarFile').attr('checked', TSCORE.Config.getWriteMetaToSidecarFile());
$('#useDefaultLocationCheckbox').attr('checked', TSCORE.Config.getUseDefaultLocation());
TSCORE.Config.getPerspectives().forEach(function(value) {
addPerspective($('#perspectiveList'), value.id);
@@ -186,7 +186,7 @@ define(function(require, exports, module) {
TSCORE.switchInterfaceLanguage(interfaceLang);
TSCORE.Config.setPerspectives(collectPerspectivesData());
TSCORE.Config.setSupportedFileTypes(collectSupportedFileTypesData());
- TSCORE.Config.setWriteTagsToFile($('#writeTagsToFiles').is(':checked'));
+ TSCORE.Config.setWriteMetaToSidecarFile($('#writeMetaToSidecarFile').is(':checked'));
TSCORE.Config.setUseDefaultLocation($('#useDefaultLocationCheckbox').is(':checked'));
TSCORE.Config.saveSettings();
}
diff --git a/data/js/settings.api.js b/data/js/settings.api.js
index bda2bd1cd..fd79375fe 100644
--- a/data/js/settings.api.js
+++ b/data/js/settings.api.js
@@ -968,15 +968,15 @@ define(function(require, exports, module) {
}
}
- var getWriteTagsToFile = function() {
- if (exports.Settings.writeTagsToFile === undefined) {
- exports.Settings.writeTagsToFile = exports.DefaultSettings.writeTagsToFile;
+ var getWriteMetaToSidecarFile = function() {
+ if (exports.Settings.writeMetaToSidecarFile === undefined) {
+ exports.Settings.writeMetaToSidecarFile = exports.DefaultSettings.writeMetaToSidecarFile;
saveSettings();
}
- return exports.Settings.writeTagsToFile;
+ return exports.Settings.writeMetaToSidecarFile;
};
- var setWriteTagsToFile = function(value) {
- exports.Settings.writeTagsToFile = value;
+ var setWriteMetaToSidecarFile = function(value) {
+ exports.Settings.writeMetaToSidecarFile = value;
};
var getUseDefaultLocation = function() {
@@ -1092,8 +1092,8 @@ define(function(require, exports, module) {
exports.loadDefaultSettings = loadDefaultSettings;
exports.saveSettings = saveSettings;
exports.addTagGroup = addTagGroup;
- exports.setWriteTagsToFile = setWriteTagsToFile;
- exports.getWriteTagsToFile = getWriteTagsToFile;
+ exports.setWriteMetaToSidecarFile = setWriteMetaToSidecarFile;
+ exports.getWriteMetaToSidecarFile = getWriteMetaToSidecarFile;
exports.getUseDefaultLocation = getUseDefaultLocation;
exports.setUseDefaultLocation = setUseDefaultLocation;
});
diff --git a/data/js/settings.default.js b/data/js/settings.default.js
index d629e88b5..cfb3380f5 100644
--- a/data/js/settings.default.js
+++ b/data/js/settings.default.js
@@ -28,6 +28,7 @@ define(function (require, exports, module) {
"isWindowMaximized": false,
"showMainMenu": false,
"useDefaultLocation": false,
+ "writeMetaToSidecarFile": false,
"lastOpenedLocation": "",
"webDavPath" : "oc/remote.php/webdav",
"ootbPerspectives": ['perspectiveList', 'perspectiveGrid', 'perspectiveGraph', 'perspectiveImageSwiper'],
diff --git a/data/js/tags.ui.js b/data/js/tags.ui.js
index dcfdde7a9..fde9bab55 100644
--- a/data/js/tags.ui.js
+++ b/data/js/tags.ui.js
@@ -33,7 +33,7 @@ define(function(require, exports, module) {
'<div class="accordion-inner" id="tagButtonsContent{{@index}}" style="padding: 2px;">' +
'<div>' +
'{{#each children}}' +
- '<a class="btn btn-sm tagButton" tag="{{title}}" parentkey="{{../key}}" style="{{style}}" title="{{titleUI}}" >' +
+ '<a class="btn btn-sm tagButton" tag="{{title}}" parentkey="{{../key}}" style="{{style}}" title="{{description}}" >' +
'<span class="{{icon}}" /> ' +
'{{title}}' +
'{{#if count}} [{{count}}]{{/if}}' +
@@ -227,9 +227,9 @@ define(function(require, exports, module) {
for (var j = 0; j < tagGroups[i].children.length; j++) {
tag = tagGroups[i].children[j];
if (tag.description !== undefined) {
- tag.titleUI = tag.description;
+ tag.description = tag.description;
} else {
- tag.titleUI = tag.title;
+ tag.description = tag.title;
}
tag.icon = '';
if (tag.type === 'smart') {
@@ -238,7 +238,7 @@ define(function(require, exports, module) {
// Add keybinding to tags
if (tag.keyBinding !== undefined && tag.keyBinding.length > 0) {
tag.icon = 'fa fa-keyboard-o';
- tag.titleUI = tag.titleUI + ' [' + tag.keyBinding + ']';
+ tag.description = tag.description + ' [' + tag.keyBinding + ']';
Mousetrap.unbind(tag.keyBinding);
Mousetrap.bind(tag.keyBinding, function(innerTag) {
return function(e) {
diff --git a/data/js/tagutils.js b/data/js/tagutils.js
index 621de9644..e8e6c156a 100644
--- a/data/js/tagutils.js
+++ b/data/js/tagutils.js
@@ -333,26 +333,26 @@ define(function(require, exports, module) {
}
function writeTagsToFile(filePath, tags) {
- console.log('Add the tags to: ' + filePath);
+ console.log('Add the tags for: ' + filePath);
- if (TSCORE.Config.getWriteTagsToFile() !== true) {
+ if (TSCORE.Config.getWriteMetaToSidecarFile()) {
TSCORE.Meta.addMetaTags(filePath, tags);
TSCORE.PerspectiveManager.updateFileUI(filePath, filePath);
- return;
- }
-
- var fileName = extractFileName(filePath);
- var containingDirectoryPath = extractContainingDirectoryPath(filePath);
- var extractedTags = extractTags(filePath);
- for (var i = 0; i < tags.length; i++) {
- // check if tag is already in the tag array
- if (extractedTags.indexOf(tags[i].trim()) < 0) {
- // Adding the new tag
- extractedTags.push(tags[i].trim());
+ } else {
+ var fileName = extractFileName(filePath);
+ var containingDirectoryPath = extractContainingDirectoryPath(filePath);
+ var extractedTags = extractTags(filePath);
+ for (var i = 0; i < tags.length; i++) {
+ // check if tag is already in the tag array
+ if (extractedTags.indexOf(tags[i].trim()) < 0) {
+ // Adding the new tag
+ extractedTags.push(tags[i].trim());
+ }
}
+ var newFileName = generateFileName(fileName, extractedTags);
+ TSCORE.IO.renameFile(filePath, containingDirectoryPath + TSCORE.dirSeparator + newFileName);
}
- var newFileName = generateFileName(fileName, extractedTags);
- TSCORE.IO.renameFile(filePath, containingDirectoryPath + TSCORE.dirSeparator + newFileName);
+
collectRecentTags(tags);
}
@@ -441,23 +441,24 @@ define(function(require, exports, module) {
function renameTag(filePath, oldTag, newTag) {
console.log('Rename tag for file: ' + filePath);
- if (TSCORE.Config.getWriteTagsToFile() !== true) {
- TSCORE.Meta.reanmeMetaTag(filePath, oldTag, newTag);
+ //todo Refine the logic to consider renaming tags from filename in a sidecar mode and vice versa
+ if (TSCORE.Config.getWriteMetaToSidecarFile()) {
+ TSCORE.Meta.renameMetaTag(filePath, oldTag, newTag);
TSCORE.PerspectiveManager.updateFileUI(filePath, filePath);
- }
-
- var fileName = extractFileName(filePath);
- var containingDirectoryPath = extractContainingDirectoryPath(filePath);
- var extractedTags = extractTags(filePath);
- for (var i = 0; i < extractedTags.length; i++) {
- // check if tag is already in the tag array
- if (extractedTags[i] === oldTag) {
- extractedTags[i] = newTag.trim();
+ } else {
+ var fileName = extractFileName(filePath);
+ var containingDirectoryPath = extractContainingDirectoryPath(filePath);
+ var extractedTags = extractTags(filePath);
+ for (var i = 0; i < extractedTags.length; i++) {
+ // check if tag is already in the tag array
+ if (extractedTags[i] === oldTag) {
+ extractedTags[i] = newTag.trim();
+ }
+ }
+ var newFileName = generateFileName(fileName, extractedTags);
+ if (newFileName !== fileName) {
+ TSCORE.IO.renameFile(filePath, containingDirectoryPath + TSCORE.dirSeparator + newFileName);
}
- }
- var newFileName = generateFileName(fileName, extractedTags);
- if (newFileName !== fileName) {
- TSCORE.IO.renameFile(filePath, containingDirectoryPath + TSCORE.dirSeparator + newFileName);
}
}
@@ -479,23 +480,24 @@ define(function(require, exports, module) {
function removeTag(filePath, tagName) {
console.log('Removing tag: ' + tagName + ' from ' + filePath);
- if (TSCORE.Config.getWriteTagsToFile() !== true) {
+ //todo Refine the logic to consider removing tags from filename in a sidecar mode and vice versa
+ if (TSCORE.Config.getWriteMetaToSidecarFile()) {
TSCORE.Meta.removeMetaTag(filePath, tagName);
TSCORE.PerspectiveManager.updateFileUI(filePath, filePath);
- }
-
- var fileName = extractFileName(filePath);
- var containingDirectoryPath = extractContainingDirectoryPath(filePath);
- var tags = extractTags(filePath);
- var newTags = [];
- for (var i = 0; i < tags.length; i++) {
- if (tags[i] !== tagName) {
- newTags.push(tags[i]);
+ } else {
+ var fileName = extractFileName(filePath);
+ var containingDirectoryPath = extractContainingDirectoryPath(filePath);
+ var tags = extractTags(filePath);
+ var newTags = [];
+ for (var i = 0; i < tags.length; i++) {
+ if (tags[i] !== tagName) {
+ newTags.push(tags[i]);
+ }
+ }
+ var newFileName = generateFileName(fileName, newTags);
+ if (newFileName !== fileName) {
+ TSCORE.IO.renameFile(filePath, containingDirectoryPath + TSCORE.dirSeparator + newFileName);
}
- }
- var newFileName = generateFileName(fileName, newTags);
- if (newFileName !== fileName) {
- TSCORE.IO.renameFile(filePath, containingDirectoryPath + TSCORE.dirSeparator + newFileName);
}
}
diff --git a/data/loader.js b/data/loader.js
index c3fe1d4ff..347d0c4a4 100644
--- a/data/loader.js
+++ b/data/loader.js
@@ -55,7 +55,7 @@ if( isFirefox ) {
}
var PRO_JS = "pro/js/pro.api";
-if(PRO.indexOf("@@PROVERS") == 0 || PRO == "false") { PRO_JS = 'js/pro'; }
+//if(PRO.indexOf("@@PROVERS") == 0 || PRO == "false") { PRO_JS = 'js/pro'; }
console.log("Loading Loader - Firefox: "+isFirefox+" | ChromeExt: "+isChrome+" | Node: "+isNode+" | Cordova: "+isCordova+" | Web: "+isWeb+" | isWin: "+isWin);
diff --git a/data/locales/en_US/ns.dialogs.json b/data/locales/en_US/ns.dialogs.json
index 7a4e32259..3976b58cf 100644
--- a/data/locales/en_US/ns.dialogs.json
+++ b/data/locales/en_US/ns.dialogs.json
@@ -146,8 +146,8 @@
"operationNotPermittedInEditModeAlert": "This operation is not permitted because the document has been already changed.",
"exportTagGroupsButton": "Export Tag Groups as JSON",
"showMainMenu": "Show main menu (restart needed)",
- "useDefaultLocation": "Use default location",
- "writeTagsToFiles": "Write tags to files",
+ "useDefaultLocation": "Use default location as a startup location",
+ "writeMetaToSidecarFile": "Use sidecar files in the .ts folders for saving meta information (e.g. tags)",
"invalidImportFile": "The imported file has invalid format",
"importGroupTagsTitle": "Import tags from file",
"-": "-"
diff --git a/default.settings.tmpl.js b/default.settings.tmpl.js
index 86639fba6..2f23d8075 100644
--- a/default.settings.tmpl.js
+++ b/default.settings.tmpl.js
@@ -29,6 +29,7 @@ define(function (require, exports, module) {
"showMainMenu": false,
"lastOpenedLocation": "",
"useDefaultLocation": false,
+ "writeMetaToSidecarFile": false,
"webDavPath" : "oc/remote.php/webdav",
"ootbPerspectives": [@@DEFAULTPERSPECTIVES],
"ootbViewers": [ "viewerBrowser", "viewerMD", "viewerImage", "viewerPDF", "editorText", "viewerText", "editorODF", "viewerURL", "viewerHTML", "viewerMHTML", "editorJSON", "viewerZIP", "viewerEPUB", "viewerAudioVideo" ],