mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-05-12 17:04:46 +00:00
[ACS-3512] - ACA enable/disable rule from listing (#2636)
* initial html layout * toggleRule method * [ACS-3512] - ACA enable/disable rule from listing * useless crutch was deleted
This commit is contained in:
parent
1ae84fb852
commit
3b9eae677c
@ -30,7 +30,8 @@
|
|||||||
<mat-divider></mat-divider>
|
<mat-divider></mat-divider>
|
||||||
|
|
||||||
<div class="aca-manage-rules__container" *ngIf="(rules$ | async).length > 0 ; else emptyContent">
|
<div class="aca-manage-rules__container" *ngIf="(rules$ | async).length > 0 ; else emptyContent">
|
||||||
<aca-rules-list [rules]="rules$ | async" (ruleSelected)="onRuleSelected($event)" [selectedRule]="selectedRule"></aca-rules-list>
|
<aca-rules-list [rules]="rules$ | async" (ruleSelected)="onRuleSelected($event)"
|
||||||
|
[selectedRule]="selectedRule" [nodeId]="nodeId"></aca-rules-list>
|
||||||
<div class="aca-manage-rules__container__rule-details">
|
<div class="aca-manage-rules__container__rule-details">
|
||||||
<div class="aca-manage-rules__container__preview">
|
<div class="aca-manage-rules__container__preview">
|
||||||
<div class="aca-manage-rules__container__preview__toolbar">
|
<div class="aca-manage-rules__container__preview__toolbar">
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
<div class="aca-rule" [class.selected]="isSelected" >
|
<div class="aca-rule" [class.selected]="isSelected" >
|
||||||
<div class="rule-info">
|
<div class="rule-info">
|
||||||
<span class="aca-rule-title">{{rule.name}}</span>
|
<div class="rule-info__header">
|
||||||
|
<span class="rule-info__header__title">{{rule.name}}</span>
|
||||||
|
<mat-slide-toggle [(ngModel)]="rule.enabled" (click)="onToggleClick(!rule.enabled)"></mat-slide-toggle>
|
||||||
|
</div>
|
||||||
<p>{{rule.description}}</p>
|
<p>{{rule.description}}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -5,13 +5,6 @@
|
|||||||
margin-bottom: 8px;
|
margin-bottom: 8px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
|
||||||
.aca-rule-title{
|
|
||||||
font-weight: 900;
|
|
||||||
font-size: 14px;
|
|
||||||
color: #212121;
|
|
||||||
line-height: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
p{
|
p{
|
||||||
margin: 6px 0 0 0;
|
margin: 6px 0 0 0;
|
||||||
color: rgba(33, 35, 40, 0.7);
|
color: rgba(33, 35, 40, 0.7);
|
||||||
@ -22,6 +15,22 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.rule-info{
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
&__header{
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
|
||||||
|
&__title{
|
||||||
|
font-weight: 900;
|
||||||
|
font-size: 14px;
|
||||||
|
color: #212121;
|
||||||
|
line-height: 20px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.selected{
|
.selected{
|
||||||
background: rgba(31, 116, 219, 0.24);
|
background: rgba(31, 116, 219, 0.24);
|
||||||
}
|
}
|
||||||
|
@ -25,12 +25,16 @@
|
|||||||
|
|
||||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
import { RuleListItemUiComponent } from './rule-list-item.ui-component';
|
import { RuleListItemUiComponent } from './rule-list-item.ui-component';
|
||||||
|
import { CoreTestingModule } from '@alfresco/adf-core';
|
||||||
|
|
||||||
describe('RuleComponent', () => {
|
describe('RuleComponent', () => {
|
||||||
let component: RuleListItemUiComponent;
|
let component: RuleListItemUiComponent;
|
||||||
let fixture: ComponentFixture<RuleListItemUiComponent>;
|
let fixture: ComponentFixture<RuleListItemUiComponent>;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [CoreTestingModule]
|
||||||
|
});
|
||||||
fixture = TestBed.createComponent(RuleListItemUiComponent);
|
fixture = TestBed.createComponent(RuleListItemUiComponent);
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
});
|
});
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
import { Component, Input } from '@angular/core';
|
import { Component, Input } from '@angular/core';
|
||||||
import { Rule } from '../../model/rule.model';
|
import { Rule } from '../../model/rule.model';
|
||||||
|
import { FolderRulesService } from '../../services/folder-rules.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'aca-rule',
|
selector: 'aca-rule',
|
||||||
@ -34,4 +35,11 @@ import { Rule } from '../../model/rule.model';
|
|||||||
export class RuleListItemUiComponent {
|
export class RuleListItemUiComponent {
|
||||||
@Input() rule: Rule;
|
@Input() rule: Rule;
|
||||||
@Input() isSelected: boolean;
|
@Input() isSelected: boolean;
|
||||||
|
@Input() nodeId: string;
|
||||||
|
|
||||||
|
constructor(private folderRulesService: FolderRulesService) {}
|
||||||
|
|
||||||
|
onToggleClick(enabled: boolean) {
|
||||||
|
this.folderRulesService.toggleRule(this.nodeId, this.rule.id, { ...this.rule, enabled });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
<div class="aca-rules-list" >
|
<div class="aca-rules-list" >
|
||||||
<aca-rule *ngFor="let rule of rules" [rule]="rule" (click)="onRuleClicked(rule)" [isSelected]="isSelected(rule)"></aca-rule>
|
<aca-rule *ngFor="let rule of rules" [rule]="rule" (click)="onRuleClicked(rule)" [isSelected]="isSelected(rule)"
|
||||||
|
[nodeId]="nodeId"></aca-rule>
|
||||||
</div>
|
</div>
|
||||||
|
@ -60,10 +60,12 @@ describe('RulesListComponent', () => {
|
|||||||
expect(rules.length).toBe(2, 'Unexpected number of rules');
|
expect(rules.length).toBe(2, 'Unexpected number of rules');
|
||||||
|
|
||||||
const rule = debugElement.query(By.css('.aca-rule:first-child'));
|
const rule = debugElement.query(By.css('.aca-rule:first-child'));
|
||||||
const title = rule.query(By.css('.aca-rule-title'));
|
const title = rule.query(By.css('.rule-info__header__title'));
|
||||||
const description = rule.query(By.css('p'));
|
const description = rule.query(By.css('p'));
|
||||||
|
const toggleBtn = rule.query(By.css('mat-slide-toggle'));
|
||||||
|
|
||||||
expect(title.nativeElement.textContent).toBe(dummyRules[0].name);
|
expect(title.nativeElement.textContent).toBe(dummyRules[0].name);
|
||||||
|
expect(toggleBtn).toBeTruthy();
|
||||||
expect(description.nativeElement.textContent).toBe(dummyRules[0].description);
|
expect(description.nativeElement.textContent).toBe(dummyRules[0].description);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -38,6 +38,9 @@ export class RulesListUiComponent {
|
|||||||
@Input()
|
@Input()
|
||||||
selectedRule: Rule;
|
selectedRule: Rule;
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
nodeId: string;
|
||||||
|
|
||||||
@Output()
|
@Output()
|
||||||
ruleSelected = new EventEmitter<Rule>();
|
ruleSelected = new EventEmitter<Rule>();
|
||||||
|
|
||||||
|
@ -109,4 +109,20 @@ describe('FolderRulesService', () => {
|
|||||||
expect(apiCallSpy).toHaveBeenCalledWith(`/nodes/${nodeId}/rule-sets/${ruleSetId}/rules/${ruleId}`, 'DELETE', params);
|
expect(apiCallSpy).toHaveBeenCalledWith(`/nodes/${nodeId}/rule-sets/${ruleSetId}/rules/${ruleId}`, 'DELETE', params);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('toggleRule', () => {
|
||||||
|
const paramsWithBody = [{}, {}, {}, {}, dummyRules[0], ['application/json'], ['application/json']];
|
||||||
|
beforeEach(async () => {
|
||||||
|
apiCallSpy = spyOn<any>(folderRulesService, 'apiCall')
|
||||||
|
.withArgs(`/nodes/${nodeId}/rule-sets/${ruleSetId}/rules/${ruleId}`, 'PUT', paramsWithBody)
|
||||||
|
.and.returnValue([]);
|
||||||
|
|
||||||
|
folderRulesService.toggleRule(nodeId, ruleId, dummyRules[0]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should send correct PUT request', async () => {
|
||||||
|
expect(apiCallSpy).toHaveBeenCalled();
|
||||||
|
expect(apiCallSpy).toHaveBeenCalledWith(`/nodes/${nodeId}/rule-sets/${ruleSetId}/rules/${ruleId}`, 'PUT', paramsWithBody);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -132,6 +132,20 @@ export class FolderRulesService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toggleRule(nodeId: string, ruleId: string, rule: Rule, ruleSetId: string = '-default-'): void {
|
||||||
|
from(
|
||||||
|
this.apiCall(`/nodes/${nodeId}/rule-sets/${ruleSetId}/rules/${ruleId}`, 'PUT', [
|
||||||
|
{},
|
||||||
|
{},
|
||||||
|
{},
|
||||||
|
{},
|
||||||
|
{ ...rule },
|
||||||
|
['application/json'],
|
||||||
|
['application/json']
|
||||||
|
])
|
||||||
|
).subscribe({ error: (error) => console.error(error) });
|
||||||
|
}
|
||||||
|
|
||||||
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