projects/netgrif-components-core/src/lib/task/services/finish-policy.service.ts
Handles the sequence of actions that are performed when a task is being finished, based on the task's configuration.
Methods |
|
constructor(_dataFocusPolicyService: DataFocusPolicyService, _finishTaskService: FinishTaskService, _taskOperations: TaskOperations, taskContentService: TaskContentService)
|
|||||||||||||||
Parameters :
|
Protected autoNoDataFinishPolicy | ||||||||
autoNoDataFinishPolicy(afterAction: AfterAction)
|
||||||||
Performs the actions that correspond to the Auto Finish Policy. If the task has no data performs finish and closes the task. Otherwise opens it and performs the data focus policy.
Parameters :
Returns :
void
|
Protected manualFinishPolicy | ||||||||
manualFinishPolicy(afterAction: Subject
|
||||||||
Performs the actions that correspond to the Manual Finish Policy. Opens the task and performs the data focus policy.
Parameters :
Returns :
void
|
Public performFinishPolicy | ||||||||||
performFinishPolicy(afterAction: AfterAction)
|
||||||||||
Performs the actions that correspond to the policy defined by the Task when it's finished.
Parameters :
Returns :
void
|
Protected isTaskPresent |
isTaskPresent()
|
Inherited from
TaskHandlingService
|
Defined in
TaskHandlingService:42
|
Returns :
boolean
|
Protected isTaskRelevant | ||||||||
isTaskRelevant(requestedTaskId: string)
|
||||||||
Inherited from
TaskHandlingService
|
||||||||
Defined in
TaskHandlingService:56
|
||||||||
Checks whether the current state of the TaskContentService and optionally if the SelectedCaseService, is still relevant to the task that was requested. This method is useful if you use UnlimitedTaskContentService, or a similar implementation. It is possible for the currently "selected" task to change in-between a backend request was sent and the response was received. In that case the response is no longer relevant and should be discarded, otherwise an illegal task state could be achieved on frontend.
Parameters :
Returns :
boolean
|
import {Inject, Injectable} from '@angular/core';
import {TaskHandlingService} from './task-handling-service';
import {TaskContentService} from '../../task-content/services/task-content.service';
import {FinishPolicy} from '../../task-content/model/policy';
import {DataFocusPolicyService} from './data-focus-policy.service';
import {NAE_TASK_OPERATIONS} from '../models/task-operations-injection-token';
import {TaskOperations} from '../interfaces/task-operations';
import {FinishTaskService} from './finish-task.service';
import {Subject} from 'rxjs';
import {AfterAction} from '../../utility/call-chain/after-action';
/**
* Handles the sequence of actions that are performed when a task is being finished, based on the task's configuration.
*/
@Injectable()
export class FinishPolicyService extends TaskHandlingService {
constructor(protected _dataFocusPolicyService: DataFocusPolicyService,
protected _finishTaskService: FinishTaskService,
@Inject(NAE_TASK_OPERATIONS) protected _taskOperations: TaskOperations,
taskContentService: TaskContentService) {
super(taskContentService);
}
/**
* Performs the actions that correspond to the policy defined by the Task when it's finished.
* @param afterAction the action that should be performed when the finish policy finishes
*/
public performFinishPolicy(afterAction: AfterAction = new AfterAction()): void {
if (this._safeTask.finishPolicy === FinishPolicy.autoNoData && !!this._safeTask.user) {
this.autoNoDataFinishPolicy(afterAction);
} else {
this.manualFinishPolicy(afterAction);
}
}
/**
* Performs the actions that correspond to the [Auto Finish Policy]{@link FinishPolicy#autoNoData}.
*
* If the task has no data performs finish and [closes]{@link TaskOperations#close} the task.
* Otherwise [opens]{@link TaskOperations#open} it and performs the [data focus policy]{@link DataFocusPolicyService}.
*
* @param afterAction the action that should be performed when the finish policy finishes
*/
protected autoNoDataFinishPolicy(afterAction: AfterAction): void {
if (this._safeTask.dataSize <= 0) {
this._finishTaskService.validateDataAndFinish(afterAction);
} else {
this._taskOperations.open();
this._dataFocusPolicyService.performDataFocusPolicy();
afterAction.resolve(true);
}
}
/**
* Performs the actions that correspond to the [Manual Finish Policy]{@link FinishPolicy#manual}.
*
* [Opens]{@link TaskOperations#open} the task and performs the [data focus policy]{@link DataFocusPolicyService}.
*
* @param afterAction the action that should be performed when the finish policy finishes
*/
protected manualFinishPolicy(afterAction: Subject<boolean>): void {
this._taskOperations.open();
this._dataFocusPolicyService.performDataFocusPolicy();
afterAction.next(true);
afterAction.complete();
}
}