[ADF-1169] validation date start task form (#2208)

* validation date start task form

* move mock test in before each of the creation component
This commit is contained in:
Eugenio Romano 2017-08-14 13:31:50 +01:00 committed by Mario Romano
parent 7aecd13b6f
commit 6d30752386
7 changed files with 235 additions and 138 deletions

View File

@ -1,37 +0,0 @@
.adf-new-task-heading {
padding: 12px 20px;
font-family: Muli;
font-weight: bold;
border-bottom: 1px solid #eee;
font-size: 18px;
float: left;
text-align: left;
width: calc(100% - 40px);
}
.adf-new-task-layout-card {
width: 66.6667%;
margin-right:calc(33.3333%/2 - 24px);
margin-left: calc(33.3333%/2 - 24px);
margin-top: 10px;
margin-bottom: 10px;
padding: 0px
}
.adf-new-task-footer {
padding: 4px;
font-family: Muli;
font-size: 18px;
border-top: 1px solid #eee;
float: left;
width: calc(100% - 40px);
text-align: right;
}
.adf-start-task-input-container {
width: 80%;
}
.adf-new-task-text-width {
width: 90%;
}

View File

@ -8,14 +8,16 @@
<md-grid-list cols="1" rowHeight="80px">
<md-grid-tile>
<md-input-container class="adf-new-task-text-width">
<input mdInput placeholder="{{'START_TASK.FORM.LABEL.NAME'|translate}}" [(ngModel)]="startTaskmodel.name" required id="name_id">
<input mdInput placeholder="{{'START_TASK.FORM.LABEL.NAME'|translate}}"
[(ngModel)]="startTaskmodel.name" required id="name_id">
</md-input-container>
</md-grid-tile>
</md-grid-list>
<md-grid-list cols="1" rowHeight="80px">
<md-grid-tile>
<md-input-container class="adf-new-task-text-width">
<textarea mdInput placeholder="{{'START_TASK.FORM.LABEL.DESCRIPTION'|translate}}" [(ngModel)]="startTaskmodel.description" id="description_id"></textarea>
<textarea mdInput placeholder="{{'START_TASK.FORM.LABEL.DESCRIPTION'|translate}}"
[(ngModel)]="startTaskmodel.description" id="description_id"></textarea>
</md-input-container>
</md-grid-tile>
</md-grid-list>
@ -24,27 +26,37 @@
<md-input-container class="adf-start-task-input-container">
<input mdInput
[mdDatepicker]="taskDatePicker"
[value]="taskDatePicker"
(click)="taskDatePicker.open()"
(keydown)="true"
(focusout)="onDateChanged($event.srcElement.value)"
placeholder="{{'START_TASK.FORM.LABEL.DATE'|translate}}"
[(ngModel)]="startTaskmodel.dueDate" id="date_id">
<button mdSuffix [mdDatepickerToggle]="taskDatePicker"></button>
</md-input-container>
<md-datepicker #taskDatePicker [touchUi]="true"></md-datepicker>
<md-datepicker #taskDatePicker [touchUi]="true"
(selectedChanged)="onDateChanged($event)"></md-datepicker>
<div class="adf-error-text-container">
<div *ngIf="dateError">
<div class="adf-error-text">{{'START_TASK.FORM.DATE.ERROR'|translate}}</div>
<i class="material-icons adf-error-icon">warning</i>
</div>
</div>
</md-grid-tile>
<md-grid-tile>
<md-select placeholder="{{'START_TASK.FORM.LABEL.ASSIGNEE'|translate}}" id="assignee_id" class="adf-start-task-input-container" [(ngModel)]="assignee">
<md-select placeholder="{{'START_TASK.FORM.LABEL.ASSIGNEE'|translate}}" id="assignee_id"
class="adf-start-task-input-container" [(ngModel)]="assignee">
<md-option>{{'START_TASK.FORM.LABEL.NONE'|translate}}</md-option>
<span *ngFor="let user of people">
<md-option [value]="user" *ngIf="!isUserNameEmpty(user)">{{ getDisplayUser(user.firstName, user.lastName, ' ')}}</md-option>
<md-option [value]="user" *ngIf="!isUserNameEmpty(user)">{{ getDisplayUser(user.firstName,
user.lastName, ' ')}}
</md-option>
</span>
</md-select>
</md-grid-tile>
</md-grid-list>
<md-grid-list cols="2" rowHeight="80px">
<md-grid-tile>
<md-select placeholder="{{'START_TASK.FORM.LABEL.FORM'|translate}}" id="form_id" [(ngModel)]="formKey" class="adf-start-task-input-container">
<md-select placeholder="{{'START_TASK.FORM.LABEL.FORM'|translate}}" id="form_id" [(ngModel)]="formKey"
class="adf-start-task-input-container">
<md-option>{{'START_TASK.FORM.LABEL.NONE'|translate}}</md-option>
<md-option *ngFor="let form of forms" [value]="form.id">{{ form.name }}</md-option>
</md-select>
@ -56,8 +68,12 @@
<md-grid-list cols="1" rowHeight="60px">
<md-grid-tile>
<div class="adf-new-task-footer">
<button md-button (click)="onCancel()" id="button-cancle">{{'START_TASK.FORM.ACTION.CANCEL'|translate}}</button>
<button md-button [disabled]="!startTaskmodel.name" (click)="start()" id="button-start">{{'START_TASK.FORM.ACTION.START'|translate}}</button>
<button md-button (click)="onCancel()" id="button-cancle">
{{'START_TASK.FORM.ACTION.CANCEL'|translate}}
</button>
<button md-button [disabled]="!startTaskmodel.name || dateError" (click)="start()" id="button-start">
{{'START_TASK.FORM.ACTION.START'|translate}}
</button>
</div>
</md-grid-tile>
</md-grid-list>

View File

@ -0,0 +1,94 @@
@import 'theming';
.adf-new-task-heading {
padding: 12px 20px;
font-family: Muli;
font-weight: bold;
border-bottom: 1px solid #eee;
font-size: 18px;
float: left;
text-align: left;
width: calc(100% - 40px);
}
.adf-new-task-layout-card {
width: 66.6667%;
margin-right: calc(33.3333%/2 - 24px);
margin-left: calc(33.3333%/2 - 24px);
margin-top: 10px;
margin-bottom: 10px;
padding: 0px;
}
.adf-new-task-footer {
padding: 4px;
font-family: Muli;
font-size: 18px;
border-top: 1px solid #eee;
float: left;
width: calc(100% - 40px);
text-align: right;
}
.adf-start-task-input-container {
width: 80%;
}
.adf-new-task-text-width {
width: 90%;
}
.adf {
&-error-text-container {
position: absolute;
width: 81%;
height: 20px;
margin-top: 30px;
}
&-error-text {
padding: 1px;
height: 16px;
font-size: 12px;
line-height: 1.33;
float: left;
color: mat-color($warn);
}
&-error-icon {
float: right;
font-size: 17px;
color: mat-color($warn);
}
&-label {
color: $alfresco-gray-label;
}
&-invalid {
.mat-input-underline {
background-color: #f44336 !important;
}
.adf-file {
border-color: mat-color($warn);
}
.mat-input-prefix {
color: mat-color($warn);
}
.adf-input {
border-color: mat-color($warn);
}
.adf-label {
color: mat-color($warn);
&:after {
background-color: mat-color($warn);
}
}
}
}

View File

@ -76,11 +76,7 @@ describe('StartTaskComponent', () => {
fixture = TestBed.createComponent(StartTaskComponent);
activitiStartTaskComponent = fixture.componentInstance;
element = fixture.nativeElement;
fixture.detectChanges();
});
}));
beforeEach(() => {
service = fixture.debugElement.injector.get(TaskListService);
peopleService = fixture.debugElement.injector.get(PeopleService);
getFormlistSpy = spyOn(service, 'getFormList').and.returnValue(Observable.of(fakeForms));
@ -101,7 +97,10 @@ describe('StartTaskComponent', () => {
company: 'app'
}
]));
fixture.detectChanges();
});
}));
it('should create instance of StartTaskComponent', () => {
expect(fixture.componentInstance instanceof StartTaskComponent).toBe(true, 'should create StartTaskComponent');

View File

@ -15,7 +15,10 @@
* limitations under the License.
*/
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation } from '@angular/core';
import { DateAdapter, MD_DATE_FORMATS } from '@angular/material';
import * as moment from 'moment';
import { MOMENT_DATE_FORMATS, MomentDateAdapter } from 'ng2-alfresco-core';
import { LogService } from 'ng2-alfresco-core';
import { Observable } from 'rxjs/Rx';
import { Form } from '../models/form.model';
@ -28,10 +31,16 @@ import { TaskListService } from './../services/tasklist.service';
@Component({
selector: 'adf-start-task, activiti-start-task',
templateUrl: './start-task.component.html',
styleUrls: ['./start-task.component.css']
styleUrls: ['./start-task.component.scss'],
providers: [
{provide: DateAdapter, useClass: MomentDateAdapter},
{provide: MD_DATE_FORMATS, useValue: MOMENT_DATE_FORMATS}],
encapsulation: ViewEncapsulation.None
})
export class StartTaskComponent implements OnInit {
public FORMAT_DATE: string = 'DD/MM/YYYY';
@Input()
appId: string;
@ -56,6 +65,8 @@ export class StartTaskComponent implements OnInit {
taskId: string;
dateError: boolean;
/**
* Constructor
* @param auth
@ -145,4 +156,15 @@ export class StartTaskComponent implements OnInit {
lastName = (lastName !== null ? lastName : '');
return firstName + delimiter + lastName;
}
onDateChanged(newDateValue): void {
this.dateError = false;
if (newDateValue) {
let momentDate = moment(newDateValue, this.FORMAT_DATE, true);
if (!momentDate.isValid()) {
this.dateError = true;
}
}
}
}

View File

@ -86,6 +86,9 @@
"ACTION": {
"START": "Start",
"CANCEL": "Cancel"
},
"DATE": {
"ERROR": "Date format DD/MM/YYYY"
}
}
},

View File

@ -21,10 +21,10 @@ import * as moment from 'moment';
export const MOMENT_DATE_FORMATS: MdDateFormats = {
parse: {
dateInput: 'MM-DD-YYYY'
dateInput: 'DD/MM/YYYY'
},
display: {
dateInput: 'MM-DD-YYYY',
dateInput: 'DD/MM/YYYY',
monthYearLabel: 'MMMM Y',
dateA11yLabel: 'LL',
monthYearA11yLabel: 'MMMM Y'