import { EventEmitter, OnInit } from '@angular/core'; import { Observable } from 'rxjs'; import { EditErrorType } from '../../enums'; import { BaseComponent } from '../base/base.component'; export declare abstract class EditComponent extends BaseComponent implements OnInit { /** * Public error. * * @readonly * @type {boolean} * @memberof EditComponent */ readonly hasError: boolean; /** * Public property that can be used as change detection. * @returns {boolean} true if there are no changes. */ readonly disabled: boolean; /** * Private property that can be used as change detection. * @returns {boolean} true if there are no changes. */ protected readonly noChange: boolean; /** * The model mostly has id. This can be string or number. */ id: string | number; /** * The model, that contains the T object. */ model: T; /** * Error type. */ errorType: EditErrorType; /** * Options object. This can be added on the sper() call. * @example super({preventInit: true}); */ protected options: EditComponentOptions; /** * This event fires, when the model is updated, and the api responded successfully. */ protected afterModelUpdated: EventEmitter; /** * This event fires, when the model is loaded from the api successfully. */ protected afterModelLoaded: EventEmitter; /** * Error flag. */ private error; /** * The original deep copy of the model, that contains the T object. This populates when the request succeeded. */ private originalModel; /** * @param options Options, that runs before the first initialize. * @example super({preventInit: true}); */ constructor(); /** * Private Initialize. */ ngOnInit(): void; /** * This function starts the uploading methods. UpdateModel(), refreshModel(), etc... */ update(): void; /** * The abstract function, that needs to be implemented in the child element. This method will GET the T model from the api. * @returns Observable * @example public getModel(): Observable { return this.service.getById(+this.id); } */ protected abstract getModel(): Observable; /** * The abstract function, that needs to be implemented in the child element. This method will PUT or POST the T model to the api. * @returns Observable * @example public updateModel(): Observable { return this.service.updateById(this.model, +this.id); } */ protected abstract updateModel(): Observable; /** * This method repopulates the model and the originalModel. This method uses the loading feature, and loads the model from the backend. */ protected reloadModel(): void; /** * This method populates the model and the originalModel. * @param resp Succsessful response from the backend. */ private setModel; /** * This method populates the model and the originalModel from the update response. * @param resp Succsessful response from the backend. */ private refreshModel; /** * Simple error handler. * @param {any} error Error * @param {EditErrorType} errorType Type of error * @param error Type of error. */ private errorHandler; } export interface EditComponent { /** * This optional function runs before the private updateModel() function runs. */ beforeUpdate?(): void; /** * This optional function runs before the afterModelLoaded event emitted. */ beforeModelLoaded(): void; /** * This optional function runs after the afterModelLoaded event fires runs. */ afterLoaded?(success?: boolean): void; /** * This optional function runs after the private updateModel() function runs. */ afterUpdate?(success?: boolean): void; } export interface EditComponentOptions { /** * True, if the first getModel() needs to be prevented. * @default false */ preventInit?: boolean; /** * True, if the model needs to be refreshed from the backend response after the update method. * @default true */ refreshModelFromResponse?: boolean; }