mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-09-17 14:21:14 +00:00
[ACS-3513] [ACS-3515] Create, edit and delete rule set link (#2810)
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
<div mat-dialog-title class="aca-rule-set-picker__header">
|
||||
<div class="aca-rule-set-picker__header__title">
|
||||
{{ 'ACA_FOLDER_RULES.LINK_RULES_DIALOG.TITLE' | translate }}
|
||||
</div>
|
||||
<button mat-icon-button mat-dialog-close class="aca-rule-set-picker__header__close" tabindex="-1">
|
||||
<mat-icon>close</mat-icon>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<mat-dialog-content class="aca-rule-set-picker__content">
|
||||
<adf-content-node-selector-panel
|
||||
class="aca-rule-set-picker__content__node-selector"
|
||||
[currentFolderId]="defaultNodeId"
|
||||
(select)="onNodeSelect($event)"
|
||||
(folderLoaded)="setFolderLoading(false)"
|
||||
(navigationChange)="setFolderLoading(true)"
|
||||
(siteChange)="setFolderLoading(true)">
|
||||
</adf-content-node-selector-panel>
|
||||
|
||||
<div class="aca-rule-set-picker__content__rule-list" [ngClass]="{ justify: rulesLoading$ | async }">
|
||||
<ng-container *ngIf="rulesLoading$ | async; else rulesLoaded">
|
||||
<mat-progress-spinner color="primary" mode="indeterminate"></mat-progress-spinner>
|
||||
</ng-container>
|
||||
|
||||
<ng-template #rulesLoaded>
|
||||
<ng-container *ngIf="hasOwnedRules(mainRuleSet$ | async); else noOwnedRules">
|
||||
<div class="aca-rule-set-picker__content__rule-list__header">
|
||||
{{ 'ACA_FOLDER_RULES.LINK_RULES_DIALOG.LIST_OF_RULES_TO_LINK' | translate }}
|
||||
</div>
|
||||
|
||||
<aca-rule-list-item
|
||||
*ngFor="let rule of (mainRuleSet$ | async).rules"
|
||||
[rule]="rule">
|
||||
</aca-rule-list-item>
|
||||
</ng-container>
|
||||
|
||||
<ng-template #noOwnedRules>
|
||||
<adf-empty-content
|
||||
icon="library_books"
|
||||
[title]="'ACA_FOLDER_RULES.LINK_RULES_DIALOG.EMPTY_RULES_LIST.TITLE' | translate"
|
||||
[subtitle]="'ACA_FOLDER_RULES.LINK_RULES_DIALOG.EMPTY_RULES_LIST.SUBTITLE' | translate">
|
||||
</adf-empty-content>
|
||||
</ng-template>
|
||||
</ng-template>
|
||||
</div>
|
||||
</mat-dialog-content>
|
||||
|
||||
<mat-dialog-actions align="end" class="aca-rule-set-picker__footer">
|
||||
<button mat-flat-button mat-dialog-close>
|
||||
{{ 'ACA_FOLDER_RULES.LINK_RULES_DIALOG.CANCEL' | translate }}
|
||||
</button>
|
||||
|
||||
<button
|
||||
mat-flat-button color="primary"
|
||||
[disabled]="!hasOwnedRules(mainRuleSet$ | async) || isBusy"
|
||||
(click)="onSubmit()">
|
||||
{{ 'ACA_FOLDER_RULES.LINK_RULES_DIALOG.SUBMIT' | translate }}
|
||||
</button>
|
||||
</mat-dialog-actions>
|
@@ -0,0 +1,76 @@
|
||||
.aca-rule-set-picker-container {
|
||||
--rule-set-picker-padding: 8px 20px;
|
||||
|
||||
.mat-dialog-container {
|
||||
padding: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.aca-rule-set-picker {
|
||||
&__header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin: 0;
|
||||
padding: var(--rule-set-picker-padding);
|
||||
box-sizing: border-box;
|
||||
border-bottom: 1px solid var(--theme-border-color);
|
||||
|
||||
&__title {
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
&__close {
|
||||
& mat-icon {
|
||||
font-size: 18px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&__content {
|
||||
position: relative;
|
||||
height: 80vh;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: grid;
|
||||
grid-template-columns: 2fr minmax(250px, 1fr);
|
||||
|
||||
&__node-selector {
|
||||
padding: 0 20px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
&__rule-list {
|
||||
padding: 0 20px 0 0;
|
||||
display: flex;
|
||||
align-items: stretch;
|
||||
flex-direction: column;
|
||||
max-height: 100%;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
|
||||
&.justify {
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
&__header {
|
||||
color: var(--theme-text-color);
|
||||
font-size: 0.9em;
|
||||
margin: 8px 0;
|
||||
}
|
||||
|
||||
.aca-rule-list-item {
|
||||
cursor: default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&__footer {
|
||||
margin: 0;
|
||||
padding: var(--rule-set-picker-padding);
|
||||
box-sizing: border-box;
|
||||
border-top: 1px solid var(--theme-border-color);
|
||||
}
|
||||
}
|
@@ -0,0 +1,116 @@
|
||||
/*!
|
||||
* @license
|
||||
* Alfresco Example Content Application
|
||||
*
|
||||
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
||||
*
|
||||
* This file is part of the Alfresco Example Content Application.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Component, Inject, 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 { NotificationService } from '@alfresco/adf-core';
|
||||
|
||||
export interface RuleSetPickerOptions {
|
||||
nodeId: string;
|
||||
defaultNodeId: string;
|
||||
existingRuleSet?: RuleSet;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'aca-rule-set-picker',
|
||||
templateUrl: './rule-set-picker.smart-component.html',
|
||||
styleUrls: ['./rule-set-picker.smart-component.scss'],
|
||||
encapsulation: ViewEncapsulation.None,
|
||||
host: { class: 'aca-rule-set-picker' },
|
||||
providers: [
|
||||
{
|
||||
provide: FolderRuleSetsService,
|
||||
useClass: FolderRuleSetsService
|
||||
}
|
||||
]
|
||||
})
|
||||
export class RuleSetPickerSmartComponent {
|
||||
nodeId = '-root-';
|
||||
defaultNodeId = '-root-';
|
||||
isBusy = false;
|
||||
existingRuleSet: RuleSet = null;
|
||||
|
||||
private selectedNodeId = '';
|
||||
private folderLoading$ = new BehaviorSubject<boolean>(true);
|
||||
|
||||
mainRuleSet$ = this.folderRuleSetsService.mainRuleSet$;
|
||||
rulesLoading$ = combineLatest(this.folderRuleSetsService.isLoading$, this.folderLoading$).pipe(
|
||||
map(([rulesLoading, folderLoading]) => rulesLoading || folderLoading)
|
||||
);
|
||||
|
||||
constructor(
|
||||
@Inject(MAT_DIALOG_DATA) public data: RuleSetPickerOptions,
|
||||
private folderRuleSetsService: FolderRuleSetsService,
|
||||
private dialogRef: MatDialogRef<RuleSetPickerSmartComponent>,
|
||||
private notificationService: NotificationService
|
||||
) {
|
||||
this.nodeId = this.data?.nodeId ?? '-root-';
|
||||
this.defaultNodeId = this.data?.defaultNodeId ?? '-root-';
|
||||
this.existingRuleSet = this.data?.existingRuleSet ?? null;
|
||||
}
|
||||
|
||||
hasOwnedRules(ruleSet: RuleSet): boolean {
|
||||
return ruleSet?.rules.length > 0 && FolderRuleSetsService.isOwnedRuleSet(ruleSet, this.selectedNodeId);
|
||||
}
|
||||
|
||||
onNodeSelect(nodes: Node[]) {
|
||||
if (nodes?.length && nodes[0].isFolder && nodes[0].id !== this.selectedNodeId) {
|
||||
this.selectedNodeId = nodes[0].id;
|
||||
this.folderRuleSetsService.loadRuleSets(this.selectedNodeId, false);
|
||||
}
|
||||
}
|
||||
|
||||
setFolderLoading(isLoading: boolean) {
|
||||
this.folderLoading$.next(isLoading);
|
||||
}
|
||||
|
||||
onSubmit() {
|
||||
this.isBusy = true;
|
||||
from(this.existingRuleSet ? this.folderRuleSetsService.deleteRuleSetLink(this.nodeId, this.existingRuleSet.id) : of(null))
|
||||
.pipe(
|
||||
switchMap(() => from(this.folderRuleSetsService.createRuleSetLink(this.nodeId, this.selectedNodeId))),
|
||||
finalize(() => {
|
||||
this.isBusy = false;
|
||||
})
|
||||
)
|
||||
.subscribe(
|
||||
() => {
|
||||
this.dialogRef.close(true);
|
||||
},
|
||||
() => {
|
||||
this.handleError();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private handleError() {
|
||||
this.notificationService.showError('ACA_FOLDER_RULES.LINK_RULES_DIALOG.ERRORS.REQUEST_FAILED');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user