@bd-innovations/abstract-section
Version:
A bunch of abstract logic for the section
83 lines (82 loc) • 2.75 kB
TypeScript
import { OnInit } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { AbstractDialogComponent } from '../abstract-dialog.component';
import { MatDialogRef } from '@angular/material/dialog';
import { AbstractDialogConfig } from '../../config/abstract-dialog.config';
import { AbstractService } from '../../providers/abstract.service';
import { Observable } from 'rxjs';
/**
* @deprecated
* */
export declare abstract class AbstractEditComponent<T> extends AbstractDialogComponent implements OnInit {
data: AbstractDialogConfig<T>;
service: AbstractService<T>;
dialogRef: MatDialogRef<AbstractEditComponent<T>, T>;
/**
* by default true, override with false when data already exist
*/
requestInitialData: boolean;
form: FormGroup;
/**
* is truly while http requests are pending
*/
pending: boolean;
protected constructor(data: AbstractDialogConfig<T>, service: AbstractService<T>, dialogRef: MatDialogRef<AbstractEditComponent<T>, T>);
/**
* if element has a keyValue & requestInitialData is true sets pending as true
* & calls getInitData() & subscribes on it
* - on response calls onSuccessfulDataInit()
* - on error calls onDataInitError()
* else calls onNullElementOrKeyValue()
*/
ngOnInit(): void;
/**
* returns service's getOneByKeyValue(keyValue)
*/
getInitData(): Observable<T>;
/**
* puts API response into data.element
* creates form with API response value
* sets pending as false
* calls afterDataInit()
* @param res: API response
*/
onSuccessfulDataInit(res: T): void;
/**
* closes dialog
* @param error: API error
*/
onDataInitError(error: any): void;
/**
* creates form with data.element
* calls afterDataInit()
*/
onNullElementOrKeyValue(): void;
/**
* use for any custom logic after getting data from API
*/
afterDataInit(): void;
abstract returnForm(obj?: T): FormGroup;
/**
* sets pending as true
* check keyValue of element, if it's true will call putRequest() else will call postRequest()
* @param submit: optional - will call API with provided submit value or take form value
*/
submit(val?: any): void;
/**
* returns service's post method
* @param submit: any value to send into post
*/
postRequest(submit: T): Observable<T>;
/**
* returns service's put method
* @param submit: any value to send into put
*/
putRequest(submit: T): Observable<T>;
/**
* handle request error if needed
* sets pending as false
* @param err: API response error
*/
onRequestError(err: any): void;
}