|
| 1 | +"use strict"; |
| 2 | +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { |
| 3 | + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } |
| 4 | + return new (P || (P = Promise))(function (resolve, reject) { |
| 5 | + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } |
| 6 | + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } |
| 7 | + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } |
| 8 | + step((generator = generator.apply(thisArg, _arguments || [])).next()); |
| 9 | + }); |
| 10 | +}; |
| 11 | +var __importDefault = (this && this.__importDefault) || function (mod) { |
| 12 | + return (mod && mod.__esModule) ? mod : { "default": mod }; |
| 13 | +}; |
| 14 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 15 | +const soukai_1 = require("soukai"); |
| 16 | +const soukai_solid_1 = require("soukai-solid"); |
| 17 | +const List_1 = __importDefault(require("./List")); |
| 18 | +const decorators_1 = require("../../utils/decorators"); |
| 19 | +const Storage_1 = __importDefault(require("../../utils/Storage")); |
| 20 | +class Workspace extends soukai_solid_1.SolidModel { |
| 21 | + setActiveList(list) { |
| 22 | + this.activeList = list; |
| 23 | + Storage_1.default.set('activeListId', list.id); |
| 24 | + } |
| 25 | + listsRelationship() { |
| 26 | + return this.contains(List_1.default); |
| 27 | + } |
| 28 | + save(containerUrl) { |
| 29 | + const _super = Object.create(null, { |
| 30 | + save: { get: () => super.save } |
| 31 | + }); |
| 32 | + return __awaiter(this, void 0, void 0, function* () { |
| 33 | + const model = yield _super.save.call(this, containerUrl); |
| 34 | + if (!this.inbox.exists()) { |
| 35 | + const list = (yield List_1.default.find(this.url)); |
| 36 | + list.setRelationModels('tasks', []); |
| 37 | + this.setInbox(list); |
| 38 | + } |
| 39 | + return model; |
| 40 | + }); |
| 41 | + } |
| 42 | + initialize(attributes, exists) { |
| 43 | + super.initialize(attributes, exists); |
| 44 | + const list = new List_1.default(this.getAttributes(), false); |
| 45 | + list.setRelationModels('tasks', []); |
| 46 | + this.setInbox(list); |
| 47 | + if (this.exists()) { |
| 48 | + this.updateInbox(); |
| 49 | + } |
| 50 | + } |
| 51 | + updateInbox() { |
| 52 | + return __awaiter(this, void 0, void 0, function* () { |
| 53 | + const list = yield List_1.default.find(this.getAttribute('url')); |
| 54 | + this.setInbox(list); |
| 55 | + }); |
| 56 | + } |
| 57 | + setInbox(list) { |
| 58 | + const inbox = (0, decorators_1.decorate)(list, { |
| 59 | + getters: { |
| 60 | + name: () => 'Inbox', |
| 61 | + }, |
| 62 | + }); |
| 63 | + inbox.editable = false; |
| 64 | + inbox.setRelationModels('workspace', this); |
| 65 | + if (!this.activeList || this.activeList === this.inbox) { |
| 66 | + this.activeList = inbox; |
| 67 | + } |
| 68 | + this.inbox = inbox; |
| 69 | + } |
| 70 | +} |
| 71 | +exports.default = Workspace; |
| 72 | +Workspace.ldpContainer = true; |
| 73 | +Workspace.rdfContexts = { |
| 74 | + 'lifecycle': 'http://purl.org/vocab/lifecycle/schema#', |
| 75 | +}; |
| 76 | +Workspace.rdfsClasses = ['lifecycle:TaskGroup']; |
| 77 | +Workspace.fields = { |
| 78 | + name: { |
| 79 | + type: soukai_1.FieldType.String, |
| 80 | + rdfProperty: 'rdfs:label', |
| 81 | + required: true, |
| 82 | + }, |
| 83 | +}; |
| 84 | +Workspace.classFields = ['inbox', 'activeList']; |
0 commit comments