1
0
Fork 0
mirror of https://github.com/marty-oehme/scripts.git synced 2025-12-10 14:02:44 +00:00

Added possibility to specify tags for the tasks by adding +tagname at the end of the entry line.

This commit is contained in:
Filip Makowski 2017-06-19 13:42:19 +02:00
parent f67a5bb9c1
commit 8c2eac447b
3 changed files with 78 additions and 9 deletions

View file

@ -149,10 +149,27 @@ QtObject {
var isTask = taskRegExp.exec(line);
if (isTask) {
var tags = [];
taskDescription = isTask[1];
logIfVerbose("Detected task: " + taskDescription);
var fetchTag;
var tagExp = /^(.+)?[\s*]?\+(.+)$/;
var currentTaskDescription = taskDescription;
do {
logIfVerbose("Fetching tags...");
fetchTag = tagExp.exec(currentTaskDescription);
if (fetchTag) {
logIfVerbose("Tag " + fetchTag[2] + " found!");
tags.push(fetchTag[2]);
currentTaskDescription = fetchTag[1];
var re = new RegExp("\\+" + fetchTag[2].replace(/ /g, ''), "i");
taskDescription = taskDescription.replace(re,'');
} else
break;
} while(currentTaskDescription);
var concatenatedProjectName = projectName.join('.');
if (tags.length == 0) {
logIfVerbose("Executing \"" + taskPath + " add pro:" + concatenatedProjectName + " " + taskDescription + "\"");
script.startDetachedProcess(taskPath,
[
@ -160,6 +177,16 @@ QtObject {
"pro:" + concatenatedProjectName,
taskDescription
]);
} else {
logIfVerbose("Executing \"" + taskPath + " add pro:" + concatenatedProjectName + " " + taskDescription + " tags:\"" + tags.join(' ') + "\"\"");
script.startDetachedProcess(taskPath,
[
"add",
"pro:" + concatenatedProjectName,
taskDescription,
"tags:\"" + tags.join(' ') + "\""
]);
}
// We expect, that the task description would be the only thing in the line, hence `return`.
return;
}
@ -257,7 +284,46 @@ QtObject {
var taskParamsRegexp = /(\d+)[\s*]?(.+)?[\s*]?/i;
var fetchTaskParams = taskParamsRegexp.exec(task);
logIfVerbose("Extracted data from task: ID " + fetchTaskParams[1] + " Desc: " + fetchTaskParams[2]);
var taskEntry = "* " + fetchTaskParams[2];
// We are fetching tags to append them to description line
var tagResult = script.startSynchronousProcess(taskPath,
[
fetchTaskParams[1],
"tag"
],
"");
var tagsPlainText = "";
if (tagResult) {
var tagsSeparated;
// The result does not contain any \n, so we are splitting by whitespace.
tagsSeparated = tagResult.toString().split('\n');
logIfVerbose(tagsSeparated);
tagsSeparated.splice(0, 1); // removing ""
if (tagsSeparated.length === 0) {
logIfVerbose("No tags");
return;
}
tagsSeparated.splice(0, 1); // removing headline
tagsSeparated.splice(0, 1); // removing "----"
tagsSeparated.splice(tagsSeparated.length - 1, 1); // removing ""
tagsSeparated.splice(tagsSeparated.length - 1, 1); // removing ""
tagsSeparated.splice(tagsSeparated.length - 1, 1); // removing ""
logIfVerbose(tagsSeparated);
tagsSeparated.forEach( function(tag){
var tagsRegexp = /[\s*]?(.+)[\s*]?1[\s*]?/i;
var fetchTag = tagsRegexp.exec(tag);
tagsPlainText += " +" + fetchTag[1].replace(/ /g,'');
});
}
var taskEntry = "* " + fetchTaskParams[2] + tagsPlainText;
logIfVerbose("Inserting \"" + taskEntry + "\" after line " + projectNameLines[currentProjectNumber - 1]);
plainText.splice(projectNameLines[currentProjectNumber - 1], 0, taskEntry);
@ -268,6 +334,8 @@ QtObject {
}
// We gather task IDs in case deleteOnImport is enabled.
taskIds.push(fetchTaskParams[1]);
});
if (deleteOnImport) {