@myrmidon/cadmus-profile-editor 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,1002 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { Injectable, model, input, computed, output, effect, ChangeDetectionStrategy, Component, signal } from '@angular/core';
|
|
3
|
+
import { of, from } from 'rxjs';
|
|
4
|
+
import { map, tap, take, concatMap, catchError, toArray } from 'rxjs/operators';
|
|
5
|
+
import * as i1 from '@myrmidon/cadmus-api';
|
|
6
|
+
import * as i1$1 from '@angular/forms';
|
|
7
|
+
import { Validators, ReactiveFormsModule } from '@angular/forms';
|
|
8
|
+
import * as i3 from '@angular/material/button';
|
|
9
|
+
import { MatIconButton, MatButtonModule } from '@angular/material/button';
|
|
10
|
+
import { MatCheckbox } from '@angular/material/checkbox';
|
|
11
|
+
import { MatSuffix, MatError as MatError$1, MatFormField as MatFormField$1, MatLabel as MatLabel$1 } from '@angular/material/form-field';
|
|
12
|
+
import { MatExpansionPanel, MatExpansionPanelHeader, MatExpansionPanelTitle, MatExpansionPanelDescription } from '@angular/material/expansion';
|
|
13
|
+
import { MatIcon } from '@angular/material/icon';
|
|
14
|
+
import { MatError, MatFormField, MatInput, MatLabel } from '@angular/material/input';
|
|
15
|
+
import { MatTab, MatTabGroup } from '@angular/material/tabs';
|
|
16
|
+
import { MatTooltip } from '@angular/material/tooltip';
|
|
17
|
+
import { ColorToContrastPipe, EllipsisPipe, StringToColorPipe } from '@myrmidon/ngx-tools';
|
|
18
|
+
import { toSignal } from '@angular/core/rxjs-interop';
|
|
19
|
+
import { MatOption, MatSelect } from '@angular/material/select';
|
|
20
|
+
import * as i2 from '@myrmidon/ngx-mat-tools';
|
|
21
|
+
import { MatProgressBar } from '@angular/material/progress-bar';
|
|
22
|
+
import * as i4 from '@angular/material/snack-bar';
|
|
23
|
+
import { MatCard, MatCardContent, MatCardHeader, MatCardTitle } from '@angular/material/card';
|
|
24
|
+
import { pendingChangesGuard } from '@myrmidon/cadmus-core';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Validates a list of {@link FacetDefinition} objects before they are persisted.
|
|
28
|
+
*
|
|
29
|
+
* Rules:
|
|
30
|
+
* - duplicate facet ID → error
|
|
31
|
+
* - facet ID still set to "new" → warning (unfilled placeholder)
|
|
32
|
+
* - duplicate facet label → error
|
|
33
|
+
* - duplicate facet color → info
|
|
34
|
+
* - duplicate facet description → info
|
|
35
|
+
* - facet with no part definitions → error
|
|
36
|
+
* - within a facet: two parts with same typeId AND same roleId
|
|
37
|
+
* (including both empty/null) → error
|
|
38
|
+
* (one with a roleId and one without is valid: they serve different roles)
|
|
39
|
+
* - within a facet: duplicate part color → info
|
|
40
|
+
* - within a facet: duplicate part description → info
|
|
41
|
+
* - (when facetModelSettings is provided) for each part/fragment entry in the
|
|
42
|
+
* settings, each thesaurus ID listed in thesauriIds is checked against the
|
|
43
|
+
* existing thesauri: missing required thesauri (prefixed with "*") → error;
|
|
44
|
+
* missing optional thesauri → info.
|
|
45
|
+
*/
|
|
46
|
+
class FacetDefinitionValidatorService {
|
|
47
|
+
_thesaurusService;
|
|
48
|
+
constructor(_thesaurusService) {
|
|
49
|
+
this._thesaurusService = _thesaurusService;
|
|
50
|
+
}
|
|
51
|
+
buildResult(issues) {
|
|
52
|
+
return {
|
|
53
|
+
issues,
|
|
54
|
+
hasErrors: issues.some((i) => i.severity === 'error'),
|
|
55
|
+
hasWarnings: issues.some((i) => i.severity === 'warning'),
|
|
56
|
+
hasInfos: issues.some((i) => i.severity === 'info'),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
checkThesauri(issues, existingIds, entries, kind) {
|
|
60
|
+
for (const [typeId, entry] of Object.entries(entries)) {
|
|
61
|
+
for (const rawId of entry.thesauriIds ?? []) {
|
|
62
|
+
const required = rawId.startsWith('*');
|
|
63
|
+
const bareId = required ? rawId.substring(1) : rawId;
|
|
64
|
+
if (!existingIds.has(bareId)) {
|
|
65
|
+
if (required) {
|
|
66
|
+
issues.push({
|
|
67
|
+
severity: 'error',
|
|
68
|
+
message: `${kind} "${typeId}" requires thesaurus "${bareId}" which does not exist.`,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
issues.push({
|
|
73
|
+
severity: 'info',
|
|
74
|
+
message: `${kind} "${typeId}" uses optional thesaurus "${bareId}" which does not exist.`,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Validate the given list of facet definitions and return a result
|
|
83
|
+
* containing all issues found.
|
|
84
|
+
* @param facets The list of facet definitions to validate.
|
|
85
|
+
* @param facetModelSettings Optional settings; when provided the thesauri
|
|
86
|
+
* referenced by each part/fragment are checked against the server.
|
|
87
|
+
*/
|
|
88
|
+
validate(facets, facetModelSettings) {
|
|
89
|
+
const issues = [];
|
|
90
|
+
const seenIds = new Set();
|
|
91
|
+
const seenLabels = new Set();
|
|
92
|
+
const seenColors = new Set();
|
|
93
|
+
const seenDescriptions = new Set();
|
|
94
|
+
for (const facet of facets) {
|
|
95
|
+
const label = `facet "${facet.id}"`;
|
|
96
|
+
// duplicate / placeholder ID
|
|
97
|
+
if (!facet.id) {
|
|
98
|
+
issues.push({ severity: 'error', message: 'A facet has an empty ID.' });
|
|
99
|
+
}
|
|
100
|
+
else if (facet.id === 'new') {
|
|
101
|
+
issues.push({
|
|
102
|
+
severity: 'warning',
|
|
103
|
+
message: `Facet has placeholder ID "new" — please assign a real ID.`,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
else if (seenIds.has(facet.id)) {
|
|
107
|
+
issues.push({
|
|
108
|
+
severity: 'error',
|
|
109
|
+
message: `Duplicate facet ID: "${facet.id}".`,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
seenIds.add(facet.id);
|
|
114
|
+
}
|
|
115
|
+
// duplicate label
|
|
116
|
+
if (facet.label) {
|
|
117
|
+
if (seenLabels.has(facet.label)) {
|
|
118
|
+
issues.push({
|
|
119
|
+
severity: 'error',
|
|
120
|
+
message: `Duplicate facet label "${facet.label}" in ${label}.`,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
seenLabels.add(facet.label);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// duplicate color (info)
|
|
128
|
+
if (facet.colorKey) {
|
|
129
|
+
if (seenColors.has(facet.colorKey)) {
|
|
130
|
+
issues.push({
|
|
131
|
+
severity: 'info',
|
|
132
|
+
message: `Duplicate facet color "${facet.colorKey}" in ${label}.`,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
seenColors.add(facet.colorKey);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
// duplicate description (info)
|
|
140
|
+
if (facet.description) {
|
|
141
|
+
if (seenDescriptions.has(facet.description)) {
|
|
142
|
+
issues.push({
|
|
143
|
+
severity: 'info',
|
|
144
|
+
message: `Duplicate facet description "${facet.description}" in ${label}.`,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
seenDescriptions.add(facet.description);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
// no part definitions
|
|
152
|
+
if (!facet.partDefinitions.length) {
|
|
153
|
+
issues.push({
|
|
154
|
+
severity: 'error',
|
|
155
|
+
message: `${label} has no part definitions.`,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
// within-facet checks
|
|
159
|
+
const seenPartKeys = new Set();
|
|
160
|
+
const seenPartColors = new Set();
|
|
161
|
+
const seenPartDescriptions = new Set();
|
|
162
|
+
for (const part of facet.partDefinitions) {
|
|
163
|
+
// duplicate typeId + roleId combination
|
|
164
|
+
// key uses empty string for absent roleId so that
|
|
165
|
+
// (typeId, undefined) vs (typeId, "r1") are treated as different
|
|
166
|
+
const key = `${part.typeId}|${part.roleId ?? ''}`;
|
|
167
|
+
if (seenPartKeys.has(key)) {
|
|
168
|
+
issues.push({
|
|
169
|
+
severity: 'error',
|
|
170
|
+
message: `Duplicate part (typeId "${part.typeId}", ` +
|
|
171
|
+
`roleId "${part.roleId ?? '(none)'}") in ${label}.`,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
seenPartKeys.add(key);
|
|
176
|
+
}
|
|
177
|
+
// duplicate part color (info)
|
|
178
|
+
if (part.colorKey) {
|
|
179
|
+
if (seenPartColors.has(part.colorKey)) {
|
|
180
|
+
issues.push({
|
|
181
|
+
severity: 'info',
|
|
182
|
+
message: `Duplicate part color "${part.colorKey}" in ${label}.`,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
seenPartColors.add(part.colorKey);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
// duplicate part description (info)
|
|
190
|
+
if (part.description) {
|
|
191
|
+
if (seenPartDescriptions.has(part.description)) {
|
|
192
|
+
issues.push({
|
|
193
|
+
severity: 'info',
|
|
194
|
+
message: `Duplicate part description "${part.description}" for type "${part.typeId}" in ${label}.`,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
seenPartDescriptions.add(part.description);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
// thesaurus coverage check (only when model settings are available)
|
|
204
|
+
if (!facetModelSettings) {
|
|
205
|
+
return of(this.buildResult(issues));
|
|
206
|
+
}
|
|
207
|
+
return this._thesaurusService.getThesaurusIds().pipe(map((ids) => {
|
|
208
|
+
const existingIds = new Set(ids);
|
|
209
|
+
this.checkThesauri(issues, existingIds, facetModelSettings.parts, 'Part');
|
|
210
|
+
if (facetModelSettings.fragments) {
|
|
211
|
+
this.checkThesauri(issues, existingIds, facetModelSettings.fragments, 'Fragment');
|
|
212
|
+
}
|
|
213
|
+
return this.buildResult(issues);
|
|
214
|
+
}));
|
|
215
|
+
}
|
|
216
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.5", ngImport: i0, type: FacetDefinitionValidatorService, deps: [{ token: i1.ThesaurusService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
217
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.5", ngImport: i0, type: FacetDefinitionValidatorService, providedIn: 'root' });
|
|
218
|
+
}
|
|
219
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.5", ngImport: i0, type: FacetDefinitionValidatorService, decorators: [{
|
|
220
|
+
type: Injectable,
|
|
221
|
+
args: [{ providedIn: 'root' }]
|
|
222
|
+
}], ctorParameters: () => [{ type: i1.ThesaurusService }] });
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Editor for a single part definition. This allows users to edit the part definition
|
|
226
|
+
* properties: type ID, selected from a list if facet model settings are provided,
|
|
227
|
+
* or entered freely if not (but this should not happen, as at least part definitions
|
|
228
|
+
* should be present and these provide fallback model settings); role ID, selected
|
|
229
|
+
* from a closed list when the part type is a base text part, or entered freely otherwise;
|
|
230
|
+
* name; color; group; sort key; description; and whether the part is required or not
|
|
231
|
+
* in its facet.
|
|
232
|
+
* NOTE: part definition settings are not edited here. They are defined server-side
|
|
233
|
+
* and will later be obsoleted.
|
|
234
|
+
*/
|
|
235
|
+
class PartDefinitionEditorComponent {
|
|
236
|
+
/**
|
|
237
|
+
* The part to edit.
|
|
238
|
+
*/
|
|
239
|
+
definition = model(...(ngDevMode ? [undefined, { debugName: "definition" }] : /* istanbul ignore next */ []));
|
|
240
|
+
/**
|
|
241
|
+
* The facet models settings, used to get the list of available part type IDs,
|
|
242
|
+
* and whether they are base text parts; in this case, the same settings also
|
|
243
|
+
* provide the list of their available role IDs from the fragments property.
|
|
244
|
+
*/
|
|
245
|
+
facetModelSettings = input(undefined, ...(ngDevMode ? [{ debugName: "facetModelSettings" }] : /* istanbul ignore next */ []));
|
|
246
|
+
/**
|
|
247
|
+
* The list of available part type IDs, taken from the facet model settings.
|
|
248
|
+
* If the facet model settings are not provided, or do not contain any part
|
|
249
|
+
* definition, this list is empty and the type ID must be entered freely.
|
|
250
|
+
*/
|
|
251
|
+
availablePartTypeIds = computed(() => {
|
|
252
|
+
const settings = this.facetModelSettings();
|
|
253
|
+
return settings?.parts ? Object.keys(settings.parts) : [];
|
|
254
|
+
}, ...(ngDevMode ? [{ debugName: "availablePartTypeIds" }] : /* istanbul ignore next */ []));
|
|
255
|
+
/**
|
|
256
|
+
* The list of available fragment IDs, taken from the facet model settings.
|
|
257
|
+
* This is used to populate the role ID select when the part type is a base
|
|
258
|
+
* text part (i.e. its baseText property in settings is true).
|
|
259
|
+
*/
|
|
260
|
+
availableFragmentIds = computed(() => {
|
|
261
|
+
const settings = this.facetModelSettings();
|
|
262
|
+
return settings?.fragments ? Object.keys(settings.fragments) : [];
|
|
263
|
+
}, ...(ngDevMode ? [{ debugName: "availableFragmentIds" }] : /* istanbul ignore next */ []));
|
|
264
|
+
/**
|
|
265
|
+
* True if the part type is a base text part, i.e. if the facet model settings
|
|
266
|
+
* for the current part type ID has the baseText property set to true. In this
|
|
267
|
+
* case, the role ID select is shown with the list of available fragment IDs
|
|
268
|
+
* from the facet model settings; otherwise, a free text input is shown for
|
|
269
|
+
* the role ID.
|
|
270
|
+
* Initialized in the constructor so it can reactively track typeId changes
|
|
271
|
+
* via a toSignal-wrapped valueChanges observable.
|
|
272
|
+
*/
|
|
273
|
+
isBaseTextPart;
|
|
274
|
+
/** Signal that mirrors typeId.valueChanges so computed() can track it. */
|
|
275
|
+
_typeIdValue;
|
|
276
|
+
/**
|
|
277
|
+
* True to hide the sort key field. This is used when the sort key is
|
|
278
|
+
* defined at the level of the part definitions list, and not at the level
|
|
279
|
+
* of each part definition.
|
|
280
|
+
*/
|
|
281
|
+
hideSortKey = input(false, ...(ngDevMode ? [{ debugName: "hideSortKey" }] : /* istanbul ignore next */ []));
|
|
282
|
+
/**
|
|
283
|
+
* Emitted when user requests to cancel the edit and close this editor.
|
|
284
|
+
*/
|
|
285
|
+
cancelEdit = output();
|
|
286
|
+
typeId;
|
|
287
|
+
roleId;
|
|
288
|
+
name;
|
|
289
|
+
required;
|
|
290
|
+
description;
|
|
291
|
+
colorKey;
|
|
292
|
+
groupKey;
|
|
293
|
+
sortKey;
|
|
294
|
+
form;
|
|
295
|
+
constructor(formBuilder) {
|
|
296
|
+
// form
|
|
297
|
+
this.typeId = formBuilder.control('', {
|
|
298
|
+
validators: [Validators.required, Validators.maxLength(100)],
|
|
299
|
+
nonNullable: true,
|
|
300
|
+
});
|
|
301
|
+
// mirror typeId value as a signal so computed() tracks it reactively
|
|
302
|
+
this._typeIdValue = toSignal(this.typeId.valueChanges, {
|
|
303
|
+
initialValue: this.typeId.value,
|
|
304
|
+
});
|
|
305
|
+
this.isBaseTextPart = computed(() => {
|
|
306
|
+
const settings = this.facetModelSettings();
|
|
307
|
+
return settings?.parts?.[this._typeIdValue()]?.baseText === true;
|
|
308
|
+
}, ...(ngDevMode ? [{ debugName: "isBaseTextPart" }] : /* istanbul ignore next */ []));
|
|
309
|
+
this.roleId = formBuilder.control(null);
|
|
310
|
+
this.name = formBuilder.control('', {
|
|
311
|
+
validators: [Validators.required, Validators.maxLength(100)],
|
|
312
|
+
nonNullable: true,
|
|
313
|
+
});
|
|
314
|
+
this.required = formBuilder.control(false, {
|
|
315
|
+
nonNullable: true,
|
|
316
|
+
});
|
|
317
|
+
this.description = formBuilder.control(null, {
|
|
318
|
+
validators: Validators.maxLength(1000),
|
|
319
|
+
});
|
|
320
|
+
// color key has form RRGGBB, where RR, GG and BB are hex values
|
|
321
|
+
// for red, green and blue
|
|
322
|
+
this.colorKey = formBuilder.control(null, {
|
|
323
|
+
validators: Validators.pattern('^[0-9a-fA-F]{6}$'),
|
|
324
|
+
});
|
|
325
|
+
this.groupKey = formBuilder.control(null);
|
|
326
|
+
this.sortKey = formBuilder.control(null);
|
|
327
|
+
this.form = formBuilder.group({
|
|
328
|
+
typeId: this.typeId,
|
|
329
|
+
roleId: this.roleId,
|
|
330
|
+
name: this.name,
|
|
331
|
+
required: this.required,
|
|
332
|
+
description: this.description,
|
|
333
|
+
colorKey: this.colorKey,
|
|
334
|
+
groupKey: this.groupKey,
|
|
335
|
+
sortKey: this.sortKey,
|
|
336
|
+
});
|
|
337
|
+
// when model changes, update form
|
|
338
|
+
effect(() => {
|
|
339
|
+
const data = this.definition();
|
|
340
|
+
this.updateForm(data);
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
updateForm(data) {
|
|
344
|
+
if (!data) {
|
|
345
|
+
this.form.reset();
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
this.typeId.setValue(data.typeId);
|
|
349
|
+
this.roleId.setValue(data.roleId || null);
|
|
350
|
+
this.name.setValue(data.name || '');
|
|
351
|
+
this.required.setValue(data.isRequired || false);
|
|
352
|
+
this.description.setValue(data.description || null);
|
|
353
|
+
this.colorKey.setValue(data.colorKey || null);
|
|
354
|
+
this.groupKey.setValue(data.groupKey || null);
|
|
355
|
+
this.sortKey.setValue(data.sortKey || null);
|
|
356
|
+
this.form.markAsPristine();
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
getData() {
|
|
360
|
+
return {
|
|
361
|
+
typeId: this.typeId.value.trim(),
|
|
362
|
+
roleId: this.roleId.value?.trim() || undefined,
|
|
363
|
+
name: this.name.value.trim(),
|
|
364
|
+
isRequired: this.required.value,
|
|
365
|
+
description: this.description.value?.trim() || undefined,
|
|
366
|
+
colorKey: this.colorKey.value?.trim() || undefined,
|
|
367
|
+
groupKey: this.groupKey.value?.trim() || undefined,
|
|
368
|
+
sortKey: this.sortKey.value?.trim() || undefined,
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
onColorPick(value) {
|
|
372
|
+
// native color input returns "#rrggbb" — strip the leading "#"
|
|
373
|
+
this.colorKey.setValue(value.slice(1));
|
|
374
|
+
this.colorKey.markAsDirty();
|
|
375
|
+
}
|
|
376
|
+
cancel() {
|
|
377
|
+
this.cancelEdit.emit();
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Saves the current form data by updating the `data` model signal.
|
|
381
|
+
* This method can be called manually (e.g., by a Save button) or
|
|
382
|
+
* automatically (via auto-save).
|
|
383
|
+
* @param pristine If true (default), the form is marked as pristine
|
|
384
|
+
* after saving.
|
|
385
|
+
* Set to false for auto-save if you want the form to remain dirty.
|
|
386
|
+
*/
|
|
387
|
+
save(pristine = true) {
|
|
388
|
+
if (this.form.invalid) {
|
|
389
|
+
// show validation errors
|
|
390
|
+
this.form.markAllAsTouched();
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
const data = this.getData();
|
|
394
|
+
this.definition.set(data);
|
|
395
|
+
if (pristine) {
|
|
396
|
+
this.form.markAsPristine();
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.5", ngImport: i0, type: PartDefinitionEditorComponent, deps: [{ token: i1$1.FormBuilder }], target: i0.ɵɵFactoryTarget.Component });
|
|
400
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.5", type: PartDefinitionEditorComponent, isStandalone: true, selector: "cadmus-part-definition-editor", inputs: { definition: { classPropertyName: "definition", publicName: "definition", isSignal: true, isRequired: false, transformFunction: null }, facetModelSettings: { classPropertyName: "facetModelSettings", publicName: "facetModelSettings", isSignal: true, isRequired: false, transformFunction: null }, hideSortKey: { classPropertyName: "hideSortKey", publicName: "hideSortKey", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { definition: "definitionChange", cancelEdit: "cancelEdit" }, ngImport: i0, template: "<form [formGroup]=\"form\" (submit)=\"save()\">\r\n <div class=\"form-row\">\r\n <!-- typeId (bound) -->\r\n @if (availablePartTypeIds().length) {\r\n <mat-form-field>\r\n <mat-label>type</mat-label>\r\n <mat-select [formControl]=\"typeId\">\r\n @for (id of availablePartTypeIds(); track id) {\r\n <mat-option [value]=\"id\">{{ id }}</mat-option>\r\n }\r\n </mat-select>\r\n @if (\r\n $any(typeId).errors?.required && (typeId.dirty || typeId.touched)\r\n ) {\r\n <mat-error>type ID required</mat-error>\r\n }\r\n </mat-form-field>\r\n } @else {\r\n <!-- typeId (free) -->\r\n <mat-form-field>\r\n <mat-label>type ID</mat-label>\r\n <input matInput [formControl]=\"typeId\" />\r\n @if (\r\n $any(typeId).errors?.required && (typeId.dirty || typeId.touched)\r\n ) {\r\n <mat-error>type ID required</mat-error>\r\n }\r\n @if (\r\n $any(typeId).errors?.maxLength && (typeId.dirty || typeId.touched)\r\n ) {\r\n <mat-error>type ID too long</mat-error>\r\n }\r\n </mat-form-field>\r\n }\r\n\r\n <!-- roleId is to be selected from a list if the part is a base text part -->\r\n @if (isBaseTextPart()) {\r\n <mat-form-field>\r\n <mat-label>role ID</mat-label>\r\n <mat-select [formControl]=\"roleId\">\r\n @for (e of availableFragmentIds(); track e) {\r\n <mat-option [value]=\"e\">{{ e }}</mat-option>\r\n }\r\n </mat-select>\r\n @if (\r\n $any(roleId).errors?.required && (roleId.dirty || roleId.touched)\r\n ) {\r\n <mat-error>role ID required</mat-error>\r\n }\r\n </mat-form-field>\r\n } @else {\r\n <!-- else roleId is free -->\r\n <mat-form-field>\r\n <mat-label>role ID</mat-label>\r\n <input matInput [formControl]=\"roleId\" />\r\n @if (\r\n $any(roleId).errors?.required && (roleId.dirty || roleId.touched)\r\n ) {\r\n <mat-error>role ID required</mat-error>\r\n }\r\n @if (\r\n $any(roleId).errors?.maxLength && (roleId.dirty || roleId.touched)\r\n ) {\r\n <mat-error>role ID too long</mat-error>\r\n }\r\n </mat-form-field>\r\n }\r\n\r\n <!-- required -->\r\n <mat-checkbox [formControl]=\"required\">required</mat-checkbox>\r\n </div>\r\n\r\n <div class=\"form-row\">\r\n <!-- name -->\r\n <mat-form-field>\r\n <mat-label>name</mat-label>\r\n <input matInput [formControl]=\"name\" />\r\n @if ($any(name).errors?.required && (name.dirty || name.touched)) {\r\n <mat-error>name required</mat-error>\r\n }\r\n @if ($any(name).errors?.maxLength && (name.dirty || name.touched)) {\r\n <mat-error>name too long</mat-error>\r\n }\r\n </mat-form-field>\r\n\r\n <!-- color -->\r\n <mat-form-field class=\"color-input\">\r\n <mat-label>color</mat-label>\r\n <input matInput [formControl]=\"colorKey\" />\r\n @if (\r\n $any(colorKey).errors?.pattern && (colorKey.dirty || colorKey.touched)\r\n ) {\r\n <mat-error>invalid color key</mat-error>\r\n }\r\n <input\r\n type=\"color\"\r\n class=\"color-picker-input\"\r\n #colorPicker\r\n [value]=\"\r\n colorKey.value?.length === 6 ? '#' + colorKey.value : '#000000'\r\n \"\r\n (input)=\"onColorPick(colorPicker.value)\"\r\n />\r\n <button\r\n type=\"button\"\r\n mat-icon-button\r\n matSuffix\r\n matTooltip=\"Pick color\"\r\n (click)=\"colorPicker.click()\"\r\n >\r\n <mat-icon>palette</mat-icon>\r\n </button>\r\n </mat-form-field>\r\n <div class=\"color-sample\" [style.--swatch-color]=\"'#' + colorKey.value\"></div>\r\n\r\n <!-- group -->\r\n <mat-form-field>\r\n <mat-label>group</mat-label>\r\n <input matInput [formControl]=\"groupKey\" />\r\n @if (\r\n $any(groupKey).errors?.maxLength && (groupKey.dirty || groupKey.touched)\r\n ) {\r\n <mat-error>group key too long</mat-error>\r\n }\r\n </mat-form-field>\r\n\r\n <!-- sortKey -->\r\n @if (!hideSortKey()) {\r\n <mat-form-field>\r\n <mat-label>sort key</mat-label>\r\n <input matInput [formControl]=\"sortKey\" />\r\n @if (\r\n $any(sortKey).errors?.maxLength && (sortKey.dirty || sortKey.touched)\r\n ) {\r\n <mat-error>sort key too long</mat-error>\r\n }\r\n </mat-form-field>\r\n }\r\n </div>\r\n\r\n <!-- description -->\r\n <div>\r\n <mat-form-field class=\"long-text\">\r\n <mat-label>description</mat-label>\r\n <textarea matInput [formControl]=\"description\" rows=\"2\"></textarea>\r\n @if (\r\n $any(description).errors?.maxLength &&\r\n (description.dirty || description.touched)\r\n ) {\r\n <mat-error>description too long</mat-error>\r\n }\r\n </mat-form-field>\r\n </div>\r\n\r\n <!-- buttons -->\r\n <div>\r\n <button\r\n type=\"button\"\r\n mat-icon-button\r\n matTooltip=\"Discard changes\"\r\n (click)=\"cancel()\"\r\n >\r\n <mat-icon class=\"mat-warn\">clear</mat-icon>\r\n </button>\r\n <button\r\n type=\"submit\"\r\n mat-icon-button\r\n matTooltip=\"Accept changes\"\r\n [disabled]=\"form.invalid || form.pristine\"\r\n >\r\n <mat-icon class=\"mat-primary\">check_circle</mat-icon>\r\n </button>\r\n </div>\r\n</form>\r\n", styles: ["input[type=color].color-picker-input{display:none}.form-row{display:flex;gap:8px;align-items:center;flex-wrap:wrap}.form-row *{flex:0 0 auto}.long-text{width:100%;max-width:800px}.color-input{width:9em}.color-sample{width:32px;height:32px;border-radius:50%;background:var(--swatch-color);margin-top:-16px}\n"], dependencies: [{ kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i1$1.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i1$1.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i1$1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1$1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],[formArray],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i1$1.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "directive", type: i1$1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "component", type: MatCheckbox, selector: "mat-checkbox", inputs: ["aria-label", "aria-labelledby", "aria-describedby", "aria-expanded", "aria-controls", "aria-owns", "id", "required", "labelPosition", "name", "value", "disableRipple", "tabIndex", "color", "disabledInteractive", "checked", "disabled", "indeterminate"], outputs: ["change", "indeterminateChange"], exportAs: ["matCheckbox"] }, { kind: "directive", type: MatError, selector: "mat-error, [matError]", inputs: ["id"] }, { kind: "component", type: MatFormField, selector: "mat-form-field", inputs: ["hideRequiredMarker", "color", "floatLabel", "appearance", "subscriptSizing", "hintLabel"], exportAs: ["matFormField"] }, { kind: "component", type: MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "component", type: MatIconButton, selector: "button[mat-icon-button], a[mat-icon-button], button[matIconButton], a[matIconButton]", exportAs: ["matButton", "matAnchor"] }, { kind: "directive", type: MatInput, selector: "input[matInput], textarea[matInput], select[matNativeControl], input[matNativeControl], textarea[matNativeControl]", inputs: ["disabled", "id", "placeholder", "name", "required", "type", "errorStateMatcher", "aria-describedby", "value", "readonly", "disabledInteractive"], exportAs: ["matInput"] }, { kind: "directive", type: MatLabel, selector: "mat-label" }, { kind: "component", type: MatOption, selector: "mat-option", inputs: ["value", "id", "disabled"], outputs: ["onSelectionChange"], exportAs: ["matOption"] }, { kind: "component", type: MatSelect, selector: "mat-select", inputs: ["aria-describedby", "panelClass", "disabled", "disableRipple", "tabIndex", "hideSingleSelectionIndicator", "placeholder", "required", "multiple", "disableOptionCentering", "compareWith", "value", "aria-label", "aria-labelledby", "errorStateMatcher", "typeaheadDebounceInterval", "sortComparator", "id", "panelWidth", "canSelectNullableOptions"], outputs: ["openedChange", "opened", "closed", "selectionChange", "valueChange"], exportAs: ["matSelect"] }, { kind: "directive", type: MatSuffix, selector: "[matSuffix], [matIconSuffix], [matTextSuffix]", inputs: ["matTextSuffix"] }, { kind: "directive", type: MatTooltip, selector: "[matTooltip]", inputs: ["matTooltipPosition", "matTooltipPositionAtOrigin", "matTooltipDisabled", "matTooltipShowDelay", "matTooltipHideDelay", "matTooltipTouchGestures", "matTooltip", "matTooltipClass"], exportAs: ["matTooltip"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
401
|
+
}
|
|
402
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.5", ngImport: i0, type: PartDefinitionEditorComponent, decorators: [{
|
|
403
|
+
type: Component,
|
|
404
|
+
args: [{ selector: 'cadmus-part-definition-editor', imports: [
|
|
405
|
+
ReactiveFormsModule,
|
|
406
|
+
MatCheckbox,
|
|
407
|
+
MatError,
|
|
408
|
+
MatFormField,
|
|
409
|
+
MatIcon,
|
|
410
|
+
MatIconButton,
|
|
411
|
+
MatInput,
|
|
412
|
+
MatLabel,
|
|
413
|
+
MatOption,
|
|
414
|
+
MatSelect,
|
|
415
|
+
MatSuffix,
|
|
416
|
+
MatTooltip,
|
|
417
|
+
], changeDetection: ChangeDetectionStrategy.OnPush, template: "<form [formGroup]=\"form\" (submit)=\"save()\">\r\n <div class=\"form-row\">\r\n <!-- typeId (bound) -->\r\n @if (availablePartTypeIds().length) {\r\n <mat-form-field>\r\n <mat-label>type</mat-label>\r\n <mat-select [formControl]=\"typeId\">\r\n @for (id of availablePartTypeIds(); track id) {\r\n <mat-option [value]=\"id\">{{ id }}</mat-option>\r\n }\r\n </mat-select>\r\n @if (\r\n $any(typeId).errors?.required && (typeId.dirty || typeId.touched)\r\n ) {\r\n <mat-error>type ID required</mat-error>\r\n }\r\n </mat-form-field>\r\n } @else {\r\n <!-- typeId (free) -->\r\n <mat-form-field>\r\n <mat-label>type ID</mat-label>\r\n <input matInput [formControl]=\"typeId\" />\r\n @if (\r\n $any(typeId).errors?.required && (typeId.dirty || typeId.touched)\r\n ) {\r\n <mat-error>type ID required</mat-error>\r\n }\r\n @if (\r\n $any(typeId).errors?.maxLength && (typeId.dirty || typeId.touched)\r\n ) {\r\n <mat-error>type ID too long</mat-error>\r\n }\r\n </mat-form-field>\r\n }\r\n\r\n <!-- roleId is to be selected from a list if the part is a base text part -->\r\n @if (isBaseTextPart()) {\r\n <mat-form-field>\r\n <mat-label>role ID</mat-label>\r\n <mat-select [formControl]=\"roleId\">\r\n @for (e of availableFragmentIds(); track e) {\r\n <mat-option [value]=\"e\">{{ e }}</mat-option>\r\n }\r\n </mat-select>\r\n @if (\r\n $any(roleId).errors?.required && (roleId.dirty || roleId.touched)\r\n ) {\r\n <mat-error>role ID required</mat-error>\r\n }\r\n </mat-form-field>\r\n } @else {\r\n <!-- else roleId is free -->\r\n <mat-form-field>\r\n <mat-label>role ID</mat-label>\r\n <input matInput [formControl]=\"roleId\" />\r\n @if (\r\n $any(roleId).errors?.required && (roleId.dirty || roleId.touched)\r\n ) {\r\n <mat-error>role ID required</mat-error>\r\n }\r\n @if (\r\n $any(roleId).errors?.maxLength && (roleId.dirty || roleId.touched)\r\n ) {\r\n <mat-error>role ID too long</mat-error>\r\n }\r\n </mat-form-field>\r\n }\r\n\r\n <!-- required -->\r\n <mat-checkbox [formControl]=\"required\">required</mat-checkbox>\r\n </div>\r\n\r\n <div class=\"form-row\">\r\n <!-- name -->\r\n <mat-form-field>\r\n <mat-label>name</mat-label>\r\n <input matInput [formControl]=\"name\" />\r\n @if ($any(name).errors?.required && (name.dirty || name.touched)) {\r\n <mat-error>name required</mat-error>\r\n }\r\n @if ($any(name).errors?.maxLength && (name.dirty || name.touched)) {\r\n <mat-error>name too long</mat-error>\r\n }\r\n </mat-form-field>\r\n\r\n <!-- color -->\r\n <mat-form-field class=\"color-input\">\r\n <mat-label>color</mat-label>\r\n <input matInput [formControl]=\"colorKey\" />\r\n @if (\r\n $any(colorKey).errors?.pattern && (colorKey.dirty || colorKey.touched)\r\n ) {\r\n <mat-error>invalid color key</mat-error>\r\n }\r\n <input\r\n type=\"color\"\r\n class=\"color-picker-input\"\r\n #colorPicker\r\n [value]=\"\r\n colorKey.value?.length === 6 ? '#' + colorKey.value : '#000000'\r\n \"\r\n (input)=\"onColorPick(colorPicker.value)\"\r\n />\r\n <button\r\n type=\"button\"\r\n mat-icon-button\r\n matSuffix\r\n matTooltip=\"Pick color\"\r\n (click)=\"colorPicker.click()\"\r\n >\r\n <mat-icon>palette</mat-icon>\r\n </button>\r\n </mat-form-field>\r\n <div class=\"color-sample\" [style.--swatch-color]=\"'#' + colorKey.value\"></div>\r\n\r\n <!-- group -->\r\n <mat-form-field>\r\n <mat-label>group</mat-label>\r\n <input matInput [formControl]=\"groupKey\" />\r\n @if (\r\n $any(groupKey).errors?.maxLength && (groupKey.dirty || groupKey.touched)\r\n ) {\r\n <mat-error>group key too long</mat-error>\r\n }\r\n </mat-form-field>\r\n\r\n <!-- sortKey -->\r\n @if (!hideSortKey()) {\r\n <mat-form-field>\r\n <mat-label>sort key</mat-label>\r\n <input matInput [formControl]=\"sortKey\" />\r\n @if (\r\n $any(sortKey).errors?.maxLength && (sortKey.dirty || sortKey.touched)\r\n ) {\r\n <mat-error>sort key too long</mat-error>\r\n }\r\n </mat-form-field>\r\n }\r\n </div>\r\n\r\n <!-- description -->\r\n <div>\r\n <mat-form-field class=\"long-text\">\r\n <mat-label>description</mat-label>\r\n <textarea matInput [formControl]=\"description\" rows=\"2\"></textarea>\r\n @if (\r\n $any(description).errors?.maxLength &&\r\n (description.dirty || description.touched)\r\n ) {\r\n <mat-error>description too long</mat-error>\r\n }\r\n </mat-form-field>\r\n </div>\r\n\r\n <!-- buttons -->\r\n <div>\r\n <button\r\n type=\"button\"\r\n mat-icon-button\r\n matTooltip=\"Discard changes\"\r\n (click)=\"cancel()\"\r\n >\r\n <mat-icon class=\"mat-warn\">clear</mat-icon>\r\n </button>\r\n <button\r\n type=\"submit\"\r\n mat-icon-button\r\n matTooltip=\"Accept changes\"\r\n [disabled]=\"form.invalid || form.pristine\"\r\n >\r\n <mat-icon class=\"mat-primary\">check_circle</mat-icon>\r\n </button>\r\n </div>\r\n</form>\r\n", styles: ["input[type=color].color-picker-input{display:none}.form-row{display:flex;gap:8px;align-items:center;flex-wrap:wrap}.form-row *{flex:0 0 auto}.long-text{width:100%;max-width:800px}.color-input{width:9em}.color-sample{width:32px;height:32px;border-radius:50%;background:var(--swatch-color);margin-top:-16px}\n"] }]
|
|
418
|
+
}], ctorParameters: () => [{ type: i1$1.FormBuilder }], propDecorators: { definition: [{ type: i0.Input, args: [{ isSignal: true, alias: "definition", required: false }] }, { type: i0.Output, args: ["definitionChange"] }], facetModelSettings: [{ type: i0.Input, args: [{ isSignal: true, alias: "facetModelSettings", required: false }] }], hideSortKey: [{ type: i0.Input, args: [{ isSignal: true, alias: "hideSortKey", required: false }] }], cancelEdit: [{ type: i0.Output, args: ["cancelEdit"] }] } });
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Editor for a single facet definition and its part definitions.
|
|
422
|
+
* This editor is used as a descendant of the facet definition list editor, and allows
|
|
423
|
+
* to edit a single facet definition and its part definitions.
|
|
424
|
+
*/
|
|
425
|
+
class FacetDefinitionEditorComponent {
|
|
426
|
+
_dialogService;
|
|
427
|
+
/**
|
|
428
|
+
* The facet definition to edit.
|
|
429
|
+
*/
|
|
430
|
+
definition = model(...(ngDevMode ? [undefined, { debugName: "definition" }] : /* istanbul ignore next */ []));
|
|
431
|
+
/**
|
|
432
|
+
* The facet models settings, used to get the list of available part type IDs,
|
|
433
|
+
* and whether they are base text parts; in this case, the same settings also
|
|
434
|
+
* provide the list of their available role IDs from the fragments property.
|
|
435
|
+
*/
|
|
436
|
+
facetModelSettings = input(undefined, ...(ngDevMode ? [{ debugName: "facetModelSettings" }] : /* istanbul ignore next */ []));
|
|
437
|
+
/**
|
|
438
|
+
* The list of available part type IDs, taken from the facet model settings.
|
|
439
|
+
* If the facet model settings are not provided, or do not contain any part
|
|
440
|
+
* definition, this list is empty and the type ID must be entered freely.
|
|
441
|
+
*/
|
|
442
|
+
availablePartTypeIds = computed(() => {
|
|
443
|
+
const settings = this.facetModelSettings();
|
|
444
|
+
return settings?.parts ? Object.keys(settings.parts) : [];
|
|
445
|
+
}, ...(ngDevMode ? [{ debugName: "availablePartTypeIds" }] : /* istanbul ignore next */ []));
|
|
446
|
+
/**
|
|
447
|
+
* Emitted when user requests to cancel the edit and close this editor.
|
|
448
|
+
*/
|
|
449
|
+
cancelEdit = output();
|
|
450
|
+
// edited part definition
|
|
451
|
+
edited = signal(undefined, ...(ngDevMode ? [{ debugName: "edited" }] : /* istanbul ignore next */ []));
|
|
452
|
+
editedIndex = signal(-1, ...(ngDevMode ? [{ debugName: "editedIndex" }] : /* istanbul ignore next */ []));
|
|
453
|
+
id;
|
|
454
|
+
label;
|
|
455
|
+
colorKey;
|
|
456
|
+
description;
|
|
457
|
+
partDefinitions;
|
|
458
|
+
form;
|
|
459
|
+
constructor(formBuilder, _dialogService) {
|
|
460
|
+
this._dialogService = _dialogService;
|
|
461
|
+
// form
|
|
462
|
+
this.id = formBuilder.control('', {
|
|
463
|
+
validators: [Validators.required, Validators.maxLength(100)],
|
|
464
|
+
nonNullable: true,
|
|
465
|
+
});
|
|
466
|
+
this.label = formBuilder.control('', {
|
|
467
|
+
validators: [Validators.required, Validators.maxLength(100)],
|
|
468
|
+
nonNullable: true,
|
|
469
|
+
});
|
|
470
|
+
// color key is a 6-digit hex string (without #)
|
|
471
|
+
this.colorKey = formBuilder.control('', {
|
|
472
|
+
validators: [Validators.pattern('^[0-9a-fA-F]{6}$')],
|
|
473
|
+
nonNullable: true,
|
|
474
|
+
});
|
|
475
|
+
this.description = formBuilder.control('', {
|
|
476
|
+
validators: [Validators.maxLength(1000)],
|
|
477
|
+
nonNullable: true,
|
|
478
|
+
});
|
|
479
|
+
this.partDefinitions = formBuilder.control([], {
|
|
480
|
+
validators: [Validators.required],
|
|
481
|
+
nonNullable: true,
|
|
482
|
+
});
|
|
483
|
+
this.form = formBuilder.group({
|
|
484
|
+
id: this.id,
|
|
485
|
+
label: this.label,
|
|
486
|
+
colorKey: this.colorKey,
|
|
487
|
+
description: this.description,
|
|
488
|
+
partDefinitions: this.partDefinitions,
|
|
489
|
+
});
|
|
490
|
+
// when model changes, update form
|
|
491
|
+
effect(() => {
|
|
492
|
+
const data = this.definition();
|
|
493
|
+
this.updateForm(data);
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
updateForm(data) {
|
|
497
|
+
if (!data) {
|
|
498
|
+
this.form.reset();
|
|
499
|
+
}
|
|
500
|
+
else {
|
|
501
|
+
this.id.setValue(data.id);
|
|
502
|
+
this.label.setValue(data.label);
|
|
503
|
+
this.colorKey.setValue(data.colorKey);
|
|
504
|
+
this.description.setValue(data.description);
|
|
505
|
+
// sort by sortKey so that the displayed order always matches the key order
|
|
506
|
+
const sorted = [...data.partDefinitions].sort((a, b) => (a.sortKey ?? '').localeCompare(b.sortKey ?? ''));
|
|
507
|
+
this.partDefinitions.setValue(sorted);
|
|
508
|
+
this.form.markAsPristine();
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
getDefinition() {
|
|
512
|
+
return {
|
|
513
|
+
id: this.id.value.trim(),
|
|
514
|
+
label: this.label.value.trim(),
|
|
515
|
+
colorKey: this.colorKey.value,
|
|
516
|
+
description: this.description.value.trim(),
|
|
517
|
+
partDefinitions: this.partDefinitions.value,
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
//#region Part definitions
|
|
521
|
+
updatePartDefinitionSortKeys() {
|
|
522
|
+
// assign an ordinal number as a 2-digits number to the sortKey
|
|
523
|
+
// of each part definition, so that they are sorted in the order of the list
|
|
524
|
+
const entries = this.partDefinitions.value.map((entry, index) => {
|
|
525
|
+
return {
|
|
526
|
+
...entry,
|
|
527
|
+
sortKey: (index + 1).toString().padStart(2, '0'),
|
|
528
|
+
};
|
|
529
|
+
});
|
|
530
|
+
this.partDefinitions.setValue(entries);
|
|
531
|
+
}
|
|
532
|
+
addPartDefinition() {
|
|
533
|
+
const definition = {
|
|
534
|
+
typeId: this.availablePartTypeIds().length
|
|
535
|
+
? this.availablePartTypeIds()[0]
|
|
536
|
+
: '',
|
|
537
|
+
name: 'new',
|
|
538
|
+
};
|
|
539
|
+
this.editedIndex.set(-1);
|
|
540
|
+
this.edited.set(definition);
|
|
541
|
+
}
|
|
542
|
+
editPartDefinition(entry, index) {
|
|
543
|
+
this.editedIndex.set(index);
|
|
544
|
+
this.edited.set(structuredClone(entry));
|
|
545
|
+
}
|
|
546
|
+
closePartDefinition() {
|
|
547
|
+
this.editedIndex.set(-1);
|
|
548
|
+
this.edited.set(undefined);
|
|
549
|
+
}
|
|
550
|
+
savePartDefinition(entry) {
|
|
551
|
+
const entries = [...this.partDefinitions.value];
|
|
552
|
+
if (this.editedIndex() === -1) {
|
|
553
|
+
entries.push(entry);
|
|
554
|
+
}
|
|
555
|
+
else {
|
|
556
|
+
entries.splice(this.editedIndex(), 1, entry);
|
|
557
|
+
}
|
|
558
|
+
this.partDefinitions.setValue(entries);
|
|
559
|
+
this.partDefinitions.markAsDirty();
|
|
560
|
+
this.partDefinitions.updateValueAndValidity();
|
|
561
|
+
this.updatePartDefinitionSortKeys();
|
|
562
|
+
this.closePartDefinition();
|
|
563
|
+
}
|
|
564
|
+
deletePartDefinition(index) {
|
|
565
|
+
const definition = this.partDefinitions.value[index];
|
|
566
|
+
this._dialogService
|
|
567
|
+
.confirm('Confirmation', `Delete part "${definition.name}"?`)
|
|
568
|
+
.subscribe((yes) => {
|
|
569
|
+
if (yes) {
|
|
570
|
+
if (this.editedIndex() === index) {
|
|
571
|
+
this.closePartDefinition();
|
|
572
|
+
}
|
|
573
|
+
const definitions = [...this.partDefinitions.value];
|
|
574
|
+
definitions.splice(index, 1);
|
|
575
|
+
this.partDefinitions.setValue(definitions);
|
|
576
|
+
this.partDefinitions.markAsDirty();
|
|
577
|
+
this.partDefinitions.updateValueAndValidity();
|
|
578
|
+
this.updatePartDefinitionSortKeys();
|
|
579
|
+
}
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
movePartDefinitionUp(index) {
|
|
583
|
+
if (index < 1) {
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
const definition = this.partDefinitions.value[index];
|
|
587
|
+
const definitions = [...this.partDefinitions.value];
|
|
588
|
+
definitions.splice(index, 1);
|
|
589
|
+
definitions.splice(index - 1, 0, definition);
|
|
590
|
+
this.partDefinitions.setValue(definitions);
|
|
591
|
+
this.partDefinitions.markAsDirty();
|
|
592
|
+
this.partDefinitions.updateValueAndValidity();
|
|
593
|
+
// keep editedIndex in sync
|
|
594
|
+
if (this.editedIndex() === index) {
|
|
595
|
+
this.editedIndex.set(index - 1);
|
|
596
|
+
}
|
|
597
|
+
else if (this.editedIndex() === index - 1) {
|
|
598
|
+
this.editedIndex.set(index);
|
|
599
|
+
}
|
|
600
|
+
this.updatePartDefinitionSortKeys();
|
|
601
|
+
}
|
|
602
|
+
movePartDefinitionDown(index) {
|
|
603
|
+
if (index + 1 >= this.partDefinitions.value.length) {
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
const definition = this.partDefinitions.value[index];
|
|
607
|
+
const definitions = [...this.partDefinitions.value];
|
|
608
|
+
definitions.splice(index, 1);
|
|
609
|
+
definitions.splice(index + 1, 0, definition);
|
|
610
|
+
this.partDefinitions.setValue(definitions);
|
|
611
|
+
this.partDefinitions.markAsDirty();
|
|
612
|
+
this.partDefinitions.updateValueAndValidity();
|
|
613
|
+
// keep editedIndex in sync
|
|
614
|
+
if (this.editedIndex() === index) {
|
|
615
|
+
this.editedIndex.set(index + 1);
|
|
616
|
+
}
|
|
617
|
+
else if (this.editedIndex() === index + 1) {
|
|
618
|
+
this.editedIndex.set(index);
|
|
619
|
+
}
|
|
620
|
+
this.updatePartDefinitionSortKeys();
|
|
621
|
+
}
|
|
622
|
+
//#endregion
|
|
623
|
+
onColorPick(value) {
|
|
624
|
+
// native color input returns "#rrggbb" — strip the leading "#"
|
|
625
|
+
this.colorKey.setValue(value.slice(1));
|
|
626
|
+
this.colorKey.markAsDirty();
|
|
627
|
+
}
|
|
628
|
+
cancel() {
|
|
629
|
+
this.cancelEdit.emit();
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* Saves the current form data by updating the `definition` model signal.
|
|
633
|
+
* This method can be called manually (e.g., by a Save button) or
|
|
634
|
+
* automatically (via auto-save).
|
|
635
|
+
* @param pristine If true (default), the form is marked as pristine
|
|
636
|
+
* after saving.
|
|
637
|
+
* Set to false for auto-save if you want the form to remain dirty.
|
|
638
|
+
*/
|
|
639
|
+
save(pristine = true) {
|
|
640
|
+
if (this.form.invalid) {
|
|
641
|
+
// show validation errors
|
|
642
|
+
this.form.markAllAsTouched();
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
const data = this.getDefinition();
|
|
646
|
+
this.definition.set(data);
|
|
647
|
+
if (pristine) {
|
|
648
|
+
this.form.markAsPristine();
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.5", ngImport: i0, type: FacetDefinitionEditorComponent, deps: [{ token: i1$1.FormBuilder }, { token: i2.DialogService }], target: i0.ɵɵFactoryTarget.Component });
|
|
652
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.5", type: FacetDefinitionEditorComponent, isStandalone: true, selector: "cadmus-facet-definition-editor", inputs: { definition: { classPropertyName: "definition", publicName: "definition", isSignal: true, isRequired: false, transformFunction: null }, facetModelSettings: { classPropertyName: "facetModelSettings", publicName: "facetModelSettings", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { definition: "definitionChange", cancelEdit: "cancelEdit" }, ngImport: i0, template: "<form [formGroup]=\"form\" (submit)=\"save()\">\r\n <mat-tab-group>\r\n <!-- GENERAL -->\r\n <mat-tab label=\"general\">\r\n <div class=\"form-row\">\r\n <!-- id -->\r\n <mat-form-field>\r\n <mat-label>ID</mat-label>\r\n <input matInput [formControl]=\"id\" />\r\n @if ($any(id).errors?.required && (id.dirty || id.touched)) {\r\n <mat-error>ID required</mat-error>\r\n }\r\n @if ($any(id).errors?.maxLength && (id.dirty || id.touched)) {\r\n <mat-error>ID too long</mat-error>\r\n }\r\n </mat-form-field>\r\n\r\n <!-- label -->\r\n <mat-form-field>\r\n <mat-label>label</mat-label>\r\n <input matInput [formControl]=\"label\" />\r\n @if ($any(label).errors?.required && (label.dirty || label.touched)) {\r\n <mat-error>label required</mat-error>\r\n }\r\n @if (\r\n $any(label).errors?.maxLength && (label.dirty || label.touched)\r\n ) {\r\n <mat-error>label too long</mat-error>\r\n }\r\n </mat-form-field>\r\n\r\n <!-- color -->\r\n <mat-form-field class=\"color-input\">\r\n <mat-label>color</mat-label>\r\n <input matInput [formControl]=\"colorKey\" />\r\n @if (\r\n $any(colorKey).errors?.pattern &&\r\n (colorKey.dirty || colorKey.touched)\r\n ) {\r\n <mat-error>invalid color key</mat-error>\r\n }\r\n <input\r\n type=\"color\"\r\n class=\"color-picker-input\"\r\n #colorPicker\r\n [value]=\"\r\n colorKey.value.length === 6 ? '#' + colorKey.value : '#000000'\r\n \"\r\n (input)=\"onColorPick(colorPicker.value)\"\r\n />\r\n <button\r\n type=\"button\"\r\n mat-icon-button\r\n matSuffix\r\n matTooltip=\"Pick color\"\r\n (click)=\"colorPicker.click()\"\r\n >\r\n <mat-icon>palette</mat-icon>\r\n </button>\r\n </mat-form-field>\r\n <div class=\"color-sample\" [style.--swatch-color]=\"'#' + colorKey.value\"></div>\r\n </div>\r\n\r\n <!-- description -->\r\n <div>\r\n <mat-form-field class=\"long-text\">\r\n <mat-label>description</mat-label>\r\n <textarea matInput [formControl]=\"description\" rows=\"2\"></textarea>\r\n @if (\r\n $any(description).errors?.maxLength &&\r\n (description.dirty || description.touched)\r\n ) {\r\n <mat-error>description too long</mat-error>\r\n }\r\n </mat-form-field>\r\n </div>\r\n </mat-tab>\r\n\r\n <!-- PARTS -->\r\n <mat-tab label=\"parts\">\r\n <div>\r\n <button\r\n type=\"button\"\r\n mat-flat-button\r\n color=\"primary\"\r\n (click)=\"addPartDefinition()\"\r\n >\r\n <mat-icon>add_circle</mat-icon> part\r\n </button>\r\n </div>\r\n @if (partDefinitions.value.length) {\r\n <table>\r\n <thead>\r\n <tr>\r\n <th></th>\r\n <th>required</th>\r\n <th>type ID</th>\r\n <th>role ID</th>\r\n <th>name</th>\r\n <th>group</th>\r\n <th>color</th>\r\n <th>description</th>\r\n </tr>\r\n </thead>\r\n <tbody>\r\n @for (\r\n entry of partDefinitions.value;\r\n track entry;\r\n let i = $index;\r\n let first = $first;\r\n let last = $last\r\n ) {\r\n <tr [class.selected]=\"i === editedIndex()\">\r\n <td class=\"fit-width\">\r\n <button\r\n type=\"button\"\r\n mat-icon-button\r\n color=\"primary\"\r\n matTooltip=\"Edit this part definition\"\r\n (click)=\"editPartDefinition(entry, i)\"\r\n >\r\n <mat-icon class=\"mat-primary\">edit</mat-icon>\r\n </button>\r\n <button\r\n type=\"button\"\r\n mat-icon-button\r\n matTooltip=\"Move this part definition up\"\r\n [disabled]=\"first\"\r\n (click)=\"movePartDefinitionUp(i)\"\r\n >\r\n <mat-icon>arrow_upward</mat-icon>\r\n </button>\r\n <button\r\n type=\"button\"\r\n mat-icon-button\r\n matTooltip=\"Move this part definition down\"\r\n [disabled]=\"last\"\r\n (click)=\"movePartDefinitionDown(i)\"\r\n >\r\n <mat-icon>arrow_downward</mat-icon>\r\n </button>\r\n <button\r\n type=\"button\"\r\n mat-icon-button\r\n color=\"warn\"\r\n matTooltip=\"Delete this part definition\"\r\n (click)=\"deletePartDefinition(i)\"\r\n >\r\n <mat-icon class=\"mat-warn\">remove_circle</mat-icon>\r\n </button>\r\n </td>\r\n <td class=\"fit-width\">\r\n <mat-checkbox\r\n [checked]=\"entry.isRequired\"\r\n disabled\r\n ></mat-checkbox>\r\n </td>\r\n <td>{{ entry.typeId }}</td>\r\n <td>{{ entry.roleId }}</td>\r\n <td>{{ entry.name }}</td>\r\n <td>{{ entry.groupKey }}</td>\r\n <td>\r\n <span\r\n class=\"color-swatch\"\r\n [style.background-color]=\"'#' + entry.colorKey\"\r\n [style.color]=\"('#' + entry.colorKey) | colorToContrast\"\r\n >\r\n {{ entry.colorKey }}\r\n </span>\r\n </td>\r\n <td>{{ entry.description | ellipsis: 50 }}</td>\r\n </tr>\r\n }\r\n </tbody>\r\n </table>\r\n }\r\n @if (edited()) {\r\n <fieldset>\r\n <mat-expansion-panel [expanded]=\"edited()\" [disabled]=\"!edited()\">\r\n <mat-expansion-panel-header>\r\n <mat-panel-title>Part #{{ editedIndex() + 1 }}</mat-panel-title>\r\n </mat-expansion-panel-header>\r\n <cadmus-part-definition-editor\r\n [facetModelSettings]=\"facetModelSettings()\"\r\n [hideSortKey]=\"true\"\r\n [definition]=\"edited()\"\r\n (definitionChange)=\"savePartDefinition($event!)\"\r\n (cancelEdit)=\"closePartDefinition()\"\r\n />\r\n </mat-expansion-panel>\r\n </fieldset>\r\n }\r\n </mat-tab>\r\n </mat-tab-group>\r\n\r\n <!-- buttons -->\r\n <div>\r\n <button\r\n type=\"button\"\r\n mat-icon-button\r\n matTooltip=\"Discard changes\"\r\n (click)=\"cancel()\"\r\n >\r\n <mat-icon class=\"mat-warn\">clear</mat-icon>\r\n </button>\r\n <button\r\n type=\"submit\"\r\n mat-icon-button\r\n matTooltip=\"Accept changes\"\r\n [disabled]=\"form.invalid || form.pristine\"\r\n >\r\n <mat-icon class=\"mat-primary\">check_circle</mat-icon>\r\n </button>\r\n </div>\r\n</form>\r\n", styles: ["input[type=color].color-picker-input{display:none}.long-text{width:100%;max-width:800px}.form-row{display:flex;gap:8px;align-items:center;flex-wrap:wrap}.form-row *{flex:0 0 auto}table{width:100%;border-collapse:collapse;color:var(--mat-sys-on-surface-variant)}tbody tr:nth-child(odd){background-color:var(--mat-sys-surface-container)}th{text-align:left;font-weight:400;color:var(--mat-sys-on-surface-variant)}tbody tr:hover{background-color:var(--mat-sys-surface-container-high)}td.fit-width{width:1px;white-space:nowrap}tbody tr.selected{background-color:var(--mat-sys-secondary-container);color:var(--mat-sys-on-secondary-container)}.color-swatch{padding:2px 6px;border-radius:4px}.color-input{width:9em}.color-sample{width:32px;height:32px;border-radius:50%;background:var(--swatch-color);margin-top:-16px}\n"], dependencies: [{ kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i1$1.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i1$1.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i1$1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1$1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],[formArray],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i1$1.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }, { kind: "directive", type: i1$1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "ngmodule", type: MatButtonModule }, { kind: "component", type: i3.MatButton, selector: " button[matButton], a[matButton], button[mat-button], button[mat-raised-button], button[mat-flat-button], button[mat-stroked-button], a[mat-button], a[mat-raised-button], a[mat-flat-button], a[mat-stroked-button] ", inputs: ["matButton"], exportAs: ["matButton", "matAnchor"] }, { kind: "component", type: i3.MatIconButton, selector: "button[mat-icon-button], a[mat-icon-button], button[matIconButton], a[matIconButton]", exportAs: ["matButton", "matAnchor"] }, { kind: "component", type: MatCheckbox, selector: "mat-checkbox", inputs: ["aria-label", "aria-labelledby", "aria-describedby", "aria-expanded", "aria-controls", "aria-owns", "id", "required", "labelPosition", "name", "value", "disableRipple", "tabIndex", "color", "disabledInteractive", "checked", "disabled", "indeterminate"], outputs: ["change", "indeterminateChange"], exportAs: ["matCheckbox"] }, { kind: "directive", type: MatError$1, selector: "mat-error, [matError]", inputs: ["id"] }, { kind: "component", type: MatExpansionPanel, selector: "mat-expansion-panel", inputs: ["hideToggle", "togglePosition"], outputs: ["afterExpand", "afterCollapse"], exportAs: ["matExpansionPanel"] }, { kind: "component", type: MatExpansionPanelHeader, selector: "mat-expansion-panel-header", inputs: ["expandedHeight", "collapsedHeight", "tabIndex"] }, { kind: "directive", type: MatExpansionPanelTitle, selector: "mat-panel-title" }, { kind: "component", type: MatFormField$1, selector: "mat-form-field", inputs: ["hideRequiredMarker", "color", "floatLabel", "appearance", "subscriptSizing", "hintLabel"], exportAs: ["matFormField"] }, { kind: "component", type: MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "directive", type: MatInput, selector: "input[matInput], textarea[matInput], select[matNativeControl], input[matNativeControl], textarea[matNativeControl]", inputs: ["disabled", "id", "placeholder", "name", "required", "type", "errorStateMatcher", "aria-describedby", "value", "readonly", "disabledInteractive"], exportAs: ["matInput"] }, { kind: "directive", type: MatLabel$1, selector: "mat-label" }, { kind: "directive", type: MatSuffix, selector: "[matSuffix], [matIconSuffix], [matTextSuffix]", inputs: ["matTextSuffix"] }, { kind: "component", type: MatTab, selector: "mat-tab", inputs: ["disabled", "label", "aria-label", "aria-labelledby", "labelClass", "bodyClass", "id"], exportAs: ["matTab"] }, { kind: "component", type: MatTabGroup, selector: "mat-tab-group", inputs: ["color", "fitInkBarToContent", "mat-stretch-tabs", "mat-align-tabs", "dynamicHeight", "selectedIndex", "headerPosition", "animationDuration", "contentTabIndex", "disablePagination", "disableRipple", "preserveContent", "backgroundColor", "aria-label", "aria-labelledby"], outputs: ["selectedIndexChange", "focusChange", "animationDone", "selectedTabChange"], exportAs: ["matTabGroup"] }, { kind: "directive", type: MatTooltip, selector: "[matTooltip]", inputs: ["matTooltipPosition", "matTooltipPositionAtOrigin", "matTooltipDisabled", "matTooltipShowDelay", "matTooltipHideDelay", "matTooltipTouchGestures", "matTooltip", "matTooltipClass"], exportAs: ["matTooltip"] }, { kind: "component", type: PartDefinitionEditorComponent, selector: "cadmus-part-definition-editor", inputs: ["definition", "facetModelSettings", "hideSortKey"], outputs: ["definitionChange", "cancelEdit"] }, { kind: "pipe", type: ColorToContrastPipe, name: "colorToContrast" }, { kind: "pipe", type: EllipsisPipe, name: "ellipsis" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
653
|
+
}
|
|
654
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.5", ngImport: i0, type: FacetDefinitionEditorComponent, decorators: [{
|
|
655
|
+
type: Component,
|
|
656
|
+
args: [{ selector: 'cadmus-facet-definition-editor', imports: [
|
|
657
|
+
ReactiveFormsModule,
|
|
658
|
+
MatButtonModule,
|
|
659
|
+
MatCheckbox,
|
|
660
|
+
MatError$1,
|
|
661
|
+
MatExpansionPanel,
|
|
662
|
+
MatExpansionPanelHeader,
|
|
663
|
+
MatExpansionPanelTitle,
|
|
664
|
+
MatFormField$1,
|
|
665
|
+
MatIcon,
|
|
666
|
+
MatInput,
|
|
667
|
+
MatLabel$1,
|
|
668
|
+
MatSuffix,
|
|
669
|
+
MatTab,
|
|
670
|
+
MatTabGroup,
|
|
671
|
+
MatTooltip,
|
|
672
|
+
ColorToContrastPipe,
|
|
673
|
+
EllipsisPipe,
|
|
674
|
+
StringToColorPipe,
|
|
675
|
+
PartDefinitionEditorComponent,
|
|
676
|
+
], changeDetection: ChangeDetectionStrategy.OnPush, template: "<form [formGroup]=\"form\" (submit)=\"save()\">\r\n <mat-tab-group>\r\n <!-- GENERAL -->\r\n <mat-tab label=\"general\">\r\n <div class=\"form-row\">\r\n <!-- id -->\r\n <mat-form-field>\r\n <mat-label>ID</mat-label>\r\n <input matInput [formControl]=\"id\" />\r\n @if ($any(id).errors?.required && (id.dirty || id.touched)) {\r\n <mat-error>ID required</mat-error>\r\n }\r\n @if ($any(id).errors?.maxLength && (id.dirty || id.touched)) {\r\n <mat-error>ID too long</mat-error>\r\n }\r\n </mat-form-field>\r\n\r\n <!-- label -->\r\n <mat-form-field>\r\n <mat-label>label</mat-label>\r\n <input matInput [formControl]=\"label\" />\r\n @if ($any(label).errors?.required && (label.dirty || label.touched)) {\r\n <mat-error>label required</mat-error>\r\n }\r\n @if (\r\n $any(label).errors?.maxLength && (label.dirty || label.touched)\r\n ) {\r\n <mat-error>label too long</mat-error>\r\n }\r\n </mat-form-field>\r\n\r\n <!-- color -->\r\n <mat-form-field class=\"color-input\">\r\n <mat-label>color</mat-label>\r\n <input matInput [formControl]=\"colorKey\" />\r\n @if (\r\n $any(colorKey).errors?.pattern &&\r\n (colorKey.dirty || colorKey.touched)\r\n ) {\r\n <mat-error>invalid color key</mat-error>\r\n }\r\n <input\r\n type=\"color\"\r\n class=\"color-picker-input\"\r\n #colorPicker\r\n [value]=\"\r\n colorKey.value.length === 6 ? '#' + colorKey.value : '#000000'\r\n \"\r\n (input)=\"onColorPick(colorPicker.value)\"\r\n />\r\n <button\r\n type=\"button\"\r\n mat-icon-button\r\n matSuffix\r\n matTooltip=\"Pick color\"\r\n (click)=\"colorPicker.click()\"\r\n >\r\n <mat-icon>palette</mat-icon>\r\n </button>\r\n </mat-form-field>\r\n <div class=\"color-sample\" [style.--swatch-color]=\"'#' + colorKey.value\"></div>\r\n </div>\r\n\r\n <!-- description -->\r\n <div>\r\n <mat-form-field class=\"long-text\">\r\n <mat-label>description</mat-label>\r\n <textarea matInput [formControl]=\"description\" rows=\"2\"></textarea>\r\n @if (\r\n $any(description).errors?.maxLength &&\r\n (description.dirty || description.touched)\r\n ) {\r\n <mat-error>description too long</mat-error>\r\n }\r\n </mat-form-field>\r\n </div>\r\n </mat-tab>\r\n\r\n <!-- PARTS -->\r\n <mat-tab label=\"parts\">\r\n <div>\r\n <button\r\n type=\"button\"\r\n mat-flat-button\r\n color=\"primary\"\r\n (click)=\"addPartDefinition()\"\r\n >\r\n <mat-icon>add_circle</mat-icon> part\r\n </button>\r\n </div>\r\n @if (partDefinitions.value.length) {\r\n <table>\r\n <thead>\r\n <tr>\r\n <th></th>\r\n <th>required</th>\r\n <th>type ID</th>\r\n <th>role ID</th>\r\n <th>name</th>\r\n <th>group</th>\r\n <th>color</th>\r\n <th>description</th>\r\n </tr>\r\n </thead>\r\n <tbody>\r\n @for (\r\n entry of partDefinitions.value;\r\n track entry;\r\n let i = $index;\r\n let first = $first;\r\n let last = $last\r\n ) {\r\n <tr [class.selected]=\"i === editedIndex()\">\r\n <td class=\"fit-width\">\r\n <button\r\n type=\"button\"\r\n mat-icon-button\r\n color=\"primary\"\r\n matTooltip=\"Edit this part definition\"\r\n (click)=\"editPartDefinition(entry, i)\"\r\n >\r\n <mat-icon class=\"mat-primary\">edit</mat-icon>\r\n </button>\r\n <button\r\n type=\"button\"\r\n mat-icon-button\r\n matTooltip=\"Move this part definition up\"\r\n [disabled]=\"first\"\r\n (click)=\"movePartDefinitionUp(i)\"\r\n >\r\n <mat-icon>arrow_upward</mat-icon>\r\n </button>\r\n <button\r\n type=\"button\"\r\n mat-icon-button\r\n matTooltip=\"Move this part definition down\"\r\n [disabled]=\"last\"\r\n (click)=\"movePartDefinitionDown(i)\"\r\n >\r\n <mat-icon>arrow_downward</mat-icon>\r\n </button>\r\n <button\r\n type=\"button\"\r\n mat-icon-button\r\n color=\"warn\"\r\n matTooltip=\"Delete this part definition\"\r\n (click)=\"deletePartDefinition(i)\"\r\n >\r\n <mat-icon class=\"mat-warn\">remove_circle</mat-icon>\r\n </button>\r\n </td>\r\n <td class=\"fit-width\">\r\n <mat-checkbox\r\n [checked]=\"entry.isRequired\"\r\n disabled\r\n ></mat-checkbox>\r\n </td>\r\n <td>{{ entry.typeId }}</td>\r\n <td>{{ entry.roleId }}</td>\r\n <td>{{ entry.name }}</td>\r\n <td>{{ entry.groupKey }}</td>\r\n <td>\r\n <span\r\n class=\"color-swatch\"\r\n [style.background-color]=\"'#' + entry.colorKey\"\r\n [style.color]=\"('#' + entry.colorKey) | colorToContrast\"\r\n >\r\n {{ entry.colorKey }}\r\n </span>\r\n </td>\r\n <td>{{ entry.description | ellipsis: 50 }}</td>\r\n </tr>\r\n }\r\n </tbody>\r\n </table>\r\n }\r\n @if (edited()) {\r\n <fieldset>\r\n <mat-expansion-panel [expanded]=\"edited()\" [disabled]=\"!edited()\">\r\n <mat-expansion-panel-header>\r\n <mat-panel-title>Part #{{ editedIndex() + 1 }}</mat-panel-title>\r\n </mat-expansion-panel-header>\r\n <cadmus-part-definition-editor\r\n [facetModelSettings]=\"facetModelSettings()\"\r\n [hideSortKey]=\"true\"\r\n [definition]=\"edited()\"\r\n (definitionChange)=\"savePartDefinition($event!)\"\r\n (cancelEdit)=\"closePartDefinition()\"\r\n />\r\n </mat-expansion-panel>\r\n </fieldset>\r\n }\r\n </mat-tab>\r\n </mat-tab-group>\r\n\r\n <!-- buttons -->\r\n <div>\r\n <button\r\n type=\"button\"\r\n mat-icon-button\r\n matTooltip=\"Discard changes\"\r\n (click)=\"cancel()\"\r\n >\r\n <mat-icon class=\"mat-warn\">clear</mat-icon>\r\n </button>\r\n <button\r\n type=\"submit\"\r\n mat-icon-button\r\n matTooltip=\"Accept changes\"\r\n [disabled]=\"form.invalid || form.pristine\"\r\n >\r\n <mat-icon class=\"mat-primary\">check_circle</mat-icon>\r\n </button>\r\n </div>\r\n</form>\r\n", styles: ["input[type=color].color-picker-input{display:none}.long-text{width:100%;max-width:800px}.form-row{display:flex;gap:8px;align-items:center;flex-wrap:wrap}.form-row *{flex:0 0 auto}table{width:100%;border-collapse:collapse;color:var(--mat-sys-on-surface-variant)}tbody tr:nth-child(odd){background-color:var(--mat-sys-surface-container)}th{text-align:left;font-weight:400;color:var(--mat-sys-on-surface-variant)}tbody tr:hover{background-color:var(--mat-sys-surface-container-high)}td.fit-width{width:1px;white-space:nowrap}tbody tr.selected{background-color:var(--mat-sys-secondary-container);color:var(--mat-sys-on-secondary-container)}.color-swatch{padding:2px 6px;border-radius:4px}.color-input{width:9em}.color-sample{width:32px;height:32px;border-radius:50%;background:var(--swatch-color);margin-top:-16px}\n"] }]
|
|
677
|
+
}], ctorParameters: () => [{ type: i1$1.FormBuilder }, { type: i2.DialogService }], propDecorators: { definition: [{ type: i0.Input, args: [{ isSignal: true, alias: "definition", required: false }] }, { type: i0.Output, args: ["definitionChange"] }], facetModelSettings: [{ type: i0.Input, args: [{ isSignal: true, alias: "facetModelSettings", required: false }] }], cancelEdit: [{ type: i0.Output, args: ["cancelEdit"] }] } });
|
|
678
|
+
|
|
679
|
+
/**
|
|
680
|
+
* Editor for a list of facet definitions. Cadmus facet definitions represent the data
|
|
681
|
+
* types of items, and define all the parts which can be included in an item. Some of
|
|
682
|
+
* them are required, others are optional. There can be multiple parts of the same type
|
|
683
|
+
* in the same item, provided that their roleId is different.
|
|
684
|
+
* This editor is used to edit the list of facet definitions from the current profile.
|
|
685
|
+
* As the top level editor, it loads and saves the facet definitions list via API
|
|
686
|
+
* services, and allows to add, edit, delete and reorder facet definitions.
|
|
687
|
+
* The actual editing of a facet definition is delegated to descendant dumb components.
|
|
688
|
+
* All edits happen in memory until the user clicks the Save button, which saves all
|
|
689
|
+
* facet definitions to the server, and shows the result of the operation.
|
|
690
|
+
*/
|
|
691
|
+
class FacetDefinitionListEditorComponent {
|
|
692
|
+
_dialogService;
|
|
693
|
+
_facetService;
|
|
694
|
+
_validator;
|
|
695
|
+
_snackbar;
|
|
696
|
+
edited = signal(undefined, ...(ngDevMode ? [{ debugName: "edited" }] : /* istanbul ignore next */ []));
|
|
697
|
+
editedIndex = signal(-1, ...(ngDevMode ? [{ debugName: "editedIndex" }] : /* istanbul ignore next */ []));
|
|
698
|
+
dirty = signal(false, ...(ngDevMode ? [{ debugName: "dirty" }] : /* istanbul ignore next */ []));
|
|
699
|
+
facets = signal([], ...(ngDevMode ? [{ debugName: "facets" }] : /* istanbul ignore next */ []));
|
|
700
|
+
busy = signal(false, ...(ngDevMode ? [{ debugName: "busy" }] : /* istanbul ignore next */ []));
|
|
701
|
+
saveResult = signal(undefined, ...(ngDevMode ? [{ debugName: "saveResult" }] : /* istanbul ignore next */ []));
|
|
702
|
+
/** True after at least one facet was successfully saved; prompts an app reload. */
|
|
703
|
+
reloadNeeded = signal(false, ...(ngDevMode ? [{ debugName: "reloadNeeded" }] : /* istanbul ignore next */ []));
|
|
704
|
+
/** Last validation result, set by validate() and by save(). */
|
|
705
|
+
validationResult = signal(undefined, ...(ngDevMode ? [{ debugName: "validationResult" }] : /* istanbul ignore next */ []));
|
|
706
|
+
/**
|
|
707
|
+
* The facet models settings, used to get the list of available part type IDs,
|
|
708
|
+
* and whether they are base text parts; in this case, the same settings also
|
|
709
|
+
* provide the list of their available role IDs from the fragments property.
|
|
710
|
+
*/
|
|
711
|
+
facetModelSettings = signal(undefined, ...(ngDevMode ? [{ debugName: "facetModelSettings" }] : /* istanbul ignore next */ []));
|
|
712
|
+
dirtyChange = output();
|
|
713
|
+
editorClose = output();
|
|
714
|
+
constructor(_dialogService, _facetService, _validator, _snackbar) {
|
|
715
|
+
this._dialogService = _dialogService;
|
|
716
|
+
this._facetService = _facetService;
|
|
717
|
+
this._validator = _validator;
|
|
718
|
+
this._snackbar = _snackbar;
|
|
719
|
+
}
|
|
720
|
+
ngOnInit() {
|
|
721
|
+
// load facets once at start
|
|
722
|
+
this.busy.set(true);
|
|
723
|
+
this._facetService.getFacets().subscribe({
|
|
724
|
+
next: (facets) => {
|
|
725
|
+
this.facets.set(facets);
|
|
726
|
+
this.busy.set(false);
|
|
727
|
+
},
|
|
728
|
+
error: (error) => {
|
|
729
|
+
console.error(error);
|
|
730
|
+
this.busy.set(false);
|
|
731
|
+
this._snackbar.open('Error loading facets', 'Close');
|
|
732
|
+
},
|
|
733
|
+
});
|
|
734
|
+
// load facet model settings once at start
|
|
735
|
+
this._facetService.getFacetModelSettings().subscribe({
|
|
736
|
+
next: (settings) => {
|
|
737
|
+
this.facetModelSettings.set(settings);
|
|
738
|
+
},
|
|
739
|
+
error: (error) => {
|
|
740
|
+
console.error(error);
|
|
741
|
+
this._snackbar.open('Error loading facet model settings', 'Close');
|
|
742
|
+
},
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
addFacet() {
|
|
746
|
+
const entry = {
|
|
747
|
+
id: 'new',
|
|
748
|
+
label: 'New facet',
|
|
749
|
+
colorKey: 'default',
|
|
750
|
+
description: '',
|
|
751
|
+
partDefinitions: [],
|
|
752
|
+
};
|
|
753
|
+
this.editedIndex.set(-1);
|
|
754
|
+
this.edited.set(entry);
|
|
755
|
+
}
|
|
756
|
+
editFacet(facet, index) {
|
|
757
|
+
this.editedIndex.set(index);
|
|
758
|
+
this.edited.set(structuredClone(facet));
|
|
759
|
+
}
|
|
760
|
+
closeFacet() {
|
|
761
|
+
this.editedIndex.set(-1);
|
|
762
|
+
this.edited.set(undefined);
|
|
763
|
+
}
|
|
764
|
+
saveFacet(facet) {
|
|
765
|
+
const entries = [...this.facets()];
|
|
766
|
+
if (this.editedIndex() === -1) {
|
|
767
|
+
entries.push(facet);
|
|
768
|
+
}
|
|
769
|
+
else {
|
|
770
|
+
entries.splice(this.editedIndex(), 1, facet);
|
|
771
|
+
}
|
|
772
|
+
this.facets.set(entries);
|
|
773
|
+
this.closeFacet();
|
|
774
|
+
this.dirty.set(true);
|
|
775
|
+
this.dirtyChange.emit(true);
|
|
776
|
+
}
|
|
777
|
+
deleteFacet(index) {
|
|
778
|
+
this._dialogService
|
|
779
|
+
.confirm('Confirmation', `Delete facet ${this.edited()?.label}?`)
|
|
780
|
+
.subscribe((yes) => {
|
|
781
|
+
if (yes) {
|
|
782
|
+
if (this.editedIndex() === index) {
|
|
783
|
+
this.closeFacet();
|
|
784
|
+
}
|
|
785
|
+
const entries = [...this.facets()];
|
|
786
|
+
entries.splice(index, 1);
|
|
787
|
+
this.facets.set(entries);
|
|
788
|
+
this.dirty.set(true);
|
|
789
|
+
this.dirtyChange.emit(true);
|
|
790
|
+
}
|
|
791
|
+
});
|
|
792
|
+
}
|
|
793
|
+
moveFacetUp(index) {
|
|
794
|
+
if (index < 1) {
|
|
795
|
+
return;
|
|
796
|
+
}
|
|
797
|
+
const facet = this.facets()[index];
|
|
798
|
+
const facets = [...this.facets()];
|
|
799
|
+
facets.splice(index, 1);
|
|
800
|
+
facets.splice(index - 1, 0, facet);
|
|
801
|
+
this.facets.set(facets);
|
|
802
|
+
this.dirty.set(true);
|
|
803
|
+
this.dirtyChange.emit(true);
|
|
804
|
+
// keep editedIndex in sync
|
|
805
|
+
if (this.editedIndex() === index) {
|
|
806
|
+
this.editedIndex.set(index - 1);
|
|
807
|
+
}
|
|
808
|
+
else if (this.editedIndex() === index - 1) {
|
|
809
|
+
this.editedIndex.set(index);
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
moveFacetDown(index) {
|
|
813
|
+
if (index + 1 >= this.facets().length) {
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
const facet = this.facets()[index];
|
|
817
|
+
const facets = [...this.facets()];
|
|
818
|
+
facets.splice(index, 1);
|
|
819
|
+
facets.splice(index + 1, 0, facet);
|
|
820
|
+
this.facets.set(facets);
|
|
821
|
+
this.dirty.set(true);
|
|
822
|
+
this.dirtyChange.emit(true);
|
|
823
|
+
// keep editedIndex in sync
|
|
824
|
+
if (this.editedIndex() === index) {
|
|
825
|
+
this.editedIndex.set(index + 1);
|
|
826
|
+
}
|
|
827
|
+
else if (this.editedIndex() === index + 1) {
|
|
828
|
+
this.editedIndex.set(index);
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
reloadApp() {
|
|
832
|
+
window.location.href = '/';
|
|
833
|
+
}
|
|
834
|
+
close() {
|
|
835
|
+
this.editorClose.emit();
|
|
836
|
+
}
|
|
837
|
+
/** Run validation and update validationResult; returns the observable. */
|
|
838
|
+
runValidation() {
|
|
839
|
+
return this._validator
|
|
840
|
+
.validate(this.facets(), this.facetModelSettings())
|
|
841
|
+
.pipe(tap((result) => this.validationResult.set(result)));
|
|
842
|
+
}
|
|
843
|
+
/** Trigger validation from the template and update the displayed result. */
|
|
844
|
+
validate() {
|
|
845
|
+
this.runValidation().pipe(take(1)).subscribe();
|
|
846
|
+
}
|
|
847
|
+
/** Persist all facets to the server; called only after all gates pass. */
|
|
848
|
+
doSave() {
|
|
849
|
+
const facets = this.facets();
|
|
850
|
+
this.busy.set(true);
|
|
851
|
+
this.saveResult.set(undefined);
|
|
852
|
+
from(facets)
|
|
853
|
+
.pipe(concatMap((facet) => this._facetService.addFacet(facet).pipe(map(() => true), catchError(() => of(false)))), toArray())
|
|
854
|
+
.subscribe((results) => {
|
|
855
|
+
const saved = [];
|
|
856
|
+
const failed = [];
|
|
857
|
+
results.forEach((ok, i) => {
|
|
858
|
+
if (ok) {
|
|
859
|
+
saved.push(facets[i].id);
|
|
860
|
+
}
|
|
861
|
+
else {
|
|
862
|
+
failed.push(facets[i].id);
|
|
863
|
+
}
|
|
864
|
+
});
|
|
865
|
+
this.busy.set(false);
|
|
866
|
+
this.dirty.set(failed.length > 0);
|
|
867
|
+
this.dirtyChange.emit(failed.length > 0);
|
|
868
|
+
if (saved.length > 0) {
|
|
869
|
+
this.reloadNeeded.set(true);
|
|
870
|
+
}
|
|
871
|
+
const parts = [];
|
|
872
|
+
if (saved.length) {
|
|
873
|
+
parts.push(`Saved: ${saved.join(', ')}`);
|
|
874
|
+
}
|
|
875
|
+
if (failed.length) {
|
|
876
|
+
parts.push(`Failed: ${failed.join(', ')}`);
|
|
877
|
+
}
|
|
878
|
+
this.saveResult.set(parts.join(' | '));
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
/**
|
|
882
|
+
* Final confirmation gate before the actual write.
|
|
883
|
+
* Always shown, even when there are no warnings or errors.
|
|
884
|
+
*/
|
|
885
|
+
confirmAndSave() {
|
|
886
|
+
this._dialogService
|
|
887
|
+
.confirm('Save facets', 'Saving replaces ALL facet definitions on the server. ' +
|
|
888
|
+
'This may affect every item in the database. Proceed?')
|
|
889
|
+
.subscribe((ok) => {
|
|
890
|
+
if (ok) {
|
|
891
|
+
this.doSave();
|
|
892
|
+
}
|
|
893
|
+
});
|
|
894
|
+
}
|
|
895
|
+
downloadFacets() {
|
|
896
|
+
const replacer = (_key, value) => value === null || value === false ? undefined : value;
|
|
897
|
+
const dataStr = 'data:text/json;charset=utf-8,' +
|
|
898
|
+
encodeURIComponent(JSON.stringify(this.facets(), replacer, 2));
|
|
899
|
+
const dlAnchorElem = document.createElement('a');
|
|
900
|
+
dlAnchorElem.setAttribute('href', dataStr);
|
|
901
|
+
dlAnchorElem.setAttribute('download', 'facets.json');
|
|
902
|
+
dlAnchorElem.click();
|
|
903
|
+
}
|
|
904
|
+
/**
|
|
905
|
+
* Validate the current facets, then — if there are no blocking errors —
|
|
906
|
+
* walk the user through confirmation gates before saving.
|
|
907
|
+
*
|
|
908
|
+
* Gates (in order):
|
|
909
|
+
* 1. Validation errors → block save, show results.
|
|
910
|
+
* 2. Validation warnings → ask user to confirm before continuing.
|
|
911
|
+
* 3. Final critical-operation confirmation → always shown.
|
|
912
|
+
*/
|
|
913
|
+
save() {
|
|
914
|
+
if (!this.facets().length) {
|
|
915
|
+
return;
|
|
916
|
+
}
|
|
917
|
+
this.runValidation()
|
|
918
|
+
.pipe(take(1))
|
|
919
|
+
.subscribe((result) => {
|
|
920
|
+
if (result.hasErrors) {
|
|
921
|
+
// validation result is already displayed; nothing more to do
|
|
922
|
+
return;
|
|
923
|
+
}
|
|
924
|
+
if (result.hasWarnings) {
|
|
925
|
+
const warnCount = result.issues.filter((i) => i.severity === 'warning').length;
|
|
926
|
+
this._dialogService
|
|
927
|
+
.confirm('Warnings', `There ${warnCount === 1 ? 'is 1 warning' : `are ${warnCount} warnings`}. ` +
|
|
928
|
+
'Review the validation results below. Proceed anyway?')
|
|
929
|
+
.subscribe((ok) => {
|
|
930
|
+
if (ok) {
|
|
931
|
+
this.confirmAndSave();
|
|
932
|
+
}
|
|
933
|
+
});
|
|
934
|
+
}
|
|
935
|
+
else {
|
|
936
|
+
this.confirmAndSave();
|
|
937
|
+
}
|
|
938
|
+
});
|
|
939
|
+
}
|
|
940
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.5", ngImport: i0, type: FacetDefinitionListEditorComponent, deps: [{ token: i2.DialogService }, { token: i1.FacetService }, { token: FacetDefinitionValidatorService }, { token: i4.MatSnackBar }], target: i0.ɵɵFactoryTarget.Component });
|
|
941
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.5", type: FacetDefinitionListEditorComponent, isStandalone: true, selector: "cadmus-facet-definition-list-editor", outputs: { dirtyChange: "dirtyChange", editorClose: "editorClose" }, ngImport: i0, template: "<div>\r\n <div class=\"form-row\">\r\n <button type=\"button\" mat-flat-button color=\"primary\" (click)=\"addFacet()\">\r\n <mat-icon>add_circle</mat-icon> facet\r\n </button>\r\n <button type=\"button\" mat-flat-button (click)=\"validate()\">\r\n <mat-icon>fact_check</mat-icon> validate\r\n </button>\r\n <button type=\"button\" mat-flat-button (click)=\"downloadFacets()\">\r\n <mat-icon>download</mat-icon> download\r\n </button>\r\n <button type=\"button\" mat-flat-button color=\"warn\" (click)=\"save()\">\r\n <mat-icon>save</mat-icon> save\r\n </button>\r\n </div>\r\n <div>\r\n @if (busy()) {\r\n <mat-progress-bar mode=\"indeterminate\" color=\"accent\" />\r\n }\r\n </div>\r\n @if (validationResult(); as vr) {\r\n <mat-expansion-panel [expanded]=\"true\">\r\n <mat-expansion-panel-header>\r\n <mat-panel-title>Validation result</mat-panel-title>\r\n <mat-panel-description>\r\n {{ vr.issues.length }} issue{{ vr.issues.length !== 1 ? \"s\" : \"\" }}\r\n </mat-panel-description>\r\n </mat-expansion-panel-header>\r\n <div class=\"validation-result\">\r\n @if (!vr.issues.length) {\r\n <span>No issues found.</span>\r\n } @else {\r\n <div class=\"validation-issues\">\r\n @for (issue of vr.issues; track $index) {\r\n <div class=\"validation-issue {{ issue.severity }}\">\r\n <mat-icon>{{\r\n issue.severity === \"error\"\r\n ? \"error\"\r\n : issue.severity === \"warning\"\r\n ? \"warning\"\r\n : \"info\"\r\n }}</mat-icon>\r\n <span>{{ issue.message }}</span>\r\n </div>\r\n }\r\n </div>\r\n }\r\n </div>\r\n </mat-expansion-panel>\r\n }\r\n @if (reloadNeeded()) {\r\n <div class=\"reload-notice\">\r\n <mat-icon>info</mat-icon>\r\n <span\r\n >Facet definitions are cached at startup. Please reload the app to apply\r\n the changes.</span\r\n >\r\n <button\r\n type=\"button\"\r\n mat-flat-button\r\n color=\"primary\"\r\n (click)=\"reloadApp()\"\r\n >\r\n <mat-icon>refresh</mat-icon>\r\n reload app\r\n </button>\r\n </div>\r\n }\r\n @if (facets().length) {\r\n <table class=\"margin-top\">\r\n <thead>\r\n <tr>\r\n <th></th>\r\n <th>ID</th>\r\n <th>label</th>\r\n <th>color</th>\r\n <th>parts</th>\r\n <th>description</th>\r\n </tr>\r\n </thead>\r\n <tbody>\r\n @for (\r\n entry of facets();\r\n track entry;\r\n let i = $index;\r\n let first = $first;\r\n let last = $last\r\n ) {\r\n <tr [class.selected]=\"i === editedIndex()\">\r\n <td class=\"fit-width\">\r\n <button\r\n type=\"button\"\r\n mat-icon-button\r\n color=\"primary\"\r\n matTooltip=\"Edit this facet\"\r\n (click)=\"editFacet(entry, i)\"\r\n >\r\n <mat-icon class=\"mat-primary\">edit</mat-icon>\r\n </button>\r\n <button\r\n type=\"button\"\r\n mat-icon-button\r\n matTooltip=\"Move this facet up\"\r\n [disabled]=\"first\"\r\n (click)=\"moveFacetUp(i)\"\r\n >\r\n <mat-icon>arrow_upward</mat-icon>\r\n </button>\r\n <button\r\n type=\"button\"\r\n mat-icon-button\r\n matTooltip=\"Move this facet down\"\r\n [disabled]=\"last\"\r\n (click)=\"moveFacetDown(i)\"\r\n >\r\n <mat-icon>arrow_downward</mat-icon>\r\n </button>\r\n <button\r\n type=\"button\"\r\n mat-icon-button\r\n color=\"warn\"\r\n matTooltip=\"Delete this facet\"\r\n (click)=\"deleteFacet(i)\"\r\n >\r\n <mat-icon class=\"mat-warn\">remove_circle</mat-icon>\r\n </button>\r\n </td>\r\n <td>{{ entry.id }}</td>\r\n <td>{{ entry.label }}</td>\r\n <td>\r\n <span\r\n class=\"color-swatch\"\r\n [style.background-color]=\"'#' + entry.colorKey\"\r\n [style.color]=\"('#' + entry.colorKey) | colorToContrast\"\r\n >\r\n {{ entry.colorKey }}\r\n </span>\r\n </td>\r\n <td>{{ entry.partDefinitions.length }}</td>\r\n <td>{{ entry.description | ellipsis: 50 }}</td>\r\n </tr>\r\n }\r\n </tbody>\r\n </table>\r\n }\r\n @if (edited()) {\r\n <fieldset>\r\n <mat-expansion-panel [expanded]=\"edited()\" [disabled]=\"!edited()\">\r\n <mat-expansion-panel-header>\r\n <mat-panel-title>Facet #{{ editedIndex() + 1 }}</mat-panel-title>\r\n </mat-expansion-panel-header>\r\n <cadmus-facet-definition-editor\r\n [facetModelSettings]=\"facetModelSettings()\"\r\n [definition]=\"edited()\"\r\n (definitionChange)=\"saveFacet($event!)\"\r\n (cancelEdit)=\"closeFacet()\"\r\n />\r\n </mat-expansion-panel>\r\n </fieldset>\r\n }\r\n</div>\r\n", styles: ["table{width:100%;border-collapse:collapse;color:var(--mat-sys-on-surface-variant)}tbody tr:nth-child(odd){background-color:var(--mat-sys-surface-container)}th{text-align:left;font-weight:400;color:var(--mat-sys-on-surface-variant)}tbody tr:hover{background-color:var(--mat-sys-surface-container-high)}td.fit-width{width:1px;white-space:nowrap}tbody tr.selected{background-color:var(--mat-sys-secondary-container);color:var(--mat-sys-on-secondary-container)}fieldset{border:1px solid silver;border-radius:6px;padding:6px}.validation-result{margin:8px 0}.validation-issues{display:flex;flex-direction:column;gap:4px;margin:8px 0}.validation-issue{display:flex;align-items:center;gap:4px}.validation-issue.error{color:var(--mat-sys-error)}.validation-issue.warning{color:var(--mat-sys-tertiary)}.reload-notice{display:flex;gap:8px;align-items:center;margin:16px 0;padding:12px;background-color:var(--mat-sys-warning);border:1px solid var(--mat-sys-warning);border-radius:4px;color:var(--mat-sys-on-warning)}.form-row{display:flex;gap:8px;align-items:center;flex-wrap:wrap}.form-row *{flex:0 0 auto}.color-swatch{padding:2px 6px;border-radius:4px}.margin-top{margin-top:1rem}\n"], dependencies: [{ kind: "ngmodule", type: MatButtonModule }, { kind: "component", type: i3.MatButton, selector: " button[matButton], a[matButton], button[mat-button], button[mat-raised-button], button[mat-flat-button], button[mat-stroked-button], a[mat-button], a[mat-raised-button], a[mat-flat-button], a[mat-stroked-button] ", inputs: ["matButton"], exportAs: ["matButton", "matAnchor"] }, { kind: "component", type: i3.MatIconButton, selector: "button[mat-icon-button], a[mat-icon-button], button[matIconButton], a[matIconButton]", exportAs: ["matButton", "matAnchor"] }, { kind: "component", type: MatExpansionPanel, selector: "mat-expansion-panel", inputs: ["hideToggle", "togglePosition"], outputs: ["afterExpand", "afterCollapse"], exportAs: ["matExpansionPanel"] }, { kind: "directive", type: MatExpansionPanelDescription, selector: "mat-panel-description" }, { kind: "component", type: MatExpansionPanelHeader, selector: "mat-expansion-panel-header", inputs: ["expandedHeight", "collapsedHeight", "tabIndex"] }, { kind: "directive", type: MatExpansionPanelTitle, selector: "mat-panel-title" }, { kind: "component", type: MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "directive", type: MatTooltip, selector: "[matTooltip]", inputs: ["matTooltipPosition", "matTooltipPositionAtOrigin", "matTooltipDisabled", "matTooltipShowDelay", "matTooltipHideDelay", "matTooltipTouchGestures", "matTooltip", "matTooltipClass"], exportAs: ["matTooltip"] }, { kind: "component", type: MatProgressBar, selector: "mat-progress-bar", inputs: ["color", "value", "bufferValue", "mode"], outputs: ["animationEnd"], exportAs: ["matProgressBar"] }, { kind: "component", type: FacetDefinitionEditorComponent, selector: "cadmus-facet-definition-editor", inputs: ["definition", "facetModelSettings"], outputs: ["definitionChange", "cancelEdit"] }, { kind: "pipe", type: ColorToContrastPipe, name: "colorToContrast" }, { kind: "pipe", type: EllipsisPipe, name: "ellipsis" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
942
|
+
}
|
|
943
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.5", ngImport: i0, type: FacetDefinitionListEditorComponent, decorators: [{
|
|
944
|
+
type: Component,
|
|
945
|
+
args: [{ selector: 'cadmus-facet-definition-list-editor', imports: [
|
|
946
|
+
MatButtonModule,
|
|
947
|
+
MatExpansionPanel,
|
|
948
|
+
MatExpansionPanelDescription,
|
|
949
|
+
MatExpansionPanelHeader,
|
|
950
|
+
MatExpansionPanelTitle,
|
|
951
|
+
MatIcon,
|
|
952
|
+
MatTooltip,
|
|
953
|
+
MatProgressBar,
|
|
954
|
+
ColorToContrastPipe,
|
|
955
|
+
EllipsisPipe,
|
|
956
|
+
StringToColorPipe,
|
|
957
|
+
FacetDefinitionEditorComponent,
|
|
958
|
+
], changeDetection: ChangeDetectionStrategy.OnPush, template: "<div>\r\n <div class=\"form-row\">\r\n <button type=\"button\" mat-flat-button color=\"primary\" (click)=\"addFacet()\">\r\n <mat-icon>add_circle</mat-icon> facet\r\n </button>\r\n <button type=\"button\" mat-flat-button (click)=\"validate()\">\r\n <mat-icon>fact_check</mat-icon> validate\r\n </button>\r\n <button type=\"button\" mat-flat-button (click)=\"downloadFacets()\">\r\n <mat-icon>download</mat-icon> download\r\n </button>\r\n <button type=\"button\" mat-flat-button color=\"warn\" (click)=\"save()\">\r\n <mat-icon>save</mat-icon> save\r\n </button>\r\n </div>\r\n <div>\r\n @if (busy()) {\r\n <mat-progress-bar mode=\"indeterminate\" color=\"accent\" />\r\n }\r\n </div>\r\n @if (validationResult(); as vr) {\r\n <mat-expansion-panel [expanded]=\"true\">\r\n <mat-expansion-panel-header>\r\n <mat-panel-title>Validation result</mat-panel-title>\r\n <mat-panel-description>\r\n {{ vr.issues.length }} issue{{ vr.issues.length !== 1 ? \"s\" : \"\" }}\r\n </mat-panel-description>\r\n </mat-expansion-panel-header>\r\n <div class=\"validation-result\">\r\n @if (!vr.issues.length) {\r\n <span>No issues found.</span>\r\n } @else {\r\n <div class=\"validation-issues\">\r\n @for (issue of vr.issues; track $index) {\r\n <div class=\"validation-issue {{ issue.severity }}\">\r\n <mat-icon>{{\r\n issue.severity === \"error\"\r\n ? \"error\"\r\n : issue.severity === \"warning\"\r\n ? \"warning\"\r\n : \"info\"\r\n }}</mat-icon>\r\n <span>{{ issue.message }}</span>\r\n </div>\r\n }\r\n </div>\r\n }\r\n </div>\r\n </mat-expansion-panel>\r\n }\r\n @if (reloadNeeded()) {\r\n <div class=\"reload-notice\">\r\n <mat-icon>info</mat-icon>\r\n <span\r\n >Facet definitions are cached at startup. Please reload the app to apply\r\n the changes.</span\r\n >\r\n <button\r\n type=\"button\"\r\n mat-flat-button\r\n color=\"primary\"\r\n (click)=\"reloadApp()\"\r\n >\r\n <mat-icon>refresh</mat-icon>\r\n reload app\r\n </button>\r\n </div>\r\n }\r\n @if (facets().length) {\r\n <table class=\"margin-top\">\r\n <thead>\r\n <tr>\r\n <th></th>\r\n <th>ID</th>\r\n <th>label</th>\r\n <th>color</th>\r\n <th>parts</th>\r\n <th>description</th>\r\n </tr>\r\n </thead>\r\n <tbody>\r\n @for (\r\n entry of facets();\r\n track entry;\r\n let i = $index;\r\n let first = $first;\r\n let last = $last\r\n ) {\r\n <tr [class.selected]=\"i === editedIndex()\">\r\n <td class=\"fit-width\">\r\n <button\r\n type=\"button\"\r\n mat-icon-button\r\n color=\"primary\"\r\n matTooltip=\"Edit this facet\"\r\n (click)=\"editFacet(entry, i)\"\r\n >\r\n <mat-icon class=\"mat-primary\">edit</mat-icon>\r\n </button>\r\n <button\r\n type=\"button\"\r\n mat-icon-button\r\n matTooltip=\"Move this facet up\"\r\n [disabled]=\"first\"\r\n (click)=\"moveFacetUp(i)\"\r\n >\r\n <mat-icon>arrow_upward</mat-icon>\r\n </button>\r\n <button\r\n type=\"button\"\r\n mat-icon-button\r\n matTooltip=\"Move this facet down\"\r\n [disabled]=\"last\"\r\n (click)=\"moveFacetDown(i)\"\r\n >\r\n <mat-icon>arrow_downward</mat-icon>\r\n </button>\r\n <button\r\n type=\"button\"\r\n mat-icon-button\r\n color=\"warn\"\r\n matTooltip=\"Delete this facet\"\r\n (click)=\"deleteFacet(i)\"\r\n >\r\n <mat-icon class=\"mat-warn\">remove_circle</mat-icon>\r\n </button>\r\n </td>\r\n <td>{{ entry.id }}</td>\r\n <td>{{ entry.label }}</td>\r\n <td>\r\n <span\r\n class=\"color-swatch\"\r\n [style.background-color]=\"'#' + entry.colorKey\"\r\n [style.color]=\"('#' + entry.colorKey) | colorToContrast\"\r\n >\r\n {{ entry.colorKey }}\r\n </span>\r\n </td>\r\n <td>{{ entry.partDefinitions.length }}</td>\r\n <td>{{ entry.description | ellipsis: 50 }}</td>\r\n </tr>\r\n }\r\n </tbody>\r\n </table>\r\n }\r\n @if (edited()) {\r\n <fieldset>\r\n <mat-expansion-panel [expanded]=\"edited()\" [disabled]=\"!edited()\">\r\n <mat-expansion-panel-header>\r\n <mat-panel-title>Facet #{{ editedIndex() + 1 }}</mat-panel-title>\r\n </mat-expansion-panel-header>\r\n <cadmus-facet-definition-editor\r\n [facetModelSettings]=\"facetModelSettings()\"\r\n [definition]=\"edited()\"\r\n (definitionChange)=\"saveFacet($event!)\"\r\n (cancelEdit)=\"closeFacet()\"\r\n />\r\n </mat-expansion-panel>\r\n </fieldset>\r\n }\r\n</div>\r\n", styles: ["table{width:100%;border-collapse:collapse;color:var(--mat-sys-on-surface-variant)}tbody tr:nth-child(odd){background-color:var(--mat-sys-surface-container)}th{text-align:left;font-weight:400;color:var(--mat-sys-on-surface-variant)}tbody tr:hover{background-color:var(--mat-sys-surface-container-high)}td.fit-width{width:1px;white-space:nowrap}tbody tr.selected{background-color:var(--mat-sys-secondary-container);color:var(--mat-sys-on-secondary-container)}fieldset{border:1px solid silver;border-radius:6px;padding:6px}.validation-result{margin:8px 0}.validation-issues{display:flex;flex-direction:column;gap:4px;margin:8px 0}.validation-issue{display:flex;align-items:center;gap:4px}.validation-issue.error{color:var(--mat-sys-error)}.validation-issue.warning{color:var(--mat-sys-tertiary)}.reload-notice{display:flex;gap:8px;align-items:center;margin:16px 0;padding:12px;background-color:var(--mat-sys-warning);border:1px solid var(--mat-sys-warning);border-radius:4px;color:var(--mat-sys-on-warning)}.form-row{display:flex;gap:8px;align-items:center;flex-wrap:wrap}.form-row *{flex:0 0 auto}.color-swatch{padding:2px 6px;border-radius:4px}.margin-top{margin-top:1rem}\n"] }]
|
|
959
|
+
}], ctorParameters: () => [{ type: i2.DialogService }, { type: i1.FacetService }, { type: FacetDefinitionValidatorService }, { type: i4.MatSnackBar }], propDecorators: { dirtyChange: [{ type: i0.Output, args: ["dirtyChange"] }], editorClose: [{ type: i0.Output, args: ["editorClose"] }] } });
|
|
960
|
+
|
|
961
|
+
class FacetEditPageComponent {
|
|
962
|
+
_dirty = signal(false, ...(ngDevMode ? [{ debugName: "_dirty" }] : /* istanbul ignore next */ []));
|
|
963
|
+
canDeactivate() {
|
|
964
|
+
return !this._dirty();
|
|
965
|
+
}
|
|
966
|
+
onDirtyChange(dirty) {
|
|
967
|
+
this._dirty.set(dirty);
|
|
968
|
+
}
|
|
969
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.5", ngImport: i0, type: FacetEditPageComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
970
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.2.5", type: FacetEditPageComponent, isStandalone: true, selector: "cadmus-facet-edit-page", ngImport: i0, template: "<mat-card>\r\n <mat-card-header>\r\n <mat-icon mat-card-avatar>dashboard</mat-icon>\r\n <mat-card-title>Edit Facets</mat-card-title>\r\n </mat-card-header>\r\n <mat-card-content>\r\n <div class=\"margin-top\">\r\n <cadmus-facet-definition-list-editor (dirtyChange)=\"onDirtyChange($event)\" />\r\n </div>\r\n </mat-card-content>\r\n</mat-card>\r\n", styles: [".margin-top{margin-top:1rem}\n"], dependencies: [{ kind: "component", type: MatCard, selector: "mat-card", inputs: ["appearance"], exportAs: ["matCard"] }, { kind: "directive", type: MatCardContent, selector: "mat-card-content" }, { kind: "component", type: MatCardHeader, selector: "mat-card-header" }, { kind: "directive", type: MatCardTitle, selector: "mat-card-title, [mat-card-title], [matCardTitle]" }, { kind: "component", type: MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "component", type: FacetDefinitionListEditorComponent, selector: "cadmus-facet-definition-list-editor", outputs: ["dirtyChange", "editorClose"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
971
|
+
}
|
|
972
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.5", ngImport: i0, type: FacetEditPageComponent, decorators: [{
|
|
973
|
+
type: Component,
|
|
974
|
+
args: [{ selector: 'cadmus-facet-edit-page', imports: [
|
|
975
|
+
MatCard,
|
|
976
|
+
MatCardContent,
|
|
977
|
+
MatCardHeader,
|
|
978
|
+
MatCardTitle,
|
|
979
|
+
MatIcon,
|
|
980
|
+
FacetDefinitionListEditorComponent,
|
|
981
|
+
], changeDetection: ChangeDetectionStrategy.OnPush, template: "<mat-card>\r\n <mat-card-header>\r\n <mat-icon mat-card-avatar>dashboard</mat-icon>\r\n <mat-card-title>Edit Facets</mat-card-title>\r\n </mat-card-header>\r\n <mat-card-content>\r\n <div class=\"margin-top\">\r\n <cadmus-facet-definition-list-editor (dirtyChange)=\"onDirtyChange($event)\" />\r\n </div>\r\n </mat-card-content>\r\n</mat-card>\r\n", styles: [".margin-top{margin-top:1rem}\n"] }]
|
|
982
|
+
}] });
|
|
983
|
+
|
|
984
|
+
const CADMUS_PROFILE_EDIT_ROUTES = [
|
|
985
|
+
{
|
|
986
|
+
path: 'facets',
|
|
987
|
+
pathMatch: 'full',
|
|
988
|
+
component: FacetEditPageComponent,
|
|
989
|
+
canDeactivate: [pendingChangesGuard],
|
|
990
|
+
},
|
|
991
|
+
];
|
|
992
|
+
|
|
993
|
+
/*
|
|
994
|
+
* Public API Surface of cadmus-profile-editor
|
|
995
|
+
*/
|
|
996
|
+
|
|
997
|
+
/**
|
|
998
|
+
* Generated bundle index. Do not edit.
|
|
999
|
+
*/
|
|
1000
|
+
|
|
1001
|
+
export { CADMUS_PROFILE_EDIT_ROUTES, FacetDefinitionEditorComponent, FacetDefinitionListEditorComponent, FacetDefinitionValidatorService, FacetEditPageComponent, PartDefinitionEditorComponent };
|
|
1002
|
+
//# sourceMappingURL=myrmidon-cadmus-profile-editor.mjs.map
|