Skip to content

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

Implementing clean tags functionality #65

Ilian4fce33aac0f2
diff --git a/data/index.html b/data/index.html
index 3646de0dc..e4c9e6a32 100644
--- a/data/index.html
+++ b/data/index.html
@@ -414,6 +414,7 @@ can be found in the LICENSE file.
</div>
</div>
<div class="modal-footer">
+ <button id="cleanTagsButton" class="btn btn-danger pull-left" data-dismiss="modal" aria-hidden="true" data-i18n="ns.dialogs:tagOperationCleanTags">Clean Tags</button>
<button class="btn" data-dismiss="modal" aria-hidden="true"><i class="fa fa-times fa-lg"></i></button>
<button id="removeTagsButton" class="btn btn-warning" data-dismiss="modal" aria-hidden="true" data-i18n="ns.dialogs:tagOperationRemoveTag">Remove Tags</button>
<button id="addTagsButton" class="btn btn-primary" data-dismiss="modal" aria-hidden="true" data-i18n="ns.dialogs:tagOperationAddTag">Add Tags</button>
diff --git a/data/js/tags.ui.js b/data/js/tags.ui.js
index 33bc84b7c..a9ac2de8a 100644
--- a/data/js/tags.ui.js
+++ b/data/js/tags.ui.js
@@ -110,7 +110,17 @@
);
generateTagGroups();
TSCORE.PerspectiveManager.refreshFileListContainer();
- });
+ });
+
+ $( "#cleanTagsButton" ).click( function() {
+ TSCORE.showConfirmDialog(
+ $.i18n.t("ns.dialogs:cleanFilesTitleConfirm"),
+ $.i18n.t("ns.dialogs:cleanFilesContentConfirm"),
+ function() {
+ TSCORE.TagUtils.cleanFilesFromTags(TSCORE.selectedFiles);
+ }
+ );
+ });
$( "#addTagsButton" ).click( function() {
var tags = $("#tags").val().split(",");
@@ -251,28 +261,37 @@
); // end group
var tagButtons = $("<div>").appendTo( "#tagButtonsContent"+i );
+ var tag;
+ var tagTitle;
for(var j=0; j < TSCORE.Config.Settings.tagGroups[i].children.length; j++) {
- var tagTitle;
- if(TSCORE.Config.Settings.tagGroups[i].children[j].description !== undefined) {
- tagTitle = TSCORE.Config.Settings.tagGroups[i].children[j].description;
+ tag = TSCORE.Config.Settings.tagGroups[i].children[j];
+ if(tag.description !== undefined) {
+ tagTitle = tag.description;
} else {
- tagTitle = "Opens context menu for "+TSCORE.Config.Settings.tagGroups[i].children[j].title;
+ tagTitle = "Opens context menu for "+tag.title;
}
var tagIcon = "";
- if(TSCORE.Config.Settings.tagGroups[i].children[j].type === "smart"){
+ if(tag.type === "smart"){
tagIcon = "<span class='fa fa-flask'/> ";
}
+ // TODO Add keybinding to tags
+// if(tag.keyBinding !== undefined) {
+// tagIcon = "<span class='fa fa-key'/> ";
+// Mousetrap.bind(tag.keyBinding, (function(innerTag) {
+// TSCORE.TagUtils.addTag(TSCORE.selectedFiles, [innerTag]);
+// } (tag.title) ));
+// }
var tagCount = "";
- if(TSCORE.Config.Settings.tagGroups[i].children[j].count !== undefined) {
- tagCount = " ("+TSCORE.Config.Settings.tagGroups[i].children[j].count+")";
+ if(tag.count !== undefined) {
+ tagCount = " ("+tag.count+")";
}
tagButtons.append($("<a>", {
"class": "btn btn-sm tagButton",
- "tag": TSCORE.Config.Settings.tagGroups[i].children[j].title,
+ "tag": tag.title,
"parentKey": TSCORE.Config.Settings.tagGroups[i].key,
"title": tagTitle,
- "text": TSCORE.Config.Settings.tagGroups[i].children[j].title+tagCount+" ",
- "style": generateTagStyle(TSCORE.Config.Settings.tagGroups[i].children[j])
+ "text": tag.title+tagCount+" ",
+ "style": generateTagStyle(tag)
})
.draggable({
"appendTo": "body",
diff --git a/data/js/tagutils.js b/data/js/tagutils.js
index c248ffb91..1fbd3d238 100644
--- a/data/js/tagutils.js
+++ b/data/js/tagutils.js
@@ -310,9 +310,26 @@
TSCORE.IO.renameFile(filePath, containingDirectoryPath+TSCORE.dirSeparator+newFileName);
}
-
-
- function addTag(filePathArray, tagArray) {
+
+ function cleanFileFromTags(filePath) {
+ console.log("Cleaning file from tags: " + filePath);
+ var fileTitle = extractTitle(filePath);
+ var fileExt = extractFileExtension(filePath);
+ var containingDirectoryPath = extractContainingDirectoryPath(filePath);
+ if(fileExt.length > 0) {
+ fileExt = "."+fileExt;
+ }
+ TSCORE.IO.renameFile(filePath, containingDirectoryPath+TSCORE.dirSeparator+fileTitle+fileExt);
+ }
+
+ function cleanFilesFromTags(filePathArray) {
+ console.log("Cleaning file from tags");
+ for (var i=0; i < filePathArray.length; i++) {
+ cleanFileFromTags(filePathArray[i]);
+ }
+ }
+
+ function addTag(filePathArray, tagArray) {
console.log("Adding tags to files");
for (var i=0; i < filePathArray.length; i++) {
writeTagsToFile(filePathArray[i], tagArray);
@@ -455,6 +472,7 @@
exports.removeTag = removeTag;
exports.removeTags = removeTags;
exports.addTag = addTag;
+ exports.cleanFilesFromTags = cleanFilesFromTags;
exports.changeTitle = changeTitle;
exports.stringEndsWith = stringEndsWith;
diff --git a/data/locales/en/ns.dialogs.json b/data/locales/en/ns.dialogs.json
index a92475d2f..d39bc69da 100644
--- a/data/locales/en/ns.dialogs.json
+++ b/data/locales/en/ns.dialogs.json
@@ -44,6 +44,9 @@
"tagOperationTagsPlaceholder": "List of tags",
"tagOperationAddTag": "Add Tags",
"tagOperationRemoveTag": "Remove Tags",
+ "tagOperationCleanTags": "Clean Tags",
+ "cleanFilesTitleConfirm": "Clean Files from Tags",
+ "cleanFilesContentConfirm": "Do you really want to remove all tags from the selected files?",
"editTagMasterTitle": "Edit Tag",
"editTagMasterName": "Name",
"editTagMasterColor": "Color",
@@ -61,6 +64,7 @@
"filePropertiesPath": "Path",
"filePropertiesSize": "Size in Bytes",
"filePropertiesLMDT": "Last Modified Datetime",
+ "filePropertiesTags": "Tags",
"createLocationTitle": "Connect a Location",
"createLocationPath": "Location Path",
"createLocationName": "Location Name",