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