@sneat/space-models 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2022/index.js +2 -0
- package/esm2022/index.js.map +1 -0
- package/esm2022/lib/dto-models.js +2 -0
- package/esm2022/lib/dto-models.js.map +1 -0
- package/esm2022/lib/index.js +6 -0
- package/esm2022/lib/index.js.map +1 -0
- package/esm2022/lib/models.js +2 -0
- package/esm2022/lib/models.js.map +1 -0
- package/esm2022/lib/space-context.js +39 -0
- package/esm2022/lib/space-context.js.map +1 -0
- package/esm2022/lib/space-item-context.js +2 -0
- package/esm2022/lib/space-item-context.js.map +1 -0
- package/esm2022/lib/uimodels/index.js +2 -0
- package/esm2022/lib/uimodels/index.js.map +1 -0
- package/esm2022/lib/uimodels/ui-models.js +218 -0
- package/esm2022/lib/uimodels/ui-models.js.map +1 -0
- package/esm2022/sneat-space-models.js +5 -0
- package/esm2022/sneat-space-models.js.map +1 -0
- package/{src/lib/dto-models.ts → lib/dto-models.d.ts} +3 -6
- package/lib/models.d.ts +56 -0
- package/lib/space-context.d.ts +11 -0
- package/lib/space-item-context.d.ts +8 -0
- package/lib/uimodels/ui-models.d.ts +39 -0
- package/package.json +14 -2
- package/sneat-space-models.d.ts +5 -0
- package/eslint.config.js +0 -7
- package/ng-package.json +0 -7
- package/project.json +0 -38
- package/src/lib/invite-models.ts +0 -1
- package/src/lib/member-context.ts +0 -1
- package/src/lib/models.ts +0 -72
- package/src/lib/sanity.spec.ts +0 -5
- package/src/lib/space-context.ts +0 -71
- package/src/lib/space-item-context.ts +0 -21
- package/src/lib/uimodels/ui-models.ts +0 -265
- package/src/test-setup.ts +0 -1
- package/tsconfig.json +0 -13
- package/tsconfig.lib.json +0 -19
- package/tsconfig.lib.prod.json +0 -7
- package/tsconfig.spec.json +0 -31
- package/vite.config.mts +0 -10
- /package/{src/index.ts → index.d.ts} +0 -0
- /package/{src/lib/index.ts → lib/index.d.ts} +0 -0
- /package/{src/lib/uimodels/index.ts → lib/uimodels/index.d.ts} +0 -0
package/esm2022/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/space/models/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC","sourcesContent":["export * from './lib';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dto-models.js","sourceRoot":"","sources":["../../../../../../libs/space/models/src/lib/dto-models.ts"],"names":[],"mappings":"","sourcesContent":["import { SpaceType } from '@sneat/core';\nimport { IRecord } from '@sneat/data';\nimport { ISpaceDbo } from '@sneat/dto';\n\nexport interface ICreateSpaceRequest {\n type: SpaceType;\n // memberType: MemberType;\n title?: string;\n}\n\nexport interface ICreateSpaceResponse {\n space: IRecord<ISpaceDbo>;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/space/models/src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC","sourcesContent":["export * from './uimodels';\nexport * from './models';\nexport * from './dto-models';\nexport * from './space-context';\nexport * from './space-item-context';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../../../../libs/space/models/src/lib/models.ts"],"names":[],"mappings":"","sourcesContent":["import { SpaceType } from '@sneat/core';\nimport { ISpaceModuleItemRef } from '@sneat/dto';\n\nexport interface ISpaceRequest {\n readonly spaceID: string;\n}\n\nexport interface ISpaceItemRequest extends ISpaceRequest {\n readonly id: string;\n}\n\nexport interface ISpaceMemberRequest extends ISpaceRequest {\n readonly memberID: string;\n}\n\nexport interface ILeaveSpaceRequest extends ISpaceRequest {\n readonly message?: string;\n}\n\nexport interface IAcceptInviteResponse {\n readonly id: string;\n}\n\nexport interface IInviteSpace {\n readonly id: string;\n readonly type: SpaceType;\n readonly title: string;\n}\n\nexport interface IRejectPersonalInviteRequest extends ISpaceRequest {\n readonly inviteID: string;\n readonly pin: string;\n}\n\nexport type SpaceMemberStatus = 'active' | 'archived';\n\nexport interface ITaskRequest extends ISpaceMemberRequest {\n readonly type: string;\n readonly task: string;\n}\n\nexport interface IReorderTaskRequest extends ITaskRequest {\n readonly len: number;\n readonly from: number;\n readonly to: number;\n readonly after?: string;\n readonly before?: string;\n}\n\nexport interface IModuleCollectionRef {\n readonly moduleID: string;\n readonly collection: string;\n}\n\nexport interface IRelatedRolesRequest {\n readonly rolesOfItem?: string[];\n readonly rolesToItem?: string[];\n}\n\nexport interface IRelatedChange {\n readonly add?: IRelatedRolesRequest;\n readonly remove?: IRelatedRolesRequest;\n}\n\nexport interface IRelatedItemChange extends IRelatedChange {\n readonly itemRef: ISpaceModuleItemRef;\n}\n\nexport interface IUpdateRelatedRequest\n extends ISpaceItemRequest, IModuleCollectionRef {\n readonly related?: IRelatedItemChange[];\n}\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { computed } from '@angular/core';
|
|
2
|
+
export function zipMapBriefsWithIDs(briefs) {
|
|
3
|
+
return briefs
|
|
4
|
+
? Object.entries(briefs).map(([id, brief]) => ({ id, brief }))
|
|
5
|
+
: [];
|
|
6
|
+
}
|
|
7
|
+
export function zipMapBriefsWithIDsAndSpaceRef(space, briefs) {
|
|
8
|
+
return briefs
|
|
9
|
+
? Object.entries(briefs).map(([id, brief]) => ({ id, brief, space }))
|
|
10
|
+
: [];
|
|
11
|
+
}
|
|
12
|
+
export function computeSpaceRefFromSpaceContext($space) {
|
|
13
|
+
return computed(() => {
|
|
14
|
+
const space = $space();
|
|
15
|
+
return space?.type
|
|
16
|
+
? { type: space?.type, id: space.id }
|
|
17
|
+
: { id: space?.id || '' };
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
export function computeSpaceIdFromSpaceRef($spaceRef) {
|
|
21
|
+
return computed(() => $spaceRef().id);
|
|
22
|
+
}
|
|
23
|
+
export const spaceContextFromBrief = (id, brief) => ({ id, type: brief.type, brief });
|
|
24
|
+
// export interface IContactContextWithBrief
|
|
25
|
+
// extends ITeamItemNavContext<IContactBrief, IContactDto> {
|
|
26
|
+
// brief: IContactBrief;
|
|
27
|
+
// parentContact?: IContactContext;
|
|
28
|
+
// }
|
|
29
|
+
export function createShortSpaceInfoFromDbo(space) {
|
|
30
|
+
if (!space.type) {
|
|
31
|
+
throw new Error('!team.type');
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
id: space.id,
|
|
35
|
+
type: space.type,
|
|
36
|
+
title: space?.dbo?.title || space.brief?.title,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=space-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"space-context.js","sourceRoot":"","sources":["../../../../../../libs/space/models/src/lib/space-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAU,MAAM,eAAe,CAAC;AASjD,MAAM,UAAU,mBAAmB,CACjC,MAAwC;IAExC,OAAO,MAAM;QACX,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAC9D,CAAC,CAAC,EAAE,CAAC;AACT,CAAC;AAED,MAAM,UAAU,8BAA8B,CAC5C,KAAgB,EAChB,MAAwC;IAExC,OAAO,MAAM;QACX,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,K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@sneat/core';\nimport { IShortSpaceInfo, ISpaceBrief, ISpaceDbo } from '@sneat/dto';\n\nexport function zipMapBriefsWithIDs<Brief>(\n briefs?: Readonly<Record<string, Brief>>,\n): readonly IIdAndBrief<Brief>[] {\n return briefs\n ? Object.entries(briefs).map(([id, brief]) => ({ id, brief }))\n : [];\n}\n\nexport function zipMapBriefsWithIDsAndSpaceRef<Brief>(\n space: ISpaceRef,\n briefs?: Readonly<Record<string, Brief>>,\n): readonly IIdAndBriefWithSpaceRef<Brief>[] {\n return briefs\n ? Object.entries(briefs).map(([id, brief]) => ({ id, brief, space }))\n : [];\n}\n\nexport interface ISpaceContext\n extends ISpaceRef, INavContext<ISpaceBrief, ISpaceDbo> {\n // readonly type?: SpaceType;\n // readonly assets?: IAssetContext[]; // TODO: this should not be here\n // readonly contacts?: IContactContext[]; // TODO: this should not be here\n}\n\nexport function computeSpaceRefFromSpaceContext(\n $space: Signal<ISpaceContext | undefined>,\n) {\n return computed<ISpaceRef>(() => {\n const space = $space();\n return space?.type\n ? { type: space?.type, id: space.id }\n : { id: space?.id || '' };\n });\n}\n\nexport function computeSpaceIdFromSpaceRef($spaceRef: () => ISpaceRef) {\n return computed<string>(() => $spaceRef().id);\n}\n\nexport const spaceContextFromBrief = (\n id: string,\n brief: ISpaceBrief,\n): ISpaceContext => ({ id, type: brief.type, brief });\n\n// export interface IContactContextWithBrief\n// \textends ITeamItemNavContext<IContactBrief, IContactDto> {\n// \tbrief: IContactBrief;\n// \tparentContact?: IContactContext;\n// }\n\nexport function createShortSpaceInfoFromDbo(\n space: ISpaceContext,\n): IShortSpaceInfo {\n if (!space.type) {\n throw new Error('!team.type');\n }\n return {\n id: space.id,\n type: space.type,\n title: space?.dbo?.title || space.brief?.title,\n };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"space-item-context.js","sourceRoot":"","sources":["../../../../../../libs/space/models/src/lib/space-item-context.ts"],"names":[],"mappings":"","sourcesContent":["import {\n IIdAndOptionalBriefAndOptionalDbo,\n IIdAndOptionalDbo,\n ISpaceRef,\n} from '@sneat/core';\n\nexport interface ISpaceItemWithOptionalBriefAndOptionalDbo<\n Brief,\n Dbo extends Brief,\n> extends IIdAndOptionalBriefAndOptionalDbo<Brief, Dbo> {\n readonly space: ISpaceRef;\n}\n\nexport interface ISpaceItemWithOptionalDbo<Dbo> extends IIdAndOptionalDbo<Dbo> {\n readonly space: ISpaceRef;\n}\n\nexport type ISpaceItemNavContext<\n Brief,\n Dbo extends Brief,\n> = ISpaceItemWithOptionalBriefAndOptionalDbo<Brief, Dbo>;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../libs/space/models/src/lib/uimodels/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC","sourcesContent":["export * from './ui-models';\n"]}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
export class Total {
|
|
2
|
+
constructor(dto) {
|
|
3
|
+
this.dto = dto;
|
|
4
|
+
if (!dto) {
|
|
5
|
+
this.dto = { count: 0 };
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
get count() {
|
|
9
|
+
return this.dto ? this.dto.count : 0;
|
|
10
|
+
}
|
|
11
|
+
per(period) {
|
|
12
|
+
switch (period) {
|
|
13
|
+
case 'month':
|
|
14
|
+
return this.perMonth();
|
|
15
|
+
case 'year':
|
|
16
|
+
return this.perYear();
|
|
17
|
+
case 'quarter':
|
|
18
|
+
return this.perQuarter();
|
|
19
|
+
case 'week':
|
|
20
|
+
return this.perWeek();
|
|
21
|
+
case 'day':
|
|
22
|
+
return this.perDay();
|
|
23
|
+
default:
|
|
24
|
+
throw new Error(`unknown period: ${period}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
perDay() {
|
|
28
|
+
if (!this.dto) {
|
|
29
|
+
return 0;
|
|
30
|
+
}
|
|
31
|
+
let result = 0;
|
|
32
|
+
if (this.dto.day !== undefined) {
|
|
33
|
+
result += this.dto.day;
|
|
34
|
+
}
|
|
35
|
+
if (this.dto.week !== undefined) {
|
|
36
|
+
result += Math.round(this.dto.week / 7);
|
|
37
|
+
}
|
|
38
|
+
if (this.dto.month !== undefined) {
|
|
39
|
+
result += Math.round(this.dto.month / 30);
|
|
40
|
+
}
|
|
41
|
+
if (this.dto.quarter !== undefined) {
|
|
42
|
+
result += Math.round(this.dto.quarter / 61);
|
|
43
|
+
}
|
|
44
|
+
if (this.dto.year !== undefined) {
|
|
45
|
+
result += Math.round(this.dto.year / 365);
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
perWeek() {
|
|
50
|
+
if (!this.dto) {
|
|
51
|
+
return 0;
|
|
52
|
+
}
|
|
53
|
+
let result = 0;
|
|
54
|
+
if (this.dto.week !== undefined) {
|
|
55
|
+
result += this.dto.week;
|
|
56
|
+
}
|
|
57
|
+
if (this.dto.month !== undefined) {
|
|
58
|
+
result += Math.round(this.dto.month / 4.33);
|
|
59
|
+
}
|
|
60
|
+
if (this.dto.day !== undefined) {
|
|
61
|
+
result += this.dto.day * 7;
|
|
62
|
+
}
|
|
63
|
+
if (this.dto.quarter !== undefined) {
|
|
64
|
+
result += Math.round(this.dto.quarter / 13);
|
|
65
|
+
}
|
|
66
|
+
if (this.dto.year !== undefined) {
|
|
67
|
+
result += Math.round(this.dto.year / 52);
|
|
68
|
+
}
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
perMonth() {
|
|
72
|
+
if (!this.dto) {
|
|
73
|
+
return 0;
|
|
74
|
+
}
|
|
75
|
+
let result = 0;
|
|
76
|
+
if (this.dto.month !== undefined) {
|
|
77
|
+
result += this.dto.month;
|
|
78
|
+
}
|
|
79
|
+
if (this.dto.day !== undefined) {
|
|
80
|
+
result += this.dto.day * 30;
|
|
81
|
+
}
|
|
82
|
+
if (this.dto.week !== undefined) {
|
|
83
|
+
result += this.dto.week * 4.33;
|
|
84
|
+
}
|
|
85
|
+
if (this.dto.year !== undefined) {
|
|
86
|
+
result += Math.round(this.dto.year / 12);
|
|
87
|
+
}
|
|
88
|
+
if (this.dto.quarter !== undefined) {
|
|
89
|
+
result += Math.round(this.dto.quarter / 3);
|
|
90
|
+
}
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
perQuarter() {
|
|
94
|
+
if (!this.dto) {
|
|
95
|
+
return 0;
|
|
96
|
+
}
|
|
97
|
+
let result = 0;
|
|
98
|
+
if (this.dto.quarter !== undefined) {
|
|
99
|
+
result += this.dto.quarter;
|
|
100
|
+
}
|
|
101
|
+
if (this.dto.day !== undefined) {
|
|
102
|
+
result += this.dto.day * 61;
|
|
103
|
+
}
|
|
104
|
+
if (this.dto.week !== undefined) {
|
|
105
|
+
result += this.dto.week * 13;
|
|
106
|
+
}
|
|
107
|
+
if (this.dto.month !== undefined) {
|
|
108
|
+
result += this.dto.month * 3;
|
|
109
|
+
}
|
|
110
|
+
if (this.dto.year !== undefined) {
|
|
111
|
+
result += Math.round(this.dto.year / 4);
|
|
112
|
+
}
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
perYear() {
|
|
116
|
+
if (!this.dto) {
|
|
117
|
+
return 0;
|
|
118
|
+
}
|
|
119
|
+
let result = 0;
|
|
120
|
+
if (this.dto.year !== undefined) {
|
|
121
|
+
result += this.dto.year;
|
|
122
|
+
}
|
|
123
|
+
if (this.dto.day !== undefined) {
|
|
124
|
+
result += this.dto.day * 365;
|
|
125
|
+
}
|
|
126
|
+
if (this.dto.week !== undefined) {
|
|
127
|
+
result += this.dto.week * 52;
|
|
128
|
+
}
|
|
129
|
+
if (this.dto.month !== undefined) {
|
|
130
|
+
result += this.dto.month * 12;
|
|
131
|
+
}
|
|
132
|
+
if (this.dto.quarter !== undefined) {
|
|
133
|
+
result += this.dto.quarter * 4;
|
|
134
|
+
}
|
|
135
|
+
return result;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
export class Totals {
|
|
139
|
+
constructor(dtoTotals) {
|
|
140
|
+
this.incomes = new Total(dtoTotals ? dtoTotals.incomes : undefined);
|
|
141
|
+
this.expenses = new Total(dtoTotals ? dtoTotals.expenses : undefined);
|
|
142
|
+
}
|
|
143
|
+
get count() {
|
|
144
|
+
return this.incomes.count + this.expenses.count;
|
|
145
|
+
}
|
|
146
|
+
isPositive(period) {
|
|
147
|
+
return this.per(period, true, true) > 0;
|
|
148
|
+
}
|
|
149
|
+
isNegative(period) {
|
|
150
|
+
return this.per(period, true, true) < 0;
|
|
151
|
+
}
|
|
152
|
+
per(period, incomes = true, expense = true) {
|
|
153
|
+
if (incomes && expense) {
|
|
154
|
+
return this.incomes.per(period) - this.expenses.per(period);
|
|
155
|
+
}
|
|
156
|
+
if (incomes) {
|
|
157
|
+
return this.incomes.per(period);
|
|
158
|
+
}
|
|
159
|
+
if (expense) {
|
|
160
|
+
return -this.expenses.per(period);
|
|
161
|
+
}
|
|
162
|
+
return 0;
|
|
163
|
+
}
|
|
164
|
+
balance(per) {
|
|
165
|
+
switch (per) {
|
|
166
|
+
case 'month':
|
|
167
|
+
return (Math.round((this.incomes.perMonth() - this.expenses.perMonth()) * 100) / 100);
|
|
168
|
+
case 'day':
|
|
169
|
+
return (Math.round((this.incomes.perDay() - this.expenses.perDay()) * 100) /
|
|
170
|
+
100);
|
|
171
|
+
default:
|
|
172
|
+
throw new Error(`Unknown parameter value: ${per}`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
export class Commune {
|
|
177
|
+
constructor(space, shortId) {
|
|
178
|
+
this.space = space;
|
|
179
|
+
this.shortId = shortId;
|
|
180
|
+
this.totals = new Totals(space.dbo?.totals);
|
|
181
|
+
}
|
|
182
|
+
get id() {
|
|
183
|
+
return this.space.id;
|
|
184
|
+
}
|
|
185
|
+
get type() {
|
|
186
|
+
return this.space.dbo?.type;
|
|
187
|
+
}
|
|
188
|
+
get title() {
|
|
189
|
+
return this.space.dbo?.title;
|
|
190
|
+
}
|
|
191
|
+
get membersCountByRole() {
|
|
192
|
+
throw new Error('Not implemented yet - disabled');
|
|
193
|
+
// if (!this._membersCountByRole) {
|
|
194
|
+
// const byRole = this.numberOf.membersByRole;
|
|
195
|
+
// if (!byRole) {
|
|
196
|
+
// return [];
|
|
197
|
+
// }
|
|
198
|
+
// this._membersCountByRole = Object.entries(byRole)
|
|
199
|
+
// .map(item => ({ role: item[0], count: item[1] as number }));
|
|
200
|
+
// }
|
|
201
|
+
// return this._membersCountByRole;
|
|
202
|
+
}
|
|
203
|
+
supports(v) {
|
|
204
|
+
if (!v) {
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
switch (v) {
|
|
208
|
+
case 'staff':
|
|
209
|
+
return this.type === 'educator' || this.type === 'realtor';
|
|
210
|
+
case 'pupils':
|
|
211
|
+
return this.type === 'educator';
|
|
212
|
+
default:
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
//# sourceMappingURL=ui-models.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ui-models.js","sourceRoot":"","sources":["../../../../../../../libs/space/models/src/lib/uimodels/ui-models.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,KAAK;IAChB,YAA4B,GAAc;QAAd,QAAG,GAAH,GAAG,CAAW;QACxC,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,IAAI,CAAC,GAAG,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;QAC1B,CAAC;IACH,CAAC;IAED,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACvC,CAAC;IAEM,GAAG,CAAC,MAAc;QACvB,QAAQ,MAAM,EAAE,CAAC;YACf,KAAK,OAAO;gBACV,OAAO,IAAI,CAAC,QAAQ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AI;QACJ,mCAAmC;IACrC,CAAC;IAEM,QAAQ,CAAC,CAAqB;QACnC,IAAI,CAAC,CAAC,EAAE,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;QACD,QAAQ,CAAC,EAAE,CAAC;YACV,KAAK,OAAO;gBACV,OAAO,IAAI,CAAC,IAAI,KAAK,UAAU,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC;YAC7D,KAAK,QAAQ;gBACX,OAAO,IAAI,CAAC,IAAI,KAAK,UAAU,CAAC;YAClC;gBACE,MAAM;QACV,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF","sourcesContent":["import { SpaceType } from '@sneat/core';\nimport { DtoTotal, DtoTotals, Period } from '@sneat/dto';\nimport { ISpaceContext } from '../space-context';\n\nexport class Total {\n constructor(public readonly dto?: DtoTotal) {\n if (!dto) {\n this.dto = { count: 0 };\n }\n }\n\n public get count(): number {\n return this.dto ? this.dto.count : 0;\n }\n\n public per(period: Period): number {\n switch (period) {\n case 'month':\n return this.perMonth();\n case 'year':\n return this.perYear();\n case 'quarter':\n return this.perQuarter();\n case 'week':\n return this.perWeek();\n case 'day':\n return this.perDay();\n default:\n throw new Error(`unknown period: ${period}`);\n }\n }\n\n public perDay(): number {\n if (!this.dto) {\n return 0;\n }\n let result = 0;\n if (this.dto.day !== undefined) {\n result += this.dto.day;\n }\n if (this.dto.week !== undefined) {\n result += Math.round(this.dto.week / 7);\n }\n if (this.dto.month !== undefined) {\n result += Math.round(this.dto.month / 30);\n }\n if (this.dto.quarter !== undefined) {\n result += Math.round(this.dto.quarter / 61);\n }\n if (this.dto.year !== undefined) {\n result += Math.round(this.dto.year / 365);\n }\n return result;\n }\n\n public perWeek(): number {\n if (!this.dto) {\n return 0;\n }\n let result = 0;\n if (this.dto.week !== undefined) {\n result += this.dto.week;\n }\n if (this.dto.month !== undefined) {\n result += Math.round(this.dto.month / 4.33);\n }\n if (this.dto.day !== undefined) {\n result += this.dto.day * 7;\n }\n if (this.dto.quarter !== undefined) {\n result += Math.round(this.dto.quarter / 13);\n }\n if (this.dto.year !== undefined) {\n result += Math.round(this.dto.year / 52);\n }\n return result;\n }\n\n public perMonth(): number {\n if (!this.dto) {\n return 0;\n }\n let result = 0;\n if (this.dto.month !== undefined) {\n result += this.dto.month;\n }\n if (this.dto.day !== undefined) {\n result += this.dto.day * 30;\n }\n if (this.dto.week !== undefined) {\n result += this.dto.week * 4.33;\n }\n if (this.dto.year !== undefined) {\n result += Math.round(this.dto.year / 12);\n }\n if (this.dto.quarter !== undefined) {\n result += Math.round(this.dto.quarter / 3);\n }\n return result;\n }\n\n public perQuarter(): number {\n if (!this.dto) {\n return 0;\n }\n let result = 0;\n if (this.dto.quarter !== undefined) {\n result += this.dto.quarter;\n }\n if (this.dto.day !== undefined) {\n result += this.dto.day * 61;\n }\n if (this.dto.week !== undefined) {\n result += this.dto.week * 13;\n }\n if (this.dto.month !== undefined) {\n result += this.dto.month * 3;\n }\n if (this.dto.year !== undefined) {\n result += Math.round(this.dto.year / 4);\n }\n return result;\n }\n\n public perYear(): number {\n if (!this.dto) {\n return 0;\n }\n let result = 0;\n if (this.dto.year !== undefined) {\n result += this.dto.year;\n }\n if (this.dto.day !== undefined) {\n result += this.dto.day * 365;\n }\n if (this.dto.week !== undefined) {\n result += this.dto.week * 52;\n }\n if (this.dto.month !== undefined) {\n result += this.dto.month * 12;\n }\n if (this.dto.quarter !== undefined) {\n result += this.dto.quarter * 4;\n }\n return result;\n }\n}\n\nexport class Totals {\n readonly incomes: Total;\n readonly expenses: Total;\n\n constructor(dtoTotals?: DtoTotals) {\n this.incomes = new Total(dtoTotals ? dtoTotals.incomes : undefined);\n this.expenses = new Total(dtoTotals ? dtoTotals.expenses : undefined);\n }\n\n get count(): number {\n return this.incomes.count + this.expenses.count;\n }\n\n isPositive(period: Period): boolean {\n return this.per(period, true, true) > 0;\n }\n\n isNegative(period: Period): boolean {\n return this.per(period, true, true) < 0;\n }\n\n per(period: Period, incomes = true, expense = true): number {\n if (incomes && expense) {\n return this.incomes.per(period) - this.expenses.per(period);\n }\n if (incomes) {\n return this.incomes.per(period);\n }\n if (expense) {\n return -this.expenses.per(period);\n }\n return 0;\n }\n\n balance(per: 'month' | 'day'): number {\n switch (per) {\n case 'month':\n return (\n Math.round(\n (this.incomes.perMonth() - this.expenses.perMonth()) * 100,\n ) / 100\n );\n case 'day':\n return (\n Math.round((this.incomes.perDay() - this.expenses.perDay()) * 100) /\n 100\n );\n default:\n throw new Error(`Unknown parameter value: ${per}`);\n }\n }\n}\n\nexport class Commune implements ISpaceContext {\n public readonly totals: Totals;\n\n constructor(\n public readonly space: ISpaceContext,\n public readonly shortId?: string,\n ) {\n this.totals = new Totals(space.dbo?.totals);\n }\n\n public get id(): string {\n return this.space.id;\n }\n\n public get type(): SpaceType | undefined {\n return this.space.dbo?.type;\n }\n\n public get title(): string | undefined {\n return this.space.dbo?.title;\n }\n\n // public get isSupportingMemberGroups(): boolean {\n // \tconst t = this.team.type;\n // \treturn t === 'educator' || t === 'sport_club' || t === 'cohabit';\n // }\n\n // public get numberOf(): TeamCounts {\n // \tif (this.team.dto?.numberOf) {\n // \t\treturn this.team.dto.numberOf;\n // \t}\n // \treturn newTeamCounts(this.team.dto?.numberOf);\n // }\n\n private _membersCountByRole?: { role: string; count: number }[];\n\n public get membersCountByRole(): { role: string; count: number }[] {\n throw new Error('Not implemented yet - disabled');\n // if (!this._membersCountByRole) {\n // \tconst byRole = this.numberOf.membersByRole;\n // \tif (!byRole) {\n // \t\treturn [];\n // \t}\n // \tthis._membersCountByRole = Object.entries(byRole)\n // \t\t.map(item => ({ role: item[0], count: item[1] as number }));\n // }\n // return this._membersCountByRole;\n }\n\n public supports(v: 'staff' | 'pupils'): boolean {\n if (!v) {\n return false;\n }\n switch (v) {\n case 'staff':\n return this.type === 'educator' || this.type === 'realtor';\n case 'pupils':\n return this.type === 'educator';\n default:\n break;\n }\n return false;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sneat-space-models.js","sourceRoot":"","sources":["../../../../../libs/space/models/src/sneat-space-models.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,SAAS,CAAC","sourcesContent":["/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"]}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { SpaceType } from '@sneat/core';
|
|
2
2
|
import { IRecord } from '@sneat/data';
|
|
3
3
|
import { ISpaceDbo } from '@sneat/dto';
|
|
4
|
-
|
|
5
4
|
export interface ICreateSpaceRequest {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
title?: string;
|
|
5
|
+
type: SpaceType;
|
|
6
|
+
title?: string;
|
|
9
7
|
}
|
|
10
|
-
|
|
11
8
|
export interface ICreateSpaceResponse {
|
|
12
|
-
|
|
9
|
+
space: IRecord<ISpaceDbo>;
|
|
13
10
|
}
|
package/lib/models.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { SpaceType } from '@sneat/core';
|
|
2
|
+
import { ISpaceModuleItemRef } from '@sneat/dto';
|
|
3
|
+
export interface ISpaceRequest {
|
|
4
|
+
readonly spaceID: string;
|
|
5
|
+
}
|
|
6
|
+
export interface ISpaceItemRequest extends ISpaceRequest {
|
|
7
|
+
readonly id: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ISpaceMemberRequest extends ISpaceRequest {
|
|
10
|
+
readonly memberID: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ILeaveSpaceRequest extends ISpaceRequest {
|
|
13
|
+
readonly message?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface IAcceptInviteResponse {
|
|
16
|
+
readonly id: string;
|
|
17
|
+
}
|
|
18
|
+
export interface IInviteSpace {
|
|
19
|
+
readonly id: string;
|
|
20
|
+
readonly type: SpaceType;
|
|
21
|
+
readonly title: string;
|
|
22
|
+
}
|
|
23
|
+
export interface IRejectPersonalInviteRequest extends ISpaceRequest {
|
|
24
|
+
readonly inviteID: string;
|
|
25
|
+
readonly pin: string;
|
|
26
|
+
}
|
|
27
|
+
export type SpaceMemberStatus = 'active' | 'archived';
|
|
28
|
+
export interface ITaskRequest extends ISpaceMemberRequest {
|
|
29
|
+
readonly type: string;
|
|
30
|
+
readonly task: string;
|
|
31
|
+
}
|
|
32
|
+
export interface IReorderTaskRequest extends ITaskRequest {
|
|
33
|
+
readonly len: number;
|
|
34
|
+
readonly from: number;
|
|
35
|
+
readonly to: number;
|
|
36
|
+
readonly after?: string;
|
|
37
|
+
readonly before?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface IModuleCollectionRef {
|
|
40
|
+
readonly moduleID: string;
|
|
41
|
+
readonly collection: string;
|
|
42
|
+
}
|
|
43
|
+
export interface IRelatedRolesRequest {
|
|
44
|
+
readonly rolesOfItem?: string[];
|
|
45
|
+
readonly rolesToItem?: string[];
|
|
46
|
+
}
|
|
47
|
+
export interface IRelatedChange {
|
|
48
|
+
readonly add?: IRelatedRolesRequest;
|
|
49
|
+
readonly remove?: IRelatedRolesRequest;
|
|
50
|
+
}
|
|
51
|
+
export interface IRelatedItemChange extends IRelatedChange {
|
|
52
|
+
readonly itemRef: ISpaceModuleItemRef;
|
|
53
|
+
}
|
|
54
|
+
export interface IUpdateRelatedRequest extends ISpaceItemRequest, IModuleCollectionRef {
|
|
55
|
+
readonly related?: IRelatedItemChange[];
|
|
56
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Signal } from '@angular/core';
|
|
2
|
+
import { IIdAndBrief, IIdAndBriefWithSpaceRef, INavContext, ISpaceRef } from '@sneat/core';
|
|
3
|
+
import { IShortSpaceInfo, ISpaceBrief, ISpaceDbo } from '@sneat/dto';
|
|
4
|
+
export declare function zipMapBriefsWithIDs<Brief>(briefs?: Readonly<Record<string, Brief>>): readonly IIdAndBrief<Brief>[];
|
|
5
|
+
export declare function zipMapBriefsWithIDsAndSpaceRef<Brief>(space: ISpaceRef, briefs?: Readonly<Record<string, Brief>>): readonly IIdAndBriefWithSpaceRef<Brief>[];
|
|
6
|
+
export interface ISpaceContext extends ISpaceRef, INavContext<ISpaceBrief, ISpaceDbo> {
|
|
7
|
+
}
|
|
8
|
+
export declare function computeSpaceRefFromSpaceContext($space: Signal<ISpaceContext | undefined>): Signal<ISpaceRef>;
|
|
9
|
+
export declare function computeSpaceIdFromSpaceRef($spaceRef: () => ISpaceRef): Signal<string>;
|
|
10
|
+
export declare const spaceContextFromBrief: (id: string, brief: ISpaceBrief) => ISpaceContext;
|
|
11
|
+
export declare function createShortSpaceInfoFromDbo(space: ISpaceContext): IShortSpaceInfo;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IIdAndOptionalBriefAndOptionalDbo, IIdAndOptionalDbo, ISpaceRef } from '@sneat/core';
|
|
2
|
+
export interface ISpaceItemWithOptionalBriefAndOptionalDbo<Brief, Dbo extends Brief> extends IIdAndOptionalBriefAndOptionalDbo<Brief, Dbo> {
|
|
3
|
+
readonly space: ISpaceRef;
|
|
4
|
+
}
|
|
5
|
+
export interface ISpaceItemWithOptionalDbo<Dbo> extends IIdAndOptionalDbo<Dbo> {
|
|
6
|
+
readonly space: ISpaceRef;
|
|
7
|
+
}
|
|
8
|
+
export type ISpaceItemNavContext<Brief, Dbo extends Brief> = ISpaceItemWithOptionalBriefAndOptionalDbo<Brief, Dbo>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { SpaceType } from '@sneat/core';
|
|
2
|
+
import { DtoTotal, DtoTotals, Period } from '@sneat/dto';
|
|
3
|
+
import { ISpaceContext } from '../space-context';
|
|
4
|
+
export declare class Total {
|
|
5
|
+
readonly dto?: DtoTotal | undefined;
|
|
6
|
+
constructor(dto?: DtoTotal | undefined);
|
|
7
|
+
get count(): number;
|
|
8
|
+
per(period: Period): number;
|
|
9
|
+
perDay(): number;
|
|
10
|
+
perWeek(): number;
|
|
11
|
+
perMonth(): number;
|
|
12
|
+
perQuarter(): number;
|
|
13
|
+
perYear(): number;
|
|
14
|
+
}
|
|
15
|
+
export declare class Totals {
|
|
16
|
+
readonly incomes: Total;
|
|
17
|
+
readonly expenses: Total;
|
|
18
|
+
constructor(dtoTotals?: DtoTotals);
|
|
19
|
+
get count(): number;
|
|
20
|
+
isPositive(period: Period): boolean;
|
|
21
|
+
isNegative(period: Period): boolean;
|
|
22
|
+
per(period: Period, incomes?: boolean, expense?: boolean): number;
|
|
23
|
+
balance(per: 'month' | 'day'): number;
|
|
24
|
+
}
|
|
25
|
+
export declare class Commune implements ISpaceContext {
|
|
26
|
+
readonly space: ISpaceContext;
|
|
27
|
+
readonly shortId?: string | undefined;
|
|
28
|
+
readonly totals: Totals;
|
|
29
|
+
constructor(space: ISpaceContext, shortId?: string | undefined);
|
|
30
|
+
get id(): string;
|
|
31
|
+
get type(): SpaceType | undefined;
|
|
32
|
+
get title(): string | undefined;
|
|
33
|
+
private _membersCountByRole?;
|
|
34
|
+
get membersCountByRole(): {
|
|
35
|
+
role: string;
|
|
36
|
+
count: number;
|
|
37
|
+
}[];
|
|
38
|
+
supports(v: 'staff' | 'pupils'): boolean;
|
|
39
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sneat/space-models",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -10,5 +10,17 @@
|
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"tslib": "2.8.1"
|
|
13
|
-
}
|
|
13
|
+
},
|
|
14
|
+
"module": "esm2022/sneat-space-models.js",
|
|
15
|
+
"typings": "sneat-space-models.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
"./package.json": {
|
|
18
|
+
"default": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./sneat-space-models.d.ts",
|
|
22
|
+
"default": "./esm2022/sneat-space-models.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"sideEffects": false
|
|
14
26
|
}
|
package/eslint.config.js
DELETED
package/ng-package.json
DELETED
package/project.json
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "space-models",
|
|
3
|
-
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
-
"projectType": "library",
|
|
5
|
-
"sourceRoot": "libs/space/models/src",
|
|
6
|
-
"prefix": "sneat",
|
|
7
|
-
"targets": {
|
|
8
|
-
"build": {
|
|
9
|
-
"executor": "@nx/angular:ng-packagr-lite",
|
|
10
|
-
"outputs": [
|
|
11
|
-
"{workspaceRoot}/dist/libs/space/models"
|
|
12
|
-
],
|
|
13
|
-
"options": {
|
|
14
|
-
"project": "libs/space/models/ng-package.json",
|
|
15
|
-
"tsConfig": "libs/space/models/tsconfig.lib.json"
|
|
16
|
-
},
|
|
17
|
-
"configurations": {
|
|
18
|
-
"production": {
|
|
19
|
-
"tsConfig": "libs/space/models/tsconfig.lib.prod.json"
|
|
20
|
-
},
|
|
21
|
-
"development": {}
|
|
22
|
-
},
|
|
23
|
-
"defaultConfiguration": "production"
|
|
24
|
-
},
|
|
25
|
-
"test": {
|
|
26
|
-
"executor": "@nx/vitest:test",
|
|
27
|
-
"outputs": [
|
|
28
|
-
"{workspaceRoot}/coverage/libs/space/models"
|
|
29
|
-
],
|
|
30
|
-
"options": {
|
|
31
|
-
"tsConfig": "libs/space/models/tsconfig.spec.json"
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
"lint": {
|
|
35
|
-
"executor": "@nx/eslint:lint"
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
package/src/lib/invite-models.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const empty = {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const empty = {};
|
package/src/lib/models.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { SpaceType } from '@sneat/core';
|
|
2
|
-
import { ISpaceModuleItemRef } from '@sneat/dto';
|
|
3
|
-
|
|
4
|
-
export interface ISpaceRequest {
|
|
5
|
-
readonly spaceID: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface ISpaceItemRequest extends ISpaceRequest {
|
|
9
|
-
readonly id: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface ISpaceMemberRequest extends ISpaceRequest {
|
|
13
|
-
readonly memberID: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface ILeaveSpaceRequest extends ISpaceRequest {
|
|
17
|
-
readonly message?: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface IAcceptInviteResponse {
|
|
21
|
-
readonly id: string;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface IInviteSpace {
|
|
25
|
-
readonly id: string;
|
|
26
|
-
readonly type: SpaceType;
|
|
27
|
-
readonly title: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface IRejectPersonalInviteRequest extends ISpaceRequest {
|
|
31
|
-
readonly inviteID: string;
|
|
32
|
-
readonly pin: string;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export type SpaceMemberStatus = 'active' | 'archived';
|
|
36
|
-
|
|
37
|
-
export interface ITaskRequest extends ISpaceMemberRequest {
|
|
38
|
-
readonly type: string;
|
|
39
|
-
readonly task: string;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export interface IReorderTaskRequest extends ITaskRequest {
|
|
43
|
-
readonly len: number;
|
|
44
|
-
readonly from: number;
|
|
45
|
-
readonly to: number;
|
|
46
|
-
readonly after?: string;
|
|
47
|
-
readonly before?: string;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export interface IModuleCollectionRef {
|
|
51
|
-
readonly moduleID: string;
|
|
52
|
-
readonly collection: string;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export interface IRelatedRolesRequest {
|
|
56
|
-
readonly rolesOfItem?: string[];
|
|
57
|
-
readonly rolesToItem?: string[];
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export interface IRelatedChange {
|
|
61
|
-
readonly add?: IRelatedRolesRequest;
|
|
62
|
-
readonly remove?: IRelatedRolesRequest;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export interface IRelatedItemChange extends IRelatedChange {
|
|
66
|
-
readonly itemRef: ISpaceModuleItemRef;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export interface IUpdateRelatedRequest
|
|
70
|
-
extends ISpaceItemRequest, IModuleCollectionRef {
|
|
71
|
-
readonly related?: IRelatedItemChange[];
|
|
72
|
-
}
|
package/src/lib/sanity.spec.ts
DELETED
package/src/lib/space-context.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { computed, Signal } from '@angular/core';
|
|
2
|
-
import {
|
|
3
|
-
IIdAndBrief,
|
|
4
|
-
IIdAndBriefWithSpaceRef,
|
|
5
|
-
INavContext,
|
|
6
|
-
ISpaceRef,
|
|
7
|
-
} from '@sneat/core';
|
|
8
|
-
import { IShortSpaceInfo, ISpaceBrief, ISpaceDbo } from '@sneat/dto';
|
|
9
|
-
|
|
10
|
-
export function zipMapBriefsWithIDs<Brief>(
|
|
11
|
-
briefs?: Readonly<Record<string, Brief>>,
|
|
12
|
-
): readonly IIdAndBrief<Brief>[] {
|
|
13
|
-
return briefs
|
|
14
|
-
? Object.entries(briefs).map(([id, brief]) => ({ id, brief }))
|
|
15
|
-
: [];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function zipMapBriefsWithIDsAndSpaceRef<Brief>(
|
|
19
|
-
space: ISpaceRef,
|
|
20
|
-
briefs?: Readonly<Record<string, Brief>>,
|
|
21
|
-
): readonly IIdAndBriefWithSpaceRef<Brief>[] {
|
|
22
|
-
return briefs
|
|
23
|
-
? Object.entries(briefs).map(([id, brief]) => ({ id, brief, space }))
|
|
24
|
-
: [];
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface ISpaceContext
|
|
28
|
-
extends ISpaceRef, INavContext<ISpaceBrief, ISpaceDbo> {
|
|
29
|
-
// readonly type?: SpaceType;
|
|
30
|
-
// readonly assets?: IAssetContext[]; // TODO: this should not be here
|
|
31
|
-
// readonly contacts?: IContactContext[]; // TODO: this should not be here
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function computeSpaceRefFromSpaceContext(
|
|
35
|
-
$space: Signal<ISpaceContext | undefined>,
|
|
36
|
-
) {
|
|
37
|
-
return computed<ISpaceRef>(() => {
|
|
38
|
-
const space = $space();
|
|
39
|
-
return space?.type
|
|
40
|
-
? { type: space?.type, id: space.id }
|
|
41
|
-
: { id: space?.id || '' };
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function computeSpaceIdFromSpaceRef($spaceRef: () => ISpaceRef) {
|
|
46
|
-
return computed<string>(() => $spaceRef().id);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export const spaceContextFromBrief = (
|
|
50
|
-
id: string,
|
|
51
|
-
brief: ISpaceBrief,
|
|
52
|
-
): ISpaceContext => ({ id, type: brief.type, brief });
|
|
53
|
-
|
|
54
|
-
// export interface IContactContextWithBrief
|
|
55
|
-
// extends ITeamItemNavContext<IContactBrief, IContactDto> {
|
|
56
|
-
// brief: IContactBrief;
|
|
57
|
-
// parentContact?: IContactContext;
|
|
58
|
-
// }
|
|
59
|
-
|
|
60
|
-
export function createShortSpaceInfoFromDbo(
|
|
61
|
-
space: ISpaceContext,
|
|
62
|
-
): IShortSpaceInfo {
|
|
63
|
-
if (!space.type) {
|
|
64
|
-
throw new Error('!team.type');
|
|
65
|
-
}
|
|
66
|
-
return {
|
|
67
|
-
id: space.id,
|
|
68
|
-
type: space.type,
|
|
69
|
-
title: space?.dbo?.title || space.brief?.title,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
IIdAndOptionalBriefAndOptionalDbo,
|
|
3
|
-
IIdAndOptionalDbo,
|
|
4
|
-
ISpaceRef,
|
|
5
|
-
} from '@sneat/core';
|
|
6
|
-
|
|
7
|
-
export interface ISpaceItemWithOptionalBriefAndOptionalDbo<
|
|
8
|
-
Brief,
|
|
9
|
-
Dbo extends Brief,
|
|
10
|
-
> extends IIdAndOptionalBriefAndOptionalDbo<Brief, Dbo> {
|
|
11
|
-
readonly space: ISpaceRef;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface ISpaceItemWithOptionalDbo<Dbo> extends IIdAndOptionalDbo<Dbo> {
|
|
15
|
-
readonly space: ISpaceRef;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export type ISpaceItemNavContext<
|
|
19
|
-
Brief,
|
|
20
|
-
Dbo extends Brief,
|
|
21
|
-
> = ISpaceItemWithOptionalBriefAndOptionalDbo<Brief, Dbo>;
|
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
import { SpaceType } from '@sneat/core';
|
|
2
|
-
import { DtoTotal, DtoTotals, Period } from '@sneat/dto';
|
|
3
|
-
import { ISpaceContext } from '../space-context';
|
|
4
|
-
|
|
5
|
-
export class Total {
|
|
6
|
-
constructor(public readonly dto?: DtoTotal) {
|
|
7
|
-
if (!dto) {
|
|
8
|
-
this.dto = { count: 0 };
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
public get count(): number {
|
|
13
|
-
return this.dto ? this.dto.count : 0;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
public per(period: Period): number {
|
|
17
|
-
switch (period) {
|
|
18
|
-
case 'month':
|
|
19
|
-
return this.perMonth();
|
|
20
|
-
case 'year':
|
|
21
|
-
return this.perYear();
|
|
22
|
-
case 'quarter':
|
|
23
|
-
return this.perQuarter();
|
|
24
|
-
case 'week':
|
|
25
|
-
return this.perWeek();
|
|
26
|
-
case 'day':
|
|
27
|
-
return this.perDay();
|
|
28
|
-
default:
|
|
29
|
-
throw new Error(`unknown period: ${period}`);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
public perDay(): number {
|
|
34
|
-
if (!this.dto) {
|
|
35
|
-
return 0;
|
|
36
|
-
}
|
|
37
|
-
let result = 0;
|
|
38
|
-
if (this.dto.day !== undefined) {
|
|
39
|
-
result += this.dto.day;
|
|
40
|
-
}
|
|
41
|
-
if (this.dto.week !== undefined) {
|
|
42
|
-
result += Math.round(this.dto.week / 7);
|
|
43
|
-
}
|
|
44
|
-
if (this.dto.month !== undefined) {
|
|
45
|
-
result += Math.round(this.dto.month / 30);
|
|
46
|
-
}
|
|
47
|
-
if (this.dto.quarter !== undefined) {
|
|
48
|
-
result += Math.round(this.dto.quarter / 61);
|
|
49
|
-
}
|
|
50
|
-
if (this.dto.year !== undefined) {
|
|
51
|
-
result += Math.round(this.dto.year / 365);
|
|
52
|
-
}
|
|
53
|
-
return result;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
public perWeek(): number {
|
|
57
|
-
if (!this.dto) {
|
|
58
|
-
return 0;
|
|
59
|
-
}
|
|
60
|
-
let result = 0;
|
|
61
|
-
if (this.dto.week !== undefined) {
|
|
62
|
-
result += this.dto.week;
|
|
63
|
-
}
|
|
64
|
-
if (this.dto.month !== undefined) {
|
|
65
|
-
result += Math.round(this.dto.month / 4.33);
|
|
66
|
-
}
|
|
67
|
-
if (this.dto.day !== undefined) {
|
|
68
|
-
result += this.dto.day * 7;
|
|
69
|
-
}
|
|
70
|
-
if (this.dto.quarter !== undefined) {
|
|
71
|
-
result += Math.round(this.dto.quarter / 13);
|
|
72
|
-
}
|
|
73
|
-
if (this.dto.year !== undefined) {
|
|
74
|
-
result += Math.round(this.dto.year / 52);
|
|
75
|
-
}
|
|
76
|
-
return result;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
public perMonth(): number {
|
|
80
|
-
if (!this.dto) {
|
|
81
|
-
return 0;
|
|
82
|
-
}
|
|
83
|
-
let result = 0;
|
|
84
|
-
if (this.dto.month !== undefined) {
|
|
85
|
-
result += this.dto.month;
|
|
86
|
-
}
|
|
87
|
-
if (this.dto.day !== undefined) {
|
|
88
|
-
result += this.dto.day * 30;
|
|
89
|
-
}
|
|
90
|
-
if (this.dto.week !== undefined) {
|
|
91
|
-
result += this.dto.week * 4.33;
|
|
92
|
-
}
|
|
93
|
-
if (this.dto.year !== undefined) {
|
|
94
|
-
result += Math.round(this.dto.year / 12);
|
|
95
|
-
}
|
|
96
|
-
if (this.dto.quarter !== undefined) {
|
|
97
|
-
result += Math.round(this.dto.quarter / 3);
|
|
98
|
-
}
|
|
99
|
-
return result;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
public perQuarter(): number {
|
|
103
|
-
if (!this.dto) {
|
|
104
|
-
return 0;
|
|
105
|
-
}
|
|
106
|
-
let result = 0;
|
|
107
|
-
if (this.dto.quarter !== undefined) {
|
|
108
|
-
result += this.dto.quarter;
|
|
109
|
-
}
|
|
110
|
-
if (this.dto.day !== undefined) {
|
|
111
|
-
result += this.dto.day * 61;
|
|
112
|
-
}
|
|
113
|
-
if (this.dto.week !== undefined) {
|
|
114
|
-
result += this.dto.week * 13;
|
|
115
|
-
}
|
|
116
|
-
if (this.dto.month !== undefined) {
|
|
117
|
-
result += this.dto.month * 3;
|
|
118
|
-
}
|
|
119
|
-
if (this.dto.year !== undefined) {
|
|
120
|
-
result += Math.round(this.dto.year / 4);
|
|
121
|
-
}
|
|
122
|
-
return result;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
public perYear(): number {
|
|
126
|
-
if (!this.dto) {
|
|
127
|
-
return 0;
|
|
128
|
-
}
|
|
129
|
-
let result = 0;
|
|
130
|
-
if (this.dto.year !== undefined) {
|
|
131
|
-
result += this.dto.year;
|
|
132
|
-
}
|
|
133
|
-
if (this.dto.day !== undefined) {
|
|
134
|
-
result += this.dto.day * 365;
|
|
135
|
-
}
|
|
136
|
-
if (this.dto.week !== undefined) {
|
|
137
|
-
result += this.dto.week * 52;
|
|
138
|
-
}
|
|
139
|
-
if (this.dto.month !== undefined) {
|
|
140
|
-
result += this.dto.month * 12;
|
|
141
|
-
}
|
|
142
|
-
if (this.dto.quarter !== undefined) {
|
|
143
|
-
result += this.dto.quarter * 4;
|
|
144
|
-
}
|
|
145
|
-
return result;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export class Totals {
|
|
150
|
-
readonly incomes: Total;
|
|
151
|
-
readonly expenses: Total;
|
|
152
|
-
|
|
153
|
-
constructor(dtoTotals?: DtoTotals) {
|
|
154
|
-
this.incomes = new Total(dtoTotals ? dtoTotals.incomes : undefined);
|
|
155
|
-
this.expenses = new Total(dtoTotals ? dtoTotals.expenses : undefined);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
get count(): number {
|
|
159
|
-
return this.incomes.count + this.expenses.count;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
isPositive(period: Period): boolean {
|
|
163
|
-
return this.per(period, true, true) > 0;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
isNegative(period: Period): boolean {
|
|
167
|
-
return this.per(period, true, true) < 0;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
per(period: Period, incomes = true, expense = true): number {
|
|
171
|
-
if (incomes && expense) {
|
|
172
|
-
return this.incomes.per(period) - this.expenses.per(period);
|
|
173
|
-
}
|
|
174
|
-
if (incomes) {
|
|
175
|
-
return this.incomes.per(period);
|
|
176
|
-
}
|
|
177
|
-
if (expense) {
|
|
178
|
-
return -this.expenses.per(period);
|
|
179
|
-
}
|
|
180
|
-
return 0;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
balance(per: 'month' | 'day'): number {
|
|
184
|
-
switch (per) {
|
|
185
|
-
case 'month':
|
|
186
|
-
return (
|
|
187
|
-
Math.round(
|
|
188
|
-
(this.incomes.perMonth() - this.expenses.perMonth()) * 100,
|
|
189
|
-
) / 100
|
|
190
|
-
);
|
|
191
|
-
case 'day':
|
|
192
|
-
return (
|
|
193
|
-
Math.round((this.incomes.perDay() - this.expenses.perDay()) * 100) /
|
|
194
|
-
100
|
|
195
|
-
);
|
|
196
|
-
default:
|
|
197
|
-
throw new Error(`Unknown parameter value: ${per}`);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
export class Commune implements ISpaceContext {
|
|
203
|
-
public readonly totals: Totals;
|
|
204
|
-
|
|
205
|
-
constructor(
|
|
206
|
-
public readonly space: ISpaceContext,
|
|
207
|
-
public readonly shortId?: string,
|
|
208
|
-
) {
|
|
209
|
-
this.totals = new Totals(space.dbo?.totals);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
public get id(): string {
|
|
213
|
-
return this.space.id;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
public get type(): SpaceType | undefined {
|
|
217
|
-
return this.space.dbo?.type;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
public get title(): string | undefined {
|
|
221
|
-
return this.space.dbo?.title;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// public get isSupportingMemberGroups(): boolean {
|
|
225
|
-
// const t = this.team.type;
|
|
226
|
-
// return t === 'educator' || t === 'sport_club' || t === 'cohabit';
|
|
227
|
-
// }
|
|
228
|
-
|
|
229
|
-
// public get numberOf(): TeamCounts {
|
|
230
|
-
// if (this.team.dto?.numberOf) {
|
|
231
|
-
// return this.team.dto.numberOf;
|
|
232
|
-
// }
|
|
233
|
-
// return newTeamCounts(this.team.dto?.numberOf);
|
|
234
|
-
// }
|
|
235
|
-
|
|
236
|
-
private _membersCountByRole?: { role: string; count: number }[];
|
|
237
|
-
|
|
238
|
-
public get membersCountByRole(): { role: string; count: number }[] {
|
|
239
|
-
throw new Error('Not implemented yet - disabled');
|
|
240
|
-
// if (!this._membersCountByRole) {
|
|
241
|
-
// const byRole = this.numberOf.membersByRole;
|
|
242
|
-
// if (!byRole) {
|
|
243
|
-
// return [];
|
|
244
|
-
// }
|
|
245
|
-
// this._membersCountByRole = Object.entries(byRole)
|
|
246
|
-
// .map(item => ({ role: item[0], count: item[1] as number }));
|
|
247
|
-
// }
|
|
248
|
-
// return this._membersCountByRole;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
public supports(v: 'staff' | 'pupils'): boolean {
|
|
252
|
-
if (!v) {
|
|
253
|
-
return false;
|
|
254
|
-
}
|
|
255
|
-
switch (v) {
|
|
256
|
-
case 'staff':
|
|
257
|
-
return this.type === 'educator' || this.type === 'realtor';
|
|
258
|
-
case 'pupils':
|
|
259
|
-
return this.type === 'educator';
|
|
260
|
-
default:
|
|
261
|
-
break;
|
|
262
|
-
}
|
|
263
|
-
return false;
|
|
264
|
-
}
|
|
265
|
-
}
|
package/src/test-setup.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import '@sneat/core/testing-light';
|
package/tsconfig.json
DELETED
package/tsconfig.lib.json
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../../tsconfig.lib.base.json",
|
|
3
|
-
"exclude": [
|
|
4
|
-
"vite.config.ts",
|
|
5
|
-
"vite.config.mts",
|
|
6
|
-
"vitest.config.ts",
|
|
7
|
-
"vitest.config.mts",
|
|
8
|
-
"src/**/*.test.ts",
|
|
9
|
-
"src/**/*.spec.ts",
|
|
10
|
-
"src/**/*.test.tsx",
|
|
11
|
-
"src/**/*.spec.tsx",
|
|
12
|
-
"src/**/*.test.js",
|
|
13
|
-
"src/**/*.spec.js",
|
|
14
|
-
"src/**/*.test.jsx",
|
|
15
|
-
"src/**/*.spec.jsx",
|
|
16
|
-
"src/test-setup.ts",
|
|
17
|
-
"src/lib/testing/**/*"
|
|
18
|
-
]
|
|
19
|
-
}
|
package/tsconfig.lib.prod.json
DELETED
package/tsconfig.spec.json
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "../../../dist/out-tsc",
|
|
5
|
-
"types": [
|
|
6
|
-
"vitest/globals",
|
|
7
|
-
"vitest/importMeta",
|
|
8
|
-
"vite/client",
|
|
9
|
-
"node",
|
|
10
|
-
"vitest"
|
|
11
|
-
]
|
|
12
|
-
},
|
|
13
|
-
"include": [
|
|
14
|
-
"vite.config.ts",
|
|
15
|
-
"vite.config.mts",
|
|
16
|
-
"vitest.config.ts",
|
|
17
|
-
"vitest.config.mts",
|
|
18
|
-
"src/**/*.test.ts",
|
|
19
|
-
"src/**/*.spec.ts",
|
|
20
|
-
"src/**/*.test.tsx",
|
|
21
|
-
"src/**/*.spec.tsx",
|
|
22
|
-
"src/**/*.test.js",
|
|
23
|
-
"src/**/*.spec.js",
|
|
24
|
-
"src/**/*.test.jsx",
|
|
25
|
-
"src/**/*.spec.jsx",
|
|
26
|
-
"src/**/*.d.ts"
|
|
27
|
-
],
|
|
28
|
-
"files": [
|
|
29
|
-
"src/test-setup.ts"
|
|
30
|
-
]
|
|
31
|
-
}
|
package/vite.config.mts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/// <reference types='vitest' />
|
|
2
|
-
import { defineConfig } from 'vitest/config';
|
|
3
|
-
import { createBaseViteConfig } from '../../../vite.config.base';
|
|
4
|
-
|
|
5
|
-
export default defineConfig(() =>
|
|
6
|
-
createBaseViteConfig({
|
|
7
|
-
dirname: __dirname,
|
|
8
|
-
name: 'space-models',
|
|
9
|
-
}),
|
|
10
|
-
);
|
|
File without changes
|
|
File without changes
|
|
File without changes
|