mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-05-12 17:04:46 +00:00
[ACS-3511] Update rules (#2701)
* rebase * fixed a bug conserning isEnabled checkbox * removed addFakeApect, added unit tests * linting * renamed openNewRuleDialog to openCreateUpdateRuleDialog
This commit is contained in:
parent
07f3c99b33
commit
a804dceade
@ -90,7 +90,8 @@
|
|||||||
"RULES": "rules"
|
"RULES": "rules"
|
||||||
},
|
},
|
||||||
"ACTIONS": {
|
"ACTIONS": {
|
||||||
"CREATE_RULE": "Create rule"
|
"CREATE_RULE": "Create rule",
|
||||||
|
"EDIT_RULE": "Edit"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"EMPTY_RULES_LIST": {
|
"EMPTY_RULES_LIST": {
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
class="aca-manage-rules__actions-bar__title__breadcrumb"></adf-breadcrumb>
|
class="aca-manage-rules__actions-bar__title__breadcrumb"></adf-breadcrumb>
|
||||||
</adf-toolbar-title>
|
</adf-toolbar-title>
|
||||||
|
|
||||||
<button mat-flat-button color="primary" (click)="openNewRuleDialog()">{{ 'ACA_FOLDER_RULES.MANAGE_RULES.TOOLBAR.ACTIONS.CREATE_RULE' | translate }}</button>
|
<button mat-flat-button color="primary" (click)="openCreateUpdateRuleDialog()">{{ 'ACA_FOLDER_RULES.MANAGE_RULES.TOOLBAR.ACTIONS.CREATE_RULE' | translate }}</button>
|
||||||
</adf-toolbar>
|
</adf-toolbar>
|
||||||
<mat-divider></mat-divider>
|
<mat-divider></mat-divider>
|
||||||
|
|
||||||
@ -40,6 +40,9 @@
|
|||||||
<button mat-icon-button (click)="onRuleDelete()" id="delete-rule-btn">
|
<button mat-icon-button (click)="onRuleDelete()" id="delete-rule-btn">
|
||||||
<mat-icon>delete_outline</mat-icon>
|
<mat-icon>delete_outline</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
|
<button mat-stroked-button (click)="onRuleUpdate()" id="edit-rule-btn">
|
||||||
|
{{ 'ACA_FOLDER_RULES.MANAGE_RULES.TOOLBAR.ACTIONS.EDIT_RULE' | translate }}
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p>{{ selectedRule.description }}</p>
|
<p>{{ selectedRule.description }}</p>
|
||||||
|
@ -103,10 +103,13 @@ export class ManageRulesSmartComponent implements OnInit, OnDestroy {
|
|||||||
this.selectedRule = rule;
|
this.selectedRule = rule;
|
||||||
}
|
}
|
||||||
|
|
||||||
openNewRuleDialog() {
|
openCreateUpdateRuleDialog(model = {}) {
|
||||||
const dialogRef = this.matDialogService.open(EditRuleDialogSmartComponent, {
|
const dialogRef = this.matDialogService.open(EditRuleDialogSmartComponent, {
|
||||||
width: '90%',
|
width: '90%',
|
||||||
panelClass: 'aca-edit-rule-dialog-container'
|
panelClass: 'aca-edit-rule-dialog-container',
|
||||||
|
data: {
|
||||||
|
model
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.onSubmitRuleDialog(dialogRef);
|
this.onSubmitRuleDialog(dialogRef);
|
||||||
@ -115,7 +118,11 @@ export class ManageRulesSmartComponent implements OnInit, OnDestroy {
|
|||||||
onSubmitRuleDialog(dialogRef) {
|
onSubmitRuleDialog(dialogRef) {
|
||||||
dialogRef.componentInstance.submitted.subscribe(async (rule) => {
|
dialogRef.componentInstance.submitted.subscribe(async (rule) => {
|
||||||
try {
|
try {
|
||||||
|
if (rule.id) {
|
||||||
|
await this.folderRulesService.updateRule(this.nodeId, rule.id, rule);
|
||||||
|
} else {
|
||||||
await this.folderRulesService.createRule(this.nodeId, rule);
|
await this.folderRulesService.createRule(this.nodeId, rule);
|
||||||
|
}
|
||||||
this.folderRulesService.loadRules(this.nodeId);
|
this.folderRulesService.loadRules(this.nodeId);
|
||||||
dialogRef.close();
|
dialogRef.close();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -140,4 +147,8 @@ export class ManageRulesSmartComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onRuleUpdate(): void {
|
||||||
|
this.openCreateUpdateRuleDialog(this.selectedRule);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,12 +47,12 @@ export class EditRuleDialogSmartComponent implements OnInit {
|
|||||||
actionDefinitions$ = this.actionsService.actionDefinitionsListing$;
|
actionDefinitions$ = this.actionsService.actionDefinitionsListing$;
|
||||||
loading$ = this.actionsService.loading$;
|
loading$ = this.actionsService.loading$;
|
||||||
|
|
||||||
constructor(@Inject(MAT_DIALOG_DATA) public options: EditRuleDialogOptions, private actionsService: ActionsService) {
|
constructor(@Inject(MAT_DIALOG_DATA) public data: EditRuleDialogOptions, private actionsService: ActionsService) {
|
||||||
this.model = this.options?.model || {};
|
this.model = this.data?.model || {};
|
||||||
}
|
}
|
||||||
|
|
||||||
get isUpdateMode(): boolean {
|
get isUpdateMode(): boolean {
|
||||||
return !!this.options?.model?.id;
|
return !!this.data?.model?.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
get title(): string {
|
get title(): string {
|
||||||
|
@ -25,11 +25,10 @@
|
|||||||
</mat-checkbox>
|
</mat-checkbox>
|
||||||
<mat-checkbox
|
<mat-checkbox
|
||||||
[attr.data-automation-id]="'rule-option-checkbox-enabled'"
|
[attr.data-automation-id]="'rule-option-checkbox-enabled'"
|
||||||
[checked]="!form.value.isEnabled" *ngIf="!preview"
|
[checked]="!form.get('isEnabled').value" *ngIf="!preview"
|
||||||
(change)="form.get('isEnabled').setValue(!$event.checked)">
|
(change)="form.get('isEnabled').setValue(!$event.checked)">
|
||||||
{{ 'ACA_FOLDER_RULES.RULE_DETAILS.OPTIONS.DISABLE_RULE' | translate }}
|
{{ 'ACA_FOLDER_RULES.RULE_DETAILS.OPTIONS.DISABLE_RULE' | translate }}
|
||||||
</mat-checkbox>
|
</mat-checkbox>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
@ -62,6 +62,7 @@ export class RuleDetailsUiComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
set value(newValue: Partial<Rule>) {
|
set value(newValue: Partial<Rule>) {
|
||||||
newValue = {
|
newValue = {
|
||||||
|
id: newValue.id || FolderRulesService.emptyRule.id,
|
||||||
name: newValue.name || FolderRulesService.emptyRule.name,
|
name: newValue.name || FolderRulesService.emptyRule.name,
|
||||||
description: newValue.description || FolderRulesService.emptyRule.description,
|
description: newValue.description || FolderRulesService.emptyRule.description,
|
||||||
triggers: newValue.triggers || FolderRulesService.emptyRule.triggers,
|
triggers: newValue.triggers || FolderRulesService.emptyRule.triggers,
|
||||||
@ -69,7 +70,7 @@ export class RuleDetailsUiComponent implements OnInit, OnDestroy {
|
|||||||
isAsynchronous: newValue.isAsynchronous || FolderRulesService.emptyRule.isAsynchronous,
|
isAsynchronous: newValue.isAsynchronous || FolderRulesService.emptyRule.isAsynchronous,
|
||||||
errorScript: newValue.errorScript || FolderRulesService.emptyRule.errorScript,
|
errorScript: newValue.errorScript || FolderRulesService.emptyRule.errorScript,
|
||||||
isInheritable: newValue.isInheritable || FolderRulesService.emptyRule.isInheritable,
|
isInheritable: newValue.isInheritable || FolderRulesService.emptyRule.isInheritable,
|
||||||
isEnabled: newValue.isEnabled || FolderRulesService.emptyRule.isEnabled,
|
isEnabled: typeof newValue.isInheritable == 'boolean' ? newValue.isEnabled : FolderRulesService.emptyRule.isEnabled,
|
||||||
actions: newValue.actions || FolderRulesService.emptyRule.actions
|
actions: newValue.actions || FolderRulesService.emptyRule.actions
|
||||||
};
|
};
|
||||||
if (this.form) {
|
if (this.form) {
|
||||||
@ -118,6 +119,7 @@ export class RuleDetailsUiComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.form = new UntypedFormGroup({
|
this.form = new UntypedFormGroup({
|
||||||
|
id: new UntypedFormControl(this.value.id),
|
||||||
name: new UntypedFormControl(this.value.name || '', Validators.required),
|
name: new UntypedFormControl(this.value.name || '', Validators.required),
|
||||||
description: new UntypedFormControl(this.value.description || ''),
|
description: new UntypedFormControl(this.value.description || ''),
|
||||||
triggers: new UntypedFormControl(this.value.triggers || ['inbound'], Validators.required),
|
triggers: new UntypedFormControl(this.value.triggers || ['inbound'], Validators.required),
|
||||||
|
@ -151,4 +151,13 @@ describe('FolderRulesService', () => {
|
|||||||
expect(result).toEqual(dummyRules[0]);
|
expect(result).toEqual(dummyRules[0]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should send correct PUT request to update rule and return it', async () => {
|
||||||
|
spyOn<any>(folderRulesService, 'apiCall')
|
||||||
|
.withArgs(`/nodes/${nodeId}/rule-sets/${ruleSetId}/rules/${ruleId}`, 'PUT', paramsWithBody)
|
||||||
|
.and.returnValue(Promise.resolve(dummyRules[0]));
|
||||||
|
|
||||||
|
const result = await folderRulesService.updateRule(nodeId, ruleId, dummyRules[0]);
|
||||||
|
expect(result).toEqual(dummyRules[0]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -118,7 +118,19 @@ export class FolderRulesService {
|
|||||||
{},
|
{},
|
||||||
{},
|
{},
|
||||||
{},
|
{},
|
||||||
{ ...this.addFakeAction(rule) },
|
{ ...rule },
|
||||||
|
['application/json'],
|
||||||
|
['application/json']
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateRule(nodeId: string, ruleId: string, rule: Rule, ruleSetId: string = '-default-') {
|
||||||
|
return this.apiCall(`/nodes/${nodeId}/rule-sets/${ruleSetId}/rules/${ruleId}`, 'PUT', [
|
||||||
|
{},
|
||||||
|
{},
|
||||||
|
{},
|
||||||
|
{},
|
||||||
|
{ ...rule },
|
||||||
['application/json'],
|
['application/json'],
|
||||||
['application/json']
|
['application/json']
|
||||||
]);
|
]);
|
||||||
@ -169,24 +181,6 @@ export class FolderRulesService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private addFakeAction(rule): Partial<Rule> {
|
|
||||||
if (rule.actions) {
|
|
||||||
return rule;
|
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
...rule,
|
|
||||||
actions: [
|
|
||||||
{
|
|
||||||
actionDefinitionId: 'add-features',
|
|
||||||
params: {
|
|
||||||
'aspect-name': 'ai:creativeWorks'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private apiCall(path: string, httpMethod: string, params?: any[]): Promise<any> {
|
private apiCall(path: string, httpMethod: string, params?: any[]): Promise<any> {
|
||||||
return this.apiService.getInstance().contentClient.callApi(path, httpMethod, ...params);
|
return this.apiService.getInstance().contentClient.callApi(path, httpMethod, ...params);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user