mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[AAE-6417] [FE] [FORM] preselect the logged user (#7377)
* [AAE-6417] [FE] [FORM] preselect the logged user * [ci:force] force e2e
This commit is contained in:
@@ -74,6 +74,7 @@ export class FormFieldModel extends FormWidgetModel {
|
|||||||
dateDisplayFormat: string = this.defaultDateFormat;
|
dateDisplayFormat: string = this.defaultDateFormat;
|
||||||
selectionType: 'single' | 'multiple' = null;
|
selectionType: 'single' | 'multiple' = null;
|
||||||
rule?: FormFieldRule;
|
rule?: FormFieldRule;
|
||||||
|
selectLoggedUser: boolean;
|
||||||
|
|
||||||
// container model members
|
// container model members
|
||||||
numberOfColumns: number = 1;
|
numberOfColumns: number = 1;
|
||||||
@@ -181,6 +182,7 @@ export class FormFieldModel extends FormWidgetModel {
|
|||||||
this.tooltip = json.tooltip;
|
this.tooltip = json.tooltip;
|
||||||
this.selectionType = json.selectionType;
|
this.selectionType = json.selectionType;
|
||||||
this.rule = json.rule;
|
this.rule = json.rule;
|
||||||
|
this.selectLoggedUser = json.selectLoggedUser;
|
||||||
|
|
||||||
if (json.placeholder && json.placeholder !== '' && json.placeholder !== 'null') {
|
if (json.placeholder && json.placeholder !== '' && json.placeholder !== 'null') {
|
||||||
this.placeholder = json.placeholder;
|
this.placeholder = json.placeholder;
|
||||||
|
@@ -0,0 +1,64 @@
|
|||||||
|
/*!
|
||||||
|
* @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 { CoreTestingModule, FormFieldModel, FormModel, IdentityUserService, setupTestBed } from '@alfresco/adf-core';
|
||||||
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
import { PeopleCloudWidgetComponent } from './people-cloud.widget';
|
||||||
|
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
||||||
|
|
||||||
|
describe('PeopleCloudWidgetComponent', () => {
|
||||||
|
let fixture: ComponentFixture<PeopleCloudWidgetComponent>;
|
||||||
|
let widget: PeopleCloudWidgetComponent;
|
||||||
|
let identityUserService: IdentityUserService;
|
||||||
|
const currentUser = { id: 'id', username: 'user' };
|
||||||
|
const fakeUser = { id: 'fake-id', username: 'fake' };
|
||||||
|
|
||||||
|
setupTestBed({
|
||||||
|
imports: [
|
||||||
|
TranslateModule.forRoot(),
|
||||||
|
CoreTestingModule
|
||||||
|
],
|
||||||
|
declarations: [
|
||||||
|
PeopleCloudWidgetComponent
|
||||||
|
],
|
||||||
|
schemas: [
|
||||||
|
CUSTOM_ELEMENTS_SCHEMA
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
identityUserService = TestBed.inject(IdentityUserService);
|
||||||
|
fixture = TestBed.createComponent(PeopleCloudWidgetComponent);
|
||||||
|
widget = fixture.componentInstance;
|
||||||
|
spyOn(identityUserService, 'getCurrentUserInfo').and.returnValue(fakeUser);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should preselect the current user', () => {
|
||||||
|
widget.field = new FormFieldModel(new FormModel(), { value: null, selectLoggedUser: true });
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(widget.preSelectUsers).toEqual([fakeUser]);
|
||||||
|
expect(identityUserService.getCurrentUserInfo).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not preselect the current user if value exist', () => {
|
||||||
|
widget.field = new FormFieldModel(new FormModel(), { value: [currentUser], selectLoggedUser: true });
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(widget.preSelectUsers).toEqual([currentUser]);
|
||||||
|
expect(identityUserService.getCurrentUserInfo).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
@@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
|
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
|
||||||
import { WidgetComponent, IdentityUserModel, FormService } from '@alfresco/adf-core';
|
import { WidgetComponent, IdentityUserModel, FormService, IdentityUserService } from '@alfresco/adf-core';
|
||||||
import { FormControl } from '@angular/forms';
|
import { FormControl } from '@angular/forms';
|
||||||
import { filter, takeUntil } from 'rxjs/operators';
|
import { filter, takeUntil } from 'rxjs/operators';
|
||||||
import { Subject } from 'rxjs';
|
import { Subject } from 'rxjs';
|
||||||
@@ -52,7 +52,7 @@ export class PeopleCloudWidgetComponent extends WidgetComponent implements OnIni
|
|||||||
preSelectUsers: IdentityUserModel[];
|
preSelectUsers: IdentityUserModel[];
|
||||||
search: FormControl;
|
search: FormControl;
|
||||||
|
|
||||||
constructor(formService: FormService) {
|
constructor(formService: FormService, private identityUserService: IdentityUserService) {
|
||||||
super(formService);
|
super(formService);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,6 +88,12 @@ export class PeopleCloudWidgetComponent extends WidgetComponent implements OnIni
|
|||||||
this.field.validate();
|
this.field.validate();
|
||||||
this.field.form.validateForm();
|
this.field.form.validateForm();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (this.field.selectLoggedUser && !this.field.value) {
|
||||||
|
const userInfo = this.identityUserService.getCurrentUserInfo();
|
||||||
|
this.preSelectUsers = [ userInfo ];
|
||||||
|
this.onChangedUser(this.preSelectUsers);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy() {
|
ngOnDestroy() {
|
||||||
|
Reference in New Issue
Block a user