Fully functional fulltext search
This commit is contained in:
@@ -3,54 +3,116 @@ import { Injectable, Inject } from '@angular/core';
|
||||
import { Schema } from "./jsonschemas.service";
|
||||
import {catchError} from "rxjs/operators";
|
||||
import {from} from "rxjs";
|
||||
import {SortDirection} from "./list/sortable.directive";
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class ApiService {
|
||||
constructor(protected http: HttpClient) {}
|
||||
constructor(protected http: HttpClient) {}
|
||||
|
||||
protected api_root: string = '/api/v1'
|
||||
protected api_root: string = '/api/v1'
|
||||
|
||||
public getSchema() {
|
||||
return this.http.get<Schema>(`${this.api_root}/openapi.json`);
|
||||
}
|
||||
public getSchema() {
|
||||
return this.http.get<Schema>(`${this.api_root}/openapi.json`);
|
||||
}
|
||||
}
|
||||
|
||||
export class SortBy {
|
||||
column: string;
|
||||
direction: SortDirection;
|
||||
|
||||
constructor(column: string, direction: SortDirection = 'asc') {
|
||||
this.column = column;
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
toString() {
|
||||
return `${this.direction}(${this.column})`;
|
||||
}
|
||||
}
|
||||
|
||||
export class Filters {
|
||||
column: string;
|
||||
operator: string;
|
||||
value: string;
|
||||
|
||||
constructor(column: string, operator: string, value: string) {
|
||||
this.column = column;
|
||||
this.operator = operator;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
toString() {
|
||||
if (this.operator == "eq") {
|
||||
|
||||
}
|
||||
return `${this.column} ${this.operator} ${this.value}`;
|
||||
}
|
||||
}
|
||||
|
||||
export class Parameters {
|
||||
page: number;
|
||||
size: number;
|
||||
sortBy: SortBy[];
|
||||
filters: Filters[];
|
||||
|
||||
constructor(page: number, size: number, sortBy: SortBy[], filters: Filters[]) {
|
||||
this.page = page;
|
||||
this.size = size;
|
||||
this.sortBy = sortBy;
|
||||
this.filters = filters;
|
||||
}
|
||||
|
||||
toString() {
|
||||
let s = `size=${this.size}`;
|
||||
s += `&page=${this.page}`;
|
||||
if (this.sortBy.length > 0 ) {
|
||||
s += `&sort_by=${this.sortBy.join(',')}`;
|
||||
}
|
||||
if (this.filters.length > 0 ) {
|
||||
s += `&query=${encodeURIComponent(this.filters.join(' AND '))}`;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class CrudService extends ApiService {
|
||||
|
||||
public loading: boolean = false;
|
||||
public loading: boolean = false;
|
||||
|
||||
public getList(resource: string, page: number, size: number, sortColumn: string, sortDirection: string) {
|
||||
return this.http.get<{ items: [{}] }>(
|
||||
`${this.api_root}/${resource.toLowerCase()}/?size=${size}&page=${page + 1}&sort_by=${sortDirection}(${sortColumn})`
|
||||
);
|
||||
}
|
||||
public getList(resource: string, page: number, size: number, sortBy: SortBy[] = [], filters: Filters[] = []) {
|
||||
|
||||
public get(resource: string, id: string) {
|
||||
return this.http.get<{}>(
|
||||
`${this.api_root}/${resource.toLowerCase()}/${id}`
|
||||
);
|
||||
}
|
||||
let params = new Parameters(page, size, sortBy, filters);
|
||||
|
||||
public update(resource: string, model: any) {
|
||||
return this.http.put<{ menu: [{}] }>(
|
||||
`${this.api_root}/${resource.toLowerCase()}/${model._id}`,
|
||||
model
|
||||
);
|
||||
}
|
||||
return this.http.get<{ items: [{}] }>(
|
||||
`${this.api_root}/${resource.toLowerCase()}/?${params}`
|
||||
);
|
||||
}
|
||||
|
||||
public create(resource: string, model: any) {
|
||||
return this.http.post<{ menu: [{}] }>(
|
||||
`${this.api_root}/${resource.toLowerCase()}/`,
|
||||
model
|
||||
);
|
||||
}
|
||||
public get(resource: string, id: string) {
|
||||
return this.http.get<{}>(
|
||||
`${this.api_root}/${resource.toLowerCase()}/${id}`
|
||||
);
|
||||
}
|
||||
|
||||
public delete(resource: string, model: any) {
|
||||
return this.http.delete<{ menu: [{}] }>(
|
||||
`${this.api_root}/${resource.toLowerCase()}/${model._id}`
|
||||
);
|
||||
}
|
||||
public update(resource: string, model: any) {
|
||||
return this.http.put<{ menu: [{}] }>(
|
||||
`${this.api_root}/${resource.toLowerCase()}/${model._id}`,
|
||||
model
|
||||
);
|
||||
}
|
||||
|
||||
public create(resource: string, model: any) {
|
||||
return this.http.post<{ menu: [{}] }>(
|
||||
`${this.api_root}/${resource.toLowerCase()}/`,
|
||||
model
|
||||
);
|
||||
}
|
||||
|
||||
public delete(resource: string, model: any) {
|
||||
return this.http.delete<{ menu: [{}] }>(
|
||||
`${this.api_root}/${resource.toLowerCase()}/${model._id}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user