mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 17:12:43 +00:00
feat: add basic templates for data list items
This commit is contained in:
@@ -12,34 +12,88 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {HTTP_INTERCEPTORS, HttpEvent,
|
||||
HttpHandler, HttpInterceptor, HttpRequest, HttpResponse} from '@angular/common/http';
|
||||
import {HTTP_INTERCEPTORS, HttpClient,
|
||||
HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse} from '@angular/common/http';
|
||||
import {Injectable} from '@angular/core';
|
||||
import {SCThing} from '@openstapps/core';
|
||||
import {Observable, of} from 'rxjs';
|
||||
import {getSampleThings} from './data/sampleThings';
|
||||
import {Observable} from 'rxjs';
|
||||
// import {SCThing} from '@openstapps/core';
|
||||
// import {Observable, of} from 'rxjs';
|
||||
import {map} from 'rxjs/operators';
|
||||
import {SampleThings} from './data/sample-things';
|
||||
|
||||
@Injectable()
|
||||
export class FakeBackendInterceptor implements HttpInterceptor {
|
||||
sampleFetcher: SampleThings;
|
||||
// http: HttpClient;
|
||||
// tslint:disable-next-line:no-empty
|
||||
constructor() {
|
||||
constructor(http: HttpClient) {
|
||||
this.sampleFetcher = new SampleThings(http);
|
||||
// this.http = http;
|
||||
}
|
||||
|
||||
// intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
||||
// let data: SCThing[] = [];
|
||||
// // fake responses for search requests for easier (backendless) development process
|
||||
// if (request.url.endsWith('/search') && request.method === 'POST') {
|
||||
// if (typeof request.body.filter !== 'undefined' && typeof request.body.filter.arguments !== 'undefined') {
|
||||
// if (request.body.filter.arguments.field === 'uid') {
|
||||
// // provide items with given uid for search requests requesting single items (detail view)
|
||||
// data = getSampleThings(request.body.filter.arguments.value);
|
||||
// return this.sampleFetcher.getSampleThings().pipe(map((sampleData: any) => {
|
||||
// return new HttpResponse({status: 200, body: {data: [sampleData.instance]}});
|
||||
// // return new HttpResponse({status: 200, body: {data: [sampleData.instance]}});
|
||||
// }),
|
||||
// // data = getSampleThings();
|
||||
// );
|
||||
// }
|
||||
// } else {
|
||||
// // if filter and arguments are not set, then provide all sample items (things)
|
||||
// data = getSampleThings();
|
||||
// // fake a response of the backend with previously defined data
|
||||
// return of(new HttpResponse({status: 200, body: {data: data}}));
|
||||
// }
|
||||
// // fake a response of the backend with previously defined data
|
||||
// // return of(new HttpResponse({status: 200, body: {data: data}}));
|
||||
// return next.handle(request);
|
||||
// } else {
|
||||
// // for all other requests, forward the requests to actually requested URL (backend)
|
||||
// return next.handle(request);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// }
|
||||
// intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
||||
// // let data: SCThing[] = [];
|
||||
// // fake responses for search requests for easier (backendless) development process
|
||||
// if (request.url.endsWith('/search') && request.method === 'POST') {
|
||||
// return this.sampleFetcher.getSampleThings().pipe(map((sampleData: any) => {
|
||||
// return new HttpResponse({status: 200, body: {data: sampleData}});
|
||||
// // return new HttpResponse({status: 200, body: {data: [sampleData.instance]}});
|
||||
// }));
|
||||
// // return of(new HttpResponse({status: 200, body: {data: data}}));
|
||||
// } else {
|
||||
// // for all other requests, forward the requests to actually requested URL (backend)
|
||||
// return next.handle(request);
|
||||
// }
|
||||
// }
|
||||
|
||||
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
||||
let data: SCThing[] = [];
|
||||
// let data: SCThing[] = [];
|
||||
// fake responses for search requests for easier (backendless) development process
|
||||
if (request.url.endsWith('/search') && request.method === 'POST') {
|
||||
if (typeof request.body.filter !== 'undefined' && typeof request.body.filter.arguments !== 'undefined') {
|
||||
if (request.body.filter.arguments.field === 'uid') {
|
||||
// provide items with given uid for search requests requesting single items (detail view)
|
||||
data = getSampleThings(request.body.filter.arguments.value);
|
||||
return this.sampleFetcher.getSampleThing(request.body.filter.arguments.value).pipe(map((sampleData: any) => {
|
||||
return new HttpResponse({status: 200, body: {data: sampleData}});
|
||||
}));
|
||||
}
|
||||
} else {
|
||||
// if filter and arguments are not set, then provide all sample items (things)
|
||||
data = getSampleThings();
|
||||
}
|
||||
// fake a response of the backend with previously defined data
|
||||
return of(new HttpResponse({status: 200, body: {data: data}}));
|
||||
return this.sampleFetcher.getSampleThings().pipe(map((sampleData: any) => {
|
||||
return new HttpResponse({status: 200, body: {data: sampleData}});
|
||||
// return new HttpResponse({status: 200, body: {data: [sampleData.instance]}});
|
||||
}));
|
||||
// return of(new HttpResponse({status: 200, body: {data: data}}));
|
||||
} else {
|
||||
// for all other requests, forward the requests to actually requested URL (backend)
|
||||
return next.handle(request);
|
||||
|
||||
Reference in New Issue
Block a user