Silviu Popa 31658c0974 [ADF-4127] ProcessServicesCloud - add claim/unclaim directive (#4464)
* [ADF-4127] ProessServicesCloud - claim task directive

* [ADF-4127] - fix doc

* [ADF-4127] - revert docs changes

* [ADF-4127] - revert doc changes

* [ADF-4127] - fix doc and reset sourceLinker.js

* [ADF-4127] - refractor task-cloud.service. add validation for claim/unclaim and fix unit tests

* [ADF-4127] - fix docs files

* [ADF-4127[ - add aditional complete task validation

* [ADF-4127] - PR changes

* [ADF-4127] - complete docs file

* [ADF-4127] - more PR changes

* [ADF-4127] - change Unclaim task name and wait for task to be claimed and unclaimed before emit the success event

* [ADF-4127] - fix unit tests
2019-03-25 12:24:26 +00:00

83 lines
2.3 KiB
TypeScript

/*!
* @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 '../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(): boolean {
return this.taskId && this.taskId.length > 0;
}
isAppValid(): boolean {
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);
}
}
}