@myrmidon/cadmus-state 0.0.8 → 0.2.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 +26 -0
  5. package/esm2020/lib/cadmus-state.module.mjs +34 -0
  6. package/esm2020/lib/edit-fragment-feature-base.mjs +115 -0
  7. package/esm2020/lib/edit-fragment-query-base.mjs +32 -0
  8. package/esm2020/lib/edit-fragment-service-base.mjs +137 -0
  9. package/esm2020/lib/edit-fragment.store.mjs +39 -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 +47 -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 +53 -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 +39 -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 +37 -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.js → myrmidon-cadmus-state.mjs} +316 -255
  26. package/fesm2015/myrmidon-cadmus-state.mjs.map +1 -0
  27. package/fesm2020/myrmidon-cadmus-state.mjs +1418 -0
  28. package/fesm2020/myrmidon-cadmus-state.mjs.map +1 -0
  29. package/lib/app.query.d.ts +3 -0
  30. package/lib/app.service.d.ts +3 -0
  31. package/lib/app.store.d.ts +3 -0
  32. package/lib/cadmus-state.module.d.ts +8 -0
  33. package/lib/edit-fragment-feature-base.d.ts +45 -3
  34. package/lib/edit-fragment-query-base.d.ts +2 -2
  35. package/lib/edit-fragment-service-base.d.ts +10 -7
  36. package/lib/edit-fragment.store.d.ts +3 -0
  37. package/lib/edit-item.query.d.ts +3 -0
  38. package/lib/edit-item.service.d.ts +4 -1
  39. package/lib/edit-item.store.d.ts +3 -0
  40. package/lib/edit-layer-part.query.d.ts +3 -0
  41. package/lib/edit-layer-part.service.d.ts +5 -3
  42. package/lib/edit-layer-part.store.d.ts +3 -0
  43. package/lib/edit-part-feature-base.d.ts +42 -17
  44. package/lib/edit-part-query-base.d.ts +3 -4
  45. package/lib/edit-part-service-base.d.ts +23 -6
  46. package/lib/edit-part.store.d.ts +3 -0
  47. package/lib/edit-thesaurus.query.d.ts +3 -0
  48. package/lib/edit-thesaurus.service.d.ts +4 -1
  49. package/lib/edit-thesaurus.store.d.ts +3 -0
  50. package/myrmidon-cadmus-state.d.ts +1 -0
  51. package/package.json +25 -13
  52. package/bundles/myrmidon-cadmus-state.umd.js +0 -1758
  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 -106
  61. package/esm2015/lib/edit-fragment-query-base.js +0 -29
  62. package/esm2015/lib/edit-fragment-service-base.js +0 -126
  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 -184
  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 -238
  69. package/esm2015/lib/edit-layer-part.store.js +0 -52
  70. package/esm2015/lib/edit-part-feature-base.js +0 -107
  71. package/esm2015/lib/edit-part-query-base.js +0 -39
  72. package/esm2015/lib/edit-part-service-base.js +0 -88
  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,1758 +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('rxjs/operators'), 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', 'rxjs/operators', '@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.rxjs.operators, global.ng.common, global['@myrmidon/cadmus-material']));
5
- }(this, (function (exports, i0, akita, i2, rxjs, i2$1, operators, 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
- // delete from server
627
- this._itemService.deletePart(id).subscribe(function (_) {
628
- _this._store.setDeletingPart(false);
629
- // reload the store
630
- _this.load(_this._store.getValue().item.id);
631
- }, function (error) {
632
- console.log(error);
633
- _this._store.setDeletingPart(false);
634
- _this._store.setError('Error deleting part ' + id);
635
- });
636
- };
637
- EditItemService.prototype.addNewLayerPart = function (itemId, typeId, roleId) {
638
- var _this = this;
639
- var part = {
640
- itemId: itemId,
641
- typeId: typeId,
642
- roleId: roleId,
643
- id: null,
644
- creatorId: null,
645
- userId: null,
646
- timeCreated: new Date(),
647
- timeModified: new Date(),
648
- };
649
- this._store.setSaving();
650
- this._itemService.addPart(part).subscribe(function (_) {
651
- _this._store.setSaving(false);
652
- // reload the store
653
- _this.load(_this._store.getValue().item.id);
654
- }, function (error) {
655
- console.log(error);
656
- _this._store.setSaving(false);
657
- _this._store.setError('Error adding new layer part for item ' + itemId);
658
- });
659
- };
660
- EditItemService.prototype.setPartThesaurusScope = function (ids, scope) {
661
- var _this = this;
662
- this._store.setSaving();
663
- this._itemService.setPartThesaurusScope(ids, scope).subscribe(function (_) {
664
- _this._store.setSaving(false);
665
- // reload the store
666
- _this.load(_this._store.getValue().item.id);
667
- }, function (error) {
668
- console.log(error);
669
- _this._store.setSaving(false);
670
- _this._store.setError("Error setting item's parts scope");
671
- });
672
- };
673
- return EditItemService;
674
- }());
675
- 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" });
676
- EditItemService.decorators = [
677
- { type: i0.Injectable, args: [{ providedIn: 'root' },] }
678
- ];
679
- EditItemService.ctorParameters = function () { return [
680
- { type: exports.EditItemStore },
681
- { type: AppQuery },
682
- { type: i2.ItemService }
683
- ]; };
684
-
685
- var EditFragmentFeatureBase = /** @class */ (function () {
686
- function EditFragmentFeatureBase(_router, route, snackbar, _editFrQuery, _editFrService, _editItemQuery, _editItemService, _editLayersQuery, _editLayersService, _libraryRouteService) {
687
- var _this = this;
688
- var _a;
689
- this._router = _router;
690
- this.snackbar = snackbar;
691
- this._editFrQuery = _editFrQuery;
692
- this._editFrService = _editFrService;
693
- this._editItemQuery = _editItemQuery;
694
- this._editItemService = _editItemService;
695
- this._editLayersQuery = _editLayersQuery;
696
- this._editLayersService = _editLayersService;
697
- this._libraryRouteService = _libraryRouteService;
698
- this.itemId = route.snapshot.params.iid;
699
- this.partId = route.snapshot.params.pid;
700
- this.frTypeId = (_a = route.snapshot.url[2]) === null || _a === void 0 ? void 0 : _a.path;
701
- this.loc = route.snapshot.params.loc;
702
- this.frRoleId = route.snapshot.queryParams.frrid;
703
- // connect _stateDirty to the value of the edit state
704
- this._editFrQuery.selectDirty().subscribe(function (d) {
705
- console.log('fr-state dirty change: ' + d);
706
- _this._stateDirty = d;
707
- });
708
- }
709
- /**
710
- * Implementation of ComponentCanDeactivate. The editor can deactivate
711
- * when both its "root" form in the wrapped UI editor and the edit state
712
- * are not dirty. The form gets dirty when edited by the user; the edit
713
- * state gets dirty after a failed save attempt.
714
- */
715
- EditFragmentFeatureBase.prototype.canDeactivate = function () {
716
- // can-deactivate from dirty
717
- return !this._formDirty && !this._stateDirty;
718
- };
719
- EditFragmentFeatureBase.prototype.ensureItemLoaded = function (id) {
720
- if (!this._editItemQuery.hasItem(id)) {
721
- this._editItemService.load(id);
722
- }
723
- };
724
- EditFragmentFeatureBase.prototype.ensureLayersLoaded = function (thesauriIds) {
725
- if (!this._editLayersQuery.getValue().part) {
726
- this._editLayersService.load(this.itemId, this.partId, thesauriIds);
727
- }
728
- };
729
- EditFragmentFeatureBase.prototype.initEditor = function (thesauriIds) {
730
- this.json$ = this._editFrQuery.selectJson();
731
- this.thesauri$ = this._editFrQuery.selectThesauri();
732
- this.baseText$ = this._editLayersQuery.select(function (state) { return state.baseText; });
733
- this.frLoc = i2$1.TokenLocation.parse(this.loc);
734
- // load item if required
735
- this.ensureItemLoaded(this.itemId);
736
- // load layers if required
737
- this.ensureLayersLoaded(thesauriIds);
738
- // load fragment
739
- this._editFrService.load(this.partId, this.loc, thesauriIds);
740
- };
741
- /**
742
- * Called when the wrapped editor dirty state changes.
743
- * In the HTML template, you MUST bind this handler to the dirtyChange event
744
- * emitted by your wrapped editor (i.e. (dirtyChange)="onDirtyChange($event)").
745
- * @param value The value of the dirty state.
746
- */
747
- EditFragmentFeatureBase.prototype.onDirtyChange = function (value) {
748
- console.log('fr dirty change: ' + value);
749
- this._formDirty = value;
750
- };
751
- EditFragmentFeatureBase.prototype.save = function (json) {
752
- var _this = this;
753
- var part = JSON.parse(JSON.stringify(this._editLayersQuery.getValue().part));
754
- var fr = JSON.parse(json);
755
- var frIndex = part.fragments.findIndex(function (f) { return f.location === _this.loc; });
756
- if (frIndex > -1) {
757
- part.fragments.splice(frIndex, 1, fr);
758
- }
759
- else {
760
- part.fragments.push(fr);
761
- }
762
- this._editFrService.save(JSON.stringify(part)).then(function (p) {
763
- console.log(p.id);
764
- _this.snackbar.open('Fragment saved', 'OK', {
765
- duration: 3000,
766
- });
767
- }, function (error) {
768
- console.error(error);
769
- _this.snackbar.open('Error saving fragment', 'OK');
770
- });
771
- };
772
- EditFragmentFeatureBase.prototype.close = function () {
773
- // /items/<id>/<part-group>/<part-typeid>/<part-id>?rid=<role-id>
774
- var part = this._editLayersQuery.getValue().part;
775
- // const item = this._editItemQuery.getValue().item;
776
- // const facet: FacetDefinition = this._appQuery.getValue().facets.find(f => {
777
- // return f.id === item.facetId;
778
- // });
779
- // const partDef = facet.partDefinitions.find(d => {
780
- // return d.typeId === part.typeId && d.roleId === d.roleId;
781
- // });
782
- var editorKey = this._libraryRouteService.getEditorKeyFromPartType(part.typeId, part.roleId);
783
- var url = "/items/" + this.itemId + "/" + editorKey.partKey + "/" + part.typeId + "/" + this.partId;
784
- this._router.navigate([url], {
785
- queryParams: {
786
- rid: this.frTypeId,
787
- },
788
- });
789
- };
790
- return EditFragmentFeatureBase;
791
- }());
792
-
793
- var EditFragmentQueryBase = /** @class */ (function (_super) {
794
- __extends(EditFragmentQueryBase, _super);
795
- function EditFragmentQueryBase(store) {
796
- var _this = _super.call(this, store) || this;
797
- _this.store = store;
798
- return _this;
799
- }
800
- EditFragmentQueryBase.prototype.selectDirty = function () {
801
- return this.select(function (state) { return state.dirty; });
802
- };
803
- EditFragmentQueryBase.prototype.selectSaving = function () {
804
- return this.select(function (state) { return state.saving; });
805
- };
806
- EditFragmentQueryBase.prototype.selectJson = function () {
807
- return this.select(function (state) { return state.fragment; }).pipe(operators.map(function (fr) {
808
- // supply IDs
809
- if (fr) {
810
- return JSON.stringify(fr);
811
- }
812
- else {
813
- return '{}';
814
- }
815
- }));
816
- };
817
- EditFragmentQueryBase.prototype.selectThesauri = function () {
818
- return this.select(function (state) { return state.thesauri; });
819
- };
820
- return EditFragmentQueryBase;
821
- }(akita.Query));
822
-
823
- var editFragmentInitialState = {
824
- fragment: null,
825
- thesauri: null,
826
- dirty: false,
827
- saving: false,
828
- loading: false,
829
- error: null,
830
- };
831
- /**
832
- * General-purpose edit-fragment store. This can be used with any fragment,
833
- * so that you should only provide your fragment store, query, and service
834
- * (usually extending EditFragmentServiceBase).
835
- */
836
- exports.EditFragmentStore = /** @class */ (function (_super) {
837
- __extends(EditFragmentStore, _super);
838
- function EditFragmentStore() {
839
- return _super.call(this, editFragmentInitialState) || this;
840
- }
841
- EditFragmentStore.prototype.setDirty = function (value) {
842
- this.update({ dirty: value });
843
- };
844
- EditFragmentStore.prototype.setSaving = function (value) {
845
- this.update({ saving: value });
846
- };
847
- return EditFragmentStore;
848
- }(akita.Store));
849
- exports.EditFragmentStore.ɵprov = i0.ɵɵdefineInjectable({ factory: function EditFragmentStore_Factory() { return new exports.EditFragmentStore(); }, token: exports.EditFragmentStore, providedIn: "root" });
850
- exports.EditFragmentStore.decorators = [
851
- { type: i0.Injectable, args: [{ providedIn: 'root' },] }
852
- ];
853
- exports.EditFragmentStore.ctorParameters = function () { return []; };
854
- exports.EditFragmentStore = __decorate([
855
- akita.StoreConfig({ name: 'edit-fragment' })
856
- ], exports.EditFragmentStore);
857
-
858
- /**
859
- * Base class for fragment editing services.
860
- */
861
- var EditFragmentServiceBase = /** @class */ (function () {
862
- function EditFragmentServiceBase(_itemService, _thesaurusService) {
863
- this._itemService = _itemService;
864
- this._thesaurusService = _thesaurusService;
865
- }
866
- /**
867
- * Load the specified fragment and thesauri.
868
- *
869
- * @param partId The ID of the part the fragment belongs to.
870
- * @param loc The fragment's location.
871
- * @param thesauriIds The optional requested thesauri IDs.
872
- */
873
- EditFragmentServiceBase.prototype.load = function (partId, loc, thesauriIds) {
874
- var _this = this;
875
- if (thesauriIds === void 0) { thesauriIds = null; }
876
- this.store.setLoading(true);
877
- if (thesauriIds) {
878
- // remove trailing ! from IDs if any
879
- var unscopedIds = thesauriIds.map(function (id) {
880
- return _this._thesaurusService.getScopedId(id, null);
881
- });
882
- rxjs.forkJoin([
883
- this._itemService.getPart(partId),
884
- this._thesaurusService.getThesauriSet(unscopedIds),
885
- ]).subscribe(function (_a) {
886
- var _b = __read(_a, 2), part = _b[0], thesauri = _b[1];
887
- var layerPart = part;
888
- var fr = layerPart.fragments.find(function (f) { return f.location === loc; });
889
- if (!fr) {
890
- // not found: new fragment
891
- _this.store.update({
892
- fragment: {
893
- location: loc,
894
- },
895
- thesauri: thesauri,
896
- loading: false,
897
- error: null,
898
- });
899
- }
900
- else {
901
- // found: existing fragment
902
- _this.store.update({
903
- fragment: fr,
904
- thesauri: thesauri,
905
- loading: false,
906
- error: null,
907
- });
908
- }
909
- // if the loaded layer part has a thesaurus scope, reload the thesauri
910
- if (part.thesaurusScope) {
911
- var scopedIds_1 = thesauriIds.map(function (id) {
912
- return _this._thesaurusService.getScopedId(id, part.thesaurusScope);
913
- });
914
- _this.store.setLoading(true);
915
- _this._thesaurusService.getThesauriSet(scopedIds_1).subscribe(function (scopedThesauri) {
916
- _this.store.update({
917
- thesauri: scopedThesauri,
918
- });
919
- }, function (error) {
920
- console.error(error);
921
- _this.store.setLoading(false);
922
- _this.store.setError('Error loading thesauri ' + scopedIds_1.join(', '));
923
- });
924
- } // scoped
925
- });
926
- }
927
- else {
928
- this._itemService.getPart(partId).subscribe(function (part) {
929
- var layerPart = part;
930
- var fr = layerPart.fragments.find(function (f) { return f.location === loc; });
931
- if (!fr) {
932
- // not found: new fragment
933
- _this.store.update({
934
- fragment: {
935
- location: loc,
936
- },
937
- loading: false,
938
- error: null,
939
- });
940
- }
941
- else {
942
- _this.store.update({
943
- fragment: fr,
944
- loading: false,
945
- error: null,
946
- });
947
- }
948
- }, function (error) {
949
- console.error(error);
950
- _this.store.setLoading(false);
951
- _this.store.setError('Error loading part ' + partId);
952
- });
953
- }
954
- };
955
- /**
956
- * Save the fragments serialized into the specified JSON code
957
- * representing their part.
958
- *
959
- * @param json The JSON code representing the fragment.
960
- * @returns Promise which when successful returns the
961
- * saved part (which contains the fragment being saved).
962
- */
963
- EditFragmentServiceBase.prototype.save = function (json) {
964
- var _this = this;
965
- this.store.setSaving(true);
966
- this.store.setDirty(true);
967
- return new Promise(function (resolve, reject) {
968
- _this._itemService.addPartJson(json).subscribe(function (part) {
969
- _this.store.update({ part: part });
970
- _this.store.setSaving(false);
971
- _this.store.setDirty(false);
972
- _this.store.setError(null);
973
- resolve(part);
974
- }, function (error) {
975
- console.error(error);
976
- _this.store.setSaving(false);
977
- _this.store.setError('Error saving fragment');
978
- reject(error);
979
- });
980
- });
981
- };
982
- EditFragmentServiceBase.prototype.setDirty = function (value) {
983
- if (value === void 0) { value = true; }
984
- this.store.setDirty(value);
985
- };
986
- return EditFragmentServiceBase;
987
- }());
988
-
989
- /**
990
- * Base class for part feature editors.
991
- * A part feature editor is a wrapper component, linking a part edit state
992
- * (accessed from a part query and loaded with a part service) to a corresponding
993
- * child UI editor.
994
- * It implements ComponentCanDeactivate to allow using the PendingChangesGuard.
995
- * To this end, it tracks the dirty state of the edited data coming from 2
996
- * different sources: the wrapped editor state (from its "root" form), and
997
- * the store edit state. This is set to dirty when a save attempt fails.
998
- * Thus, at the end the user will be prompted when closing an editor either
999
- * because he has changed data in it, or because he attempted a save without
1000
- * success.
1001
- */
1002
- var EditPartFeatureBase = /** @class */ (function () {
1003
- function EditPartFeatureBase(router, route, snackbar, _editPartQuery, _editPartService, _editItemQuery, _editItemService) {
1004
- var _this = this;
1005
- this.router = router;
1006
- this.snackbar = snackbar;
1007
- this._editPartQuery = _editPartQuery;
1008
- this._editPartService = _editPartService;
1009
- this._editItemQuery = _editItemQuery;
1010
- this._editItemService = _editItemService;
1011
- this.itemId = route.snapshot.params.iid;
1012
- this.partId = route.snapshot.params.pid;
1013
- if (this.partId === 'new') {
1014
- this.partId = null;
1015
- }
1016
- this.roleId = route.snapshot.queryParams.rid;
1017
- if (this.roleId === 'default') {
1018
- this.roleId = null;
1019
- }
1020
- // connect _stateDirty to the value of the edit state
1021
- this._editPartQuery.selectDirty().subscribe(function (d) {
1022
- console.log('part-state dirty change: ' + d);
1023
- _this._stateDirty = d;
1024
- });
1025
- }
1026
- /**
1027
- * Implementation of ComponentCanDeactivate. The editor can deactivate
1028
- * when both its "root" form in the wrapped UI editor and the edit state
1029
- * are not dirty. The form gets dirty when edited by the user; the edit
1030
- * state gets dirty after a failed save attempt.
1031
- */
1032
- EditPartFeatureBase.prototype.canDeactivate = function () {
1033
- // can-deactivate from dirty
1034
- return !this._formDirty && !this._stateDirty;
1035
- };
1036
- EditPartFeatureBase.prototype.ensureItemLoaded = function (id) {
1037
- if (!this._editItemQuery.hasItem(id)) {
1038
- this._editItemService.load(id);
1039
- }
1040
- };
1041
- /**
1042
- * Initialize the editor. You MUST call this in your OnInit.
1043
- * @param thesauriIds The optional ID(s) of the thesauri sets you want
1044
- * to use in your editor.
1045
- */
1046
- EditPartFeatureBase.prototype.initEditor = function (thesauriIds) {
1047
- var _this = this;
1048
- this.json$ = new rxjs.BehaviorSubject('{}');
1049
- this._editPartQuery.selectJson(this.itemId, this.partId, this.roleId).subscribe(function (json) {
1050
- _this.json$.next(json);
1051
- });
1052
- this.thesauri$ = this._editPartQuery.selectThesauri();
1053
- // load item if required
1054
- this.ensureItemLoaded(this.itemId);
1055
- // load part (none if new) and thesauri
1056
- this._editPartService.load(this.partId, thesauriIds);
1057
- };
1058
- /**
1059
- * Called when the wrapped editor dirty state changes.
1060
- * In the HTML template, you MUST bind this handler to the dirtyChange event
1061
- * emitted by your wrapped editor (i.e. (dirtyChange)="onDirtyChange($event)").
1062
- * @param value The value of the dirty state.
1063
- */
1064
- EditPartFeatureBase.prototype.onDirtyChange = function (value) {
1065
- console.log('part dirty change: ' + value);
1066
- this._formDirty = value;
1067
- };
1068
- /**
1069
- * Save the part.
1070
- * @param json The JSON code representing the edited part.
1071
- */
1072
- EditPartFeatureBase.prototype.save = function (json) {
1073
- var _this = this;
1074
- this._editPartService.save(json).then(function (part) {
1075
- // update part ID if it was null (new part)
1076
- if (!_this.partId) {
1077
- _this.partId = part.id;
1078
- }
1079
- console.log('Part saved: ' + part.id);
1080
- // emit the updated saved part
1081
- _this.json$.next(json);
1082
- _this.snackbar.open('Part saved', 'OK', {
1083
- duration: 3000,
1084
- });
1085
- }, function (error) {
1086
- console.error(error);
1087
- _this.snackbar.open('Error saving part', 'OK');
1088
- });
1089
- };
1090
- /**
1091
- * Close the editor by navigating back to the part's item.
1092
- */
1093
- EditPartFeatureBase.prototype.close = function () {
1094
- this.router.navigate(['items', this.itemId]);
1095
- };
1096
- return EditPartFeatureBase;
1097
- }());
1098
-
1099
- /**
1100
- * Base class for implementing editor part queries.
1101
- * To implement an editor part query, just extend this passing the specialized
1102
- * part's store to the constructor.
1103
- */
1104
- var EditPartQueryBase = /** @class */ (function (_super) {
1105
- __extends(EditPartQueryBase, _super);
1106
- function EditPartQueryBase(store, _utilService) {
1107
- var _this = _super.call(this, store) || this;
1108
- _this.store = store;
1109
- _this._utilService = _utilService;
1110
- return _this;
1111
- }
1112
- EditPartQueryBase.prototype.selectDirty = function () {
1113
- return this.select(function (state) { return state.dirty; });
1114
- };
1115
- EditPartQueryBase.prototype.selectSaving = function () {
1116
- return this.select(function (state) { return state.saving; });
1117
- };
1118
- EditPartQueryBase.prototype.selectJson = function (itemId, partId, roleId) {
1119
- var _this = this;
1120
- return this.select(function (state) { return state.part; }).pipe(operators.map(function (part) {
1121
- // supply IDs
1122
- if (part) {
1123
- var clone = _this._utilService.deepCopy(part);
1124
- clone.itemId = itemId;
1125
- clone.id = partId;
1126
- clone.roleId = roleId;
1127
- return JSON.stringify(clone);
1128
- }
1129
- else {
1130
- return '{}';
1131
- }
1132
- }));
1133
- };
1134
- EditPartQueryBase.prototype.selectThesauri = function () {
1135
- return this.select(function (state) { return state.thesauri; });
1136
- };
1137
- return EditPartQueryBase;
1138
- }(akita.Query));
1139
-
1140
- var EditPartServiceBase = /** @class */ (function () {
1141
- function EditPartServiceBase(itemService, thesaurusService) {
1142
- this.itemService = itemService;
1143
- this.thesaurusService = thesaurusService;
1144
- }
1145
- EditPartServiceBase.prototype.load = function (partId, thesauriIds) {
1146
- var _this = this;
1147
- if (thesauriIds === void 0) { thesauriIds = null; }
1148
- this.store.setLoading(true);
1149
- if (thesauriIds) {
1150
- // remove trailing ! from IDs if any
1151
- var unscopedIds = thesauriIds.map(function (id) {
1152
- return _this.thesaurusService.getScopedId(id, null);
1153
- });
1154
- rxjs.forkJoin({
1155
- part: this.itemService.getPart(partId),
1156
- thesauri: this.thesaurusService.getThesauriSet(unscopedIds),
1157
- }).subscribe(function (result) {
1158
- var _a;
1159
- _this.store.setLoading(false);
1160
- _this.store.update({
1161
- part: result.part,
1162
- thesauri: result.thesauri,
1163
- });
1164
- // if the loaded part has a thesaurus scope, reload the thesauri
1165
- if ((_a = result.part) === null || _a === void 0 ? void 0 : _a.thesaurusScope) {
1166
- var scopedIds_1 = thesauriIds.map(function (id) {
1167
- return _this.thesaurusService.getScopedId(id, result.part.thesaurusScope);
1168
- });
1169
- _this.store.setLoading(true);
1170
- _this.thesaurusService.getThesauriSet(thesauriIds).subscribe(function (thesauri) {
1171
- _this.store.update({
1172
- thesauri: thesauri,
1173
- });
1174
- }, function (error) {
1175
- console.error(error);
1176
- _this.store.setLoading(false);
1177
- _this.store.setError('Error loading thesauri ' + scopedIds_1.join(', '));
1178
- });
1179
- } // scoped
1180
- });
1181
- }
1182
- else {
1183
- if (!partId) {
1184
- return;
1185
- }
1186
- this.itemService.getPart(partId).subscribe(function (part) {
1187
- _this.store.update({
1188
- part: part,
1189
- loading: false,
1190
- error: null,
1191
- });
1192
- }, function (error) {
1193
- console.error(error);
1194
- _this.store.setLoading(false);
1195
- _this.store.setError('Error loading part ' + partId);
1196
- });
1197
- }
1198
- };
1199
- /**
1200
- * Save the JSON code representing a part.
1201
- *
1202
- * @param json The JSON code representing the part.
1203
- * @returns Promise which when successful returns the
1204
- * saved part.
1205
- */
1206
- EditPartServiceBase.prototype.save = function (json) {
1207
- var _this = this;
1208
- this.store.setSaving(true);
1209
- this.store.setDirty(true);
1210
- return new Promise(function (resolve, reject) {
1211
- _this.itemService.addPartJson(json).subscribe(function (part) {
1212
- _this.store.update({ part: part });
1213
- _this.store.setSaving(false);
1214
- _this.store.setDirty(false);
1215
- _this.store.setError(null);
1216
- resolve(part);
1217
- }, function (error) {
1218
- console.error(error);
1219
- _this.store.setSaving(false);
1220
- _this.store.setError('Error saving part');
1221
- reject(error);
1222
- });
1223
- });
1224
- };
1225
- EditPartServiceBase.prototype.setDirty = function (value) {
1226
- if (value === void 0) { value = true; }
1227
- this.store.setDirty(value);
1228
- };
1229
- return EditPartServiceBase;
1230
- }());
1231
-
1232
- var editPartInitialState = {
1233
- part: null,
1234
- thesauri: null,
1235
- dirty: false,
1236
- saving: false,
1237
- loading: false,
1238
- error: null
1239
- };
1240
- /**
1241
- * General-purpose edit-part store. This can be used with any part, so that
1242
- * you should only provide your part store, query, and service (usually
1243
- * extending EditPartServiceBase).
1244
- */
1245
- exports.EditPartStore = /** @class */ (function (_super) {
1246
- __extends(EditPartStore, _super);
1247
- function EditPartStore() {
1248
- return _super.call(this, editPartInitialState) || this;
1249
- }
1250
- EditPartStore.prototype.setDirty = function (value) {
1251
- this.update({ dirty: value });
1252
- };
1253
- EditPartStore.prototype.setSaving = function (value) {
1254
- this.update({ saving: value });
1255
- };
1256
- return EditPartStore;
1257
- }(akita.Store));
1258
- exports.EditPartStore.ɵprov = i0.ɵɵdefineInjectable({ factory: function EditPartStore_Factory() { return new exports.EditPartStore(); }, token: exports.EditPartStore, providedIn: "root" });
1259
- exports.EditPartStore.decorators = [
1260
- { type: i0.Injectable, args: [{ providedIn: 'root' },] }
1261
- ];
1262
- exports.EditPartStore.ctorParameters = function () { return []; };
1263
- exports.EditPartStore = __decorate([
1264
- akita.StoreConfig({ name: 'edit-part' })
1265
- ], exports.EditPartStore);
1266
-
1267
- var initialState$2 = {
1268
- part: null,
1269
- baseText: null,
1270
- baseTextPart: null,
1271
- locations: [],
1272
- breakChance: -1,
1273
- layerHints: [],
1274
- thesauri: {},
1275
- loading: false,
1276
- error: null,
1277
- deletingFragment: false,
1278
- savingFragment: false,
1279
- refreshingBreakChance: false,
1280
- patchingLayer: false,
1281
- };
1282
- exports.EditLayerPartStore = /** @class */ (function (_super) {
1283
- __extends(EditLayerPartStore, _super);
1284
- function EditLayerPartStore() {
1285
- return _super.call(this, initialState$2) || this;
1286
- }
1287
- EditLayerPartStore.prototype.setDeletingFragment = function (value) {
1288
- if (value === void 0) { value = true; }
1289
- this.update({ deletingFragment: value });
1290
- };
1291
- EditLayerPartStore.prototype.setSavingFragment = function (value) {
1292
- if (value === void 0) { value = true; }
1293
- this.update({ savingFragment: value });
1294
- };
1295
- EditLayerPartStore.prototype.setRefreshingBreakChance = function (value) {
1296
- if (value === void 0) { value = true; }
1297
- this.update({ refreshingBreakChance: value });
1298
- };
1299
- EditLayerPartStore.prototype.setBreakChance = function (value) {
1300
- this.update({ breakChance: value });
1301
- };
1302
- EditLayerPartStore.prototype.setPatchingLayer = function (value) {
1303
- if (value === void 0) { value = true; }
1304
- this.update({ patchingLayer: value });
1305
- };
1306
- EditLayerPartStore.prototype.setLocations = function (locations) {
1307
- this.update({ locations: locations });
1308
- };
1309
- return EditLayerPartStore;
1310
- }(akita.Store));
1311
- exports.EditLayerPartStore.ɵprov = i0.ɵɵdefineInjectable({ factory: function EditLayerPartStore_Factory() { return new exports.EditLayerPartStore(); }, token: exports.EditLayerPartStore, providedIn: "root" });
1312
- exports.EditLayerPartStore.decorators = [
1313
- { type: i0.Injectable, args: [{ providedIn: 'root' },] }
1314
- ];
1315
- exports.EditLayerPartStore.ctorParameters = function () { return []; };
1316
- exports.EditLayerPartStore = __decorate([
1317
- akita.StoreConfig({ name: 'edit-layer-part' })
1318
- ], exports.EditLayerPartStore);
1319
-
1320
- var EditLayerPartQuery = /** @class */ (function (_super) {
1321
- __extends(EditLayerPartQuery, _super);
1322
- function EditLayerPartQuery(store) {
1323
- var _this = _super.call(this, store) || this;
1324
- _this.store = store;
1325
- return _this;
1326
- }
1327
- EditLayerPartQuery.prototype.selectDeletingFragment = function () {
1328
- return this.select(function (state) { return state.deletingFragment; });
1329
- };
1330
- EditLayerPartQuery.prototype.selectSavingFragment = function () {
1331
- return this.select(function (state) { return state.savingFragment; });
1332
- };
1333
- EditLayerPartQuery.prototype.selectRefreshingBreakChance = function () {
1334
- return this.select(function (state) { return state.refreshingBreakChance; });
1335
- };
1336
- EditLayerPartQuery.prototype.selectBreakChance = function () {
1337
- return this.select(function (state) { return state.breakChance; });
1338
- };
1339
- EditLayerPartQuery.prototype.selectLayerHints = function () {
1340
- return this.select(function (state) { return state.layerHints; });
1341
- };
1342
- EditLayerPartQuery.prototype.selectPatchingLayers = function () {
1343
- return this.select(function (state) { return state.patchingLayer; });
1344
- };
1345
- return EditLayerPartQuery;
1346
- }(akita.Query));
1347
- EditLayerPartQuery.ɵprov = i0.ɵɵdefineInjectable({ factory: function EditLayerPartQuery_Factory() { return new EditLayerPartQuery(i0.ɵɵinject(exports.EditLayerPartStore)); }, token: EditLayerPartQuery, providedIn: "root" });
1348
- EditLayerPartQuery.decorators = [
1349
- { type: i0.Injectable, args: [{ providedIn: 'root' },] }
1350
- ];
1351
- EditLayerPartQuery.ctorParameters = function () { return [
1352
- { type: exports.EditLayerPartStore }
1353
- ]; };
1354
-
1355
- var EditLayerPartService = /** @class */ (function () {
1356
- function EditLayerPartService(_store, _itemService, _facetService, _utilService, _thesaurusService) {
1357
- this._store = _store;
1358
- this._itemService = _itemService;
1359
- this._facetService = _facetService;
1360
- this._utilService = _utilService;
1361
- this._thesaurusService = _thesaurusService;
1362
- }
1363
- EditLayerPartService.prototype.getLocations = function (part) {
1364
- var locations = [];
1365
- if (part && part.fragments) {
1366
- part.fragments.forEach(function (p) {
1367
- locations.push(i2$1.TokenLocation.parse(p.location));
1368
- });
1369
- }
1370
- return locations;
1371
- };
1372
- /**
1373
- * Load the state for editing layer part(s).
1374
- *
1375
- * @param itemId The item ID the layer part belongs to.
1376
- * @param partId The layer part ID.
1377
- * @param thesauriIds The optional thesauri IDs to load.
1378
- */
1379
- EditLayerPartService.prototype.load = function (itemId, partId, thesauriIds) {
1380
- var _this = this;
1381
- if (thesauriIds === void 0) { thesauriIds = null; }
1382
- if (this._store.getValue().loading) {
1383
- return;
1384
- }
1385
- this._store.setLoading(true);
1386
- if (thesauriIds) {
1387
- // remove trailing ! from IDs if any
1388
- var unscopedIds = thesauriIds.map(function (id) {
1389
- return _this._thesaurusService.getScopedId(id, null);
1390
- });
1391
- rxjs.forkJoin({
1392
- // TODO: eventually optimize by adding method param to load only fragments locations
1393
- layerPart: this._itemService.getPart(partId),
1394
- baseText: this._itemService.getBaseTextPart(itemId),
1395
- layers: this._facetService.getFacetParts(itemId, true),
1396
- breakChance: this._itemService.getLayerPartBreakChance(partId),
1397
- layerHints: this._itemService.getLayerPartHints(partId),
1398
- thesauri: this._thesaurusService.getThesauriSet(unscopedIds),
1399
- }).subscribe(function (result) {
1400
- _this._store.update({
1401
- part: result.layerPart,
1402
- baseText: result.baseText.text,
1403
- baseTextPart: result.baseText.part,
1404
- locations: _this.getLocations(result.layerPart),
1405
- breakChance: result.breakChance.chance,
1406
- layerHints: result.layerHints,
1407
- thesauri: result.thesauri,
1408
- loading: false,
1409
- error: null,
1410
- });
1411
- // if the loaded part has a thesaurus scope, reload the thesauri
1412
- if (result.layerPart.thesaurusScope) {
1413
- var scopedIds_1 = thesauriIds.map(function (id) {
1414
- return _this._thesaurusService.getScopedId(id, result.layerPart.thesaurusScope);
1415
- });
1416
- _this._store.setLoading(true);
1417
- _this._thesaurusService.getThesauriSet(scopedIds_1).subscribe(function (thesauri) {
1418
- _this._store.update({
1419
- thesauri: thesauri,
1420
- });
1421
- }, function (error) {
1422
- console.error(error);
1423
- _this._store.setLoading(false);
1424
- _this._store.setError('Error loading thesauri ' + scopedIds_1.join(', '));
1425
- });
1426
- } // scoped
1427
- }, function (error) {
1428
- console.error(error);
1429
- _this._store.setLoading(false);
1430
- _this._store.setError('Error loading text layer part ' + partId);
1431
- });
1432
- }
1433
- else {
1434
- rxjs.forkJoin({
1435
- // TODO: eventually optimize by adding method param to load only fragments locations
1436
- layerPart: this._itemService.getPart(partId),
1437
- baseText: this._itemService.getBaseTextPart(itemId),
1438
- layers: this._facetService.getFacetParts(itemId, true),
1439
- breakChance: this._itemService.getLayerPartBreakChance(partId),
1440
- layerHints: this._itemService.getLayerPartHints(partId),
1441
- }).subscribe(function (result) {
1442
- _this._store.update({
1443
- part: result.layerPart,
1444
- baseText: result.baseText.text,
1445
- baseTextPart: result.baseText.part,
1446
- locations: _this.getLocations(result.layerPart),
1447
- breakChance: result.breakChance.chance,
1448
- layerHints: result.layerHints,
1449
- loading: false,
1450
- error: null,
1451
- });
1452
- }, function (error) {
1453
- console.error(error);
1454
- _this._store.setLoading(false);
1455
- _this._store.setError('Error loading text layer part ' + partId);
1456
- });
1457
- }
1458
- };
1459
- /**
1460
- * Refresh the layer part break chance.
1461
- */
1462
- EditLayerPartService.prototype.refreshBreakChance = function () {
1463
- var _this = this;
1464
- var store = this._store.getValue();
1465
- var part = store.part;
1466
- if (!part || store.refreshingBreakChance) {
1467
- return;
1468
- }
1469
- this._store.setRefreshingBreakChance(true);
1470
- this._itemService.getLayerPartBreakChance(part.id).subscribe(function (result) {
1471
- _this._store.setRefreshingBreakChance(false);
1472
- _this._store.setBreakChance(result.chance);
1473
- }, function (error) {
1474
- console.error(error);
1475
- _this._store.setRefreshingBreakChance(false);
1476
- _this._store.setBreakChance(-1);
1477
- _this._store.setError('Error refreshing break chance for text layer part ' + part.id);
1478
- });
1479
- };
1480
- EditLayerPartService.prototype.applyLayerPatches = function (partId, patches) {
1481
- var _this = this;
1482
- this._store.setPatchingLayer(true);
1483
- this._itemService.applyLayerPatches(partId, patches).subscribe(function (part) {
1484
- _this._store.setPatchingLayer(false);
1485
- _this.load(part.itemId, partId);
1486
- }, function (error) {
1487
- console.error(error);
1488
- _this._store.setPatchingLayer(false);
1489
- _this._store.setError('Error patching text layer part ' + partId);
1490
- });
1491
- };
1492
- /**
1493
- * Delete the fragment at the specified location.
1494
- *
1495
- * @param loc The fragment's location.
1496
- */
1497
- EditLayerPartService.prototype.deleteFragment = function (loc) {
1498
- var _this = this;
1499
- this._store.setDeletingFragment(true);
1500
- // find the fragment
1501
- var part = this._store.getValue().part;
1502
- if (!part) {
1503
- return;
1504
- }
1505
- var i = part.fragments.findIndex(function (p) {
1506
- return i2$1.TokenLocation.parse(p.location).overlaps(loc);
1507
- });
1508
- if (i === -1) {
1509
- return;
1510
- }
1511
- // remove it from the part
1512
- // work on a copy, as store objects are immutable
1513
- part = this._utilService.deepCopy(part);
1514
- part.fragments.splice(i, 1);
1515
- // update the part and reload state once done
1516
- this._itemService.addPart(part).subscribe(function (_) {
1517
- _this._store.setDeletingFragment(false);
1518
- _this.load(part.itemId, part.id);
1519
- // this._store.update({
1520
- // part: part,
1521
- // deletingFragment: false,
1522
- // error: null
1523
- // });
1524
- }, function (error) {
1525
- console.error(error);
1526
- _this._store.setDeletingFragment(false);
1527
- _this._store.setError("Error deleting fragment at " + loc + " in part " + part.id);
1528
- });
1529
- };
1530
- /**
1531
- * Save the specified fragment.
1532
- *
1533
- * @param fragment The fragment.
1534
- */
1535
- EditLayerPartService.prototype.saveFragment = function (fragment) {
1536
- var _this = this;
1537
- this._store.setSavingFragment();
1538
- // find the fragment
1539
- var part = this._store.getValue().part;
1540
- if (!part) {
1541
- return;
1542
- }
1543
- // add or replace it
1544
- // work on a copy, as store objects are immutable
1545
- part = this._utilService.deepCopy(part);
1546
- // replace all the overlapping fragments with the new one
1547
- var newLoc = i2$1.TokenLocation.parse(fragment.location);
1548
- var insertAt = 0;
1549
- for (var i = part.fragments.length - 1; i > -1; i--) {
1550
- var frLoc = i2$1.TokenLocation.parse(part.fragments[i].location);
1551
- if (newLoc.compareTo(frLoc) >= 0) {
1552
- insertAt = i + 1;
1553
- }
1554
- if (newLoc.overlaps(frLoc)) {
1555
- part.fragments.splice(i, 1);
1556
- if (insertAt > i && insertAt > 0) {
1557
- insertAt--;
1558
- }
1559
- }
1560
- }
1561
- // add the new fragment
1562
- part.fragments.splice(insertAt, 0, fragment);
1563
- // update the part and reload once done
1564
- this._itemService.addPart(part).subscribe(function (_) {
1565
- _this.load(part.itemId, part.id);
1566
- // this._store.update({
1567
- // part: part,
1568
- // deletingFragment: false,
1569
- // error: null
1570
- // });
1571
- }, function (error) {
1572
- console.error(error);
1573
- _this._store.setSavingFragment(false);
1574
- _this._store.setError("Error saving fragment at " + fragment.location + " in part " + part.id);
1575
- });
1576
- };
1577
- return EditLayerPartService;
1578
- }());
1579
- 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$1.UtilService), i0.ɵɵinject(i2.ThesaurusService)); }, token: EditLayerPartService, providedIn: "root" });
1580
- EditLayerPartService.decorators = [
1581
- { type: i0.Injectable, args: [{ providedIn: 'root' },] }
1582
- ];
1583
- EditLayerPartService.ctorParameters = function () { return [
1584
- { type: exports.EditLayerPartStore },
1585
- { type: i2.ItemService },
1586
- { type: i2.FacetService },
1587
- { type: i2$1.UtilService },
1588
- { type: i2.ThesaurusService }
1589
- ]; };
1590
-
1591
- var initialState$3 = {
1592
- thesaurus: null,
1593
- dirty: false,
1594
- saving: false,
1595
- loading: false,
1596
- error: null,
1597
- };
1598
- exports.EditThesaurusStore = /** @class */ (function (_super) {
1599
- __extends(EditThesaurusStore, _super);
1600
- function EditThesaurusStore() {
1601
- return _super.call(this, initialState$3) || this;
1602
- }
1603
- EditThesaurusStore.prototype.setDirty = function (value) {
1604
- if (value === void 0) { value = true; }
1605
- this.update({
1606
- dirty: value,
1607
- });
1608
- };
1609
- EditThesaurusStore.prototype.setSaving = function (value) {
1610
- if (value === void 0) { value = true; }
1611
- this.update({
1612
- saving: value,
1613
- });
1614
- };
1615
- return EditThesaurusStore;
1616
- }(akita.Store));
1617
- exports.EditThesaurusStore.ɵprov = i0.ɵɵdefineInjectable({ factory: function EditThesaurusStore_Factory() { return new exports.EditThesaurusStore(); }, token: exports.EditThesaurusStore, providedIn: "root" });
1618
- exports.EditThesaurusStore.decorators = [
1619
- { type: i0.Injectable, args: [{ providedIn: 'root' },] }
1620
- ];
1621
- exports.EditThesaurusStore.ctorParameters = function () { return []; };
1622
- exports.EditThesaurusStore = __decorate([
1623
- akita.StoreConfig({ name: 'edit-thesaurus', resettable: true })
1624
- ], exports.EditThesaurusStore);
1625
-
1626
- var EditThesaurusQuery = /** @class */ (function (_super) {
1627
- __extends(EditThesaurusQuery, _super);
1628
- function EditThesaurusQuery(store) {
1629
- var _this = _super.call(this, store) || this;
1630
- _this.store = store;
1631
- return _this;
1632
- }
1633
- EditThesaurusQuery.prototype.selectThesaurus = function () {
1634
- return this.select(function (state) { return state.thesaurus; });
1635
- };
1636
- EditThesaurusQuery.prototype.selectLoading = function () {
1637
- return this.select(function (state) { return state.loading; });
1638
- };
1639
- EditThesaurusQuery.prototype.selectSaving = function () {
1640
- return this.select(function (state) { return state.saving; });
1641
- };
1642
- return EditThesaurusQuery;
1643
- }(akita.Query));
1644
- EditThesaurusQuery.ɵprov = i0.ɵɵdefineInjectable({ factory: function EditThesaurusQuery_Factory() { return new EditThesaurusQuery(i0.ɵɵinject(exports.EditThesaurusStore)); }, token: EditThesaurusQuery, providedIn: "root" });
1645
- EditThesaurusQuery.decorators = [
1646
- { type: i0.Injectable, args: [{ providedIn: 'root' },] }
1647
- ];
1648
- EditThesaurusQuery.ctorParameters = function () { return [
1649
- { type: exports.EditThesaurusStore }
1650
- ]; };
1651
-
1652
- var EditThesaurusService = /** @class */ (function () {
1653
- function EditThesaurusService(_store, _thesaurusService) {
1654
- this._store = _store;
1655
- this._thesaurusService = _thesaurusService;
1656
- }
1657
- EditThesaurusService.prototype.load = function (id) {
1658
- var _this = this;
1659
- this._store.setLoading(true);
1660
- if (id) {
1661
- this._thesaurusService.getThesaurus(id, true).subscribe(function (thesaurus) {
1662
- _this._store.setLoading(false);
1663
- _this._store.update({
1664
- thesaurus: thesaurus,
1665
- });
1666
- }, function (error) {
1667
- console.error(error);
1668
- _this._store.setLoading(false);
1669
- _this._store.setError('Error loading thesaurus ' + id);
1670
- });
1671
- }
1672
- else {
1673
- this._store.update({
1674
- thesaurus: {
1675
- id: null,
1676
- language: 'en',
1677
- entries: [],
1678
- },
1679
- });
1680
- }
1681
- };
1682
- EditThesaurusService.prototype.reset = function () {
1683
- this._store.reset();
1684
- };
1685
- EditThesaurusService.prototype.save = function (thesaurus) {
1686
- var _this = this;
1687
- this._store.setSaving(true);
1688
- return new Promise(function (resolve, reject) {
1689
- _this._thesaurusService.addThesaurus(thesaurus).subscribe(function (saved) {
1690
- _this._store.setSaving(false);
1691
- _this.load(_this._store.getValue().thesaurus.id);
1692
- resolve(saved);
1693
- }, function (error) {
1694
- console.error(error);
1695
- _this._store.setSaving(false);
1696
- _this._store.setError('Error saving thesaurus');
1697
- reject(error);
1698
- });
1699
- });
1700
- };
1701
- return EditThesaurusService;
1702
- }());
1703
- EditThesaurusService.ɵprov = i0.ɵɵdefineInjectable({ factory: function EditThesaurusService_Factory() { return new EditThesaurusService(i0.ɵɵinject(exports.EditThesaurusStore), i0.ɵɵinject(i2.ThesaurusService)); }, token: EditThesaurusService, providedIn: "root" });
1704
- EditThesaurusService.decorators = [
1705
- { type: i0.Injectable, args: [{ providedIn: 'root' },] }
1706
- ];
1707
- EditThesaurusService.ctorParameters = function () { return [
1708
- { type: exports.EditThesaurusStore },
1709
- { type: i2.ThesaurusService }
1710
- ]; };
1711
-
1712
- var CadmusStateModule = /** @class */ (function () {
1713
- function CadmusStateModule() {
1714
- }
1715
- return CadmusStateModule;
1716
- }());
1717
- CadmusStateModule.decorators = [
1718
- { type: i0.NgModule, args: [{
1719
- imports: [
1720
- common.CommonModule,
1721
- // Cadmus
1722
- i2$1.CadmusCoreModule,
1723
- i2.CadmusApiModule,
1724
- cadmusMaterial.CadmusMaterialModule,
1725
- ],
1726
- },] }
1727
- ];
1728
-
1729
- /*
1730
- * Public API Surface of cadmus-state
1731
- */
1732
-
1733
- /**
1734
- * Generated bundle index. Do not edit.
1735
- */
1736
-
1737
- exports.AppQuery = AppQuery;
1738
- exports.AppService = AppService;
1739
- exports.CadmusStateModule = CadmusStateModule;
1740
- exports.EditFragmentFeatureBase = EditFragmentFeatureBase;
1741
- exports.EditFragmentQueryBase = EditFragmentQueryBase;
1742
- exports.EditFragmentServiceBase = EditFragmentServiceBase;
1743
- exports.EditItemQuery = EditItemQuery;
1744
- exports.EditItemService = EditItemService;
1745
- exports.EditLayerPartQuery = EditLayerPartQuery;
1746
- exports.EditLayerPartService = EditLayerPartService;
1747
- exports.EditPartFeatureBase = EditPartFeatureBase;
1748
- exports.EditPartQueryBase = EditPartQueryBase;
1749
- exports.EditPartServiceBase = EditPartServiceBase;
1750
- exports.EditThesaurusQuery = EditThesaurusQuery;
1751
- exports.EditThesaurusService = EditThesaurusService;
1752
- exports.editFragmentInitialState = editFragmentInitialState;
1753
- exports.editPartInitialState = editPartInitialState;
1754
-
1755
- Object.defineProperty(exports, '__esModule', { value: true });
1756
-
1757
- })));
1758
- //# sourceMappingURL=myrmidon-cadmus-state.umd.js.map