[AAE-8856] Enable left label for form widgets in several widgets (#7640)

This commit is contained in:
Rubén Barroso 2022-05-18 18:43:59 +02:00 committed by GitHub
parent d4779360d8
commit b13a5cc282
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 482 additions and 109 deletions

View File

@ -1,26 +1,21 @@
<div class="adf-amount-widget__container adf-amount-widget {{field.className}}" <div class="adf-amount-widget__container adf-amount-widget {{field.className}}"
[class.adf-invalid]="!field.isValid && isTouched()" [class.adf-invalid]="!field.isValid && isTouched()" [class.adf-readonly]="field.readOnly"
[class.adf-readonly]="field.readOnly"> [class.adf-left-label-input-container]="field.leftLabels">
<div>
<label class="adf-label" <label class="adf-label"
[attr.for]="field.id">{{field.name | translate }}<span class="adf-asterisk" *ngIf="isRequired()">*</span></label> [class.adf-left-label]="field.leftLabels" [attr.for]="field.id">{{field.name | translate }}<span class="adf-asterisk" *ngIf="isRequired()">*</span></label>
</div>
<div>
<mat-form-field class="adf-amount-widget__input" [hideRequiredMarker]="true"> <mat-form-field class="adf-amount-widget__input" [hideRequiredMarker]="true">
<span matPrefix class="adf-amount-widget__prefix-spacing">{{ currency }} &nbsp;</span> <span matPrefix class="adf-amount-widget__prefix-spacing">{{ currency }} &nbsp;</span>
<input matInput <input matInput [matTooltip]="field.tooltip" matTooltipPosition="above" matTooltipShowDelay="1000"
[matTooltip]="field.tooltip" class="adf-input" type="text" [id]="field.id" [required]="isRequired()"
matTooltipPosition="above" [placeholder]="placeholder" [value]="field.value" [(ngModel)]="field.value"
matTooltipShowDelay="1000" (ngModelChange)="onFieldChanged(field)" [disabled]="field.readOnly"
class="adf-input"
type="text"
[id]="field.id"
[required]="isRequired()"
[placeholder]="placeholder"
[value]="field.value"
[(ngModel)]="field.value"
(ngModelChange)="onFieldChanged(field)"
[disabled]="field.readOnly"
(blur)="markAsTouched()"> (blur)="markAsTouched()">
</mat-form-field> </mat-form-field>
<error-widget [error]="field.validationSummary"></error-widget> <error-widget [error]="field.validationSummary"></error-widget>
<error-widget *ngIf="isInvalidFieldRequired() && isTouched()" <error-widget *ngIf="isInvalidFieldRequired() && isTouched()"
required="{{ 'FORM.FIELD.REQUIRED' | translate }}"></error-widget> required="{{ 'FORM.FIELD.REQUIRED' | translate }}"></error-widget>
</div>
</div> </div>

View File

@ -2,6 +2,10 @@
&-amount-widget { &-amount-widget {
width: 100%; width: 100%;
margin-top: 15px; margin-top: 15px;
.adf-left-label {
line-height: 36px;
}
} }
&-amount-widget__input { &-amount-widget__input {

View File

@ -118,6 +118,7 @@ describe('AmountWidgetComponent - rendering', () => {
let widget: AmountWidgetComponent; let widget: AmountWidgetComponent;
let fixture: ComponentFixture<AmountWidgetComponent>; let fixture: ComponentFixture<AmountWidgetComponent>;
let element: HTMLElement;
setupTestBed({ setupTestBed({
imports: [ imports: [
@ -130,6 +131,7 @@ describe('AmountWidgetComponent - rendering', () => {
beforeEach(() => { beforeEach(() => {
fixture = TestBed.createComponent(AmountWidgetComponent); fixture = TestBed.createComponent(AmountWidgetComponent);
widget = fixture.componentInstance; widget = fixture.componentInstance;
element = fixture.nativeElement;
}); });
it('[C309692] - Should be possible to set the General Properties for Amount Widget', async () => { it('[C309692] - Should be possible to set the General Properties for Amount Widget', async () => {
@ -207,6 +209,69 @@ describe('AmountWidgetComponent - rendering', () => {
expect(tooltip).toEqual(widget.field.tooltip); expect(tooltip).toEqual(widget.field.tooltip);
}); });
describe('when form model has left labels', () => {
it('should have left labels classes on leftLabels true', async () => {
widget.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id', leftLabels: true }), {
id: 'amount-id',
name: 'amount-name',
value: '',
type: FormFieldTypes.AMOUNT,
readOnly: false,
required: true
});
fixture.detectChanges();
await fixture.whenStable();
const widgetContainer = element.querySelector('.adf-left-label-input-container');
expect(widgetContainer).not.toBeNull();
const adfLeftLabel = element.querySelector('.adf-left-label');
expect(adfLeftLabel).not.toBeNull();
});
it('should not have left labels classes on leftLabels false', async () => {
widget.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id', leftLabels: false }), {
id: 'amount-id',
name: 'amount-name',
value: '',
type: FormFieldTypes.AMOUNT,
readOnly: false,
required: true
});
fixture.detectChanges();
await fixture.whenStable();
const widgetContainer = element.querySelector('.adf-left-label-input-container');
expect(widgetContainer).toBeNull();
const adfLeftLabel = element.querySelector('.adf-left-label');
expect(adfLeftLabel).toBeNull();
});
it('should not have left labels classes on leftLabels not present', async () => {
widget.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id' }), {
id: 'amount-id',
name: 'amount-name',
value: '',
type: FormFieldTypes.AMOUNT,
readOnly: false,
required: true
});
fixture.detectChanges();
await fixture.whenStable();
const widgetContainer = element.querySelector('.adf-left-label-input-container');
expect(widgetContainer).toBeNull();
const adfLeftLabel = element.querySelector('.adf-left-label');
expect(adfLeftLabel).toBeNull();
});
});
}); });
describe('AmountWidgetComponent settings', () => { describe('AmountWidgetComponent settings', () => {

View File

@ -1,6 +1,10 @@
<div class="{{field.className}}" id="data-time-widget" [class.adf-invalid]="!field.isValid && isTouched()"> <div class="{{field.className}}" id="data-time-widget" [class.adf-invalid]="!field.isValid && isTouched()" [class.adf-left-label-input-container]="field.leftLabels">
<mat-form-field class="adf-date-time-widget" [hideRequiredMarker]="true"> <div *ngIf="field.leftLabels">
<label class="adf-label" [attr.for]="field.id">{{field.name | translate }} ({{field.dateDisplayFormat}})<span class="adf-asterisk" *ngIf="isRequired()">*</span></label> <label class="adf-label adf-left-label" [attr.for]="field.id">{{field.name | translate }} ({{field.dateDisplayFormat}})<span class="adf-asterisk" *ngIf="isRequired()">*</span></label>
</div>
<div>
<mat-form-field class="adf-date-time-widget" [class.adf-left-label-input-datepicker]="field.leftLabels" [hideRequiredMarker]="true">
<label class="adf-label" *ngIf="!field.leftLabels" [attr.for]="field.id">{{field.name | translate }} ({{field.dateDisplayFormat}})<span class="adf-asterisk" *ngIf="isRequired()">*</span></label>
<input matInput <input matInput
[id]="field.id" [id]="field.id"
[value]="field.value" [value]="field.value"
@ -26,4 +30,5 @@
[max]="maxDate" [max]="maxDate"
[disabled]="field.readOnly" [disabled]="field.readOnly"
(dateInput)="onDateChanged($any($event).targetElement.value)"> (dateInput)="onDateChanged($any($event).targetElement.value)">
</div>
</div> </div>

View File

@ -8,6 +8,16 @@
top: 20px; top: 20px;
} }
} }
&-left-label-input-datepicker {
.mat-form-field-suffix {
top: 0;
}
.mat-form-field-infix {
width: 100%;
}
}
} }
.mat-datetimepicker-toggle { .mat-datetimepicker-toggle {

View File

@ -250,4 +250,76 @@ describe('DateTimeWidgetComponent', () => {
}); });
}); });
}); });
describe('when form model has left labels', () => {
it('should have left labels classes on leftLabels true', async () => {
widget.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id', leftLabels: true }), {
id: 'datetime-id',
name: 'datetime-name',
value: '',
type: FormFieldTypes.DATETIME,
readOnly: false,
required: true
});
fixture.detectChanges();
await fixture.whenStable();
const widgetContainer = element.querySelector('.adf-left-label-input-container');
expect(widgetContainer).not.toBeNull();
const leftDatePicker = element.querySelector('.adf-left-label-input-datepicker');
expect(leftDatePicker).not.toBeNull();
const adfLeftLabel = element.querySelector('.adf-left-label');
expect(adfLeftLabel).not.toBeNull();
});
it('should not have left labels classes on leftLabels false', async () => {
widget.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id', leftLabels: false }), {
id: 'datetime-id',
name: 'datetime-name',
value: '',
type: FormFieldTypes.DATETIME,
readOnly: false,
required: true
});
fixture.detectChanges();
await fixture.whenStable();
const widgetContainer = element.querySelector('.adf-left-label-input-container');
expect(widgetContainer).toBeNull();
const leftDatePicker = element.querySelector('.adf-left-label-input-datepicker');
expect(leftDatePicker).toBeNull();
const adfLeftLabel = element.querySelector('.adf-left-label');
expect(adfLeftLabel).toBeNull();
});
it('should not have left labels classes on leftLabels not present', async () => {
widget.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id' }), {
id: 'datetime-id',
name: 'datetime-name',
value: '',
type: FormFieldTypes.DATETIME,
readOnly: false,
required: true
});
fixture.detectChanges();
await fixture.whenStable();
const widgetContainer = element.querySelector('.adf-left-label-input-container');
expect(widgetContainer).toBeNull();
const leftDatePicker = element.querySelector('.adf-left-label-input-datepicker');
expect(leftDatePicker).toBeNull();
const adfLeftLabel = element.querySelector('.adf-left-label');
expect(adfLeftLabel).toBeNull();
});
});
}); });

View File

@ -1,6 +1,11 @@
<div class="{{field.className}}" id="data-widget" [class.adf-invalid]="!field.isValid && isTouched()"> <div class="{{field.className}}" id="data-widget" [class.adf-invalid]="!field.isValid && isTouched()" [class.adf-left-label-input-container]="field.leftLabels">
<mat-form-field class="adf-date-widget" [hideRequiredMarker]="true"> <div *ngIf="field.leftLabels">
<label class="adf-label" [attr.for]="field.id">{{field.name | translate }} ({{field.dateDisplayFormat}})<span class="adf-asterisk" <label class="adf-label adf-left-label" [attr.for]="field.id">{{field.name | translate }} ({{field.dateDisplayFormat}})<span class="adf-asterisk"
*ngIf="isRequired()">*</span></label>
</div>
<div>
<mat-form-field class="adf-date-widget" [class.adf-left-label-input-datepicker]="field.leftLabels" [hideRequiredMarker]="true">
<label class="adf-label" *ngIf="!field.leftLabels" [attr.for]="field.id">{{field.name | translate }} ({{field.dateDisplayFormat}})<span class="adf-asterisk"
*ngIf="isRequired()">*</span></label> *ngIf="isRequired()">*</span></label>
<input matInput <input matInput
[id]="field.id" [id]="field.id"
@ -26,4 +31,5 @@
[max]="maxDate" [max]="maxDate"
[disabled]="field.readOnly" [disabled]="field.readOnly"
(dateInput)="onDateChanged($any($event).targetElement.value)"> (dateInput)="onDateChanged($any($event).targetElement.value)">
</div>
</div> </div>

View File

@ -8,4 +8,14 @@
top: 20px; top: 20px;
} }
} }
&-left-label-input-datepicker {
.mat-form-field-suffix {
top: 0;
}
.mat-form-field-infix {
width: 100%;
}
}
} }

View File

@ -17,7 +17,7 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { DateCloudWidgetComponent, DATE_FORMAT_CLOUD } from './date-cloud.widget'; import { DateCloudWidgetComponent, DATE_FORMAT_CLOUD } from './date-cloud.widget';
import { setupTestBed, FormFieldModel, FormModel } from '@alfresco/adf-core'; import { setupTestBed, FormFieldModel, FormModel, FormFieldTypes } from '@alfresco/adf-core';
import moment from 'moment-es6'; import moment from 'moment-es6';
import { ProcessServiceCloudTestingModule } from '../../../../testing/process-service-cloud.testing.module'; import { ProcessServiceCloudTestingModule } from '../../../../testing/process-service-cloud.testing.module';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
@ -230,4 +230,76 @@ describe('DateWidgetComponent', () => {
}); });
}); });
describe('when form model has left labels', () => {
it('should have left labels classes on leftLabels true', async () => {
widget.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id', leftLabels: true }), {
id: 'date-id',
name: 'date-name',
value: '',
type: FormFieldTypes.DATE,
readOnly: false,
required: true
});
fixture.detectChanges();
await fixture.whenStable();
const widgetContainer = element.querySelector('.adf-left-label-input-container');
expect(widgetContainer).not.toBeNull();
const leftDatePicker = element.querySelector('.adf-left-label-input-datepicker');
expect(leftDatePicker).not.toBeNull();
const adfLeftLabel = element.querySelector('.adf-left-label');
expect(adfLeftLabel).not.toBeNull();
});
it('should not have left labels classes on leftLabels false', async () => {
widget.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id', leftLabels: false }), {
id: 'date-id',
name: 'date-name',
value: '',
type: FormFieldTypes.DATE,
readOnly: false,
required: true
});
fixture.detectChanges();
await fixture.whenStable();
const widgetContainer = element.querySelector('.adf-left-label-input-container');
expect(widgetContainer).toBeNull();
const leftDatePicker = element.querySelector('.adf-left-label-input-datepicker');
expect(leftDatePicker).toBeNull();
const adfLeftLabel = element.querySelector('.adf-left-label');
expect(adfLeftLabel).toBeNull();
});
it('should not have left labels classes on leftLabels not present', async () => {
widget.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id' }), {
id: 'date-id',
name: 'date-name',
value: '',
type: FormFieldTypes.DATE,
readOnly: false,
required: true
});
fixture.detectChanges();
await fixture.whenStable();
const widgetContainer = element.querySelector('.adf-left-label-input-container');
expect(widgetContainer).toBeNull();
const leftDatePicker = element.querySelector('.adf-left-label-input-datepicker');
expect(leftDatePicker).toBeNull();
const adfLeftLabel = element.querySelector('.adf-left-label');
expect(adfLeftLabel).toBeNull();
});
});
}); });

View File

@ -1,7 +1,10 @@
<div class="adf-dropdown-widget {{field.className}}" <div class="adf-dropdown-widget {{field.className}}"
[class.adf-invalid]="!field.isValid && isTouched()" [class.adf-readonly]="field.readOnly"> [class.adf-invalid]="!field.isValid && isTouched()" [class.adf-readonly]="field.readOnly" [class.adf-left-label-input-container]="field.leftLabels">
<label class="adf-label" [attr.for]="field.id">{{field.name | translate }}<span class="adf-asterisk" <div>
<label class="adf-label" [class.adf-left-label]="field.leftLabels" [attr.for]="field.id">{{field.name | translate }}<span class="adf-asterisk"
*ngIf="isRequired()">*</span></label> *ngIf="isRequired()">*</span></label>
</div>
<div>
<adf-cloud-group [mode]="mode" <adf-cloud-group [mode]="mode"
[title]="title" [title]="title"
[readOnly]="field.readOnly" [readOnly]="field.readOnly"
@ -18,5 +21,6 @@
<error-widget [error]="field.validationSummary"></error-widget> <error-widget [error]="field.validationSummary"></error-widget>
<error-widget class="adf-dropdown-required-message" *ngIf="isInvalidFieldRequired() && isTouched()" <error-widget class="adf-dropdown-required-message" *ngIf="isInvalidFieldRequired() && isTouched()"
required="{{ 'FORM.FIELD.REQUIRED' | translate }}"></error-widget> required="{{ 'FORM.FIELD.REQUIRED' | translate }}"></error-widget>
</div>
</div> </div>

View File

@ -80,4 +80,67 @@ describe('GroupCloudWidgetComponent', () => {
expect(element.querySelector('.adf-invalid')).toBeTruthy(); expect(element.querySelector('.adf-invalid')).toBeTruthy();
}); });
}); });
describe('when form model has left labels', () => {
it('should have left labels classes on leftLabels true', async () => {
widget.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id', leftLabels: true }), {
id: 'group-id',
name: 'group-name',
value: '',
type: FormFieldTypes.GROUP,
readOnly: false,
required: true
});
fixture.detectChanges();
await fixture.whenStable();
const widgetContainer = element.querySelector('.adf-left-label-input-container');
expect(widgetContainer).not.toBeNull();
const adfLeftLabel = element.querySelector('.adf-left-label');
expect(adfLeftLabel).not.toBeNull();
});
it('should not have left labels classes on leftLabels false', async () => {
widget.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id', leftLabels: false }), {
id: 'group-id',
name: 'group-name',
value: '',
type: FormFieldTypes.GROUP,
readOnly: false,
required: true
});
fixture.detectChanges();
await fixture.whenStable();
const widgetContainer = element.querySelector('.adf-left-label-input-container');
expect(widgetContainer).toBeNull();
const adfLeftLabel = element.querySelector('.adf-left-label');
expect(adfLeftLabel).toBeNull();
});
it('should not have left labels classes on leftLabels not present', async () => {
widget.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id' }), {
id: 'group-id',
name: 'group-name',
value: '',
type: FormFieldTypes.GROUP,
readOnly: false,
required: true
});
fixture.detectChanges();
await fixture.whenStable();
const widgetContainer = element.querySelector('.adf-left-label-input-container');
expect(widgetContainer).toBeNull();
const adfLeftLabel = element.querySelector('.adf-left-label');
expect(adfLeftLabel).toBeNull();
});
});
}); });

View File

@ -1,6 +1,9 @@
<div class="adf-dropdown-widget {{field.className}}" <div class="adf-dropdown-widget {{field.className}}"
[class.adf-invalid]="!field.isValid && isTouched()" [class.adf-readonly]="field.readOnly"> [class.adf-invalid]="!field.isValid && isTouched()" [class.adf-readonly]="field.readOnly" [class.adf-left-label-input-container]="field.leftLabels">
<label class="adf-label" [attr.for]="field.id">{{field.name | translate }}<span class="adf-asterisk" *ngIf="isRequired()">*</span></label> <div>
<label class="adf-label" [class.adf-left-label]="field.leftLabels" [attr.for]="field.id">{{field.name | translate }}<span class="adf-asterisk" *ngIf="isRequired()">*</span></label>
</div>
<div>
<adf-cloud-people <adf-cloud-people
[preSelectUsers]="preSelectUsers" [preSelectUsers]="preSelectUsers"
[validate]="true" [validate]="true"
@ -21,5 +24,6 @@
<error-widget [error]="field.validationSummary"></error-widget> <error-widget [error]="field.validationSummary"></error-widget>
<error-widget class="adf-dropdown-required-message" *ngIf="isInvalidFieldRequired() && isTouched()" <error-widget class="adf-dropdown-required-message" *ngIf="isInvalidFieldRequired() && isTouched()"
required="{{ 'FORM.FIELD.REQUIRED' | translate }}"></error-widget> required="{{ 'FORM.FIELD.REQUIRED' | translate }}"></error-widget>
</div>
</div> </div>

View File

@ -99,4 +99,67 @@ describe('PeopleCloudWidgetComponent', () => {
expect(element.querySelector('.adf-invalid')).toBeTruthy(); expect(element.querySelector('.adf-invalid')).toBeTruthy();
}); });
}); });
describe('when form model has left labels', () => {
it('should have left labels classes on leftLabels true', async () => {
widget.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id', leftLabels: true }), {
id: 'people-id',
name: 'people-name',
value: '',
type: FormFieldTypes.PEOPLE,
readOnly: false,
required: true
});
fixture.detectChanges();
await fixture.whenStable();
const widgetContainer = element.querySelector('.adf-left-label-input-container');
expect(widgetContainer).not.toBeNull();
const adfLeftLabel = element.querySelector('.adf-left-label');
expect(adfLeftLabel).not.toBeNull();
});
it('should not have left labels classes on leftLabels false', async () => {
widget.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id', leftLabels: false }), {
id: 'people-id',
name: 'people-name',
value: '',
type: FormFieldTypes.PEOPLE,
readOnly: false,
required: true
});
fixture.detectChanges();
await fixture.whenStable();
const widgetContainer = element.querySelector('.adf-left-label-input-container');
expect(widgetContainer).toBeNull();
const adfLeftLabel = element.querySelector('.adf-left-label');
expect(adfLeftLabel).toBeNull();
});
it('should not have left labels classes on leftLabels not present', async () => {
widget.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id' }), {
id: 'people-id',
name: 'people-name',
value: '',
type: FormFieldTypes.PEOPLE,
readOnly: false,
required: true
});
fixture.detectChanges();
await fixture.whenStable();
const widgetContainer = element.querySelector('.adf-left-label-input-container');
expect(widgetContainer).toBeNull();
const adfLeftLabel = element.querySelector('.adf-left-label');
expect(adfLeftLabel).toBeNull();
});
});
}); });