mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-03-14 10:42:40 +00:00
fix: update core and apply stricter tslint rules
This commit is contained in:
@@ -1,3 +1,17 @@
|
||||
/*
|
||||
* Copyright (C) 2019 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/* tslint:disable */
|
||||
export const sampleResources = [{
|
||||
'errorNames': [],
|
||||
|
||||
@@ -20,10 +20,11 @@ import {SCAcademicEvent, SCArticle, SCBook, SCBuilding, SCCatalog,
|
||||
import {Observable, of} from 'rxjs';
|
||||
import {sampleResources} from './resources/test-resources';
|
||||
|
||||
// tslint:disable:no-magic-numbers
|
||||
const sampleMessages: SCMessage[] = [
|
||||
{
|
||||
audiences: ['students'],
|
||||
message: 'Foo Message Text',
|
||||
messageBody: 'Foo Message Text',
|
||||
name: 'Foo Message',
|
||||
origin: {
|
||||
indexed: 'SOME-DATE',
|
||||
@@ -35,7 +36,7 @@ const sampleMessages: SCMessage[] = [
|
||||
},
|
||||
{
|
||||
audiences: ['employees'],
|
||||
message: 'Bar Message Text',
|
||||
messageBody: 'Bar Message Text',
|
||||
name: 'Bar Message',
|
||||
origin: {
|
||||
indexed: 'SOME-DATE',
|
||||
@@ -363,31 +364,46 @@ export const sampleThingsMap: {[key in SCThingType | string]: SCThing[]} = {
|
||||
tour: [],
|
||||
video: [],
|
||||
};
|
||||
// tslint:enable:no-magic-numbers
|
||||
|
||||
// provides all or certain sample things to be used in tests or backendless development
|
||||
/**
|
||||
* TODO
|
||||
*
|
||||
* provides all or certain sample things to be used in tests or backendless development
|
||||
*/
|
||||
export function getSampleThings(...uids: string[]): SCThing[] {
|
||||
const sampleThings: SCThing[] = [];
|
||||
if (typeof uids !== 'undefined' && uids.length > 0) {
|
||||
uids.forEach((uid) => {
|
||||
Object.keys(sampleThingsMap).forEach((key) => {
|
||||
sampleThingsMap[key].forEach((thing) => {
|
||||
if (thing.uid === uid) {
|
||||
sampleThings.push(thing);
|
||||
}
|
||||
Object.keys(sampleThingsMap)
|
||||
.forEach((key) => {
|
||||
sampleThingsMap[key].forEach((thing) => {
|
||||
if (thing.uid === uid) {
|
||||
sampleThings.push(thing);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
Object.keys(sampleThingsMap).forEach((key) => {
|
||||
sampleThings.push(...sampleThingsMap[key]);
|
||||
});
|
||||
Object.keys(sampleThingsMap)
|
||||
.forEach((key) => {
|
||||
sampleThings.push(...sampleThingsMap[key]);
|
||||
});
|
||||
}
|
||||
|
||||
return sampleThings;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
@Injectable()
|
||||
export class SampleThings {
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
http: HttpClient;
|
||||
|
||||
constructor(http: HttpClient) {
|
||||
this.http = http;
|
||||
}
|
||||
@@ -396,6 +412,28 @@ export class SampleThings {
|
||||
// // return of(sampleDishes[0]);
|
||||
// }
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
// tslint:disable-next-line:prefer-function-over-method
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
// tslint:disable-next-line:prefer-function-over-method
|
||||
getSampleThings(): Observable<any[]> {
|
||||
// const jsonContent: any[] = await this.http.get('http://localhost:8100/assets/json/joined.json').toPromise();
|
||||
const sampleThings: any[] = [];
|
||||
@@ -405,18 +443,7 @@ export class SampleThings {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,11 +15,12 @@
|
||||
import {HTTP_INTERCEPTORS, HttpClient,
|
||||
HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse} from '@angular/common/http';
|
||||
import {Injectable} from '@angular/core';
|
||||
import {SCIndexResponse, SCThingOriginType, SCThingType} from '@openstapps/core';
|
||||
import {SCIndexResponse, SCSettingInputType, SCThingOriginType, SCThingType} from '@openstapps/core';
|
||||
import {Observable, of} from 'rxjs';
|
||||
import {map, delay} from 'rxjs/operators';
|
||||
import {delay, map} from 'rxjs/operators';
|
||||
import {SampleThings} from './data/sample-things';
|
||||
|
||||
// tslint:disable:no-magic-numbers
|
||||
const sampleIndexResponse: SCIndexResponse = {
|
||||
app: {
|
||||
campusPolygon: {
|
||||
@@ -58,12 +59,9 @@ const sampleIndexResponse: SCIndexResponse = {
|
||||
settings: [
|
||||
{
|
||||
categories: ['profile'],
|
||||
defaultValue: 'student',
|
||||
description: '',
|
||||
input: {
|
||||
defaultValue: 'student',
|
||||
inputType: 'singleChoice',
|
||||
values: ['student', 'employee', 'guest'],
|
||||
},
|
||||
inputType: SCSettingInputType.SingleChoice,
|
||||
name: 'group',
|
||||
order: 1,
|
||||
origin: {
|
||||
@@ -87,15 +85,13 @@ const sampleIndexResponse: SCIndexResponse = {
|
||||
},
|
||||
type: SCThingType.Setting,
|
||||
uid: '',
|
||||
values: ['student', 'employee', 'guest'],
|
||||
},
|
||||
{
|
||||
categories: ['profile'],
|
||||
defaultValue: 'en',
|
||||
description: '',
|
||||
input: {
|
||||
defaultValue: 'en',
|
||||
inputType: 'singleChoice',
|
||||
values: ['en', 'de'],
|
||||
},
|
||||
inputType: SCSettingInputType.SingleChoice,
|
||||
name: 'language',
|
||||
order: 0,
|
||||
origin: {
|
||||
@@ -117,15 +113,13 @@ const sampleIndexResponse: SCIndexResponse = {
|
||||
},
|
||||
type: SCThingType.Setting,
|
||||
uid: '',
|
||||
values: ['en', 'de'],
|
||||
},
|
||||
{
|
||||
categories: ['privacy'],
|
||||
defaultValue: false,
|
||||
description: '',
|
||||
input: {
|
||||
defaultValue: false,
|
||||
inputType: 'singleChoice',
|
||||
values: [true, false],
|
||||
},
|
||||
inputType: SCSettingInputType.SingleChoice,
|
||||
name: 'geoLocation',
|
||||
order: 0,
|
||||
origin: {
|
||||
@@ -149,6 +143,7 @@ const sampleIndexResponse: SCIndexResponse = {
|
||||
},
|
||||
type: SCThingType.Setting,
|
||||
uid: '',
|
||||
values: [true, false],
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -226,20 +221,33 @@ const sampleIndexResponse: SCIndexResponse = {
|
||||
},
|
||||
};
|
||||
|
||||
// tslint:enable:no-magic-numbers
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
@Injectable()
|
||||
export class FakeBackendInterceptor implements HttpInterceptor {
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
sampleFetcher: SampleThings;
|
||||
|
||||
constructor(http: HttpClient) {
|
||||
this.sampleFetcher = new SampleThings(http);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
||||
if (request.method === 'POST') {
|
||||
if (request.url.endsWith('/') && request.method === 'POST') {
|
||||
// respond with expected (faked) index response
|
||||
return of(new HttpResponse({status: 200, body: sampleIndexResponse}));
|
||||
// respond with a search response with sample data
|
||||
} else if (request.url.endsWith('/search')) {
|
||||
}
|
||||
if (request.url.endsWith('/search')) {
|
||||
if (typeof request.body.filter !== 'undefined' && typeof request.body.filter.arguments !== 'undefined') {
|
||||
if (request.body.filter.arguments.field === 'uid') {
|
||||
return this.sampleFetcher.getSampleThing(request.body.filter.arguments.value)
|
||||
@@ -248,11 +256,14 @@ export class FakeBackendInterceptor implements HttpInterceptor {
|
||||
}), delay(1000)); // add delay for skeleton screens to be seen (see !16)
|
||||
}
|
||||
}
|
||||
return this.sampleFetcher.getSampleThings().pipe(map((sampleData: any) => {
|
||||
return new HttpResponse({status: 200, body: {data: sampleData}});
|
||||
}), delay(1000)); // add delay for skeleton screens to be seen (see !16)
|
||||
|
||||
return this.sampleFetcher.getSampleThings()
|
||||
.pipe(map((sampleData: any) => {
|
||||
return new HttpResponse({status: 200, body: {data: sampleData}});
|
||||
}), delay(1000)); // add delay for skeleton screens to be seen (see !16)
|
||||
}
|
||||
}
|
||||
|
||||
return next.handle(request);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user