From 94f36a1494fb5bdbc764408edf2b7a4645ec8513 Mon Sep 17 00:00:00 2001 From: George Date: Mon, 24 Jul 2023 17:49:03 +0300 Subject: [PATCH] RED-6778, add dossier only toggle. --- .../add-edit-entity.component.html | 42 ++++++++-- .../add-edit-entity.component.scss | 24 ++++++ .../add-edit-entity.component.ts | 82 ++++++++++--------- .../src/app/modules/shared/shared.module.ts | 2 + apps/red-ui/src/assets/config/config.json | 12 +-- apps/red-ui/src/assets/i18n/redact/de.json | 7 +- apps/red-ui/src/assets/i18n/redact/en.json | 7 +- apps/red-ui/src/assets/i18n/scm/de.json | 7 +- apps/red-ui/src/assets/i18n/scm/en.json | 7 +- 9 files changed, 127 insertions(+), 63 deletions(-) diff --git a/apps/red-ui/src/app/modules/shared/components/add-edit-entity/add-edit-entity.component.html b/apps/red-ui/src/app/modules/shared/components/add-edit-entity/add-edit-entity.component.html index 85bc988ce..8514ad901 100644 --- a/apps/red-ui/src/app/modules/shared/components/add-edit-entity/add-edit-entity.component.html +++ b/apps/red-ui/src/app/modules/shared/components/add-edit-entity/add-edit-entity.component.html @@ -84,15 +84,39 @@ -
- - {{ 'add-edit-entity.form.case-sensitive' | translate }} - -
+
+ + + + {{ 'add-edit-entity.form.template-and-dossier-dictionaries' | translate }} + + + + {{ 'add-edit-entity.form.dossier-dictionary-only' | translate }} + + -
- - {{ 'add-edit-entity.form.add-to-dictionary-action' | translate }} - +
+ + {{ 'add-edit-entity.form.manage-entries-in-dictionary-editor-only' | translate }} + +
+
+ + {{ 'add-edit-entity.form.case-sensitive' | translate }} + +
diff --git a/apps/red-ui/src/app/modules/shared/components/add-edit-entity/add-edit-entity.component.scss b/apps/red-ui/src/app/modules/shared/components/add-edit-entity/add-edit-entity.component.scss index 38569f36f..0e294bf7c 100644 --- a/apps/red-ui/src/app/modules/shared/components/add-edit-entity/add-edit-entity.component.scss +++ b/apps/red-ui/src/app/modules/shared/components/add-edit-entity/add-edit-entity.component.scss @@ -9,3 +9,27 @@ margin-top: 0; } } + +.dictionary-extras { + margin-left: 38px; + margin-top: 14px; + + .round-checkbox-form-entry:first-of-type { + margin-bottom: 10px; + } +} + +.round-checkbox-form-entry { + display: flex; + gap: 8px; + margin-bottom: 20px; + user-select: none; +} + +.cursor-pointer { + cursor: pointer; +} + +.disabled { + opacity: 0.6; +} diff --git a/apps/red-ui/src/app/modules/shared/components/add-edit-entity/add-edit-entity.component.ts b/apps/red-ui/src/app/modules/shared/components/add-edit-entity/add-edit-entity.component.ts index 480198427..81ca1132b 100644 --- a/apps/red-ui/src/app/modules/shared/components/add-edit-entity/add-edit-entity.component.ts +++ b/apps/red-ui/src/app/modules/shared/components/add-edit-entity/add-edit-entity.component.ts @@ -9,6 +9,7 @@ import { PermissionsService } from '@services/permissions.service'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import { DictionaryService } from '@services/entity-services/dictionary.service'; import { BaseFormComponent, LoadingService, Toaster } from '@iqser/common-ui'; +import { Roles } from '@users/roles'; const REDACTION_FIELDS = ['defaultReason']; @@ -35,6 +36,7 @@ export class AddEditEntityComponent extends BaseFormComponent implements OnInit technicalName$: Observable; colors: Color[]; + readonly roles = Roles; constructor( private readonly _dictionariesMapService: DictionariesMapService, @@ -48,10 +50,6 @@ export class AddEditEntityComponent extends BaseFormComponent implements OnInit super(); } - cpDisabled(color: Color) { - return this.form.get(color.controlName).disabled; - } - get #isDossierRedaction(): boolean { return this.entity?.type === 'dossier_redaction'; } @@ -60,26 +58,34 @@ export class AddEditEntityComponent extends BaseFormComponent implements OnInit return !!this.entity?.systemManaged; } - get #addToDictionaryActionControl() { - return { value: !!this.entity?.addToDictionaryAction, disabled: this.#isSystemManaged && !this.#isDossierRedaction }; - } - get #isHint(): boolean { return !!this.form.get('hint')?.value; } + cpDisabled(color: Color) { + return this.form.get(color.controlName).disabled; + } + revert(): void { this.form.patchValue(this.initialFormValue); } ngOnInit() { - this._initializeForm(); + this.#initializeForm(); + } + + toggleDossierOnlyEntity() { + const propName = 'dossierDictionaryOnly'; + const control = this.form.get(propName); + if (control.disabled) { + return; + } + this.form.patchValue({ [propName]: !control?.value }); } async save(): Promise { this._loadingService.start(); - const dictionary = this._formToObject(); - + const dictionary = this.#formToObject(); try { if (this.entity) { // edit mode @@ -108,26 +114,26 @@ export class AddEditEntityComponent extends BaseFormComponent implements OnInit labelParams: () => ({ type: this.#isHint ? 'hint' : 'redaction' }), placeholder: _('add-edit-entity.form.color-placeholder'), controlName: 'hexColor', - hasColor$: this._colorEmpty$(form, 'hexColor'), + hasColor$: this.#colorEmpty$(form, 'hexColor'), }, { label: _('add-edit-entity.form.color'), labelParams: () => ({ type: 'recommendation' }), placeholder: _('add-edit-entity.form.color-placeholder'), controlName: 'recommendationHexColor', - hasColor$: this._colorEmpty$(form, 'recommendationHexColor'), + hasColor$: this.#colorEmpty$(form, 'recommendationHexColor'), }, { label: _('add-edit-entity.form.color'), labelParams: () => ({ type: this.#isHint ? 'ignored' : 'skipped' }), placeholder: _('add-edit-entity.form.color-placeholder'), controlName: 'skippedHexColor', - hasColor$: this._colorEmpty$(form, 'skippedHexColor'), + hasColor$: this.#colorEmpty$(form, 'skippedHexColor'), }, ]; } - private _initializeForm(): void { + #initializeForm(): void { let controlsConfig: Record = { label: [this.entity?.label, [Validators.required, Validators.minLength(3)]], hexColor: [this.entity?.hexColor, [Validators.required, Validators.minLength(7)]], @@ -143,26 +149,28 @@ export class AddEditEntityComponent extends BaseFormComponent implements OnInit rank: [{ value: this.entity?.rank, disabled: this.#isSystemManaged }, Validators.required], hint: [{ value: !!this.entity?.hint, disabled: this.#isSystemManaged }], hasDictionary: [{ value: !!this.entity?.hasDictionary, disabled: this.#isSystemManaged }], - caseSensitive: [{ value: this.entity ? !this.entity.caseInsensitive : false, disabled: this.#isSystemManaged }], + dossierDictionaryOnly: [{ value: !!this.entity?.dossierDictionaryOnly, disabled: this.#isSystemManaged || this.entity }], + caseSensitive: [{ value: !!this.entity?.caseInsensitive, disabled: this.#isSystemManaged }], + manageEntriesInDictionaryEditorOnly: [ + { + value: !this.entity?.addToDictionaryAction, + disabled: this.#isSystemManaged && !this.#isDossierRedaction, + }, + ], }; } if (!this.entity?.hint && !this.#isDossierRedaction) { - Object.assign(controlsConfig, { + controlsConfig = { + ...controlsConfig, defaultReason: [{ value: null, disabled: true }], - }); - } - - if (this.entity?.hasDictionary || this.#isDossierRedaction) { - Object.assign(controlsConfig, { - addToDictionaryAction: [this.#addToDictionaryActionControl], - }); + }; } const form = this._formBuilder.group(controlsConfig); this.#initializeColors(form); - this.technicalName$ = form.get('label').valueChanges.pipe(map((value: string) => this._toTechnicalName(value))); + this.technicalName$ = form.get('label').valueChanges.pipe(map((value: string) => this.#toTechnicalName(value))); if (!this.#isDossierRedaction) { form.get('hint').valueChanges.subscribe(isHint => { @@ -173,17 +181,9 @@ export class AddEditEntityComponent extends BaseFormComponent implements OnInit } }); - form.get('hasDictionary').valueChanges.subscribe(hasDictionary => { - if (hasDictionary) { - form.addControl('addToDictionaryAction', new UntypedFormControl(this.#addToDictionaryActionControl)); - } else { - form.removeControl('addToDictionaryAction'); - } - }); - if (!this.entity) { form.get('label').valueChanges.subscribe((label: string) => { - form.get('type').setValue(this._toTechnicalName(label)); + form.get('type').setValue(this.#toTechnicalName(label)); }); } } @@ -197,7 +197,7 @@ export class AddEditEntityComponent extends BaseFormComponent implements OnInit this.form = form; } - private _toTechnicalName(value: string) { + #toTechnicalName(value: string) { const existingTechnicalNames = this._dictionariesMapService.get(this.dossierTemplateId).map(dict => dict.type); const baseTechnicalName = toSnakeCase(value.trim()); let technicalName = baseTechnicalName.replaceAll(/[^A-Za-z0-9_-]/g, ''); @@ -211,19 +211,20 @@ export class AddEditEntityComponent extends BaseFormComponent implements OnInit return technicalName; } - private _colorEmpty$(form: UntypedFormGroup, field: string) { + #colorEmpty$(form: UntypedFormGroup, field: string) { return form.get(field).valueChanges.pipe( startWith(form.get(field).value), map((value: string) => !value || value?.length === 0), ); } - private _formToObject(): IDictionary { + #formToObject(): IDictionary { // Fields which aren't set for hints, need additional check - const addToDictionaryAction = !!this.form.get('addToDictionaryAction')?.value; + const addToDictionaryAction = !this.form.get('manageEntriesInDictionaryEditorOnly')?.value; const hasDictionary = !!this.form.get('hasDictionary')?.value; + const dossierDictionaryOnly = !!this.form.get('dossierDictionaryOnly')?.value; - let entity = { + const entity = { ...this.entity, label: this.form.get('label').value, hexColor: this.form.get('hexColor').value, @@ -231,10 +232,11 @@ export class AddEditEntityComponent extends BaseFormComponent implements OnInit skippedHexColor: this.form.get('skippedHexColor').value, dossierTemplateId: this.dossierTemplateId, addToDictionaryAction, + dossierDictionaryOnly, }; if (this.entity?.type !== 'dossier_redaction') { - entity = { + return { ...entity, type: this.form.get('type').value, description: this.form.get('description').value, diff --git a/apps/red-ui/src/app/modules/shared/shared.module.ts b/apps/red-ui/src/app/modules/shared/shared.module.ts index b1919ca5b..104cc7c10 100644 --- a/apps/red-ui/src/app/modules/shared/shared.module.ts +++ b/apps/red-ui/src/app/modules/shared/shared.module.ts @@ -15,6 +15,7 @@ import { IqserAllowDirective, IqserDenyDirective, IqserHelpModeModule, + RoundCheckboxComponent, StopPropagationDirective, } from '@iqser/common-ui'; import { NavigateLastDossiersScreenDirective } from './directives/navigate-last-dossiers-screen.directive'; @@ -98,6 +99,7 @@ const deleteThisWhenAllComponentsAreStandalone = [DonutChartComponent]; IqserAllowDirective, IqserDenyDirective, SelectComponent, + RoundCheckboxComponent, ], exports: [...modules, ...components, ...utils, ...deleteThisWhenAllComponentsAreStandalone], providers: [ diff --git a/apps/red-ui/src/assets/config/config.json b/apps/red-ui/src/assets/config/config.json index 280ef08c2..9734775ed 100644 --- a/apps/red-ui/src/assets/config/config.json +++ b/apps/red-ui/src/assets/config/config.json @@ -1,9 +1,9 @@ { "ADMIN_CONTACT_NAME": null, "ADMIN_CONTACT_URL": null, - "API_URL": "https://dev-04.iqser.cloud", - "APP_NAME": "DocuMine", - "IS_DOCUMINE": true, + "API_URL": "https://dan.iqser.cloud", + "APP_NAME": "RedactManager", + "IS_DOCUMINE": false, "AUTO_READ_TIME": 3, "BACKEND_APP_VERSION": "4.4.40", "EULA_URL": "EULA_URL", @@ -12,13 +12,13 @@ "MAX_RETRIES_ON_SERVER_ERROR": 3, "OAUTH_CLIENT_ID": "redaction", "OAUTH_IDP_HINT": null, - "OAUTH_URL": "https://dev-04.iqser.cloud/auth", + "OAUTH_URL": "https://dan.iqser.cloud/auth", "RECENT_PERIOD_IN_HOURS": 24, "SELECTION_MODE": "structural", "MANUAL_BASE_URL": "https://docs.redactmanager.com/preview", "ANNOTATIONS_THRESHOLD": 1000, - "THEME": "scm", - "BASE_TRANSLATIONS_DIRECTORY": "/assets/i18n/scm/", + "THEME": "redact", + "BASE_TRANSLATIONS_DIRECTORY": "/assets/i18n/redact/", "AVAILABLE_NOTIFICATIONS_DAYS": 30, "AVAILABLE_OLD_NOTIFICATIONS_MINUTES": 60, "NOTIFICATIONS_THRESHOLD": 1000, diff --git a/apps/red-ui/src/assets/i18n/redact/de.json b/apps/red-ui/src/assets/i18n/redact/de.json index 5004a0238..51474b85a 100644 --- a/apps/red-ui/src/assets/i18n/redact/de.json +++ b/apps/red-ui/src/assets/i18n/redact/de.json @@ -118,7 +118,6 @@ "invalid-color-or-rank": "" }, "form": { - "add-to-dictionary-action": "", "case-sensitive": "", "color": "", "color-placeholder": "", @@ -126,15 +125,19 @@ "default-reason-placeholder": "", "description": "", "description-placeholder": "", + "dossier-dictionary-only": "", "has-dictionary": "", "hint": "", + "linked-to-global-entity": "", + "manage-entries-in-dictionary-editor-only": "", "name": "", "name-placeholder": "", "rank": "", "rank-placeholder": "", "redaction": "", "technical-name": "", - "technical-name-hint": "" + "technical-name-hint": "", + "template-and-dossier-dictionaries": "" }, "success": { "create": "", diff --git a/apps/red-ui/src/assets/i18n/redact/en.json b/apps/red-ui/src/assets/i18n/redact/en.json index 47451d760..3e3de999f 100644 --- a/apps/red-ui/src/assets/i18n/redact/en.json +++ b/apps/red-ui/src/assets/i18n/redact/en.json @@ -118,7 +118,6 @@ "invalid-color-or-rank": "Invalid color or rank! Rank is already used by another entity or the color is not a valid hexColor!" }, "form": { - "add-to-dictionary-action": "Enable 'Add to dictionary'", "case-sensitive": "Case Sensitive", "color": "{type, select, redaction{Redaction} hint{Hint} recommendation{Recommendation} skipped{Skipped Redaction} ignored{Ignored Hint} other{}} Color", "color-placeholder": "#", @@ -126,15 +125,19 @@ "default-reason-placeholder": "No Default Reason", "description": "Description", "description-placeholder": "Enter Description", + "dossier-dictionary-only": "Dossier dictionary only", "has-dictionary": "Has dictionary", "hint": "Hint", + "linked-to-global-entity": "Linked to global entity", + "manage-entries-in-dictionary-editor-only": "Manage entries in Dictionary editor only", "name": "Display Name", "name-placeholder": "Enter Name", "rank": "Rank", "rank-placeholder": "1000", "redaction": "Redaction", "technical-name": "Technical Name", - "technical-name-hint": "{type, select, edit{Autogenerated based on the initial display name.} create{Autogenerates based on the display name and cannot be edited after saving.} other{}}" + "technical-name-hint": "{type, select, edit{Autogenerated based on the initial display name.} create{Autogenerates based on the display name and cannot be edited after saving.} other{}}", + "template-and-dossier-dictionaries": "Template & dossier dictionaries" }, "success": { "create": "Entity added!", diff --git a/apps/red-ui/src/assets/i18n/scm/de.json b/apps/red-ui/src/assets/i18n/scm/de.json index d0b7d4164..9c4ff5b64 100644 --- a/apps/red-ui/src/assets/i18n/scm/de.json +++ b/apps/red-ui/src/assets/i18n/scm/de.json @@ -118,7 +118,6 @@ "invalid-color-or-rank": "" }, "form": { - "add-to-dictionary-action": "", "case-sensitive": "", "color": "", "color-placeholder": "", @@ -126,15 +125,19 @@ "default-reason-placeholder": "", "description": "", "description-placeholder": "", + "dossier-dictionary-only": "", "has-dictionary": "", "hint": "", + "linked-to-global-entity": "", + "manage-entries-in-dictionary-editor-only": "", "name": "", "name-placeholder": "", "rank": "", "rank-placeholder": "", "redaction": "", "technical-name": "", - "technical-name-hint": "" + "technical-name-hint": "", + "template-and-dossier-dictionaries": "" }, "success": { "create": "", diff --git a/apps/red-ui/src/assets/i18n/scm/en.json b/apps/red-ui/src/assets/i18n/scm/en.json index f1885e2b9..9dbe556f9 100644 --- a/apps/red-ui/src/assets/i18n/scm/en.json +++ b/apps/red-ui/src/assets/i18n/scm/en.json @@ -118,7 +118,6 @@ "invalid-color-or-rank": "Invalid color or rank! Rank is already used by another entity or the color is not a valid hexColor!" }, "form": { - "add-to-dictionary-action": "Enable 'Add to dictionary'", "case-sensitive": "Case Sensitive", "color": "{type, select, redaction{Component} hint{Hint} recommendation{Recommendation} skipped{Skipped Component} ignored{Ignored Hint} other{}} Color", "color-placeholder": "#", @@ -126,15 +125,19 @@ "default-reason-placeholder": "No Default Reason", "description": "Description", "description-placeholder": "Enter Description", + "dossier-dictionary-only": "", "has-dictionary": "Has dictionary", "hint": "Hint", + "linked-to-global-entity": "", + "manage-entries-in-dictionary-editor-only": "", "name": "Display Name", "name-placeholder": "Enter Name", "rank": "Rank", "rank-placeholder": "1000", "redaction": "Component", "technical-name": "Technical Name", - "technical-name-hint": "{type, select, edit{Autogenerated based on the initial display name.} create{Autogenerates based on the display name and cannot be edited after saving.} other{}}" + "technical-name-hint": "{type, select, edit{Autogenerated based on the initial display name.} create{Autogenerates based on the display name and cannot be edited after saving.} other{}}", + "template-and-dossier-dictionaries": "" }, "success": { "create": "Entity added!",