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:
30750
src/app/_helpers/data/resources/test-resources.ts
Normal file
30750
src/app/_helpers/data/resources/test-resources.ts
Normal file
File diff suppressed because it is too large
Load Diff
@@ -12,9 +12,13 @@
|
||||
* 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 {HttpClient} from '@angular/common/http';
|
||||
import {Injectable} from '@angular/core';
|
||||
import {SCAcademicEvent, SCArticle, SCBook, SCBuilding, SCCatalog,
|
||||
SCDateSeries, SCDish, SCFavorite, SCMessage, SCPerson, SCRoom,
|
||||
SCThing, SCThingOriginType, SCThingType, SCToDo, SCToDoPriority} from '@openstapps/core';
|
||||
import {Observable, of} from 'rxjs';
|
||||
import {sampleResources} from './resources/test-resources';
|
||||
|
||||
const sampleMessages: SCMessage[] = [
|
||||
{
|
||||
@@ -45,8 +49,20 @@ const sampleMessages: SCMessage[] = [
|
||||
|
||||
const sampleDishes: SCDish[] = [
|
||||
{
|
||||
categories: ['main dish'],
|
||||
categories: ['main dish', 'salad'],
|
||||
name: 'Foo Dish',
|
||||
// offers: [
|
||||
// {
|
||||
// 'availability': 'in stock',
|
||||
// 'availabilityStarts': '2017-01-30T00:00:00.000Z',
|
||||
// 'availabilityEnds': '2017-01-30T23:59:59.999Z',
|
||||
// 'prices': {
|
||||
// 'default': 4.85,
|
||||
// 'student': 2.85,
|
||||
// 'employee': 3.85,
|
||||
// 'guest': 4.85,
|
||||
// },
|
||||
// ],
|
||||
origin: {
|
||||
indexed: 'SOME-DATE',
|
||||
name: 'some name',
|
||||
@@ -56,7 +72,7 @@ const sampleDishes: SCDish[] = [
|
||||
uid: 'dish-123',
|
||||
},
|
||||
{
|
||||
categories: ['side dish'],
|
||||
categories: ['side dish', 'salad'],
|
||||
name: 'Bar Dish',
|
||||
origin: {
|
||||
indexed: 'SOME-DATE',
|
||||
@@ -368,3 +384,39 @@ export function getSampleThings(...uids: string[]): SCThing[] {
|
||||
}
|
||||
return sampleThings;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class SampleThings {
|
||||
http: HttpClient;
|
||||
constructor(http: HttpClient) {
|
||||
this.http = http;
|
||||
}
|
||||
// getSampleThings(): Observable<any> {
|
||||
// return this.http.get('http://localhost:8100/assets/json/joined.json');
|
||||
// // return of(sampleDishes[0]);
|
||||
// }
|
||||
|
||||
getSampleThings(): Observable<any[]> {
|
||||
// const jsonContent: any[] = await this.http.get('http://localhost:8100/assets/json/joined.json').toPromise();
|
||||
const sampleThings: any[] = [];
|
||||
sampleResources.forEach((resource) => {
|
||||
// tslint:disable-next-line:max-line-length
|
||||
// if ([SCThingType.Video].includes(resource.instance.type as SCThingType)) {
|
||||
sampleThings.push(resource.instance);
|
||||
// }
|
||||
});
|
||||
return of(sampleThings);
|
||||
}
|
||||
|
||||
getSampleThing(uid: string): Observable<any[]> {
|
||||
// const jsonContent: any[] = await this.http.get('http://localhost:8100/assets/json/joined.json').toPromise();
|
||||
const sampleThings: any[] = [];
|
||||
for (const resource of sampleResources) {
|
||||
if (resource.instance.uid as SCThingType === uid) {
|
||||
sampleThings.push(resource.instance);
|
||||
return of(sampleThings);
|
||||
}
|
||||
}
|
||||
return of(sampleThings);
|
||||
}
|
||||
}
|
||||
@@ -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