UNPKG

@rero/ng-core

Version:

RERO angular core library.

156 lines (155 loc) 6.17 kB
import { HttpClient } from '@angular/common/http'; import { FormlyFieldConfig } from '@ngx-formly/core'; import { TranslateService } from '@ngx-translate/core'; import { Observable } from 'rxjs'; import { ApiService } from '../api/api.service'; import { Error } from '../error/error'; import { Record } from './record'; import { RecordHandleErrorService } from './record.handle-error.service'; import * as i0 from "@angular/core"; export declare class RecordService { protected http: HttpClient; protected apiService: ApiService; protected translateService: TranslateService; protected recordHandleErrorService: RecordHandleErrorService; static readonly DEFAULT_REST_RESULTS_SIZE = 10; static readonly MAX_REST_RESULTS_SIZE = 9999; /** * Event for record created */ private onCreate; /** * Event for record updated */ private onUpdate; /** * Event for record deleted */ private onDelete; /** * On create observable * @return onCreate Subject */ get onCreate$(): Observable<RecordEvent>; /** * On update observable * @return onUpdate Subject */ get onUpdate$(): Observable<RecordEvent>; /** * On delete observable * @return onDelete Subject */ get onDelete$(): Observable<RecordEvent>; /** * Get records filtered by given parameters. * * @param type - string, type of resource * @param query - string, keyword to search for * @param page - number, return records corresponding to this page * @param itemsPerPage - number, number of records to return * @param aggregationsFilters - list, option list of filters; usually used by * the aggregation filters. * @param preFilters - object, option list of additional filters. The value can * a string or a list of string to filter with multiple values. * @param headers - HttpHeaders optional http header for the backend call. * @param sort - parameter for sorting records (eg. 'mostrecent' or '-mostrecent') * @param facets - list of strings, define which aggregations/facets should be included into the response. */ getRecords(type: string, query?: string, page?: number, itemsPerPage?: number, aggregationsFilters?: any[], preFilters?: object, headers?: any, sort?: string, facets?: string[]): Observable<Record | Error>; /** * Delete a record. * @param type - string, type of record * @param pid - string, PID to remove */ delete(type: string, pid: string): Observable<void | Error>; /** * Get record data * @param type - string, type of resource * @param pid - string, record PID */ getRecord(type: string, pid: string, resolve?: number, headers?: any): Observable<any | Error>; /** * Return the schema form to generate the form based on the resource given. * @param recordType - string, type of the resource */ getSchemaForm(recordType: string): Observable<any>; /** * Create a new record * @param recordType - string, type of resource * @param record - object, record to create */ create(recordType: string, record: object): Observable<any>; /** * Update a record * @param recordType - string, type of resource * @param pid - string, record PID * @param record - object, record to update */ update(recordType: string, pid: string, record: any): Observable<Object>; /** * Check if a record is already registered with the same value * @param recordType - string, type of record * @param field - string, field to check * @param value - string, value to check * @param excludePid - string, PID to ignore (normally the current record we are checking) */ valueAlreadyExists(recordType: string, field: string, value: string, excludePid: string): Observable<{ alreadyTaken: string; }>; /** * Check if a record is already registered with the same value * @param field - FormlyFieldConfig, field to check * @param recordType - string, type of record * @param excludePid - string, PID to ignore (normally the current record we are checking) * @param term - string, the elasticsearch term to check the uniqueness, use field.key if not given * @param limitToValues - string[], limit the test to a given list of values * @param filter - string, additional es query filters */ uniqueValue(field: FormlyFieldConfig, recordType: string, excludePid?: string, term?: any, limitToValues?: string[], filter?: string): Observable<boolean> | Observable<{ alreadyTaken: any; }>; /** * Transform a total value string or object representation * (ES compatibility v6 and v7) * @param total - string or object * @param relation - boolean * @return integer, text or null */ totalHits(total: any, relation?: boolean): any; /** * Return the suggestions for query and field. * * @param resource Resource type. * @param url URL of suggestions endpoint. * @param field Field to search for suggestions. * @param q Query. * @returns Observable containing the list of suggestions. */ suggestions(resource: string, url: string, field: string, q: string): Observable<Array<string>>; /** * Error handling during api call process. * @param error - HttpErrorResponse * @param resourceName- Name of current resource * @return throwError */ private _handleError; /** * Creates and returns a HttpHeader object to send to request. * @param headers Object containing http headers to send to request. */ private _createRequestHeaders; /** * Create a message for event * @param resource - string * @param data - any */ private _createEvent; static ɵfac: i0.ɵɵFactoryDeclaration<RecordService, never>; static ɵprov: i0.ɵɵInjectableDeclaration<RecordService>; } /** Record Event Interface */ export interface RecordEvent { resource: string; data: any; }