-
+
- @if (hasUpdatedValues && canEdit) {
+ @if (hasUpdatedValues() && canEdit()) {
();
+ currentEntry: WritableSignal;
+ readonly canEdit = input();
+ readonly deselectLast = output();
+ readonly overrideValue = output();
+ readonly revertOverride = output();
+ hasUpdatedValues = computed(() => this.currentEntry().overridden);
+ selected = false;
+ valueBeforeCurrentEdit: IComponentValue[];
protected entryLabel: string;
protected editing = false;
- protected hasUpdatedValues = false;
protected initialEntry: IComponentLogEntry;
+ disabled = computed(() => {
+ for (let i = 0; i < this.currentEntry().componentValues.length; i++) {
+ if (this.currentEntry().componentValues[i].value !== this.initialEntry.componentValues[i]?.value) {
+ return false;
+ }
+ }
+ return this.currentEntry().componentValues.length === this.initialEntry.componentValues.length;
+ });
protected readonly iconButtonTypes = IconButtonTypes;
- @Input() entry: IComponentLogEntry;
- @Input() canEdit: boolean;
- @Output() readonly deselectLast = new EventEmitter();
- @Output() readonly overrideValue = new EventEmitter();
- @Output() readonly revertOverride = new EventEmitter();
- selected = false;
constructor(
readonly helpModeService: HelpModeService,
@@ -52,39 +62,18 @@ export class EditableStructuredComponentValueComponent implements OnInit {
private readonly _state: FilePreviewStateService,
) {}
- get disabled() {
- for (let i = 0; i < this.entry.componentValues.length; i++) {
- if (this.entry.componentValues[i].value !== this.initialEntry.componentValues[i]?.value) {
- return false;
- }
- }
- return this.entry.componentValues.length === this.initialEntry.componentValues.length;
- }
-
- get #hasUpdatedValues() {
- for (const value of this.entry.componentValues) {
- if (value.originalValue === null && value.value === '') {
- continue;
- }
- if (value.originalValue !== value.value) {
- return true;
- }
- }
- return false;
- }
-
get #initialEntry() {
- return JSON.parse(JSON.stringify(this.entry));
+ return JSON.parse(JSON.stringify(this.entry()));
}
ngOnInit() {
+ this.currentEntry = signal(this.entry());
this.reset();
}
reset() {
this.initialEntry = this.#initialEntry;
- this.hasUpdatedValues = this.#hasUpdatedValues;
- this.entryLabel = this.parseName(this.entry.name);
+ this.entryLabel = this.parseName(this.currentEntry().name);
this.deselect();
}
@@ -96,11 +85,12 @@ export class EditableStructuredComponentValueComponent implements OnInit {
}
this.deselectLast.emit();
this.selected = true;
- this._state.componentReferenceIds = this.#getUniqueReferencesIds(this.entry.componentValues);
+ this._state.componentReferenceIds = this.#getUniqueReferencesIds(this.currentEntry().componentValues);
}
}
edit() {
+ this.valueBeforeCurrentEdit = JSON.parse(JSON.stringify([...this.currentEntry().componentValues]));
this.deselectLast.emit();
this.selected = true;
this.editing = true;
@@ -114,37 +104,48 @@ export class EditableStructuredComponentValueComponent implements OnInit {
this._state.componentReferenceIds = null;
}
+ cancel($event?: MouseEvent) {
+ this.currentEntry.update(value => ({ ...value, componentValues: this.valueBeforeCurrentEdit }));
+ this.deselect($event);
+ }
+
removeValue(index: number) {
- this.entry.componentValues.splice(index, 1);
+ this.currentEntry.update(value => ({ ...value, componentValues: value.componentValues.filter((_, i) => i !== index) }));
}
save() {
- this.entry.overridden = true;
- this.overrideValue.emit(this.entry);
+ this.currentEntry.update(value => ({ ...value, overridden: true }));
+ this.overrideValue.emit(this.currentEntry());
this.reset();
}
async undo() {
- const dialog = this._iqserDialog.openDefault(RevertValueDialogComponent, { data: { entry: this.entry }, width: '800px' });
+ const dialog = this._iqserDialog.openDefault(RevertValueDialogComponent, { data: { entry: this.currentEntry() }, width: '800px' });
const result = await dialog.result();
if (result) {
- this.revertOverride.emit(this.entry.name);
+ this.revertOverride.emit(this.currentEntry().name);
this.reset();
}
}
add() {
- this.entry.componentValues.push({
- componentRuleId: null,
- entityReferences: [],
- originalValue: null,
- value: '',
- valueDescription: '',
- });
+ this.currentEntry.update(value => ({
+ ...value,
+ componentValues: [
+ ...value.componentValues,
+ {
+ componentRuleId: null,
+ entityReferences: [],
+ originalValue: null,
+ value: '',
+ valueDescription: '',
+ },
+ ],
+ }));
}
drop(event: CdkDragDrop) {
- moveItemInArray(this.entry.componentValues, event.previousIndex, event.currentIndex);
+ moveItemInArray(this.currentEntry().componentValues, event.previousIndex, event.currentIndex);
}
parseName(name: string) {
@@ -167,7 +168,7 @@ export class EditableStructuredComponentValueComponent implements OnInit {
#updateTextAreaHeight() {
setTimeout(() => {
- for (let i = 0; i < this.entry.componentValues.length; i++) {
+ for (let i = 0; i < this.currentEntry().componentValues.length; i++) {
const textArea = document.getElementById(`value-input-${i}`);
textArea.style.height = 'auto';
textArea.style.height = `${textArea.scrollHeight}px`;