alfresco-ng2-components/demo-shell/src/app/components/cloud/people-groups-cloud-demo.component.ts
Maurizio Vitale e27833d770
[AAE-9019] - People/Group cloud with HxP (#7658)
* Cover the use cases by mocking them

* Replace the mock with real stream and remove useless code

* Provide new service to fetch groups

* Fix group tests

* Use the interface and token injection

* [AAE-8870] add unit test and mock for new service

* Improve roles condifion

* initialize the stream as part of NgOnInit to be sure it relies on the correct FormControl instance(input)

* Rollback tmp change for roles

* [AAE-8641] people abstraction mock

* [AAE-8641] revert angular.json changes

* [AAE-8641] few conditions and code improvements

* [AAE-8641] revert change input controls name

* [AAE-8641] initialize the stream as part of ngOnInit

* [AAE-8641] people abstraction improvements

* [AAE-8870] cherry pick people abstraction

* [AAE-8641] fix people-group e2es

* fix lint

* remove hardcoded identityHost

* Use the identityhost api in case of cloud

* Solve issue with returnType array string

* Rebase and use GroupModel from cloud

* Rebase and use GroupModel from cloud

* Use the bpmHost instead of identityFor

* Add identity ingress for user access service

* Rename test

* Fix linting issues

* Fix playwright storybook e2e for people and group

* Trigger travis

* Fix people group e2e

* improved formatting

* Remove not needed travis var override

* Remove unused import after rebase

* Make roles in filter optional + remove comments

Co-authored-by: Tomasz <tomasz.gnyp@hyland.com>
Co-authored-by: arditdomi <ardit.domi@hyland.com>
2022-06-28 16:21:59 +01:00

165 lines
4.9 KiB
TypeScript

/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Component, ViewEncapsulation } from '@angular/core';
import { ComponentSelectionMode, IdentityUserModel, IdentityGroupModel } from '@alfresco/adf-process-services-cloud';
import { MatCheckboxChange } from '@angular/material/checkbox';
import { MatRadioChange } from '@angular/material/radio';
@Component({
selector: 'app-people-groups-cloud',
templateUrl: './people-groups-cloud-demo.component.html',
styleUrls: ['./people-groups-cloud-demo.component.scss'],
encapsulation: ViewEncapsulation.None
})
export class PeopleGroupCloudDemoComponent {
defaultFilterMode: string = 'appName';
defaultGroupPlaceholder: string = `[{"id": "1", "name":"activitiUserGroup"}]`;
defaultPeoplePlaceholder: string = `[{"id": "1", email": "user@user.com", "firstName":"user", "lastName": "lastName", "username": "user"}]`;
peopleMode: ComponentSelectionMode = 'single';
preSelectUsers: IdentityUserModel[] = [];
invalidUsers: IdentityUserModel[] = [];
peopleRoles: string[] = [];
groupsRestriction: string[] = [];
peopleAppName: string;
peopleFilterMode: string = this.defaultFilterMode;
peoplePreselectValidation = false;
groupPreselectValidation = false;
peopleReadonly = false;
groupReadonly = false;
groupMode: ComponentSelectionMode = 'single';
preSelectGroup: IdentityGroupModel[] = [];
invalidGroups: IdentityGroupModel[] = [];
groupRoles: string[];
groupAppName: string;
groupFilterMode: string = this.defaultFilterMode;
setPeoplePreselectValue(value: string): void {
this.preSelectUsers = this.getArrayFromString(value);
}
setGroupsPreselectValue(value: string): void {
this.preSelectGroup = this.getArrayFromString(value);
}
setPeopleRoles(value: string): void {
this.peopleRoles = this.getArrayFromString(value);
}
setGroupRoles(value: string): void {
this.groupRoles = this.getArrayFromString(value);
}
setPeopleAppName(value: string): void {
this.peopleAppName = value;
}
setGroupAppName(value: string): void {
this.groupAppName = value;
}
setPeopleGroupsRestriction(value: string): void {
this.groupsRestriction = this.getArrayFromString(value);
}
onChangePeopleMode(event: MatRadioChange): void {
this.peopleMode = event.value;
}
onChangePeopleReadonly(event: MatCheckboxChange): void {
this.peopleReadonly = event.checked;
}
onChangeGroupReadonly(event: MatCheckboxChange): void {
this.groupReadonly = event.checked;
}
onChangeGroupsMode(event: MatRadioChange): void {
this.groupMode = event.value;
}
onChangePeopleFilterMode(event: MatRadioChange): void {
this.peopleFilterMode = event.value;
this.resetPeopleFilter();
}
onChangeGroupsFilterMode(event: MatRadioChange): void {
this.groupFilterMode = event.value;
this.restGroupFilter();
}
isPeopleAppNameSelected(): boolean {
return this.peopleFilterMode === 'appName';
}
isGroupAppNameSelected(): boolean {
return this.groupFilterMode === 'appName';
}
resetPeopleFilter(): void {
if (this.isPeopleAppNameSelected()) {
this.peopleRoles = [];
} else {
this.peopleAppName = '';
}
}
restGroupFilter(): void {
if (this.isGroupAppNameSelected()) {
this.groupRoles = [];
} else {
this.groupAppName = '';
}
}
onChangePeopleValidation(event: MatCheckboxChange): void {
this.peoplePreselectValidation = event.checked;
}
onChangeGroupValidation(event: MatCheckboxChange): void {
this.groupPreselectValidation = event.checked;
}
onGroupsWarning(warning: any): void {
this.invalidGroups = warning.groups;
}
onUsersWarning(warning: any): void {
this.invalidUsers = warning.users;
}
isStringArray(str: string): boolean {
try {
const result = JSON.parse(str);
return Array.isArray(result);
} catch (e) {
return false;
}
}
private getArrayFromString<T = any>(value: string): T[] {
if (this.isStringArray(value)) {
return JSON.parse(value);
} else {
return [];
}
}
}