mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
committed by
Eugenio Romano
parent
128d3af54a
commit
1e4ce68963
@@ -15,6 +15,17 @@
|
|||||||
<label class="mdl-textfield__label" id="task-description-label"
|
<label class="mdl-textfield__label" id="task-description-label"
|
||||||
for="taskDescription">{{'START_TASK.DIALOG.LABEL.DESCRIPTION'|translate}}</label>
|
for="taskDescription">{{'START_TASK.DIALOG.LABEL.DESCRIPTION'|translate}}</label>
|
||||||
</div>
|
</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>
|
||||||
<div class="mdl-dialog__actions">
|
<div class="mdl-dialog__actions">
|
||||||
<button type="button" id="button-start" (click)="start()" class="mdl-button">
|
<button type="button" id="button-start" (click)="start()" class="mdl-button">
|
||||||
|
@@ -23,6 +23,7 @@ import { ActivitiTaskListService } from '../services/activiti-tasklist.service';
|
|||||||
import { ActivitiStartTaskButton } from './activiti-start-task.component';
|
import { ActivitiStartTaskButton } from './activiti-start-task.component';
|
||||||
import { TranslationMock } from '../assets/translation.service.mock';
|
import { TranslationMock } from '../assets/translation.service.mock';
|
||||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||||
|
import { Observable } from 'rxjs/Rx';
|
||||||
|
|
||||||
declare let jasmine: any;
|
declare let jasmine: any;
|
||||||
|
|
||||||
@@ -30,6 +31,7 @@ describe('Activiti Start Task Component', () => {
|
|||||||
|
|
||||||
let activitiStartTaskButton: ActivitiStartTaskButton;
|
let activitiStartTaskButton: ActivitiStartTaskButton;
|
||||||
let fixture: ComponentFixture<ActivitiStartTaskButton>;
|
let fixture: ComponentFixture<ActivitiStartTaskButton>;
|
||||||
|
let service: ActivitiTaskListService;
|
||||||
let element: HTMLElement;
|
let element: HTMLElement;
|
||||||
let startTaskButton: HTMLElement;
|
let startTaskButton: HTMLElement;
|
||||||
|
|
||||||
@@ -51,6 +53,7 @@ describe('Activiti Start Task Component', () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jasmine.Ajax.install();
|
jasmine.Ajax.install();
|
||||||
|
service = fixture.debugElement.injector.get(ActivitiTaskListService);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@@ -80,6 +83,49 @@ describe('Activiti Start Task Component', () => {
|
|||||||
expect(element.querySelector('#start-task-dialog').getAttribute('open')).toBeNull();
|
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', () => {
|
it('should create new task when start is clicked', () => {
|
||||||
activitiStartTaskButton.onSuccess.subscribe(() => {
|
activitiStartTaskButton.onSuccess.subscribe(() => {
|
||||||
expect(element.querySelector('#start-task-dialog').getAttribute('open')).toBeNull();
|
expect(element.querySelector('#start-task-dialog').getAttribute('open')).toBeNull();
|
||||||
|
@@ -19,6 +19,7 @@ import { Component, EventEmitter, Input, Output, ViewChild } from '@angular/core
|
|||||||
import { AlfrescoTranslationService } from 'ng2-alfresco-core';
|
import { AlfrescoTranslationService } from 'ng2-alfresco-core';
|
||||||
import { TaskDetailsModel } from '../models/task-details.model';
|
import { TaskDetailsModel } from '../models/task-details.model';
|
||||||
import { ActivitiTaskListService } from './../services/activiti-tasklist.service';
|
import { ActivitiTaskListService } from './../services/activiti-tasklist.service';
|
||||||
|
import { Form } from '../models/form.model';
|
||||||
|
|
||||||
declare let componentHandler: any;
|
declare let componentHandler: any;
|
||||||
declare let dialogPolyfill: any;
|
declare let dialogPolyfill: any;
|
||||||
@@ -40,6 +41,10 @@ export class ActivitiStartTaskButton {
|
|||||||
@ViewChild('dialog')
|
@ViewChild('dialog')
|
||||||
dialog: any;
|
dialog: any;
|
||||||
|
|
||||||
|
forms: Form [];
|
||||||
|
|
||||||
|
formId: string;
|
||||||
|
|
||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
|
|
||||||
@@ -68,6 +73,7 @@ export class ActivitiStartTaskButton {
|
|||||||
this.onSuccess.emit(res);
|
this.onSuccess.emit(res);
|
||||||
this.closeDialog();
|
this.closeDialog();
|
||||||
this.resetForm();
|
this.resetForm();
|
||||||
|
this.attachForm(res.id);
|
||||||
},
|
},
|
||||||
(err) => {
|
(err) => {
|
||||||
window.alert('An error occurred while trying to add the task');
|
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() {
|
public cancel() {
|
||||||
this.closeDialog();
|
this.closeDialog();
|
||||||
}
|
}
|
||||||
@@ -85,11 +98,24 @@ export class ActivitiStartTaskButton {
|
|||||||
if (!this.dialog.nativeElement.showModal) {
|
if (!this.dialog.nativeElement.showModal) {
|
||||||
dialogPolyfill.registerDialog(this.dialog.nativeElement);
|
dialogPolyfill.registerDialog(this.dialog.nativeElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.loadFormsTask();
|
||||||
|
|
||||||
if (this.dialog) {
|
if (this.dialog) {
|
||||||
this.dialog.nativeElement.showModal();
|
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() {
|
private closeDialog() {
|
||||||
if (this.dialog) {
|
if (this.dialog) {
|
||||||
this.dialog.nativeElement.close();
|
this.dialog.nativeElement.close();
|
||||||
|
@@ -67,7 +67,8 @@
|
|||||||
"TITLE": "Start Task",
|
"TITLE": "Start Task",
|
||||||
"LABEL": {
|
"LABEL": {
|
||||||
"NAME": "Name",
|
"NAME": "Name",
|
||||||
"DESCRIPTION": "Description"
|
"DESCRIPTION": "Description",
|
||||||
|
"ATTACHFORM" : "Attach a Form"
|
||||||
},
|
},
|
||||||
"ACTION": {
|
"ACTION": {
|
||||||
"START": "Start",
|
"START": "Start",
|
||||||
|
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
@@ -15,14 +15,15 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {Injectable} from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {AlfrescoAuthenticationService, AlfrescoApiService} from 'ng2-alfresco-core';
|
import { AlfrescoAuthenticationService, AlfrescoApiService } from 'ng2-alfresco-core';
|
||||||
import {Observable} from 'rxjs/Rx';
|
import { Observable } from 'rxjs/Rx';
|
||||||
import {FilterRepresentationModel} from '../models/filter.model';
|
import { FilterRepresentationModel } from '../models/filter.model';
|
||||||
import {TaskQueryRequestRepresentationModel} from '../models/filter.model';
|
import { TaskQueryRequestRepresentationModel } from '../models/filter.model';
|
||||||
import {Comment} from '../models/comment.model';
|
import { Comment } from '../models/comment.model';
|
||||||
import {User} from '../models/user.model';
|
import { User } from '../models/user.model';
|
||||||
import {TaskDetailsModel} from '../models/task-details.model';
|
import { TaskDetailsModel } from '../models/task-details.model';
|
||||||
|
import { Form } from '../models/form.model';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ActivitiTaskListService {
|
export class ActivitiTaskListService {
|
||||||
@@ -128,6 +129,31 @@ export class ActivitiTaskListService {
|
|||||||
}).catch(this.handleError);
|
}).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
|
* Create and return the default filters
|
||||||
* @param appId
|
* @param appId
|
||||||
|
Reference in New Issue
Block a user