File

projects/netgrif-components-core/src/lib/task/services/finish-policy.service.ts

Description

Handles the sequence of actions that are performed when a task is being finished, based on the task's configuration.

Extends

TaskHandlingService

Index

Methods

Constructor

constructor(_dataFocusPolicyService: DataFocusPolicyService, _finishTaskService: FinishTaskService, _taskOperations: TaskOperations, taskContentService: TaskContentService)
Parameters :
Name Type Optional
_dataFocusPolicyService DataFocusPolicyService No
_finishTaskService FinishTaskService No
_taskOperations TaskOperations No
taskContentService TaskContentService No

Methods

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 :
Name Type Optional Description
afterAction AfterAction No

the action that should be performed when the finish policy finishes

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 :
Name Type Optional Description
afterAction Subject<boolean> No

the action that should be performed when the finish policy finishes

Returns : void
Public performFinishPolicy
performFinishPolicy(afterAction: AfterAction)

Performs the actions that correspond to the policy defined by the Task when it's finished.

Parameters :
Name Type Optional Default value Description
afterAction AfterAction No new AfterAction()

the action that should be performed when the finish policy finishes

Returns : void
Protected isTaskPresent
isTaskPresent()
Inherited from TaskHandlingService
Returns : boolean

true if a {

Protected isTaskRelevant
isTaskRelevant(requestedTaskId: string)
Inherited from TaskHandlingService

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 :
Name Type Optional Description
requestedTaskId string No

the stringId of the requested task

Returns : boolean

true if the requested task is still relevant to the state of the frontend. Returns false otherwise.

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();
    }
}

result-matching ""

    No results matching ""