File

projects/netgrif-components-core/src/lib/task/services/task-request-state.service.ts

Description

Holds information about the state of backend requests regarding a single Task instance held within the TaskContentService.

This Service is used by many other Services that handle the necessary logic for working with a single Task on frontend.

Extends

TaskHandlingService

Index

Properties
Methods

Constructor

constructor(_taskContent: TaskContentService)
Parameters :
Name Type Optional
_taskContent TaskContentService No

Methods

Public isLoading
isLoading(taskId?: string)

not held within the injected TaskContentService.

If no value is provided, the state of the task held in the TaskContentService will be returned.

Parameters :
Name Type Optional Description
taskId string Yes

stringId of the {

Returns : boolean | undefined

whether the task is currently loading, or undefined if the queried task is not held within the injected {

Public isUpdating
isUpdating(taskId?: string)

not held within the injected TaskContentService.

If no value is provided, the state of the task held in the TaskContentService will be returned.

Parameters :
Name Type Optional Description
taskId string Yes

stringId of the {

Returns : boolean | undefined

whether the task is currently updating it's data fields, or undefined if the queried task is not held within the injected {

ngOnDestroy
ngOnDestroy()
Returns : void
Public startLoading
startLoading(taskId: string)

Changes the state of the loading indicator to true, if the task held within the injected TaskContentService has the Id that is provided as argument. This method does nothing otherwise.

Parameters :
Name Type Optional Description
taskId string No

stringId of the {

Returns : void
Public startUpdating
startUpdating(taskId: string)

Changes the state of the updating indicator to true, if the task held within the injected TaskContentService has the Id that is provided as argument. This method does nothing otherwise.

Parameters :
Name Type Optional Description
taskId string No

stringId of the {

Returns : void
Public stopLoading
stopLoading(taskId: string)

Changes the state of the loading indicator to false, if the task held within the injected TaskContentService has the Id that is provided as argument. This method does nothing otherwise.

Parameters :
Name Type Optional Description
taskId string No

stringId of the {

Returns : void
Public stopUpdating
stopUpdating(taskId: string)

Changes the state of the updating indicator to false, if the task held within the injected TaskContentService has the Id that is provided as argument. This method does nothing otherwise.

Parameters :
Name Type Optional Description
taskId string No

stringId of the {

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.

Properties

Protected _loading
Type : LoadingEmitter
Protected _updating
Type : LoadingEmitter
import {Injectable, OnDestroy} from '@angular/core';
import {LoadingEmitter} from '../../utility/loading-emitter';
import {TaskContentService} from '../../task-content/services/task-content.service';
import {TaskHandlingService} from './task-handling-service';

/**
 * Holds information about the state of backend requests regarding a single {@link Task} instance
 * held within the {@link TaskContentService}.
 *
 * This Service is used by many other Services that handle the necessary logic for working with a single Task on frontend.
 */
@Injectable()
export class TaskRequestStateService extends TaskHandlingService implements OnDestroy {

    protected _loading: LoadingEmitter;
    protected _updating: LoadingEmitter;

    constructor(_taskContent: TaskContentService) {
        super(_taskContent);
        this._loading = new LoadingEmitter();
        this._updating = new LoadingEmitter();
        _taskContent.task$.subscribe(() => {
            this._loading.off();
            this._updating.off();
        });
    }

    /**
     * @returns whether the task is currently loading, or `undefined` if the queried task is
     * not held within the injected {@link TaskContentService}.
     *
     * @param taskId stringId of the {@link Task} we would like to get information about.
     * If no value is provided, the state of the task held in the {@link TaskContentService} will be returned.
     */
    public isLoading(taskId?: string): boolean | undefined {
        if (taskId !== undefined && !this.isTaskRelevant(taskId)) {
            return undefined;
        }
        return this._loading.isActive;
    }

    /**
     * Changes the state of the loading indicator to `true`,
     * if the task held within the injected {@link TaskContentService} has the Id that is provided as argument.
     * This method does nothing otherwise.
     *
     * @param taskId stringId of the {@link Task} who's loading state we want to change
     */
    public startLoading(taskId: string): void {
        if (!this.isTaskRelevant(taskId)) {
            return;
        }
        this._loading.on();
    }

    /**
     * Changes the state of the loading indicator to `false`,
     * if the task held within the injected {@link TaskContentService} has the Id that is provided as argument.
     * This method does nothing otherwise.
     *
     * @param taskId stringId of the {@link Task} who's loading state we want to change
     */
    public stopLoading(taskId: string): void {
        if (!this.isTaskRelevant(taskId)) {
            return;
        }
        this._loading.off();
    }

    /**
     * @returns whether the task is currently updating it's data fields, or `undefined` if the queried task is
     * not held within the injected {@link TaskContentService}.
     *
     * @param taskId stringId of the {@link Task} we would like to get information about.
     * If no value is provided, the state of the task held in the {@link TaskContentService} will be returned.
     */
    public isUpdating(taskId?: string): boolean | undefined {
        if (taskId !== undefined && !this.isTaskRelevant(taskId)) {
            return undefined;
        }
        return this._updating.isActive;
    }

    /**
     * Changes the state of the updating indicator to `true`,
     * if the task held within the injected {@link TaskContentService} has the Id that is provided as argument.
     * This method does nothing otherwise.
     *
     * @param taskId stringId of the {@link Task} who's loading state we want to change
     */
    public startUpdating(taskId: string): void {
        if (!this.isTaskRelevant(taskId)) {
            return;
        }
        this._updating.on();
    }

    /**
     * Changes the state of the updating indicator to `false`,
     * if the task held within the injected {@link TaskContentService} has the Id that is provided as argument.
     * This method does nothing otherwise.
     *
     * @param taskId stringId of the {@link Task} who's loading state we want to change
     */
    public stopUpdating(taskId: string): void {
        if (!this.isTaskRelevant(taskId)) {
            return;
        }
        this._updating.off();
    }

    ngOnDestroy(): void {
        this._loading.complete();
        this._updating.complete();
    }
}

result-matching ""

    No results matching ""