mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
[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:
parent
7aecd13b6f
commit
6d30752386
@ -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%;
|
||||
}
|
@ -1,66 +1,82 @@
|
||||
<md-card class="adf-new-task-layout-card">
|
||||
<md-grid-list cols="1" rowHeight="60px">
|
||||
<md-grid-tile>
|
||||
<div class="adf-new-task-heading">{{'START_TASK.FORM.TITLE'|translate}}</div>
|
||||
</md-grid-tile>
|
||||
</md-grid-list>
|
||||
<md-card-content>
|
||||
<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">
|
||||
</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>
|
||||
</md-input-container>
|
||||
</md-grid-tile>
|
||||
</md-grid-list>
|
||||
<md-grid-list cols="2" rowHeight="80px">
|
||||
<md-grid-tile>
|
||||
<md-input-container class="adf-start-task-input-container">
|
||||
<input mdInput
|
||||
[mdDatepicker]="taskDatePicker"
|
||||
[value]="taskDatePicker"
|
||||
(click)="taskDatePicker.open()"
|
||||
(keydown)="true"
|
||||
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-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-option>{{'START_TASK.FORM.LABEL.NONE'|translate}}</md-option>
|
||||
<md-grid-list cols="1" rowHeight="60px">
|
||||
<md-grid-tile>
|
||||
<div class="adf-new-task-heading">{{'START_TASK.FORM.TITLE'|translate}}</div>
|
||||
</md-grid-tile>
|
||||
</md-grid-list>
|
||||
<md-card-content>
|
||||
<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">
|
||||
</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>
|
||||
</md-input-container>
|
||||
</md-grid-tile>
|
||||
</md-grid-list>
|
||||
<md-grid-list cols="2" rowHeight="80px">
|
||||
<md-grid-tile>
|
||||
<md-input-container class="adf-start-task-input-container">
|
||||
<input mdInput
|
||||
[mdDatepicker]="taskDatePicker"
|
||||
(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"
|
||||
(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-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-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>
|
||||
</md-grid-tile>
|
||||
<md-grid-tile></md-grid-tile>
|
||||
</md-grid-list>
|
||||
</md-card-content>
|
||||
<md-card-actions>
|
||||
<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>
|
||||
</div>
|
||||
</md-grid-tile>
|
||||
</md-grid-list>
|
||||
</md-card-actions>
|
||||
</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-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>
|
||||
</md-grid-tile>
|
||||
<md-grid-tile></md-grid-tile>
|
||||
</md-grid-list>
|
||||
</md-card-content>
|
||||
<md-card-actions>
|
||||
<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 || dateError" (click)="start()" id="button-start">
|
||||
{{'START_TASK.FORM.ACTION.START'|translate}}
|
||||
</button>
|
||||
</div>
|
||||
</md-grid-tile>
|
||||
</md-grid-list>
|
||||
</md-card-actions>
|
||||
</md-card>
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -76,33 +76,32 @@ describe('StartTaskComponent', () => {
|
||||
fixture = TestBed.createComponent(StartTaskComponent);
|
||||
activitiStartTaskComponent = fixture.componentInstance;
|
||||
element = fixture.nativeElement;
|
||||
|
||||
service = fixture.debugElement.injector.get(TaskListService);
|
||||
peopleService = fixture.debugElement.injector.get(PeopleService);
|
||||
getFormlistSpy = spyOn(service, 'getFormList').and.returnValue(Observable.of(fakeForms));
|
||||
getWorkflowUsersSpy = spyOn(peopleService, 'getWorkflowUsers').and.returnValue(Observable.of([
|
||||
{
|
||||
id: 1,
|
||||
firstName: 'fakeName',
|
||||
lastName: 'fakeName',
|
||||
email: 'fake@app.activiti.com',
|
||||
company: 'Alfresco.com',
|
||||
pictureId: 3003
|
||||
},
|
||||
{
|
||||
id: 1001,
|
||||
firstName: 'fake-name',
|
||||
lastName: 'fake-name',
|
||||
email: 'fake-@app.com',
|
||||
company: 'app'
|
||||
}
|
||||
]));
|
||||
|
||||
fixture.detectChanges();
|
||||
});
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
service = fixture.debugElement.injector.get(TaskListService);
|
||||
peopleService = fixture.debugElement.injector.get(PeopleService);
|
||||
getFormlistSpy = spyOn(service, 'getFormList').and.returnValue(Observable.of(fakeForms));
|
||||
getWorkflowUsersSpy = spyOn(peopleService, 'getWorkflowUsers').and.returnValue(Observable.of([
|
||||
{
|
||||
id: 1,
|
||||
firstName: 'fakeName',
|
||||
lastName: 'fakeName',
|
||||
email: 'fake@app.activiti.com',
|
||||
company: 'Alfresco.com',
|
||||
pictureId: 3003
|
||||
},
|
||||
{
|
||||
id: 1001,
|
||||
firstName: 'fake-name',
|
||||
lastName: 'fake-name',
|
||||
email: 'fake-@app.com',
|
||||
company: 'app'
|
||||
}
|
||||
]));
|
||||
});
|
||||
|
||||
it('should create instance of StartTaskComponent', () => {
|
||||
expect(fixture.componentInstance instanceof StartTaskComponent).toBe(true, 'should create StartTaskComponent');
|
||||
});
|
||||
|
@ -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
|
||||
@ -83,13 +94,13 @@ export class StartTaskComponent implements OnInit {
|
||||
)
|
||||
)
|
||||
.subscribe(
|
||||
(res: any) => {
|
||||
this.success.emit(res);
|
||||
},
|
||||
(err) => {
|
||||
this.error.emit(err);
|
||||
this.logService.error('An error occurred while creating new task');
|
||||
});
|
||||
(res: any) => {
|
||||
this.success.emit(res);
|
||||
},
|
||||
(err) => {
|
||||
this.error.emit(err);
|
||||
this.logService.error('An error occurred while creating new task');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,8 +126,8 @@ export class StartTaskComponent implements OnInit {
|
||||
|
||||
private loadFormsTask(): void {
|
||||
this.taskService.getFormList().subscribe((res: Form[]) => {
|
||||
this.forms = res;
|
||||
},
|
||||
this.forms = res;
|
||||
},
|
||||
(err) => {
|
||||
this.error.emit(err);
|
||||
this.logService.error('An error occurred while trying to get the forms');
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -78,14 +78,17 @@
|
||||
"NONE": "None",
|
||||
"NAME": "Name",
|
||||
"DESCRIPTION": "Description",
|
||||
"ATTACHFORM" : "Attach a Form",
|
||||
"ASSIGNEE" : "Assignee",
|
||||
"FORM" : "Form",
|
||||
"DATE" : "Choose a Date"
|
||||
"ATTACHFORM": "Attach a Form",
|
||||
"ASSIGNEE": "Assignee",
|
||||
"FORM": "Form",
|
||||
"DATE": "Choose a Date"
|
||||
},
|
||||
"ACTION": {
|
||||
"START": "Start",
|
||||
"CANCEL": "Cancel"
|
||||
},
|
||||
"DATE": {
|
||||
"ERROR": "Date format DD/MM/YYYY"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -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'
|
||||
|
Loading…
x
Reference in New Issue
Block a user