Skip to content

Commit 1d741e5

Browse files
Built
1 parent 5529f73 commit 1d741e5

8 files changed

Lines changed: 198 additions & 156 deletions

File tree

tasks/soukai/lib/Workspaces.d.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Store } from 'vuex';
2+
import Service from '@/services/Service';
3+
import User from '@/models/users/User';
4+
import Workspace from '@/models/soukai/Workspace';
5+
interface State {
6+
activeWorkspace: Workspace | null;
7+
workspaces: Workspace[];
8+
}
9+
export default class Workspaces extends Service {
10+
get empty(): boolean;
11+
get active(): Workspace | null;
12+
get all(): Workspace[];
13+
setActive(workspace: Workspace | null): Promise<void>;
14+
add(workspace: Workspace, activate?: boolean): void;
15+
remove(workspace: Workspace): void;
16+
protected get storage(): State;
17+
protected init(): Promise<void>;
18+
protected registerStoreModule(store: Store<State>): void;
19+
protected unregisterStoreModule(store: Store<State>): void;
20+
protected load(user: User): Promise<void>;
21+
protected unload(): Promise<void>;
22+
private loadWorkspace;
23+
}
24+
export {};

tasks/soukai/lib/Workspaces.js

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
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 Service_1 = __importDefault(require("@/services/Service"));
16+
const Workspace_1 = __importDefault(require("@/models/soukai/Workspace"));
17+
const EventBus_1 = __importDefault(require("@/utils/EventBus"));
18+
const Storage_1 = __importDefault(require("@/utils/Storage"));
19+
class Workspaces extends Service_1.default {
20+
get empty() {
21+
return !this.storage.workspaces || this.storage.workspaces.length === 0;
22+
}
23+
get active() {
24+
return this.storage.activeWorkspace;
25+
}
26+
get all() {
27+
return this.storage.workspaces;
28+
}
29+
setActive(workspace) {
30+
return __awaiter(this, void 0, void 0, function* () {
31+
this.app.$store.commit('setActiveWorkspace', workspace);
32+
if (workspace)
33+
Storage_1.default.set('activeWorkspaceId', workspace.id);
34+
else
35+
Storage_1.default.remove('activeWorkspaceId');
36+
});
37+
}
38+
add(workspace, activate = true) {
39+
this.app.$store.commit('addWorkspace', workspace);
40+
if (activate)
41+
this.setActive(workspace);
42+
}
43+
remove(workspace) {
44+
this.app.$store.commit('removeWorkspace', workspace);
45+
this.setActive(this.all.length > 0 ? this.all[0] : null);
46+
}
47+
get storage() {
48+
return this.app.$store.state.workspaces
49+
? this.app.$store.state.workspaces
50+
: {};
51+
}
52+
init() {
53+
const _super = Object.create(null, {
54+
init: { get: () => super.init }
55+
});
56+
return __awaiter(this, void 0, void 0, function* () {
57+
yield _super.init.call(this);
58+
yield this.app.$auth.ready;
59+
if (this.app.$auth.isLoggedIn()) {
60+
yield this.load(this.app.$auth.user);
61+
}
62+
EventBus_1.default.on('login', this.load.bind(this));
63+
EventBus_1.default.on('logout', this.unload.bind(this));
64+
});
65+
}
66+
registerStoreModule(store) {
67+
store.registerModule('workspaces', {
68+
state: {
69+
activeWorkspace: null,
70+
workspaces: [],
71+
},
72+
mutations: {
73+
setActiveWorkspace(state, activeWorkspace) {
74+
state.activeWorkspace = activeWorkspace;
75+
},
76+
setWorkspaces(state, workspaces) {
77+
state.workspaces = workspaces;
78+
},
79+
addWorkspace(state, workspace) {
80+
state.workspaces.push(workspace);
81+
},
82+
removeWorkspace(state, workspace) {
83+
const index = state.workspaces.findIndex(existingWorkspace => existingWorkspace === workspace);
84+
if (index !== -1) {
85+
state.workspaces.splice(index, 1);
86+
}
87+
},
88+
},
89+
});
90+
}
91+
unregisterStoreModule(store) {
92+
store.unregisterModule('workspaces');
93+
}
94+
load(user) {
95+
return __awaiter(this, void 0, void 0, function* () {
96+
const workspaces = [];
97+
const activeWorkspaceId = Storage_1.default.get('activeWorkspaceId');
98+
const activeListId = Storage_1.default.get('activeListId');
99+
let activeWorkspace;
100+
for (const storage of user.storages) {
101+
workspaces.push(...(yield Workspace_1.default.from(storage).all()));
102+
}
103+
activeWorkspace = workspaces.find(workspace => workspace.id === activeWorkspaceId);
104+
if (!activeWorkspace && workspaces.length > 0)
105+
activeWorkspace = workspaces[0];
106+
if (activeWorkspace)
107+
yield this.loadWorkspace(activeWorkspace, activeListId);
108+
this.app.$store.commit('setWorkspaces', workspaces);
109+
this.app.$store.commit('setActiveWorkspace', activeWorkspace);
110+
});
111+
}
112+
unload() {
113+
return __awaiter(this, void 0, void 0, function* () {
114+
this.app.$store.commit('setWorkspaces', []);
115+
this.app.$store.commit('setActiveWorkspace', null);
116+
Storage_1.default.remove('activeWorkspaceId');
117+
Storage_1.default.remove('activeListId');
118+
});
119+
}
120+
loadWorkspace(workspace, activeListId) {
121+
return __awaiter(this, void 0, void 0, function* () {
122+
if (!workspace.isRelationLoaded('lists')) {
123+
yield workspace.loadRelation('lists');
124+
// TODO this could be done automatically in Soukai
125+
for (const list of workspace.lists) {
126+
list.setRelationModels('workspace', workspace);
127+
}
128+
}
129+
workspace.setActiveList(workspace.lists.find(list => list.id === activeListId) ||
130+
workspace.activeList);
131+
if (workspace && !workspace.activeList.isRelationLoaded('tasks'))
132+
yield workspace.activeList.loadRelation('tasks');
133+
});
134+
}
135+
}
136+
exports.default = Workspaces;

tasks/soukai/lib/helpers/uuid.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/// <reference types="node" />
2+
import crypto from 'node:crypto';
3+
export declare class Uuid {
4+
v4(options?: crypto.RandomUUIDOptions | undefined): string;
5+
}
6+
declare const _default: Uuid;
7+
export default _default;

tasks/soukai/lib/helpers/uuid.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"use strict";
2+
var __importDefault = (this && this.__importDefault) || function (mod) {
3+
return (mod && mod.__esModule) ? mod : { "default": mod };
4+
};
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
exports.Uuid = void 0;
7+
const node_crypto_1 = __importDefault(require("node:crypto"));
8+
class Uuid {
9+
v4(options) {
10+
return node_crypto_1.default.randomUUID(options);
11+
}
12+
}
13+
exports.Uuid = Uuid;
14+
exports.default = new Uuid();

tasks/soukai/lib/index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export { Uuid } from './helpers/uuid';
2+
import uuid from './helpers/uuid';
3+
export default uuid;

tasks/soukai/lib/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"use strict";
2+
var __importDefault = (this && this.__importDefault) || function (mod) {
3+
return (mod && mod.__esModule) ? mod : { "default": mod };
4+
};
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
exports.Uuid = void 0;
7+
var uuid_1 = require("./helpers/uuid");
8+
Object.defineProperty(exports, "Uuid", { enumerable: true, get: function () { return uuid_1.Uuid; } });
9+
const uuid_2 = __importDefault(require("./helpers/uuid"));
10+
exports.default = uuid_2.default;

tasks/soukai/package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tasks/soukai/src/Workspaces.ts

Lines changed: 0 additions & 152 deletions
This file was deleted.

0 commit comments

Comments
 (0)