allow the Session script to start projects and tags as well as tasks
parent
1b747dd466
commit
d6130d64a8
|
@ -4,33 +4,64 @@ WARNING: if you're looking at the file ending in .js and want to make changes,
|
||||||
don't! Modify the .ts file and run `tsc` instead!
|
don't! Modify the .ts file and run `tsc` instead!
|
||||||
*/
|
*/
|
||||||
(() => {
|
(() => {
|
||||||
|
function findCategory(tag) {
|
||||||
|
if (tag.name == "Wandering Toolmaker") {
|
||||||
|
return tag.name;
|
||||||
|
}
|
||||||
|
else if (tag.name == "teams" || (tag.parent && tag.parent.name == "teams") || tag.name == "work" || (tag.parent && tag.parent.name == "work")) {
|
||||||
|
return "Team";
|
||||||
|
}
|
||||||
|
else if (tag.name == "personal" || (tag.parent && tag.parent.name == "personal")) {
|
||||||
|
return "Personal";
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
var action = new PlugIn.Action(async (selection, sender) => {
|
var action = new PlugIn.Action(async (selection, sender) => {
|
||||||
try {
|
try {
|
||||||
let task = selection.tasks[0];
|
|
||||||
let possibleCategories = [
|
let possibleCategories = [
|
||||||
"Personal",
|
"Personal",
|
||||||
"Team",
|
"Team",
|
||||||
"Wandering Toolmaker",
|
"Wandering Toolmaker",
|
||||||
];
|
];
|
||||||
let defaultCategory = possibleCategories[0];
|
let defaultCategory = possibleCategories[0];
|
||||||
for (let tag of task.tags) {
|
let defaultProject = null;
|
||||||
if (tag.name == "Wandering Toolmaker") {
|
let defaultMinutes = "25";
|
||||||
defaultCategory = tag.name;
|
if (selection.tasks[0]) {
|
||||||
break;
|
let task = selection.tasks[0];
|
||||||
|
for (let tag of task.tags) {
|
||||||
|
let category = findCategory(tag);
|
||||||
|
if (category !== null) {
|
||||||
|
defaultCategory = category;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (tag.name == "teams" || (tag.parent && tag.parent.name == "teams") || tag.name == "work" || (tag.parent && tag.parent.name == "work")) {
|
if (task.containingProject) {
|
||||||
defaultCategory = "Team";
|
defaultProject = task.containingProject.name;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
else if (tag.name == "personal" || (tag.parent && tag.parent.name == "personal")) {
|
}
|
||||||
defaultCategory = "Personal";
|
else if (selection.tags[0]) {
|
||||||
break;
|
let tag = selection.tags[0];
|
||||||
|
defaultProject = tag.name;
|
||||||
|
let category = findCategory(tag);
|
||||||
|
if (category !== null) {
|
||||||
|
defaultCategory = category;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (selection.projects[0]) {
|
||||||
|
let project = selection.projects[0];
|
||||||
|
defaultProject = project.name;
|
||||||
|
for (let tag of project.tags) {
|
||||||
|
let category = findCategory(tag);
|
||||||
|
if (category !== null) {
|
||||||
|
defaultCategory = category;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let focusForm = new Form();
|
let focusForm = new Form();
|
||||||
focusForm.addField(new Form.Field.String("project", "Project", task.containingProject ? task.containingProject.name : null));
|
focusForm.addField(new Form.Field.String("project", "Project", defaultProject));
|
||||||
focusForm.addField(new Form.Field.Option("category", "Category", possibleCategories, possibleCategories, defaultCategory));
|
focusForm.addField(new Form.Field.Option("category", "Category", possibleCategories, possibleCategories, defaultCategory));
|
||||||
focusForm.addField(new Form.Field.String("minutes", "Minutes", "25"));
|
focusForm.addField(new Form.Field.String("minutes", "Minutes", defaultMinutes));
|
||||||
await focusForm.show("Focus on…", "Start");
|
await focusForm.show("Focus on…", "Start");
|
||||||
let values = focusForm.values;
|
let values = focusForm.values;
|
||||||
let rawSessionUrl = `session:///start?intent=${encodeURIComponent(values.project)}&categoryName=${encodeURIComponent(values.category)}&duration=${encodeURIComponent(values.minutes)}`;
|
let rawSessionUrl = `session:///start?intent=${encodeURIComponent(values.project)}&categoryName=${encodeURIComponent(values.category)}&duration=${encodeURIComponent(values.minutes)}`;
|
||||||
|
@ -45,7 +76,7 @@ don't! Modify the .ts file and run `tsc` instead!
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
action.validate = function (selection, sender) {
|
action.validate = function (selection, sender) {
|
||||||
return (selection.tasks.length === 1);
|
return (selection.tasks.length === 1 || selection.tags.length === 1 || selection.projects.length === 1);
|
||||||
};
|
};
|
||||||
return action;
|
return action;
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -3,34 +3,75 @@ WARNING: if you're looking at the file ending in .js and want to make changes,
|
||||||
don't! Modify the .ts file and run `tsc` instead!
|
don't! Modify the .ts file and run `tsc` instead!
|
||||||
*/
|
*/
|
||||||
(() => {
|
(() => {
|
||||||
|
function findCategory(tag: Tag): string | null {
|
||||||
|
if (tag.name == "Wandering Toolmaker") {
|
||||||
|
return tag.name
|
||||||
|
|
||||||
|
} else if (tag.name == "teams" || (tag.parent && tag.parent.name == "teams") || tag.name == "work" || (tag.parent && tag.parent.name == "work")) {
|
||||||
|
return "Team"
|
||||||
|
|
||||||
|
} else if (tag.name == "personal" || (tag.parent && tag.parent.name == "personal")) {
|
||||||
|
return "Personal"
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
var action = new PlugIn.Action(async (selection: Selection, sender: any) => {
|
var action = new PlugIn.Action(async (selection: Selection, sender: any) => {
|
||||||
try {
|
try {
|
||||||
let task = selection.tasks[0]
|
|
||||||
|
|
||||||
let possibleCategories = [
|
let possibleCategories = [
|
||||||
"Personal",
|
"Personal",
|
||||||
"Team",
|
"Team",
|
||||||
"Wandering Toolmaker",
|
"Wandering Toolmaker",
|
||||||
];
|
];
|
||||||
let defaultCategory = possibleCategories[0];
|
let defaultCategory: string = possibleCategories[0];
|
||||||
|
let defaultProject: string | null = null;
|
||||||
|
let defaultMinutes: string = "25";
|
||||||
|
|
||||||
for (let tag of task.tags) {
|
if (selection.tasks[0]) {
|
||||||
if (tag.name == "Wandering Toolmaker") {
|
let task = selection.tasks[0]
|
||||||
defaultCategory = tag.name;
|
|
||||||
break;
|
for (let tag of task.tags) {
|
||||||
} else if (tag.name == "teams" || (tag.parent && tag.parent.name == "teams") || tag.name == "work" || (tag.parent && tag.parent.name == "work")) {
|
let category = findCategory(tag);
|
||||||
defaultCategory = "Team";
|
if (category !== null) {
|
||||||
break;
|
defaultCategory = category
|
||||||
} else if (tag.name == "personal" || (tag.parent && tag.parent.name == "personal")) {
|
break
|
||||||
defaultCategory = "Personal";
|
}
|
||||||
break;
|
}
|
||||||
|
|
||||||
|
if (task.containingProject) {
|
||||||
|
defaultProject = task.containingProject.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (selection.tags[0]) {
|
||||||
|
let tag = selection.tags[0]
|
||||||
|
|
||||||
|
defaultProject = tag.name
|
||||||
|
|
||||||
|
let category = findCategory(tag)
|
||||||
|
if (category !== null) {
|
||||||
|
defaultCategory = category
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (selection.projects[0]) {
|
||||||
|
let project = selection.projects[0]
|
||||||
|
|
||||||
|
defaultProject = project.name
|
||||||
|
|
||||||
|
for (let tag of project.tags) {
|
||||||
|
let category = findCategory(tag);
|
||||||
|
if (category !== null) {
|
||||||
|
defaultCategory = category
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let focusForm = new Form();
|
let focusForm = new Form();
|
||||||
focusForm.addField(new Form.Field.String("project", "Project", task.containingProject ? task.containingProject.name : null));
|
focusForm.addField(new Form.Field.String("project", "Project", defaultProject));
|
||||||
focusForm.addField(new Form.Field.Option("category", "Category", possibleCategories, possibleCategories, defaultCategory));
|
focusForm.addField(new Form.Field.Option("category", "Category", possibleCategories, possibleCategories, defaultCategory));
|
||||||
focusForm.addField(new Form.Field.String("minutes", "Minutes", "25"));
|
focusForm.addField(new Form.Field.String("minutes", "Minutes", defaultMinutes));
|
||||||
|
|
||||||
await focusForm.show("Focus on…", "Start");
|
await focusForm.show("Focus on…", "Start");
|
||||||
let values = focusForm.values as {
|
let values = focusForm.values as {
|
||||||
|
@ -51,7 +92,7 @@ don't! Modify the .ts file and run `tsc` instead!
|
||||||
});
|
});
|
||||||
|
|
||||||
action.validate = function(selection: Selection, sender: any){
|
action.validate = function(selection: Selection, sender: any){
|
||||||
return (selection.tasks.length === 1)
|
return (selection.tasks.length === 1 || selection.tags.length === 1 || selection.projects.length === 1)
|
||||||
};
|
};
|
||||||
|
|
||||||
return action;
|
return action;
|
||||||
|
|
Reference in New Issue