[AAE-1351] [GroupCloudComponent] Validate pre-selected groups (#5353)

* * Added an input flag to validate preselected groups.
* Modified demo shell groups page.

* * Added unit tests to the recent changes.

* * Fixed comments
This commit is contained in:
siva kumar
2020-01-03 15:59:29 +05:30
committed by Maurizio Vitale
parent 12d068c228
commit 68df1ad440
5 changed files with 277 additions and 30 deletions

View File

@@ -40,16 +40,29 @@
[appName]="peopleAppName"
[roles]="peopleRoles"
[title]="'ADF_TASK_LIST.START_TASK.FORM.LABEL.ASSIGNEE'"
[mode]="peopleMode"></adf-cloud-people>
[mode]="peopleMode"
(selectUser)="onSelectUser($event)"
(warning)="onUsersWarning($event)"></adf-cloud-people>
</div>
<div class="app-people-list" *ngIf="canShowPeopleList()">
<h4>{{ 'PEOPLE_GROUPS_CLOUD.ALL_SELECTED_USERS' | translate }}</h4>
<mat-list role="list">
<mat-list-item *ngFor="let item of preSelectUsers" role="listitem">
<mat-icon mat-list-icon>person</mat-icon>
{{ item?.firstName }} {{ item?.lastName }}
{{item | fullName}}
</mat-list-item>
</mat-list>
<div *ngIf="invalidUsers.length > 0">
<h4>{{ 'PEOPLE_GROUPS_CLOUD.INVALID_USERS' | translate }} <mat-icon>warning</mat-icon> </h4>
<mat-list role="list">
<mat-list-item *ngFor="let invalidUser of invalidUsers" role="listitem">
<mat-icon mat-list-icon>person</mat-icon>
{{invalidUser | fullName}}
</mat-list-item>
</mat-list>
</div>
</div>
</mat-card-content>
</mat-card>
@@ -86,19 +99,39 @@
<mat-label>Preselect: {{ DEFAULT_GROUP_PLACEHOLDER }}</mat-label>
<input matInput (input)="setGroupsPreselectValue($event)" data-automation-id="app-group-preselect-input" />
</mat-form-field>
<mat-checkbox class="app-group-preselect-validation" (change)="onChangeGroupValidation($event)">{{
'PEOPLE_GROUPS_CLOUD.PRESELECT_VALIDATION' | translate }}</mat-checkbox>
</div>
<div>
<adf-cloud-group [mode]="groupMode" [roles]="groupRoles" [appName]="groupAppName" [preSelectGroups]="preSelectGroup"
(selectGroup)="onSelectGroup($event)" (removeGroup)="onRemoveGroup($event)"></adf-cloud-group>
<adf-cloud-group
[mode]="groupMode"
[validate]="groupPreselectValidation"
[roles]="groupRoles"
[appName]="groupAppName"
[preSelectGroups]="preSelectGroup"
(selectGroup)="onSelectGroup($event)"
(removeGroup)="onRemoveGroup($event)"
(warning)="onGroupsWarning($event)"></adf-cloud-group>
</div>
<div class="app-group-list" *ngIf="canShowGroupList()">
<h4>{{ 'PEOPLE_GROUPS_CLOUD.ALL_SELECTED_GROUPS' | translate }}</h4>
<mat-list role="list">
<mat-list-item *ngFor="let item of preSelectGroup" role="listitem">
<mat-icon mat-list-icon>group</mat-icon>
{{ item.name }}
</mat-list-item>
</mat-list>
<div *ngIf="invalidGroups.length > 0">
<h4>{{ 'PEOPLE_GROUPS_CLOUD.INVALID_GROUPS' | translate }} <mat-icon>warning</mat-icon> </h4>
<mat-list role="list">
<mat-list-item *ngFor="let invalidGroup of invalidGroups" role="listitem">
<mat-icon mat-list-icon>group</mat-icon>
{{invalidGroup?.name}}
</mat-list-item>
</mat-list>
</div>
</div>
</mat-card-content>
</mat-card>

View File

@@ -18,7 +18,7 @@
import { Component, ViewEncapsulation } from '@angular/core';
import { PeopleCloudComponent, GroupCloudComponent } from '@alfresco/adf-process-services-cloud';
import { MatRadioChange, MatCheckboxChange } from '@angular/material';
import { IdentityGroupModel } from '@alfresco/adf-core';
import { IdentityGroupModel, IdentityUserModel } from '@alfresco/adf-core';
@Component({
selector: 'app-people-groups-cloud',
@@ -33,14 +33,17 @@ export class PeopleGroupCloudDemoComponent {
DEFAULT_PEOPLE_PLACEHOLDER: string = `[{"id": "1", email": "user@user.com", "firstName":"user", "lastName": "lastName", "username": "user"}]`;
peopleMode: string = PeopleCloudComponent.MODE_SINGLE;
preSelectUsers: string[] = [];
preSelectUsers: IdentityUserModel[] = [];
invalidUsers: IdentityGroupModel[] = [];
peopleRoles: string[] = [];
peopleAppName: string;
peopleFilterMode: string = this.DEFAULT_FILTER_MODE;
peoplePreselectValidation: Boolean = false;
groupPreselectValidation = false;
groupMode: string = GroupCloudComponent.MODE_SINGLE;
preSelectGroup: IdentityGroupModel[] = [];
invalidGroups: IdentityGroupModel[] = [];
selectedGroupList: IdentityGroupModel[] = [];
groupRoles: string[];
groupAppName: string;
@@ -117,6 +120,25 @@ export class PeopleGroupCloudDemoComponent {
onChangePeopleValidation(event: MatCheckboxChange) {
this.peoplePreselectValidation = event.checked;
this.preSelectUsers = [...this.preSelectUsers];
if (!this.peoplePreselectValidation) {
this.invalidUsers = [];
}
}
onChangeGroupValidation(event: MatCheckboxChange) {
this.groupPreselectValidation = event.checked;
this.preSelectGroup = [...this.preSelectGroup];
if (!this.groupPreselectValidation) {
this.invalidGroups = [];
}
}
onGroupsWarning(warning: any) {
this.invalidGroups = warning.groups;
}
onUsersWarning(warning: any) {
this.invalidUsers = warning.users;
}
isStringArray(str: string) {
@@ -149,6 +171,12 @@ export class PeopleGroupCloudDemoComponent {
this.preSelectGroup = this.preSelectGroup.filter((value: any) => value.id !== group.id);
}
onSelectUser(user: IdentityUserModel) {
if (this.peopleMode === PeopleCloudComponent.MODE_MULTIPLE) {
this.preSelectUsers.push(user);
}
}
onSelectGroup(group: IdentityGroupModel) {
if (this.groupMode === GroupCloudComponent.MODE_MULTIPLE) {
this.preSelectGroup.push(group);