Skip to content

Commit

Permalink
[ACS-3513] [ACS-3515] Create, edit and delete rule set link (#2810)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Hunter committed Nov 24, 2022
1 parent a479394 commit d9d2441
Show file tree
Hide file tree
Showing 20 changed files with 439 additions and 76 deletions.
21 changes: 21 additions & 0 deletions projects/aca-folder-rules/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
},
"ACTIONS": {
"CREATE_RULE": "Create rule",
"LINK_RULES": "Link rules",
"EDIT_RULE": "Edit",
"SEE_IN_FOLDER": "See in folder"
}
Expand All @@ -106,6 +107,10 @@
"DELETE_RULE": {
"TITLE": "Delete rule",
"MESSAGE": "Are you sure you want to delete this rule?"
},
"DELETE_RULE_SET_LINK": {
"TITLE": "Delete rule set link",
"MESSAGE": "Are you sure you want to delete the link to this rule set?"
}
},
"RULE_LIST": {
Expand All @@ -116,6 +121,22 @@
"LOAD_MORE_RULES": "Load more rules",
"LOADING_RULES": "Loading rules",
"INHERITED_RULES_WILL_BE_RUN_FIRST": "Inherited rules will be run first"
},
"LINK_RULES_DIALOG": {
"TITLE": "Select a folder to link rules from",
"CANCEL": "Cancel",
"SUBMIT": "Select folder",
"EMPTY_RULES_LIST": {
"TITLE": "No owned rules",
"SUBTITLE": "The selected folder doesn't have any rules of its own."
},
"LIST_OF_RULES_TO_LINK": "List of rules that will be linked",
"ERRORS": {
"REQUEST_FAILED": "Error while trying to create a link to a rule set"
}
},
"ERRORS": {
"DELETE_RULE_SET_LINK_FAILED": "Error while trying to delete a link from a rule set"
}
}
}
7 changes: 5 additions & 2 deletions projects/aca-folder-rules/src/lib/folder-rules.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ import { RuleCompositeConditionUiComponent } from './rule-details/conditions/rul
import { RuleDetailsUiComponent } from './rule-details/rule-details.ui-component';
import { RuleSimpleConditionUiComponent } from './rule-details/conditions/rule-simple-condition.ui-component';
import { GenericErrorModule, PageLayoutModule } from '@alfresco/aca-shared';
import { BreadcrumbModule, DocumentListModule } from '@alfresco/adf-content-services';
import { BreadcrumbModule, ContentNodeSelectorModule, DocumentListModule } from '@alfresco/adf-content-services';
import { RuleListItemUiComponent } from './rule-list/rule-list-item/rule-list-item.ui-component';
import { RuleListGroupingUiComponent } from './rule-list/rule-list-grouping/rule-list-grouping.ui-component';
import { RuleTriggersUiComponent } from './rule-details/triggers/rule-triggers.ui-component';
import { RuleOptionsUiComponent } from './rule-details/options/rule-options.ui-component';
import { RuleActionListUiComponent } from './rule-details/actions/rule-action-list.ui-component';
import { RuleActionUiComponent } from './rule-details/actions/rule-action.ui-component';
import { RuleListUiComponent } from './rule-list/rule-list/rule-list.ui-component';
import { RuleSetPickerSmartComponent } from './rule-set-picker/rule-set-picker.smart-component';

const routes: Routes = [
{
Expand All @@ -61,7 +62,8 @@ const routes: Routes = [
BreadcrumbModule,
DocumentListModule,
ExtensionsModule,
GenericErrorModule
GenericErrorModule,
ContentNodeSelectorModule
],
declarations: [
EditRuleDialogSmartComponent,
Expand All @@ -73,6 +75,7 @@ const routes: Routes = [
RuleListGroupingUiComponent,
RuleListItemUiComponent,
RuleListUiComponent,
RuleSetPickerSmartComponent,
RuleSimpleConditionUiComponent,
RuleTriggersUiComponent,
RuleOptionsUiComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,22 @@
class="aca-manage-rules__actions-bar__title__breadcrumb"></adf-breadcrumb>
</adf-toolbar-title>

<button
*ngIf="canEditRule(mainRuleSet$ | async)"
data-automation-id="manage-rules-create-button"
mat-flat-button color="primary"
(click)="openCreateUpdateRuleDialog()">
{{ 'ACA_FOLDER_RULES.MANAGE_RULES.TOOLBAR.ACTIONS.CREATE_RULE' | translate }}
</button>
<div class="aca-manage-rules__actions-bar__buttons">
<button
*ngIf="!(mainRuleSet$ | async)"
mat-stroked-button
(click)="openLinkRulesDialog()">
{{ 'ACA_FOLDER_RULES.MANAGE_RULES.TOOLBAR.ACTIONS.LINK_RULES' | translate }}
</button>

<button
*ngIf="canEditRule(mainRuleSet$ | async)"
data-automation-id="manage-rules-create-button"
mat-flat-button color="primary"
(click)="openCreateUpdateRuleDialog()">
{{ 'ACA_FOLDER_RULES.MANAGE_RULES.TOOLBAR.ACTIONS.CREATE_RULE' | translate }}
</button>
</div>

</adf-toolbar>
<mat-divider></mat-divider>
Expand All @@ -48,7 +57,9 @@
(loadMoreRuleSets)="onLoadMoreRuleSets()"
(loadMoreRules)="onLoadMoreRules($event)"
(selectRule)="onSelectRule($event)"
(ruleEnabledChanged)="onRuleEnabledToggle($event[0], $event[1])">
(ruleEnabledChanged)="onRuleEnabledToggle($event[0], $event[1])"
(ruleSetEditLinkClicked)="openLinkRulesDialog($event)"
(ruleSetUnlinkClicked)="onRuleSetUnlinkClicked($event)">
</aca-rule-list>

<div class="aca-manage-rules__container__rule-details">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
margin-left: 18px;
}
}

&__buttons {
display: flex;
align-items: stretch;
gap: 4px;
}
}

&__container {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { ActionDefinitionTransformed } from '../model/rule-action.model';
import { ActionsService } from '../services/actions.service';
import { FolderRuleSetsService } from '../services/folder-rule-sets.service';
import { RuleSet } from '../model/rule-set.model';
import { RuleSetPickerSmartComponent } from '../rule-set-picker/rule-set-picker.smart-component';

@Component({
selector: 'aca-manage-rules',
Expand Down Expand Up @@ -184,4 +185,45 @@ export class ManageRulesSmartComponent implements OnInit, OnDestroy {
canEditRule(ruleSet: RuleSet): boolean {
return !ruleSet || FolderRuleSetsService.isOwnedRuleSet(ruleSet, this.nodeId);
}

openLinkRulesDialog(existingRuleSet?: RuleSet) {
this.matDialogService
.open(RuleSetPickerSmartComponent, {
width: '90%',
panelClass: 'aca-rule-set-picker-container',
data: {
nodeId: this.nodeId,
defaultNodeId: this.nodeId,
existingRuleSet
}
})
.afterClosed()
.subscribe((result) => {
if (result) {
this.folderRuleSetsService.refreshMainRuleSet();
}
});
}

onRuleSetUnlinkClicked(linkedRuleSet: RuleSet) {
this.matDialogService
.open(ConfirmDialogComponent, {
data: {
title: 'ACA_FOLDER_RULES.CONFIRMATION_DIALOG.DELETE_RULE_SET_LINK.TITLE',
message: 'ACA_FOLDER_RULES.CONFIRMATION_DIALOG.DELETE_RULE_SET_LINK.MESSAGE'
},
minWidth: '346px'
})
.afterClosed()
.subscribe(async (result) => {
if (result) {
try {
await this.folderRuleSetsService.deleteRuleSetLink(this.nodeId, linkedRuleSet.id);
this.folderRuleSetsService.refreshMainRuleSet();
} catch (error) {
this.notificationService.showError('ACA_FOLDER_RULES.ERRORS.DELETE_RULE_SET_LINK_FAILED');
}
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import { timer } from 'rxjs';

describe('EditRuleDialogSmartComponent', () => {
let fixture: ComponentFixture<EditRuleDialogSmartComponent>;
let actionsService: ActionsService;

const dialogRef = {
close: jasmine.createSpy('close'),
Expand All @@ -64,9 +63,8 @@ describe('EditRuleDialogSmartComponent', () => {
]
});

actionsService = TestBed.inject(ActionsService);
spyOn(actionsService, 'loadActionDefinitions').and.stub();
spyOn(actionsService, 'getParameterConstraints').and.stub();
spyOn(ActionsService.prototype, 'loadActionDefinitions').and.stub();
spyOn(ActionsService.prototype, 'getParameterConstraints').and.stub();

fixture = TestBed.createComponent(EditRuleDialogSmartComponent);
fixture.detectChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export interface EditRuleDialogOptions {
templateUrl: './edit-rule-dialog.smart-component.html',
styleUrls: ['./edit-rule-dialog.smart-component.scss'],
encapsulation: ViewEncapsulation.None,
host: { class: 'aca-edit-rule-dialog' }
host: { class: 'aca-edit-rule-dialog' },
providers: [{ provide: ActionsService, useClass: ActionsService }]
})
export class EditRuleDialogSmartComponent implements OnInit, OnDestroy {
formValid = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
tabindex="0"
[rule]="item.rule"
[isSelected]="isSelected(item.rule)"
[showEnabledToggle]="showEnabledToggles"
(click)="onRuleClicked(item.rule)"
(enabledChanged)="onEnabledChanged(item.rule, $event)">
</aca-rule-list-item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@ describe('RuleListGroupingUiComponent', () => {
const rule = debugElement.query(By.css('.aca-rule-list-item:first-child'));
const name = rule.query(By.css('.aca-rule-list-item__header__name'));
const description = rule.query(By.css('.aca-rule-list-item__description'));
const toggleBtn = rule.query(By.css('mat-slide-toggle'));

expect(name.nativeElement.textContent).toBe(rulesMock[0].name);
expect(toggleBtn).toBeTruthy();
expect(description.nativeElement.textContent).toBe(rulesMock[0].description);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export class RuleListGroupingUiComponent {
items: RuleGroupingItem[] = [];
@Input()
selectedRule: Rule = null;
@Input()
showEnabledToggles = false;

@Output()
selectRule = new EventEmitter<Rule>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<span class="aca-rule-list-item__header__name">{{ rule.name }}</span>

<mat-slide-toggle
*ngIf="showEnabledToggle"
[checked]="rule.isEnabled"
(click)="onToggleClick(!rule.isEnabled, $event)">
</mat-slide-toggle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export class RuleListItemUiComponent {
@Input()
@HostBinding('class.selected')
isSelected: boolean;
@Input()
showEnabledToggle = false;

@Output()
enabledChanged = new EventEmitter<boolean>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,22 @@
data-automation-id="rule-list-item"
[ngClass]="{ expanded: inheritedRuleSetsExpanded }">

<div class="aca-rule-list__item__header">
<div
tabindex="0"
class="aca-rule-list__item__header"
matRipple matRippleColor="hsla(0,0%,0%,0.05)"
(click)="inheritedRuleSetsExpanded = !inheritedRuleSetsExpanded"
(keyup.enter)="inheritedRuleSetsExpanded = !inheritedRuleSetsExpanded">

<div
tabindex="0"
class="aca-rule-list__item__header__title"
matRipple matRippleColor="hsla(0,0%,0%,0.05)"
(click)="inheritedRuleSetsExpanded = !inheritedRuleSetsExpanded"
(keyup.enter)="inheritedRuleSetsExpanded = !inheritedRuleSetsExpanded">

<span class="aca-rule-list__item__header__title__text">
{{ 'ACA_FOLDER_RULES.RULE_LIST.INHERITED_RULES' | translate }}
<mat-icon [matTooltip]="'ACA_FOLDER_RULES.RULE_LIST.INHERITED_RULES_WILL_BE_RUN_FIRST' | translate">
info
</mat-icon>
</span>
<mat-icon class="aca-rule-list__item__header__icon">
{{ inheritedRuleSetsExpanded ? 'expand_more' : 'chevron_right' }}
<span class="aca-rule-list__item__header__title">
{{ 'ACA_FOLDER_RULES.RULE_LIST.INHERITED_RULES' | translate }}
<mat-icon [matTooltip]="'ACA_FOLDER_RULES.RULE_LIST.INHERITED_RULES_WILL_BE_RUN_FIRST' | translate">
info
</mat-icon>
</div>

</span>
<mat-icon class="aca-rule-list__item__header__icon">
{{ inheritedRuleSetsExpanded ? 'expand_more' : 'chevron_right' }}
</mat-icon>
</div>

<aca-rule-list-grouping
Expand All @@ -44,34 +40,37 @@
data-automation-id="rule-list-item"
[ngClass]="{ expanded: mainRuleSetExpanded }">

<div class="aca-rule-list__item__header">

<div
tabindex="0"
class="aca-rule-list__item__header__title"
data-automation-id="main-rule-set-title"
matRipple matRippleColor="hsla(0,0%,0%,0.05)"
(click)="mainRuleSetExpanded = !mainRuleSetExpanded"
(keyup.enter)="mainRuleSetExpanded = !mainRuleSetExpanded">
<div
tabindex="0"
class="aca-rule-list__item__header"
matRipple matRippleColor="hsla(0,0%,0%,0.05)"
(click)="mainRuleSetExpanded = !mainRuleSetExpanded"
(keyup.enter)="mainRuleSetExpanded = !mainRuleSetExpanded">

<span class="aca-rule-list__item__header__title" data-automation-id="main-rule-set-title">
<ng-container *ngIf="isMainRuleSetOwned; else linkedRuleSet">
{{ 'ACA_FOLDER_RULES.RULE_LIST.OWNED_RULES' | translate }}
</ng-container>
<ng-template #linkedRuleSet>
{{ 'ACA_FOLDER_RULES.RULE_LIST.LINKED_RULES' | translate }}
</ng-template>
</span>

<mat-icon class="aca-rule-list__item__header__icon">
{{ mainRuleSetExpanded ? 'expand_more' : 'chevron_right' }}
</mat-icon>
</div>
<ng-container *ngIf="!isMainRuleSetOwned">
<mat-icon class="aca-rule-list__item__header__icon" (click)="onRuleSetEditLinkClicked($event)">edit</mat-icon>
<mat-icon class="aca-rule-list__item__header__icon" (click)="onRuleSetUnlinkClicked($event)">link_off</mat-icon>
</ng-container>

<mat-icon class="aca-rule-list__item__header__icon">
{{ mainRuleSetExpanded ? 'expand_more' : 'chevron_right' }}
</mat-icon>
</div>

<aca-rule-list-grouping
*ngIf="mainRuleSetExpanded"
[items]="mainRuleSetGroupingItems"
[selectedRule]="selectedRule"
[showEnabledToggles]="isMainRuleSetOwned"
(selectRule)="onSelectRule($event)"
(ruleEnabledChanged)="onRuleEnabledChanged($event)"
(loadMoreRules)="onLoadMoreRules($event)">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,29 @@
&__header {
display: flex;
flex-direction: row;
gap: 4px;
align-items: stretch;
cursor: pointer;
color: var(--theme-text-color);
user-select: none;
font-size: 0.9em;
padding: 0.5em 1em;

& > * {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
}

&__title {
padding: 0.5em 1em;
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-start;
flex: 1;

&__text {
display: flex;
flex-direction: row;
align-items: center;

.mat-icon {
transform: scale(0.8);
}
.mat-icon {
transform: scale(0.8);
}
}
}
Expand Down

0 comments on commit d9d2441

Please sign in to comment.