src/lib/models/task.ts (view raw)
1import { getStringNoLocale, getUrl, getDatetime, type Thing } from '@inrupt/solid-client';
2import { SCHEMA_INRUPT } from '@inrupt/vocab-common-rdf';
3
4const SCHEMA_CUSTOM = {
5 // Types
6 ScheduleAction: 'http://schema.org/ScheduleAction',
7
8 // Properties
9 scheduledTime: 'http://schema.org/scheduledTime',
10 actionStatus: 'http://schema.org/actionStatus',
11
12 // Enumeration types
13 ActionStatusType: {
14 active: 'http://schema.org/ActiveActionStatus',
15 done: 'http://schema.org/CompletedActionStatus'
16 }
17};
18
19export class Task {
20 type = SCHEMA_CUSTOM.ScheduleAction;
21 done: boolean;
22 name: string | null;
23 datetime: Date | null;
24
25 constructor(taskInput: Thing) {
26 this.name = getStringNoLocale(taskInput, SCHEMA_INRUPT.name);
27 this.done =
28 getUrl(taskInput, SCHEMA_CUSTOM.actionStatus) === SCHEMA_CUSTOM.ActionStatusType.done;
29 this.datetime = getDatetime(taskInput, SCHEMA_CUSTOM.scheduledTime);
30 }
31
32 serialize() {
33 // TODO could be improved
34 return JSON.parse(JSON.stringify(this));
35 }
36}