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