@myrmidon/cadmus-item-editor 0.0.13 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/README.md +24 -24
  2. package/esm2020/lib/cadmus-item-editor.module.mjs +83 -0
  3. package/esm2020/lib/item-editor/item-editor.component.mjs +353 -0
  4. package/esm2020/lib/missing-parts/missing-parts.component.mjs +71 -0
  5. package/esm2020/lib/parts-scope-editor/parts-scope-editor.component.mjs +118 -0
  6. package/esm2020/myrmidon-cadmus-item-editor.mjs +5 -0
  7. package/esm2020/public-api.mjs +6 -0
  8. package/fesm2015/myrmidon-cadmus-item-editor.mjs +607 -0
  9. package/fesm2015/myrmidon-cadmus-item-editor.mjs.map +1 -0
  10. package/fesm2020/myrmidon-cadmus-item-editor.mjs +604 -0
  11. package/fesm2020/myrmidon-cadmus-item-editor.mjs.map +1 -0
  12. package/lib/cadmus-item-editor.module.d.ts +19 -0
  13. package/lib/item-editor/item-editor.component.d.ts +20 -17
  14. package/lib/missing-parts/missing-parts.component.d.ts +12 -9
  15. package/lib/parts-scope-editor/parts-scope-editor.component.d.ts +8 -5
  16. package/myrmidon-cadmus-item-editor.d.ts +1 -2
  17. package/package.json +27 -15
  18. package/bundles/myrmidon-cadmus-item-editor.umd.js +0 -929
  19. package/bundles/myrmidon-cadmus-item-editor.umd.js.map +0 -1
  20. package/bundles/myrmidon-cadmus-item-editor.umd.min.js +0 -16
  21. package/bundles/myrmidon-cadmus-item-editor.umd.min.js.map +0 -1
  22. package/esm2015/lib/cadmus-item-editor.module.js +0 -45
  23. package/esm2015/lib/item-editor/item-editor.component.js +0 -337
  24. package/esm2015/lib/missing-parts/missing-parts.component.js +0 -62
  25. package/esm2015/lib/parts-scope-editor/parts-scope-editor.component.js +0 -115
  26. package/esm2015/myrmidon-cadmus-item-editor.js +0 -7
  27. package/esm2015/public-api.js +0 -6
  28. package/fesm2015/myrmidon-cadmus-item-editor.js +0 -554
  29. package/fesm2015/myrmidon-cadmus-item-editor.js.map +0 -1
  30. package/myrmidon-cadmus-item-editor.metadata.json +0 -1
@@ -1,7 +0,0 @@
1
- /**
2
- * Generated bundle index. Do not edit.
3
- */
4
- export * from './public-api';
5
- export { MissingPartsComponent as ɵa } from './lib/missing-parts/missing-parts.component';
6
- export { PartsScopeEditorComponent as ɵb } from './lib/parts-scope-editor/parts-scope-editor.component';
7
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibXlybWlkb24tY2FkbXVzLWl0ZW0tZWRpdG9yLmpzIiwic291cmNlUm9vdCI6Ii4uLy4uLy4uLy4uL3Byb2plY3RzL215cm1pZG9uL2NhZG11cy1pdGVtLWVkaXRvci9zcmMvIiwic291cmNlcyI6WyJteXJtaWRvbi1jYWRtdXMtaXRlbS1lZGl0b3IudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7O0dBRUc7QUFFSCxjQUFjLGNBQWMsQ0FBQztBQUU3QixPQUFPLEVBQUMscUJBQXFCLElBQUksRUFBRSxFQUFDLE1BQU0sNkNBQTZDLENBQUM7QUFDeEYsT0FBTyxFQUFDLHlCQUF5QixJQUFJLEVBQUUsRUFBQyxNQUFNLHVEQUF1RCxDQUFDIiwic291cmNlc0NvbnRlbnQiOlsiLyoqXG4gKiBHZW5lcmF0ZWQgYnVuZGxlIGluZGV4LiBEbyBub3QgZWRpdC5cbiAqL1xuXG5leHBvcnQgKiBmcm9tICcuL3B1YmxpYy1hcGknO1xuXG5leHBvcnQge01pc3NpbmdQYXJ0c0NvbXBvbmVudCBhcyDJtWF9IGZyb20gJy4vbGliL21pc3NpbmctcGFydHMvbWlzc2luZy1wYXJ0cy5jb21wb25lbnQnO1xuZXhwb3J0IHtQYXJ0c1Njb3BlRWRpdG9yQ29tcG9uZW50IGFzIMm1Yn0gZnJvbSAnLi9saWIvcGFydHMtc2NvcGUtZWRpdG9yL3BhcnRzLXNjb3BlLWVkaXRvci5jb21wb25lbnQnOyJdfQ==
@@ -1,6 +0,0 @@
1
- /*
2
- * Public API Surface of cadmus-item-editor
3
- */
4
- export * from './lib/item-editor/item-editor.component';
5
- export * from './lib/cadmus-item-editor.module';
6
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHVibGljLWFwaS5qcyIsInNvdXJjZVJvb3QiOiIuLi8uLi8uLi8uLi9wcm9qZWN0cy9teXJtaWRvbi9jYWRtdXMtaXRlbS1lZGl0b3Ivc3JjLyIsInNvdXJjZXMiOlsicHVibGljLWFwaS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7R0FFRztBQUVILGNBQWMseUNBQXlDLENBQUM7QUFDeEQsY0FBYyxpQ0FBaUMsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbIi8qXG4gKiBQdWJsaWMgQVBJIFN1cmZhY2Ugb2YgY2FkbXVzLWl0ZW0tZWRpdG9yXG4gKi9cblxuZXhwb3J0ICogZnJvbSAnLi9saWIvaXRlbS1lZGl0b3IvaXRlbS1lZGl0b3IuY29tcG9uZW50JztcbmV4cG9ydCAqIGZyb20gJy4vbGliL2NhZG11cy1pdGVtLWVkaXRvci5tb2R1bGUnO1xuIl19
@@ -1,554 +0,0 @@
1
- import { Component, EventEmitter, Input, Output, NgModule } from '@angular/core';
2
- import { LibraryRouteService, CadmusCoreModule } from '@myrmidon/cadmus-core';
3
- import { Validators, FormBuilder, ReactiveFormsModule, FormsModule } from '@angular/forms';
4
- import { Router, ActivatedRoute, RouterModule } from '@angular/router';
5
- import { MatSnackBar } from '@angular/material/snack-bar';
6
- import { DialogService, CustomValidators, CadmusUiModule } from '@myrmidon/cadmus-ui';
7
- import { AppQuery, EditItemQuery, EditItemService, CadmusStateModule } from '@myrmidon/cadmus-state';
8
- import { AuthService, FacetService, CadmusApiModule } from '@myrmidon/cadmus-api';
9
- import { CommonModule } from '@angular/common';
10
- import { ClipboardModule } from '@angular/cdk/clipboard';
11
- import { MomentModule } from 'ngx-moment';
12
- import { CadmusMaterialModule } from '@myrmidon/cadmus-material';
13
-
14
- /**
15
- * Item editor. This can edit a new or existing item's metadata and parts.
16
- */
17
- class ItemEditorComponent {
18
- constructor(_router, _route, _snackbar, _appQuery, _query, _editItemService, _libraryRouteService, _dialogService, _authService, _formBuilder) {
19
- this._router = _router;
20
- this._route = _route;
21
- this._snackbar = _snackbar;
22
- this._appQuery = _appQuery;
23
- this._query = _query;
24
- this._editItemService = _editItemService;
25
- this._libraryRouteService = _libraryRouteService;
26
- this._dialogService = _dialogService;
27
- this._authService = _authService;
28
- this._formBuilder = _formBuilder;
29
- this.id = this._route.snapshot.params.id;
30
- if (this.id === 'new') {
31
- this.id = null;
32
- }
33
- // new part form
34
- this.newPartType = _formBuilder.control(null, Validators.required);
35
- this.newPart = _formBuilder.group({
36
- newPartType: this.newPartType,
37
- });
38
- // item's metadata form
39
- this.title = _formBuilder.control(null, [
40
- Validators.required,
41
- Validators.maxLength(500),
42
- ]);
43
- this.sortKey = _formBuilder.control(null, [
44
- Validators.required,
45
- Validators.maxLength(500),
46
- ]);
47
- this.sortKey.disable();
48
- this.description = _formBuilder.control(null, [
49
- Validators.required,
50
- Validators.maxLength(1000),
51
- ]);
52
- this.facet = _formBuilder.control(null, Validators.required);
53
- this.group = _formBuilder.control(null, Validators.maxLength(100));
54
- this.flags = _formBuilder.control(0);
55
- this.flagChecks = _formBuilder.array([]);
56
- this.metadata = _formBuilder.group({
57
- title: this.title,
58
- sortKey: this.sortKey,
59
- description: this.description,
60
- facet: this.facet,
61
- group: this.group,
62
- flagChecks: this.flagChecks,
63
- });
64
- this.userLevel = 0;
65
- }
66
- ngOnInit() {
67
- this._authService.currentUser$.subscribe((user) => {
68
- this.user = user;
69
- this.userLevel = this._authService.getCurrentUserLevel();
70
- });
71
- this.item$ = this._query.selectItem();
72
- this.parts$ = this._query.selectParts();
73
- this.partGroups$ = this._query.select((state) => state.partGroups);
74
- this.layerPartInfos$ = this._query.select((state) => state.layerPartInfos);
75
- this.facet$ = this._query.selectFacet();
76
- this.facets$ = this._appQuery.selectFacets();
77
- // rebuild the flags controls array when flags definitions change
78
- this._appQuery.selectFlags().subscribe((defs) => {
79
- this.flagDefinitions = defs;
80
- this.buildFlagsControls();
81
- });
82
- this.typeThesaurus$ = this._appQuery.selectTypeThesaurus();
83
- this.loading$ = this._query.selectLoading();
84
- this.saving$ = this._query.selectSaving();
85
- this.deletingPart$ = this._query.selectDeletingPart();
86
- this.error$ = this._query.selectError();
87
- // when flags controls values change, update the flags value
88
- this.flagChecks.valueChanges.subscribe((_) => {
89
- this.flags.setValue(this.getFlagsValue());
90
- });
91
- // update the metadata form when item changes
92
- this.item$.subscribe((item) => {
93
- this.updateMetadataForm(item);
94
- this.newPartDefinitions = this.getNewPartDefinitions();
95
- });
96
- // load the item (if any) and its lookup
97
- this._editItemService.load(this.id);
98
- }
99
- canDeactivate() {
100
- return !this.metadata.dirty;
101
- }
102
- getExistingPartTypeAndRoleIds() {
103
- const groups = this._query.getValue().partGroups;
104
- if (!groups) {
105
- return [];
106
- }
107
- const results = [];
108
- for (const group of groups) {
109
- for (const part of group.parts) {
110
- results.push({
111
- typeId: part.typeId,
112
- roleId: part.roleId,
113
- });
114
- }
115
- }
116
- return results;
117
- }
118
- getNewPartDefinitions() {
119
- var _a;
120
- const facet = this._query.getValue().facet;
121
- if (!facet) {
122
- return [];
123
- }
124
- const existingTypeRoleIds = this.getExistingPartTypeAndRoleIds();
125
- const defs = [];
126
- for (const def of facet.partDefinitions) {
127
- // exclude layer parts, as these are in the layers tab
128
- if ((_a = def.roleId) === null || _a === void 0 ? void 0 : _a.startsWith('fr.')) {
129
- continue;
130
- }
131
- // exclude parts present in the item
132
- if (existingTypeRoleIds.find((tr) => {
133
- return (tr.typeId === def.typeId &&
134
- ((!tr.roleId && !def.roleId) || tr.roleId === def.roleId));
135
- })) {
136
- continue;
137
- }
138
- defs.push(def);
139
- }
140
- // sort by sort key
141
- defs.sort((a, b) => {
142
- return a.sortKey.localeCompare(b.sortKey);
143
- });
144
- return defs;
145
- }
146
- /**
147
- * Builds the array of flags controls according to the current flags
148
- * definitions and the current flags value.
149
- */
150
- buildFlagsControls() {
151
- this.flagChecks.clear();
152
- for (const def of this.flagDefinitions) {
153
- const flagValue = def.id;
154
- // tslint:disable-next-line: no-bitwise
155
- const checked = (this.flags.value & flagValue) !== 0;
156
- this.flagChecks.push(this._formBuilder.control(checked));
157
- }
158
- }
159
- /**
160
- * Update the flags controls from the current flags value.
161
- */
162
- updateFlagControls() {
163
- if (!this.flagDefinitions) {
164
- return;
165
- }
166
- for (let i = 0; i < this.flagDefinitions.length; i++) {
167
- const flagValue = this.flagDefinitions[i].id;
168
- // tslint:disable-next-line: no-bitwise
169
- const checked = (this.flags.value & flagValue) !== 0;
170
- this.flagChecks.at(i).setValue(checked);
171
- }
172
- }
173
- /**
174
- * Get the flags value from the flags controls.
175
- */
176
- getFlagsValue() {
177
- let flagsValue = 0;
178
- for (let i = 0; i < this.flagDefinitions.length; i++) {
179
- const flagValue = this.flagDefinitions[i].id;
180
- if (this.flagChecks.at(i).value) {
181
- // tslint:disable-next-line: no-bitwise
182
- flagsValue |= flagValue;
183
- }
184
- }
185
- return flagsValue;
186
- }
187
- updateMetadataForm(item) {
188
- if (!item) {
189
- this.metadata.reset();
190
- this.updateFlagControls();
191
- }
192
- else {
193
- this.title.setValue(item.title);
194
- this.sortKey.setValue(item.sortKey);
195
- this.description.setValue(item.description);
196
- this.facet.setValue(item.facetId);
197
- this.group.setValue(item.groupId);
198
- this.flags.setValue(item.flags);
199
- this.updateFlagControls();
200
- this.metadata.markAsPristine();
201
- }
202
- }
203
- getTypeIdName(typeId) {
204
- const state = this._appQuery.getValue();
205
- if (!state || !state.typeThesaurus) {
206
- return typeId;
207
- }
208
- // strip :suffix if any
209
- const i = typeId.lastIndexOf(':');
210
- if (i > -1) {
211
- typeId = typeId.substr(0, i);
212
- }
213
- const entry = state.typeThesaurus.entries.find((e) => e.id === typeId);
214
- return entry ? entry.value : typeId;
215
- }
216
- getRoleIdName(roleId) {
217
- if (!roleId || !roleId.startsWith('fr.')) {
218
- return roleId;
219
- }
220
- return this.getTypeIdName(roleId);
221
- }
222
- tryTrim(value) {
223
- return value ? value.trim() : value;
224
- }
225
- save() {
226
- if (!this.metadata.valid) {
227
- return;
228
- }
229
- const item = Object.assign({}, this._query.getValue().item);
230
- item.title = this.tryTrim(this.title.value);
231
- item.sortKey = this.sortKey.value;
232
- item.description = this.tryTrim(this.description.value);
233
- item.facetId = this.tryTrim(this.facet.value);
234
- item.groupId = this.tryTrim(this.group.value);
235
- item.flags = this.flags.value;
236
- // save and reload as edited if was new
237
- this._editItemService.save(item).then((saved) => {
238
- this.metadata.markAsPristine();
239
- if (!item.id) {
240
- this.id = saved.id;
241
- this._router.navigate(['/items', saved.id]);
242
- }
243
- });
244
- }
245
- partExists(typeId, roleId) {
246
- const groups = this._query.getValue().partGroups;
247
- return groups.some((g) => {
248
- return g.parts.some((p) => p.typeId === typeId && ((!p.roleId && !roleId) || p.roleId === roleId));
249
- });
250
- }
251
- addPart(def) {
252
- if (!def && !this.newPartType.valid) {
253
- return;
254
- }
255
- if (!this.id) {
256
- this._snackbar.open('Please save the item before adding parts', 'OK', {
257
- duration: 3000,
258
- });
259
- return;
260
- }
261
- const typeId = def ? def.typeId : this.newPartType.value.typeId;
262
- const roleId = def ? def.roleId : this.newPartType.value.roleId;
263
- if (this.partExists(typeId, roleId)) {
264
- return;
265
- }
266
- const route = this._libraryRouteService.buildPartEditorRoute(this.id, 'new', typeId, roleId);
267
- // navigate to the editor
268
- this._router.navigate([route.route], route.rid
269
- ? {
270
- queryParams: {
271
- rid: route.rid,
272
- },
273
- }
274
- : {});
275
- }
276
- editPart(part) {
277
- // build the target route to the appropriate part editor
278
- const route = this._libraryRouteService.buildPartEditorRoute(part.itemId, part.id, part.typeId, part.roleId);
279
- // navigate to the editor
280
- this._router.navigate([route.route], route.rid
281
- ? {
282
- queryParams: {
283
- rid: route.rid,
284
- },
285
- }
286
- : {});
287
- }
288
- deletePart(part) {
289
- this._dialogService
290
- .confirm('Confirm Deletion', `Delete part "${part.typeId}"?`)
291
- .subscribe((result) => {
292
- if (!result) {
293
- return;
294
- }
295
- // delete
296
- this._editItemService.deletePart(part.id).then((_) => {
297
- // once deleted, refresh new-part definitions
298
- this.newPartDefinitions = this.getNewPartDefinitions();
299
- }, (error) => {
300
- console.error(error);
301
- this._snackbar.open('Error deleting part', 'OK');
302
- });
303
- });
304
- }
305
- addLayerPart(part) {
306
- let name = this.getTypeIdName(part.typeId);
307
- if (part.roleId) {
308
- name += ' for ' + this.getRoleIdName(part.roleId);
309
- }
310
- this._dialogService
311
- .confirm('Confirm Addition', `Add layer "${name}"?`)
312
- .subscribe((result) => {
313
- if (!result) {
314
- return;
315
- }
316
- this._editItemService.addNewLayerPart(part.itemId, part.typeId, part.roleId);
317
- });
318
- }
319
- setPartsScope(request) {
320
- this._editItemService.setPartThesaurusScope(request.ids, request.scope);
321
- }
322
- }
323
- ItemEditorComponent.decorators = [
324
- { type: Component, args: [{
325
- selector: 'cadmus-item-editor',
326
- template: "<mat-card>\r\n <mat-card-header>\r\n <mat-card-title>\r\n {{ (item$ | async)?.title || \"Item\" }}\r\n </mat-card-title>\r\n <mat-card-subtitle>\r\n {{ (item$ | async)?.description }}\r\n </mat-card-subtitle>\r\n </mat-card-header>\r\n <mat-card-content *ngIf=\"!id || (item$ | async) as item\">\r\n <p *ngIf=\"id\">\r\n ID:\r\n <input\r\n [cdkCopyToClipboard]=\"item.id\"\r\n type=\"text\"\r\n readonly=\"true\"\r\n spellcheck=\"false\"\r\n matTooltip=\"Click to copy\"\r\n [value]=\"item.id\"\r\n class=\"id\"\r\n />\r\n </p>\r\n <p *ngIf=\"id\">\r\n Last saved {{ item.timeModified | amLocal | amTimeAgo }} by\r\n {{ item.userId }} on\r\n {{ item.timeModified | date: \"yyyy-MM-dd HH:mm:ss\" }}.<br />\r\n Created {{ item.timeCreated | amLocal | amTimeAgo }} by\r\n {{ item.creatorId }} on\r\n {{ item.timeCreated | date: \"yyyy-MM-dd HH:mm:ss\" }}.\r\n </p>\r\n <p *ngIf=\"error$ | async as error\">\r\n <mat-error>\r\n {{ error }}\r\n </mat-error>\r\n </p>\r\n\r\n <mat-progress-bar\r\n mode=\"indeterminate\"\r\n *ngIf=\"(loading$ | async) || (saving$ | async)\"\r\n ></mat-progress-bar>\r\n\r\n <!-- item content -->\r\n <mat-tab-group [selectedIndex]=\"id ? 1 : 0\">\r\n <!-- metadata -->\r\n <mat-tab label=\"Metadata\">\r\n <form [formGroup]=\"metadata\" (ngSubmit)=\"save()\">\r\n <!-- title -->\r\n <div>\r\n <mat-form-field>\r\n <input\r\n matInput\r\n type=\"text\"\r\n id=\"title\"\r\n placeholder=\"title\"\r\n formControlName=\"title\"\r\n />\r\n <mat-error\r\n *ngIf=\"\r\n title.hasError('required') && (title.touched || title.dirty)\r\n \"\r\n >enter title</mat-error\r\n >\r\n <mat-error\r\n *ngIf=\"\r\n title.hasError('maxLength') && (title.touched || title.dirty)\r\n \"\r\n >\r\n title too long</mat-error\r\n >\r\n </mat-form-field>\r\n </div>\r\n\r\n <!-- sortKey -->\r\n <div>\r\n <mat-form-field>\r\n <input\r\n matInput\r\n type=\"text\"\r\n id=\"sortKey\"\r\n placeholder=\"sort key\"\r\n formControlName=\"sortKey\"\r\n />\r\n <mat-error\r\n *ngIf=\"\r\n sortKey.hasError('required') &&\r\n (sortKey.touched || sortKey.dirty)\r\n \"\r\n >enter sort key</mat-error\r\n >\r\n <mat-error\r\n *ngIf=\"\r\n sortKey.hasError('maxLength') &&\r\n (sortKey.touched || sortKey.dirty)\r\n \"\r\n >sort key too long</mat-error\r\n >\r\n </mat-form-field>\r\n </div>\r\n\r\n <!-- description -->\r\n <div>\r\n <mat-form-field class=\"full-width\">\r\n <textarea\r\n rows=\"2\"\r\n matInput\r\n id=\"description\"\r\n placeholder=\"description\"\r\n formControlName=\"description\"\r\n ></textarea>\r\n <mat-error\r\n *ngIf=\"\r\n description.hasError('required') &&\r\n (description.touched || description.dirty)\r\n \"\r\n >enter description</mat-error\r\n >\r\n <mat-error\r\n *ngIf=\"\r\n description.hasError('maxLength') &&\r\n (description.touched || description.dirty)\r\n \"\r\n >description too long</mat-error\r\n >\r\n </mat-form-field>\r\n </div>\r\n\r\n <!-- facet -->\r\n <div>\r\n <mat-form-field style=\"width: 400px\">\r\n <mat-select\r\n placeholder=\"facet\"\r\n formControlName=\"facet\"\r\n required=\"true\"\r\n >\r\n <mat-option *ngFor=\"let f of facets$ | async\" [value]=\"f.id\">\r\n {{ f.label }}\r\n </mat-option>\r\n </mat-select>\r\n <mat-error>please select a facet</mat-error>\r\n </mat-form-field>\r\n </div>\r\n\r\n <!-- group -->\r\n <div>\r\n <mat-form-field>\r\n <input matInput formControlName=\"group\" placeholder=\"group ID\" />\r\n <mat-error\r\n *ngIf=\"\r\n group.hasError('maxLength') && (group.dirty || group.touched)\r\n \"\r\n >too long</mat-error\r\n >\r\n </mat-form-field>\r\n </div>\r\n\r\n <!-- flags -->\r\n <div formArrayName=\"flagChecks\" *ngIf=\"flagDefinitions\">\r\n <mat-checkbox\r\n class=\"flag\"\r\n *ngFor=\"let c of flagChecks.controls; let i = index\"\r\n [formControlName]=\"i\"\r\n >\r\n <span [style.color]=\"'#' + flagDefinitions[i].colorKey\"\r\n >&#x2b24;</span\r\n >\r\n &nbsp;\r\n {{ flagDefinitions[i].label }}\r\n </mat-checkbox>\r\n </div>\r\n <br />\r\n\r\n <div>\r\n <button\r\n type=\"submit\"\r\n mat-raised-button\r\n color=\"primary\"\r\n [disabled]=\"\r\n userLevel < 2 || (saving$ | async) || (loading$ | async)\r\n \"\r\n matTooltip=\"Save metadata\"\r\n *ngIf=\"\r\n user.roles.includes('admin') ||\r\n user.roles.includes('editor') ||\r\n user.roles.includes('operator')\r\n \"\r\n >\r\n <mat-icon>save</mat-icon> save\r\n </button>\r\n </div>\r\n </form>\r\n </mat-tab>\r\n\r\n <!-- parts -->\r\n <mat-tab label=\"Parts\" *ngIf=\"id\">\r\n <div class=\"new-part\">\r\n <form [formGroup]=\"newPart\">\r\n <mat-form-field>\r\n <mat-select\r\n placeholder=\"part\"\r\n formControlName=\"newPartType\"\r\n required\r\n >\r\n <mat-option *ngFor=\"let p of newPartDefinitions\" [value]=\"p\">\r\n <span [style.color]=\"'#' + p.colorKey\" class=\"new-part-icon\"\r\n >&#x2b24;</span\r\n >\r\n {{ p.name }}\r\n <span *ngIf=\"p.roleId\" class=\"new-part-role\">{{\r\n p.roleId\r\n }}</span>\r\n </mat-option>\r\n </mat-select>\r\n <mat-error>part type required</mat-error>\r\n </mat-form-field>\r\n &nbsp;\r\n <button\r\n mat-stroked-button\r\n color=\"primary\"\r\n type=\"button\"\r\n [disabled]=\"userLevel < 2 || (loading$ | async) || !newPart.valid\"\r\n (click)=\"addPart()\"\r\n matTooltip=\"Add a new part of the selected type\"\r\n >\r\n <mat-icon>add_circle</mat-icon>\r\n add part\r\n </button>\r\n </form>\r\n </div>\r\n\r\n <mat-divider></mat-divider>\r\n\r\n <mat-expansion-panel\r\n *ngFor=\"let group of partGroups$ | async\"\r\n [expanded]=\"true\"\r\n >\r\n <mat-expansion-panel-header>\r\n <mat-panel-title\r\n ><strong>{{ group.label }}</strong></mat-panel-title\r\n >\r\n <mat-panel-description>{{\r\n group.parts.length\r\n }}</mat-panel-description>\r\n </mat-expansion-panel-header>\r\n\r\n <table>\r\n <thead>\r\n <tr>\r\n <th style=\"width: 124px\"></th>\r\n <th>type</th>\r\n <th>role</th>\r\n <th fxHide.xs>modified</th>\r\n <th fxHide.xs>user</th>\r\n </tr>\r\n </thead>\r\n <tbody>\r\n <tr *ngFor=\"let part of group.parts\">\r\n <!-- edit -->\r\n <td>\r\n <button\r\n mat-icon-button\r\n type=\"button\"\r\n color=\"primary\"\r\n matTooltip=\"Edit this part\"\r\n [disabled]=\"(loading$ | async) || (deletingPart$ | async)\"\r\n (click)=\"editPart(part)\"\r\n >\r\n <mat-icon>create</mat-icon>\r\n </button>\r\n <!-- delete -->\r\n <button\r\n mat-icon-button\r\n type=\"button\"\r\n matTooltip=\"Delete this part\"\r\n [disabled]=\"\r\n userLevel < 2 ||\r\n (loading$ | async) ||\r\n (deletingPart$ | async)\r\n \"\r\n (click)=\"deletePart(part)\"\r\n *ngIf=\"\r\n user.roles.includes('admin') ||\r\n user.roles.includes('editor') ||\r\n user.roles.includes('operator')\r\n \"\r\n >\r\n <mat-icon color=\"warn\">delete</mat-icon>\r\n </button>\r\n <!-- copy -->\r\n <button\r\n mat-icon-button\r\n type=\"button\"\r\n matTooltip=\"Copy this part ID\"\r\n [cdkCopyToClipboard]=\"part.id\"\r\n >\r\n <mat-icon>assignment</mat-icon>\r\n </button>\r\n </td>\r\n <td>\r\n <cadmus-part-badge\r\n [partTypeIds]=\"part\"\r\n [facetDefinition]=\"facet$ | async\"\r\n [badgeType]=\"1\"\r\n [typeThesaurus]=\"typeThesaurus$ | async\"\r\n ></cadmus-part-badge>\r\n </td>\r\n <td>\r\n <cadmus-part-badge\r\n [partTypeIds]=\"part\"\r\n [facetDefinition]=\"facet$ | async\"\r\n [badgeType]=\"2\"\r\n [typeThesaurus]=\"typeThesaurus$ | async\"\r\n ></cadmus-part-badge>\r\n </td>\r\n <td fxHide.xs>{{ part.timeModified | amLocal | amTimeAgo }}</td>\r\n <td fxHide.xs>{{ part.userId }}</td>\r\n </tr>\r\n </tbody>\r\n </table>\r\n </mat-expansion-panel>\r\n\r\n <cadmus-missing-parts\r\n [partDefinitions]=\"(facet$ | async)?.partDefinitions\"\r\n [parts]=\"parts$ | async\"\r\n [typeThesaurus]=\"typeThesaurus$ | async\"\r\n (addRequest)=\"addPart($event)\"\r\n ></cadmus-missing-parts>\r\n </mat-tab>\r\n\r\n <mat-tab label=\"Layers\" *ngIf=\"id\">\r\n <table *ngIf=\"layerPartInfos$ | async as parts\">\r\n <thead>\r\n <th></th>\r\n <th>type</th>\r\n <th>role</th>\r\n <th>frr.</th>\r\n <th>last modified</th>\r\n </thead>\r\n <tbody>\r\n <tr *ngFor=\"let part of parts\">\r\n <td>\r\n <button\r\n *ngIf=\"!part.isAbsent\"\r\n type=\"button\"\r\n color=\"primary\"\r\n mat-icon-button\r\n matTooltip=\"Edit this layer part\"\r\n (click)=\"editPart(part)\"\r\n >\r\n <mat-icon>edit</mat-icon>\r\n </button>\r\n <button\r\n *ngIf=\"part.isAbsent\"\r\n type=\"button\"\r\n mat-icon-button\r\n color=\"primary\"\r\n matTooltip=\"Add this layer part\"\r\n [disabled]=\"userLevel < 2\"\r\n (click)=\"addLayerPart(part)\"\r\n >\r\n <mat-icon>add_circle</mat-icon>\r\n </button>\r\n <button\r\n *ngIf=\"!part.isAbsent\"\r\n type=\"button\"\r\n mat-icon-button\r\n color=\"warn\"\r\n matTooltip=\"Delete this layer part\"\r\n [disabled]=\"userLevel < 2\"\r\n (click)=\"deletePart(part)\"\r\n >\r\n <mat-icon>delete</mat-icon>\r\n </button>\r\n <button\r\n *ngIf=\"!part.isAbsent\"\r\n mat-icon-button\r\n type=\"button\"\r\n matTooltip=\"Copy this part ID\"\r\n [cdkCopyToClipboard]=\"part.id\"\r\n >\r\n <mat-icon>assignment</mat-icon>\r\n </button>\r\n </td>\r\n <td>\r\n <cadmus-part-badge\r\n [partTypeIds]=\"part\"\r\n [facetDefinition]=\"facet$ | async\"\r\n [badgeType]=\"1\"\r\n [typeThesaurus]=\"typeThesaurus$ | async\"\r\n ></cadmus-part-badge>\r\n </td>\r\n <td>\r\n <cadmus-part-badge\r\n [partTypeIds]=\"part\"\r\n [facetDefinition]=\"facet$ | async\"\r\n [badgeType]=\"2\"\r\n [typeThesaurus]=\"typeThesaurus$ | async\"\r\n ></cadmus-part-badge>\r\n </td>\r\n <td\r\n [ngClass]=\"{\r\n 'count-n': part.fragmentCount,\r\n 'count-z': !part.fragmentCount\r\n }\"\r\n >\r\n {{ part.fragmentCount }}\r\n </td>\r\n <td>\r\n <span *ngIf=\"!part.isAbsent\">\r\n {{ part.timeModified | amLocal | amTimeAgo }}\r\n </span>\r\n </td>\r\n </tr>\r\n </tbody>\r\n </table>\r\n </mat-tab>\r\n\r\n <mat-tab\r\n label=\"Th-Scopes\"\r\n *ngIf=\"parts$ | async | sort: 'typeId' | sort: 'roleId' as parts\"\r\n >\r\n <cadmus-parts-scope-editor\r\n [parts]=\"parts\"\r\n [readonly]=\"userLevel < 2 || (saving$ | async) || (loading$ | async)\"\r\n (setScopeRequest)=\"setPartsScope($event)\"\r\n ></cadmus-parts-scope-editor>\r\n </mat-tab>\r\n </mat-tab-group>\r\n </mat-card-content>\r\n</mat-card>\r\n",
327
- styles: [".full-width{width:100%}th{color:silver;font-weight:400}div.new-part{margin-left:32px}span.new-part-role{color:grey;margin-left:8px;vertical-align:middle}span.new-part-icon{margin:0 4px;vertical-align:middle}td.count-n{color:#03c03c;text-align:center}td.count-z{color:#f34f41;text-align:center}input.id{color:grey;font-family:Courier New,Courier,monospace;min-width:22em}.flag{margin-left:10px}"]
328
- },] }
329
- ];
330
- ItemEditorComponent.ctorParameters = () => [
331
- { type: Router },
332
- { type: ActivatedRoute },
333
- { type: MatSnackBar },
334
- { type: AppQuery },
335
- { type: EditItemQuery },
336
- { type: EditItemService },
337
- { type: LibraryRouteService },
338
- { type: DialogService },
339
- { type: AuthService },
340
- { type: FormBuilder }
341
- ];
342
-
343
- /**
344
- * Parts thesaurus scope dumb editor component.
345
- * This is used to set the thesaurus scope of multiple item's parts at once
346
- * in the item editor.
347
- */
348
- class PartsScopeEditorComponent {
349
- constructor(_formBuilder, _facetService, _dialogService, _appQuery, _itemQuery) {
350
- this._formBuilder = _formBuilder;
351
- this._facetService = _facetService;
352
- this._dialogService = _dialogService;
353
- this._appQuery = _appQuery;
354
- this._itemQuery = _itemQuery;
355
- // events
356
- this.setScopeRequest = new EventEmitter();
357
- // form
358
- this.checks = _formBuilder.array([], CustomValidators.minChecked(1));
359
- this.scope = _formBuilder.control(null, [
360
- Validators.maxLength(50),
361
- Validators.pattern(/^[-a-zA-Z0-9_]+$/),
362
- ]);
363
- this.form = _formBuilder.group({
364
- checks: this.checks,
365
- scope: this.scope,
366
- });
367
- }
368
- get parts() {
369
- return this._parts;
370
- }
371
- set parts(value) {
372
- this._parts = value;
373
- this.updateForm();
374
- }
375
- ngOnInit() { }
376
- updateForm() {
377
- this.checks.clear();
378
- if (!this._parts || this._parts.length === 0) {
379
- return;
380
- }
381
- for (let i = 0; i < this._parts.length; i++) {
382
- this.checks.push(this._formBuilder.control(false));
383
- }
384
- }
385
- getPartColor(typeId, roleId) {
386
- const state = this._itemQuery.getValue();
387
- return this._facetService.getPartColor(typeId, roleId, state === null || state === void 0 ? void 0 : state.facet);
388
- }
389
- getTypeIdName(typeId) {
390
- const state = this._appQuery.getValue();
391
- if (!state || !state.typeThesaurus) {
392
- return typeId;
393
- }
394
- // strip :suffix if any
395
- const i = typeId.lastIndexOf(':');
396
- if (i > -1) {
397
- typeId = typeId.substr(0, i);
398
- }
399
- const entry = state.typeThesaurus.entries.find((e) => e.id === typeId);
400
- return entry ? entry.value : typeId;
401
- }
402
- getRoleIdName(roleId) {
403
- if (!roleId || !roleId.startsWith('fr.')) {
404
- return roleId;
405
- }
406
- return this.getTypeIdName(roleId);
407
- }
408
- submit() {
409
- if (this.form.invalid) {
410
- return;
411
- }
412
- const ids = [];
413
- for (let i = 0; i < this.checks.length; i++) {
414
- if (this.checks.controls[i].value === true) {
415
- ids.push(this._parts[i].id);
416
- }
417
- }
418
- let msg = this.scope.value
419
- ? `Assign scope "${this.scope.value}" to ${ids.length} part`
420
- : `Remove scope from ${ids.length} part`;
421
- msg += ids.length > 1 ? 's?' : '?';
422
- this._dialogService.confirm('Confirm Scopes', msg).subscribe((result) => {
423
- if (!result) {
424
- return;
425
- }
426
- this.setScopeRequest.emit({
427
- ids,
428
- scope: this.scope.value,
429
- });
430
- });
431
- }
432
- }
433
- PartsScopeEditorComponent.decorators = [
434
- { type: Component, args: [{
435
- selector: 'cadmus-parts-scope-editor',
436
- template: "<form [formGroup]=\"form\" (submit)=\"submit()\">\n <table id=\"parts\">\n <thead>\n <tr>\n <th style=\"min-width: 32px;\"></th>\n <th>type</th>\n <th>role</th>\n <th>scope</th>\n <th>modified</th>\n <th>user</th>\n </tr>\n </thead>\n <tbody>\n <tr\n formArrayName=\"checks\"\n *ngFor=\"let ctl of checks.controls; let i = index\"\n >\n <td>\n &nbsp;\n <mat-checkbox [formControlName]=\"i\"></mat-checkbox>\n </td>\n <td>\n <span\n class=\"model-type\"\n [style.background-color]=\"\n getPartColor(parts[i].typeId, parts[i].roleId)\n \"\n >{{ getTypeIdName(parts[i].typeId) }}</span\n >\n </td>\n <td>{{ getRoleIdName(parts[i].roleId) }}</td>\n <td>{{ parts[i].thesaurusScope }}</td>\n <td>{{ parts[i].timeModified | amLocal | amTimeAgo }}</td>\n <td>{{ parts[i].userId }}</td>\n </tr>\n </tbody>\n </table>\n <div>\n <mat-form-field>\n <input matInput placeholder=\"scope\" formControlName=\"scope\" />\n <mat-error\n *ngIf=\"scope.hasError('maxLength') && (scope.dirty || scope.touched)\"\n >too long</mat-error\n >\n <mat-error\n *ngIf=\"scope.hasError('pattern') && (scope.dirty || scope.touched)\"\n >invalid scope</mat-error\n >\n </mat-form-field>\n </div>\n <button\n mat-raised-button\n color=\"primary\"\n type=\"submit\"\n [disabled]=\"form.invalid || readonly\"\n matTooltip=\"Assign the scope to the checked parts\"\n >\n assign\n </button>\n</form>\n",
437
- styles: ["th{color:silver;font-weight:400;text-align:left}span.model-type{border-radius:6px;padding:4px}table#parts{border-collapse:initial;border-spacing:0 8px}"]
438
- },] }
439
- ];
440
- PartsScopeEditorComponent.ctorParameters = () => [
441
- { type: FormBuilder },
442
- { type: FacetService },
443
- { type: DialogService },
444
- { type: AppQuery },
445
- { type: EditItemQuery }
446
- ];
447
- PartsScopeEditorComponent.propDecorators = {
448
- parts: [{ type: Input }],
449
- readonly: [{ type: Input }],
450
- setScopeRequest: [{ type: Output }]
451
- };
452
-
453
- class MissingPartsComponent {
454
- constructor() {
455
- this.missingDefinitions = [];
456
- this.addRequest = new EventEmitter();
457
- }
458
- get partDefinitions() {
459
- return this._partDefinitions;
460
- }
461
- set partDefinitions(value) {
462
- this._partDefinitions = value;
463
- this.updateMissing();
464
- }
465
- get parts() {
466
- return this._parts;
467
- }
468
- set parts(value) {
469
- this._parts = value;
470
- this.updateMissing();
471
- }
472
- /**
473
- * The types thesaurus.
474
- */
475
- get typeThesaurus() {
476
- return this._typeThesaurus;
477
- }
478
- set typeThesaurus(value) {
479
- this._typeThesaurus = value;
480
- this.updateMissing();
481
- }
482
- ngOnInit() { }
483
- isPartPresent(typeId, roleId) {
484
- return this._partDefinitions.some((d) => d.typeId === typeId && d.roleId === roleId);
485
- }
486
- updateMissing() {
487
- this.missingDefinitions.length = 0;
488
- if (!this._partDefinitions) {
489
- return;
490
- }
491
- for (let i = 0; i < this._partDefinitions.length; i++) {
492
- const def = this._partDefinitions[i];
493
- if (!this.isPartPresent(def.typeId, def.roleId)) {
494
- this.missingDefinitions.push(def);
495
- }
496
- }
497
- }
498
- }
499
- MissingPartsComponent.decorators = [
500
- { type: Component, args: [{
501
- selector: 'cadmus-missing-parts',
502
- template: "<div *ngIf=\"missingDefinitions.length\">\r\n <h3><mat-icon color=\"warn\">warning</mat-icon>&nbsp; Missing Parts</h3>\r\n <table>\r\n <tbody>\r\n <tr *ngFor=\"let def of missingDefinitions\">\r\n <td>\r\n <button type=\"button\" mat-icon-button matTooltip=\"Add this part\">\r\n <mat-icon>add_circle</mat-icon>\r\n </button>\r\n </td>\r\n <td matTooltip=\"def.description\">\r\n <cadmus-part-badge\r\n [partTypeIds]=\"def\"\r\n [facetDefinition]=\"def\"\r\n [typeThesaurus]=\"typeThesaurus\"\r\n ></cadmus-part-badge>\r\n </td>\r\n </tr>\r\n </tbody>\r\n </table>\r\n</div>\r\n",
503
- styles: [""]
504
- },] }
505
- ];
506
- MissingPartsComponent.ctorParameters = () => [];
507
- MissingPartsComponent.propDecorators = {
508
- partDefinitions: [{ type: Input }],
509
- parts: [{ type: Input }],
510
- typeThesaurus: [{ type: Input }],
511
- addRequest: [{ type: Output }]
512
- };
513
-
514
- // https://github.com/ng-packagr/ng-packagr/issues/778
515
- const RouterModuleForChild = RouterModule.forChild([
516
- { path: '', pathMatch: 'full', component: ItemEditorComponent },
517
- ]);
518
- class CadmusItemEditorModule {
519
- }
520
- CadmusItemEditorModule.decorators = [
521
- { type: NgModule, args: [{
522
- imports: [
523
- CommonModule,
524
- ReactiveFormsModule,
525
- FormsModule,
526
- RouterModuleForChild,
527
- ClipboardModule,
528
- MomentModule,
529
- // cadmus
530
- CadmusCoreModule,
531
- CadmusMaterialModule,
532
- CadmusApiModule,
533
- CadmusUiModule,
534
- CadmusStateModule,
535
- ],
536
- declarations: [
537
- ItemEditorComponent,
538
- MissingPartsComponent,
539
- PartsScopeEditorComponent,
540
- ],
541
- exports: [ItemEditorComponent],
542
- },] }
543
- ];
544
-
545
- /*
546
- * Public API Surface of cadmus-item-editor
547
- */
548
-
549
- /**
550
- * Generated bundle index. Do not edit.
551
- */
552
-
553
- export { CadmusItemEditorModule, ItemEditorComponent, RouterModuleForChild, MissingPartsComponent as ɵa, PartsScopeEditorComponent as ɵb };
554
- //# sourceMappingURL=myrmidon-cadmus-item-editor.js.map