@netgrif/components-core
Version:
Netgrif Application engine frontend core Angular library
193 lines (192 loc) • 12.4 kB
TypeScript
import { OnDestroy } from '@angular/core';
import { Observable, Subject, Subscription } from 'rxjs';
import { TaskContentService } from '../../task-content/services/task-content.service';
import { TaskRequestStateService } from './task-request-state.service';
import { TranslateService } from '@ngx-translate/core';
import { LoggerService } from '../../logger/services/logger.service';
import { SnackBarService } from '../../snack-bar/services/snack-bar.service';
import { TaskResourceService } from '../../resources/engine-endpoint/task-resource.service';
import { FieldConverterService } from '../../task-content/services/field-converter.service';
import { TaskSetDataRequestBody } from '../../resources/interface/task-set-data-request-body';
import { TaskHandlingService } from './task-handling-service';
import { TaskOperations } from '../interfaces/task-operations';
import { HttpErrorResponse } from '@angular/common/http';
import { SelectedCaseService } from './selected-case.service';
import { TaskEvent } from '../../task-content/model/task-event';
import { TaskEventService } from '../../task-content/services/task-event.service';
import { DataField } from '../../data-fields/models/abstract-data-field';
import { CallChainService } from '../../utility/call-chain/call-chain.service';
import { DataGroup } from '../../resources/interface/data-groups';
import { EventQueueService } from '../../event-queue/services/event-queue.service';
import { AfterAction } from '../../utility/call-chain/after-action';
import { UserComparatorService } from '../../user/services/user-comparator.service';
import { TaskSetDataRequestContext } from '../models/task-set-data-request-context';
import { EventOutcomeMessageResource } from '../../resources/interface/message-resource';
import { EventService } from '../../event/services/event.service';
import { ChangedFieldsService } from '../../changed-fields/services/changed-fields.service';
import { FrontActionService } from "../../actions/services/front-action.service";
import * as i0 from "@angular/core";
/**
* Handles the loading and updating of data fields and behaviour of
* a single Task object managed by a {@link TaskContentService} instance.
*/
export declare class TaskDataService extends TaskHandlingService implements OnDestroy {
protected _taskState: TaskRequestStateService;
protected _translate: TranslateService;
protected _log: LoggerService;
protected _snackBar: SnackBarService;
protected _taskResourceService: TaskResourceService;
protected _fieldConverterService: FieldConverterService;
protected _taskEvent: TaskEventService;
protected _taskOperations: TaskOperations;
protected _afterActionFactory: CallChainService;
protected _eventQueue: EventQueueService;
protected _userComparator: UserComparatorService;
protected _eventService: EventService;
protected _changedFieldsService: ChangedFieldsService;
protected _frontActionService: FrontActionService;
protected _updateSuccess$: Subject<boolean>;
protected _dataReloadSubscription: Subscription;
constructor(_taskState: TaskRequestStateService, _translate: TranslateService, _log: LoggerService, _snackBar: SnackBarService, _taskResourceService: TaskResourceService, _fieldConverterService: FieldConverterService, _taskEvent: TaskEventService, _taskOperations: TaskOperations, _selectedCaseService: SelectedCaseService, _taskContentService: TaskContentService, _afterActionFactory: CallChainService, _eventQueue: EventQueueService, _userComparator: UserComparatorService, _eventService: EventService, _changedFieldsService: ChangedFieldsService, _frontActionService: FrontActionService);
ngOnDestroy(): void;
/**
* Contains information about the success or failure of backend
* calls in [updateTaskDataFields]{@link TaskDataService#updateTaskDataFields} method.
*/
get updateSuccess$(): Observable<boolean>;
/**
* Loads the Data Fields of an uninitialized Task from backend
* and populates the Task managed by {@link TaskContentService} with the appropriate objects.
*
* Beware that if the Task has some data already loaded this function does nothing
* and only passes `true` to the `afterAction` argument.
*
* If the task held within the {@link TaskContentService} changes before a response is received, the response will be ignored
* and the `afterAction` will not be executed.
*
* @param afterAction if the request completes successfully emits `true` into the Subject, otherwise `false` will be emitted
* @param force set to `true` if you need force reload of all task data
*/
initializeTaskDataFields(afterAction?: AfterAction, force?: boolean): void;
/**
* Performs a `getData` request on the task currently stored in the `taskContent` service
* @param afterAction the action that should be performed after the request is processed
* @param force set to `true` if you need force reload of all task data
* @param nextEvent indicates to the event queue that the next event can be processed
*/
protected performGetDataRequest(afterAction: AfterAction, force: boolean, nextEvent: AfterAction): void;
/**
* Processes a successful outcome of a `getData` request
* @param gottenTaskId the ID of the task whose data was requested
* @param dataGroups the returned data groups of the task
* @param afterAction the action that should be performed after the request is processed
* @param nextEvent indicates to the event queue that the next event can be processed
*/
protected processSuccessfulGetDataRequest(gottenTaskId: string, dataGroups: Array<DataGroup>, afterAction: AfterAction, nextEvent: AfterAction): void;
/**
* Processes an erroneous outcome of a `getData` request
* @param gottenTaskId the ID of the task whose data was requested
* @param error the returned error
* @param afterAction the action that should be performed after the request is processed
* @param nextEvent indicates to the event queue that the next event can be processed
*/
protected processErroneousGetDataRequest(gottenTaskId: string, error: HttpErrorResponse | Error, afterAction: AfterAction, nextEvent: AfterAction): void;
/**
* Collects all changed data fields and notifies the backend of the changes.
*
* If the request is successful clears the [changed]{@link DataField#changed} flag on all data fields that were a part of the request
* and emits a {@link ChangedFields} object into this object's [changedFields$]{@link TaskDataService#changedFields$} stream.
*
* If the task held within the {@link TaskContentService} changes before a response is received, the response will be ignored
* and the `afterAction` will not be executed.
*
* @param afterAction if the request completes successfully emits `true` into the Subject, otherwise `false` will be emitted
*/
updateTaskDataFields(afterAction?: AfterAction): void;
/**
* @ignore
* Goes over all the data fields in the managed Task and if they are valid and changed adds them to the set data request
*/
protected createUpdateRequestContext(): TaskSetDataRequestContext;
protected addFieldToSetDataRequestBody(context: TaskSetDataRequestContext, taskId: string, field: DataField<any>): void;
protected isAutocompleteEnumException(field: DataField<unknown>): boolean;
/**
* @param field the checked field
* @returns whether the field was updated on frontend and thus the backend should be notified
*/
protected wasFieldUpdated(field: DataField<unknown>): boolean;
/**
* Checks whether the request could still be performed by the logged user
* @param request
*/
protected isSetDataRequestStillValid(request: TaskSetDataRequestBody): boolean;
/**
* Performs a `setData` request on the task currently stored in the `taskContent` service
* @param setTaskId ID of the task
* @param context context of the `setData` request
* @param afterAction the action that should be performed after the request is processed
* @param nextEvent indicates to the event queue that the next event can be processed
*/
protected performSetDataRequest(setTaskId: string, context: TaskSetDataRequestContext, afterAction: AfterAction, nextEvent: AfterAction): void;
/**
* Processes an unsuccessful outcome of a `setData` request
* @param setTaskId the ID of the task whose data was set
* @param response the resulting Event outcome of the set data request
* @param afterAction the action that should be performed after the request is processed
* @param nextEvent indicates to the event queue that the next event can be processed
* @param body hold the data that was sent in request
*/
protected processUnsuccessfulSetDataRequest(setTaskId: string, response: EventOutcomeMessageResource, afterAction: AfterAction, nextEvent: AfterAction, context: TaskSetDataRequestContext): void;
/**
* Processes a successful outcome of a `setData` request
* @param setTaskId the ID of the task whose data was set
* @param response the resulting Event outcome of the set data request
* @param afterAction the action that should be performed after the request is processed
* @param nextEvent indicates to the event queue that the next event can be processed
* @param context hold the data that was sent in request
*/
protected processSuccessfulSetDataRequest(setTaskId: string, response: EventOutcomeMessageResource, afterAction: AfterAction, nextEvent: AfterAction, context: TaskSetDataRequestContext): void;
/**
* Processes an erroneous outcome of a `setData` request
* @param setTaskId the ID of the task whose data was set
* @param error the returned error
* @param afterAction the action that should be performed after the request is processed
* @param nextEvent indicates to the event queue that the next event can be processed
* @param body hold the data that was sent in request
*/
protected processErroneousSetDataRequest(setTaskId: string, error: HttpErrorResponse, afterAction: AfterAction, nextEvent: AfterAction, context: TaskSetDataRequestContext): void;
/**
* Reverts the effects of a failed `setData` request, so that the user sees current values.
* @param context the context of the failed request
*/
protected revertSetDataRequest(context: TaskSetDataRequestContext): void;
/**
* Compares the values that are in the backend compatible format as given by the {@link FieldConverterService}
* and determines whether they are the same value, or not.
* @param current the current value (can also be called `value1` or `left`)
* @param old the new value (can also be called `value2` or `right`)
* @returns `true` if the values are the same and `false` otherwise
*/
protected compareBackendFormattedFieldValues(current: any, old: any): boolean;
/**
* @ignore
*
* stops loading and updating indicators, and emits the `result` value
* to both the `afterAction` and [_updateSuccess$]{@link TaskDataService#_updateSuccess$} streams.
*
* @param afterAction the call chain steam of the update data method
* @param result result of the update data request
* @param setTaskId the ID of the {@link Task}, who's state should be updated
*/
protected updateStateInfo(afterAction: AfterAction, result: boolean, setTaskId: string): void;
/**
* Publishes a get/set data notification to the {@link TaskEventService}
* @param event the event that occurred to the task
* @param success whether the get/set data operation was successful or not
*/
protected sendNotification(event: TaskEvent.GET_DATA | TaskEvent.SET_DATA, success: boolean): void;
protected revertToPreviousValue(context: TaskSetDataRequestContext): void;
protected clearWaitingForResponseFlag(body: TaskSetDataRequestBody): void;
static ɵfac: i0.ɵɵFactoryDeclaration<TaskDataService, [null, null, null, null, null, null, null, null, { optional: true; }, null, null, null, null, null, null, null]>;
static ɵprov: i0.ɵɵInjectableDeclaration<TaskDataService>;
}