@myrmidon/cadmus-state 0.0.9 → 0.3.0

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.
Files changed (78) hide show
  1. package/README.md +24 -24
  2. package/esm2020/lib/app.query.mjs +29 -0
  3. package/esm2020/lib/app.service.mjs +43 -0
  4. package/esm2020/lib/app.store.mjs +24 -0
  5. package/esm2020/lib/cadmus-state.module.mjs +38 -0
  6. package/esm2020/lib/edit-fragment-feature-base.mjs +118 -0
  7. package/esm2020/lib/edit-fragment-query-base.mjs +32 -0
  8. package/esm2020/lib/edit-fragment-service-base.mjs +140 -0
  9. package/esm2020/lib/edit-fragment.store.mjs +36 -0
  10. package/esm2020/lib/edit-item.query.mjs +52 -0
  11. package/esm2020/lib/edit-item.service.mjs +182 -0
  12. package/esm2020/lib/edit-item.store.mjs +40 -0
  13. package/esm2020/lib/edit-layer-part.query.mjs +35 -0
  14. package/esm2020/lib/edit-layer-part.service.mjs +230 -0
  15. package/esm2020/lib/edit-layer-part.store.mjs +49 -0
  16. package/esm2020/lib/edit-part-feature-base.mjs +116 -0
  17. package/esm2020/lib/edit-part-query-base.mjs +25 -0
  18. package/esm2020/lib/edit-part-service-base.mjs +120 -0
  19. package/esm2020/lib/edit-part.store.mjs +31 -0
  20. package/esm2020/lib/edit-thesaurus.query.mjs +26 -0
  21. package/esm2020/lib/edit-thesaurus.service.mjs +59 -0
  22. package/esm2020/lib/edit-thesaurus.store.mjs +30 -0
  23. package/{esm2015/myrmidon-cadmus-state.js → esm2020/myrmidon-cadmus-state.mjs} +1 -1
  24. package/{esm2015/public-api.js → esm2020/public-api.mjs} +1 -1
  25. package/fesm2015/myrmidon-cadmus-state.mjs +1408 -0
  26. package/fesm2015/myrmidon-cadmus-state.mjs.map +1 -0
  27. package/{fesm2015/myrmidon-cadmus-state.js → fesm2020/myrmidon-cadmus-state.mjs} +189 -207
  28. package/fesm2020/myrmidon-cadmus-state.mjs.map +1 -0
  29. package/lib/app.query.d.ts +7 -4
  30. package/lib/app.service.d.ts +4 -1
  31. package/lib/app.store.d.ts +5 -2
  32. package/lib/cadmus-state.module.d.ts +9 -0
  33. package/lib/edit-fragment-feature-base.d.ts +7 -7
  34. package/lib/edit-fragment-query-base.d.ts +5 -5
  35. package/lib/edit-fragment-service-base.d.ts +1 -1
  36. package/lib/edit-fragment.store.d.ts +5 -2
  37. package/lib/edit-item.query.d.ts +9 -6
  38. package/lib/edit-item.service.d.ts +5 -2
  39. package/lib/edit-item.store.d.ts +8 -5
  40. package/lib/edit-layer-part.query.d.ts +9 -6
  41. package/lib/edit-layer-part.service.d.ts +5 -2
  42. package/lib/edit-layer-part.store.d.ts +6 -3
  43. package/lib/edit-part-feature-base.d.ts +9 -9
  44. package/lib/edit-part-query-base.d.ts +4 -4
  45. package/lib/edit-part-service-base.d.ts +3 -3
  46. package/lib/edit-part.store.d.ts +5 -3
  47. package/lib/edit-thesaurus.query.d.ts +5 -3
  48. package/lib/edit-thesaurus.service.d.ts +5 -2
  49. package/lib/edit-thesaurus.store.d.ts +4 -1
  50. package/myrmidon-cadmus-state.d.ts +1 -0
  51. package/package.json +25 -13
  52. package/bundles/myrmidon-cadmus-state.umd.js +0 -1812
  53. package/bundles/myrmidon-cadmus-state.umd.js.map +0 -1
  54. package/bundles/myrmidon-cadmus-state.umd.min.js +0 -16
  55. package/bundles/myrmidon-cadmus-state.umd.min.js.map +0 -1
  56. package/esm2015/lib/app.query.js +0 -31
  57. package/esm2015/lib/app.service.js +0 -49
  58. package/esm2015/lib/app.store.js +0 -25
  59. package/esm2015/lib/cadmus-state.module.js +0 -19
  60. package/esm2015/lib/edit-fragment-feature-base.js +0 -116
  61. package/esm2015/lib/edit-fragment-query-base.js +0 -32
  62. package/esm2015/lib/edit-fragment-service-base.js +0 -137
  63. package/esm2015/lib/edit-fragment.store.js +0 -38
  64. package/esm2015/lib/edit-item.query.js +0 -56
  65. package/esm2015/lib/edit-item.service.js +0 -188
  66. package/esm2015/lib/edit-item.store.js +0 -46
  67. package/esm2015/lib/edit-layer-part.query.js +0 -37
  68. package/esm2015/lib/edit-layer-part.service.js +0 -235
  69. package/esm2015/lib/edit-layer-part.store.js +0 -52
  70. package/esm2015/lib/edit-part-feature-base.js +0 -116
  71. package/esm2015/lib/edit-part-query-base.js +0 -25
  72. package/esm2015/lib/edit-part-service-base.js +0 -121
  73. package/esm2015/lib/edit-part.store.js +0 -38
  74. package/esm2015/lib/edit-thesaurus.query.js +0 -28
  75. package/esm2015/lib/edit-thesaurus.service.js +0 -63
  76. package/esm2015/lib/edit-thesaurus.store.js +0 -36
  77. package/fesm2015/myrmidon-cadmus-state.js.map +0 -1
  78. package/myrmidon-cadmus-state.metadata.json +0 -1
@@ -1,1812 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@datorama/akita'), require('@myrmidon/cadmus-api'), require('rxjs'), require('@myrmidon/cadmus-core'), require('@angular/common'), require('@myrmidon/cadmus-material')) :
3
- typeof define === 'function' && define.amd ? define('@myrmidon/cadmus-state', ['exports', '@angular/core', '@datorama/akita', '@myrmidon/cadmus-api', 'rxjs', '@myrmidon/cadmus-core', '@angular/common', '@myrmidon/cadmus-material'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.myrmidon = global.myrmidon || {}, global.myrmidon['cadmus-state'] = {}), global.ng.core, global['@datorama/akita'], global['@myrmidon/cadmus-api'], global.rxjs, global['@myrmidon/cadmus-core'], global.ng.common, global['@myrmidon/cadmus-material']));
5
- }(this, (function (exports, i0, akita, i2, rxjs, i2$1, common, cadmusMaterial) { 'use strict';
6
-
7
- /*! *****************************************************************************
8
- Copyright (c) Microsoft Corporation.
9
-
10
- Permission to use, copy, modify, and/or distribute this software for any
11
- purpose with or without fee is hereby granted.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
- PERFORMANCE OF THIS SOFTWARE.
20
- ***************************************************************************** */
21
- /* global Reflect, Promise */
22
- var extendStatics = function (d, b) {
23
- extendStatics = Object.setPrototypeOf ||
24
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
25
- function (d, b) { for (var p in b)
26
- if (Object.prototype.hasOwnProperty.call(b, p))
27
- d[p] = b[p]; };
28
- return extendStatics(d, b);
29
- };
30
- function __extends(d, b) {
31
- extendStatics(d, b);
32
- function __() { this.constructor = d; }
33
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
34
- }
35
- var __assign = function () {
36
- __assign = Object.assign || function __assign(t) {
37
- for (var s, i = 1, n = arguments.length; i < n; i++) {
38
- s = arguments[i];
39
- for (var p in s)
40
- if (Object.prototype.hasOwnProperty.call(s, p))
41
- t[p] = s[p];
42
- }
43
- return t;
44
- };
45
- return __assign.apply(this, arguments);
46
- };
47
- function __rest(s, e) {
48
- var t = {};
49
- for (var p in s)
50
- if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
51
- t[p] = s[p];
52
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
53
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
54
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
55
- t[p[i]] = s[p[i]];
56
- }
57
- return t;
58
- }
59
- function __decorate(decorators, target, key, desc) {
60
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
61
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
62
- r = Reflect.decorate(decorators, target, key, desc);
63
- else
64
- for (var i = decorators.length - 1; i >= 0; i--)
65
- if (d = decorators[i])
66
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
67
- return c > 3 && r && Object.defineProperty(target, key, r), r;
68
- }
69
- function __param(paramIndex, decorator) {
70
- return function (target, key) { decorator(target, key, paramIndex); };
71
- }
72
- function __metadata(metadataKey, metadataValue) {
73
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
74
- return Reflect.metadata(metadataKey, metadataValue);
75
- }
76
- function __awaiter(thisArg, _arguments, P, generator) {
77
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
78
- return new (P || (P = Promise))(function (resolve, reject) {
79
- function fulfilled(value) { try {
80
- step(generator.next(value));
81
- }
82
- catch (e) {
83
- reject(e);
84
- } }
85
- function rejected(value) { try {
86
- step(generator["throw"](value));
87
- }
88
- catch (e) {
89
- reject(e);
90
- } }
91
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
92
- step((generator = generator.apply(thisArg, _arguments || [])).next());
93
- });
94
- }
95
- function __generator(thisArg, body) {
96
- var _ = { label: 0, sent: function () { if (t[0] & 1)
97
- throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
98
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
99
- function verb(n) { return function (v) { return step([n, v]); }; }
100
- function step(op) {
101
- if (f)
102
- throw new TypeError("Generator is already executing.");
103
- while (_)
104
- try {
105
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
106
- return t;
107
- if (y = 0, t)
108
- op = [op[0] & 2, t.value];
109
- switch (op[0]) {
110
- case 0:
111
- case 1:
112
- t = op;
113
- break;
114
- case 4:
115
- _.label++;
116
- return { value: op[1], done: false };
117
- case 5:
118
- _.label++;
119
- y = op[1];
120
- op = [0];
121
- continue;
122
- case 7:
123
- op = _.ops.pop();
124
- _.trys.pop();
125
- continue;
126
- default:
127
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
128
- _ = 0;
129
- continue;
130
- }
131
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
132
- _.label = op[1];
133
- break;
134
- }
135
- if (op[0] === 6 && _.label < t[1]) {
136
- _.label = t[1];
137
- t = op;
138
- break;
139
- }
140
- if (t && _.label < t[2]) {
141
- _.label = t[2];
142
- _.ops.push(op);
143
- break;
144
- }
145
- if (t[2])
146
- _.ops.pop();
147
- _.trys.pop();
148
- continue;
149
- }
150
- op = body.call(thisArg, _);
151
- }
152
- catch (e) {
153
- op = [6, e];
154
- y = 0;
155
- }
156
- finally {
157
- f = t = 0;
158
- }
159
- if (op[0] & 5)
160
- throw op[1];
161
- return { value: op[0] ? op[1] : void 0, done: true };
162
- }
163
- }
164
- var __createBinding = Object.create ? (function (o, m, k, k2) {
165
- if (k2 === undefined)
166
- k2 = k;
167
- Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
168
- }) : (function (o, m, k, k2) {
169
- if (k2 === undefined)
170
- k2 = k;
171
- o[k2] = m[k];
172
- });
173
- function __exportStar(m, o) {
174
- for (var p in m)
175
- if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
176
- __createBinding(o, m, p);
177
- }
178
- function __values(o) {
179
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
180
- if (m)
181
- return m.call(o);
182
- if (o && typeof o.length === "number")
183
- return {
184
- next: function () {
185
- if (o && i >= o.length)
186
- o = void 0;
187
- return { value: o && o[i++], done: !o };
188
- }
189
- };
190
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
191
- }
192
- function __read(o, n) {
193
- var m = typeof Symbol === "function" && o[Symbol.iterator];
194
- if (!m)
195
- return o;
196
- var i = m.call(o), r, ar = [], e;
197
- try {
198
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
199
- ar.push(r.value);
200
- }
201
- catch (error) {
202
- e = { error: error };
203
- }
204
- finally {
205
- try {
206
- if (r && !r.done && (m = i["return"]))
207
- m.call(i);
208
- }
209
- finally {
210
- if (e)
211
- throw e.error;
212
- }
213
- }
214
- return ar;
215
- }
216
- function __spread() {
217
- for (var ar = [], i = 0; i < arguments.length; i++)
218
- ar = ar.concat(__read(arguments[i]));
219
- return ar;
220
- }
221
- function __spreadArrays() {
222
- for (var s = 0, i = 0, il = arguments.length; i < il; i++)
223
- s += arguments[i].length;
224
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
225
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
226
- r[k] = a[j];
227
- return r;
228
- }
229
- ;
230
- function __await(v) {
231
- return this instanceof __await ? (this.v = v, this) : new __await(v);
232
- }
233
- function __asyncGenerator(thisArg, _arguments, generator) {
234
- if (!Symbol.asyncIterator)
235
- throw new TypeError("Symbol.asyncIterator is not defined.");
236
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
237
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
238
- function verb(n) { if (g[n])
239
- i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
240
- function resume(n, v) { try {
241
- step(g[n](v));
242
- }
243
- catch (e) {
244
- settle(q[0][3], e);
245
- } }
246
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
247
- function fulfill(value) { resume("next", value); }
248
- function reject(value) { resume("throw", value); }
249
- function settle(f, v) { if (f(v), q.shift(), q.length)
250
- resume(q[0][0], q[0][1]); }
251
- }
252
- function __asyncDelegator(o) {
253
- var i, p;
254
- return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
255
- function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
256
- }
257
- function __asyncValues(o) {
258
- if (!Symbol.asyncIterator)
259
- throw new TypeError("Symbol.asyncIterator is not defined.");
260
- var m = o[Symbol.asyncIterator], i;
261
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
262
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
263
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
264
- }
265
- function __makeTemplateObject(cooked, raw) {
266
- if (Object.defineProperty) {
267
- Object.defineProperty(cooked, "raw", { value: raw });
268
- }
269
- else {
270
- cooked.raw = raw;
271
- }
272
- return cooked;
273
- }
274
- ;
275
- var __setModuleDefault = Object.create ? (function (o, v) {
276
- Object.defineProperty(o, "default", { enumerable: true, value: v });
277
- }) : function (o, v) {
278
- o["default"] = v;
279
- };
280
- function __importStar(mod) {
281
- if (mod && mod.__esModule)
282
- return mod;
283
- var result = {};
284
- if (mod != null)
285
- for (var k in mod)
286
- if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
287
- __createBinding(result, mod, k);
288
- __setModuleDefault(result, mod);
289
- return result;
290
- }
291
- function __importDefault(mod) {
292
- return (mod && mod.__esModule) ? mod : { default: mod };
293
- }
294
- function __classPrivateFieldGet(receiver, privateMap) {
295
- if (!privateMap.has(receiver)) {
296
- throw new TypeError("attempted to get private field on non-instance");
297
- }
298
- return privateMap.get(receiver);
299
- }
300
- function __classPrivateFieldSet(receiver, privateMap, value) {
301
- if (!privateMap.has(receiver)) {
302
- throw new TypeError("attempted to set private field on non-instance");
303
- }
304
- privateMap.set(receiver, value);
305
- return value;
306
- }
307
-
308
- var initialState = {
309
- facets: [],
310
- flags: [],
311
- typeThesaurus: null,
312
- itemBrowserThesaurus: null,
313
- };
314
- exports.AppStore = /** @class */ (function (_super) {
315
- __extends(AppStore, _super);
316
- function AppStore() {
317
- return _super.call(this, initialState) || this;
318
- }
319
- return AppStore;
320
- }(akita.Store));
321
- exports.AppStore.ɵprov = i0.ɵɵdefineInjectable({ factory: function AppStore_Factory() { return new exports.AppStore(); }, token: exports.AppStore, providedIn: "root" });
322
- exports.AppStore.decorators = [
323
- { type: i0.Injectable, args: [{ providedIn: 'root' },] }
324
- ];
325
- exports.AppStore.ctorParameters = function () { return []; };
326
- exports.AppStore = __decorate([
327
- akita.StoreConfig({ name: 'app', resettable: false })
328
- ], exports.AppStore);
329
-
330
- var AppQuery = /** @class */ (function (_super) {
331
- __extends(AppQuery, _super);
332
- function AppQuery(store) {
333
- var _this = _super.call(this, store) || this;
334
- _this.store = store;
335
- return _this;
336
- }
337
- AppQuery.prototype.selectFacets = function () {
338
- return this.select(function (state) { return state.facets; });
339
- };
340
- AppQuery.prototype.selectFlags = function () {
341
- return this.select(function (state) { return state.flags; });
342
- };
343
- AppQuery.prototype.selectTypeThesaurus = function () {
344
- return this.select(function (state) { return state.typeThesaurus; });
345
- };
346
- AppQuery.prototype.selectItemBrowserThesaurus = function () {
347
- return this.select(function (state) { return state.itemBrowserThesaurus; });
348
- };
349
- return AppQuery;
350
- }(akita.Query));
351
- AppQuery.ɵprov = i0.ɵɵdefineInjectable({ factory: function AppQuery_Factory() { return new AppQuery(i0.ɵɵinject(exports.AppStore)); }, token: AppQuery, providedIn: "root" });
352
- AppQuery.decorators = [
353
- { type: i0.Injectable, args: [{ providedIn: 'root' },] }
354
- ];
355
- AppQuery.ctorParameters = function () { return [
356
- { type: exports.AppStore }
357
- ]; };
358
-
359
- var AppService = /** @class */ (function () {
360
- function AppService(_store, _facetService, _flagService, _thesaurusService) {
361
- this._store = _store;
362
- this._facetService = _facetService;
363
- this._flagService = _flagService;
364
- this._thesaurusService = _thesaurusService;
365
- }
366
- AppService.prototype.load = function () {
367
- var _this = this;
368
- this._store.setLoading(true);
369
- var facets$ = this._facetService.getFacets();
370
- var flags$ = this._flagService.getFlags();
371
- var thesauri$ = this._thesaurusService.getThesauriSet([
372
- 'model-types@en',
373
- 'item-browsers@en',
374
- ]);
375
- rxjs.forkJoin([facets$, flags$, thesauri$]).subscribe(function (_a) {
376
- var _b = __read(_a, 3), facets = _b[0], flags = _b[1], thesauri = _b[2];
377
- _this._store.setLoading(false);
378
- _this._store.setError(null);
379
- _this._store.update({
380
- facets: facets,
381
- flags: flags,
382
- typeThesaurus: thesauri['model-types'],
383
- itemBrowserThesaurus: thesauri['item-browsers'],
384
- });
385
- }, function (error) {
386
- console.error(error);
387
- _this._store.setLoading(false);
388
- _this._store.setError('Error loading app state');
389
- });
390
- };
391
- return AppService;
392
- }());
393
- AppService.ɵprov = i0.ɵɵdefineInjectable({ factory: function AppService_Factory() { return new AppService(i0.ɵɵinject(exports.AppStore), i0.ɵɵinject(i2.FacetService), i0.ɵɵinject(i2.FlagService), i0.ɵɵinject(i2.ThesaurusService)); }, token: AppService, providedIn: "root" });
394
- AppService.decorators = [
395
- { type: i0.Injectable, args: [{ providedIn: 'root' },] }
396
- ];
397
- AppService.ctorParameters = function () { return [
398
- { type: exports.AppStore },
399
- { type: i2.FacetService },
400
- { type: i2.FlagService },
401
- { type: i2.ThesaurusService }
402
- ]; };
403
-
404
- var initialState$1 = {
405
- item: null,
406
- parts: [],
407
- partGroups: [],
408
- layerPartInfos: [],
409
- facet: null,
410
- dirty: false,
411
- saving: false,
412
- deletingPart: false,
413
- loading: false,
414
- error: null
415
- };
416
- exports.EditItemStore = /** @class */ (function (_super) {
417
- __extends(EditItemStore, _super);
418
- function EditItemStore() {
419
- return _super.call(this, initialState$1) || this;
420
- }
421
- EditItemStore.prototype.setDirty = function (value) {
422
- if (value === void 0) { value = true; }
423
- this.update({
424
- dirty: value
425
- });
426
- };
427
- EditItemStore.prototype.setSaving = function (value) {
428
- if (value === void 0) { value = true; }
429
- this.update({
430
- saving: value
431
- });
432
- };
433
- EditItemStore.prototype.setDeletingPart = function (value) {
434
- if (value === void 0) { value = true; }
435
- this.update({
436
- deletingPart: value
437
- });
438
- };
439
- return EditItemStore;
440
- }(akita.Store));
441
- exports.EditItemStore.ɵprov = i0.ɵɵdefineInjectable({ factory: function EditItemStore_Factory() { return new exports.EditItemStore(); }, token: exports.EditItemStore, providedIn: "root" });
442
- exports.EditItemStore.decorators = [
443
- { type: i0.Injectable, args: [{ providedIn: 'root' },] }
444
- ];
445
- exports.EditItemStore.ctorParameters = function () { return []; };
446
- exports.EditItemStore = __decorate([
447
- akita.StoreConfig({ name: 'edit-item', resettable: true })
448
- ], exports.EditItemStore);
449
-
450
- /**
451
- * The query facade to the edit item store.
452
- */
453
- var EditItemQuery = /** @class */ (function (_super) {
454
- __extends(EditItemQuery, _super);
455
- function EditItemQuery(store, _libraryRouteService) {
456
- var _this = _super.call(this, store) || this;
457
- _this.store = store;
458
- _this._libraryRouteService = _libraryRouteService;
459
- return _this;
460
- }
461
- EditItemQuery.prototype.selectItem = function () {
462
- return this.select(function (state) { return state.item; });
463
- };
464
- EditItemQuery.prototype.selectParts = function () {
465
- return this.select(function (state) { return state.parts; });
466
- };
467
- EditItemQuery.prototype.selectFacet = function () {
468
- return this.select(function (state) { return state.facet; });
469
- };
470
- EditItemQuery.prototype.selectSaving = function () {
471
- return this.select(function (state) { return state.saving; });
472
- };
473
- EditItemQuery.prototype.selectDeletingPart = function () {
474
- return this.select(function (state) { return state.deletingPart; });
475
- };
476
- EditItemQuery.prototype.hasItem = function (id) {
477
- if (id === void 0) { id = null; }
478
- var item = this.getValue().item;
479
- if (!item || (id && id !== item.id)) {
480
- return false;
481
- }
482
- return true;
483
- };
484
- EditItemQuery.prototype.getEditorKeyFromPartTypeId = function (typeId, roleId) {
485
- if (roleId === void 0) { roleId = null; }
486
- var facet = this.getValue().facet;
487
- if (!facet) {
488
- return 'default';
489
- }
490
- return this._libraryRouteService.getEditorKeyFromPartType(typeId, roleId)
491
- .partKey;
492
- };
493
- return EditItemQuery;
494
- }(akita.Query));
495
- EditItemQuery.ɵprov = i0.ɵɵdefineInjectable({ factory: function EditItemQuery_Factory() { return new EditItemQuery(i0.ɵɵinject(exports.EditItemStore), i0.ɵɵinject(i2$1.LibraryRouteService)); }, token: EditItemQuery, providedIn: "root" });
496
- EditItemQuery.decorators = [
497
- { type: i0.Injectable, args: [{ providedIn: 'root' },] }
498
- ];
499
- EditItemQuery.ctorParameters = function () { return [
500
- { type: exports.EditItemStore },
501
- { type: i2$1.LibraryRouteService }
502
- ]; };
503
-
504
- /**
505
- * The service which handles the edit item store.
506
- */
507
- var EditItemService = /** @class */ (function () {
508
- function EditItemService(_store, _appQuery, _itemService) {
509
- this._store = _store;
510
- this._appQuery = _appQuery;
511
- this._itemService = _itemService;
512
- }
513
- EditItemService.prototype.pickDefaultFacet = function (facets) {
514
- if (!facets.length) {
515
- return null;
516
- }
517
- // if there is a facet with id="default", pick it
518
- var defaultFacet = facets.find(function (f) { return f.id === 'default'; });
519
- if (defaultFacet) {
520
- return defaultFacet;
521
- }
522
- // else just pick the first in the list
523
- return facets[0];
524
- };
525
- /**
526
- * Load the item with the specified ID (if any; the ID can be null for
527
- * a new item), and all the required lookup data into the item store.
528
- */
529
- EditItemService.prototype.load = function (itemId) {
530
- var _this = this;
531
- this._store.setLoading(true);
532
- var layers$ = this._itemService.getItemLayerInfo(itemId, true);
533
- var appState = this._appQuery.getValue();
534
- // if not a new item, include it in load
535
- if (itemId) {
536
- rxjs.forkJoin({
537
- item: this._itemService.getItem(itemId, true),
538
- layers: layers$,
539
- }).subscribe(function (result) {
540
- _this._store.setLoading(false);
541
- _this._store.setError(null);
542
- var itemFacet = appState.facets.find(function (f) {
543
- return f.id === result.item.facetId;
544
- });
545
- var facetParts = itemFacet ? itemFacet.partDefinitions : [];
546
- _this._store.update({
547
- item: result.item,
548
- parts: result.item.parts,
549
- partGroups: _this._itemService.groupParts(result.item.parts, facetParts),
550
- layerPartInfos: result.layers,
551
- facet: appState.facets.find(function (f) { return f.id === result.item.facetId; }),
552
- });
553
- }, function (error) {
554
- console.error(error);
555
- _this._store.setLoading(false);
556
- _this._store.setError('Error loading item ' + itemId);
557
- });
558
- }
559
- else {
560
- // if new, just set an empty item
561
- rxjs.forkJoin({
562
- layers: layers$,
563
- }).subscribe(function (result) {
564
- _this._store.setLoading(false);
565
- _this._store.setError(null);
566
- _this._store.update({
567
- item: {
568
- id: null,
569
- title: null,
570
- description: null,
571
- facetId: null,
572
- groupId: null,
573
- sortKey: null,
574
- flags: 0,
575
- timeCreated: new Date(),
576
- creatorId: null,
577
- timeModified: new Date(),
578
- userId: null,
579
- },
580
- parts: [],
581
- partGroups: [],
582
- layerPartInfos: result.layers,
583
- facet: _this.pickDefaultFacet(appState.facets),
584
- });
585
- }, function (error) {
586
- console.error(error);
587
- _this._store.setLoading(false);
588
- _this._store.setError('Error loading item ' + itemId);
589
- });
590
- }
591
- };
592
- /**
593
- * Reset the item.
594
- */
595
- EditItemService.prototype.reset = function () {
596
- this._store.reset();
597
- };
598
- /**
599
- * Save the item and update the store.
600
- * @param item The item to be saved.
601
- */
602
- EditItemService.prototype.save = function (item) {
603
- var _this = this;
604
- this._store.setSaving();
605
- return new Promise(function (resolve, reject) {
606
- _this._itemService.addItem(item).subscribe(function (saved) {
607
- _this._store.setSaving(false);
608
- // reload the store
609
- _this.load(saved.id);
610
- resolve(saved);
611
- }, function (error) {
612
- console.error(error);
613
- _this._store.setSaving(false);
614
- _this._store.setError('Error saving item');
615
- reject(error);
616
- });
617
- });
618
- };
619
- /**
620
- * Delete the part with the specified ID from the edited item.
621
- * @param id The ID of the part to be deleted.
622
- */
623
- EditItemService.prototype.deletePart = function (id) {
624
- var _this = this;
625
- this._store.setDeletingPart();
626
- return new Promise(function (resolve, reject) {
627
- // delete from server
628
- _this._itemService.deletePart(id).subscribe(function (_) {
629
- _this._store.setDeletingPart(false);
630
- // reload the store
631
- _this.load(_this._store.getValue().item.id);
632
- resolve(id);
633
- }, function (error) {
634
- console.log(error);
635
- _this._store.setDeletingPart(false);
636
- _this._store.setError('Error deleting part ' + id);
637
- reject(error);
638
- });
639
- });
640
- };
641
- EditItemService.prototype.addNewLayerPart = function (itemId, typeId, roleId) {
642
- var _this = this;
643
- var part = {
644
- itemId: itemId,
645
- typeId: typeId,
646
- roleId: roleId,
647
- id: null,
648
- creatorId: null,
649
- userId: null,
650
- timeCreated: new Date(),
651
- timeModified: new Date(),
652
- };
653
- this._store.setSaving();
654
- this._itemService.addPart(part).subscribe(function (_) {
655
- _this._store.setSaving(false);
656
- // reload the store
657
- _this.load(_this._store.getValue().item.id);
658
- }, function (error) {
659
- console.log(error);
660
- _this._store.setSaving(false);
661
- _this._store.setError('Error adding new layer part for item ' + itemId);
662
- });
663
- };
664
- EditItemService.prototype.setPartThesaurusScope = function (ids, scope) {
665
- var _this = this;
666
- this._store.setSaving();
667
- this._itemService.setPartThesaurusScope(ids, scope).subscribe(function (_) {
668
- _this._store.setSaving(false);
669
- // reload the store
670
- _this.load(_this._store.getValue().item.id);
671
- }, function (error) {
672
- console.log(error);
673
- _this._store.setSaving(false);
674
- _this._store.setError("Error setting item's parts scope");
675
- });
676
- };
677
- return EditItemService;
678
- }());
679
- EditItemService.ɵprov = i0.ɵɵdefineInjectable({ factory: function EditItemService_Factory() { return new EditItemService(i0.ɵɵinject(exports.EditItemStore), i0.ɵɵinject(AppQuery), i0.ɵɵinject(i2.ItemService)); }, token: EditItemService, providedIn: "root" });
680
- EditItemService.decorators = [
681
- { type: i0.Injectable, args: [{ providedIn: 'root' },] }
682
- ];
683
- EditItemService.ctorParameters = function () { return [
684
- { type: exports.EditItemStore },
685
- { type: AppQuery },
686
- { type: i2.ItemService }
687
- ]; };
688
-
689
- /**
690
- * Base class for fragment feature editors.
691
- * This is similar to the EditPartFeatureBase class.
692
- */
693
- var EditFragmentFeatureBase = /** @class */ (function () {
694
- function EditFragmentFeatureBase(_router, route, snackbar, _editFrQuery, _editFrService, _editItemQuery, _editItemService, _editLayersQuery, _editLayersService, _libraryRouteService) {
695
- var _this = this;
696
- var _a;
697
- this._router = _router;
698
- this.snackbar = snackbar;
699
- this._editFrQuery = _editFrQuery;
700
- this._editFrService = _editFrService;
701
- this._editItemQuery = _editItemQuery;
702
- this._editItemService = _editItemService;
703
- this._editLayersQuery = _editLayersQuery;
704
- this._editLayersService = _editLayersService;
705
- this._libraryRouteService = _libraryRouteService;
706
- this.itemId = route.snapshot.params.iid;
707
- this.partId = route.snapshot.params.pid;
708
- this.frTypeId = (_a = route.snapshot.url[2]) === null || _a === void 0 ? void 0 : _a.path;
709
- this.loc = route.snapshot.params.loc;
710
- this.frRoleId = route.snapshot.queryParams.frrid;
711
- // connect _stateDirty to the value of the edit state
712
- this._editFrQuery.selectDirty().subscribe(function (d) {
713
- console.log('fr dirty change (from state): ' + d);
714
- _this._stateDirty = d;
715
- });
716
- }
717
- /**
718
- * Implementation of ComponentCanDeactivate. The editor can deactivate
719
- * when both its "root" form in the wrapped UI editor and the edit state
720
- * are not dirty. The form gets dirty when edited by the user; the edit
721
- * state gets dirty after a failed save attempt.
722
- */
723
- EditFragmentFeatureBase.prototype.canDeactivate = function () {
724
- // can-deactivate from dirty
725
- return !this._formDirty && !this._stateDirty;
726
- };
727
- EditFragmentFeatureBase.prototype.ensureItemLoaded = function (id) {
728
- if (!this._editItemQuery.hasItem(id)) {
729
- this._editItemService.load(id);
730
- }
731
- };
732
- EditFragmentFeatureBase.prototype.ensureLayersLoaded = function (thesauriIds) {
733
- if (!this._editLayersQuery.getValue().part) {
734
- this._editLayersService.load(this.itemId, this.partId, thesauriIds);
735
- }
736
- };
737
- /**
738
- * Initialize the editor. You MUST call this in your OnInit.
739
- *
740
- * @param thesauriIds The optional ID(s) of the thesauri sets you want
741
- * to use in your editor.
742
- */
743
- EditFragmentFeatureBase.prototype.initEditor = function (thesauriIds) {
744
- this.fragment$ = this._editFrQuery.selectFragment();
745
- this.thesauri$ = this._editFrQuery.selectThesauri();
746
- this.baseText$ = this._editLayersQuery.select(function (state) { return state.baseText; });
747
- this.frLoc = i2$1.TokenLocation.parse(this.loc);
748
- // load item if required
749
- this.ensureItemLoaded(this.itemId);
750
- // load layers if required
751
- this.ensureLayersLoaded(thesauriIds);
752
- // load fragment
753
- this._editFrService.load(this.partId, this.loc, thesauriIds);
754
- };
755
- /**
756
- * Called when the wrapped editor dirty state changes.
757
- * In the HTML template, you MUST bind this handler to the dirtyChange event
758
- * emitted by your wrapped editor (i.e. (dirtyChange)="onDirtyChange($event)").
759
- * @param value The value of the dirty state.
760
- */
761
- EditFragmentFeatureBase.prototype.onDirtyChange = function (value) {
762
- console.log('fr dirty change (from editor): ' + value);
763
- this._formDirty = value;
764
- };
765
- /**
766
- * Save the fragment.
767
- *
768
- * @param fragment The fragment to be saved.
769
- */
770
- EditFragmentFeatureBase.prototype.save = function (fragment) {
771
- var _this = this;
772
- // get a copy of the container part
773
- var part = JSON.parse(JSON.stringify(this._editLayersQuery.getValue().part));
774
- // replace the fragment edited in it
775
- var frIndex = part.fragments.findIndex(function (f) { return f.location === _this.loc; });
776
- if (frIndex > -1) {
777
- part.fragments.splice(frIndex, 1, fragment);
778
- }
779
- else {
780
- part.fragments.push(fragment);
781
- }
782
- // save the new layer part with the replaced fragment
783
- this._editFrService.save(part).then(function (p) {
784
- console.log(p.id);
785
- _this.snackbar.open('Fragment saved', 'OK', {
786
- duration: 3000,
787
- });
788
- }, function (error) {
789
- console.error(error);
790
- _this.snackbar.open('Error saving fragment', 'OK');
791
- });
792
- };
793
- EditFragmentFeatureBase.prototype.close = function () {
794
- // /items/<id>/<part-group>/<part-typeid>/<part-id>?rid=<role-id>
795
- var part = this._editLayersQuery.getValue().part;
796
- var editorKey = this._libraryRouteService.getEditorKeyFromPartType(part.typeId, part.roleId);
797
- var url = "/items/" + this.itemId + "/" + editorKey.partKey + "/" + part.typeId + "/" + this.partId;
798
- this._router.navigate([url], {
799
- queryParams: {
800
- rid: this.frTypeId,
801
- },
802
- });
803
- };
804
- return EditFragmentFeatureBase;
805
- }());
806
-
807
- var EditFragmentQueryBase = /** @class */ (function (_super) {
808
- __extends(EditFragmentQueryBase, _super);
809
- function EditFragmentQueryBase(store) {
810
- var _this = _super.call(this, store) || this;
811
- _this.store = store;
812
- return _this;
813
- }
814
- EditFragmentQueryBase.prototype.selectDirty = function () {
815
- return this.select(function (state) { return state.dirty; });
816
- };
817
- EditFragmentQueryBase.prototype.selectSaving = function () {
818
- return this.select(function (state) { return state.saving; });
819
- };
820
- EditFragmentQueryBase.prototype.selectFragment = function () {
821
- return this.select(function (state) { return state.fragment; });
822
- };
823
- // public selectJson(): Observable<string> {
824
- // return this.select((state) => state.fragment).pipe(
825
- // map((fr: Fragment) => {
826
- // // supply IDs
827
- // if (fr) {
828
- // return JSON.stringify(fr);
829
- // } else {
830
- // return '{}';
831
- // }
832
- // })
833
- // );
834
- // }
835
- EditFragmentQueryBase.prototype.selectThesauri = function () {
836
- return this.select(function (state) { return state.thesauri; });
837
- };
838
- return EditFragmentQueryBase;
839
- }(akita.Query));
840
-
841
- var editFragmentInitialState = {
842
- fragment: null,
843
- thesauri: null,
844
- dirty: false,
845
- saving: false,
846
- loading: false,
847
- error: null,
848
- };
849
- /**
850
- * General-purpose edit-fragment store. This can be used with any fragment,
851
- * so that you should only provide your fragment store, query, and service
852
- * (usually extending EditFragmentServiceBase).
853
- */
854
- exports.EditFragmentStore = /** @class */ (function (_super) {
855
- __extends(EditFragmentStore, _super);
856
- function EditFragmentStore() {
857
- return _super.call(this, editFragmentInitialState) || this;
858
- }
859
- EditFragmentStore.prototype.setDirty = function (value) {
860
- this.update({ dirty: value });
861
- };
862
- EditFragmentStore.prototype.setSaving = function (value) {
863
- this.update({ saving: value });
864
- };
865
- return EditFragmentStore;
866
- }(akita.Store));
867
- exports.EditFragmentStore.ɵprov = i0.ɵɵdefineInjectable({ factory: function EditFragmentStore_Factory() { return new exports.EditFragmentStore(); }, token: exports.EditFragmentStore, providedIn: "root" });
868
- exports.EditFragmentStore.decorators = [
869
- { type: i0.Injectable, args: [{ providedIn: 'root' },] }
870
- ];
871
- exports.EditFragmentStore.ctorParameters = function () { return []; };
872
- exports.EditFragmentStore = __decorate([
873
- akita.StoreConfig({ name: 'edit-fragment' })
874
- ], exports.EditFragmentStore);
875
-
876
- /**
877
- * Base class for fragment editor services.
878
- */
879
- var EditFragmentServiceBase = /** @class */ (function () {
880
- function EditFragmentServiceBase(_itemService, _thesaurusService) {
881
- this._itemService = _itemService;
882
- this._thesaurusService = _thesaurusService;
883
- }
884
- /**
885
- * Load into the state the fragment with the specified ID
886
- * and its thesauri.
887
- *
888
- * @param partId The ID of the part the fragment belongs to.
889
- * @param loc The fragment's location.
890
- * @param thesauriIds The thesauri IDs array, or null.
891
- */
892
- EditFragmentServiceBase.prototype.load = function (partId, loc, thesauriIds) {
893
- var _this = this;
894
- if (thesauriIds === void 0) { thesauriIds = null; }
895
- // signal that we're loading
896
- this.store.setLoading(true);
897
- // if thesauri are required:
898
- if (thesauriIds) {
899
- // remove trailing ! from IDs if any
900
- var unscopedIds = thesauriIds.map(function (id) {
901
- return _this._thesaurusService.getScopedId(id, null);
902
- });
903
- // fetch fragment and thesauri
904
- rxjs.forkJoin({
905
- part: this._itemService.getPart(partId),
906
- thesauri: this._thesaurusService.getThesauriSet(unscopedIds),
907
- }).subscribe(function (result) {
908
- // loading has ended
909
- _this.store.setLoading(false);
910
- var layerPart = result.part;
911
- var fr = layerPart.fragments.find(function (f) { return f.location === loc; });
912
- if (!fr) {
913
- // not found: new fragment
914
- _this.store.update({
915
- fragment: {
916
- location: loc,
917
- },
918
- thesauri: result.thesauri,
919
- loading: false,
920
- error: null,
921
- });
922
- }
923
- else {
924
- // found: existing fragment
925
- _this.store.update({
926
- fragment: fr,
927
- thesauri: result.thesauri,
928
- loading: false,
929
- error: null,
930
- });
931
- }
932
- // if the loaded layer part has a thesaurus scope, reload the thesauri
933
- if (result.part.thesaurusScope) {
934
- var scopedIds_1 = thesauriIds.map(function (id) {
935
- return _this._thesaurusService.getScopedId(id, result.part.thesaurusScope);
936
- });
937
- // loading again
938
- _this.store.setLoading(true);
939
- _this._thesaurusService.getThesauriSet(scopedIds_1).subscribe(function (thesauri) {
940
- // completed, replace the thesauri
941
- _this.store.update({
942
- thesauri: thesauri,
943
- loading: false
944
- });
945
- }, function (error) {
946
- console.error(error);
947
- _this.store.setLoading(false);
948
- _this.store.setError('Error loading thesauri ' + scopedIds_1.join(', '));
949
- });
950
- } // scoped
951
- });
952
- }
953
- else {
954
- // without thesauri to be fetched, just fetch the part
955
- this._itemService.getPart(partId).subscribe(function (part) {
956
- var layerPart = part;
957
- var fr = layerPart.fragments.find(function (f) { return f.location === loc; });
958
- if (!fr) {
959
- // not found: new fragment
960
- _this.store.update({
961
- fragment: {
962
- location: loc,
963
- },
964
- loading: false,
965
- error: null,
966
- });
967
- }
968
- else {
969
- _this.store.update({
970
- fragment: fr,
971
- loading: false,
972
- error: null,
973
- });
974
- }
975
- }, function (error) {
976
- console.error(error);
977
- _this.store.setLoading(false);
978
- _this.store.setError('Error loading fragment\'s part ' + partId);
979
- });
980
- }
981
- };
982
- /**
983
- * Save the fragments in their layer part.
984
- *
985
- * @param part The part.
986
- * @returns Promise which when successful returns the
987
- * saved part (which contains the fragment being saved).
988
- */
989
- EditFragmentServiceBase.prototype.save = function (part) {
990
- var _this = this;
991
- this.store.setSaving(true);
992
- this.store.setDirty(true);
993
- return new Promise(function (resolve, reject) {
994
- _this._itemService.addPart(part).subscribe(function (saved) {
995
- _this.store.update({
996
- part: saved,
997
- saving: false,
998
- dirty: false,
999
- error: null,
1000
- });
1001
- resolve(part);
1002
- }, function (error) {
1003
- console.error(error);
1004
- _this.store.setSaving(false);
1005
- _this.store.setError('Error saving fragment\'s part');
1006
- reject(error);
1007
- });
1008
- });
1009
- };
1010
- EditFragmentServiceBase.prototype.setDirty = function (value) {
1011
- if (value === void 0) { value = true; }
1012
- this.store.setDirty(value);
1013
- };
1014
- return EditFragmentServiceBase;
1015
- }());
1016
-
1017
- /**
1018
- * Base class for part feature editors.
1019
- * A part feature editor is a wrapper component, linking a part edit
1020
- * state (accessed from a part query and loaded with a part service)
1021
- * to a corresponding wrapped UI editor.
1022
- * It implements ComponentCanDeactivate to allow using the
1023
- * PendingChangesGuard. To this end, it tracks the dirty state of
1024
- * the edited data coming from 2 different sources: the wrapped editor
1025
- * state (from its "root" form), and the store edit state. This is
1026
- * set to dirty when a save attempt fails.
1027
- * Thus, at the end the user will be prompted when closing an editor
1028
- * either because he has changed data in it, or because he attempted
1029
- * a save without success.
1030
- */
1031
- var EditPartFeatureBase = /** @class */ (function () {
1032
- function EditPartFeatureBase(router, route, snackbar, _editPartQuery, _editPartService, _editItemQuery, _editItemService) {
1033
- var _this = this;
1034
- this.router = router;
1035
- this.snackbar = snackbar;
1036
- this._editPartQuery = _editPartQuery;
1037
- this._editPartService = _editPartService;
1038
- this._editItemQuery = _editItemQuery;
1039
- this._editItemService = _editItemService;
1040
- // item ID
1041
- this.itemId = route.snapshot.params.iid;
1042
- // type ID (from "TYPEID/:pid")
1043
- this.typeId = route.snapshot.routeConfig.path.substr(0, route.snapshot.routeConfig.path.indexOf('/'));
1044
- // part ID or null (if "new")
1045
- this.partId = route.snapshot.params.pid;
1046
- if (this.partId === 'new') {
1047
- this.partId = null;
1048
- }
1049
- // role ID or null (if "default")
1050
- this.roleId = route.snapshot.queryParams.rid;
1051
- if (this.roleId === 'default') {
1052
- this.roleId = null;
1053
- }
1054
- // connect _stateDirty to the value observed in the part state
1055
- this._editPartQuery.selectDirty().subscribe(function (d) {
1056
- console.log('part dirty change (from state): ' + d);
1057
- _this._stateDirty = d;
1058
- });
1059
- }
1060
- /**
1061
- * Implementation of ComponentCanDeactivate. The editor can deactivate
1062
- * when both its "root" form in the wrapped UI editor and the edit state
1063
- * are not dirty. The form gets dirty when edited by the user; the edit
1064
- * state gets dirty after a failed save attempt.
1065
- */
1066
- EditPartFeatureBase.prototype.canDeactivate = function () {
1067
- // can-deactivate from dirty
1068
- return !this._formDirty && !this._stateDirty;
1069
- };
1070
- EditPartFeatureBase.prototype.ensureItemLoaded = function (id) {
1071
- if (!this._editItemQuery.hasItem(id)) {
1072
- this._editItemService.load(id);
1073
- }
1074
- };
1075
- /**
1076
- * Initialize the editor. You MUST call this in your OnInit.
1077
- *
1078
- * @param thesauriIds The optional ID(s) of the thesauri sets you want
1079
- * to use in your editor.
1080
- */
1081
- EditPartFeatureBase.prototype.initEditor = function (thesauriIds) {
1082
- // connect part and thesauri to state via query
1083
- this.part$ = this._editPartQuery.selectPart();
1084
- this.thesauri$ = this._editPartQuery.selectThesauri();
1085
- // load item if required
1086
- this.ensureItemLoaded(this.itemId);
1087
- // load part (none if new) and thesauri
1088
- this._editPartService.load(this.partId, // a new part has null here
1089
- thesauriIds,
1090
- // for a new part, we must supply item and role
1091
- this.itemId, this.typeId, this.roleId);
1092
- };
1093
- /**
1094
- * Called when the wrapped editor dirty state changes.
1095
- * In the HTML template, you MUST bind this handler to the dirtyChange event
1096
- * emitted by your wrapped editor (i.e. (dirtyChange)="onDirtyChange($event)").
1097
- *
1098
- * @param value The value of the dirty state.
1099
- */
1100
- EditPartFeatureBase.prototype.onDirtyChange = function (value) {
1101
- console.log('part dirty change (from editor): ' + value);
1102
- this._formDirty = value;
1103
- };
1104
- /**
1105
- * Save the part.
1106
- *
1107
- * @param part The part to be saved.
1108
- */
1109
- EditPartFeatureBase.prototype.save = function (part) {
1110
- var _this = this;
1111
- // save via part service, which invokes item service
1112
- // for the backend, and then updates the part's store
1113
- this._editPartService.save(part).then(function (saved) {
1114
- // update the route-defined part ID if it was null (new part)
1115
- if (!_this.partId) {
1116
- _this.partId = saved.id;
1117
- }
1118
- console.log('Part saved: ' + saved.id);
1119
- _this.snackbar.open('Part saved', 'OK', {
1120
- duration: 3000,
1121
- });
1122
- }, function (error) {
1123
- console.error(error);
1124
- _this.snackbar.open('Error saving part', 'OK');
1125
- });
1126
- };
1127
- /**
1128
- * Close the editor by navigating back to the part's item.
1129
- */
1130
- EditPartFeatureBase.prototype.close = function () {
1131
- this.router.navigate(['items', this.itemId]);
1132
- };
1133
- return EditPartFeatureBase;
1134
- }());
1135
-
1136
- /**
1137
- * Base class for implementing editor part queries.
1138
- * To implement an editor part query, just extend this passing the specialized
1139
- * part's store to the constructor.
1140
- */
1141
- var EditPartQueryBase = /** @class */ (function (_super) {
1142
- __extends(EditPartQueryBase, _super);
1143
- function EditPartQueryBase(store) {
1144
- var _this = _super.call(this, store) || this;
1145
- _this.store = store;
1146
- return _this;
1147
- }
1148
- EditPartQueryBase.prototype.selectDirty = function () {
1149
- return this.select(function (state) { return state.dirty; });
1150
- };
1151
- EditPartQueryBase.prototype.selectSaving = function () {
1152
- return this.select(function (state) { return state.saving; });
1153
- };
1154
- EditPartQueryBase.prototype.selectPart = function () {
1155
- return this.select(function (state) { return state.part; });
1156
- };
1157
- EditPartQueryBase.prototype.selectThesauri = function () {
1158
- return this.select(function (state) { return state.thesauri; });
1159
- };
1160
- return EditPartQueryBase;
1161
- }(akita.Query));
1162
-
1163
- /**
1164
- * Base class for part editor services.
1165
- */
1166
- var EditPartServiceBase = /** @class */ (function () {
1167
- function EditPartServiceBase(itemService, thesaurusService) {
1168
- this.itemService = itemService;
1169
- this.thesaurusService = thesaurusService;
1170
- }
1171
- /**
1172
- * Load into the state the part with the specified ID
1173
- * and its thesauri.
1174
- * If the ID is not specified, it's a new part; in this case,
1175
- * it will get a null ID, but use the specified itemId and roleId.
1176
- *
1177
- * @param partId The part ID, unless it's a new part.
1178
- * @param thesauriIds The thesauri IDs array, or null.
1179
- * @param itemId The item ID for the new part.
1180
- * @param typeId The part type ID for the new part.
1181
- * @param roleId The role ID for the new part.
1182
- */
1183
- EditPartServiceBase.prototype.load = function (partId, thesauriIds, itemId, typeId, roleId) {
1184
- var _this = this;
1185
- if (thesauriIds === void 0) { thesauriIds = null; }
1186
- // signal that we're loading
1187
- this.store.setLoading(true);
1188
- // if thesauri are required:
1189
- if (thesauriIds) {
1190
- // remove trailing ! from IDs if any
1191
- var unscopedIds = thesauriIds.map(function (id) {
1192
- return _this.thesaurusService.getScopedId(id, null);
1193
- });
1194
- // fetch part and thesauri
1195
- rxjs.forkJoin({
1196
- part: this.itemService.getPart(partId),
1197
- thesauri: this.thesaurusService.getThesauriSet(unscopedIds),
1198
- }).subscribe(function (result) {
1199
- var _a;
1200
- // loading has ended
1201
- _this.store.setLoading(false);
1202
- // update the store with a new or existing part,
1203
- // and its requested thesauri
1204
- _this.store.update({
1205
- part: result.part || {
1206
- id: null,
1207
- itemId: itemId,
1208
- typeId: typeId,
1209
- roleId: roleId,
1210
- },
1211
- thesauri: result.thesauri,
1212
- });
1213
- // if the loaded part has a thesaurus scope, reload the thesauri
1214
- if ((_a = result.part) === null || _a === void 0 ? void 0 : _a.thesaurusScope) {
1215
- var scopedIds_1 = thesauriIds.map(function (id) {
1216
- return _this.thesaurusService.getScopedId(id, result.part.thesaurusScope);
1217
- });
1218
- // loading again
1219
- _this.store.setLoading(true);
1220
- _this.thesaurusService.getThesauriSet(thesauriIds).subscribe(function (thesauri) {
1221
- // completed, replace the thesauri
1222
- _this.store.update({
1223
- thesauri: thesauri,
1224
- loading: false,
1225
- });
1226
- }, function (error) {
1227
- console.error(error);
1228
- _this.store.setLoading(false);
1229
- _this.store.setError('Error loading thesauri ' + scopedIds_1.join(', '));
1230
- });
1231
- } // scoped
1232
- });
1233
- }
1234
- else {
1235
- // without thesauri to be fetched, just fetch the part
1236
- this.itemService.getPart(partId).subscribe(function (part) {
1237
- _this.store.update({
1238
- part: part || {
1239
- id: null,
1240
- itemId: itemId,
1241
- typeId: typeId,
1242
- roleId: roleId,
1243
- },
1244
- loading: false,
1245
- error: null,
1246
- });
1247
- }, function (error) {
1248
- console.error(error);
1249
- _this.store.setLoading(false);
1250
- _this.store.setError('Error loading part ' + partId);
1251
- });
1252
- }
1253
- };
1254
- /**
1255
- * Save the part.
1256
- *
1257
- * @param part The part.
1258
- * @returns Promise which when successful returns the saved part.
1259
- */
1260
- EditPartServiceBase.prototype.save = function (part) {
1261
- var _this = this;
1262
- this.store.setSaving(true);
1263
- this.store.setDirty(true);
1264
- return new Promise(function (resolve, reject) {
1265
- _this.itemService.addPart(part).subscribe(function (saved) {
1266
- _this.store.update({
1267
- part: saved,
1268
- saving: false,
1269
- dirty: false,
1270
- error: null,
1271
- });
1272
- resolve(part);
1273
- }, function (error) {
1274
- console.error(error);
1275
- _this.store.setSaving(false);
1276
- _this.store.setError('Error saving part');
1277
- reject(error);
1278
- });
1279
- });
1280
- };
1281
- EditPartServiceBase.prototype.setDirty = function (value) {
1282
- if (value === void 0) { value = true; }
1283
- this.store.setDirty(value);
1284
- };
1285
- return EditPartServiceBase;
1286
- }());
1287
-
1288
- var editPartInitialState = {
1289
- part: null,
1290
- thesauri: null,
1291
- dirty: false,
1292
- saving: false,
1293
- loading: false,
1294
- error: null
1295
- };
1296
- /**
1297
- * General-purpose edit-part store. This can be used with any part, so that
1298
- * you should only provide your part store, query, and service (usually
1299
- * extending EditPartServiceBase).
1300
- */
1301
- exports.EditPartStore = /** @class */ (function (_super) {
1302
- __extends(EditPartStore, _super);
1303
- function EditPartStore() {
1304
- return _super.call(this, editPartInitialState) || this;
1305
- }
1306
- EditPartStore.prototype.setDirty = function (value) {
1307
- this.update({ dirty: value });
1308
- };
1309
- EditPartStore.prototype.setSaving = function (value) {
1310
- this.update({ saving: value });
1311
- };
1312
- return EditPartStore;
1313
- }(akita.Store));
1314
- exports.EditPartStore.ɵprov = i0.ɵɵdefineInjectable({ factory: function EditPartStore_Factory() { return new exports.EditPartStore(); }, token: exports.EditPartStore, providedIn: "root" });
1315
- exports.EditPartStore.decorators = [
1316
- { type: i0.Injectable, args: [{ providedIn: 'root' },] }
1317
- ];
1318
- exports.EditPartStore.ctorParameters = function () { return []; };
1319
- exports.EditPartStore = __decorate([
1320
- akita.StoreConfig({ name: 'edit-part' })
1321
- ], exports.EditPartStore);
1322
-
1323
- var initialState$2 = {
1324
- part: null,
1325
- baseText: null,
1326
- baseTextPart: null,
1327
- locations: [],
1328
- breakChance: -1,
1329
- layerHints: [],
1330
- thesauri: {},
1331
- loading: false,
1332
- error: null,
1333
- deletingFragment: false,
1334
- savingFragment: false,
1335
- refreshingBreakChance: false,
1336
- patchingLayer: false,
1337
- };
1338
- exports.EditLayerPartStore = /** @class */ (function (_super) {
1339
- __extends(EditLayerPartStore, _super);
1340
- function EditLayerPartStore() {
1341
- return _super.call(this, initialState$2) || this;
1342
- }
1343
- EditLayerPartStore.prototype.setDeletingFragment = function (value) {
1344
- if (value === void 0) { value = true; }
1345
- this.update({ deletingFragment: value });
1346
- };
1347
- EditLayerPartStore.prototype.setSavingFragment = function (value) {
1348
- if (value === void 0) { value = true; }
1349
- this.update({ savingFragment: value });
1350
- };
1351
- EditLayerPartStore.prototype.setRefreshingBreakChance = function (value) {
1352
- if (value === void 0) { value = true; }
1353
- this.update({ refreshingBreakChance: value });
1354
- };
1355
- EditLayerPartStore.prototype.setBreakChance = function (value) {
1356
- this.update({ breakChance: value });
1357
- };
1358
- EditLayerPartStore.prototype.setPatchingLayer = function (value) {
1359
- if (value === void 0) { value = true; }
1360
- this.update({ patchingLayer: value });
1361
- };
1362
- EditLayerPartStore.prototype.setLocations = function (locations) {
1363
- this.update({ locations: locations });
1364
- };
1365
- return EditLayerPartStore;
1366
- }(akita.Store));
1367
- exports.EditLayerPartStore.ɵprov = i0.ɵɵdefineInjectable({ factory: function EditLayerPartStore_Factory() { return new exports.EditLayerPartStore(); }, token: exports.EditLayerPartStore, providedIn: "root" });
1368
- exports.EditLayerPartStore.decorators = [
1369
- { type: i0.Injectable, args: [{ providedIn: 'root' },] }
1370
- ];
1371
- exports.EditLayerPartStore.ctorParameters = function () { return []; };
1372
- exports.EditLayerPartStore = __decorate([
1373
- akita.StoreConfig({ name: 'edit-layer-part' })
1374
- ], exports.EditLayerPartStore);
1375
-
1376
- var EditLayerPartQuery = /** @class */ (function (_super) {
1377
- __extends(EditLayerPartQuery, _super);
1378
- function EditLayerPartQuery(store) {
1379
- var _this = _super.call(this, store) || this;
1380
- _this.store = store;
1381
- return _this;
1382
- }
1383
- EditLayerPartQuery.prototype.selectDeletingFragment = function () {
1384
- return this.select(function (state) { return state.deletingFragment; });
1385
- };
1386
- EditLayerPartQuery.prototype.selectSavingFragment = function () {
1387
- return this.select(function (state) { return state.savingFragment; });
1388
- };
1389
- EditLayerPartQuery.prototype.selectRefreshingBreakChance = function () {
1390
- return this.select(function (state) { return state.refreshingBreakChance; });
1391
- };
1392
- EditLayerPartQuery.prototype.selectBreakChance = function () {
1393
- return this.select(function (state) { return state.breakChance; });
1394
- };
1395
- EditLayerPartQuery.prototype.selectLayerHints = function () {
1396
- return this.select(function (state) { return state.layerHints; });
1397
- };
1398
- EditLayerPartQuery.prototype.selectPatchingLayers = function () {
1399
- return this.select(function (state) { return state.patchingLayer; });
1400
- };
1401
- return EditLayerPartQuery;
1402
- }(akita.Query));
1403
- EditLayerPartQuery.ɵprov = i0.ɵɵdefineInjectable({ factory: function EditLayerPartQuery_Factory() { return new EditLayerPartQuery(i0.ɵɵinject(exports.EditLayerPartStore)); }, token: EditLayerPartQuery, providedIn: "root" });
1404
- EditLayerPartQuery.decorators = [
1405
- { type: i0.Injectable, args: [{ providedIn: 'root' },] }
1406
- ];
1407
- EditLayerPartQuery.ctorParameters = function () { return [
1408
- { type: exports.EditLayerPartStore }
1409
- ]; };
1410
-
1411
- var EditLayerPartService = /** @class */ (function () {
1412
- function EditLayerPartService(_store, _itemService, _facetService, _thesaurusService) {
1413
- this._store = _store;
1414
- this._itemService = _itemService;
1415
- this._facetService = _facetService;
1416
- this._thesaurusService = _thesaurusService;
1417
- }
1418
- EditLayerPartService.prototype.getLocations = function (part) {
1419
- var locations = [];
1420
- if (part && part.fragments) {
1421
- part.fragments.forEach(function (p) {
1422
- locations.push(i2$1.TokenLocation.parse(p.location));
1423
- });
1424
- }
1425
- return locations;
1426
- };
1427
- /**
1428
- * Load the state for editing layer part(s).
1429
- *
1430
- * @param itemId The item ID the layer part belongs to.
1431
- * @param partId The layer part ID.
1432
- * @param thesauriIds The optional thesauri IDs to load.
1433
- */
1434
- EditLayerPartService.prototype.load = function (itemId, partId, thesauriIds) {
1435
- var _this = this;
1436
- if (thesauriIds === void 0) { thesauriIds = null; }
1437
- if (this._store.getValue().loading) {
1438
- return;
1439
- }
1440
- this._store.setLoading(true);
1441
- if (thesauriIds) {
1442
- // remove trailing ! from IDs if any
1443
- var unscopedIds = thesauriIds.map(function (id) {
1444
- return _this._thesaurusService.getScopedId(id, null);
1445
- });
1446
- rxjs.forkJoin({
1447
- // TODO: eventually optimize by adding method param to load only fragments locations
1448
- layerPart: this._itemService.getPart(partId),
1449
- baseText: this._itemService.getBaseTextPart(itemId),
1450
- layers: this._facetService.getFacetParts(itemId, true),
1451
- breakChance: this._itemService.getLayerPartBreakChance(partId),
1452
- layerHints: this._itemService.getLayerPartHints(partId),
1453
- thesauri: this._thesaurusService.getThesauriSet(unscopedIds),
1454
- }).subscribe(function (result) {
1455
- _this._store.update({
1456
- part: result.layerPart,
1457
- baseText: result.baseText.text,
1458
- baseTextPart: result.baseText.part,
1459
- locations: _this.getLocations(result.layerPart),
1460
- breakChance: result.breakChance.chance,
1461
- layerHints: result.layerHints,
1462
- thesauri: result.thesauri,
1463
- loading: false,
1464
- error: null,
1465
- });
1466
- // if the loaded part has a thesaurus scope, reload the thesauri
1467
- if (result.layerPart.thesaurusScope) {
1468
- var scopedIds_1 = thesauriIds.map(function (id) {
1469
- return _this._thesaurusService.getScopedId(id, result.layerPart.thesaurusScope);
1470
- });
1471
- _this._store.setLoading(true);
1472
- _this._thesaurusService.getThesauriSet(scopedIds_1).subscribe(function (thesauri) {
1473
- _this._store.update({
1474
- thesauri: thesauri,
1475
- });
1476
- }, function (error) {
1477
- console.error(error);
1478
- _this._store.setLoading(false);
1479
- _this._store.setError('Error loading thesauri ' + scopedIds_1.join(', '));
1480
- });
1481
- } // scoped
1482
- }, function (error) {
1483
- console.error(error);
1484
- _this._store.setLoading(false);
1485
- _this._store.setError('Error loading text layer part ' + partId);
1486
- });
1487
- }
1488
- else {
1489
- rxjs.forkJoin({
1490
- // TODO: eventually optimize by adding method param to load only fragments locations
1491
- layerPart: this._itemService.getPart(partId),
1492
- baseText: this._itemService.getBaseTextPart(itemId),
1493
- layers: this._facetService.getFacetParts(itemId, true),
1494
- breakChance: this._itemService.getLayerPartBreakChance(partId),
1495
- layerHints: this._itemService.getLayerPartHints(partId),
1496
- }).subscribe(function (result) {
1497
- _this._store.update({
1498
- part: result.layerPart,
1499
- baseText: result.baseText.text,
1500
- baseTextPart: result.baseText.part,
1501
- locations: _this.getLocations(result.layerPart),
1502
- breakChance: result.breakChance.chance,
1503
- layerHints: result.layerHints,
1504
- loading: false,
1505
- error: null,
1506
- });
1507
- }, function (error) {
1508
- console.error(error);
1509
- _this._store.setLoading(false);
1510
- _this._store.setError('Error loading text layer part ' + partId);
1511
- });
1512
- }
1513
- };
1514
- /**
1515
- * Refresh the layer part break chance.
1516
- */
1517
- EditLayerPartService.prototype.refreshBreakChance = function () {
1518
- var _this = this;
1519
- var store = this._store.getValue();
1520
- var part = store.part;
1521
- if (!part || store.refreshingBreakChance) {
1522
- return;
1523
- }
1524
- this._store.setRefreshingBreakChance(true);
1525
- this._itemService.getLayerPartBreakChance(part.id).subscribe(function (result) {
1526
- _this._store.setRefreshingBreakChance(false);
1527
- _this._store.setBreakChance(result.chance);
1528
- }, function (error) {
1529
- console.error(error);
1530
- _this._store.setRefreshingBreakChance(false);
1531
- _this._store.setBreakChance(-1);
1532
- _this._store.setError('Error refreshing break chance for text layer part ' + part.id);
1533
- });
1534
- };
1535
- EditLayerPartService.prototype.applyLayerPatches = function (partId, patches) {
1536
- var _this = this;
1537
- this._store.setPatchingLayer(true);
1538
- this._itemService.applyLayerPatches(partId, patches).subscribe(function (part) {
1539
- _this._store.setPatchingLayer(false);
1540
- _this.load(part.itemId, partId);
1541
- }, function (error) {
1542
- console.error(error);
1543
- _this._store.setPatchingLayer(false);
1544
- _this._store.setError('Error patching text layer part ' + partId);
1545
- });
1546
- };
1547
- /**
1548
- * Delete the fragment at the specified location.
1549
- *
1550
- * @param loc The fragment's location.
1551
- */
1552
- EditLayerPartService.prototype.deleteFragment = function (loc) {
1553
- var _this = this;
1554
- this._store.setDeletingFragment(true);
1555
- // find the fragment
1556
- var part = this._store.getValue().part;
1557
- if (!part) {
1558
- return;
1559
- }
1560
- var i = part.fragments.findIndex(function (p) {
1561
- return i2$1.TokenLocation.parse(p.location).overlaps(loc);
1562
- });
1563
- if (i === -1) {
1564
- return;
1565
- }
1566
- // remove it from the part
1567
- // work on a copy, as store objects are immutable
1568
- part = i2$1.deepCopy(part);
1569
- part.fragments.splice(i, 1);
1570
- // update the part and reload state once done
1571
- this._itemService.addPart(part).subscribe(function (_) {
1572
- _this._store.setDeletingFragment(false);
1573
- _this.load(part.itemId, part.id);
1574
- // this._store.update({
1575
- // part: part,
1576
- // deletingFragment: false,
1577
- // error: null
1578
- // });
1579
- }, function (error) {
1580
- console.error(error);
1581
- _this._store.setDeletingFragment(false);
1582
- _this._store.setError("Error deleting fragment at " + loc + " in part " + part.id);
1583
- });
1584
- };
1585
- /**
1586
- * Save the specified fragment.
1587
- *
1588
- * @param fragment The fragment.
1589
- */
1590
- EditLayerPartService.prototype.saveFragment = function (fragment) {
1591
- var _this = this;
1592
- this._store.setSavingFragment();
1593
- // find the fragment
1594
- var part = this._store.getValue().part;
1595
- if (!part) {
1596
- return;
1597
- }
1598
- // add or replace it
1599
- // work on a copy, as store objects are immutable
1600
- part = i2$1.deepCopy(part);
1601
- // replace all the overlapping fragments with the new one
1602
- var newLoc = i2$1.TokenLocation.parse(fragment.location);
1603
- var insertAt = 0;
1604
- for (var i = part.fragments.length - 1; i > -1; i--) {
1605
- var frLoc = i2$1.TokenLocation.parse(part.fragments[i].location);
1606
- if (newLoc.compareTo(frLoc) >= 0) {
1607
- insertAt = i + 1;
1608
- }
1609
- if (newLoc.overlaps(frLoc)) {
1610
- part.fragments.splice(i, 1);
1611
- if (insertAt > i && insertAt > 0) {
1612
- insertAt--;
1613
- }
1614
- }
1615
- }
1616
- // add the new fragment
1617
- part.fragments.splice(insertAt, 0, fragment);
1618
- // update the part and reload once done
1619
- this._itemService.addPart(part).subscribe(function (_) {
1620
- _this.load(part.itemId, part.id);
1621
- // this._store.update({
1622
- // part: part,
1623
- // deletingFragment: false,
1624
- // error: null
1625
- // });
1626
- }, function (error) {
1627
- console.error(error);
1628
- _this._store.setSavingFragment(false);
1629
- _this._store.setError("Error saving fragment at " + fragment.location + " in part " + part.id);
1630
- });
1631
- };
1632
- return EditLayerPartService;
1633
- }());
1634
- EditLayerPartService.ɵprov = i0.ɵɵdefineInjectable({ factory: function EditLayerPartService_Factory() { return new EditLayerPartService(i0.ɵɵinject(exports.EditLayerPartStore), i0.ɵɵinject(i2.ItemService), i0.ɵɵinject(i2.FacetService), i0.ɵɵinject(i2.ThesaurusService)); }, token: EditLayerPartService, providedIn: "root" });
1635
- EditLayerPartService.decorators = [
1636
- { type: i0.Injectable, args: [{ providedIn: 'root' },] }
1637
- ];
1638
- EditLayerPartService.ctorParameters = function () { return [
1639
- { type: exports.EditLayerPartStore },
1640
- { type: i2.ItemService },
1641
- { type: i2.FacetService },
1642
- { type: i2.ThesaurusService }
1643
- ]; };
1644
-
1645
- var initialState$3 = {
1646
- thesaurus: null,
1647
- dirty: false,
1648
- saving: false,
1649
- loading: false,
1650
- error: null,
1651
- };
1652
- exports.EditThesaurusStore = /** @class */ (function (_super) {
1653
- __extends(EditThesaurusStore, _super);
1654
- function EditThesaurusStore() {
1655
- return _super.call(this, initialState$3) || this;
1656
- }
1657
- EditThesaurusStore.prototype.setDirty = function (value) {
1658
- if (value === void 0) { value = true; }
1659
- this.update({
1660
- dirty: value,
1661
- });
1662
- };
1663
- EditThesaurusStore.prototype.setSaving = function (value) {
1664
- if (value === void 0) { value = true; }
1665
- this.update({
1666
- saving: value,
1667
- });
1668
- };
1669
- return EditThesaurusStore;
1670
- }(akita.Store));
1671
- exports.EditThesaurusStore.ɵprov = i0.ɵɵdefineInjectable({ factory: function EditThesaurusStore_Factory() { return new exports.EditThesaurusStore(); }, token: exports.EditThesaurusStore, providedIn: "root" });
1672
- exports.EditThesaurusStore.decorators = [
1673
- { type: i0.Injectable, args: [{ providedIn: 'root' },] }
1674
- ];
1675
- exports.EditThesaurusStore.ctorParameters = function () { return []; };
1676
- exports.EditThesaurusStore = __decorate([
1677
- akita.StoreConfig({ name: 'edit-thesaurus', resettable: true })
1678
- ], exports.EditThesaurusStore);
1679
-
1680
- var EditThesaurusQuery = /** @class */ (function (_super) {
1681
- __extends(EditThesaurusQuery, _super);
1682
- function EditThesaurusQuery(store) {
1683
- var _this = _super.call(this, store) || this;
1684
- _this.store = store;
1685
- return _this;
1686
- }
1687
- EditThesaurusQuery.prototype.selectThesaurus = function () {
1688
- return this.select(function (state) { return state.thesaurus; });
1689
- };
1690
- EditThesaurusQuery.prototype.selectLoading = function () {
1691
- return this.select(function (state) { return state.loading; });
1692
- };
1693
- EditThesaurusQuery.prototype.selectSaving = function () {
1694
- return this.select(function (state) { return state.saving; });
1695
- };
1696
- return EditThesaurusQuery;
1697
- }(akita.Query));
1698
- EditThesaurusQuery.ɵprov = i0.ɵɵdefineInjectable({ factory: function EditThesaurusQuery_Factory() { return new EditThesaurusQuery(i0.ɵɵinject(exports.EditThesaurusStore)); }, token: EditThesaurusQuery, providedIn: "root" });
1699
- EditThesaurusQuery.decorators = [
1700
- { type: i0.Injectable, args: [{ providedIn: 'root' },] }
1701
- ];
1702
- EditThesaurusQuery.ctorParameters = function () { return [
1703
- { type: exports.EditThesaurusStore }
1704
- ]; };
1705
-
1706
- var EditThesaurusService = /** @class */ (function () {
1707
- function EditThesaurusService(_store, _thesaurusService) {
1708
- this._store = _store;
1709
- this._thesaurusService = _thesaurusService;
1710
- }
1711
- EditThesaurusService.prototype.load = function (id) {
1712
- var _this = this;
1713
- this._store.setLoading(true);
1714
- if (id) {
1715
- this._thesaurusService.getThesaurus(id, true).subscribe(function (thesaurus) {
1716
- _this._store.setLoading(false);
1717
- _this._store.update({
1718
- thesaurus: thesaurus,
1719
- });
1720
- }, function (error) {
1721
- console.error(error);
1722
- _this._store.setLoading(false);
1723
- _this._store.setError('Error loading thesaurus ' + id);
1724
- });
1725
- }
1726
- else {
1727
- this._store.update({
1728
- thesaurus: {
1729
- id: null,
1730
- language: 'en',
1731
- entries: [],
1732
- },
1733
- });
1734
- }
1735
- };
1736
- EditThesaurusService.prototype.reset = function () {
1737
- this._store.reset();
1738
- };
1739
- EditThesaurusService.prototype.save = function (thesaurus) {
1740
- var _this = this;
1741
- this._store.setSaving(true);
1742
- return new Promise(function (resolve, reject) {
1743
- _this._thesaurusService.addThesaurus(thesaurus).subscribe(function (saved) {
1744
- _this._store.setSaving(false);
1745
- _this.load(_this._store.getValue().thesaurus.id);
1746
- resolve(saved);
1747
- }, function (error) {
1748
- console.error(error);
1749
- _this._store.setSaving(false);
1750
- _this._store.setError('Error saving thesaurus');
1751
- reject(error);
1752
- });
1753
- });
1754
- };
1755
- return EditThesaurusService;
1756
- }());
1757
- EditThesaurusService.ɵprov = i0.ɵɵdefineInjectable({ factory: function EditThesaurusService_Factory() { return new EditThesaurusService(i0.ɵɵinject(exports.EditThesaurusStore), i0.ɵɵinject(i2.ThesaurusService)); }, token: EditThesaurusService, providedIn: "root" });
1758
- EditThesaurusService.decorators = [
1759
- { type: i0.Injectable, args: [{ providedIn: 'root' },] }
1760
- ];
1761
- EditThesaurusService.ctorParameters = function () { return [
1762
- { type: exports.EditThesaurusStore },
1763
- { type: i2.ThesaurusService }
1764
- ]; };
1765
-
1766
- var CadmusStateModule = /** @class */ (function () {
1767
- function CadmusStateModule() {
1768
- }
1769
- return CadmusStateModule;
1770
- }());
1771
- CadmusStateModule.decorators = [
1772
- { type: i0.NgModule, args: [{
1773
- imports: [
1774
- common.CommonModule,
1775
- // Cadmus
1776
- i2$1.CadmusCoreModule,
1777
- i2.CadmusApiModule,
1778
- cadmusMaterial.CadmusMaterialModule,
1779
- ],
1780
- },] }
1781
- ];
1782
-
1783
- /*
1784
- * Public API Surface of cadmus-state
1785
- */
1786
-
1787
- /**
1788
- * Generated bundle index. Do not edit.
1789
- */
1790
-
1791
- exports.AppQuery = AppQuery;
1792
- exports.AppService = AppService;
1793
- exports.CadmusStateModule = CadmusStateModule;
1794
- exports.EditFragmentFeatureBase = EditFragmentFeatureBase;
1795
- exports.EditFragmentQueryBase = EditFragmentQueryBase;
1796
- exports.EditFragmentServiceBase = EditFragmentServiceBase;
1797
- exports.EditItemQuery = EditItemQuery;
1798
- exports.EditItemService = EditItemService;
1799
- exports.EditLayerPartQuery = EditLayerPartQuery;
1800
- exports.EditLayerPartService = EditLayerPartService;
1801
- exports.EditPartFeatureBase = EditPartFeatureBase;
1802
- exports.EditPartQueryBase = EditPartQueryBase;
1803
- exports.EditPartServiceBase = EditPartServiceBase;
1804
- exports.EditThesaurusQuery = EditThesaurusQuery;
1805
- exports.EditThesaurusService = EditThesaurusService;
1806
- exports.editFragmentInitialState = editFragmentInitialState;
1807
- exports.editPartInitialState = editPartInitialState;
1808
-
1809
- Object.defineProperty(exports, '__esModule', { value: true });
1810
-
1811
- })));
1812
- //# sourceMappingURL=myrmidon-cadmus-state.umd.js.map