#1233 attach form to a task (#1313)

This commit is contained in:
Mario Romano
2016-12-16 17:19:39 +00:00
committed by Eugenio Romano
parent 128d3af54a
commit 1e4ce68963
6 changed files with 153 additions and 9 deletions

View File

@@ -15,6 +15,17 @@
<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="" selected="selected" selected>None</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">

View File

@@ -23,6 +23,7 @@ import { ActivitiTaskListService } from '../services/activiti-tasklist.service';
import { ActivitiStartTaskButton } from './activiti-start-task.component';
import { TranslationMock } from '../assets/translation.service.mock';
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { Observable } from 'rxjs/Rx';
declare let jasmine: any;
@@ -30,6 +31,7 @@ describe('Activiti Start Task Component', () => {
let activitiStartTaskButton: ActivitiStartTaskButton;
let fixture: ComponentFixture<ActivitiStartTaskButton>;
let service: ActivitiTaskListService;
let element: HTMLElement;
let startTaskButton: HTMLElement;
@@ -51,6 +53,7 @@ describe('Activiti Start Task Component', () => {
beforeEach(() => {
jasmine.Ajax.install();
service = fixture.debugElement.injector.get(ActivitiTaskListService);
});
afterEach(() => {
@@ -80,6 +83,49 @@ describe('Activiti Start Task Component', () => {
expect(element.querySelector('#start-task-dialog').getAttribute('open')).toBeNull();
});
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();
});
});
let createTaskButton = <HTMLElement> element.querySelector('#button-start');
activitiStartTaskButton.name = 'fake-name';
activitiStartTaskButton.formId = '123';
startTaskButton.click();
createTaskButton.click();
expect(attachFormToATask).toHaveBeenCalled();
});
it('should not attach a task when a form id is not 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();
});
});
let createTaskButton = <HTMLElement> element.querySelector('#button-start');
activitiStartTaskButton.name = 'fake-name';
startTaskButton.click();
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 create new task when start is clicked', () => {
activitiStartTaskButton.onSuccess.subscribe(() => {
expect(element.querySelector('#start-task-dialog').getAttribute('open')).toBeNull();

View File

@@ -19,6 +19,7 @@ import { Component, EventEmitter, Input, Output, ViewChild } from '@angular/core
import { AlfrescoTranslationService } from 'ng2-alfresco-core';
import { TaskDetailsModel } from '../models/task-details.model';
import { ActivitiTaskListService } from './../services/activiti-tasklist.service';
import { Form } from '../models/form.model';
declare let componentHandler: any;
declare let dialogPolyfill: any;
@@ -40,6 +41,10 @@ export class ActivitiStartTaskButton {
@ViewChild('dialog')
dialog: any;
forms: Form [];
formId: string;
name: string;
description: string;
@@ -68,6 +73,7 @@ export class ActivitiStartTaskButton {
this.onSuccess.emit(res);
this.closeDialog();
this.resetForm();
this.attachForm(res.id);
},
(err) => {
window.alert('An error occurred while trying to add the task');
@@ -77,6 +83,13 @@ export class ActivitiStartTaskButton {
}
}
private attachForm(taskId: string) {
if (this.formId && taskId) {
this.taskService.attachFormToATask(taskId, Number(this.formId));
this.formId = null;
}
}
public cancel() {
this.closeDialog();
}
@@ -85,11 +98,24 @@ export class ActivitiStartTaskButton {
if (!this.dialog.nativeElement.showModal) {
dialogPolyfill.registerDialog(this.dialog.nativeElement);
}
this.loadFormsTask();
if (this.dialog) {
this.dialog.nativeElement.showModal();
}
}
private loadFormsTask() {
this.taskService.getFormList().subscribe((res: Form[]) => {
this.forms = res;
},
(err) => {
window.alert('An error occurred while trying to get the forms');
console.log(err);
});
}
private closeDialog() {
if (this.dialog) {
this.dialog.nativeElement.close();

View File

@@ -67,7 +67,8 @@
"TITLE": "Start Task",
"LABEL": {
"NAME": "Name",
"DESCRIPTION": "Description"
"DESCRIPTION": "Description",
"ATTACHFORM" : "Attach a Form"
},
"ACTION": {
"START": "Start",

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.
*/
/**
*
* This object represent of the Form.
*
*
* @returns {Form} .
*/
export class Form {
id: number;
name: string;
constructor(id: number, name: string) {
this.name = name;
this.id = id;
}
}

View File

@@ -15,14 +15,15 @@
* limitations under the License.
*/
import {Injectable} from '@angular/core';
import {AlfrescoAuthenticationService, AlfrescoApiService} from 'ng2-alfresco-core';
import {Observable} from 'rxjs/Rx';
import {FilterRepresentationModel} from '../models/filter.model';
import {TaskQueryRequestRepresentationModel} from '../models/filter.model';
import {Comment} from '../models/comment.model';
import {User} from '../models/user.model';
import {TaskDetailsModel} from '../models/task-details.model';
import { Injectable } from '@angular/core';
import { AlfrescoAuthenticationService, AlfrescoApiService } from 'ng2-alfresco-core';
import { Observable } from 'rxjs/Rx';
import { FilterRepresentationModel } from '../models/filter.model';
import { TaskQueryRequestRepresentationModel } from '../models/filter.model';
import { Comment } from '../models/comment.model';
import { User } from '../models/user.model';
import { TaskDetailsModel } from '../models/task-details.model';
import { Form } from '../models/form.model';
@Injectable()
export class ActivitiTaskListService {
@@ -128,6 +129,31 @@ export class ActivitiTaskListService {
}).catch(this.handleError);
}
/**
* Retrive all the form shared with this user
* @returns {TaskDetailsModel}
*/
getFormList(): Observable<Form []> {
let opts = {
'filter': 'myReusableForms', // String | filter
'sort': 'modifiedDesc', // String | sort
'modelType': 2 // Integer | modelType
};
return Observable.fromPromise(this.apiService.getInstance().activiti.modelsApi.getModels(opts)).map(res => res)
.map((response: any) => {
let forms: Form[] = [];
response.data.forEach((form) => {
forms.push(new Form(form.id, form.name));
});
return forms;
}).catch(this.handleError);
}
attachFormToATask(taskId: string, formId: number): Observable<any> {
return Observable.fromPromise(this.apiService.getInstance().activiti.taskApi.attachForm(taskId, {'formId': formId}));
}
/**
* Create and return the default filters
* @param appId