Skip to content

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

Smart tags added

uggrockbdba2b4be25e
diff --git a/data/js/settings.api.js b/data/js/settings.api.js
index 147b4e4bd..a42ca63d7 100644
--- a/data/js/settings.api.js
+++ b/data/js/settings.api.js
@@ -53,13 +53,12 @@ define(function(require, exports, module) {
"lastOpenedDirectory": "",
"tagspacesList": [],
"extensionsPath": "ext",
- "ootbPerspectives": [ 'perspectiveThumb', 'perspectiveGraph' ],
+ "ootbPerspectives": [ 'perspectiveDefault', 'perspectiveThumb', 'perspectiveGraph' ],
"ootbViewers": [ "viewerBrowser", "viewerMD", "viewerImage", "viewerPDF", "editorText" ],
"ootbEditors": [ "editorHTML", "editorText" ],
"perspectives": [
- {
- "id": "perspectiveThumb", // ID should be equal to the directory name where the extension is located
- },
+ { "id": "perspectiveDefault" }, // ID should be equal to the directory name where the extension is located
+ { "id": "perspectiveThumb" }// ID should be equal to the directory name where the extension is located
],
"supportedFileTypes": [
{ "type": "jpg", "viewer": "viewerImage", "editor": "false" },
@@ -127,27 +126,87 @@ define(function(require, exports, module) {
}
]
},
+ {
+ "title": "Smart Tags",
+ "key": "SMR",
+ "expanded": true,
+ "children": [
+ {
+ "type": "smart",
+ "title": "now",
+ "functionality": "now",
+ "desciption": "Adds the current date and time as tag",
+ "color": "#4986e7",
+ "textcolor": "#ffffff"
+ },
+ {
+ "type": "smart",
+ "title": "today",
+ "functionality": "today",
+ "desciption": "Adds the current date as tag",
+ "color": "#4986e7",
+ "textcolor": "#ffffff"
+ },
+ {
+ "type": "smart",
+ "title": "tomorrow",
+ "functionality": "tomorrow",
+ "desciption": "Adds tomorrow's date as tag",
+ "color": "#4986e7",
+ "textcolor": "#ffffff"
+ },
+ {
+ "type": "smart",
+ "title": "yesterday",
+ "functionality": "yesterday",
+ "desciption": "Adds the date of yesterday as tag",
+ "color": "#4986e7",
+ "textcolor": "#ffffff"
+ },
+ {
+ "type": "smart",
+ "title": "month",
+ "functionality": "currentMonth",
+ "desciption": "Adds the current year and month as tag",
+ "color": "#4986e7",
+ "textcolor": "#ffffff"
+ },
+ {
+ "type": "smart",
+ "title": "year",
+ "functionality": "currentYear",
+ "desciption": "Adds the current year as tag",
+ "color": "#4986e7",
+ "textcolor": "#ffffff"
+ },
+ {
+ "type": "smart",
+ "title": "here",
+ "functionality": "here",
+ "desciption": "Adds the current location as tag",
+ "color": "#ff7537",
+ "textcolor": "#ffffff"
+ },
+ ]
+ },
{
"expanded": true,
"children": [
{
"type": "plain",
"title": "high",
- "parentKey": "49138",
"color": "#ff7537",
"textcolor": "#ffffff"
},
{
"type": "plain",
"title": "medium",
- "parentKey": "49138",
"color": "#ffad46",
"textcolor": "#ffffff"
},
{
"type": "plain",
"title": "low",
- "parentKey": "49138",
"color": "#7bd148",
"textcolor": "#ffffff"
}
diff --git a/data/js/tags.ui.js b/data/js/tags.ui.js
index dd58cc678..da5a0a45e 100644
--- a/data/js/tags.ui.js
+++ b/data/js/tags.ui.js
@@ -36,7 +36,7 @@ define(function(require, exports, module) {
// Context menu for the tags in the tag tree
$( "#tagTreeMenuAddTagToFile" ).click( function() {
- TSCORE.TagUtils.addTag(TSCORE.selectedFiles, [TSCORE.selectedTag]);
+ TSCORE.TagUtils.addTag(TSCORE.selectedFiles, [TSCORE.selectedTag]);
});
$( "#tagTreeMenuAddTagAsFilter" ).click( function() {
@@ -143,7 +143,7 @@ define(function(require, exports, module) {
for(var i=0; i < TSCORE.Config.Settings["tagGroups"].length; i++) {
$("#tagGroupsContent").append($("<div>", {
- "class": "accordion-group",
+ "class": "accordion-group disableTextSelection",
"style": "width: 99%; border: 0px #aaa solid;",
})
.append($("<div>", {
@@ -217,33 +217,107 @@ define(function(require, exports, module) {
var tagButtons = $("<div>").appendTo( "#tagButtonsContent"+i );
for(var j=0; j < TSCORE.Config.Settings["tagGroups"][i]["children"].length; j++) {
+ var tagTitle = undefined;
+ if(TSCORE.Config.Settings["tagGroups"][i]["children"][j].description != undefined) {
+ tagTitle = TSCORE.Config.Settings["tagGroups"][i]["children"][j].description;
+ } else {
+ tagTitle = "Opens context menu for "+TSCORE.Config.Settings["tagGroups"][i]["children"][j].title;
+ }
+ var tagIcon = "";
+ if(TSCORE.Config.Settings["tagGroups"][i]["children"][j].type == "smart"){
+ tagIcon = "<span class='icon-beaker'/> "
+ }
tagButtons.append($("<a>", {
"class": "btn btn-small tagButton",
"tag": TSCORE.Config.Settings["tagGroups"][i]["children"][j].title,
"parentKey": TSCORE.Config.Settings["tagGroups"][i].key,
- "title": "Opens context menu for "+TSCORE.Config.Settings["tagGroups"][i]["children"][j].title,
+ "title": tagTitle,
"text": TSCORE.Config.Settings["tagGroups"][i]["children"][j].title+" ",
"style": generateTagStyle(TSCORE.Config.Settings["tagGroups"][i]["children"][j]),
})
.click( function() {
- TSCORE.selectedTag = $(this).attr("tag");
TSCORE.selectedTagData = TSCORE.Config.getTagData($(this).attr("tag"), $(this).attr("parentKey"));
+ TSCORE.selectedTag = generateTagValue(TSCORE.selectedTagData);
TSCORE.selectedTagData.parentKey = $(this).attr("parentKey");
})
.draggable({
"appendTo": "body",
"helper": "clone",
"revert": 'invalid',
+ "start": function(e, ui) {
+ TSCORE.selectedTagData = TSCORE.Config.getTagData($(this).attr("tag"), $(this).attr("parentKey"));
+ TSCORE.selectedTag = generateTagValue(TSCORE.selectedTagData);
+ TSCORE.selectedTagData.parentKey = $(this).attr("parentKey");
+ }
})
+ .prepend(tagIcon)
.append("<span class='caret'/>")
.dropdown( 'attach' , '#tagTreeMenu' )
);
}
}
- // Activating nano scroller
- //$("#tagGroups").nanoScroller();
}
+ function generateTagValue(tagData) {
+ var tagValue = tagData.title;
+ if (tagData.type == "smart") {
+ switch (tagData.functionality){
+ case "here": {
+ /* window.onload = function() {
+ if (navigator.geolocation) {
+ navigator.geolocation.getCurrentPosition(function(position) {
+ var lat = position.coords.latitude;
+ var lng = position.coords.longitude;
+ alert("Current position: " + lat + " " + lng);
+ }, function(error) {
+ alert('Error occurred. Error code: ' + error.code);
+ },{timeout:50000});
+ }else{
+ alert('no geolocation support');
+ }
+ };*/
+ break;
+ }
+ case "today": {
+ tagValue = TSCORE.TagUtils.formatDateTime4Tag(new Date(), false);
+ break;
+ }
+ case "tomorrow": {
+ var d = new Date();
+ d.setDate(d.getDate() + 1);
+ tagValue = TSCORE.TagUtils.formatDateTime4Tag(d, false);
+ break;
+ }
+ case "yesterday": {
+ var d = new Date();
+ d.setDate(d.getDate() - 1);
+ tagValue = TSCORE.TagUtils.formatDateTime4Tag(d, false);
+ break;
+ }
+ case "currentMonth": {
+ var cMonth = ""+((new Date()).getMonth()+1);
+ if(cMonth.length == 1) {
+ cMonth = "0"+cMonth;
+ }
+ tagValue = ""+(new Date()).getFullYear()+cMonth;
+ break;
+ }
+ case "currentYear": {
+ tagValue = ""+(new Date()).getFullYear();
+ break;
+ }
+ case "now": {
+ tagValue = TSCORE.TagUtils.formatDateTime4Tag(new Date(), true);
+ break;
+ }
+ default : {
+ break;
+ }
+ }
+ }
+ return tagValue;
+ }
+
function openTagMenu(tagButton, tag, filePath) {
TSCORE.selectedFiles.push(filePath);
TSCORE.selectedTag = tag;
@@ -285,6 +359,7 @@ define(function(require, exports, module) {
return tagStyle;
}
+
// Helper function generating file extension button
function generateExtButton(fileExtension, filePath) {
//console.log("Creating ext button...");
diff --git a/data/js/tagutils.js b/data/js/tagutils.js
index c97e258c8..d2fcadb22 100644
--- a/data/js/tagutils.js
+++ b/data/js/tagutils.js
@@ -115,6 +115,32 @@ define(function(require, exports, module) {
}
return cYear+"."+cMonth+"."+cDate+time;
}
+
+ function formatDateTime4Tag(date, includeTime) {
+ if ((date === undefined) || (date === "")) return "";
+ var d = new Date(date);
+ var cDate = d.getDate();
+ cDate = cDate + "";
+ if (cDate.length == 1) { cDate = "0" + cDate; }
+ var cMonth = d.getMonth(); cMonth++;
+ cMonth = cMonth + "";
+ if (cMonth.length == 1) { cMonth = "0" + cMonth; }
+ var cYear = d.getFullYear();
+ var cHour = d.getHours();
+ cHour = cHour + "";
+ if (cHour.length == 1) { cHour = "0" + cHour; }
+ var cMinute = d.getMinutes();
+ cMinute = cMinute + "";
+ if (cMinute.length == 1) { cMinute = "0" + cMinute; }
+ var cSecond = d.getSeconds();
+ cSecond = cSecond + "";
+ if (cSecond.length == 1) { cSecond = "0" + cSecond; }
+ var time = "";
+ if (includeTime) {
+ time = "-"+cHour+""+cMinute+""+cSecond;
+ }
+ return cYear+""+cMonth+""+cDate+time;
+ }
function extractTags(filePath) {
console.log("Extracting tags from: "+filePath);
@@ -134,7 +160,8 @@ define(function(require, exports, module) {
tags = tagContainer.split(TAG_DELIMITER);
for (var i=0; i < tags.length; i++) {
- if(tags[i].trim().length > 1) {
+ // Min tag length set to 1 character
+ if(tags[i].trim().length > 0) {
cleanedTags.push(tags[i]);
}
}
@@ -158,7 +185,7 @@ define(function(require, exports, module) {
}
// Splitting filename with space, comma, plus, underscore and score delimiters
- tags = tagContainer.split(/[\s,+_-]+/);
+ tags = tagContainer.split(/[\s,.+_-]+/);
var cleanedTags = [];
@@ -363,6 +390,7 @@ define(function(require, exports, module) {
exports.extractTitle = extractTitle;
exports.formatFileSize = formatFileSize;
exports.formatDateTime = formatDateTime;
+ exports.formatDateTime4Tag = formatDateTime4Tag;
exports.extractTags = extractTags;
exports.suggestTags = suggestTags;
exports.writeTagsToFile = writeTagsToFile;