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