Skip to content

Commit

Permalink
Tests and bugfixes for task shifting
Browse files Browse the repository at this point in the history
  • Loading branch information
pajoma committed Apr 10, 2022
1 parent c3275c9 commit ed24b17
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 33 deletions.
8 changes: 4 additions & 4 deletions src/provider/codeactions/for-open-tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class OpenTaskActions implements vscode.CodeActionProvider {
if (!this.isOpenTask(document, range)) { return; }
return Promise.all([
this.createCompleteTaskAction(`Complete this task`, document, range),
// this.createShiftTaskAction(`Copy this task to next day's entry`, document, range, ShiftTarget.nextDay),
// this.createShiftTaskAction(`Plan for the next working day`, document, range, ShiftTarget.nextDay), // extracting date for current doc not working yet
this.createShiftTaskAction(`Plan for tomorrow`, document, range, ShiftTarget.tomorrow),
this.createShiftTaskAction(`Plan for today`, document, range, ShiftTarget.today)
]
Expand Down Expand Up @@ -136,9 +136,9 @@ export class OpenTaskActions implements vscode.CodeActionProvider {
private getCopyText(target: ShiftTarget): string {

switch (target) {
case ShiftTarget.nextDay: return " (next day)";
case ShiftTarget.today: return (" ("+moment().format("MM-DD")+")");
case ShiftTarget.tomorrow: return (" ("+moment().add(1, "d").format("MM-DD")+")");
case ShiftTarget.nextDay: return " (moved: next day)";
case ShiftTarget.today: return (" (moved: "+moment().format("MM-DD")+")");
case ShiftTarget.tomorrow: return (" (moved: "+moment().add(1, "d").format("MM-DD")+")");
}
}
}
4 changes: 2 additions & 2 deletions src/provider/codelens/shift-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ export class ShiftTaskCodeLens implements vscode.CodeLensProvider {

async getRegex() : Promise<RegExp> {
let template = await this.ctrl.configuration.getTaskInlineTemplate();
return new RegExp(template.after)
return new RegExp(template.after);
}

public async provideCodeLenses(document: vscode.TextDocument, token: vscode.CancellationToken): Promise<vscode.CodeLens[]> {
this.codeLenses = [];
const regex = await this.getRegex()
const regex = await this.getRegex();
const text = document.getText();
const matches = regex.exec(text);

Expand Down
48 changes: 27 additions & 21 deletions src/provider/commands/copy-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,39 +57,45 @@ export class CopyTaskCommand implements vscode.Command {
this.ctrl.logger.trace("command called with ", document.uri, ", text ", text, " and target ", target);

switch (target) {
case ShiftTarget.nextDay: this.insertTaskInNextDaysEntry(document, text);
case ShiftTarget.today: this.insertTaskToTodaysEntry(document, text);
case ShiftTarget.tomorrow: this.insertTaskToTomorrowsEntry(document, text);
case ShiftTarget.nextDay: return this.insertTaskInNextWorkdDaysEntry(document, text);
case ShiftTarget.today: return this.insertTaskToTodaysEntry(text);
case ShiftTarget.tomorrow: return this.insertTaskToTomorrowsEntry(text);
}
}

private async insertTaskInNextWorkdDaysEntry(document: vscode.TextDocument, taskString: string) {
const entryDate: Date = await J.Util.getDateFromURIAndConfig(document.uri.toString(), this.ctrl.config);
const entryMoment = moment(entryDate);

let dayIncrement = 1;

if (entryMoment.day() === 5) {
dayIncrement = 3;
} else if (entryMoment.day() === 6) {
dayIncrement = 2;
}

this.insertTaskToEntry(taskString, moment(entryDate).add(dayIncrement, "d").toDate());
}

return;
private async insertTaskToTomorrowsEntry(taskString: string) {
this.insertTaskToEntry(taskString, moment().add(1, 'd').toDate());
}

private async insertTaskToTodaysEntry(taskString: string) {
this.insertTaskToEntry(taskString, moment().toDate());
}

private async insertTaskToTomorrowsEntry(document: vscode.TextDocument, taskString: string) {
// get text document for tomorrow
const tomorrowDoc : vscode.TextDocument = await this.ctrl.reader.loadEntryForDay(moment().add(1, 'd').toDate());
private async insertTaskToEntry(taskString: string, date: Date) {
const doc : vscode.TextDocument = await this.ctrl.reader.loadEntryForDay(date);
const tpl : J.Model.InlineTemplate = await this.ctrl.config.getTaskInlineTemplate();
const pos = this.ctrl.inject.computePositionForInput(tomorrowDoc, tpl);
const inlineString: J.Model.InlineString = await this.ctrl.inject.buildInlineString(tomorrowDoc, tpl, ["${input}", taskString]);
const pos = this.ctrl.inject.computePositionForInput(doc, tpl);
const inlineString: J.Model.InlineString = await this.ctrl.inject.buildInlineString(doc, tpl, ["${input}", taskString]);
this.ctrl.inject.injectInlineString(inlineString);

tomorrowDoc.save();
}

private async insertTaskToTodaysEntry(document: vscode.TextDocument, taskString: string) {
throw new Error('Method not implemented.');
doc.save();
}

private async insertTaskInNextDaysEntry(document: vscode.TextDocument, taskString: string) {
let entryDate: Date = await J.Util.getDateFromURIAndConfig(document.uri.toString(), this.ctrl.config);

let nextDate = new Date(entryDate.getFullYear(), entryDate.getMonth(), entryDate.getDate() + 1);

console.log("inserting line in new entry for date: ", nextDate);
throw new Error('Method not implemented.');
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class PrintDurationCommand implements vscode.Command, vscode.Disposable {
let mod: number = text.search(/AM|PM/);
if (mod > 0) {
if (text.charAt(mod - 1) !== " ") {
text = text.substr(0, mod - 1) + " " + text.substr(mod);
text = text.substring(0, mod - 1) + " " + text.substr(mod);
}
time = moment(text, "hmm A");
}
Expand Down
2 changes: 1 addition & 1 deletion src/provider/commands/print-sum-of-selected-numbers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class PrintSumCommand implements vscode.Command, vscode.Disposable {

public static create(ctrl: J.Util.Ctrl): vscode.Disposable {
const cmd = new this(ctrl);
vscode.commands.registerCommand(cmd.command, () => cmd.execute())
vscode.commands.registerCommand(cmd.command, () => cmd.execute());
return cmd;
}
/**
Expand Down
4 changes: 2 additions & 2 deletions src/provider/commands/show-entry-for-tomorrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import { AbstractLoadEntryForDateCommand } from './show-entry-for-date';


export class ShowEntryForTomorrowCommand extends AbstractLoadEntryForDateCommand {
title: string = "Show journal entry for tomorrow"
command: string = "journal.tomorrow"
title: string = "Show journal entry for tomorrow";
command: string = "journal.tomorrow";


public static create(ctrl: J.Util.Ctrl): vscode.Disposable {
Expand Down
4 changes: 2 additions & 2 deletions src/provider/commands/show-entry-for-yesterday.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import { AbstractLoadEntryForDateCommand } from './show-entry-for-date';


export class ShowEntryForYesterdayCommand extends AbstractLoadEntryForDateCommand{
title: string = "Show journal entry for yesterday"
command: string = "journal.yesterday"
title: string = "Show journal entry for yesterday";
command: string = "journal.yesterday";


public static create(ctrl: J.Util.Ctrl): vscode.Disposable {
Expand Down

0 comments on commit ed24b17

Please sign in to comment.