1
0
Fork 0
mirror of https://github.com/marty-oehme/scripts.git synced 2024-12-22 16:08:09 +00:00

Nested headers parsing available during task importing.

This commit is contained in:
Filip Makowski 2017-06-11 18:45:15 +02:00
parent 7bd91852f9
commit ae141f1c6e

View file

@ -115,6 +115,10 @@ QtObject {
var i; var i;
for (i = projectName.length + referenceHeaderLevel - headerLevel + 1; i > 0; i--) { for (i = projectName.length + referenceHeaderLevel - headerLevel + 1; i > 0; i--) {
projectName.pop(); projectName.pop();
if (projectName.length === 0) {
referenceHeaderLevel = headerLevel - 1;
break;
}
} }
} }
projectName.push(proName); projectName.push(proName);
@ -151,10 +155,35 @@ QtObject {
// Get selected text to determine the project we want to import from. // Get selected text to determine the project we want to import from.
var projectNames = []; var projectNames = [];
var referenceHeaderLevel = 0;
getSelectedTextAndSeparateByNewline().forEach(function (line){ getSelectedTextAndSeparateByNewline().forEach(function (line){
if (getProjectNameAndRun(line, function (proName, headerLevel) { if (getProjectNameAndRun(line, function (proName, headerLevel) {
projectNames.push(proName); if (projectNames.length === 0) {
logIfVerbose("No project detected yet. Inserting " + proName)
projectNames.push([proName]);
logIfVerbose("Reference header level set to " + headerLevel)
referenceHeaderLevel = headerLevel - 1;
return;
}
var newProjectName = projectNames[projectNames.length - 1].slice();
logIfVerbose("Last project name inserted was " + newProjectName.join('.'));
if (newProjectName.length + referenceHeaderLevel >= headerLevel) {
logIfVerbose("Same header level detected.");
var i;
for (i = newProjectName.length + referenceHeaderLevel - headerLevel + 1; i > 0; i--) {
newProjectName.pop();
if (newProjectName.length === 0) {
referenceHeaderLevel = headerLevel - 1;
break;
}
}
}
newProjectName.push(proName);
projectNames.push(newProjectName);
logIfVerbose("Project name detected. Inserted value is " + newProjectName.join('.'))
})) return; })) return;
}); });
@ -162,14 +191,25 @@ QtObject {
script.noteTextEditWrite(script.noteTextEditSelectedText()); script.noteTextEditWrite(script.noteTextEditSelectedText());
projectNames.forEach( function(projectName) { projectNames.forEach( function(projectName) {
var concatenatedProjectName = projectName.join('.');
var result = script.startSynchronousProcess(taskPath, var result = script.startSynchronousProcess(taskPath,
[ [
"pro.is:" + projectName, "pro.is:" + concatenatedProjectName,
"rc.report.next.columns=description.desc", "rc.report.next.columns=description.desc",
"rc.report.next.labels=Desc" "rc.report.next.labels=Desc"
], ],
""); "");
if (result) { if (result) {
// via https://stackoverflow.com/a/35635260
var repeat = function(str, count) {
var array = [];
for(var i = 0; i < count;)
array[i++] = str;
return array.join('');
}
script.noteTextEditWrite("\n");
script.noteTextEditWrite(repeat('#', projectName.length) + ' ' + projectName[projectName.length - 1] + "\n\n");
var tasksSeparated; var tasksSeparated;
// The result does not contain any \n, so we are splitting by whitespace. // The result does not contain any \n, so we are splitting by whitespace.
tasksSeparated = result.toString().split('\n'); tasksSeparated = result.toString().split('\n');
@ -186,9 +226,6 @@ QtObject {
tasksSeparated.splice(tasksSeparated.length - 1, 1); // removing "X tasks" tasksSeparated.splice(tasksSeparated.length - 1, 1); // removing "X tasks"
tasksSeparated.splice(tasksSeparated.length - 1, 1); // removing "" tasksSeparated.splice(tasksSeparated.length - 1, 1); // removing ""
script.noteTextEditWrite("\n");
script.noteTextEditWrite("# " + projectName + "\n\n");
tasksSeparated.forEach( function(taskDesc){ tasksSeparated.forEach( function(taskDesc){
script.noteTextEditWrite("* " + taskDesc + "\n"); script.noteTextEditWrite("* " + taskDesc + "\n");
}); });