[ADF-4128] ProcessCloud - add complete task directive (#4364)

* [ADF-4128] ProcessCloud - add complete task directive

* [ADF-4128]  ProcessCloud - fix completion functionality and add documentation

* [ADF-4128] ProcessCloud - PR changes

* [ADF-4128] ProcessCloud - lint

* [ADF-4148] ProcessServicesCloud - change layout

* [ADF-4128] fix PR changes

* [ADF-4128] - refractor complete task directive

* [ADF-4128] - fix lint

* [ADF-4128] - PR changes

* [ADF-4128] - replace isCompleted method  from service with model method

* [ADF-4128] fix unit tests

* [ADF-4128] - change travis yml

* [ADF-4128] - fix travis.yml

* [ADF-4128] - travis lint
This commit is contained in:
Silviu Popa
2019-03-18 14:34:08 +02:00
committed by Eugenio Romano
parent e586ee17d5
commit 791051edee
20 changed files with 654 additions and 82 deletions

View File

@@ -0,0 +1,82 @@
/*!
* @license
* Copyright 2019 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.
*/
import { Directive, Input, HostListener, Output, EventEmitter, OnInit } from '@angular/core';
import { TaskCloudService } from '../task-header/services/task-cloud.service';
@Directive({
selector: '[adf-cloud-complete-task]'
})
export class CompleteTaskDirective implements OnInit {
/** (Required) The id of the task. */
@Input()
taskId: string;
/** (Required) The name of the application. */
@Input()
appName: string;
/** Emitted when the task is completed. */
@Output()
success: EventEmitter<any> = new EventEmitter<any>();
/** Emitted when the task cannot be completed. */
@Output()
error: EventEmitter<any> = new EventEmitter<any>();
invalidParams: string[] = [];
constructor(private taskListService: TaskCloudService) {}
ngOnInit() {
this.validateInputs();
}
validateInputs() {
if (!this.isTaskValid()) {
this.invalidParams.push('taskId');
}
if (!this.isAppValid()) {
this.invalidParams.push('appName');
}
if (this.invalidParams.length) {
throw new Error(`Attribute ${this.invalidParams.join(', ')} is required`);
}
}
isTaskValid() {
return this.taskId && this.taskId.length > 0;
}
isAppValid() {
return this.appName && this.appName.length > 0;
}
@HostListener('click')
async onClick() {
try {
const result = await this.taskListService.completeTask(this.appName, this.taskId).toPromise();
if (result) {
this.success.emit(result);
}
} catch (error) {
this.error.emit(error);
}
}
}