mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-4038] People/GroupCloudDemo - add appName filter (#4283)
* [ADF-4038] - People/Group Cloud Component add app name filter * [ADF-4038] add unit test, modify ngOnChange appName condition * [ADF-4038] People/GroupCloudDemo - add radio button to filter application name or roles
This commit is contained in:
committed by
Eugenio Romano
parent
8901261ec9
commit
898d62477e
@@ -293,7 +293,10 @@
|
|||||||
"SINGLE": "Single Selection",
|
"SINGLE": "Single Selection",
|
||||||
"MULTI": "Multiple Selection",
|
"MULTI": "Multiple Selection",
|
||||||
"PRESELECTED_VALUE": "Preselect: ",
|
"PRESELECTED_VALUE": "Preselect: ",
|
||||||
"ROLE": "Roles: "
|
"ROLE": "Roles: ",
|
||||||
|
"APP_NAME": "Aplication Name",
|
||||||
|
"APP_FILTER_MODE": "Filter by application name",
|
||||||
|
"ROLE_FILTER_MODE": "Filter by role"
|
||||||
},
|
},
|
||||||
"ABOUT": {
|
"ABOUT": {
|
||||||
"TITLE": "Plugins",
|
"TITLE": "Plugins",
|
||||||
|
@@ -12,17 +12,27 @@
|
|||||||
'PEOPLE_GROUPS_CLOUD.MULTI' | translate }}</mat-radio-button>
|
'PEOPLE_GROUPS_CLOUD.MULTI' | translate }}</mat-radio-button>
|
||||||
</mat-radio-group>
|
</mat-radio-group>
|
||||||
<div class="people-control-options">
|
<div class="people-control-options">
|
||||||
<mat-form-field class="adf-preselect-value">
|
<mat-radio-group (change)="onChangePeopleFilterMode($event)">
|
||||||
|
<mat-radio-button checked="true" class="adf-people-single-mode" value="appName">{{
|
||||||
|
'PEOPLE_GROUPS_CLOUD.APP_FILTER_MODE' | translate }}</mat-radio-button>
|
||||||
|
<mat-radio-button class="adf-people-multiple-mode" value="role">{{
|
||||||
|
'PEOPLE_GROUPS_CLOUD.ROLE_FILTER_MODE' | translate }}</mat-radio-button>
|
||||||
|
</mat-radio-group>
|
||||||
|
<mat-form-field *ngIf="!isPeopleAppNameSelected()" class="adf-preselect-value">
|
||||||
<mat-label>{{ 'PEOPLE_GROUPS_CLOUD.ROLE' | translate }} ['ACTIVITI_ADMIN', "ACTIVITI_USER"]</mat-label>
|
<mat-label>{{ 'PEOPLE_GROUPS_CLOUD.ROLE' | translate }} ['ACTIVITI_ADMIN', "ACTIVITI_USER"]</mat-label>
|
||||||
<input matInput (input)="setPeopleRoles($event)" />
|
<input matInput (input)="setPeopleRoles($event)" />
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
<mat-form-field class="adf-preselect-value full">
|
<mat-form-field *ngIf="isPeopleAppNameSelected()" class="adf-preselect-value">
|
||||||
|
<mat-label>{{ 'PEOPLE_GROUPS_CLOUD.APP_NAME' | translate }}</mat-label>
|
||||||
|
<input matInput (input)="setPeopleAppName($event)" />
|
||||||
|
</mat-form-field>
|
||||||
|
<mat-form-field class="adf-preselect-value-full">
|
||||||
<mat-label>{{ 'PEOPLE_GROUPS_CLOUD.PRESELECTED_VALUE' | translate }}: {{ DEFAULT_PEOPLE_PLACEHOLDER }}</mat-label>
|
<mat-label>{{ 'PEOPLE_GROUPS_CLOUD.PRESELECTED_VALUE' | translate }}: {{ DEFAULT_PEOPLE_PLACEHOLDER }}</mat-label>
|
||||||
<input matInput (input)="setPeoplePreselectValue($event)" />
|
<input matInput (input)="setPeoplePreselectValue($event)" />
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<adf-cloud-people [preSelectUsers]="preSelectUsers" [roles]="peopleRoles" [mode]="peopleMode"></adf-cloud-people>
|
<adf-cloud-people [preSelectUsers]="preSelectUsers" [appName]="peopleAppName" [roles]="peopleRoles" [mode]="peopleMode"></adf-cloud-people>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="adf-people-list" *ngIf="canShowPeopleList()">
|
<div class="adf-people-list" *ngIf="canShowPeopleList()">
|
||||||
@@ -50,18 +60,28 @@
|
|||||||
'PEOPLE_GROUPS_CLOUD.MULTI' | translate }}</mat-radio-button>
|
'PEOPLE_GROUPS_CLOUD.MULTI' | translate }}</mat-radio-button>
|
||||||
</mat-radio-group>
|
</mat-radio-group>
|
||||||
<div class="groups-control-options">
|
<div class="groups-control-options">
|
||||||
<mat-form-field class="adf-preselect-value">
|
<mat-radio-group (change)="onChangeGroupsFilterMode($event)">
|
||||||
|
<mat-radio-button checked="true" class="adf-people-single-mode" value="appName">{{
|
||||||
|
'PEOPLE_GROUPS_CLOUD.APP_FILTER_MODE' | translate }}</mat-radio-button>
|
||||||
|
<mat-radio-button class="adf-people-multiple-mode" value="role">{{
|
||||||
|
'PEOPLE_GROUPS_CLOUD.ROLE_FILTER_MODE' | translate }}</mat-radio-button>
|
||||||
|
</mat-radio-group>
|
||||||
|
<mat-form-field *ngIf="!isGroupAppNameSelected()" class="adf-preselect-value">
|
||||||
<mat-label>{{ 'PEOPLE_GROUPS_CLOUD.ROLE' | translate }} ['ACTIVITI_ADMIN', "ACTIVITI_USER"]</mat-label>
|
<mat-label>{{ 'PEOPLE_GROUPS_CLOUD.ROLE' | translate }} ['ACTIVITI_ADMIN', "ACTIVITI_USER"]</mat-label>
|
||||||
<input matInput (input)="setGroupRoles($event)" />
|
<input matInput (input)="setGroupRoles($event)" />
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
<mat-form-field class="adf-preselect-value full">
|
<mat-form-field *ngIf="isGroupAppNameSelected()" class="adf-preselect-value">
|
||||||
|
<mat-label>{{ 'PEOPLE_GROUPS_CLOUD.APP_NAME' | translate }}</mat-label>
|
||||||
|
<input matInput (input)="setGroupAppName($event)" />
|
||||||
|
</mat-form-field>
|
||||||
|
<mat-form-field class="adf-preselect-value-full">
|
||||||
<mat-label>Preselect: {{ DEFAULT_GROUP_PLACEHOLDER }}</mat-label>
|
<mat-label>Preselect: {{ DEFAULT_GROUP_PLACEHOLDER }}</mat-label>
|
||||||
<input matInput (input)="setGroupsPreselectValue($event)" />
|
<input matInput (input)="setGroupsPreselectValue($event)" />
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<adf-cloud-group [mode]="groupMode" [roles]="groupRoles" [preSelectGroups]="preSelectGroup" (selectGroup)="onSelectGroup($event)"
|
<adf-cloud-group [mode]="groupMode" [roles]="groupRoles" [appName]="groupAppName" [preSelectGroups]="preSelectGroup"
|
||||||
(removeGroup)="onRemoveGroup($event)"></adf-cloud-group>
|
(selectGroup)="onSelectGroup($event)" (removeGroup)="onRemoveGroup($event)"></adf-cloud-group>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="adf-group-list" *ngIf="canShowGroupList()">
|
<div class="adf-group-list" *ngIf="canShowGroupList()">
|
||||||
|
@@ -18,9 +18,13 @@
|
|||||||
margin-right: 15px;
|
margin-right: 15px;
|
||||||
min-width: 330px;
|
min-width: 330px;
|
||||||
|
|
||||||
&-full {
|
&-big {
|
||||||
width:60%;
|
width:60%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&-full {
|
||||||
|
width:100%;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -27,17 +27,22 @@ import { MatRadioChange } from '@angular/material';
|
|||||||
})
|
})
|
||||||
export class PeopleGroupCloudDemoComponent {
|
export class PeopleGroupCloudDemoComponent {
|
||||||
|
|
||||||
|
DEFAULT_FILTER_MODE: string = 'appName';
|
||||||
DEFAULT_GROUP_PLACEHOLDER: string = `[{"id": "1", "name":"activitiUserGroup"}]`;
|
DEFAULT_GROUP_PLACEHOLDER: string = `[{"id": "1", "name":"activitiUserGroup"}]`;
|
||||||
DEFAULT_PEOPLE_PLACEHOLDER: string = `[{"email": "example@alfresco.com", "firstName":"Administrator", "lastName": "ADF"}]`;
|
DEFAULT_PEOPLE_PLACEHOLDER: string = `[{"email": "example@alfresco.com", "firstName":"Administrator", "lastName": "ADF"}]`;
|
||||||
|
|
||||||
peopleMode: string = PeopleCloudComponent.MODE_SINGLE;
|
peopleMode: string = PeopleCloudComponent.MODE_SINGLE;
|
||||||
preSelectUsers: string[] = [];
|
preSelectUsers: string[] = [];
|
||||||
peopleRoles: string[] = [];
|
peopleRoles: string[] = [];
|
||||||
|
peopleAppName: string;
|
||||||
|
peopleFilterMode: string = this.DEFAULT_FILTER_MODE;
|
||||||
|
|
||||||
groupMode: string = GroupCloudComponent.MODE_SINGLE;
|
groupMode: string = GroupCloudComponent.MODE_SINGLE;
|
||||||
preSelectGroup: GroupModel[] = [];
|
preSelectGroup: GroupModel[] = [];
|
||||||
selectedGroupList: GroupModel[] = [];
|
selectedGroupList: GroupModel[] = [];
|
||||||
groupRoles: string[];
|
groupRoles: string[];
|
||||||
|
groupAppName: string;
|
||||||
|
groupFilterMode: string = this.DEFAULT_FILTER_MODE;
|
||||||
|
|
||||||
setPeoplePreselectValue(event: any) {
|
setPeoplePreselectValue(event: any) {
|
||||||
this.preSelectUsers = this.getArrayFromString(event.target.value);
|
this.preSelectUsers = this.getArrayFromString(event.target.value);
|
||||||
@@ -55,6 +60,14 @@ export class PeopleGroupCloudDemoComponent {
|
|||||||
this.groupRoles = this.getArrayFromString(event.target.value);
|
this.groupRoles = this.getArrayFromString(event.target.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setPeopleAppName(event: any) {
|
||||||
|
this.peopleAppName = event.target.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
setGroupAppName(event: any) {
|
||||||
|
this.groupAppName = event.target.value;
|
||||||
|
}
|
||||||
|
|
||||||
onChangePeopleMode(event: MatRadioChange) {
|
onChangePeopleMode(event: MatRadioChange) {
|
||||||
this.peopleMode = event.value;
|
this.peopleMode = event.value;
|
||||||
this.preSelectUsers = [...this.preSelectUsers];
|
this.preSelectUsers = [...this.preSelectUsers];
|
||||||
@@ -65,6 +78,40 @@ export class PeopleGroupCloudDemoComponent {
|
|||||||
this.preSelectGroup = [...this.preSelectGroup];
|
this.preSelectGroup = [...this.preSelectGroup];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onChangePeopleFilterMode(event: MatRadioChange) {
|
||||||
|
this.peopleFilterMode = event.value;
|
||||||
|
this.resetPeopleFilter();
|
||||||
|
}
|
||||||
|
|
||||||
|
onChangeGroupsFilterMode(event: MatRadioChange) {
|
||||||
|
this.groupFilterMode = event.value;
|
||||||
|
this.restGroupFilter();
|
||||||
|
}
|
||||||
|
|
||||||
|
isPeopleAppNameSelected() {
|
||||||
|
return this.peopleFilterMode === 'appName';
|
||||||
|
}
|
||||||
|
|
||||||
|
isGroupAppNameSelected() {
|
||||||
|
return this.groupFilterMode === 'appName';
|
||||||
|
}
|
||||||
|
|
||||||
|
resetPeopleFilter() {
|
||||||
|
if (this.isPeopleAppNameSelected()) {
|
||||||
|
this.peopleRoles = [];
|
||||||
|
} else {
|
||||||
|
this.peopleAppName = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
restGroupFilter() {
|
||||||
|
if (this.isGroupAppNameSelected()) {
|
||||||
|
this.groupRoles = [];
|
||||||
|
} else {
|
||||||
|
this.groupAppName = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
isStringArray(str: string) {
|
isStringArray(str: string) {
|
||||||
try {
|
try {
|
||||||
const result = JSON.parse(str);
|
const result = JSON.parse(str);
|
||||||
|
@@ -26,6 +26,7 @@ import { GroupCloudService } from '../services/group-cloud.service';
|
|||||||
import { setupTestBed, AlfrescoApiServiceMock } from '@alfresco/adf-core';
|
import { setupTestBed, AlfrescoApiServiceMock } from '@alfresco/adf-core';
|
||||||
import { mockGroups } from '../mock/group-cloud.mock';
|
import { mockGroups } from '../mock/group-cloud.mock';
|
||||||
import { GroupModel } from '../models/group.model';
|
import { GroupModel } from '../models/group.model';
|
||||||
|
import { SimpleChange } from '@angular/core';
|
||||||
|
|
||||||
describe('GroupCloudComponent', () => {
|
describe('GroupCloudComponent', () => {
|
||||||
let component: GroupCloudComponent;
|
let component: GroupCloudComponent;
|
||||||
@@ -59,6 +60,9 @@ describe('GroupCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to fetch client id', async(() => {
|
it('should be able to fetch client id', async(() => {
|
||||||
|
component.ngOnChanges( {
|
||||||
|
appName: new SimpleChange(null, component.appName, true)
|
||||||
|
});
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
fixture.whenStable().then(() => {
|
fixture.whenStable().then(() => {
|
||||||
expect(getClientIdByApplicationNameSpy).toHaveBeenCalled();
|
expect(getClientIdByApplicationNameSpy).toHaveBeenCalled();
|
||||||
@@ -291,4 +295,22 @@ describe('GroupCloudComponent', () => {
|
|||||||
expect(checkGroupHasAccessSpy).not.toHaveBeenCalled();
|
expect(checkGroupHasAccessSpy).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
it('should load the clients if appName change', async( () => {
|
||||||
|
component.appName = 'ADF';
|
||||||
|
fixture.detectChanges();
|
||||||
|
fixture.whenStable().then( () => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(getClientIdByApplicationNameSpy).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should filter users if appName change', async(() => {
|
||||||
|
component.appName = 'ADF';
|
||||||
|
fixture.detectChanges();
|
||||||
|
fixture.whenStable().then( () => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(checkGroupHasAccessSpy).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
@@ -107,19 +107,24 @@ export class GroupCloudComponent implements OnInit, OnChanges {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
|
||||||
this.initSearch();
|
this.initSearch();
|
||||||
|
|
||||||
if (this.appName) {
|
|
||||||
this.disableSearch();
|
|
||||||
this.loadClientId();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnChanges(changes: SimpleChanges) {
|
ngOnChanges(changes: SimpleChanges) {
|
||||||
if (changes.preSelectGroups && this.hasPreSelectGroups()) {
|
if (changes.preSelectGroups && this.hasPreSelectGroups()) {
|
||||||
this.loadPreSelectGroups();
|
this.loadPreSelectGroups();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (changes.appName && this.isAppNameChanged(changes.appName)) {
|
||||||
|
this.disableSearch();
|
||||||
|
this.loadClientId();
|
||||||
|
} else {
|
||||||
|
this.enableSearch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private isAppNameChanged(change) {
|
||||||
|
return change.previousValue !== change.currentValue && this.appName && this.appName.length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async loadClientId() {
|
private async loadClientId() {
|
||||||
|
@@ -31,6 +31,7 @@ describe('PeopleCloudComponent', () => {
|
|||||||
let identityService: IdentityUserService;
|
let identityService: IdentityUserService;
|
||||||
let findUsersSpy: jasmine.Spy;
|
let findUsersSpy: jasmine.Spy;
|
||||||
let checkUserHasAccessSpy: jasmine.Spy;
|
let checkUserHasAccessSpy: jasmine.Spy;
|
||||||
|
let loadClientsByApplicationNameSpy: jasmine.Spy;
|
||||||
|
|
||||||
setupTestBed({
|
setupTestBed({
|
||||||
imports: [ProcessServiceCloudTestingModule, StartTaskCloudTestingModule],
|
imports: [ProcessServiceCloudTestingModule, StartTaskCloudTestingModule],
|
||||||
@@ -44,7 +45,7 @@ describe('PeopleCloudComponent', () => {
|
|||||||
identityService = TestBed.get(IdentityUserService);
|
identityService = TestBed.get(IdentityUserService);
|
||||||
findUsersSpy = spyOn(identityService, 'findUsersByName').and.returnValue(of(mockUsers));
|
findUsersSpy = spyOn(identityService, 'findUsersByName').and.returnValue(of(mockUsers));
|
||||||
checkUserHasAccessSpy = spyOn(identityService, 'checkUserHasClientApp').and.returnValue(of(true));
|
checkUserHasAccessSpy = spyOn(identityService, 'checkUserHasClientApp').and.returnValue(of(true));
|
||||||
spyOn(identityService, 'getClientIdByApplicationName').and.returnValue(of('mock-client-id'));
|
loadClientsByApplicationNameSpy = spyOn(identityService, 'getClientIdByApplicationName').and.returnValue(of('mock-client-id'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create PeopleCloudComponent', () => {
|
it('should create PeopleCloudComponent', () => {
|
||||||
@@ -294,4 +295,24 @@ describe('PeopleCloudComponent', () => {
|
|||||||
expect(checkUserHasRoleSpy).not.toHaveBeenCalled();
|
expect(checkUserHasRoleSpy).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
it('should load the clients if appName change', async( () => {
|
||||||
|
component.appName = 'ADF';
|
||||||
|
fixture.detectChanges();
|
||||||
|
fixture.whenStable().then( () => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(loadClientsByApplicationNameSpy).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should filter users if appName change', async(() => {
|
||||||
|
component.appName = '';
|
||||||
|
fixture.detectChanges();
|
||||||
|
component.appName = 'ADF';
|
||||||
|
fixture.detectChanges();
|
||||||
|
fixture.whenStable().then( () => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(checkUserHasAccessSpy).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
@@ -102,17 +102,23 @@ export class PeopleCloudComponent implements OnInit, OnChanges {
|
|||||||
this.selectedUsersSubject = new BehaviorSubject<IdentityUserModel[]>(this.preSelectUsers);
|
this.selectedUsersSubject = new BehaviorSubject<IdentityUserModel[]>(this.preSelectUsers);
|
||||||
this.selectedUsers$ = this.selectedUsersSubject.asObservable();
|
this.selectedUsers$ = this.selectedUsersSubject.asObservable();
|
||||||
this.initSearch();
|
this.initSearch();
|
||||||
|
|
||||||
if (this.appName) {
|
|
||||||
this.disableSearch();
|
|
||||||
this.loadClientId();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnChanges(changes: SimpleChanges) {
|
ngOnChanges(changes: SimpleChanges) {
|
||||||
if (changes.preSelectUsers && this.hasPreSelectUsers()) {
|
if (changes.preSelectUsers && this.hasPreSelectUsers()) {
|
||||||
this.loadPreSelectUsers();
|
this.loadPreSelectUsers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (changes.appName && this.isAppNameChanged(changes.appName)) {
|
||||||
|
this.disableSearch();
|
||||||
|
this.loadClientId();
|
||||||
|
} else {
|
||||||
|
this.enableSearch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private isAppNameChanged(change) {
|
||||||
|
return change.previousValue !== change.currentValue && this.appName && this.appName.length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private initSearch() {
|
private initSearch() {
|
||||||
@@ -202,6 +208,7 @@ export class PeopleCloudComponent implements OnInit, OnChanges {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async loadClientId() {
|
private async loadClientId() {
|
||||||
|
|
||||||
this.clientId = await this.identityUserService.getClientIdByApplicationName(this.appName).toPromise();
|
this.clientId = await this.identityUserService.getClientIdByApplicationName(this.appName).toPromise();
|
||||||
|
|
||||||
if (this.clientId) {
|
if (this.clientId) {
|
||||||
|
Reference in New Issue
Block a user