[ADF-918] Activiti Start Task - Refactoring (#2065)

* [#DW-60] Task-create Task

* Updated en.json with new form fields
* Refactored start Button(Disable/Enable)
* Migrated from mdl to md
* Added documentation

* #DW-60 Task- create task

* Changed component name ActivitiStarttaskButton to ActivitiStartTaskComponent
* activiti-start-task to adf-start-task

* [ADF-918]  Activiti Start Task - Refactoring

* Removed unwanted  activiti-start-task.png
* Renamed component name in test
* Refactored CSS

* [ADF-918] Activiti Start Task - Refactoring

* Added condtional parameter passing and added a test case

* [ADF-918] Activiti Start Task - Refactoring

* Removed trailing space.
* Refactored Spec file.

* [ADF-918] Activiti Start Task - Refactoring

* Created  startTaskModel with form feilds.
* Modified testcases  after adding startTaskModel.
* Removed @input property.

* [ADF-918] Activiti Start Task - Refactoring

* Fixed tslint issuse (Exceeds maximum line length)
* Refactored date field.

* [ADF-918] Activiti Start Task - Refactoring

* Changed property name date to dueDate.
This commit is contained in:
siva kumar
2017-07-12 16:34:59 +05:30
committed by Eugenio Romano
parent 160d73cee3
commit acfe257327
12 changed files with 460 additions and 190 deletions

View File

@@ -40,6 +40,7 @@
* [Properties](#properties-8)
+ [Events](#events-7)
- [ADF Comments Component](#adf-comments-component)
- [Start Task Component](#start-task-component)
* [Properties](#properties-9)
+ [Events](#events-8)
- [Build from sources](#build-from-sources)
@@ -489,12 +490,38 @@ This component displays comments entered by involved users to a specified task.
| --- | --- |
| error | Raised when an error occurs while displaying/adding a comment |
## Start Task Component
This component Creates/Starts new task for the specified app
```html
<adf-start-task
[appId]="YOUR_APP_ID">
</adf-start-task>
```
![adf-start-task](docs/assets/adf-start-task.png)
### Properties
| Name | Type | Description |
| --- | --- | --- |
| appId | string | (**required**): The id of the app. |
#### Events
| Name | Description |
| --- | --- |
| onSuccess | Raised when the task is successfully created |
| cancel | Raised when the cancel button is pressed by the user |
| error | Raised if there is an error during task creation |
## Build from sources
You can build component from sources with the following commands:
```sh
npm install
npm run build
```

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@@ -17,7 +17,17 @@
import { DatePipe } from '@angular/common';
import { ModuleWithProviders, NgModule } from '@angular/core';
import { MdButtonModule, MdIconModule, MdInputModule, MdProgressSpinnerModule } from '@angular/material';
import {
MdButtonModule,
MdIconModule,
MdInputModule,
MdProgressSpinnerModule,
MdDatepickerModule,
MdGridListModule,
MdAutocompleteModule,
MdNativeDateModule,
MdSelectModule
} from '@angular/material';
import { ActivitiFormModule } from 'ng2-activiti-form';
import { CoreModule } from 'ng2-alfresco-core';
import { DataTableModule } from 'ng2-alfresco-datatable';
@@ -32,12 +42,12 @@ import {
ActivitiCreateTaskAttachmentComponent,
ActivitiFilters,
ActivitiPeople,
ActivitiPeopleSearch,
ActivitiStartTaskButton,
ActivitiTaskDetails,
ActivitiTaskHeader,
ActivitiTaskList,
AdfCommentListComponent,
ActivitiPeopleSearch,
ActivitiStartTaskComponent,
ActivitiTaskDetails,
ActivitiTaskList,
NoTaskDetailsTemplateComponent,
PeopleList,
TaskAttachmentListComponent
@@ -59,7 +69,7 @@ export const ACTIVITI_TASKLIST_DIRECTIVES: any[] = [
ActivitiComments,
ActivitiPeople,
ActivitiTaskHeader,
ActivitiStartTaskButton,
ActivitiStartTaskComponent,
ActivitiPeopleSearch,
TaskAttachmentListComponent,
ActivitiCreateTaskAttachmentComponent,
@@ -81,7 +91,12 @@ export const ACTIVITI_TASKLIST_PROVIDERS: any[] = [
MdIconModule,
MdButtonModule,
MdInputModule,
MdProgressSpinnerModule
MdProgressSpinnerModule,
MdDatepickerModule,
MdNativeDateModule,
MdSelectModule,
MdAutocompleteModule,
MdGridListModule
],
declarations: [
...ACTIVITI_TASKLIST_DIRECTIVES

View File

@@ -0,0 +1,34 @@
/*!
* @license
* Copyright 2016 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.
*/
export let startTaskMock = {
'name': 'fakeName',
'description': 'fakeDescription',
'assignee': {'id': 2001, 'firstName': 'Jhon', 'lastName': 'Adams', 'email': 'jhon@app.activiti.com'},
'dueDate': '2017-11-03T15:25:42.749+0000',
'formKey': '11201',
'category': 'fakeAppId'
};
export let noDataMock = {
'name': '',
'description': '',
'assignee': {},
'dueDate': '',
'formKey': '',
'category': ';'
};

View File

@@ -1,7 +1,37 @@
:host {
width: 100%;
.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);
}
.activiti-label {
font-weight: bolder;
.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

@@ -1,39 +1,63 @@
<button md-raised-button (click)="showDialog()" id="start-task-button">
<md-icon>add</md-icon>
<span>{{'START_TASK.BUTTON'|translate}}</span>
</button>
<dialog class="mdl-dialog" id="start-task-dialog" #dialog>
<h4 class="mdl-dialog__title" id="start-task-dialog-title">{{'START_TASK.DIALOG.TITLE'|translate}}</h4>
<div class="mdl-dialog__content">
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="mdl-textfield__input" type="text" [(ngModel)]="name" id="taskName"/>
<label class="mdl-textfield__label" for="taskName">{{'START_TASK.DIALOG.LABEL.NAME'|translate}}</label>
</div>
<div class="mdl-textfield mdl-js-textfield">
<textarea class="mdl-textfield__input" type="text" [(ngModel)]="description" rows="3"
id="taskDescription"></textarea>
<label class="mdl-textfield__label" id="task-description-label"
for="taskDescription">{{'START_TASK.DIALOG.LABEL.DESCRIPTION'|translate}}</label>
</div>
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<label class="mdl-textfield__label" >{{'START_TASK.DIALOG.LABEL.ATTACHFORM'|translate}}</label>
</div>
<div class="mdl-textfield mdl-js-textfield alf-mdl-selectfield">
<select name="taskForm" [(ngModel)]="formId" >
<option value="null">{{'START_TASK.DIALOG.LABEL.NONE'|translate}}</option>
<option *ngFor="let form of forms" [value]="form.id">
{{form.name}}
</option>
</select>
</div>
</div>
<div class="mdl-dialog__actions">
<button type="button" id="button-start" (click)="start()" class="mdl-button">
{{'START_TASK.DIALOG.ACTION.START'|translate}}
</button>
<button type="button" id="button-cancel" (click)="cancel()" class="mdl-button close">
{{'START_TASK.DIALOG.ACTION.CANCEL'|translate}}
</button>
</div>
</dialog>
<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)]="startTaskmodel.assignee">
<md-option>{{'START_TASK.FORM.LABEL.NONE'|translate}}</md-option>
<md-option *ngFor="let user of people" [value]="user">{{ user.firstName +' '+ user.lastName }}</md-option>
</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)]="startTaskmodel.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-card>

View File

@@ -16,94 +16,199 @@
*/
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MdButtonModule, MdDatepickerModule, MdGridListModule, MdIconModule, MdInputModule, MdNativeDateModule, MdSelectModule } from '@angular/material';
import { AlfrescoTranslationService, CoreModule } from 'ng2-alfresco-core';
import { Observable } from 'rxjs/Rx';
import { StartTaskModel } from '../models/index';
import { ActivitiPeopleService } from '../services/activiti-people.service';
import { ActivitiTaskListService } from '../services/activiti-tasklist.service';
import { ActivitiStartTaskButton } from './activiti-start-task.component';
import { startTaskMock } from './../assets/start-task.mock';
import { ActivitiStartTaskComponent } from './activiti-start-task.component';
declare let jasmine: any;
describe('ActivitiStartTaskButton', () => {
describe('ActivitiStartTaskComponent', () => {
let activitiStartTaskButton: ActivitiStartTaskButton;
let fixture: ComponentFixture<ActivitiStartTaskButton>;
let activitiStartTaskComponent: ActivitiStartTaskComponent;
let fixture: ComponentFixture<ActivitiStartTaskComponent>;
let service: ActivitiTaskListService;
let peopleService: ActivitiPeopleService;
let element: HTMLElement;
let startTaskButton: HTMLElement;
let getformlistSpy: jasmine.Spy;
let getWorkflowUsersSpy: jasmine.Spy;
let getcreateNewTaskSpy: jasmine.Spy;
let fakeForms = [
{
id: 123,
name: 'Display Data'
},
{
id: 1111,
name: 'Employee Info'
}
];
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
CoreModule.forRoot()
CoreModule.forRoot(),
MdInputModule,
MdIconModule,
MdButtonModule,
MdDatepickerModule,
MdGridListModule,
MdNativeDateModule,
MdSelectModule
],
declarations: [
ActivitiStartTaskButton
ActivitiStartTaskComponent
],
providers: [
ActivitiTaskListService
ActivitiTaskListService,
ActivitiPeopleService
]
}).compileComponents().then(() => {
let translateService = TestBed.get(AlfrescoTranslationService);
spyOn(translateService, 'addTranslationFolder').and.stub();
spyOn(translateService.translate, 'get').and.callFake((key) => { return Observable.of(key); });
fixture = TestBed.createComponent(ActivitiStartTaskButton);
activitiStartTaskButton = fixture.componentInstance;
fixture = TestBed.createComponent(ActivitiStartTaskComponent);
activitiStartTaskComponent = fixture.componentInstance;
element = fixture.nativeElement;
fixture.detectChanges();
startTaskButton = <HTMLElement> element.querySelector('#start-task-button');
});
}));
beforeEach(() => {
jasmine.Ajax.install();
service = fixture.debugElement.injector.get(ActivitiTaskListService);
peopleService = fixture.debugElement.injector.get(ActivitiPeopleService);
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'
}
]));
});
afterEach(() => {
jasmine.Ajax.uninstall();
it('should create instance of ActivitiStartTaskComponent', () => {
expect(fixture.componentInstance instanceof ActivitiStartTaskComponent).toBe(true, 'should create ActivitiStartTaskComponent');
});
it('should show start task button', () => {
expect(element.querySelector('#start-task-button')).toBeDefined();
expect(element.querySelector('#start-task-button')).not.toBeNull();
expect(element.querySelector('#start-task-button').textContent).toContain('START_TASK.BUTTON');
it('should fetch fakeform on ngonint', () => {
activitiStartTaskComponent.ngOnInit();
expect(activitiStartTaskComponent.forms).toEqual(fakeForms);
expect(activitiStartTaskComponent.forms[0].name).toEqual('Display Data');
expect(activitiStartTaskComponent.forms[1].name).toEqual('Employee Info');
expect(activitiStartTaskComponent.forms[1].id).toEqual(1111);
expect(getformlistSpy).toHaveBeenCalled();
});
it('should show start dialog on press button', () => {
startTaskButton.click();
expect(element.querySelector('#start-task-dialog')).not.toBeNull();
expect(element.querySelector('#start-task-dialog').getAttribute('open')).not.toBeNull();
expect(element.querySelector('#start-task-dialog-title')).not.toBeNull();
expect(element.querySelector('#start-task-dialog-title').textContent).toContain('START_TASK.DIALOG.TITLE');
});
describe('create task', () => {
it('should close start dialog on cancel button', () => {
startTaskButton.click();
expect(element.querySelector('#start-task-dialog')).not.toBeNull();
expect(element.querySelector('#start-task-dialog').getAttribute('open')).not.toBeNull();
let cancelButton = <HTMLElement> element.querySelector('#button-cancel');
cancelButton.click();
expect(element.querySelector('#start-task-dialog').getAttribute('open')).toBeNull();
});
beforeEach(() => {
jasmine.Ajax.install();
getcreateNewTaskSpy = spyOn(service, 'createNewTask').and.returnValue(Observable.of(
{
id: 91,
name: 'fakeName',
formKey: '4',
assignee: {id: 1001, firstName: 'fakeName', email: 'fake@app.activiti.com'}
}
));
});
it('should attach a task when a form id slected', () => {
let attachFormToATask = spyOn(service, 'attachFormToATask').and.returnValue(Observable.of());
spyOn(service, 'createNewTask').and.callFake(
function() {
return Observable.create(observer => {
observer.next({ id: 'task-id'});
observer.complete();
});
afterEach(() => {
jasmine.Ajax.uninstall();
});
it('should create new task when start is clicked', async(() => {
activitiStartTaskComponent.onSuccess.subscribe((res) => {
expect(res).toBeDefined();
});
activitiStartTaskComponent.appId = 'fakeAppId';
activitiStartTaskComponent.startTaskmodel = new StartTaskModel(startTaskMock);
activitiStartTaskComponent.start();
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 200
});
}));
let createTaskButton = <HTMLElement> element.querySelector('#button-start');
it('should send on onSuccess event when the task is started', async(() => {
activitiStartTaskComponent.onSuccess.subscribe((res) => {
expect(res).toBeDefined();
expect(res.id).toBe(91);
expect(res.name).toBe('fakeName');
expect(res.formKey).toBe('4');
expect(res.assignee.id).toBe(1001);
});
activitiStartTaskComponent.appId = 'fakeAppId';
activitiStartTaskComponent.startTaskmodel = new StartTaskModel(startTaskMock);
activitiStartTaskComponent.start();
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 200,
contentType: 'json',
responseText:
{
id: '91',
name: 'fakeName',
description: 'fakeDescription',
formKey: '4',
assignee: {id: 1001, firstName: 'fakeName', email: 'fake@app.activiti.com'},
dueDate: null,
endDate: null,
duration: null,
priority: 50,
parentTaskId: null,
parentTaskName: null
}
});
}));
activitiStartTaskButton.name = 'fake-name';
activitiStartTaskButton.formId = '123';
startTaskButton.click();
createTaskButton.click();
expect(attachFormToATask).toHaveBeenCalled();
it('should send on onSuccess event when only name is given', async(() => {
activitiStartTaskComponent.onSuccess.subscribe((res) => {
expect(res).toBeDefined();
});
activitiStartTaskComponent.appId = 'fakeAppId';
activitiStartTaskComponent.startTaskmodel.name = 'fakeName';
activitiStartTaskComponent.startTaskmodel = new StartTaskModel(startTaskMock);
activitiStartTaskComponent.start();
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 200,
contentType: 'json',
responseText: {}
});
}));
it('should attach a task when a form id selected', () => {
activitiStartTaskComponent.onSuccess.subscribe((res) => {
expect(res).toBeDefined();
expect(res.formKey).toBe('4');
});
activitiStartTaskComponent.appId = 'fakeAppId';
activitiStartTaskComponent.startTaskmodel = new StartTaskModel(startTaskMock);
activitiStartTaskComponent.start();
expect(getcreateNewTaskSpy).toHaveBeenCalled();
});
it('should not emit onSuccess event when data not present', async(() => {
let onSuccessSpy: jasmine.Spy = spyOn(activitiStartTaskComponent.onSuccess, 'emit');
activitiStartTaskComponent.startTaskmodel = new StartTaskModel(null);
activitiStartTaskComponent.start();
fixture.detectChanges();
expect(getcreateNewTaskSpy).not.toHaveBeenCalled();
expect(onSuccessSpy).not.toHaveBeenCalled();
}));
});
it('should not attach a task when a form id is not slected', () => {
@@ -115,60 +220,56 @@ describe('ActivitiStartTaskButton', () => {
observer.complete();
});
});
let createTaskButton = <HTMLElement> element.querySelector('#button-start');
activitiStartTaskButton.name = 'fake-name';
startTaskButton.click();
activitiStartTaskComponent.startTaskmodel.name = 'fake-name';
createTaskButton.click();
expect(attachFormToATask).not.toHaveBeenCalled();
});
it('should load form when dialogs open', () => {
let loadForms = spyOn(service, 'getFormList').and.returnValue(Observable.of());
startTaskButton.click();
expect(loadForms).toHaveBeenCalled();
it('should show start task button', () => {
expect(element.querySelector('#button-start')).toBeDefined();
expect(element.querySelector('#button-start')).not.toBeNull();
expect(element.querySelector('#button-start').textContent).toContain('START_TASK.FORM.ACTION.START');
});
it('should create new task when start is clicked', () => {
activitiStartTaskButton.onSuccess.subscribe(() => {
expect(element.querySelector('#start-task-dialog').getAttribute('open')).toBeNull();
});
let createTaskButton = <HTMLElement> element.querySelector('#button-start');
startTaskButton.click();
activitiStartTaskButton.name = 'fake-name';
createTaskButton.click();
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 200
});
it('should fetch all users on ngonint', async(() => {
activitiStartTaskComponent.ngOnInit();
expect(activitiStartTaskComponent.people).toBeDefined();
expect(activitiStartTaskComponent.people[0].firstName).toEqual('fakeName');
expect(activitiStartTaskComponent.people[1].firstName).toEqual('fake-name');
expect(activitiStartTaskComponent.people[0].id).toEqual(1);
expect(activitiStartTaskComponent.people[1].id).toEqual(1001);
expect(getWorkflowUsersSpy).toHaveBeenCalled();
}));
it('should not emit TaskDetails OnCancle', () => {
let emitSpy = spyOn(activitiStartTaskComponent.cancel, 'emit');
activitiStartTaskComponent.onCancel();
expect(emitSpy).not.toBeNull();
expect(emitSpy).toHaveBeenCalled();
});
it('alert message is showed on start error', () => {
spyOn(window, 'alert');
activitiStartTaskButton.onSuccess.subscribe(() => {
expect(window.alert).toHaveBeenCalledWith('An error occurred while trying to add the task');
});
let createTaskButton = <HTMLElement> element.querySelector('#button-start');
startTaskButton.click();
activitiStartTaskButton.name = 'fake-name';
createTaskButton.click();
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 403
});
it('should start button disable if name is empty', () => {
let createTaskButton = fixture.nativeElement.querySelector('#button-start');
activitiStartTaskComponent.startTaskmodel.name = '';
fixture.detectChanges();
expect(createTaskButton.disabled).toBeTruthy();
});
it('should send on success event when the task is started', () => {
activitiStartTaskButton.onSuccess.subscribe((res) => {
expect(res).toBeDefined();
});
let createTaskButton = <HTMLElement> element.querySelector('#button-start');
startTaskButton.click();
activitiStartTaskButton.name = 'fake-name';
createTaskButton.click();
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 200,
contentType: 'json',
responseText: {}
});
it('should cancle start task on cancle button clicked', () => {
let emitSpy = spyOn(activitiStartTaskComponent.cancel, 'emit');
let cancleTaskButton = fixture.nativeElement.querySelector('#button-cancle');
activitiStartTaskComponent.startTaskmodel.name = '';
fixture.detectChanges();
cancleTaskButton.click();
expect(emitSpy).not.toBeNull();
expect(emitSpy).toHaveBeenCalled();
});
it('should enable button if name is not empty', () => {
let createTaskButton = fixture.nativeElement.querySelector('#button-start');
activitiStartTaskComponent.startTaskmodel.name = 'fakeName';
fixture.detectChanges();
expect(createTaskButton.enable).toBeFalsy();
});
});

View File

@@ -15,20 +15,20 @@
* limitations under the License.
*/
import { Component, EventEmitter, Input, Output, ViewChild } from '@angular/core';
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { AlfrescoTranslationService, LogService } from 'ng2-alfresco-core';
import { Form } from '../models/form.model';
import { StartTaskModel, User } from '../models/index';
import { TaskDetailsModel } from '../models/task-details.model';
import { ActivitiPeopleService } from '../services/activiti-people.service';
import { ActivitiTaskListService } from './../services/activiti-tasklist.service';
declare let dialogPolyfill: any;
@Component({
selector: 'adf-start-task, activiti-start-task',
templateUrl: './activiti-start-task.component.html',
styleUrls: ['./activiti-start-task.component.css']
})
export class ActivitiStartTaskButton {
export class ActivitiStartTaskComponent implements OnInit {
@Input()
appId: string;
@@ -36,19 +36,18 @@ export class ActivitiStartTaskButton {
@Output()
onSuccess: EventEmitter<any> = new EventEmitter<any>();
@Output()
cancel: EventEmitter<void> = new EventEmitter<void>();
@Output()
error: EventEmitter<any> = new EventEmitter<any>();
@ViewChild('dialog')
dialog: any;
people: User [] = [];
startTaskmodel: StartTaskModel = new StartTaskModel();
forms: Form [];
formId: string = null;
name: string;
description: string;
/**
* Constructor
* @param auth
@@ -57,6 +56,7 @@ export class ActivitiStartTaskButton {
*/
constructor(private translateService: AlfrescoTranslationService,
private taskService: ActivitiTaskListService,
private peopleService: ActivitiPeopleService,
private logService: LogService) {
if (translateService) {
@@ -64,20 +64,22 @@ export class ActivitiStartTaskButton {
}
}
ngOnInit() {
this.loadFormsTask();
this.getUsers();
}
public start() {
if (this.name) {
this.taskService.createNewTask(new TaskDetailsModel({
name: this.name,
description: this.description,
category: this.appId ? '' + this.appId : null
})).subscribe(
if (this.startTaskmodel.name) {
this.startTaskmodel.category = this.appId;
this.taskService.createNewTask(new TaskDetailsModel(this.startTaskmodel)).subscribe(
(res: any) => {
this.onSuccess.emit(res);
this.closeDialog();
this.resetForm();
this.attachForm(res.id);
this.resetForm();
},
(err) => {
this.error.emit(err);
this.logService.error('An error occurred while trying to add the task');
}
);
@@ -85,46 +87,35 @@ export class ActivitiStartTaskButton {
}
private attachForm(taskId: string) {
if (this.formId && taskId) {
this.taskService.attachFormToATask(taskId, Number(this.formId));
this.formId = null;
if (this.startTaskmodel.formKey && taskId) {
this.taskService.attachFormToATask(taskId, Number(this.startTaskmodel.formKey));
}
}
public cancel() {
this.closeDialog();
}
public showDialog() {
if (!this.dialog.nativeElement.showModal) {
dialogPolyfill.registerDialog(this.dialog.nativeElement);
}
this.loadFormsTask();
if (this.dialog) {
this.dialog.nativeElement.showModal();
}
public onCancel() {
this.cancel.emit();
}
private loadFormsTask() {
this.taskService.getFormList().subscribe((res: Form[]) => {
this.forms = res;
},
(err) => {
(err) => {
this.error.emit(err);
this.logService.error('An error occurred while trying to get the forms');
});
}
private closeDialog() {
if (this.dialog) {
this.dialog.nativeElement.close();
}
private resetForm() {
this.startTaskmodel = null;
}
private resetForm() {
this.name = '';
this.description = '';
private getUsers() {
this.peopleService.getWorkflowUsers().subscribe((users) => {
this.people = users;
}, (err) => {
this.error.emit(err);
this.logService.error('Could not load users');
});
}
}

View File

@@ -71,13 +71,16 @@
},
"START_TASK": {
"BUTTON": "CREATE TASK",
"DIALOG": {
"FORM": {
"TITLE": "Start Task",
"LABEL": {
"NONE": "None",
"NAME": "Name",
"DESCRIPTION": "Description",
"ATTACHFORM" : "Attach a Form"
"ATTACHFORM" : "Attach a Form",
"ASSIGNEE" : "Assignee",
"FORM" : "Form",
"DATE" : "Choose a Date"
},
"ACTION": {
"START": "Start",

View File

@@ -22,3 +22,4 @@ export * from './user.model';
export * from './task-details.model';
export * from './task-details.event';
export * from './user-event.model';
export * from './start-task.model';

View File

@@ -0,0 +1,44 @@
/*!
* @license
* Copyright 2016 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.
*/
/**
*
* This object represent of the StartTaskModel.
*
*
* @returns {StartTaskModel} .
*/
import { User } from './user.model';
export class StartTaskModel {
name: string;
description: string;
assignee: User;
dueDate: any;
formKey: any;
category: string;
constructor(obj?: any) {
this.name = obj && obj.name || null;
this.description = obj && obj.description || null;
this.assignee = obj && obj.assignee ? new User(obj.assignee) : null;
this.dueDate = obj && obj.dueDate || null;
this.formKey = obj && obj.formKey || null;
this.category = obj && obj.category || null;
}
}

View File

@@ -28,7 +28,7 @@ export class ActivitiPeopleService {
private logService: LogService) {
}
getWorkflowUsers(taskId: string, searchWord: string): Observable<User[]> {
getWorkflowUsers(taskId?: string, searchWord?: string): Observable<User[]> {
let option = {excludeTaskId: taskId, filter: searchWord};
return Observable.fromPromise(this.getWorkflowUserApi(option))
.map((response: any) => <User[]> response.data || [])