From d125fe5ff921c7d8798182e436b97534a8312fc7 Mon Sep 17 00:00:00 2001 From: swapnil-verma-gl <92505353+swapnil-verma-gl@users.noreply.github.com> Date: Tue, 6 Jun 2023 14:02:19 +0530 Subject: [PATCH] [ACS-5088] Replaced function calls in templates with variable references (#3227) * [ACS-5088] Replaced method calls in templates with variables * [ACS-5088] Replaced method calls in templates with variables * [ACS-5088] Replaced method calls for *ngIf and *ngFor with variables - Batch 1 (WIP) * [ACS-5088] Replaced method calls for *ngIf and *ngFor with variables - Batch 2 (WIP) * [ACS-5088] Replaced instances of $any with cast pipe. Replaced other instances of method calls in templates with variables * [ACS-5088] Resolved test cases * [ACS-5088] Resolved test cases in aca-content library * [ACS-5088] Resolved test cases in aca-shared library * [ACS-5088] Resolved test cases in aca-folder-rules library * [ACS-5088] Reverted usage of cast pipe to $any() * [ACS-5088] Fixed incorrect revert * [ACS-5088] Resolved code review findings - shortened expressions and made onDestroy subjects use void instead of boolean * [ACS-5088] Resolved code review findings - changed parameter name in sort function * [ACS-5088] Resolved code review findings - added 'void' type to onDestroy subjects * [ACS-5088] Upgraded eslint version to 8.41.0. Added "@angular-eslint/template/no-call-expression" rule to prevent function calls in templates unless needed (reports warnings) * [ACS-5088] Resolved typo in ToggleFavoriteComponent --- .eslintrc.json | 4 +- .../toggle-shared.component.html | 12 ++-- .../toggle-shared.component.spec.ts | 8 +-- .../toggle-shared/toggle-shared.component.ts | 34 +++++---- .../name-column/name-column.component.ts | 17 ++--- .../tags-column/tags-column.component.ts | 15 ++-- .../lib/components/files/files.component.html | 2 +- .../lib/components/files/files.component.ts | 7 +- .../comments-tab.component.spec.ts | 8 ++- .../comments-tab/comments-tab.component.ts | 14 ++-- .../library-metadata-form.component.html | 2 +- .../library-metadata-form.component.ts | 9 ++- .../metadata-tab.component.spec.ts | 17 +++-- .../metadata-tab/metadata-tab.component.ts | 13 ++-- .../search-input/search-input.component.html | 2 +- .../search-input.component.spec.ts | 4 +- .../search-input/search-input.component.ts | 7 +- .../search-libraries-results.component.html | 2 +- .../search-results-row.component.ts | 7 +- .../search-results.component.html | 2 +- .../search-results.component.ts | 9 +++ .../components/button-menu.component.html | 2 +- .../document-display-mode.component.spec.ts | 16 +++-- .../document-display-mode.component.ts | 28 +++++--- .../toggle-edit-offline.component.ts | 14 ++-- .../view-profile/view-profile.component.html | 6 +- .../create-from-template.dialog.html | 2 +- .../create-from-template.dialog.ts | 15 ++-- .../manage-rules.smart-component.html | 6 +- .../manage-rules.smart-component.ts | 28 +++++--- .../rule-action-list.ui-component.html | 2 +- .../actions/rule-action-list.ui-component.ts | 7 +- .../actions/rule-action.ui-component.html | 2 +- .../actions/rule-action.ui-component.scss | 4 ++ .../actions/rule-action.ui-component.ts | 36 +++++----- ...rule-composite-condition.ui-component.html | 8 +-- .../rule-composite-condition.ui-component.ts | 41 +++++------ .../edit-rule-dialog.ui-component.ts | 12 +--- .../options/rule-options.ui-component.html | 6 +- .../options/rule-options.ui-component.ts | 22 +++--- .../rule-details.ui-component.html | 10 +-- .../rule-details/rule-details.ui-component.ts | 70 ++++++------------- .../triggers/rule-triggers.ui-component.html | 4 +- .../triggers/rule-triggers.ui-component.ts | 15 ++-- .../rule-list-grouping.ui-component.html | 2 +- .../rule-set-picker.smart-component.html | 4 +- .../rule-set-picker.smart-component.ts | 22 ++++-- .../lib/services/folder-rule-sets.service.ts | 4 +- .../src/lib/services/folder-rules.service.ts | 2 +- .../locked-by/locked-by.component.spec.ts | 2 +- .../locked-by/locked-by.component.ts | 10 +-- .../toolbar-menu/toolbar-menu.component.ts | 12 ++-- 52 files changed, 313 insertions(+), 296 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 2ad07cd96e..86accfe7ae 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -315,10 +315,12 @@ "*.html" ], "extends": ["plugin:@nrwl/nx/angular-template", "plugin:@angular-eslint/template/accessibility"], + "parser": "@angular-eslint/template-parser", "rules": { "@angular-eslint/template/no-negated-async": "off", "@angular-eslint/template/no-positive-tabindex": "error", - "@angular-eslint/template/eqeqeq": "error" + "@angular-eslint/template/eqeqeq": "error", + "@angular-eslint/template/no-call-expression": "warn" } }, { diff --git a/projects/aca-content/src/lib/components/common/toggle-shared/toggle-shared.component.html b/projects/aca-content/src/lib/components/common/toggle-shared/toggle-shared.component.html index 8721a52cff..ba165602cd 100644 --- a/projects/aca-content/src/lib/components/common/toggle-shared/toggle-shared.component.html +++ b/projects/aca-content/src/lib/components/common/toggle-shared/toggle-shared.component.html @@ -1,8 +1,8 @@ - + - @@ -12,9 +12,9 @@ - @@ -92,7 +92,7 @@

{{'APP.EDIT_PROFILE.COMPANY_DETAILS' | translate}}
-
@@ -142,4 +142,4 @@

{{'APP.EDIT_PROFILE.EMAIL' | tr - \ No newline at end of file + diff --git a/projects/aca-content/src/lib/dialogs/node-template/create-from-template.dialog.html b/projects/aca-content/src/lib/dialogs/node-template/create-from-template.dialog.html index 7fc0a9b551..993f504035 100644 --- a/projects/aca-content/src/lib/dialogs/node-template/create-from-template.dialog.html +++ b/projects/aca-content/src/lib/dialogs/node-template/create-from-template.dialog.html @@ -1,4 +1,4 @@ -

+

diff --git a/projects/aca-content/src/lib/dialogs/node-template/create-from-template.dialog.ts b/projects/aca-content/src/lib/dialogs/node-template/create-from-template.dialog.ts index a273b86270..7df6e8ee0d 100644 --- a/projects/aca-content/src/lib/dialogs/node-template/create-from-template.dialog.ts +++ b/projects/aca-content/src/lib/dialogs/node-template/create-from-template.dialog.ts @@ -45,6 +45,8 @@ import { MatButtonModule } from '@angular/material/button'; export class CreateFromTemplateDialogComponent implements OnInit { public form: UntypedFormGroup; + title = ''; + constructor( private translationService: TranslationService, private store: Store, @@ -59,6 +61,11 @@ export class CreateFromTemplateDialogComponent implements OnInit { title: [this.data.properties ? this.data.properties['cm:title'] : '', Validators.maxLength(256)], description: [this.data.properties ? this.data.properties['cm:description'] : '', Validators.maxLength(512)] }); + + this.title = this.translationService.instant( + this.data.isFolder ? 'NODE_FROM_TEMPLATE.FOLDER_DIALOG_TITLE' : 'NODE_FROM_TEMPLATE.FILE_DIALOG_TITLE', + { template: this.data.name } + ); } onSubmit() { @@ -73,14 +80,6 @@ export class CreateFromTemplateDialogComponent implements OnInit { this.store.dispatch(new CreateFromTemplate(data)); } - title(): string { - if (this.data.isFolder) { - return this.translationService.instant('NODE_FROM_TEMPLATE.FOLDER_DIALOG_TITLE', { template: this.data.name }); - } - - return this.translationService.instant('NODE_FROM_TEMPLATE.FILE_DIALOG_TITLE', { template: this.data.name }); - } - close() { this.dialogRef.close(); } diff --git a/projects/aca-folder-rules/src/lib/manage-rules/manage-rules.smart-component.html b/projects/aca-folder-rules/src/lib/manage-rules/manage-rules.smart-component.html index a5451562c7..35144a0754 100644 --- a/projects/aca-folder-rules/src/lib/manage-rules/manage-rules.smart-component.html +++ b/projects/aca-folder-rules/src/lib/manage-rules/manage-rules.smart-component.html @@ -47,7 +47,7 @@ diff --git a/projects/aca-folder-rules/src/lib/manage-rules/manage-rules.smart-component.ts b/projects/aca-folder-rules/src/lib/manage-rules/manage-rules.smart-component.ts index 47ff67a375..a2a570f952 100644 --- a/projects/aca-folder-rules/src/lib/manage-rules/manage-rules.smart-component.ts +++ b/projects/aca-folder-rules/src/lib/manage-rules/manage-rules.smart-component.ts @@ -22,7 +22,7 @@ * from Hyland Software. If not, see . */ -import { Component, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core'; +import { ChangeDetectionStrategy, Component, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core'; import { Location } from '@angular/common'; import { FolderRulesService } from '../services/folder-rules.service'; import { Observable, Subject, Subscription } from 'rxjs'; @@ -47,6 +47,7 @@ import { ActionParameterConstraint } from '../model/action-parameter-constraint. templateUrl: 'manage-rules.smart-component.html', styleUrls: ['manage-rules.smart-component.scss'], encapsulation: ViewEncapsulation.None, + changeDetection: ChangeDetectionStrategy.Default, host: { class: 'aca-manage-rules' } }) export class ManageRulesSmartComponent implements OnInit, OnDestroy { @@ -65,6 +66,10 @@ export class ManageRulesSmartComponent implements OnInit, OnDestroy { actionsLoading$: Observable; actionDefinitions$: Observable; parameterConstraints$: Observable; + canEditMainRule = false; + canEditSelectedRule = false; + isMainRuleSetNotEmpty = false; + isInheritedRuleSetsNotEmpty = false; private destroyed$ = new Subject(); private _actionDefinitionsSub: Subscription; @@ -110,6 +115,19 @@ export class ManageRulesSmartComponent implements OnInit, OnDestroy { this._actionDefinitionsSub = this.actionDefinitions$.subscribe((actionDefinitions: ActionDefinitionTransformed[]) => this.actionsService.loadActionParameterConstraints(actionDefinitions) ); + + this.mainRuleSet$.pipe(takeUntil(this.destroyed$)).subscribe((ruleSet) => { + this.canEditMainRule = this.canEditRule(ruleSet); + this.isMainRuleSetNotEmpty = !!ruleSet; + }); + + this.inheritedRuleSets$.pipe(takeUntil(this.destroyed$)).subscribe((inheritedRuleSet) => { + this.isInheritedRuleSetsNotEmpty = inheritedRuleSet.some((ruleSet) => ruleSet.rules.some((rule: Rule) => rule.isEnabled)); + }); + + this.selectedRuleSet$.pipe(takeUntil(this.destroyed$)).subscribe((ruleSet) => { + this.canEditSelectedRule = this.canEditRule(ruleSet); + }); } ngOnDestroy() { @@ -251,12 +269,4 @@ export class ManageRulesSmartComponent implements OnInit, OnDestroy { } }); } - - isMainRuleSetNotEmpty(mainRuleSet: RuleSet): boolean { - return !!mainRuleSet; - } - - isInheritedRuleSetsNotEmpty(inheritedRuleSets: RuleSet[]): boolean { - return inheritedRuleSets.some((ruleSet) => ruleSet.rules.some((rule: Rule) => rule.isEnabled)); - } } diff --git a/projects/aca-folder-rules/src/lib/rule-details/actions/rule-action-list.ui-component.html b/projects/aca-folder-rules/src/lib/rule-details/actions/rule-action-list.ui-component.html index 071dae114f..1af5b6d3b5 100644 --- a/projects/aca-folder-rules/src/lib/rule-details/actions/rule-action-list.ui-component.html +++ b/projects/aca-folder-rules/src/lib/rule-details/actions/rule-action-list.ui-component.html @@ -19,7 +19,7 @@ mat-menu-item data-automation-id="rule-action-list-remove-action-button" [title]="'ACA_FOLDER_RULES.RULE_DETAILS.ACTION_BUTTONS.REMOVE' | translate" - [disabled]="formArray.controls.length <= 1" + [disabled]="formControls.length <= 1" (click)="removeAction(control)"> delete {{ 'ACA_FOLDER_RULES.RULE_DETAILS.ACTION_BUTTONS.REMOVE' | translate }} diff --git a/projects/aca-folder-rules/src/lib/rule-details/actions/rule-action-list.ui-component.ts b/projects/aca-folder-rules/src/lib/rule-details/actions/rule-action-list.ui-component.ts index 853557982c..7c5bca6e6c 100644 --- a/projects/aca-folder-rules/src/lib/rule-details/actions/rule-action-list.ui-component.ts +++ b/projects/aca-folder-rules/src/lib/rule-details/actions/rule-action-list.ui-component.ts @@ -56,9 +56,7 @@ export class RuleActionListUiComponent implements ControlValueAccessor, OnDestro formArray = new FormArray([]); private formArraySubscription: Subscription; - get formControls(): FormControl[] { - return this.formArray.controls as FormControl[]; - } + formControls: FormControl[] = []; onChange: (actions: RuleAction[]) => void = () => undefined; onTouch: () => void = () => undefined; @@ -73,6 +71,7 @@ export class RuleActionListUiComponent implements ControlValueAccessor, OnDestro ]; } this.formArray = new FormArray(actions.map((action: RuleAction) => new FormControl(action))); + this.formControls = this.formArray.controls as FormControl[]; this.formArraySubscription?.unsubscribe(); this.formArraySubscription = this.formArray.valueChanges.subscribe((value: any) => { this.onChange(value); @@ -94,6 +93,7 @@ export class RuleActionListUiComponent implements ControlValueAccessor, OnDestro params: {} }; this.formArray.push(new FormControl(newAction, [Validators.required, ruleActionValidator(this.actionDefinitions)])); + this.formControls = this.formArray.controls as FormControl[]; } ngOnDestroy() { @@ -103,5 +103,6 @@ export class RuleActionListUiComponent implements ControlValueAccessor, OnDestro removeAction(control: FormControl) { const index = this.formArray.value.indexOf(control.value); this.formArray.removeAt(index); + this.formControls = this.formArray.controls as FormControl[]; } } diff --git a/projects/aca-folder-rules/src/lib/rule-details/actions/rule-action.ui-component.html b/projects/aca-folder-rules/src/lib/rule-details/actions/rule-action.ui-component.html index 5a8be2c76a..32119eb02b 100644 --- a/projects/aca-folder-rules/src/lib/rule-details/actions/rule-action.ui-component.html +++ b/projects/aca-folder-rules/src/lib/rule-details/actions/rule-action.ui-component.html @@ -16,7 +16,7 @@ diff --git a/projects/aca-folder-rules/src/lib/rule-details/actions/rule-action.ui-component.scss b/projects/aca-folder-rules/src/lib/rule-details/actions/rule-action.ui-component.scss index b34ac6879e..51598a840f 100644 --- a/projects/aca-folder-rules/src/lib/rule-details/actions/rule-action.ui-component.scss +++ b/projects/aca-folder-rules/src/lib/rule-details/actions/rule-action.ui-component.scss @@ -8,4 +8,8 @@ width: 280px; } } + + &-full-width { + width: 100%; + } } diff --git a/projects/aca-folder-rules/src/lib/rule-details/actions/rule-action.ui-component.ts b/projects/aca-folder-rules/src/lib/rule-details/actions/rule-action.ui-component.ts index 5094e279cc..1eba93faab 100644 --- a/projects/aca-folder-rules/src/lib/rule-details/actions/rule-action.ui-component.ts +++ b/projects/aca-folder-rules/src/lib/rule-details/actions/rule-action.ui-component.ts @@ -22,7 +22,7 @@ * from Hyland Software. If not, see . */ -import { Component, forwardRef, Input, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core'; +import { Component, forwardRef, Input, OnChanges, OnDestroy, OnInit, SimpleChanges, ViewEncapsulation } from '@angular/core'; import { ControlValueAccessor, FormControl, FormGroup, NG_VALUE_ACCESSOR, Validators } from '@angular/forms'; import { ActionDefinitionTransformed, RuleAction } from '../../model/rule-action.model'; import { CardViewItem } from '@alfresco/adf-core/lib/card-view/interfaces/card-view-item.interface'; @@ -57,27 +57,15 @@ import { TranslateService } from '@ngx-translate/core'; CardViewUpdateService ] }) -export class RuleActionUiComponent implements ControlValueAccessor, OnInit, OnDestroy { +export class RuleActionUiComponent implements ControlValueAccessor, OnInit, OnChanges, OnDestroy { @Input() nodeId = ''; - private _actionDefinitions: ActionDefinitionTransformed[]; @Input() - get actionDefinitions(): ActionDefinitionTransformed[] { - return this._actionDefinitions; - } - set actionDefinitions(value: ActionDefinitionTransformed[]) { - this._actionDefinitions = value.sort((a, b) => a.title.localeCompare(b.title)); - } + actionDefinitions: ActionDefinitionTransformed[]; - private _readOnly = false; @Input() - get readOnly(): boolean { - return this._readOnly; - } - set readOnly(isReadOnly: boolean) { - this.setDisabledState(isReadOnly); - } + readOnly = false; private _parameterConstraints = []; @Input() @@ -135,6 +123,10 @@ export class RuleActionUiComponent implements ControlValueAccessor, OnInit, OnDe } ngOnInit() { + this.actionDefinitions = this.actionDefinitions.sort((firstActionDefinition, secondActionDefinition) => + firstActionDefinition.title.localeCompare(secondActionDefinition.title) + ); + this.form.valueChanges.pipe(takeUntil(this.onDestroy$)).subscribe(() => { this.setDefaultParameters(); this.setCardViewProperties(); @@ -158,6 +150,14 @@ export class RuleActionUiComponent implements ControlValueAccessor, OnInit, OnDe }); } + ngOnChanges(changes: SimpleChanges): void { + const readOnly = changes['readOnly']?.currentValue; + if (readOnly !== undefined && readOnly !== null) { + this.readOnly = readOnly; + this.setDisabledState(readOnly); + } + } + ngOnDestroy() { this.onDestroy$.next(); this.onDestroy$.complete(); @@ -272,10 +272,10 @@ export class RuleActionUiComponent implements ControlValueAccessor, OnInit, OnDe setDisabledState(isDisabled: boolean) { if (isDisabled) { - this._readOnly = true; + this.readOnly = true; this.form.disable(); } else { - this._readOnly = false; + this.readOnly = false; this.form.enable(); } } diff --git a/projects/aca-folder-rules/src/lib/rule-details/conditions/rule-composite-condition.ui-component.html b/projects/aca-folder-rules/src/lib/rule-details/conditions/rule-composite-condition.ui-component.html index 4cea158ebf..ab2e23dff4 100644 --- a/projects/aca-folder-rules/src/lib/rule-details/conditions/rule-composite-condition.ui-component.html +++ b/projects/aca-folder-rules/src/lib/rule-details/conditions/rule-composite-condition.ui-component.html @@ -9,9 +9,8 @@ + [formControl]="invertedControl" + [disabled]="readOnly"> {{ 'ACA_FOLDER_RULES.RULE_DETAILS.LOGIC_OPERATORS.IF' | translate }} {{ 'ACA_FOLDER_RULES.RULE_DETAILS.LOGIC_OPERATORS.NOT_IF' | translate }} @@ -19,9 +18,8 @@ + [formControl]="booleanModeControl"> {{ 'ACA_FOLDER_RULES.RULE_DETAILS.LOGIC_OPERATORS.AND' | translate }} {{ 'ACA_FOLDER_RULES.RULE_DETAILS.LOGIC_OPERATORS.OR' | translate }} diff --git a/projects/aca-folder-rules/src/lib/rule-details/conditions/rule-composite-condition.ui-component.ts b/projects/aca-folder-rules/src/lib/rule-details/conditions/rule-composite-condition.ui-component.ts index f3f061c1d6..f53d588314 100644 --- a/projects/aca-folder-rules/src/lib/rule-details/conditions/rule-composite-condition.ui-component.ts +++ b/projects/aca-folder-rules/src/lib/rule-details/conditions/rule-composite-condition.ui-component.ts @@ -22,7 +22,7 @@ * from Hyland Software. If not, see . */ -import { Component, forwardRef, HostBinding, Input, OnDestroy, ViewEncapsulation } from '@angular/core'; +import { Component, forwardRef, HostBinding, Input, OnChanges, OnDestroy, SimpleChanges, ViewEncapsulation } from '@angular/core'; import { RuleCompositeCondition } from '../../model/rule-composite-condition.model'; import { ControlValueAccessor, FormArray, FormControl, FormGroup, NG_VALUE_ACCESSOR } from '@angular/forms'; import { RuleSimpleCondition } from '../../model/rule-simple-condition.model'; @@ -41,7 +41,7 @@ import { RuleSimpleCondition } from '../../model/rule-simple-condition.model'; } ] }) -export class RuleCompositeConditionUiComponent implements ControlValueAccessor, OnDestroy { +export class RuleCompositeConditionUiComponent implements ControlValueAccessor, OnDestroy, OnChanges { @HostBinding('class.secondaryBackground') @Input() secondaryBackground = false; @@ -58,26 +58,17 @@ export class RuleCompositeConditionUiComponent implements ControlValueAccessor, readonly isOrImplemented = false; - private _readOnly = false; @Input() - get readOnly(): boolean { - return this._readOnly; - } - set readOnly(isReadOnly: boolean) { - this.setDisabledState(isReadOnly); - } + public readOnly = false; private formSubscription = this.form.valueChanges.subscribe((value: any) => { this.onChange(value); this.onTouch(); }); - get invertedControl(): FormControl { - return this.form.get('inverted') as FormControl; - } - get booleanModeControl(): FormControl { - return this.form.get('booleanMode') as FormControl; - } + public invertedControl = this.form.get('inverted') as FormControl; + public booleanModeControl = this.form.get('booleanMode') as FormControl; + get compositeConditionsFormArray(): FormArray { return this.form.get('compositeConditions') as FormArray; } @@ -111,22 +102,14 @@ export class RuleCompositeConditionUiComponent implements ControlValueAccessor, setDisabledState(isDisabled: boolean) { if (isDisabled) { - this._readOnly = true; + this.readOnly = true; this.form.disable(); } else { - this._readOnly = false; + this.readOnly = false; this.form.enable(); } } - setInverted(value: boolean) { - this.invertedControl.setValue(value); - } - - setBooleanMode(value: 'and' | 'or') { - this.booleanModeControl.setValue(value); - } - isFormControlSimpleCondition(control: FormControl): boolean { // eslint-disable-next-line no-prototype-builtins return control.value.hasOwnProperty('field'); @@ -160,4 +143,12 @@ export class RuleCompositeConditionUiComponent implements ControlValueAccessor, ngOnDestroy() { this.formSubscription.unsubscribe(); } + + ngOnChanges(changes: SimpleChanges): void { + const readOnly = changes['readOnly'].currentValue; + if (readOnly !== undefined && readOnly !== null) { + this.readOnly = readOnly; + this.setDisabledState(readOnly); + } + } } diff --git a/projects/aca-folder-rules/src/lib/rule-details/edit-rule-dialog.ui-component.ts b/projects/aca-folder-rules/src/lib/rule-details/edit-rule-dialog.ui-component.ts index a7a6e75ccb..d5948842c0 100644 --- a/projects/aca-folder-rules/src/lib/rule-details/edit-rule-dialog.ui-component.ts +++ b/projects/aca-folder-rules/src/lib/rule-details/edit-rule-dialog.ui-component.ts @@ -52,6 +52,9 @@ export class EditRuleDialogUiComponent { formValue: Partial; @Output() submitted = new EventEmitter>(); + title = 'ACA_FOLDER_RULES.EDIT_RULE_DIALOG.' + (this.isUpdateMode ? 'UPDATE_TITLE' : 'CREATE_TITLE'); + submitLabel = 'ACA_FOLDER_RULES.EDIT_RULE_DIALOG.' + (this.isUpdateMode ? 'UPDATE' : 'CREATE'); + constructor(@Inject(MAT_DIALOG_DATA) public data: EditRuleDialogOptions) { this.model = this.data?.model || {}; this.nodeId = this.data?.nodeId; @@ -62,15 +65,6 @@ export class EditRuleDialogUiComponent { get isUpdateMode(): boolean { return !!this.data?.model?.id; } - - get title(): string { - return 'ACA_FOLDER_RULES.EDIT_RULE_DIALOG.' + (this.isUpdateMode ? 'UPDATE_TITLE' : 'CREATE_TITLE'); - } - - get submitLabel(): string { - return 'ACA_FOLDER_RULES.EDIT_RULE_DIALOG.' + (this.isUpdateMode ? 'UPDATE' : 'CREATE'); - } - onSubmit() { this.submitted.emit(this.formValue); } diff --git a/projects/aca-folder-rules/src/lib/rule-details/options/rule-options.ui-component.html b/projects/aca-folder-rules/src/lib/rule-details/options/rule-options.ui-component.html index 687288771c..e996d0abaf 100644 --- a/projects/aca-folder-rules/src/lib/rule-details/options/rule-options.ui-component.html +++ b/projects/aca-folder-rules/src/lib/rule-details/options/rule-options.ui-component.html @@ -18,14 +18,10 @@ data-automation-id="rule-option-select-errorScript"> {{ 'ACA_FOLDER_RULES.RULE_DETAILS.OPTIONS.NO_SCRIPT' | translate }} - - - {{ option.label }} - - diff --git a/projects/aca-folder-rules/src/lib/rule-details/options/rule-options.ui-component.ts b/projects/aca-folder-rules/src/lib/rule-details/options/rule-options.ui-component.ts index 6a6f6ddfbb..3c34bfd00f 100644 --- a/projects/aca-folder-rules/src/lib/rule-details/options/rule-options.ui-component.ts +++ b/projects/aca-folder-rules/src/lib/rule-details/options/rule-options.ui-component.ts @@ -22,7 +22,7 @@ * from Hyland Software. If not, see . */ -import { Component, forwardRef, HostBinding, Input, OnDestroy, ViewEncapsulation } from '@angular/core'; +import { Component, forwardRef, HostBinding, Input, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core'; import { AbstractControl, ControlValueAccessor, FormControl, FormGroup, NG_VALUE_ACCESSOR } from '@angular/forms'; import { MatCheckboxChange } from '@angular/material/checkbox'; import { RuleOptions } from '../../model/rule.model'; @@ -42,7 +42,7 @@ import { ActionParameterConstraint, ConstraintValue } from '../../model/action-p } ] }) -export class RuleOptionsUiComponent implements ControlValueAccessor, OnDestroy { +export class RuleOptionsUiComponent implements ControlValueAccessor, OnInit, OnDestroy { form = new FormGroup({ isDisabled: new FormControl(), isInheritable: new FormControl(), @@ -51,6 +51,8 @@ export class RuleOptionsUiComponent implements ControlValueAccessor, OnDestroy { }); formSubscription = this.form.valueChanges.subscribe((value: any) => { + this.isAsynchronousChecked = value.isAsynchronous; + this.isInheritableChecked = value.isInheritable; this.onChange({ isEnabled: !value.isDisabled, isInheritable: value.isInheritable, @@ -71,16 +73,10 @@ export class RuleOptionsUiComponent implements ControlValueAccessor, OnDestroy { onChange: (options: RuleOptions) => void = () => undefined; onTouch: () => void = () => undefined; - get isAsynchronousChecked(): boolean { - return this.form.get('isAsynchronous').value; - } - get isInheritableChecked(): boolean { - return this.form.get('isInheritable').value; - } + isAsynchronousChecked = false; + isInheritableChecked = false; - get errorScriptOptions(): ConstraintValue[] { - return this.errorScriptConstraint?.constraints ?? []; - } + errorScriptOptions: ConstraintValue[] = []; writeValue(options: RuleOptions) { const isAsynchronousFormControl = this.form.get('isAsynchronous'); @@ -116,6 +112,10 @@ export class RuleOptionsUiComponent implements ControlValueAccessor, OnDestroy { } } + ngOnInit(): void { + this.errorScriptOptions = this.errorScriptConstraint?.constraints ?? []; + } + ngOnDestroy() { this.formSubscription.unsubscribe(); } diff --git a/projects/aca-folder-rules/src/lib/rule-details/rule-details.ui-component.html b/projects/aca-folder-rules/src/lib/rule-details/rule-details.ui-component.html index 5b98554d7c..a649c0360d 100644 --- a/projects/aca-folder-rules/src/lib/rule-details/rule-details.ui-component.html +++ b/projects/aca-folder-rules/src/lib/rule-details/rule-details.ui-component.html @@ -8,8 +8,8 @@ - {{ getErrorMessage(name) | translate }} + [placeholder]="'ACA_FOLDER_RULES.RULE_DETAILS.PLACEHOLDER.NAME' | translate"> + {{ 'ACA_FOLDER_RULES.RULE_DETAILS.ERROR.REQUIRED' | translate }}
@@ -21,7 +21,7 @@ @@ -32,13 +32,13 @@
{{ 'ACA_FOLDER_RULES.RULE_DETAILS.LABEL.WHEN' | translate }}
- {{ getErrorMessage(triggers) | translate }} + {{ 'ACA_FOLDER_RULES.RULE_DETAILS.ERROR.INSUFFICIENT_TRIGGERS_SELECTED' | translate }}
- {{ getErrorMessage(conditions) | translate }} + {{ 'ACA_FOLDER_RULES.RULE_DETAILS.ERROR.RULE_COMPOSITE_CONDITION_INVALID' | translate }}
diff --git a/projects/aca-folder-rules/src/lib/rule-details/rule-details.ui-component.ts b/projects/aca-folder-rules/src/lib/rule-details/rule-details.ui-component.ts index 97d13698c9..7bb35e43ce 100644 --- a/projects/aca-folder-rules/src/lib/rule-details/rule-details.ui-component.ts +++ b/projects/aca-folder-rules/src/lib/rule-details/rule-details.ui-component.ts @@ -23,7 +23,7 @@ */ import { Component, EventEmitter, Input, OnDestroy, OnInit, Output, ViewEncapsulation } from '@angular/core'; -import { AbstractControl, UntypedFormGroup, UntypedFormControl, Validators } from '@angular/forms'; +import { UntypedFormGroup, UntypedFormControl, Validators } from '@angular/forms'; import { Subject } from 'rxjs'; import { distinctUntilChanged, map, takeUntil } from 'rxjs/operators'; import { Rule, RuleForForm } from '../model/rule.model'; @@ -41,21 +41,11 @@ import { ActionParameterConstraint } from '../model/action-parameter-constraint. host: { class: 'aca-rule-details' } }) export class RuleDetailsUiComponent implements OnInit, OnDestroy { - private _readOnly = false; @Input() - get readOnly(): boolean { - return this._readOnly; - } - set readOnly(value: boolean) { - this._readOnly = value; - if (this.form?.disable) { - if (value) { - this.form.disable(); - } else { - this.form.enable(); - } - } - } + readOnly: boolean; + + descriptionPlaceHolder: string; + private _initialValue: RuleForForm = FolderRulesService.emptyRuleForForm; @Input() get value(): Partial { @@ -107,6 +97,7 @@ export class RuleDetailsUiComponent implements OnInit, OnDestroy { private onDestroy$ = new Subject(); form: UntypedFormGroup; + errorScriptConstraint: ActionParameterConstraint; get name(): UntypedFormControl { return this.form.get('name') as UntypedFormControl; } @@ -116,6 +107,7 @@ export class RuleDetailsUiComponent implements OnInit, OnDestroy { get triggers(): UntypedFormControl { return this.form.get('triggers') as UntypedFormControl; } + get conditions(): UntypedFormControl { return this.form.get('conditions') as UntypedFormControl; } @@ -124,10 +116,6 @@ export class RuleDetailsUiComponent implements OnInit, OnDestroy { return !this.readOnly || this.value.isAsynchronous || this.value.isInheritable; } - get errorScriptConstraint(): ActionParameterConstraint { - return this.parameterConstraints.find((parameterConstraint: ActionParameterConstraint) => parameterConstraint.name === 'script-ref'); - } - ngOnInit() { this.form = new UntypedFormGroup({ id: new UntypedFormControl(this.value.id), @@ -151,7 +139,6 @@ export class RuleDetailsUiComponent implements OnInit, OnDestroy { errorScript: this.value.errorScript }) }); - this.readOnly = this._readOnly; this.form.statusChanges .pipe( @@ -167,39 +154,24 @@ export class RuleDetailsUiComponent implements OnInit, OnDestroy { this.form.valueChanges.pipe(takeUntil(this.onDestroy$)).subscribe(() => { this.formValueChanged.emit(this.value); }); - } - ngOnDestroy() { - this.onDestroy$.next(); - this.onDestroy$.complete(); - } - - getErrorMessage(control: AbstractControl): string { if (this.readOnly) { - return ''; - } - if (control.hasError('required')) { - return control === this.triggers - ? 'ACA_FOLDER_RULES.RULE_DETAILS.ERROR.INSUFFICIENT_TRIGGERS_SELECTED' - : 'ACA_FOLDER_RULES.RULE_DETAILS.ERROR.REQUIRED'; - } else if (control.hasError('ruleCompositeConditionInvalid')) { - return 'ACA_FOLDER_RULES.RULE_DETAILS.ERROR.RULE_COMPOSITE_CONDITION_INVALID'; + this.form.disable(); + } else { + this.form.enable(); } - return ''; + + this.descriptionPlaceHolder = this.readOnly + ? 'ACA_FOLDER_RULES.RULE_DETAILS.PLACEHOLDER.NO_DESCRIPTION' + : 'ACA_FOLDER_RULES.RULE_DETAILS.PLACEHOLDER.DESCRIPTION'; + + this.errorScriptConstraint = this.parameterConstraints.find( + (parameterConstraint: ActionParameterConstraint) => parameterConstraint.name === 'script-ref' + ); } - getPlaceholder(fieldName: string): string { - let str = 'ACA_FOLDER_RULES.RULE_DETAILS.PLACEHOLDER.'; - switch (fieldName) { - case 'name': - str += 'NAME'; - break; - case 'description': - str += this.readOnly ? 'NO_DESCRIPTION' : 'DESCRIPTION'; - break; - default: - return ''; - } - return str; + ngOnDestroy() { + this.onDestroy$.next(); + this.onDestroy$.complete(); } } diff --git a/projects/aca-folder-rules/src/lib/rule-details/triggers/rule-triggers.ui-component.html b/projects/aca-folder-rules/src/lib/rule-details/triggers/rule-triggers.ui-component.html index dc03cc0b37..16501ff7fc 100644 --- a/projects/aca-folder-rules/src/lib/rule-details/triggers/rule-triggers.ui-component.html +++ b/projects/aca-folder-rules/src/lib/rule-details/triggers/rule-triggers.ui-component.html @@ -1,7 +1,7 @@
{{ 'ACA_FOLDER_RULES.RULE_DETAILS.TRIGGERS.' + trigger | uppercase | translate }}
@@ -10,7 +10,7 @@ {{ 'ACA_FOLDER_RULES.RULE_DETAILS.TRIGGERS.' + trigger | uppercase | translate }} diff --git a/projects/aca-folder-rules/src/lib/rule-details/triggers/rule-triggers.ui-component.ts b/projects/aca-folder-rules/src/lib/rule-details/triggers/rule-triggers.ui-component.ts index 07334d8239..2c55570228 100644 --- a/projects/aca-folder-rules/src/lib/rule-details/triggers/rule-triggers.ui-component.ts +++ b/projects/aca-folder-rules/src/lib/rule-details/triggers/rule-triggers.ui-component.ts @@ -42,6 +42,10 @@ import { RuleTrigger } from '../../model/rule.model'; export class RuleTriggersUiComponent implements ControlValueAccessor { readonly triggerOptions: RuleTrigger[] = ['inbound', 'update', 'outbound']; + public selectedTriggers: { [key: string]: boolean } = { + inbound: true + }; + value: RuleTrigger[] = ['inbound']; readOnly = false; @@ -50,6 +54,8 @@ export class RuleTriggersUiComponent implements ControlValueAccessor { writeValue(triggers: RuleTrigger[]) { this.value = triggers; + this.selectedTriggers = {}; + this.value.forEach((trigger) => (this.selectedTriggers[trigger] = true)); } registerOnChange(fn: () => void) { @@ -64,10 +70,6 @@ export class RuleTriggersUiComponent implements ControlValueAccessor { this.readOnly = isDisabled; } - isTriggerChecked(trigger: RuleTrigger): boolean { - return this.value.includes(trigger); - } - onTriggerChange(trigger: RuleTrigger, checked: boolean) { if (checked) { this.value.push(trigger); @@ -77,11 +79,8 @@ export class RuleTriggersUiComponent implements ControlValueAccessor { 1 ); } + this.selectedTriggers[trigger] = checked; this.onTouch(); this.onChange([...this.value]); } - - isTriggerSelected(trigger: RuleTrigger): boolean { - return this.value.includes(trigger); - } } diff --git a/projects/aca-folder-rules/src/lib/rule-list/rule-list-grouping/rule-list-grouping.ui-component.html b/projects/aca-folder-rules/src/lib/rule-list/rule-list-grouping/rule-list-grouping.ui-component.html index 263750e718..6f94c0b94d 100644 --- a/projects/aca-folder-rules/src/lib/rule-list/rule-list-grouping/rule-list-grouping.ui-component.html +++ b/projects/aca-folder-rules/src/lib/rule-list/rule-list-grouping/rule-list-grouping.ui-component.html @@ -5,7 +5,7 @@ matRipple matRippleColor="hsla(0,0%,0%,0.05)" tabindex="0" [rule]="item.rule" - [isSelected]="isSelected(item.rule)" + [isSelected]="item.rule.id === this.selectedRule?.id" [showEnabledToggle]="showEnabledToggles" (click)="onRuleClicked(item.rule)" (enabledChanged)="onEnabledChanged(item.rule, $event)"> diff --git a/projects/aca-folder-rules/src/lib/rule-set-picker/rule-set-picker.smart-component.html b/projects/aca-folder-rules/src/lib/rule-set-picker/rule-set-picker.smart-component.html index 484ffdec5e..12a097fa1b 100644 --- a/projects/aca-folder-rules/src/lib/rule-set-picker/rule-set-picker.smart-component.html +++ b/projects/aca-folder-rules/src/lib/rule-set-picker/rule-set-picker.smart-component.html @@ -23,7 +23,7 @@
- +
{{ 'ACA_FOLDER_RULES.LINK_RULES_DIALOG.LIST_OF_RULES_TO_LINK' | translate }}
@@ -52,7 +52,7 @@ diff --git a/projects/aca-folder-rules/src/lib/rule-set-picker/rule-set-picker.smart-component.ts b/projects/aca-folder-rules/src/lib/rule-set-picker/rule-set-picker.smart-component.ts index 1eebae1d92..a43ff637dc 100644 --- a/projects/aca-folder-rules/src/lib/rule-set-picker/rule-set-picker.smart-component.ts +++ b/projects/aca-folder-rules/src/lib/rule-set-picker/rule-set-picker.smart-component.ts @@ -22,13 +22,13 @@ * from Hyland Software. If not, see . */ -import { Component, Inject, ViewEncapsulation } from '@angular/core'; +import { Component, Inject, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import { FolderRuleSetsService } from '../services/folder-rule-sets.service'; import { Node } from '@alfresco/js-api'; import { RuleSet } from '../model/rule-set.model'; -import { BehaviorSubject, combineLatest, from, of } from 'rxjs'; -import { finalize, map, switchMap } from 'rxjs/operators'; +import { BehaviorSubject, combineLatest, from, of, Subject } from 'rxjs'; +import { finalize, map, switchMap, takeUntil } from 'rxjs/operators'; import { NotificationService } from '@alfresco/adf-core'; export interface RuleSetPickerOptions { @@ -45,11 +45,12 @@ export interface RuleSetPickerOptions { host: { class: 'aca-rule-set-picker' }, providers: [FolderRuleSetsService] }) -export class RuleSetPickerSmartComponent { +export class RuleSetPickerSmartComponent implements OnInit, OnDestroy { nodeId = '-root-'; defaultNodeId = '-root-'; isBusy = false; existingRuleSet: RuleSet = null; + hasOwnedRules = false; private selectedNodeId = ''; private folderLoading$ = new BehaviorSubject(true); @@ -59,6 +60,8 @@ export class RuleSetPickerSmartComponent { map(([rulesLoading, folderLoading]) => rulesLoading || folderLoading) ); + onDestroy$ = new Subject(); + constructor( @Inject(MAT_DIALOG_DATA) public data: RuleSetPickerOptions, private folderRuleSetsService: FolderRuleSetsService, @@ -70,8 +73,15 @@ export class RuleSetPickerSmartComponent { this.existingRuleSet = this.data?.existingRuleSet ?? null; } - hasOwnedRules(ruleSet: RuleSet): boolean { - return ruleSet?.rules.length > 0 && FolderRuleSetsService.isOwnedRuleSet(ruleSet, this.selectedNodeId); + ngOnInit(): void { + this.mainRuleSet$.pipe(takeUntil(this.onDestroy$)).subscribe((mainRuleSet) => { + this.hasOwnedRules = mainRuleSet?.rules.length > 0 && FolderRuleSetsService.isOwnedRuleSet(mainRuleSet, this.selectedNodeId); + }); + } + + ngOnDestroy(): void { + this.onDestroy$.next(); + this.onDestroy$.complete(); } onNodeSelect(nodes: Node[]) { diff --git a/projects/aca-folder-rules/src/lib/services/folder-rule-sets.service.ts b/projects/aca-folder-rules/src/lib/services/folder-rule-sets.service.ts index 6af1fe52c7..8d5620233b 100644 --- a/projects/aca-folder-rules/src/lib/services/folder-rule-sets.service.ts +++ b/projects/aca-folder-rules/src/lib/services/folder-rule-sets.service.ts @@ -233,8 +233,8 @@ export class FolderRuleSetsService { refreshMainRuleSet(ruleToSelect: Rule = null) { this.getMainRuleSet(this.currentFolder.id).subscribe((mainRuleSet: RuleSet) => { - this.mainRuleSet = mainRuleSet; - this.mainRuleSetSource.next(mainRuleSet); + this.mainRuleSet = { ...mainRuleSet }; + this.mainRuleSetSource.next(this.mainRuleSet); if (mainRuleSet) { const ruleToSelectInRuleSet = ruleToSelect ? mainRuleSet.rules.find((rule: Rule) => rule.id === ruleToSelect.id) : mainRuleSet.rules[0]; this.folderRulesService.selectRule(ruleToSelectInRuleSet); diff --git a/projects/aca-folder-rules/src/lib/services/folder-rules.service.ts b/projects/aca-folder-rules/src/lib/services/folder-rules.service.ts index 69afc1c077..2c84547cd7 100644 --- a/projects/aca-folder-rules/src/lib/services/folder-rules.service.ts +++ b/projects/aca-folder-rules/src/lib/services/folder-rules.service.ts @@ -162,7 +162,7 @@ export class FolderRulesService { } private formatRules(res): Rule[] { - return res.list.entries.map((entry) => this.formatRule(entry.entry)); + return [...res.list.entries.map((entry) => this.formatRule(entry.entry))]; } private formatRule(obj): Rule { diff --git a/projects/aca-shared/src/lib/components/locked-by/locked-by.component.spec.ts b/projects/aca-shared/src/lib/components/locked-by/locked-by.component.spec.ts index 56c5aa1828..a5631d6e8a 100644 --- a/projects/aca-shared/src/lib/components/locked-by/locked-by.component.spec.ts +++ b/projects/aca-shared/src/lib/components/locked-by/locked-by.component.spec.ts @@ -36,7 +36,7 @@ describe('LockedByComponent', () => { } } as any }; - + component.ngOnInit(); expect(component.text).toBe('owner-name'); }); }); diff --git a/projects/aca-shared/src/lib/components/locked-by/locked-by.component.ts b/projects/aca-shared/src/lib/components/locked-by/locked-by.component.ts index 7d8a830cb4..5b67e5bece 100644 --- a/projects/aca-shared/src/lib/components/locked-by/locked-by.component.ts +++ b/projects/aca-shared/src/lib/components/locked-by/locked-by.component.ts @@ -22,7 +22,7 @@ * from Hyland Software. If not, see . */ -import { Component, Input, ChangeDetectionStrategy, ViewEncapsulation } from '@angular/core'; +import { Component, Input, ChangeDetectionStrategy, ViewEncapsulation, OnInit } from '@angular/core'; import { NodeEntry } from '@alfresco/js-api'; import { TranslateModule } from '@ngx-translate/core'; import { MatIconModule } from '@angular/material/icon'; @@ -43,11 +43,13 @@ import { MatIconModule } from '@angular/material/icon'; class: 'aca-locked-by' } }) -export class LockedByComponent { +export class LockedByComponent implements OnInit { @Input() node: NodeEntry; - get text(): string { - return this.node?.entry?.properties?.['cm:lockOwner']?.displayName; + public text: string; + + ngOnInit(): void { + this.text = this.node?.entry?.properties?.['cm:lockOwner']?.displayName; } } diff --git a/projects/aca-shared/src/lib/components/tool-bar/toolbar-menu/toolbar-menu.component.ts b/projects/aca-shared/src/lib/components/tool-bar/toolbar-menu/toolbar-menu.component.ts index b023cd90e1..c6817a2d69 100644 --- a/projects/aca-shared/src/lib/components/tool-bar/toolbar-menu/toolbar-menu.component.ts +++ b/projects/aca-shared/src/lib/components/tool-bar/toolbar-menu/toolbar-menu.component.ts @@ -22,7 +22,7 @@ * from Hyland Software. If not, see . */ -import { Component, Input, ViewEncapsulation, HostListener, ViewChild, ViewChildren, QueryList, AfterViewInit } from '@angular/core'; +import { Component, Input, ViewEncapsulation, HostListener, ViewChild, ViewChildren, QueryList, AfterViewInit, OnInit } from '@angular/core'; import { ContentActionRef } from '@alfresco/adf-extensions'; import { MatMenu, MatMenuItem, MatMenuTrigger } from '@angular/material/menu'; import { ThemePalette } from '@angular/material/core'; @@ -34,7 +34,7 @@ import { ToolbarMenuItemComponent } from '../toolbar-menu-item/toolbar-menu-item encapsulation: ViewEncapsulation.None, host: { class: 'app-toolbar-menu' } }) -export class ToolbarMenuComponent implements AfterViewInit { +export class ToolbarMenuComponent implements OnInit, AfterViewInit { @Input() actionRef: ContentActionRef; @@ -56,15 +56,17 @@ export class ToolbarMenuComponent implements AfterViewInit { color?: string; }; - get type(): string { - return this.data?.menuType || 'default'; - } + type = 'default'; @HostListener('document:keydown.Escape') handleKeydownEscape() { this.matTrigger.closeMenu(); } + ngOnInit(): void { + this.type = this.data?.menuType || 'default'; + } + ngAfterViewInit(): void { const menuItems: MatMenuItem[] = []; this.toolbarMenuItems.forEach((toolbarMenuItem: ToolbarMenuItemComponent) => {