Skip to content

Commit

Permalink
Merge pull request #24 from Quorafind/dev
Browse files Browse the repository at this point in the history
Remove unused files
  • Loading branch information
Quorafind authored Feb 14, 2022
2 parents fe8a014 + c3d2d4b commit ca1fe67
Show file tree
Hide file tree
Showing 7 changed files with 318 additions and 416 deletions.
4 changes: 2 additions & 2 deletions main.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/bigCalendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ReactDOM from 'react-dom';

import App from './App';
// import type BCalendar from './index';
import type BigCalendarPlugin from './index';
import type BigCalendarPlugin from './index';
import {dailyNotesService, eventService} from './services';
import {getDateFromFile} from 'obsidian-daily-notes-interface';

Expand Down Expand Up @@ -82,8 +82,8 @@ export class BigCalendar extends ItemView {

InsertAfter = this.plugin.settings.InsertAfter;
StartDate = this.plugin.settings.StartDate;
DefaultEventComposition = this.plugin.settings.DefaultEventComposition;
ProcessEntriesBelow = this.plugin.settings.ProcessEntriesBelow;
DefaultEventComposition = this.plugin.settings.DefaultEventComposition;
ProcessEntriesBelow = this.plugin.settings.ProcessEntriesBelow;

this.bigCalendarComponent = React.createElement(App);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const CALENDAR_VIEW_TYPE = 'calendar_view';
export const CALENDAR_VIEW_TYPE = 'big-calendar';
334 changes: 157 additions & 177 deletions src/obComponents/obParseTasks.ts
Original file line number Diff line number Diff line change
@@ -1,188 +1,168 @@
// Credits go to Schemar's Tasks Plugin: https://github.dev/schemar/obsidian-tasks

import type { Moment } from 'moment';
import { Recurrence } from './obParseTasksRecurrence';
import {Moment} from '[email protected]@obsidian/node_modules/moment';
import {Recurrence} from './obParseTasksRecurrence';

export enum Status {
Todo = 'Todo',
Done = 'Done',
Todo = 'Todo',
Done = 'Done',
}

export class Task {
public readonly status: Status;
public readonly description: string;
public readonly path: string;
/**
* The original character from within `[]` in the document.
* Required to be added to the LI the same way obsidian does as a `data-task` attribute.
*/
public readonly originalStatusCharacter: string;
public readonly precedingHeader: string | null;

public readonly startDate: Moment | null;
public readonly scheduledDate: Moment | null;
public readonly dueDate: Moment | null;
public readonly doneDate: Moment | null;

public readonly recurrence: Recurrence | null;
/** The blockLink is a "^" annotation after the dates/recurrence rules. */
public readonly blockLink: string;

public static readonly dateFormat = 'YYYY-MM-DD';
public static readonly taskRegex = /^([\s\t]*)[-*] +\[(.)\] *(.*)/u;
// The following regexes end with `$` because they will be matched and
// removed from the end until none are left.
public static readonly startDateRegex = /🛫 ?(\d{4}-\d{2}-\d{2})$/u;
public static readonly scheduledDateRegex = /[] ?(\d{4}-\d{2}-\d{2})$/u;
public static readonly dueDateRegex = /[📅📆🗓] ?(\d{4}-\d{2}-\d{2})$/u;
public static readonly doneDateRegex = / ?(\d{4}-\d{2}-\d{2})$/u;
public static readonly recurrenceRegex = /🔁([a-zA-Z0-9, !]+)$/u;

constructor({
status,
description,
path,
originalStatusCharacter,
startDate,
scheduledDate,
dueDate,
doneDate,
recurrence,
}: {
status: Status;
description: string;
path: string;
originalStatusCharacter: string;
startDate: moment.Moment | null;
scheduledDate: moment.Moment | null;
dueDate: moment.Moment | null;
doneDate: moment.Moment | null;
recurrence: Recurrence | null;
}) {
this.status = status;
this.description = description;
this.path = path;
this.originalStatusCharacter = originalStatusCharacter;
this.startDate = startDate;
this.scheduledDate = scheduledDate;
this.dueDate = dueDate;
this.doneDate = doneDate;

this.recurrence = recurrence;
public readonly status: Status;
public readonly description: string;
public readonly path: string;
/**
* The original character from within `[]` in the document.
* Required to be added to the LI the same way obsidian does as a `data-task` attribute.
*/
public readonly originalStatusCharacter: string;
public readonly precedingHeader: string | null;

public readonly startDate: Moment | null;
public readonly scheduledDate: Moment | null;
public readonly dueDate: Moment | null;
public readonly doneDate: Moment | null;

public readonly recurrence: Recurrence | null;
/** The blockLink is a "^" annotation after the dates/recurrence rules. */
public readonly blockLink: string;

public static readonly dateFormat = 'YYYY-MM-DD';
public static readonly taskRegex = /^([\s\t]*)[-*] +\[(.)\] *(.*)/u;
// The following regexes end with `$` because they will be matched and
// removed from the end until none are left.
public static readonly startDateRegex = /🛫 ?(\d{4}-\d{2}-\d{2})$/u;
public static readonly scheduledDateRegex = /[] ?(\d{4}-\d{2}-\d{2})$/u;
public static readonly dueDateRegex = /[📅📆🗓] ?(\d{4}-\d{2}-\d{2})$/u;
public static readonly doneDateRegex = / ?(\d{4}-\d{2}-\d{2})$/u;
public static readonly recurrenceRegex = /🔁([a-zA-Z0-9, !]+)$/u;

constructor({
status,
description,
path,
originalStatusCharacter,
startDate,
scheduledDate,
dueDate,
doneDate,
recurrence,
}: {
status: Status;
description: string;
path: string;
originalStatusCharacter: string;
startDate: moment.Moment | null;
scheduledDate: moment.Moment | null;
dueDate: moment.Moment | null;
doneDate: moment.Moment | null;
recurrence: Recurrence | null;
}) {
this.status = status;
this.description = description;
this.path = path;
this.originalStatusCharacter = originalStatusCharacter;
this.startDate = startDate;
this.scheduledDate = scheduledDate;
this.dueDate = dueDate;
this.doneDate = doneDate;

this.recurrence = recurrence;
}

public static fromLine({line, path}: {line: string; path: string; precedingHeader: string | null}): Task | null {
const regexMatch = line.match(Task.taskRegex);
if (regexMatch === null) {
return null;
}

public static fromLine({
line,
path,
}: {
line: string;
path: string;
precedingHeader: string | null;
}): Task | null {
const regexMatch = line.match(Task.taskRegex);
if (regexMatch === null) {
return null;
}

const statusString = regexMatch[2].toLowerCase();

let status: Status;
switch (statusString) {
case ' ':
status = Status.Todo;
break;
default:
status = Status.Done;
}

// match[3] includes the whole body of the task after the brackets.
const body = regexMatch[3].trim();

let description = body;

// Keep matching and removing special strings from the end of the
// description in any order. The loop should only run once if the
// strings are in the expected order after the description.
let matched: boolean;
let startDate: Moment | null = null;
let scheduledDate: Moment | null = null;
let dueDate: Moment | null = null;
let doneDate: Moment | null = null;
let recurrence: Recurrence | null = null;
// Add a "max runs" failsafe to never end in an endless loop:
const maxRuns = 7;
let runs = 0;
do {
matched = false;

const doneDateMatch = description.match(Task.doneDateRegex);
if (doneDateMatch !== null) {
doneDate = window.moment(doneDateMatch[1], Task.dateFormat);
description = description
.replace(Task.doneDateRegex, '')
.trim();
matched = true;
}

const dueDateMatch = description.match(Task.dueDateRegex);
if (dueDateMatch !== null) {
dueDate = window.moment(dueDateMatch[1], Task.dateFormat);
description = description.replace(Task.dueDateRegex, '').trim();
matched = true;
}

const scheduledDateMatch = description.match(
Task.scheduledDateRegex,
);
if (scheduledDateMatch !== null) {
scheduledDate = window.moment(
scheduledDateMatch[1],
Task.dateFormat,
);
description = description
.replace(Task.scheduledDateRegex, '')
.trim();
matched = true;
}

const startDateMatch = description.match(Task.startDateRegex);
if (startDateMatch !== null) {
startDate = window.moment(startDateMatch[1], Task.dateFormat);
description = description
.replace(Task.startDateRegex, '')
.trim();
matched = true;
}

const recurrenceMatch = description.match(Task.recurrenceRegex);
if (recurrenceMatch !== null) {
recurrence = Recurrence.fromText({
recurrenceRuleText: recurrenceMatch[1].trim(),
startDate,
scheduledDate,
dueDate,
});

description = description
.replace(Task.recurrenceRegex, '')
.trim();
matched = true;
}

runs++;
} while (matched && runs <= maxRuns);

const task = new Task({
status,
description,
path,
originalStatusCharacter: statusString,
startDate,
scheduledDate,
dueDate,
doneDate,
recurrence,
});
return task;
const statusString = regexMatch[2].toLowerCase();

let status: Status;
switch (statusString) {
case ' ':
status = Status.Todo;
break;
default:
status = Status.Done;
}

// match[3] includes the whole body of the task after the brackets.
const body = regexMatch[3].trim();

let description = body;

// Keep matching and removing special strings from the end of the
// description in any order. The loop should only run once if the
// strings are in the expected order after the description.
let matched: boolean;
let startDate: Moment | null = null;
let scheduledDate: Moment | null = null;
let dueDate: Moment | null = null;
let doneDate: Moment | null = null;
let recurrence: Recurrence | null = null;
// Add a "max runs" failsafe to never end in an endless loop:
const maxRuns = 7;
let runs = 0;
do {
matched = false;

const doneDateMatch = description.match(Task.doneDateRegex);
if (doneDateMatch !== null) {
doneDate = window.moment(doneDateMatch[1], Task.dateFormat);
description = description.replace(Task.doneDateRegex, '').trim();
matched = true;
}

const dueDateMatch = description.match(Task.dueDateRegex);
if (dueDateMatch !== null) {
dueDate = window.moment(dueDateMatch[1], Task.dateFormat);
description = description.replace(Task.dueDateRegex, '').trim();
matched = true;
}

const scheduledDateMatch = description.match(Task.scheduledDateRegex);
if (scheduledDateMatch !== null) {
scheduledDate = window.moment(scheduledDateMatch[1], Task.dateFormat);
description = description.replace(Task.scheduledDateRegex, '').trim();
matched = true;
}

const startDateMatch = description.match(Task.startDateRegex);
if (startDateMatch !== null) {
startDate = window.moment(startDateMatch[1], Task.dateFormat);
description = description.replace(Task.startDateRegex, '').trim();
matched = true;
}

const recurrenceMatch = description.match(Task.recurrenceRegex);
if (recurrenceMatch !== null) {
recurrence = Recurrence.fromText({
recurrenceRuleText: recurrenceMatch[1].trim(),
startDate,
scheduledDate,
dueDate,
});

description = description.replace(Task.recurrenceRegex, '').trim();
matched = true;
}

runs++;
} while (matched && runs <= maxRuns);

const task = new Task({
status,
description,
path,
originalStatusCharacter: statusString,
startDate,
scheduledDate,
dueDate,
doneDate,
recurrence,
});
return task;
}
}
Loading

0 comments on commit ca1fe67

Please sign in to comment.