diff --git a/apps/red-ui/src/app/modules/admin/screens/dictionary-overview/dictionary-overview-screen.component.ts b/apps/red-ui/src/app/modules/admin/screens/dictionary-overview/dictionary-overview-screen.component.ts
index d8c5b401d..e952312da 100644
--- a/apps/red-ui/src/app/modules/admin/screens/dictionary-overview/dictionary-overview-screen.component.ts
+++ b/apps/red-ui/src/app/modules/admin/screens/dictionary-overview/dictionary-overview-screen.component.ts
@@ -3,11 +3,9 @@ import { DictionaryControllerService, TypeValue } from '@redaction/red-ui-http';
import { AppStateService } from '@state/app-state.service';
import { PermissionsService } from '@services/permissions.service';
import { ActivatedRoute, Router } from '@angular/router';
-import { NotificationService } from '@services/notification.service';
import { TranslateService } from '@ngx-translate/core';
import { saveAs } from 'file-saver';
import { ComponentHasChanges } from '@guards/can-deactivate.guard';
-import { FormBuilder } from '@angular/forms';
import { AdminDialogService } from '../../services/admin-dialog.service';
import { DictionaryManagerComponent } from '../../../shared/components/dictionary-manager/dictionary-manager.component';
import { DictionarySaveService } from '../../../shared/services/dictionary-save.service';
@@ -22,20 +20,18 @@ export class DictionaryOverviewScreenComponent extends ComponentHasChanges imple
entries: string[] = [];
@ViewChild('dictionaryManager', { static: false })
- private _dictionaryManager: DictionaryManagerComponent;
- @ViewChild('fileInput') private _fileInput: ElementRef;
+ private readonly _dictionaryManager: DictionaryManagerComponent;
+ @ViewChild('fileInput') private readonly _fileInput: ElementRef;
constructor(
readonly permissionsService: PermissionsService,
- private readonly _notificationService: NotificationService,
protected readonly _translateService: TranslateService,
private readonly _dictionarySaveService: DictionarySaveService,
private readonly _dictionaryControllerService: DictionaryControllerService,
private readonly _dialogService: AdminDialogService,
private readonly _router: Router,
private readonly _activatedRoute: ActivatedRoute,
- private readonly _appStateService: AppStateService,
- private readonly _formBuilder: FormBuilder
+ private readonly _appStateService: AppStateService
) {
super(_translateService);
this._appStateService.activateDictionary(
@@ -93,7 +89,7 @@ export class DictionaryOverviewScreenComponent extends ComponentHasChanges imple
if (file) {
fileReader.onload = () => {
- this._dictionaryManager.editorValue = fileReader.result;
+ this._dictionaryManager.editorValue = fileReader.result as string;
this._fileInput.nativeElement.value = null;
};
fileReader.readAsText(file);
diff --git a/apps/red-ui/src/app/modules/admin/screens/rules/rules-screen.component.html b/apps/red-ui/src/app/modules/admin/screens/rules/rules-screen.component.html
index dcac0f4c7..c04706a24 100644
--- a/apps/red-ui/src/app/modules/admin/screens/rules/rules-screen.component.html
+++ b/apps/red-ui/src/app/modules/admin/screens/rules/rules-screen.component.html
@@ -20,18 +20,11 @@
0;
+ onCodeEditorInit(editor: ICodeEditor) {
+ this._codeEditor = editor;
+ (window as any).monaco.editor.defineTheme('redaction', {
+ base: 'vs',
+ inherit: true,
+ rules: [],
+ colors: {
+ 'editor.lineHighlightBackground': '#f4f5f7'
+ }
+ });
+ (window as any).monaco.editor.setTheme('redaction');
}
- textChanged($event: any) {
+ get hasChanges(): boolean {
+ return this._decorations.length > 0;
+ }
+
+ get codeEditorText() {
+ return this.currentLines.join('\n');
+ }
+
+ set codeEditorText($event: any) {
this.currentLines = $event.split('\n');
- this.changedLines = [];
- this.activeEditMarkers.forEach((am) => {
- this.editorComponent.getEditor().getSession().removeMarker(am);
- });
- this.activeEditMarkers = [];
+ this.codeEditorTextChanged();
+ }
- for (let i = 0; i < this.currentLines.length; i++) {
- const currentEntry = this.currentLines[i];
- if (this.initialLines.indexOf(currentEntry) < 0) {
- this.changedLines.push(i);
- }
- }
+ @debounce()
+ codeEditorTextChanged() {
+ const newDecorations = this.currentLines
+ .filter((entry) => this._isNew(entry))
+ .map((entry) => this._makeDecorationFor(entry));
- const range = ace.require('ace/range').Range;
- for (const i of this.changedLines) {
- const entry = this.currentLines[i];
- if (entry?.trim().length > 0) {
- // only mark non-empty lines
- this.activeEditMarkers.push(
- this.editorComponent
- .getEditor()
- .getSession()
- .addMarker(new range(i, 0, i, 1), 'changed-row-marker', 'fullLine')
- );
- }
- }
+ this._decorations = this._codeEditor.deltaDecorations(this._decorations, newDecorations);
+ }
+
+ private _isNew(entry: string): boolean {
+ return this.initialLines.indexOf(entry) < 0 && entry?.trim().length > 0;
+ }
+
+ private _makeDecorationFor(entry: string): IModelDeltaDecoration {
+ const line = this.currentLines.indexOf(entry) + 1;
+
+ return {
+ range: new monaco.Range(line, 1, line, 1),
+ options: { isWholeLine: true, className: 'changed-row-marker' }
+ } as IModelDeltaDecoration;
}
async save(): Promise {
this.processing = true;
this._rulesControllerService
.uploadRules({
- rules: this.editorComponent.getEditor().getValue(),
+ rules: this._codeEditor.getModel().getValue(),
ruleSetId: this._appStateService.activeRuleSetId
})
.subscribe(
@@ -107,14 +124,13 @@ export class RulesScreenComponent extends ComponentHasChanges {
}
revert(): void {
- this.initialLines = this.rules.split('\n');
- this.editorComponent.getEditor().setValue(this.rules);
- this.editorComponent.getEditor().clearSelection();
+ this.currentLines = this.initialLines;
+ this._decorations = this._codeEditor?.deltaDecorations(this._decorations, []) || [];
this.processing = false;
}
download(): void {
- const content = this.editorComponent.getEditor().getValue();
+ const content = this._codeEditor.getModel().getValue();
const blob = new Blob([content], {
type: 'text/plain;charset=utf-8'
});
@@ -127,7 +143,7 @@ export class RulesScreenComponent extends ComponentHasChanges {
if (file) {
fileReader.onload = () => {
- this.editorComponent.getEditor().setValue(fileReader.result);
+ this._codeEditor.getModel().setValue(fileReader.result as string);
this._fileInput.nativeElement.value = null;
};
fileReader.readAsText(file);
@@ -137,12 +153,10 @@ export class RulesScreenComponent extends ComponentHasChanges {
private _initialize() {
this._rulesControllerService.downloadRules(this._appStateService.activeRuleSetId).subscribe(
(rules) => {
- this.rules = rules.rules;
+ this.currentLines = this.initialLines = rules.rules.split('\n');
this.revert();
},
- () => {
- this.processing = false;
- }
+ () => (this.processing = false)
);
}
}
diff --git a/apps/red-ui/src/app/modules/projects/dialogs/dossier-dictionary-dialog/dossier-dictionary-dialog.component.html b/apps/red-ui/src/app/modules/projects/dialogs/dossier-dictionary-dialog/dossier-dictionary-dialog.component.html
index ed6607f78..2f61b1b69 100644
--- a/apps/red-ui/src/app/modules/projects/dialogs/dossier-dictionary-dialog/dossier-dictionary-dialog.component.html
+++ b/apps/red-ui/src/app/modules/projects/dialogs/dossier-dictionary-dialog/dossier-dictionary-dialog.component.html
@@ -7,7 +7,7 @@
#dictionaryManager
[withFloatingActions]="false"
[canEdit]="canEdit"
- [initialDictionaryEntries]="project.type?.entries"
+ [initialEntries]="project.type?.entries"
>
diff --git a/apps/red-ui/src/app/modules/projects/dialogs/dossier-dictionary-dialog/dossier-dictionary-dialog.component.ts b/apps/red-ui/src/app/modules/projects/dialogs/dossier-dictionary-dialog/dossier-dictionary-dialog.component.ts
index d07667e21..900fb9966 100644
--- a/apps/red-ui/src/app/modules/projects/dialogs/dossier-dictionary-dialog/dossier-dictionary-dialog.component.ts
+++ b/apps/red-ui/src/app/modules/projects/dialogs/dossier-dictionary-dialog/dossier-dictionary-dialog.component.ts
@@ -31,8 +31,8 @@ export class DossierDictionaryDialogComponent {
saveDossierDictionary() {
this._dictionarySaveService
.saveEntries(
- this._dictionaryManager.currentDictionaryEntries,
- this._dictionaryManager.initialDictionaryEntries,
+ this._dictionaryManager.currentEntries,
+ this._dictionaryManager.initialEntries,
this.project.ruleSetId,
'dossier_redaction',
this.project.projectId
diff --git a/apps/red-ui/src/app/modules/projects/dialogs/edit-project-dialog/dictionary/edit-project-dictionary.component.html b/apps/red-ui/src/app/modules/projects/dialogs/edit-project-dialog/dictionary/edit-project-dictionary.component.html
index 9a82a73a6..bc28e0f49 100644
--- a/apps/red-ui/src/app/modules/projects/dialogs/edit-project-dialog/dictionary/edit-project-dictionary.component.html
+++ b/apps/red-ui/src/app/modules/projects/dialogs/edit-project-dialog/dictionary/edit-project-dictionary.component.html
@@ -1,5 +1,5 @@
diff --git a/apps/red-ui/src/app/modules/projects/dialogs/edit-project-dialog/dictionary/edit-project-dictionary.component.ts b/apps/red-ui/src/app/modules/projects/dialogs/edit-project-dialog/dictionary/edit-project-dictionary.component.ts
index c7d014cb2..8c00c41f0 100644
--- a/apps/red-ui/src/app/modules/projects/dialogs/edit-project-dialog/dictionary/edit-project-dictionary.component.ts
+++ b/apps/red-ui/src/app/modules/projects/dialogs/edit-project-dialog/dictionary/edit-project-dictionary.component.ts
@@ -39,8 +39,8 @@ export class EditProjectDictionaryComponent implements EditProjectSectionInterfa
save() {
this._dictionarySaveService
.saveEntries(
- this._dictionaryManager.currentDictionaryEntries,
- this._dictionaryManager.initialDictionaryEntries,
+ this._dictionaryManager.currentEntries,
+ this._dictionaryManager.initialEntries,
this.projectWrapper.ruleSetId,
'dossier_redaction',
this.projectWrapper.projectId,
diff --git a/apps/red-ui/src/app/modules/shared/components/dictionary-manager/dictionary-manager.component.html b/apps/red-ui/src/app/modules/shared/components/dictionary-manager/dictionary-manager.component.html
index dcdd4db08..ada7c69d8 100644
--- a/apps/red-ui/src/app/modules/shared/components/dictionary-manager/dictionary-manager.component.html
+++ b/apps/red-ui/src/app/modules/shared/components/dictionary-manager/dictionary-manager.component.html
@@ -16,7 +16,7 @@