@myrmidon/cadmus-state 1.1.2 → 2.0.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.
- package/esm2020/lib/app.repository.mjs +75 -0
- package/esm2020/lib/cadmus-state.module.mjs +4 -4
- package/esm2020/lib/edit-fragment-feature-base.mjs +76 -63
- package/esm2020/lib/edit-part-feature-base.mjs +78 -68
- package/esm2020/lib/edited-layer.repository.mjs +277 -0
- package/esm2020/lib/edited-thesaurus.repository.mjs +80 -0
- package/esm2020/lib/fragment-editor.service.mjs +167 -0
- package/esm2020/lib/part-editor.service.mjs +157 -0
- package/esm2020/public-api.mjs +6 -19
- package/fesm2015/myrmidon-cadmus-state.mjs +640 -1095
- package/fesm2015/myrmidon-cadmus-state.mjs.map +1 -1
- package/fesm2020/myrmidon-cadmus-state.mjs +665 -1080
- package/fesm2020/myrmidon-cadmus-state.mjs.map +1 -1
- package/lib/{app.store.d.ts → app.repository.d.ts} +24 -8
- package/lib/edit-fragment-feature-base.d.ts +35 -53
- package/lib/edit-part-feature-base.d.ts +37 -51
- package/lib/edited-layer.repository.d.ts +90 -0
- package/lib/edited-thesaurus.repository.d.ts +34 -0
- package/lib/fragment-editor.service.d.ts +40 -0
- package/lib/part-editor.service.d.ts +39 -0
- package/package.json +3 -3
- package/public-api.d.ts +5 -18
- package/esm2020/lib/app.query.mjs +0 -38
- package/esm2020/lib/app.service.mjs +0 -60
- package/esm2020/lib/app.store.mjs +0 -27
- package/esm2020/lib/edit-fragment-query-base.mjs +0 -20
- package/esm2020/lib/edit-fragment-service-base.mjs +0 -140
- package/esm2020/lib/edit-fragment.store.mjs +0 -36
- package/esm2020/lib/edit-item.query.mjs +0 -52
- package/esm2020/lib/edit-item.service.mjs +0 -212
- package/esm2020/lib/edit-item.store.mjs +0 -40
- package/esm2020/lib/edit-layer-part.query.mjs +0 -35
- package/esm2020/lib/edit-layer-part.service.mjs +0 -230
- package/esm2020/lib/edit-layer-part.store.mjs +0 -49
- package/esm2020/lib/edit-part-query-base.mjs +0 -25
- package/esm2020/lib/edit-part-service-base.mjs +0 -120
- package/esm2020/lib/edit-part.store.mjs +0 -31
- package/esm2020/lib/edit-thesaurus.query.mjs +0 -26
- package/esm2020/lib/edit-thesaurus.service.mjs +0 -59
- package/esm2020/lib/edit-thesaurus.store.mjs +0 -30
- package/lib/app.query.d.ts +0 -18
- package/lib/app.service.d.ts +0 -14
- package/lib/edit-fragment-query-base.d.ts +0 -12
- package/lib/edit-fragment-service-base.d.ts +0 -39
- package/lib/edit-fragment.store.d.ts +0 -24
- package/lib/edit-item.query.d.ts +0 -22
- package/lib/edit-item.service.d.ts +0 -38
- package/lib/edit-item.store.d.ts +0 -49
- package/lib/edit-layer-part.query.d.ts +0 -17
- package/lib/edit-layer-part.service.d.ts +0 -39
- package/lib/edit-layer-part.store.d.ts +0 -57
- package/lib/edit-part-query-base.d.ts +0 -17
- package/lib/edit-part-service-base.d.ts +0 -42
- package/lib/edit-part.store.d.ts +0 -32
- package/lib/edit-thesaurus.query.d.ts +0 -13
- package/lib/edit-thesaurus.service.d.ts +0 -14
- package/lib/edit-thesaurus.store.d.ts +0 -17
|
@@ -1,81 +1,46 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { Injectable, NgModule } from '@angular/core';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { forkJoin, take } from 'rxjs';
|
|
6
|
-
import * as
|
|
2
|
+
import { Injectable, Component, NgModule } from '@angular/core';
|
|
3
|
+
import { createStore, withProps, select, setProp } from '@ngneat/elf';
|
|
4
|
+
import { withRequestsStatus, updateRequestStatus } from '@ngneat/elf-requests';
|
|
5
|
+
import { forkJoin, BehaviorSubject, take, map } from 'rxjs';
|
|
6
|
+
import * as i1 from '@myrmidon/cadmus-api';
|
|
7
7
|
import { CadmusApiModule } from '@myrmidon/cadmus-api';
|
|
8
|
-
import * as
|
|
8
|
+
import * as i4 from '@myrmidon/cadmus-core';
|
|
9
9
|
import { TokenLocation, CadmusCoreModule } from '@myrmidon/cadmus-core';
|
|
10
|
+
import * as i1$1 from '@angular/router';
|
|
11
|
+
import * as i2 from '@angular/material/snack-bar';
|
|
10
12
|
import { deepCopy, NgToolsModule } from '@myrmidon/ng-tools';
|
|
11
13
|
import { CommonModule } from '@angular/common';
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
previewCKeys: [],
|
|
19
|
-
};
|
|
20
|
-
let AppStore = class AppStore extends Store {
|
|
21
|
-
constructor() {
|
|
22
|
-
super(initialState$2);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
AppStore.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: AppStore, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
26
|
-
AppStore.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: AppStore, providedIn: 'root' });
|
|
27
|
-
AppStore = __decorate([
|
|
28
|
-
StoreConfig({ name: 'app', resettable: false })
|
|
29
|
-
], AppStore);
|
|
30
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: AppStore, decorators: [{
|
|
31
|
-
type: Injectable,
|
|
32
|
-
args: [{ providedIn: 'root' }]
|
|
33
|
-
}], ctorParameters: function () { return []; } });
|
|
34
|
-
|
|
35
|
-
class AppQuery extends Query {
|
|
36
|
-
constructor(store) {
|
|
37
|
-
super(store);
|
|
38
|
-
this.store = store;
|
|
39
|
-
}
|
|
40
|
-
selectFacets() {
|
|
41
|
-
return this.select((state) => state.facets);
|
|
42
|
-
}
|
|
43
|
-
selectFlags() {
|
|
44
|
-
return this.select((state) => state.flags);
|
|
45
|
-
}
|
|
46
|
-
selectTypeThesaurus() {
|
|
47
|
-
return this.select((state) => state.typeThesaurus);
|
|
48
|
-
}
|
|
49
|
-
selectItemBrowserThesaurus() {
|
|
50
|
-
return this.select((state) => state.itemBrowserThesaurus);
|
|
51
|
-
}
|
|
52
|
-
selectPreviewJKeys() {
|
|
53
|
-
return this.select((state) => state.previewJKeys);
|
|
54
|
-
}
|
|
55
|
-
selectPreviewFKeys() {
|
|
56
|
-
return this.select((state) => state.previewFKeys);
|
|
57
|
-
}
|
|
58
|
-
selectPreviewCKeys() {
|
|
59
|
-
return this.select((state) => state.previewCKeys);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
AppQuery.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: AppQuery, deps: [{ token: AppStore }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
63
|
-
AppQuery.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: AppQuery, providedIn: 'root' });
|
|
64
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: AppQuery, decorators: [{
|
|
65
|
-
type: Injectable,
|
|
66
|
-
args: [{ providedIn: 'root' }]
|
|
67
|
-
}], ctorParameters: function () { return [{ type: AppStore }]; } });
|
|
68
|
-
|
|
69
|
-
class AppService {
|
|
70
|
-
constructor(_store, _facetService, _flagService, _thesaurusService, _previewService) {
|
|
71
|
-
this._store = _store;
|
|
15
|
+
/**
|
|
16
|
+
* App state ELF repository.
|
|
17
|
+
*/
|
|
18
|
+
class AppRepository {
|
|
19
|
+
constructor(_facetService, _flagService, _thesaurusService, _previewService) {
|
|
72
20
|
this._facetService = _facetService;
|
|
73
21
|
this._flagService = _flagService;
|
|
74
22
|
this._thesaurusService = _thesaurusService;
|
|
75
23
|
this._previewService = _previewService;
|
|
24
|
+
this._store = createStore({ name: 'app' }, withProps({
|
|
25
|
+
facets: [],
|
|
26
|
+
flags: [],
|
|
27
|
+
previewJKeys: [],
|
|
28
|
+
previewFKeys: [],
|
|
29
|
+
previewCKeys: [],
|
|
30
|
+
}), withRequestsStatus());
|
|
31
|
+
this.facets$ = this._store.pipe(select((state) => state.facets));
|
|
32
|
+
this.flags$ = this._store.pipe(select((state) => state.flags));
|
|
33
|
+
this.typeThesaurus$ = this._store.pipe(select((state) => state.typeThesaurus));
|
|
34
|
+
this.itemBrowserThesaurus$ = this._store.pipe(select((state) => state.itemBrowserThesaurus));
|
|
35
|
+
this.previewJKeys$ = this._store.pipe(select((state) => state.previewJKeys));
|
|
36
|
+
this.previewFKeys$ = this._store.pipe(select((state) => state.previewFKeys));
|
|
37
|
+
this.previewCKeys$ = this._store.pipe(select((state) => state.previewCKeys));
|
|
38
|
+
}
|
|
39
|
+
getValue() {
|
|
40
|
+
return this._store.getValue();
|
|
76
41
|
}
|
|
77
42
|
load() {
|
|
78
|
-
this._store.
|
|
43
|
+
this._store.update(updateRequestStatus('app', 'pending'));
|
|
79
44
|
const facets$ = this._facetService.getFacets();
|
|
80
45
|
const flags$ = this._flagService.getFlags();
|
|
81
46
|
const thesauri$ = this._thesaurusService.getThesauriSet([
|
|
@@ -91,405 +56,264 @@ class AppService {
|
|
|
91
56
|
thesauri: thesauri$,
|
|
92
57
|
jKeys: jKeys$,
|
|
93
58
|
fKeys: fKeys$,
|
|
94
|
-
cKeys: cKeys
|
|
59
|
+
cKeys: cKeys$,
|
|
95
60
|
}).subscribe({
|
|
96
61
|
next: (result) => {
|
|
97
|
-
this._store.
|
|
98
|
-
this._store.
|
|
99
|
-
this._store.update({
|
|
100
|
-
facets: result.facets,
|
|
101
|
-
flags: result.flags,
|
|
102
|
-
typeThesaurus: result.thesauri['model-types'],
|
|
103
|
-
itemBrowserThesaurus: result.thesauri['item-browsers'],
|
|
104
|
-
previewJKeys: result.jKeys,
|
|
105
|
-
previewFKeys: result.fKeys,
|
|
106
|
-
previewCKeys: result.cKeys
|
|
107
|
-
});
|
|
108
|
-
},
|
|
109
|
-
error: (error) => {
|
|
110
|
-
console.error(error);
|
|
111
|
-
this._store.setLoading(false);
|
|
112
|
-
this._store.setError('Error loading app state');
|
|
62
|
+
this._store.update(updateRequestStatus('app', 'success'));
|
|
63
|
+
this._store.update((state) => (Object.assign(Object.assign({}, state), { facets: result.facets, flags: result.flags, typeThesaurus: result.thesauri['model-types'], itemBrowserThesaurus: result.thesauri['item-browsers'], previewJKeys: result.jKeys, previewFKeys: result.fKeys, previewCKeys: result.cKeys })));
|
|
113
64
|
},
|
|
114
65
|
});
|
|
115
66
|
}
|
|
116
67
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
68
|
+
AppRepository.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: AppRepository, deps: [{ token: i1.FacetService }, { token: i1.FlagService }, { token: i1.ThesaurusService }, { token: i1.PreviewService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
69
|
+
AppRepository.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: AppRepository, providedIn: 'root' });
|
|
70
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: AppRepository, decorators: [{
|
|
120
71
|
type: Injectable,
|
|
121
72
|
args: [{ providedIn: 'root' }]
|
|
122
|
-
}], ctorParameters: function () { return [{ type:
|
|
123
|
-
|
|
124
|
-
const initialState$1 = {
|
|
125
|
-
parts: [],
|
|
126
|
-
partGroups: [],
|
|
127
|
-
layerPartInfos: [],
|
|
128
|
-
};
|
|
129
|
-
let EditItemStore = class EditItemStore extends Store {
|
|
130
|
-
constructor() {
|
|
131
|
-
super(initialState$1);
|
|
132
|
-
}
|
|
133
|
-
setDirty(value = true) {
|
|
134
|
-
this.update({
|
|
135
|
-
dirty: value,
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
setSaving(value = true) {
|
|
139
|
-
this.update({
|
|
140
|
-
saving: value,
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
setDeletingPart(value = true) {
|
|
144
|
-
this.update({
|
|
145
|
-
deletingPart: value,
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
EditItemStore.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: EditItemStore, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
150
|
-
EditItemStore.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: EditItemStore, providedIn: 'root' });
|
|
151
|
-
EditItemStore = __decorate([
|
|
152
|
-
StoreConfig({ name: 'edit-item', resettable: true })
|
|
153
|
-
], EditItemStore);
|
|
154
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: EditItemStore, decorators: [{
|
|
155
|
-
type: Injectable,
|
|
156
|
-
args: [{ providedIn: 'root' }]
|
|
157
|
-
}], ctorParameters: function () { return []; } });
|
|
73
|
+
}], ctorParameters: function () { return [{ type: i1.FacetService }, { type: i1.FlagService }, { type: i1.ThesaurusService }, { type: i1.PreviewService }]; } });
|
|
158
74
|
|
|
159
75
|
/**
|
|
160
|
-
*
|
|
76
|
+
* Service used by layer part editor wrappers to load part and thesauri
|
|
77
|
+
* or save parts.
|
|
161
78
|
*/
|
|
162
|
-
class
|
|
163
|
-
constructor(
|
|
164
|
-
super(store);
|
|
165
|
-
this.store = store;
|
|
166
|
-
this._libraryRouteService = _libraryRouteService;
|
|
167
|
-
}
|
|
168
|
-
selectItem() {
|
|
169
|
-
return this.select((state) => state.item);
|
|
170
|
-
}
|
|
171
|
-
selectParts() {
|
|
172
|
-
return this.select((state) => state.parts);
|
|
173
|
-
}
|
|
174
|
-
selectFacet() {
|
|
175
|
-
return this.select((state) => state.facet);
|
|
176
|
-
}
|
|
177
|
-
selectSaving() {
|
|
178
|
-
return this.select((state) => (state.saving ? true : false));
|
|
179
|
-
}
|
|
180
|
-
selectDeletingPart() {
|
|
181
|
-
return this.select((state) => (state.deletingPart ? true : false));
|
|
182
|
-
}
|
|
183
|
-
hasItem(id) {
|
|
184
|
-
const item = this.getValue().item;
|
|
185
|
-
if (!item || (id && id !== item.id)) {
|
|
186
|
-
return false;
|
|
187
|
-
}
|
|
188
|
-
return true;
|
|
189
|
-
}
|
|
190
|
-
getEditorKeyFromPartTypeId(typeId, roleId) {
|
|
191
|
-
const facet = this.getValue().facet;
|
|
192
|
-
if (!facet) {
|
|
193
|
-
return 'default';
|
|
194
|
-
}
|
|
195
|
-
return this._libraryRouteService.getEditorKeyFromPartType(typeId, roleId)
|
|
196
|
-
.partKey;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
EditItemQuery.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: EditItemQuery, deps: [{ token: EditItemStore }, { token: i2$1.LibraryRouteService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
200
|
-
EditItemQuery.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: EditItemQuery, providedIn: 'root' });
|
|
201
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: EditItemQuery, decorators: [{
|
|
202
|
-
type: Injectable,
|
|
203
|
-
args: [{ providedIn: 'root' }]
|
|
204
|
-
}], ctorParameters: function () { return [{ type: EditItemStore }, { type: i2$1.LibraryRouteService }]; } });
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* The service which handles the edit item store.
|
|
208
|
-
*/
|
|
209
|
-
class EditItemService {
|
|
210
|
-
constructor(_store, _appQuery, _itemService) {
|
|
211
|
-
this._store = _store;
|
|
212
|
-
this._appQuery = _appQuery;
|
|
79
|
+
class FragmentEditorService {
|
|
80
|
+
constructor(_itemService, _thesaurusService) {
|
|
213
81
|
this._itemService = _itemService;
|
|
82
|
+
this._thesaurusService = _thesaurusService;
|
|
83
|
+
this._loading$ = new BehaviorSubject(false);
|
|
84
|
+
this.loading$ = this._loading$.asObservable();
|
|
85
|
+
this._saving$ = new BehaviorSubject(false);
|
|
86
|
+
this.saving$ = this._saving$.asObservable();
|
|
87
|
+
}
|
|
88
|
+
getFragmentFromPart(part, loc) {
|
|
89
|
+
const fr = part.fragments.find((f) => f.location === loc);
|
|
90
|
+
return (fr !== null && fr !== void 0 ? fr : {
|
|
91
|
+
location: loc,
|
|
92
|
+
});
|
|
214
93
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
return defaultFacet;
|
|
223
|
-
}
|
|
224
|
-
// else just pick the first in the list
|
|
225
|
-
return facets[0];
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Load the item with the specified ID (if any; the ID can be null for
|
|
229
|
-
* a new item), and all the required lookup data into the item store.
|
|
230
|
-
*/
|
|
231
|
-
load(itemId) {
|
|
232
|
-
this._store.setLoading(true);
|
|
233
|
-
const appState = this._appQuery.getValue();
|
|
234
|
-
// if not a new item, include it in load
|
|
235
|
-
const layers$ = this._itemService.getItemLayerInfo(itemId || 'new', true);
|
|
236
|
-
if (itemId) {
|
|
94
|
+
loadWithThesauri(identity, thesauriIds) {
|
|
95
|
+
// remove trailing ! from IDs if any
|
|
96
|
+
const unscopedIds = thesauriIds.map((id) => {
|
|
97
|
+
return this._thesaurusService.getScopedId(id);
|
|
98
|
+
});
|
|
99
|
+
return new Promise((resolve, reject) => {
|
|
100
|
+
// load part and thesauri
|
|
237
101
|
forkJoin({
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
102
|
+
part: this._itemService.getPart(identity.partId || ''),
|
|
103
|
+
thesauri: this._thesaurusService.getThesauriSet(unscopedIds),
|
|
104
|
+
t: this._itemService.getBaseTextPart(identity.itemId),
|
|
105
|
+
}).subscribe({
|
|
241
106
|
next: (result) => {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
107
|
+
const layerPart = result.part;
|
|
108
|
+
const thesauri = result.thesauri;
|
|
109
|
+
const fr = this.getFragmentFromPart(layerPart, identity.loc);
|
|
110
|
+
// if the loaded part has a thesaurus scope, reload the thesauri
|
|
111
|
+
if (layerPart.thesaurusScope) {
|
|
112
|
+
const scopedIds = thesauriIds.map((id) => {
|
|
113
|
+
return this._thesaurusService.getScopedId(id, layerPart.thesaurusScope);
|
|
114
|
+
});
|
|
115
|
+
this._thesaurusService.getThesauriSet(scopedIds).subscribe({
|
|
116
|
+
next: (scopedThesauri) => {
|
|
117
|
+
this._loading$.next(false);
|
|
118
|
+
resolve({
|
|
119
|
+
value: fr,
|
|
120
|
+
layerPart: layerPart,
|
|
121
|
+
baseText: result.t.text,
|
|
122
|
+
thesauri: scopedThesauri,
|
|
123
|
+
});
|
|
124
|
+
},
|
|
125
|
+
error: (error) => {
|
|
126
|
+
this._loading$.next(false);
|
|
127
|
+
console.error(error);
|
|
128
|
+
reject({
|
|
129
|
+
message: 'Error loading thesauri ' + scopedIds.join(', '),
|
|
130
|
+
error: error,
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
// else just use the loaded thesauri
|
|
137
|
+
this._loading$.next(false);
|
|
138
|
+
resolve({
|
|
139
|
+
value: fr,
|
|
140
|
+
layerPart: layerPart,
|
|
141
|
+
baseText: result.t.text,
|
|
142
|
+
thesauri: thesauri,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
255
145
|
},
|
|
256
146
|
error: (error) => {
|
|
147
|
+
this._loading$.next(false);
|
|
257
148
|
console.error(error);
|
|
258
|
-
|
|
259
|
-
|
|
149
|
+
reject({
|
|
150
|
+
message: 'Error loading thesauri ' + unscopedIds.join(', '),
|
|
151
|
+
error: error,
|
|
152
|
+
});
|
|
260
153
|
},
|
|
261
154
|
});
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
loadWithoutThesauri(identity) {
|
|
158
|
+
this._loading$.next(true);
|
|
159
|
+
return new Promise((resolve, reject) => {
|
|
160
|
+
// load layer part and base text
|
|
265
161
|
forkJoin({
|
|
266
|
-
|
|
267
|
-
|
|
162
|
+
t: this._itemService.getBaseTextPart(identity.itemId),
|
|
163
|
+
p: this._itemService.getPart(identity.partId),
|
|
164
|
+
}).subscribe({
|
|
268
165
|
next: (result) => {
|
|
269
|
-
this.
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
facetId: '',
|
|
277
|
-
groupId: '',
|
|
278
|
-
sortKey: '',
|
|
279
|
-
flags: 0,
|
|
280
|
-
timeCreated: new Date(),
|
|
281
|
-
creatorId: '',
|
|
282
|
-
timeModified: new Date(),
|
|
283
|
-
userId: '',
|
|
284
|
-
},
|
|
285
|
-
parts: [],
|
|
286
|
-
partGroups: [],
|
|
287
|
-
layerPartInfos: result.layers,
|
|
288
|
-
facet: this.pickDefaultFacet(appState.facets),
|
|
166
|
+
this._loading$.next(false);
|
|
167
|
+
const layerPart = result.p;
|
|
168
|
+
resolve({
|
|
169
|
+
value: this.getFragmentFromPart(layerPart, identity.loc),
|
|
170
|
+
layerPart: layerPart,
|
|
171
|
+
baseText: result.t.text,
|
|
172
|
+
thesauri: {},
|
|
289
173
|
});
|
|
290
174
|
},
|
|
291
175
|
error: (error) => {
|
|
176
|
+
this._loading$.next(false);
|
|
292
177
|
console.error(error);
|
|
293
|
-
|
|
294
|
-
|
|
178
|
+
reject({
|
|
179
|
+
message: 'Error loading layer part ' + identity.partId,
|
|
180
|
+
error: error,
|
|
181
|
+
});
|
|
295
182
|
},
|
|
296
183
|
});
|
|
297
|
-
}
|
|
184
|
+
});
|
|
298
185
|
}
|
|
299
186
|
/**
|
|
300
|
-
*
|
|
187
|
+
* Load into the state the part with the specified ID
|
|
188
|
+
* and its thesauri.
|
|
189
|
+
* If the ID is not specified, it's a new part; in this case,
|
|
190
|
+
* it will get a null ID, but use the specified itemId and roleId.
|
|
191
|
+
*
|
|
192
|
+
* @param identity The part identity.
|
|
193
|
+
* @param thesauriIds The thesauri IDs array.
|
|
301
194
|
*/
|
|
302
|
-
|
|
303
|
-
|
|
195
|
+
load(identity, thesauriIds) {
|
|
196
|
+
if (thesauriIds === null || thesauriIds === void 0 ? void 0 : thesauriIds.length) {
|
|
197
|
+
return this.loadWithThesauri(identity, thesauriIds);
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
return this.loadWithoutThesauri(identity);
|
|
201
|
+
}
|
|
304
202
|
}
|
|
305
203
|
/**
|
|
306
|
-
* Save the
|
|
307
|
-
*
|
|
204
|
+
* Save the fragments in their layer part.
|
|
205
|
+
*
|
|
206
|
+
* @param part The part.
|
|
207
|
+
* @returns Promise which when successful returns the saved part.
|
|
308
208
|
*/
|
|
309
|
-
save(
|
|
310
|
-
this.
|
|
209
|
+
save(part) {
|
|
210
|
+
this._saving$.next(true);
|
|
311
211
|
return new Promise((resolve, reject) => {
|
|
312
|
-
this._itemService
|
|
313
|
-
.addItem(item)
|
|
314
|
-
.pipe(take(1))
|
|
315
|
-
.subscribe({
|
|
212
|
+
this._itemService.addPart(part).subscribe({
|
|
316
213
|
next: (saved) => {
|
|
317
|
-
this.
|
|
318
|
-
// reload the store
|
|
319
|
-
this.load(saved.id);
|
|
214
|
+
this._saving$.next(false);
|
|
320
215
|
resolve(saved);
|
|
321
216
|
},
|
|
322
217
|
error: (error) => {
|
|
218
|
+
this._saving$.next(false);
|
|
323
219
|
console.error(error);
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
});
|
|
329
|
-
});
|
|
330
|
-
}
|
|
331
|
-
/**
|
|
332
|
-
* Delete the part with the specified ID from the edited item.
|
|
333
|
-
* @param id The ID of the part to be deleted.
|
|
334
|
-
*/
|
|
335
|
-
deletePart(id) {
|
|
336
|
-
this._store.setDeletingPart();
|
|
337
|
-
return new Promise((resolve, reject) => {
|
|
338
|
-
// delete from server
|
|
339
|
-
this._itemService
|
|
340
|
-
.deletePart(id)
|
|
341
|
-
.pipe(take(1))
|
|
342
|
-
.subscribe({
|
|
343
|
-
next: (_) => {
|
|
344
|
-
var _a;
|
|
345
|
-
this._store.setDeletingPart(false);
|
|
346
|
-
// reload the store
|
|
347
|
-
this.load((_a = this._store.getValue().item) === null || _a === void 0 ? void 0 : _a.id);
|
|
348
|
-
resolve(id);
|
|
349
|
-
},
|
|
350
|
-
error: (error) => {
|
|
351
|
-
console.log(error);
|
|
352
|
-
this._store.setDeletingPart(false);
|
|
353
|
-
this._store.setError('Error deleting part ' + id);
|
|
354
|
-
reject(error);
|
|
220
|
+
reject({
|
|
221
|
+
message: 'Error saving part ' + part.id,
|
|
222
|
+
error: error,
|
|
223
|
+
});
|
|
355
224
|
},
|
|
356
225
|
});
|
|
357
226
|
});
|
|
358
227
|
}
|
|
359
|
-
addNewLayerPart(itemId, typeId, roleId) {
|
|
360
|
-
const part = {
|
|
361
|
-
itemId,
|
|
362
|
-
typeId,
|
|
363
|
-
roleId,
|
|
364
|
-
id: '',
|
|
365
|
-
creatorId: '',
|
|
366
|
-
userId: '',
|
|
367
|
-
timeCreated: new Date(),
|
|
368
|
-
timeModified: new Date(),
|
|
369
|
-
};
|
|
370
|
-
this._store.setSaving();
|
|
371
|
-
this._itemService
|
|
372
|
-
.addPart(part)
|
|
373
|
-
.pipe(take(1))
|
|
374
|
-
.subscribe({
|
|
375
|
-
next: (_) => {
|
|
376
|
-
var _a;
|
|
377
|
-
this._store.setSaving(false);
|
|
378
|
-
// reload the store
|
|
379
|
-
this.load((_a = this._store.getValue().item) === null || _a === void 0 ? void 0 : _a.id);
|
|
380
|
-
},
|
|
381
|
-
error: (error) => {
|
|
382
|
-
console.log(error);
|
|
383
|
-
this._store.setSaving(false);
|
|
384
|
-
this._store.setError('Error adding new layer part for item ' + itemId);
|
|
385
|
-
},
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
setPartThesaurusScope(ids, scope) {
|
|
389
|
-
this._store.setSaving();
|
|
390
|
-
this._itemService
|
|
391
|
-
.setPartThesaurusScope(ids, scope)
|
|
392
|
-
.pipe(take(1))
|
|
393
|
-
.subscribe({
|
|
394
|
-
next: (_) => {
|
|
395
|
-
var _a;
|
|
396
|
-
this._store.setSaving(false);
|
|
397
|
-
// reload the store
|
|
398
|
-
this.load((_a = this._store.getValue().item) === null || _a === void 0 ? void 0 : _a.id);
|
|
399
|
-
},
|
|
400
|
-
error: (error) => {
|
|
401
|
-
console.log(error);
|
|
402
|
-
this._store.setSaving(false);
|
|
403
|
-
this._store.setError("Error setting item's parts scope");
|
|
404
|
-
},
|
|
405
|
-
});
|
|
406
|
-
}
|
|
407
228
|
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
229
|
+
FragmentEditorService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: FragmentEditorService, deps: [{ token: i1.ItemService }, { token: i1.ThesaurusService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
230
|
+
FragmentEditorService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: FragmentEditorService, providedIn: 'root' });
|
|
231
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: FragmentEditorService, decorators: [{
|
|
411
232
|
type: Injectable,
|
|
412
|
-
args: [{
|
|
413
|
-
|
|
233
|
+
args: [{
|
|
234
|
+
providedIn: 'root',
|
|
235
|
+
}]
|
|
236
|
+
}], ctorParameters: function () { return [{ type: i1.ItemService }, { type: i1.ThesaurusService }]; } });
|
|
414
237
|
|
|
415
238
|
/**
|
|
416
239
|
* Base class for fragment feature editors.
|
|
417
240
|
* This is similar to the EditPartFeatureBase class.
|
|
418
241
|
*/
|
|
419
242
|
class EditFragmentFeatureBase {
|
|
420
|
-
constructor(_router, route, snackbar,
|
|
243
|
+
constructor(_router, route, snackbar, editorService, _libraryRouteService) {
|
|
421
244
|
var _a;
|
|
422
245
|
this._router = _router;
|
|
423
246
|
this.snackbar = snackbar;
|
|
424
|
-
this.
|
|
425
|
-
this._editFrService = _editFrService;
|
|
426
|
-
this._editItemQuery = _editItemQuery;
|
|
427
|
-
this._editItemService = _editItemService;
|
|
428
|
-
this._editLayersQuery = _editLayersQuery;
|
|
429
|
-
this._editLayersService = _editLayersService;
|
|
247
|
+
this.editorService = editorService;
|
|
430
248
|
this._libraryRouteService = _libraryRouteService;
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
this.
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
249
|
+
// fragment route:
|
|
250
|
+
// /items/<iid>/@partGroup/fragment/<pid>/@frTypeId/<loc>?frrid
|
|
251
|
+
const itemId = route.snapshot.params['iid'];
|
|
252
|
+
const partId = route.snapshot.params['pid'];
|
|
253
|
+
const frTypeId = (_a = route.snapshot.url[2]) === null || _a === void 0 ? void 0 : _a.path;
|
|
254
|
+
const loc = route.snapshot.params['loc'];
|
|
255
|
+
const frRoleId = route.snapshot.queryParams['frrid'];
|
|
256
|
+
this.identity = {
|
|
257
|
+
itemId: itemId,
|
|
258
|
+
typeId: '',
|
|
259
|
+
partId: partId,
|
|
260
|
+
roleId: frTypeId,
|
|
261
|
+
frTypeId: frTypeId,
|
|
262
|
+
frRoleId: frRoleId,
|
|
263
|
+
loc: loc,
|
|
264
|
+
};
|
|
265
|
+
// subscriptions
|
|
266
|
+
this._loadingSub = this.editorService.loading$.subscribe((loading) => (this.loading = loading));
|
|
267
|
+
this._savingSub = this.editorService.saving$.subscribe((saving) => (this.saving = saving));
|
|
444
268
|
}
|
|
445
269
|
/**
|
|
446
|
-
*
|
|
447
|
-
*
|
|
448
|
-
*
|
|
449
|
-
*
|
|
270
|
+
* Override in derived classes to return the IDs of the thesauri requested
|
|
271
|
+
* for this editor.
|
|
272
|
+
*
|
|
273
|
+
* @return Array with thesauri IDs, eventually empty.
|
|
450
274
|
*/
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
return !this._formDirty && !this._stateDirty;
|
|
454
|
-
}
|
|
455
|
-
ensureItemLoaded(id) {
|
|
456
|
-
if (!this._editItemQuery.hasItem(id)) {
|
|
457
|
-
this._editItemService.load(id);
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
ensureLayersLoaded(thesauriIds) {
|
|
461
|
-
if (!this._editLayersQuery.getValue().part) {
|
|
462
|
-
this._editLayersService.load(this.itemId, this.partId, thesauriIds);
|
|
463
|
-
}
|
|
275
|
+
getReqThesauriIds() {
|
|
276
|
+
return [];
|
|
464
277
|
}
|
|
465
278
|
/**
|
|
466
|
-
*
|
|
467
|
-
*
|
|
468
|
-
* @param thesauriIds The optional ID(s) of the thesauri sets you want
|
|
469
|
-
* to use in your editor.
|
|
279
|
+
* Called once data has been loaded.
|
|
470
280
|
*/
|
|
471
|
-
|
|
281
|
+
onDataLoaded() { }
|
|
282
|
+
ngOnInit() {
|
|
472
283
|
var _a;
|
|
473
|
-
this.
|
|
474
|
-
this.
|
|
475
|
-
|
|
476
|
-
this.
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
284
|
+
this.loading = true;
|
|
285
|
+
this.frLoc = (_a = TokenLocation.parse(this.identity.loc)) !== null && _a !== void 0 ? _a : undefined;
|
|
286
|
+
const thesIds = this.getReqThesauriIds();
|
|
287
|
+
this.editorService
|
|
288
|
+
.load(this.identity, thesIds)
|
|
289
|
+
.then((data) => {
|
|
290
|
+
if (data) {
|
|
291
|
+
this.data = data;
|
|
292
|
+
this.onDataLoaded();
|
|
293
|
+
}
|
|
294
|
+
})
|
|
295
|
+
.catch((reason) => {
|
|
296
|
+
this.snackbar.open(reason.message, 'OK');
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
ngOnDestroy() {
|
|
300
|
+
var _a, _b;
|
|
301
|
+
(_a = this._loadingSub) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
302
|
+
(_b = this._savingSub) === null || _b === void 0 ? void 0 : _b.unsubscribe();
|
|
303
|
+
}
|
|
304
|
+
canDeactivate() {
|
|
305
|
+
return !this.dirty;
|
|
483
306
|
}
|
|
484
307
|
/**
|
|
485
308
|
* Called when the wrapped editor dirty state changes.
|
|
486
309
|
* In the HTML template, you MUST bind this handler to the dirtyChange event
|
|
487
310
|
* emitted by your wrapped editor (i.e. (dirtyChange)="onDirtyChange($event)").
|
|
311
|
+
*
|
|
488
312
|
* @param value The value of the dirty state.
|
|
489
313
|
*/
|
|
490
314
|
onDirtyChange(value) {
|
|
491
|
-
console.log('
|
|
492
|
-
this.
|
|
315
|
+
console.log('part dirty change (from editor): ' + value);
|
|
316
|
+
this.dirty = value;
|
|
493
317
|
}
|
|
494
318
|
/**
|
|
495
319
|
* Save the fragment.
|
|
@@ -497,10 +321,9 @@ class EditFragmentFeatureBase {
|
|
|
497
321
|
* @param fragment The fragment to be saved.
|
|
498
322
|
*/
|
|
499
323
|
save(fragment) {
|
|
500
|
-
//
|
|
501
|
-
const part =
|
|
502
|
-
|
|
503
|
-
const frIndex = part.fragments.findIndex((f) => f.location === this.loc);
|
|
324
|
+
// update a copy of the edited part with new fragment
|
|
325
|
+
const part = Object.assign({}, this.data.layerPart);
|
|
326
|
+
const frIndex = part.fragments.findIndex((f) => f.location === this.identity.loc);
|
|
504
327
|
if (frIndex > -1) {
|
|
505
328
|
part.fragments.splice(frIndex, 1, fragment);
|
|
506
329
|
}
|
|
@@ -508,7 +331,7 @@ class EditFragmentFeatureBase {
|
|
|
508
331
|
part.fragments.push(fragment);
|
|
509
332
|
}
|
|
510
333
|
// save the new layer part with the replaced fragment
|
|
511
|
-
this.
|
|
334
|
+
this.editorService.save(part).then((p) => {
|
|
512
335
|
console.log(p.id);
|
|
513
336
|
this.snackbar.open('Fragment saved', 'OK', {
|
|
514
337
|
duration: 3000,
|
|
@@ -520,282 +343,252 @@ class EditFragmentFeatureBase {
|
|
|
520
343
|
}
|
|
521
344
|
close() {
|
|
522
345
|
// /items/<id>/<part-group>/<part-typeid>/<part-id>?rid=<role-id>
|
|
523
|
-
const part = this.
|
|
346
|
+
const part = this.data.layerPart;
|
|
524
347
|
const editorKey = this._libraryRouteService.getEditorKeyFromPartType(part.typeId, part.roleId);
|
|
525
|
-
const url = `/items/${this.itemId}/${editorKey.partKey}/${part.typeId}/${this.partId}`;
|
|
348
|
+
const url = `/items/${this.identity.itemId}/${editorKey.partKey}/${part.typeId}/${this.identity.partId}`;
|
|
526
349
|
this._router.navigate([url], {
|
|
527
350
|
queryParams: {
|
|
528
|
-
rid: this.frTypeId,
|
|
351
|
+
rid: this.identity.frTypeId,
|
|
529
352
|
},
|
|
530
353
|
});
|
|
531
354
|
}
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
}
|
|
542
|
-
selectSaving() {
|
|
543
|
-
return this.select((state) => state.saving);
|
|
544
|
-
}
|
|
545
|
-
selectFragment() {
|
|
546
|
-
return this.select((state) => state.fragment);
|
|
547
|
-
}
|
|
548
|
-
selectThesauri() {
|
|
549
|
-
return this.select((state) => state.thesauri);
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
const editFragmentInitialState = {
|
|
554
|
-
dirty: false,
|
|
555
|
-
saving: false,
|
|
556
|
-
loading: false,
|
|
557
|
-
};
|
|
558
|
-
/**
|
|
559
|
-
* General-purpose edit-fragment store. This can be used with any fragment,
|
|
560
|
-
* so that you should only provide your fragment store, query, and service
|
|
561
|
-
* (usually extending EditFragmentServiceBase).
|
|
562
|
-
*/
|
|
563
|
-
let EditFragmentStore = class EditFragmentStore extends Store {
|
|
564
|
-
constructor() {
|
|
565
|
-
super(editFragmentInitialState);
|
|
566
|
-
}
|
|
567
|
-
setDirty(value) {
|
|
568
|
-
this.update({ dirty: value });
|
|
569
|
-
}
|
|
570
|
-
setSaving(value) {
|
|
571
|
-
this.update({ saving: value });
|
|
572
|
-
}
|
|
573
|
-
};
|
|
574
|
-
EditFragmentStore.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: EditFragmentStore, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
575
|
-
EditFragmentStore.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: EditFragmentStore, providedIn: 'root' });
|
|
576
|
-
EditFragmentStore = __decorate([
|
|
577
|
-
StoreConfig({ name: 'edit-fragment' })
|
|
578
|
-
], EditFragmentStore);
|
|
579
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: EditFragmentStore, decorators: [{
|
|
580
|
-
type: Injectable,
|
|
581
|
-
args: [{ providedIn: 'root' }]
|
|
582
|
-
}], ctorParameters: function () { return []; } });
|
|
355
|
+
}
|
|
356
|
+
EditFragmentFeatureBase.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: EditFragmentFeatureBase, deps: [{ token: i1$1.Router }, { token: i1$1.ActivatedRoute }, { token: i2.MatSnackBar }, { token: FragmentEditorService }, { token: i4.LibraryRouteService }], target: i0.ɵɵFactoryTarget.Component });
|
|
357
|
+
EditFragmentFeatureBase.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.0.0", type: EditFragmentFeatureBase, selector: "ng-component", ngImport: i0, template: '', isInline: true });
|
|
358
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: EditFragmentFeatureBase, decorators: [{
|
|
359
|
+
type: Component,
|
|
360
|
+
args: [{
|
|
361
|
+
template: '',
|
|
362
|
+
}]
|
|
363
|
+
}], ctorParameters: function () { return [{ type: i1$1.Router }, { type: i1$1.ActivatedRoute }, { type: i2.MatSnackBar }, { type: FragmentEditorService }, { type: i4.LibraryRouteService }]; } });
|
|
583
364
|
|
|
584
365
|
/**
|
|
585
|
-
*
|
|
366
|
+
* Service used by part editor wrappers to load part and thesauri
|
|
367
|
+
* or save parts.
|
|
586
368
|
*/
|
|
587
|
-
class
|
|
369
|
+
class PartEditorService {
|
|
588
370
|
constructor(_itemService, _thesaurusService) {
|
|
589
371
|
this._itemService = _itemService;
|
|
590
372
|
this._thesaurusService = _thesaurusService;
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
this.store.setLoading(true);
|
|
606
|
-
// if thesauri are required:
|
|
607
|
-
if (thesauriIds) {
|
|
608
|
-
// remove trailing ! from IDs if any
|
|
609
|
-
const unscopedIds = thesauriIds.map((id) => {
|
|
610
|
-
return this._thesaurusService.getScopedId(id);
|
|
611
|
-
});
|
|
612
|
-
// fetch fragment and thesauri
|
|
373
|
+
this._loading$ = new BehaviorSubject(false);
|
|
374
|
+
this.loading$ = this._loading$.asObservable();
|
|
375
|
+
this._saving$ = new BehaviorSubject(false);
|
|
376
|
+
this.saving$ = this._saving$.asObservable();
|
|
377
|
+
}
|
|
378
|
+
loadWithThesauri(identity, thesauriIds) {
|
|
379
|
+
// remove trailing ! from IDs if any
|
|
380
|
+
const unscopedIds = thesauriIds.map((id) => {
|
|
381
|
+
return this._thesaurusService.getScopedId(id);
|
|
382
|
+
});
|
|
383
|
+
// return a promise
|
|
384
|
+
this._loading$.next(true);
|
|
385
|
+
return new Promise((resolve, reject) => {
|
|
386
|
+
// load part and thesauri
|
|
613
387
|
forkJoin({
|
|
614
|
-
part: this._itemService.getPart(partId),
|
|
388
|
+
part: this._itemService.getPart(identity.partId || ''),
|
|
615
389
|
thesauri: this._thesaurusService.getThesauriSet(unscopedIds),
|
|
616
|
-
}).subscribe(
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
this.store.update({
|
|
625
|
-
fragment: {
|
|
626
|
-
location: loc,
|
|
627
|
-
},
|
|
628
|
-
thesauri: result.thesauri,
|
|
629
|
-
loading: false,
|
|
630
|
-
error: null,
|
|
631
|
-
});
|
|
632
|
-
}
|
|
633
|
-
else {
|
|
634
|
-
// found: existing fragment
|
|
635
|
-
this.store.update({
|
|
636
|
-
fragment: fr,
|
|
637
|
-
thesauri: result.thesauri,
|
|
638
|
-
loading: false,
|
|
639
|
-
error: null,
|
|
640
|
-
});
|
|
641
|
-
}
|
|
642
|
-
// if the loaded layer part has a thesaurus scope, reload the thesauri
|
|
643
|
-
if ((_a = result.part) === null || _a === void 0 ? void 0 : _a.thesaurusScope) {
|
|
644
|
-
const scopedIds = thesauriIds.map((id) => {
|
|
645
|
-
var _a;
|
|
646
|
-
return this._thesaurusService.getScopedId(id, (_a = result.part) === null || _a === void 0 ? void 0 : _a.thesaurusScope);
|
|
647
|
-
});
|
|
648
|
-
// loading again
|
|
649
|
-
this.store.setLoading(true);
|
|
650
|
-
this._thesaurusService.getThesauriSet(scopedIds).subscribe((thesauri) => {
|
|
651
|
-
// completed, replace the thesauri
|
|
652
|
-
this.store.update({
|
|
653
|
-
thesauri,
|
|
654
|
-
loading: false
|
|
390
|
+
}).subscribe({
|
|
391
|
+
next: (result) => {
|
|
392
|
+
const part = result.part;
|
|
393
|
+
const thesauri = result.thesauri;
|
|
394
|
+
// if the loaded part has a thesaurus scope, reload the thesauri
|
|
395
|
+
if (part.thesaurusScope) {
|
|
396
|
+
const scopedIds = thesauriIds.map((id) => {
|
|
397
|
+
return this._thesaurusService.getScopedId(id, part.thesaurusScope);
|
|
655
398
|
});
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
399
|
+
this._thesaurusService.getThesauriSet(scopedIds).subscribe({
|
|
400
|
+
next: (scopedThesauri) => {
|
|
401
|
+
this._loading$.next(false);
|
|
402
|
+
resolve({
|
|
403
|
+
value: part,
|
|
404
|
+
thesauri: scopedThesauri,
|
|
405
|
+
});
|
|
406
|
+
},
|
|
407
|
+
error: (error) => {
|
|
408
|
+
this._loading$.next(false);
|
|
409
|
+
console.error(error);
|
|
410
|
+
reject({
|
|
411
|
+
message: 'Error loading thesauri ' + scopedIds.join(', '),
|
|
412
|
+
error: error,
|
|
413
|
+
});
|
|
414
|
+
},
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
// else just use the loaded thesauri
|
|
419
|
+
this._loading$.next(false);
|
|
420
|
+
resolve({
|
|
421
|
+
value: part,
|
|
422
|
+
thesauri: thesauri,
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
},
|
|
426
|
+
error: (error) => {
|
|
427
|
+
this._loading$.next(false);
|
|
428
|
+
console.error(error);
|
|
429
|
+
reject({
|
|
430
|
+
message: 'Error loading thesauri ' + unscopedIds.join(', '),
|
|
431
|
+
error: error,
|
|
660
432
|
});
|
|
661
|
-
}
|
|
433
|
+
},
|
|
662
434
|
});
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
},
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
this.
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
loadWithoutThesauri(partId) {
|
|
438
|
+
return new Promise((resolve, reject) => {
|
|
439
|
+
this._loading$.next(true);
|
|
440
|
+
this._itemService
|
|
441
|
+
.getPart(partId)
|
|
442
|
+
.pipe(take(1), map((part) => {
|
|
443
|
+
return part
|
|
444
|
+
? {
|
|
445
|
+
value: part,
|
|
446
|
+
thesauri: {},
|
|
447
|
+
}
|
|
448
|
+
: null;
|
|
449
|
+
}))
|
|
450
|
+
.subscribe({
|
|
451
|
+
next: (result) => {
|
|
452
|
+
this._loading$.next(false);
|
|
453
|
+
resolve(result);
|
|
454
|
+
},
|
|
455
|
+
error: (error) => {
|
|
456
|
+
this._loading$.next(false);
|
|
457
|
+
console.error(error);
|
|
458
|
+
reject({
|
|
459
|
+
message: 'Error loading part ' + partId,
|
|
460
|
+
error: error,
|
|
684
461
|
});
|
|
685
|
-
}
|
|
686
|
-
}, (error) => {
|
|
687
|
-
console.error(error);
|
|
688
|
-
this.store.setLoading(false);
|
|
689
|
-
this.store.setError('Error loading fragment\'s part ' + partId);
|
|
462
|
+
},
|
|
690
463
|
});
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Load into the state the part with the specified ID
|
|
468
|
+
* and its thesauri.
|
|
469
|
+
* If the ID is not specified, it's a new part; in this case,
|
|
470
|
+
* it will get a null ID, but use the specified itemId and roleId.
|
|
471
|
+
*
|
|
472
|
+
* @param identity The part identity.
|
|
473
|
+
* @param thesauriIds The thesauri IDs array.
|
|
474
|
+
*/
|
|
475
|
+
load(identity, thesauriIds) {
|
|
476
|
+
if (thesauriIds === null || thesauriIds === void 0 ? void 0 : thesauriIds.length) {
|
|
477
|
+
return this.loadWithThesauri(identity, thesauriIds);
|
|
478
|
+
}
|
|
479
|
+
else {
|
|
480
|
+
return this.loadWithoutThesauri(identity.partId);
|
|
691
481
|
}
|
|
692
482
|
}
|
|
693
483
|
/**
|
|
694
|
-
* Save the
|
|
484
|
+
* Save the part.
|
|
695
485
|
*
|
|
696
486
|
* @param part The part.
|
|
697
|
-
* @returns Promise which when successful returns the
|
|
698
|
-
* saved part (which contains the fragment being saved).
|
|
487
|
+
* @returns Promise which when successful returns the saved part.
|
|
699
488
|
*/
|
|
700
489
|
save(part) {
|
|
701
|
-
this.
|
|
702
|
-
this.store.setDirty(true);
|
|
490
|
+
this._saving$.next(true);
|
|
703
491
|
return new Promise((resolve, reject) => {
|
|
704
|
-
this._itemService.addPart(part).subscribe(
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
492
|
+
this._itemService.addPart(part).subscribe({
|
|
493
|
+
next: (saved) => {
|
|
494
|
+
this._saving$.next(false);
|
|
495
|
+
resolve(saved);
|
|
496
|
+
},
|
|
497
|
+
error: (error) => {
|
|
498
|
+
this._saving$.next(false);
|
|
499
|
+
console.error(error);
|
|
500
|
+
reject({
|
|
501
|
+
message: 'Error saving part ' + part.id,
|
|
502
|
+
error: error,
|
|
503
|
+
});
|
|
504
|
+
},
|
|
717
505
|
});
|
|
718
506
|
});
|
|
719
507
|
}
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
508
|
+
}
|
|
509
|
+
PartEditorService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: PartEditorService, deps: [{ token: i1.ItemService }, { token: i1.ThesaurusService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
510
|
+
PartEditorService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: PartEditorService, providedIn: 'root' });
|
|
511
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: PartEditorService, decorators: [{
|
|
512
|
+
type: Injectable,
|
|
513
|
+
args: [{
|
|
514
|
+
providedIn: 'root',
|
|
515
|
+
}]
|
|
516
|
+
}], ctorParameters: function () { return [{ type: i1.ItemService }, { type: i1.ThesaurusService }]; } });
|
|
724
517
|
|
|
725
518
|
/**
|
|
726
519
|
* Base class for part feature editors.
|
|
727
|
-
* A part feature editor is a wrapper component
|
|
728
|
-
*
|
|
729
|
-
* to a corresponding wrapped UI editor.
|
|
730
|
-
* It implements ComponentCanDeactivate to allow using the
|
|
731
|
-
* PendingChangesGuard. To this end, it tracks the dirty state of
|
|
732
|
-
* the edited data coming from 2 different sources: the wrapped editor
|
|
733
|
-
* state (from its "root" form), and the store edit state. This is
|
|
734
|
-
* set to dirty when a save attempt fails.
|
|
735
|
-
* Thus, at the end the user will be prompted when closing an editor
|
|
736
|
-
* either because he has changed data in it, or because he attempted
|
|
737
|
-
* a save without success.
|
|
520
|
+
* A part feature editor is a wrapper component around a model editor component,
|
|
521
|
+
* used to separate the editor's logic from its host infrastructure.
|
|
738
522
|
*/
|
|
739
523
|
class EditPartFeatureBase {
|
|
740
|
-
constructor(router, route, snackbar,
|
|
524
|
+
constructor(router, route, snackbar, itemService, thesaurusService, editorService) {
|
|
741
525
|
this.router = router;
|
|
742
526
|
this.snackbar = snackbar;
|
|
743
|
-
this.
|
|
744
|
-
this.
|
|
745
|
-
this.
|
|
746
|
-
|
|
527
|
+
this.itemService = itemService;
|
|
528
|
+
this.thesaurusService = thesaurusService;
|
|
529
|
+
this.editorService = editorService;
|
|
530
|
+
// part route:
|
|
531
|
+
// /items/<iid>/@partGroup/@partTypeId/<pid>?rid
|
|
747
532
|
// item ID
|
|
748
|
-
|
|
749
|
-
// type ID (from "
|
|
750
|
-
|
|
533
|
+
const itemId = route.snapshot.params['iid'];
|
|
534
|
+
// type ID (from "@partTypeId/:pid")
|
|
535
|
+
const typeId = route.snapshot.routeConfig.path.substring(0, route.snapshot.routeConfig.path.indexOf('/'));
|
|
751
536
|
// part ID or null (if "new")
|
|
752
|
-
|
|
753
|
-
if (
|
|
754
|
-
|
|
537
|
+
let partId = route.snapshot.params['pid'];
|
|
538
|
+
if (partId === 'new') {
|
|
539
|
+
partId = null;
|
|
755
540
|
}
|
|
756
541
|
// role ID or null (if "default")
|
|
757
|
-
|
|
758
|
-
if (
|
|
759
|
-
|
|
542
|
+
let roleId = route.snapshot.queryParams['rid'];
|
|
543
|
+
if (roleId === 'default') {
|
|
544
|
+
roleId = null;
|
|
760
545
|
}
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
546
|
+
this.identity = {
|
|
547
|
+
itemId: itemId,
|
|
548
|
+
typeId: typeId,
|
|
549
|
+
partId: partId,
|
|
550
|
+
roleId: roleId,
|
|
551
|
+
};
|
|
552
|
+
// subscriptions
|
|
553
|
+
this._loadingSub = this.editorService.loading$.subscribe((loading) => (this.loading = loading));
|
|
554
|
+
this._savingSub = this.editorService.saving$.subscribe((saving) => (this.saving = saving));
|
|
766
555
|
}
|
|
767
556
|
/**
|
|
768
|
-
*
|
|
769
|
-
*
|
|
770
|
-
*
|
|
771
|
-
*
|
|
557
|
+
* Override in derived classes to return the IDs of the thesauri requested
|
|
558
|
+
* for this editor.
|
|
559
|
+
*
|
|
560
|
+
* @return Array with thesauri IDs, eventually empty.
|
|
772
561
|
*/
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
return !this._formDirty && !this._stateDirty;
|
|
776
|
-
}
|
|
777
|
-
ensureItemLoaded(id) {
|
|
778
|
-
if (!this._editItemQuery.hasItem(id)) {
|
|
779
|
-
this._editItemService.load(id);
|
|
780
|
-
}
|
|
562
|
+
getReqThesauriIds() {
|
|
563
|
+
return [];
|
|
781
564
|
}
|
|
782
565
|
/**
|
|
783
|
-
*
|
|
784
|
-
*
|
|
785
|
-
* @param thesauriIds The optional ID(s) of the thesauri sets you want
|
|
786
|
-
* to use in your editor.
|
|
566
|
+
* Called once data has been loaded.
|
|
787
567
|
*/
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
this.
|
|
792
|
-
|
|
793
|
-
this.
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
568
|
+
onDataLoaded() { }
|
|
569
|
+
ngOnInit() {
|
|
570
|
+
// load data
|
|
571
|
+
this.loading = true;
|
|
572
|
+
const thesIds = this.getReqThesauriIds();
|
|
573
|
+
this.editorService
|
|
574
|
+
.load(this.identity, thesIds)
|
|
575
|
+
.then((data) => {
|
|
576
|
+
if (data) {
|
|
577
|
+
this.data = data;
|
|
578
|
+
this.onDataLoaded();
|
|
579
|
+
}
|
|
580
|
+
})
|
|
581
|
+
.catch((reason) => {
|
|
582
|
+
this.snackbar.open(reason.message, 'OK');
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
ngOnDestroy() {
|
|
586
|
+
var _a, _b;
|
|
587
|
+
(_a = this._loadingSub) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
588
|
+
(_b = this._savingSub) === null || _b === void 0 ? void 0 : _b.unsubscribe();
|
|
589
|
+
}
|
|
590
|
+
canDeactivate() {
|
|
591
|
+
return !this.dirty;
|
|
799
592
|
}
|
|
800
593
|
/**
|
|
801
594
|
* Called when the wrapped editor dirty state changes.
|
|
@@ -806,7 +599,7 @@ class EditPartFeatureBase {
|
|
|
806
599
|
*/
|
|
807
600
|
onDirtyChange(value) {
|
|
808
601
|
console.log('part dirty change (from editor): ' + value);
|
|
809
|
-
this.
|
|
602
|
+
this.dirty = value;
|
|
810
603
|
}
|
|
811
604
|
/**
|
|
812
605
|
* Save the part.
|
|
@@ -814,284 +607,146 @@ class EditPartFeatureBase {
|
|
|
814
607
|
* @param part The part to be saved.
|
|
815
608
|
*/
|
|
816
609
|
save(part) {
|
|
817
|
-
|
|
818
|
-
// for the backend, and then updates the part's store
|
|
819
|
-
this._editPartService.save(part).then((saved) => {
|
|
610
|
+
this.editorService.save(part).then((saved) => {
|
|
820
611
|
// update the route-defined part ID if it was null (new part)
|
|
821
|
-
if (!this.partId) {
|
|
822
|
-
this.
|
|
612
|
+
if (!this.identity.partId) {
|
|
613
|
+
this.identity = Object.assign(Object.assign({}, this.identity), { partId: saved.id });
|
|
823
614
|
}
|
|
824
615
|
console.log('Part saved: ' + saved.id);
|
|
825
616
|
this.snackbar.open('Part saved', 'OK', {
|
|
826
617
|
duration: 3000,
|
|
827
618
|
});
|
|
828
|
-
}, (
|
|
829
|
-
|
|
830
|
-
this.snackbar.open('Error saving part', 'OK');
|
|
619
|
+
}, (reason) => {
|
|
620
|
+
this.snackbar.open(reason.message, 'OK');
|
|
831
621
|
});
|
|
832
622
|
}
|
|
833
623
|
/**
|
|
834
624
|
* Close the editor by navigating back to the part's item.
|
|
835
625
|
*/
|
|
836
626
|
close() {
|
|
837
|
-
this.router.navigate(['items', this.itemId]);
|
|
627
|
+
this.router.navigate(['items', this.identity.itemId]);
|
|
838
628
|
}
|
|
839
|
-
}
|
|
629
|
+
}
|
|
630
|
+
EditPartFeatureBase.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: EditPartFeatureBase, deps: [{ token: i1$1.Router }, { token: i1$1.ActivatedRoute }, { token: i2.MatSnackBar }, { token: i1.ItemService }, { token: i1.ThesaurusService }, { token: PartEditorService }], target: i0.ɵɵFactoryTarget.Component });
|
|
631
|
+
EditPartFeatureBase.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.0.0", type: EditPartFeatureBase, selector: "ng-component", ngImport: i0, template: '', isInline: true });
|
|
632
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: EditPartFeatureBase, decorators: [{
|
|
633
|
+
type: Component,
|
|
634
|
+
args: [{
|
|
635
|
+
template: '',
|
|
636
|
+
}]
|
|
637
|
+
}], ctorParameters: function () { return [{ type: i1$1.Router }, { type: i1$1.ActivatedRoute }, { type: i2.MatSnackBar }, { type: i1.ItemService }, { type: i1.ThesaurusService }, { type: PartEditorService }]; } });
|
|
840
638
|
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
this.
|
|
850
|
-
}
|
|
851
|
-
selectDirty() {
|
|
852
|
-
return this.select((state) => state.dirty);
|
|
853
|
-
}
|
|
854
|
-
selectSaving() {
|
|
855
|
-
return this.select((state) => state.saving);
|
|
639
|
+
class EditedThesaurusRepository {
|
|
640
|
+
constructor(_thesaurusService) {
|
|
641
|
+
this._thesaurusService = _thesaurusService;
|
|
642
|
+
this._store = createStore({ name: 'edited-thesaurus' }, withProps({}), withRequestsStatus());
|
|
643
|
+
this._loading$ = new BehaviorSubject(false);
|
|
644
|
+
this.loading$ = this._loading$.asObservable();
|
|
645
|
+
this._saving$ = new BehaviorSubject(false);
|
|
646
|
+
this.saving$ = this._saving$.asObservable();
|
|
647
|
+
this.thesaurus$ = this._store.pipe(select((state) => state.thesaurus));
|
|
856
648
|
}
|
|
857
|
-
|
|
858
|
-
return this.
|
|
649
|
+
getValue() {
|
|
650
|
+
return this._store.getValue();
|
|
859
651
|
}
|
|
860
|
-
|
|
861
|
-
return this.
|
|
862
|
-
}
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
/**
|
|
866
|
-
* Base class for part editor services.
|
|
867
|
-
*/
|
|
868
|
-
class EditPartServiceBase {
|
|
869
|
-
constructor(itemService, thesaurusService) {
|
|
870
|
-
this.itemService = itemService;
|
|
871
|
-
this.thesaurusService = thesaurusService;
|
|
652
|
+
getThesaurus() {
|
|
653
|
+
return this._store.query((state) => state.thesaurus);
|
|
872
654
|
}
|
|
873
655
|
/**
|
|
874
|
-
* Load
|
|
875
|
-
* and its thesauri.
|
|
876
|
-
* If the ID is not specified, it's a new part; in this case,
|
|
877
|
-
* it will get a null ID, but use the specified itemId and roleId.
|
|
656
|
+
* Load the specified thesaurus.
|
|
878
657
|
*
|
|
879
|
-
* @param
|
|
880
|
-
* @param thesauriIds The thesauri IDs array.
|
|
881
|
-
* @param itemId The item ID for the new part.
|
|
882
|
-
* @param typeId The part type ID for the new part.
|
|
883
|
-
* @param roleId The role ID for the new part.
|
|
658
|
+
* @param id The thesaurus ID or undefined to load a new thesaurus.
|
|
884
659
|
*/
|
|
885
|
-
load(
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
thesauri: this.thesaurusService.getThesauriSet(unscopedIds),
|
|
898
|
-
}).subscribe((result) => {
|
|
899
|
-
var _a;
|
|
900
|
-
// loading has ended
|
|
901
|
-
this.store.setLoading(false);
|
|
902
|
-
// update the store with a new or existing part,
|
|
903
|
-
// and its requested thesauri
|
|
904
|
-
this.store.update({
|
|
905
|
-
part: result.part || {
|
|
906
|
-
id: null,
|
|
907
|
-
itemId,
|
|
908
|
-
typeId,
|
|
909
|
-
roleId,
|
|
910
|
-
},
|
|
911
|
-
thesauri: result.thesauri,
|
|
912
|
-
});
|
|
913
|
-
// if the loaded part has a thesaurus scope, reload the thesauri
|
|
914
|
-
if ((_a = result.part) === null || _a === void 0 ? void 0 : _a.thesaurusScope) {
|
|
915
|
-
const scopedIds = thesauriIds.map((id) => {
|
|
916
|
-
var _a;
|
|
917
|
-
return this.thesaurusService.getScopedId(id, (_a = result.part) === null || _a === void 0 ? void 0 : _a.thesaurusScope);
|
|
918
|
-
});
|
|
919
|
-
// loading again
|
|
920
|
-
this.store.setLoading(true);
|
|
921
|
-
this.thesaurusService.getThesauriSet(scopedIds).subscribe((thesauri) => {
|
|
922
|
-
// completed, replace the thesauri
|
|
923
|
-
this.store.update({
|
|
924
|
-
thesauri,
|
|
925
|
-
loading: false,
|
|
926
|
-
});
|
|
927
|
-
}, (error) => {
|
|
928
|
-
console.error(error);
|
|
929
|
-
this.store.setLoading(false);
|
|
930
|
-
this.store.setError('Error loading thesauri ' + scopedIds.join(', '));
|
|
931
|
-
});
|
|
932
|
-
} // scoped
|
|
660
|
+
load(id) {
|
|
661
|
+
this._loading$.next(true);
|
|
662
|
+
if (id) {
|
|
663
|
+
this._thesaurusService.getThesaurus(id, true).subscribe({
|
|
664
|
+
next: (thesaurus) => {
|
|
665
|
+
this._loading$.next(false);
|
|
666
|
+
this._store.update(setProp('thesaurus', thesaurus));
|
|
667
|
+
},
|
|
668
|
+
error: (error) => {
|
|
669
|
+
this._loading$.next(false);
|
|
670
|
+
console.error('Error loding thesaurus: ' + JSON.stringify(error || {}));
|
|
671
|
+
},
|
|
933
672
|
});
|
|
934
673
|
}
|
|
935
674
|
else {
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
itemId,
|
|
942
|
-
typeId,
|
|
943
|
-
roleId,
|
|
944
|
-
},
|
|
945
|
-
loading: false,
|
|
946
|
-
error: null,
|
|
947
|
-
});
|
|
948
|
-
}, (error) => {
|
|
949
|
-
console.error(error);
|
|
950
|
-
this.store.setLoading(false);
|
|
951
|
-
this.store.setError('Error loading part ' + partId);
|
|
952
|
-
});
|
|
675
|
+
this._store.update(setProp('thesaurus', {
|
|
676
|
+
id: '',
|
|
677
|
+
language: 'en',
|
|
678
|
+
entries: [],
|
|
679
|
+
}));
|
|
953
680
|
}
|
|
954
681
|
}
|
|
955
682
|
/**
|
|
956
|
-
* Save the
|
|
683
|
+
* Save the specified thesaurus.
|
|
957
684
|
*
|
|
958
|
-
* @param
|
|
959
|
-
* @returns Promise
|
|
685
|
+
* @param thesaurus The thesaurus to save.
|
|
686
|
+
* @returns Promise with saved thesaurus.
|
|
960
687
|
*/
|
|
961
|
-
save(
|
|
962
|
-
this.
|
|
963
|
-
this.store.setDirty(true);
|
|
688
|
+
save(thesaurus) {
|
|
689
|
+
this._saving$.next(true);
|
|
964
690
|
return new Promise((resolve, reject) => {
|
|
965
|
-
this.
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
this.store.setError('Error saving part');
|
|
977
|
-
reject(error);
|
|
691
|
+
this._thesaurusService.addThesaurus(thesaurus).subscribe({
|
|
692
|
+
next: (saved) => {
|
|
693
|
+
this._saving$.next(false);
|
|
694
|
+
this.load(saved.id);
|
|
695
|
+
resolve(saved);
|
|
696
|
+
},
|
|
697
|
+
error: (error) => {
|
|
698
|
+
this._saving$.next(false);
|
|
699
|
+
console.error('Error loding thesaurus: ' + JSON.stringify(error || {}));
|
|
700
|
+
reject(error);
|
|
701
|
+
},
|
|
978
702
|
});
|
|
979
703
|
});
|
|
980
704
|
}
|
|
981
|
-
setDirty(value = true) {
|
|
982
|
-
this.store.setDirty(value);
|
|
983
|
-
}
|
|
984
|
-
}
|
|
985
|
-
|
|
986
|
-
/**
|
|
987
|
-
* General-purpose edit-part store. This can be used with any part, so that
|
|
988
|
-
* you should only provide your part store, query, and service (usually
|
|
989
|
-
* extending EditPartServiceBase).
|
|
990
|
-
*/
|
|
991
|
-
let EditPartStore = class EditPartStore extends Store {
|
|
992
|
-
constructor() {
|
|
993
|
-
super({});
|
|
994
|
-
}
|
|
995
|
-
setDirty(value) {
|
|
996
|
-
this.update({ dirty: value });
|
|
997
|
-
}
|
|
998
|
-
setSaving(value) {
|
|
999
|
-
this.update({ saving: value });
|
|
1000
|
-
}
|
|
1001
|
-
};
|
|
1002
|
-
EditPartStore.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: EditPartStore, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1003
|
-
EditPartStore.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: EditPartStore, providedIn: 'root' });
|
|
1004
|
-
EditPartStore = __decorate([
|
|
1005
|
-
StoreConfig({ name: 'edit-part' })
|
|
1006
|
-
], EditPartStore);
|
|
1007
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: EditPartStore, decorators: [{
|
|
1008
|
-
type: Injectable,
|
|
1009
|
-
args: [{ providedIn: 'root' }]
|
|
1010
|
-
}], ctorParameters: function () { return []; } });
|
|
1011
|
-
|
|
1012
|
-
const initialState = {
|
|
1013
|
-
locations: [],
|
|
1014
|
-
breakChance: -1,
|
|
1015
|
-
layerHints: [],
|
|
1016
|
-
thesauri: {},
|
|
1017
|
-
loading: false,
|
|
1018
|
-
deletingFragment: false,
|
|
1019
|
-
savingFragment: false,
|
|
1020
|
-
refreshingBreakChance: false,
|
|
1021
|
-
patchingLayer: false,
|
|
1022
|
-
};
|
|
1023
|
-
let EditLayerPartStore = class EditLayerPartStore extends Store {
|
|
1024
|
-
constructor() {
|
|
1025
|
-
super(initialState);
|
|
1026
|
-
}
|
|
1027
|
-
setDeletingFragment(value = true) {
|
|
1028
|
-
this.update({ deletingFragment: value });
|
|
1029
|
-
}
|
|
1030
|
-
setSavingFragment(value = true) {
|
|
1031
|
-
this.update({ savingFragment: value });
|
|
1032
|
-
}
|
|
1033
|
-
setRefreshingBreakChance(value = true) {
|
|
1034
|
-
this.update({ refreshingBreakChance: value });
|
|
1035
|
-
}
|
|
1036
|
-
setBreakChance(value) {
|
|
1037
|
-
this.update({ breakChance: value });
|
|
1038
|
-
}
|
|
1039
|
-
setPatchingLayer(value = true) {
|
|
1040
|
-
this.update({ patchingLayer: value });
|
|
1041
|
-
}
|
|
1042
|
-
setLocations(locations) {
|
|
1043
|
-
this.update({ locations });
|
|
1044
|
-
}
|
|
1045
|
-
};
|
|
1046
|
-
EditLayerPartStore.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: EditLayerPartStore, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1047
|
-
EditLayerPartStore.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: EditLayerPartStore, providedIn: 'root' });
|
|
1048
|
-
EditLayerPartStore = __decorate([
|
|
1049
|
-
StoreConfig({ name: 'edit-layer-part' })
|
|
1050
|
-
], EditLayerPartStore);
|
|
1051
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: EditLayerPartStore, decorators: [{
|
|
1052
|
-
type: Injectable,
|
|
1053
|
-
args: [{ providedIn: 'root' }]
|
|
1054
|
-
}], ctorParameters: function () { return []; } });
|
|
1055
|
-
|
|
1056
|
-
class EditLayerPartQuery extends Query {
|
|
1057
|
-
constructor(store) {
|
|
1058
|
-
super(store);
|
|
1059
|
-
this.store = store;
|
|
1060
|
-
}
|
|
1061
|
-
selectDeletingFragment() {
|
|
1062
|
-
return this.select((state) => state.deletingFragment);
|
|
1063
|
-
}
|
|
1064
|
-
selectSavingFragment() {
|
|
1065
|
-
return this.select((state) => state.savingFragment);
|
|
1066
|
-
}
|
|
1067
|
-
selectRefreshingBreakChance() {
|
|
1068
|
-
return this.select((state) => state.refreshingBreakChance);
|
|
1069
|
-
}
|
|
1070
|
-
selectBreakChance() {
|
|
1071
|
-
return this.select((state) => state.breakChance);
|
|
1072
|
-
}
|
|
1073
|
-
selectLayerHints() {
|
|
1074
|
-
return this.select((state) => state.layerHints);
|
|
1075
|
-
}
|
|
1076
|
-
selectPatchingLayers() {
|
|
1077
|
-
return this.select((state) => state.patchingLayer);
|
|
1078
|
-
}
|
|
1079
705
|
}
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
706
|
+
EditedThesaurusRepository.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: EditedThesaurusRepository, deps: [{ token: i1.ThesaurusService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
707
|
+
EditedThesaurusRepository.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: EditedThesaurusRepository, providedIn: 'root' });
|
|
708
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: EditedThesaurusRepository, decorators: [{
|
|
1083
709
|
type: Injectable,
|
|
1084
710
|
args: [{ providedIn: 'root' }]
|
|
1085
|
-
}], ctorParameters: function () { return [{ type:
|
|
711
|
+
}], ctorParameters: function () { return [{ type: i1.ThesaurusService }]; } });
|
|
1086
712
|
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
713
|
+
/**
|
|
714
|
+
* Edited layer part ELF repository.
|
|
715
|
+
*/
|
|
716
|
+
class EditedLayerRepository {
|
|
717
|
+
constructor(_itemService, _facetService, _thesaurusService) {
|
|
1090
718
|
this._itemService = _itemService;
|
|
1091
719
|
this._facetService = _facetService;
|
|
1092
720
|
this._thesaurusService = _thesaurusService;
|
|
1093
|
-
|
|
1094
|
-
|
|
721
|
+
this._store = createStore({ name: 'edited-layer' }, withProps({
|
|
722
|
+
locations: [],
|
|
723
|
+
breakChance: 0,
|
|
724
|
+
layerHints: [],
|
|
725
|
+
}), withRequestsStatus());
|
|
726
|
+
this._loading$ = new BehaviorSubject(false);
|
|
727
|
+
this.loading$ = this._loading$.asObservable();
|
|
728
|
+
this._saving$ = new BehaviorSubject(false);
|
|
729
|
+
this.saving$ = this._saving$.asObservable();
|
|
730
|
+
this.part$ = this._store.pipe(select((state) => state.part));
|
|
731
|
+
this.baseText$ = this._store.pipe(select((state) => state.baseText));
|
|
732
|
+
this.baseTextPart$ = this._store.pipe(select((state) => state.baseTextPart));
|
|
733
|
+
this.locations$ = this._store.pipe(select((state) => state.locations));
|
|
734
|
+
this.breakChance$ = this._store.pipe(select((state) => state.breakChance));
|
|
735
|
+
this.layerHints$ = this._store.pipe(select((state) => state.layerHints));
|
|
736
|
+
}
|
|
737
|
+
getValue() {
|
|
738
|
+
return this._store.getValue();
|
|
739
|
+
}
|
|
740
|
+
getPart() {
|
|
741
|
+
return this._store.query((state) => state.part);
|
|
742
|
+
}
|
|
743
|
+
getBaseText() {
|
|
744
|
+
return this._store.query((state => state.baseText));
|
|
745
|
+
}
|
|
746
|
+
getLocations() {
|
|
747
|
+
return this._store.query((state) => state.locations);
|
|
748
|
+
}
|
|
749
|
+
getPartLocations(part) {
|
|
1095
750
|
const locations = [];
|
|
1096
751
|
if (part && part.fragments) {
|
|
1097
752
|
part.fragments.forEach((p) => {
|
|
@@ -1100,6 +755,70 @@ class EditLayerPartService {
|
|
|
1100
755
|
}
|
|
1101
756
|
return locations;
|
|
1102
757
|
}
|
|
758
|
+
loadWithThesauri(itemId, partId, thesauriIds) {
|
|
759
|
+
// remove trailing ! from IDs if any
|
|
760
|
+
const unscopedIds = thesauriIds.map((id) => {
|
|
761
|
+
return this._thesaurusService.getScopedId(id);
|
|
762
|
+
});
|
|
763
|
+
this._loading$.next(true);
|
|
764
|
+
forkJoin({
|
|
765
|
+
// TODO: eventually optimize by adding method param to load only fragments locations
|
|
766
|
+
layerPart: this._itemService.getPart(partId),
|
|
767
|
+
baseText: this._itemService.getBaseTextPart(itemId),
|
|
768
|
+
layers: this._facetService.getFacetParts(itemId, true),
|
|
769
|
+
breakChance: this._itemService.getLayerPartBreakChance(partId),
|
|
770
|
+
layerHints: this._itemService.getLayerPartHints(partId),
|
|
771
|
+
thesauri: this._thesaurusService.getThesauriSet(unscopedIds),
|
|
772
|
+
}).subscribe({
|
|
773
|
+
next: (result) => {
|
|
774
|
+
var _a;
|
|
775
|
+
// if the loaded part has a thesaurus scope, reload the thesauri
|
|
776
|
+
if ((_a = result.layerPart) === null || _a === void 0 ? void 0 : _a.thesaurusScope) {
|
|
777
|
+
const scopedIds = thesauriIds.map((id) => {
|
|
778
|
+
return this._thesaurusService.getScopedId(id, result.layerPart.thesaurusScope);
|
|
779
|
+
});
|
|
780
|
+
this._thesaurusService.getThesauriSet(scopedIds).subscribe({
|
|
781
|
+
next: (thesauri) => {
|
|
782
|
+
this._loading$.next(false);
|
|
783
|
+
this._store.update((state) => (Object.assign(Object.assign({}, state), { part: result.layerPart, baseText: result.baseText.text, baseTextPart: result.baseText.part, locations: this.getPartLocations(result.layerPart), breakChance: result.breakChance.chance, layerHints: result.layerHints, thesauri: thesauri })));
|
|
784
|
+
},
|
|
785
|
+
error: (error) => {
|
|
786
|
+
this._loading$.next(false);
|
|
787
|
+
console.error('Error loading thesauri: ' + JSON.stringify(error || {}));
|
|
788
|
+
},
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
else {
|
|
792
|
+
this._loading$.next(false);
|
|
793
|
+
this._store.update((state) => (Object.assign(Object.assign({}, state), { part: result.layerPart, baseText: result.baseText.text, baseTextPart: result.baseText.part, locations: this.getPartLocations(result.layerPart), breakChance: result.breakChance.chance, layerHints: result.layerHints, thesauri: result.thesauri })));
|
|
794
|
+
}
|
|
795
|
+
},
|
|
796
|
+
error: (error) => {
|
|
797
|
+
this._loading$.next(false);
|
|
798
|
+
console.error('Error loading text layer part: ' + JSON.stringify(error || {}));
|
|
799
|
+
},
|
|
800
|
+
});
|
|
801
|
+
}
|
|
802
|
+
loadWithoutThesauri(itemId, partId) {
|
|
803
|
+
this._loading$.next(true);
|
|
804
|
+
forkJoin({
|
|
805
|
+
// TODO: eventually optimize by adding method param to load only fragments locations
|
|
806
|
+
layerPart: this._itemService.getPart(partId),
|
|
807
|
+
baseText: this._itemService.getBaseTextPart(itemId),
|
|
808
|
+
layers: this._facetService.getFacetParts(itemId, true),
|
|
809
|
+
breakChance: this._itemService.getLayerPartBreakChance(partId),
|
|
810
|
+
layerHints: this._itemService.getLayerPartHints(partId),
|
|
811
|
+
}).subscribe({
|
|
812
|
+
next: (result) => {
|
|
813
|
+
this._loading$.next(false);
|
|
814
|
+
this._store.update((state) => (Object.assign(Object.assign({}, state), { part: result.layerPart, baseText: result.baseText.text, baseTextPart: result.baseText.part, locations: this.getPartLocations(result.layerPart), breakChance: result.breakChance.chance, layerHints: result.layerHints })));
|
|
815
|
+
},
|
|
816
|
+
error: (error) => {
|
|
817
|
+
this._loading$.next(false);
|
|
818
|
+
console.error('Error loading text layer part: ' + JSON.stringify(error || {}));
|
|
819
|
+
},
|
|
820
|
+
});
|
|
821
|
+
}
|
|
1103
822
|
/**
|
|
1104
823
|
* Load the state for editing layer part(s).
|
|
1105
824
|
*
|
|
@@ -1108,82 +827,11 @@ class EditLayerPartService {
|
|
|
1108
827
|
* @param thesauriIds The optional thesauri IDs to load.
|
|
1109
828
|
*/
|
|
1110
829
|
load(itemId, partId, thesauriIds) {
|
|
1111
|
-
if (
|
|
1112
|
-
|
|
1113
|
-
}
|
|
1114
|
-
this._store.setLoading(true);
|
|
1115
|
-
if (thesauriIds) {
|
|
1116
|
-
// remove trailing ! from IDs if any
|
|
1117
|
-
const unscopedIds = thesauriIds.map((id) => {
|
|
1118
|
-
return this._thesaurusService.getScopedId(id);
|
|
1119
|
-
});
|
|
1120
|
-
forkJoin({
|
|
1121
|
-
// TODO: eventually optimize by adding method param to load only fragments locations
|
|
1122
|
-
layerPart: this._itemService.getPart(partId),
|
|
1123
|
-
baseText: this._itemService.getBaseTextPart(itemId),
|
|
1124
|
-
layers: this._facetService.getFacetParts(itemId, true),
|
|
1125
|
-
breakChance: this._itemService.getLayerPartBreakChance(partId),
|
|
1126
|
-
layerHints: this._itemService.getLayerPartHints(partId),
|
|
1127
|
-
thesauri: this._thesaurusService.getThesauriSet(unscopedIds),
|
|
1128
|
-
}).subscribe((result) => {
|
|
1129
|
-
var _a;
|
|
1130
|
-
this._store.update({
|
|
1131
|
-
part: result.layerPart,
|
|
1132
|
-
baseText: result.baseText.text,
|
|
1133
|
-
baseTextPart: result.baseText.part,
|
|
1134
|
-
locations: this.getLocations(result.layerPart),
|
|
1135
|
-
breakChance: result.breakChance.chance,
|
|
1136
|
-
layerHints: result.layerHints,
|
|
1137
|
-
thesauri: result.thesauri,
|
|
1138
|
-
loading: false,
|
|
1139
|
-
error: undefined,
|
|
1140
|
-
});
|
|
1141
|
-
// if the loaded part has a thesaurus scope, reload the thesauri
|
|
1142
|
-
if ((_a = result.layerPart) === null || _a === void 0 ? void 0 : _a.thesaurusScope) {
|
|
1143
|
-
const scopedIds = thesauriIds.map((id) => {
|
|
1144
|
-
return this._thesaurusService.getScopedId(id, result.layerPart.thesaurusScope);
|
|
1145
|
-
});
|
|
1146
|
-
this._store.setLoading(true);
|
|
1147
|
-
this._thesaurusService.getThesauriSet(scopedIds).subscribe((thesauri) => {
|
|
1148
|
-
this._store.update({
|
|
1149
|
-
thesauri,
|
|
1150
|
-
});
|
|
1151
|
-
}, (error) => {
|
|
1152
|
-
console.error(error);
|
|
1153
|
-
this._store.setLoading(false);
|
|
1154
|
-
this._store.setError('Error loading thesauri ' + scopedIds.join(', '));
|
|
1155
|
-
});
|
|
1156
|
-
} // scoped
|
|
1157
|
-
}, (error) => {
|
|
1158
|
-
console.error(error);
|
|
1159
|
-
this._store.setLoading(false);
|
|
1160
|
-
this._store.setError('Error loading text layer part ' + partId);
|
|
1161
|
-
});
|
|
830
|
+
if (thesauriIds === null || thesauriIds === void 0 ? void 0 : thesauriIds.length) {
|
|
831
|
+
this.loadWithThesauri(itemId, partId, thesauriIds);
|
|
1162
832
|
}
|
|
1163
833
|
else {
|
|
1164
|
-
|
|
1165
|
-
// TODO: eventually optimize by adding method param to load only fragments locations
|
|
1166
|
-
layerPart: this._itemService.getPart(partId),
|
|
1167
|
-
baseText: this._itemService.getBaseTextPart(itemId),
|
|
1168
|
-
layers: this._facetService.getFacetParts(itemId, true),
|
|
1169
|
-
breakChance: this._itemService.getLayerPartBreakChance(partId),
|
|
1170
|
-
layerHints: this._itemService.getLayerPartHints(partId),
|
|
1171
|
-
}).subscribe((result) => {
|
|
1172
|
-
this._store.update({
|
|
1173
|
-
part: result.layerPart,
|
|
1174
|
-
baseText: result.baseText.text,
|
|
1175
|
-
baseTextPart: result.baseText.part,
|
|
1176
|
-
locations: this.getLocations(result.layerPart),
|
|
1177
|
-
breakChance: result.breakChance.chance,
|
|
1178
|
-
layerHints: result.layerHints,
|
|
1179
|
-
loading: false,
|
|
1180
|
-
error: undefined,
|
|
1181
|
-
});
|
|
1182
|
-
}, (error) => {
|
|
1183
|
-
console.error(error);
|
|
1184
|
-
this._store.setLoading(false);
|
|
1185
|
-
this._store.setError('Error loading text layer part ' + partId);
|
|
1186
|
-
});
|
|
834
|
+
this.loadWithoutThesauri(itemId, partId);
|
|
1187
835
|
}
|
|
1188
836
|
}
|
|
1189
837
|
/**
|
|
@@ -1192,29 +840,30 @@ class EditLayerPartService {
|
|
|
1192
840
|
refreshBreakChance() {
|
|
1193
841
|
const store = this._store.getValue();
|
|
1194
842
|
const part = store.part;
|
|
1195
|
-
if (!part
|
|
843
|
+
if (!part) {
|
|
1196
844
|
return;
|
|
1197
845
|
}
|
|
1198
|
-
this.
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
this._store.setError('Error refreshing break chance for text layer part ' + part.id);
|
|
846
|
+
this._itemService.getLayerPartBreakChance(part.id).subscribe({
|
|
847
|
+
next: (result) => {
|
|
848
|
+
this._store.update(setProp('breakChance', result.chance));
|
|
849
|
+
},
|
|
850
|
+
error: (error) => {
|
|
851
|
+
console.error('Error calculating break chance: ' + JSON.stringify(error || {}));
|
|
852
|
+
this._store.update(setProp('breakChance', -1));
|
|
853
|
+
},
|
|
1207
854
|
});
|
|
1208
855
|
}
|
|
1209
856
|
applyLayerPatches(partId, patches) {
|
|
1210
|
-
this.
|
|
1211
|
-
this._itemService.applyLayerPatches(partId, patches).subscribe(
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
857
|
+
this._saving$.next(true);
|
|
858
|
+
this._itemService.applyLayerPatches(partId, patches).subscribe({
|
|
859
|
+
next: (part) => {
|
|
860
|
+
this._saving$.next(false);
|
|
861
|
+
this.load(part.itemId, partId);
|
|
862
|
+
},
|
|
863
|
+
error: (error) => {
|
|
864
|
+
this._saving$.next(false);
|
|
865
|
+
console.error('Error patching text layer part: ' + JSON.stringify(error || {}));
|
|
866
|
+
},
|
|
1218
867
|
});
|
|
1219
868
|
}
|
|
1220
869
|
/**
|
|
@@ -1223,7 +872,6 @@ class EditLayerPartService {
|
|
|
1223
872
|
* @param loc The fragment's location.
|
|
1224
873
|
*/
|
|
1225
874
|
deleteFragment(loc) {
|
|
1226
|
-
this._store.setDeletingFragment(true);
|
|
1227
875
|
// find the fragment
|
|
1228
876
|
let part = this._store.getValue().part;
|
|
1229
877
|
if (!part) {
|
|
@@ -1236,23 +884,23 @@ class EditLayerPartService {
|
|
|
1236
884
|
if (i === -1) {
|
|
1237
885
|
return;
|
|
1238
886
|
}
|
|
887
|
+
this._saving$.next(true);
|
|
1239
888
|
// remove it from the part
|
|
1240
889
|
// work on a copy, as store objects are immutable
|
|
1241
890
|
part = deepCopy(part);
|
|
1242
891
|
part.fragments.splice(i, 1);
|
|
1243
892
|
// update the part and reload state once done
|
|
1244
|
-
this._itemService.addPart(part).subscribe(
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
this._store.setError(`Error deleting fragment at ${loc} in part ${part.id}`);
|
|
893
|
+
this._itemService.addPart(part).subscribe({
|
|
894
|
+
next: (_) => {
|
|
895
|
+
this._saving$.next(false);
|
|
896
|
+
this.load(part.itemId, part.id);
|
|
897
|
+
},
|
|
898
|
+
error: (error) => {
|
|
899
|
+
this._saving$.next(false);
|
|
900
|
+
console.error(error);
|
|
901
|
+
console.error(`Error deleting fragment at ${loc} in part ${part.id}: ` +
|
|
902
|
+
JSON.stringify(error || {}));
|
|
903
|
+
},
|
|
1256
904
|
});
|
|
1257
905
|
}
|
|
1258
906
|
/**
|
|
@@ -1261,7 +909,6 @@ class EditLayerPartService {
|
|
|
1261
909
|
* @param fragment The fragment.
|
|
1262
910
|
*/
|
|
1263
911
|
saveFragment(fragment) {
|
|
1264
|
-
this._store.setSavingFragment();
|
|
1265
912
|
// find the fragment
|
|
1266
913
|
let part = this._store.getValue().part;
|
|
1267
914
|
if (!part) {
|
|
@@ -1269,6 +916,7 @@ class EditLayerPartService {
|
|
|
1269
916
|
}
|
|
1270
917
|
// add or replace it
|
|
1271
918
|
// work on a copy, as store objects are immutable
|
|
919
|
+
this._saving$.next(true);
|
|
1272
920
|
part = deepCopy(part);
|
|
1273
921
|
// replace all the overlapping fragments with the new one
|
|
1274
922
|
const newLoc = TokenLocation.parse(fragment.location);
|
|
@@ -1288,143 +936,39 @@ class EditLayerPartService {
|
|
|
1288
936
|
// add the new fragment
|
|
1289
937
|
part.fragments.splice(insertAt, 0, fragment);
|
|
1290
938
|
// update the part and reload once done
|
|
1291
|
-
this._itemService.addPart(part).subscribe(
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
this._store.setSavingFragment(false);
|
|
1301
|
-
this._store.setError(`Error saving fragment at ${fragment.location} in part ${part.id}`);
|
|
1302
|
-
});
|
|
1303
|
-
}
|
|
1304
|
-
}
|
|
1305
|
-
EditLayerPartService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: EditLayerPartService, deps: [{ token: EditLayerPartStore }, { token: i2.ItemService }, { token: i2.FacetService }, { token: i2.ThesaurusService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1306
|
-
EditLayerPartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: EditLayerPartService, providedIn: 'root' });
|
|
1307
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: EditLayerPartService, decorators: [{
|
|
1308
|
-
type: Injectable,
|
|
1309
|
-
args: [{ providedIn: 'root' }]
|
|
1310
|
-
}], ctorParameters: function () { return [{ type: EditLayerPartStore }, { type: i2.ItemService }, { type: i2.FacetService }, { type: i2.ThesaurusService }]; } });
|
|
1311
|
-
|
|
1312
|
-
let EditThesaurusStore = class EditThesaurusStore extends Store {
|
|
1313
|
-
constructor() {
|
|
1314
|
-
super({});
|
|
1315
|
-
}
|
|
1316
|
-
setDirty(value = true) {
|
|
1317
|
-
this.update({
|
|
1318
|
-
dirty: value,
|
|
1319
|
-
});
|
|
1320
|
-
}
|
|
1321
|
-
setSaving(value = true) {
|
|
1322
|
-
this.update({
|
|
1323
|
-
saving: value,
|
|
1324
|
-
});
|
|
1325
|
-
}
|
|
1326
|
-
};
|
|
1327
|
-
EditThesaurusStore.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: EditThesaurusStore, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1328
|
-
EditThesaurusStore.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: EditThesaurusStore, providedIn: 'root' });
|
|
1329
|
-
EditThesaurusStore = __decorate([
|
|
1330
|
-
StoreConfig({ name: 'edit-thesaurus', resettable: true })
|
|
1331
|
-
], EditThesaurusStore);
|
|
1332
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: EditThesaurusStore, decorators: [{
|
|
1333
|
-
type: Injectable,
|
|
1334
|
-
args: [{ providedIn: 'root' }]
|
|
1335
|
-
}], ctorParameters: function () { return []; } });
|
|
1336
|
-
|
|
1337
|
-
class EditThesaurusQuery extends Query {
|
|
1338
|
-
constructor(store) {
|
|
1339
|
-
super(store);
|
|
1340
|
-
this.store = store;
|
|
1341
|
-
}
|
|
1342
|
-
selectThesaurus() {
|
|
1343
|
-
return this.select(state => state.thesaurus);
|
|
1344
|
-
}
|
|
1345
|
-
// public selectLoading(): Observable<boolean | undefined> {
|
|
1346
|
-
// return this.select(state => state.loading);
|
|
1347
|
-
// }
|
|
1348
|
-
selectSaving() {
|
|
1349
|
-
return this.select(state => state.saving);
|
|
1350
|
-
}
|
|
1351
|
-
}
|
|
1352
|
-
EditThesaurusQuery.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: EditThesaurusQuery, deps: [{ token: EditThesaurusStore }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1353
|
-
EditThesaurusQuery.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: EditThesaurusQuery, providedIn: 'root' });
|
|
1354
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: EditThesaurusQuery, decorators: [{
|
|
1355
|
-
type: Injectable,
|
|
1356
|
-
args: [{ providedIn: 'root' }]
|
|
1357
|
-
}], ctorParameters: function () { return [{ type: EditThesaurusStore }]; } });
|
|
1358
|
-
|
|
1359
|
-
class EditThesaurusService {
|
|
1360
|
-
constructor(_store, _thesaurusService) {
|
|
1361
|
-
this._store = _store;
|
|
1362
|
-
this._thesaurusService = _thesaurusService;
|
|
1363
|
-
}
|
|
1364
|
-
load(id) {
|
|
1365
|
-
this._store.setLoading(true);
|
|
1366
|
-
if (id) {
|
|
1367
|
-
this._thesaurusService.getThesaurus(id, true).subscribe((thesaurus) => {
|
|
1368
|
-
this._store.setLoading(false);
|
|
1369
|
-
this._store.update({
|
|
1370
|
-
thesaurus,
|
|
1371
|
-
});
|
|
1372
|
-
}, (error) => {
|
|
1373
|
-
console.error(error);
|
|
1374
|
-
this._store.setLoading(false);
|
|
1375
|
-
this._store.setError('Error loading thesaurus ' + id);
|
|
1376
|
-
});
|
|
1377
|
-
}
|
|
1378
|
-
else {
|
|
1379
|
-
this._store.update({
|
|
1380
|
-
thesaurus: {
|
|
1381
|
-
id: '',
|
|
1382
|
-
language: 'en',
|
|
1383
|
-
entries: [],
|
|
1384
|
-
},
|
|
1385
|
-
});
|
|
1386
|
-
}
|
|
1387
|
-
}
|
|
1388
|
-
reset() {
|
|
1389
|
-
this._store.reset();
|
|
1390
|
-
}
|
|
1391
|
-
save(thesaurus) {
|
|
1392
|
-
this._store.setSaving(true);
|
|
1393
|
-
return new Promise((resolve, reject) => {
|
|
1394
|
-
this._thesaurusService.addThesaurus(thesaurus).subscribe((saved) => {
|
|
1395
|
-
this._store.setSaving(false);
|
|
1396
|
-
this.load(this._store.getValue().thesaurus.id);
|
|
1397
|
-
resolve(saved);
|
|
1398
|
-
}, (error) => {
|
|
1399
|
-
console.error(error);
|
|
1400
|
-
this._store.setSaving(false);
|
|
1401
|
-
this._store.setError('Error saving thesaurus');
|
|
1402
|
-
reject(error);
|
|
1403
|
-
});
|
|
939
|
+
this._itemService.addPart(part).subscribe({
|
|
940
|
+
next: (_) => {
|
|
941
|
+
this._saving$.next(false);
|
|
942
|
+
this.load(part.itemId, part.id);
|
|
943
|
+
},
|
|
944
|
+
error: (error) => {
|
|
945
|
+
this._saving$.next(false);
|
|
946
|
+
console.error(`Error saving fragment at ${fragment.location} in part ${part.id}: ` + JSON.stringify(error || {}));
|
|
947
|
+
},
|
|
1404
948
|
});
|
|
1405
949
|
}
|
|
1406
950
|
}
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
951
|
+
EditedLayerRepository.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: EditedLayerRepository, deps: [{ token: i1.ItemService }, { token: i1.FacetService }, { token: i1.ThesaurusService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
952
|
+
EditedLayerRepository.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: EditedLayerRepository, providedIn: 'root' });
|
|
953
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: EditedLayerRepository, decorators: [{
|
|
1410
954
|
type: Injectable,
|
|
1411
955
|
args: [{ providedIn: 'root' }]
|
|
1412
|
-
}], ctorParameters: function () { return [{ type:
|
|
956
|
+
}], ctorParameters: function () { return [{ type: i1.ItemService }, { type: i1.FacetService }, { type: i1.ThesaurusService }]; } });
|
|
1413
957
|
|
|
1414
958
|
class CadmusStateModule {
|
|
1415
959
|
}
|
|
1416
|
-
CadmusStateModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
1417
|
-
CadmusStateModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "
|
|
960
|
+
CadmusStateModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: CadmusStateModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
961
|
+
CadmusStateModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.0.0", ngImport: i0, type: CadmusStateModule, imports: [CommonModule,
|
|
1418
962
|
// Cadmus
|
|
1419
963
|
CadmusCoreModule,
|
|
1420
964
|
CadmusApiModule,
|
|
1421
965
|
NgToolsModule] });
|
|
1422
|
-
CadmusStateModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "
|
|
966
|
+
CadmusStateModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: CadmusStateModule, imports: [CommonModule,
|
|
1423
967
|
// Cadmus
|
|
1424
968
|
CadmusCoreModule,
|
|
1425
969
|
CadmusApiModule,
|
|
1426
970
|
NgToolsModule] });
|
|
1427
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
971
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: CadmusStateModule, decorators: [{
|
|
1428
972
|
type: NgModule,
|
|
1429
973
|
args: [{
|
|
1430
974
|
imports: [
|
|
@@ -1445,5 +989,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.3", ngImpor
|
|
|
1445
989
|
* Generated bundle index. Do not edit.
|
|
1446
990
|
*/
|
|
1447
991
|
|
|
1448
|
-
export {
|
|
992
|
+
export { AppRepository, CadmusStateModule, EditFragmentFeatureBase, EditPartFeatureBase, EditedLayerRepository, EditedThesaurusRepository, FragmentEditorService, PartEditorService };
|
|
993
|
+
//# sourceMappingURL=myrmidon-cadmus-state.mjs.map
|
|
1449
994
|
//# sourceMappingURL=myrmidon-cadmus-state.mjs.map
|