rejuvenate Session for what I want to do now
parent
7e34ec3439
commit
99a399ba74
|
@ -4,64 +4,53 @@ 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!
|
||||
*/
|
||||
(() => {
|
||||
function findCategory(tag) {
|
||||
if (tag.name == "Wandering Toolmaker") {
|
||||
return tag.name;
|
||||
const allCategories = ["Work", "Personal", "Learning"];
|
||||
const defaultCategory = "Work";
|
||||
function findCategory(tags) {
|
||||
let todo = [...tags];
|
||||
while (true) {
|
||||
const current = todo.pop();
|
||||
if (!current) {
|
||||
return defaultCategory;
|
||||
}
|
||||
else if (current.name == "work") {
|
||||
return "Work";
|
||||
}
|
||||
else if (current.name == "personal") {
|
||||
return "Personal";
|
||||
}
|
||||
else if (current.name == "learning") {
|
||||
return "Learning";
|
||||
}
|
||||
else if (current.parent) {
|
||||
todo.push(current.parent);
|
||||
}
|
||||
}
|
||||
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) => {
|
||||
try {
|
||||
let possibleCategories = ["Personal", "Team", "Wandering Toolmaker"];
|
||||
let defaultCategory = possibleCategories[0];
|
||||
let defaultProject = null;
|
||||
let defaultMinutes = "25";
|
||||
let suggestedCategory = defaultCategory;
|
||||
let suggestedProject = null;
|
||||
let suggestedMinutes = "25";
|
||||
if (selection.tasks[0]) {
|
||||
let task = selection.tasks[0];
|
||||
for (let tag of task.tags) {
|
||||
let category = findCategory(tag);
|
||||
if (category !== null) {
|
||||
defaultCategory = category;
|
||||
break;
|
||||
}
|
||||
}
|
||||
suggestedCategory = findCategory(task.tasks);
|
||||
if (task.containingProject) {
|
||||
defaultProject = task.containingProject.name;
|
||||
suggestedProject = 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.tags) {
|
||||
suggestedCategory = findCategory(selection.tags);
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
suggestedProject = project.name;
|
||||
suggestedCategory = findCategory(project.tags);
|
||||
}
|
||||
let focusForm = new Form();
|
||||
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.String("minutes", "Minutes", defaultMinutes));
|
||||
focusForm.addField(new Form.Field.String("project", "Project", suggestedProject));
|
||||
focusForm.addField(new Form.Field.Option("category", "Category", allCategories, allCategories, suggestedCategory));
|
||||
focusForm.addField(new Form.Field.String("minutes", "Minutes", suggestedMinutes));
|
||||
await focusForm.show("Focus on…", "Start");
|
||||
let values = focusForm.values;
|
||||
let rawSessionUrl = `session:///start?intent=${encodeURIComponent(values.project)}&categoryName=${encodeURIComponent(values.category)}&duration=${encodeURIComponent(values.minutes)}`;
|
||||
|
@ -75,7 +64,7 @@ don't! Modify the .ts file and run `tsc` instead!
|
|||
console.error(err);
|
||||
}
|
||||
});
|
||||
action.validate = function (selection, sender) {
|
||||
action.validate = function (selection) {
|
||||
return (selection.tasks.length === 1 ||
|
||||
selection.tags.length === 1 ||
|
||||
selection.projects.length === 1);
|
||||
|
|
|
@ -3,85 +3,68 @@ 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!
|
||||
*/
|
||||
(() => {
|
||||
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";
|
||||
}
|
||||
type Category = "Work" | "Personal" | "Learning";
|
||||
const allCategories: Category[] = ["Work", "Personal", "Learning"];
|
||||
const defaultCategory: Category = "Work";
|
||||
|
||||
return null;
|
||||
function findCategory(tags: Tag[]): Category {
|
||||
let todo = [...tags];
|
||||
|
||||
while (true) {
|
||||
const current = todo.pop();
|
||||
|
||||
if (!current) {
|
||||
return defaultCategory;
|
||||
} else if (current.name == "work") {
|
||||
return "Work";
|
||||
} else if (current.name == "personal") {
|
||||
return "Personal";
|
||||
} else if (current.name == "learning") {
|
||||
return "Learning";
|
||||
} else if (current.parent) {
|
||||
todo.push(current.parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var action = new PlugIn.Action(async (selection: Selection, sender: any) => {
|
||||
var action = new PlugIn.Action(async (selection: Selection) => {
|
||||
try {
|
||||
let possibleCategories = ["Personal", "Team", "Wandering Toolmaker"];
|
||||
let defaultCategory: string = possibleCategories[0];
|
||||
let defaultProject: string | null = null;
|
||||
let defaultMinutes: string = "25";
|
||||
let suggestedCategory: Category = defaultCategory;
|
||||
let suggestedProject: string | null = null;
|
||||
let suggestedMinutes: string = "25";
|
||||
|
||||
if (selection.tasks[0]) {
|
||||
let task = selection.tasks[0];
|
||||
|
||||
for (let tag of task.tags) {
|
||||
let category = findCategory(tag);
|
||||
if (category !== null) {
|
||||
defaultCategory = category;
|
||||
break;
|
||||
}
|
||||
}
|
||||
suggestedCategory = findCategory(task.tasks);
|
||||
|
||||
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;
|
||||
suggestedProject = task.containingProject.name;
|
||||
}
|
||||
} else if (selection.tags) {
|
||||
suggestedCategory = findCategory(selection.tags);
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
suggestedProject = project.name;
|
||||
suggestedCategory = findCategory(project.tags);
|
||||
}
|
||||
|
||||
let focusForm = new Form();
|
||||
focusForm.addField(
|
||||
new Form.Field.String("project", "Project", defaultProject)
|
||||
new Form.Field.String("project", "Project", suggestedProject)
|
||||
);
|
||||
focusForm.addField(
|
||||
new Form.Field.Option(
|
||||
"category",
|
||||
"Category",
|
||||
possibleCategories,
|
||||
possibleCategories,
|
||||
defaultCategory
|
||||
allCategories,
|
||||
allCategories,
|
||||
suggestedCategory
|
||||
)
|
||||
);
|
||||
focusForm.addField(
|
||||
new Form.Field.String("minutes", "Minutes", defaultMinutes)
|
||||
new Form.Field.String("minutes", "Minutes", suggestedMinutes)
|
||||
);
|
||||
|
||||
await focusForm.show("Focus on…", "Start");
|
||||
|
@ -106,7 +89,7 @@ don't! Modify the .ts file and run `tsc` instead!
|
|||
}
|
||||
});
|
||||
|
||||
action.validate = function (selection: Selection, sender: any) {
|
||||
action.validate = function (selection: Selection) {
|
||||
return (
|
||||
selection.tasks.length === 1 ||
|
||||
selection.tags.length === 1 ||
|
||||
|
|
Reference in New Issue