mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-05-12 17:04:46 +00:00
[ACS-3596] Create / Update rule dialog - display errors (#2685)
* folder-rules.service - createRule method * add temp method addFakeAction * [ACS-3596] Create / Update rule dialog - display errors * comments removed
This commit is contained in:
parent
ef0d89989d
commit
cd6a2cc238
@ -34,6 +34,7 @@ import { tap } from 'rxjs/operators';
|
|||||||
import { EditRuleDialogSmartComponent } from '../rule-details/edit-rule-dialog.smart-component';
|
import { EditRuleDialogSmartComponent } from '../rule-details/edit-rule-dialog.smart-component';
|
||||||
import { MatDialog } from '@angular/material/dialog';
|
import { MatDialog } from '@angular/material/dialog';
|
||||||
import { ConfirmDialogComponent } from '@alfresco/adf-content-services';
|
import { ConfirmDialogComponent } from '@alfresco/adf-content-services';
|
||||||
|
import { NotificationService } from '@alfresco/adf-core';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'aca-manage-rules',
|
selector: 'aca-manage-rules',
|
||||||
@ -49,12 +50,14 @@ export class ManageRulesSmartComponent implements OnInit, OnDestroy {
|
|||||||
selectedRule: Rule = null;
|
selectedRule: Rule = null;
|
||||||
nodeId: string = null;
|
nodeId: string = null;
|
||||||
deletedRuleSubscription$: Subscription;
|
deletedRuleSubscription$: Subscription;
|
||||||
|
ruleDialogOnSubmitSubscription$: Subscription;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private location: Location,
|
private location: Location,
|
||||||
private folderRulesService: FolderRulesService,
|
private folderRulesService: FolderRulesService,
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
private matDialogService: MatDialog
|
private matDialogService: MatDialog,
|
||||||
|
private notificationService: NotificationService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
@ -93,10 +96,24 @@ export class ManageRulesSmartComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
openNewRuleDialog() {
|
openNewRuleDialog() {
|
||||||
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'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.onSubmitRuleDialog(dialogRef);
|
||||||
|
}
|
||||||
|
|
||||||
|
onSubmitRuleDialog(dialogRef) {
|
||||||
|
dialogRef.componentInstance.submitted.subscribe(async (rule) => {
|
||||||
|
try {
|
||||||
|
await this.folderRulesService.createRule(this.nodeId, rule);
|
||||||
|
this.folderRulesService.loadRules(this.nodeId);
|
||||||
|
dialogRef.close();
|
||||||
|
} catch (error) {
|
||||||
|
this.notificationService.showError(error.response.body.error.errorKey);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onRuleDelete(): void {
|
onRuleDelete(): void {
|
||||||
|
@ -8,10 +8,10 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<mat-dialog-content class="aca-edit-rule-dialog__content">
|
<mat-dialog-content class="aca-edit-rule-dialog__content">
|
||||||
<aca-rule-details (formValidationChanged)="formValid = $event" [value]="model"></aca-rule-details>
|
<aca-rule-details (formValidationChanged)="formValid = $event" (formValueChanged)="formValue = $event" [value]="model"></aca-rule-details>
|
||||||
</mat-dialog-content>
|
</mat-dialog-content>
|
||||||
|
|
||||||
<mat-dialog-actions align="end" class="aca-edit-rule-dialog__footer">
|
<mat-dialog-actions align="end" class="aca-edit-rule-dialog__footer">
|
||||||
<button mat-flat-button mat-dialog-close>{{ 'ACA_FOLDER_RULES.EDIT_RULE_DIALOG.CANCEL' | translate }}</button>
|
<button mat-flat-button mat-dialog-close>{{ 'ACA_FOLDER_RULES.EDIT_RULE_DIALOG.CANCEL' | translate }}</button>
|
||||||
<button mat-flat-button color="primary" [disabled]="!formValid" data-automation-id="edit-rule-dialog-submit">{{ submitLabel | translate }}</button>
|
<button mat-flat-button color="primary" [disabled]="!formValid" data-automation-id="edit-rule-dialog-submit" (click)="onSubmit()">{{ submitLabel | translate }}</button>
|
||||||
</mat-dialog-actions>
|
</mat-dialog-actions>
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Component, Inject, ViewEncapsulation } from '@angular/core';
|
import { Component, EventEmitter, Inject, Output, ViewEncapsulation } from '@angular/core';
|
||||||
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
|
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
|
||||||
import { Rule } from '../model/rule.model';
|
import { Rule } from '../model/rule.model';
|
||||||
|
|
||||||
@ -41,6 +41,8 @@ export interface EditRuleDialogOptions {
|
|||||||
export class EditRuleDialogSmartComponent {
|
export class EditRuleDialogSmartComponent {
|
||||||
formValid = false;
|
formValid = false;
|
||||||
model: Partial<Rule>;
|
model: Partial<Rule>;
|
||||||
|
formValue: Partial<Rule>;
|
||||||
|
@Output() submitted = new EventEmitter<Partial<Rule>>();
|
||||||
|
|
||||||
constructor(@Inject(MAT_DIALOG_DATA) public options: EditRuleDialogOptions) {
|
constructor(@Inject(MAT_DIALOG_DATA) public options: EditRuleDialogOptions) {
|
||||||
this.model = this.options?.model || {};
|
this.model = this.options?.model || {};
|
||||||
@ -57,4 +59,8 @@ export class EditRuleDialogSmartComponent {
|
|||||||
get submitLabel(): string {
|
get submitLabel(): string {
|
||||||
return 'ACA_FOLDER_RULES.EDIT_RULE_DIALOG.' + (this.isUpdateMode ? 'UPDATE' : 'CREATE');
|
return 'ACA_FOLDER_RULES.EDIT_RULE_DIALOG.' + (this.isUpdateMode ? 'UPDATE' : 'CREATE');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onSubmit() {
|
||||||
|
this.submitted.emit(this.formValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,7 @@ describe('FolderRulesService', () => {
|
|||||||
const ruleId = '********-fake-rule-****-********';
|
const ruleId = '********-fake-rule-****-********';
|
||||||
const ruleSetId = '-default-';
|
const ruleSetId = '-default-';
|
||||||
const params = [{}, {}, {}, {}, {}, ['application/json'], ['application/json']];
|
const params = [{}, {}, {}, {}, {}, ['application/json'], ['application/json']];
|
||||||
|
const paramsWithBody = [{}, {}, {}, {}, dummyRules[0], ['application/json'], ['application/json']];
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
@ -111,7 +112,6 @@ describe('FolderRulesService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('toggleRule', () => {
|
describe('toggleRule', () => {
|
||||||
const paramsWithBody = [{}, {}, {}, {}, dummyRules[0], ['application/json'], ['application/json']];
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
apiCallSpy = spyOn<any>(folderRulesService, 'apiCall')
|
apiCallSpy = spyOn<any>(folderRulesService, 'apiCall')
|
||||||
.withArgs(`/nodes/${nodeId}/rule-sets/${ruleSetId}/rules/${ruleId}`, 'PUT', paramsWithBody)
|
.withArgs(`/nodes/${nodeId}/rule-sets/${ruleSetId}/rules/${ruleId}`, 'PUT', paramsWithBody)
|
||||||
@ -138,4 +138,19 @@ describe('FolderRulesService', () => {
|
|||||||
expect(apiCallSpy).toHaveBeenCalledWith(`/aspects`, 'GET', params);
|
expect(apiCallSpy).toHaveBeenCalledWith(`/aspects`, 'GET', params);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('createRule', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
spyOn<any>(folderRulesService, 'apiCall')
|
||||||
|
.withArgs(`/nodes/${nodeId}/rule-sets/${ruleSetId}/rules`, 'POST', paramsWithBody)
|
||||||
|
.and.returnValue(Promise.resolve(dummyRules[0]));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should send correct POST request and return created rule', function () {
|
||||||
|
folderRulesService.createRule(nodeId, dummyRules[0]).then((result) => {
|
||||||
|
expect(folderRulesService.createRule).toHaveBeenCalledWith(nodeId, dummyRules[0]);
|
||||||
|
expect(result).toEqual(dummyRules[0]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -112,6 +112,18 @@ export class FolderRulesService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createRule(nodeId: string, rule: Partial<Rule>, ruleSetId: string = '-default-') {
|
||||||
|
return this.apiCall(`/nodes/${nodeId}/rule-sets/${ruleSetId}/rules`, 'POST', [
|
||||||
|
{},
|
||||||
|
{},
|
||||||
|
{},
|
||||||
|
{},
|
||||||
|
{ ...this.addFakeAction(rule) },
|
||||||
|
['application/json'],
|
||||||
|
['application/json']
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
deleteRule(nodeId: string, ruleId: string, ruleSetId: string = '-default-'): void {
|
deleteRule(nodeId: string, ruleId: string, ruleSetId: string = '-default-'): void {
|
||||||
this.loadingSource.next(true);
|
this.loadingSource.next(true);
|
||||||
from(
|
from(
|
||||||
@ -157,6 +169,24 @@ 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