Skip to content

Commit

Permalink
Implementing clean tags functionality #65
Browse files Browse the repository at this point in the history
  • Loading branch information
uggrock committed May 7, 2014
1 parent dff0e60 commit 4fce33a
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 14 deletions.
1 change: 1 addition & 0 deletions data/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ <h4 data-i18n="ns.dialogs:tagOperationTitle">Tag operation on multiple files</h4
</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>
Expand Down
41 changes: 30 additions & 11 deletions data/js/tags.ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(",");
Expand Down Expand Up @@ -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",
Expand Down
24 changes: 21 additions & 3 deletions data/js/tagutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -455,6 +472,7 @@
exports.removeTag = removeTag;
exports.removeTags = removeTags;
exports.addTag = addTag;
exports.cleanFilesFromTags = cleanFilesFromTags;
exports.changeTitle = changeTitle;
exports.stringEndsWith = stringEndsWith;

Expand Down
4 changes: 4 additions & 0 deletions data/locales/en/ns.dialogs.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 4fce33a

Please sign in to comment.