From 1727c0280f72b7d0e31c091258017ea06e8c3e42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jovan=20Kruni=C4=87?= Date: Tue, 8 Feb 2022 19:00:27 +0100 Subject: [PATCH] refactor: remove unused fake environment --- angular.json | 29 -- .../_helpers/{fakesearch => data}/filters.ts | 0 src/app/_helpers/data/sample-things.ts | 2 +- src/app/_helpers/fake-backend.interceptor.ts | 383 ------------------ src/app/app.module.ts | 63 ++- src/environments/environment.fake.ts | 35 -- src/environments/environment.prod.ts | 2 +- src/environments/environment.ts | 1 - 8 files changed, 31 insertions(+), 484 deletions(-) rename src/app/_helpers/{fakesearch => data}/filters.ts (100%) delete mode 100644 src/app/_helpers/fake-backend.interceptor.ts delete mode 100644 src/environments/environment.fake.ts diff --git a/angular.json b/angular.json index 9b9455cb..4ecc73f2 100644 --- a/angular.json +++ b/angular.json @@ -101,32 +101,6 @@ } ], "progress": false - }, - "fake": { - "fileReplacements": [ - { - "replace": "src/environments/environment.ts", - "with": "src/environments/environment.fake.ts" - } - ], - "optimization": true, - "outputHashing": "all", - "sourceMap": false, - "namedChunks": false, - "extractLicenses": true, - "vendorChunk": false, - "buildOptimizer": true, - "budgets": [ - { - "type": "initial", - "maximumWarning": "2mb", - "maximumError": "5mb" - }, - { - "type": "anyComponentStyle", - "maximumWarning": "6kb" - } - ] } }, "defaultConfiguration": "" @@ -143,9 +117,6 @@ "ci": { "progress": false, "browserTarget": "app:build" - }, - "fake": { - "browserTarget": "app:build:fake" } } }, diff --git a/src/app/_helpers/fakesearch/filters.ts b/src/app/_helpers/data/filters.ts similarity index 100% rename from src/app/_helpers/fakesearch/filters.ts rename to src/app/_helpers/data/filters.ts diff --git a/src/app/_helpers/data/sample-things.ts b/src/app/_helpers/data/sample-things.ts index 7e6e3ad5..57e5b46d 100644 --- a/src/app/_helpers/data/sample-things.ts +++ b/src/app/_helpers/data/sample-things.ts @@ -34,7 +34,7 @@ import { SCToDoPriority, } from '@openstapps/core'; import {Observable, of} from 'rxjs'; -import {checkFilter} from '../fakesearch/filters'; +import {checkFilter} from './filters'; import {sampleResources} from './resources/test-resources'; /* eslint-disable */ diff --git a/src/app/_helpers/fake-backend.interceptor.ts b/src/app/_helpers/fake-backend.interceptor.ts deleted file mode 100644 index 4641e612..00000000 --- a/src/app/_helpers/fake-backend.interceptor.ts +++ /dev/null @@ -1,383 +0,0 @@ -/* - * Copyright (C) 2021 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 . - */ -import { - HttpClient, - HttpEvent, - HttpHandler, - HttpInterceptor, - HttpRequest, - HttpResponse, - HTTP_INTERCEPTORS, -} from '@angular/common/http'; -import {Injectable} from '@angular/core'; -import { - SCIndexResponse, - SCSettingInputType, - SCThingOriginType, - SCThingType, -} from '@openstapps/core'; -import {Observable, of} from 'rxjs'; -import {delay, map} from 'rxjs/operators'; -import packageJson from '../../../package.json'; -import {facetsMock} from './data/sample-facets'; -import {SampleThings} from './data/sample-things'; - -/* eslint-disable unicorn/no-abusive-eslint-disable */ -/* eslint-disable */ -export const sampleIndexResponse: SCIndexResponse = { - app: { - aboutPages: {}, - campusPolygon: { - coordinates: [ - [ - [ - 13.31916332244873, - 52.50796756998264, - ], - [ - 13.336544036865234, - 52.50796756998264, - ], - [ - 13.336544036865234, - 52.51726547416385, - ], - [ - 13.31916332244873, - 52.51726547416385, - ], - [ - 13.31916332244873, - 52.50796756998264, - ], - ], - ], - type: 'Polygon', - }, - features: { - }, - menus: [ - { - icon: 'menu', - id: 'main', - items: [ - { - icon: 'search', - route: '/search', - title: 'search', - translations: { - de: { - title: 'Suche', - }, - en: { - title: 'search', - }, - }, - }, - { - icon: 'map', - route: '/map', - title: 'campus map', - translations: { - de: { - title: 'Campus Karte', - }, - en: { - title: 'campus map', - }, - }, - }, - { - icon: 'cafe', - route: '/canteen', - title: 'canteen', - translations: { - de: { - title: 'Mensa', - }, - en: { - title: 'canteen', - }, - }, - }, - ], - name: 'main menu', - translations: { - de: { - name: 'Hauptmenü', - }, - en: { - name: 'main menu', - }, - }, - }, - { - icon: 'person', - id: 'personal', - items: [ - { - icon: 'settings', - route: '/settings', - title: 'settings', - translations: { - de: { - title: 'Einstellungen', - }, - en: { - title: 'settings', - }, - }, - }, - { - icon: 'information', - route: '/about', - title: 'about', - translations: { - de: { - title: 'Über StApps', - }, - en: { - title: 'About StApps', - }, - }, - }, - ], - name: 'Your Study-App', - translations: { - de: { - name: 'Deine Studi-App', - }, - en: { - name: 'Your Study-App', - }, - }, - }, - ], - name: 'StApps - Technische Universität Berlin', - privacyPolicyUrl: 'https://stappsbe01.innocampus.tu-berlin.de/_static/privacy.md', - settings: [ - { - categories: ['profile'], - defaultValue: 'student', - description: 'The user group the app is going to be used.' - + 'This settings for example is getting used for the predefined price category of mensa meals.', - inputType: SCSettingInputType.SingleChoice, - name: 'group', - order: 1, - origin: { - indexed: '2018-09-11T12:30:00Z', - name: 'Dummy', - type: SCThingOriginType.Remote, - }, - translations: { - de: { - description: 'Mit welcher Benutzergruppe soll die App verwendet werden?' - + ' Die Einstellung wird beispielsweise für die Vorauswahl der Preiskategorie der Mensa verwendet.', - name: 'Gruppe', - values: [ - 'Student', - 'Angestellter', - 'Gast', - ], - }, - en: { - description: 'The user group the app is going to be used.' - + 'This settings for example is getting used for the predefined price category of mensa meals.', - name: 'Group', - values: [ - 'Student', - 'Employee', - 'Guest', - ], - }, - }, - type: SCThingType.Setting, - uid: '2c97aa36-4aa2-43de-bc5d-a2b2cb3a530e', - values: ['student', 'employee', 'guest'], - }, - { - categories: ['profile'], - defaultValue: 'en', - description: 'The language this app is going to use.', - inputType: SCSettingInputType.SingleChoice, - name: 'language', - order: 0, - origin: { - indexed: '2018-09-11T12:30:00Z', - name: 'Dummy', - type: SCThingOriginType.Remote, - }, - translations: { - de: { - description: 'Die Sprache in der die App angezeigt wird.', - name: 'Sprache', - values: [ - 'Deutsch', - 'English', - ], - }, - en: { - description: 'The language this app is going to use.', - name: 'Language', - values: [ - 'Deutsch', - 'English', - ], - }, - }, - type: SCThingType.Setting, - uid: 'dc9d6dec-6576-45ef-9e35-3598c0d6a662', - values: ['de', 'en'], - }, - ], - }, - auth: {}, - backend: { - SCVersion: packageJson.dependencies['@openstapps/core'], - externalRequestTimeout: 5000, - hiddenTypes: [ - SCThingType.DateSeries, - SCThingType.Diff, - SCThingType.Floor, - ], - mappingIgnoredTags: [], - maxMultiSearchRouteQueries: 5, - maxRequestBodySize: 512 * 1024, - name: 'Technische Universität Berlin', - namespace: '909a8cbc-8520-456c-b474-ef1525f14209', - sortableFields: [ - { - fieldName: 'name', - sortTypes: ['ducet'], - }, - { - fieldName: 'type', - sortTypes: ['ducet'], - }, - { - fieldName: 'categories', - onlyOnTypes: [ - SCThingType.AcademicEvent, - SCThingType.Building, - SCThingType.Catalog, - SCThingType.Dish, - SCThingType.PointOfInterest, - SCThingType.Room, - ], - sortTypes: ['ducet'], - }, - { - fieldName: 'geo.point.coordinates', - onlyOnTypes: [ - SCThingType.Building, - SCThingType.PointOfInterest, - SCThingType.Room, - ], - sortTypes: ['distance'], - }, - { - fieldName: 'geo.point.coordinates', - onlyOnTypes: [ - SCThingType.Building, - SCThingType.PointOfInterest, - SCThingType.Room, - ], - sortTypes: ['distance'], - }, - { - fieldName: 'inPlace.geo.point.coordinates', - onlyOnTypes: [ - SCThingType.DateSeries, - SCThingType.Dish, - SCThingType.Floor, - SCThingType.Organization, - SCThingType.PointOfInterest, - SCThingType.Room, - SCThingType.Ticket, - ], - sortTypes: ['distance'], - }, - { - fieldName: 'offers', - onlyOnTypes: [ - SCThingType.Dish, - ], - sortTypes: ['price'], - }, - ], - }, -}; - -/* eslint-enable no-magic-numbers */ - -/** - * TODO - */ -@Injectable() -export class FakeBackendInterceptor implements HttpInterceptor { - - /** - * Delay time of faked responses - */ - RESPONSE_DELAY = 1000; - - /** - * TODO - */ - sampleFetcher: SampleThings; - - constructor(http: HttpClient) { - this.sampleFetcher = new SampleThings(http); - } - - /** - * TODO - */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - intercept(request: HttpRequest, next: HttpHandler): Observable> { - 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 - } - 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) - // eslint-disable-next-line @typescript-eslint/no-explicit-any - .pipe(map((sampleData: any) => { - return new HttpResponse({status: 200, body: {data: sampleData}}); - }), delay(this.RESPONSE_DELAY)); // add delay for skeleton screens to be seen (see !16) - } - } - - return this.sampleFetcher.getSampleThings(request.body.filter) - // eslint-disable-next-line @typescript-eslint/no-explicit-any - .pipe(map((sampleData: any) => { - return new HttpResponse({status: 200, body: {data: sampleData, facets: facetsMock}}); - }), delay(this.RESPONSE_DELAY)); // add delay for skeleton screens to be seen (see !16) - } - } - - return next.handle(request); - } -} - -export const fakeBackendProvider = { - multi: true, - provide: HTTP_INTERCEPTORS, - useClass: FakeBackendInterceptor, -}; diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 249961d5..dbac2c4e 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -20,7 +20,7 @@ import { } from '@angular/common'; import {HttpClient, HttpClientModule} from '@angular/common/http'; import localeDe from '@angular/common/locales/de'; -import {APP_INITIALIZER, NgModule, Provider} from '@angular/core'; +import {APP_INITIALIZER, NgModule} from '@angular/core'; import {BrowserModule} from '@angular/platform-browser'; import {RouteReuseStrategy} from '@angular/router'; import {Diagnostic} from '@ionic-native/diagnostic/ngx'; @@ -50,7 +50,6 @@ import {SettingsModule} from './modules/settings/settings.module'; import {SettingsProvider} from './modules/settings/settings.provider'; import {StorageModule} from './modules/storage/storage.module'; import {ThingTranslateModule} from './translation/thing-translate.module'; -import {fakeBackendProvider} from './_helpers/fake-backend.interceptor'; import {UtilModule} from './util/util.module'; import {initLogger} from './_helpers/ts-logger'; import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; @@ -118,35 +117,6 @@ export function createTranslateLoader(http: HttpClient) { return new TranslateHttpLoader(http, './assets/i18n/', '.json'); } -const providers: Provider[] = [ - Diagnostic, - { - provide: RouteReuseStrategy, - useClass: IonicRouteStrategy, - }, - { - provide: LocationStrategy, - useClass: PathLocationStrategy, - }, - { - provide: Browser, - useFactory: browserFactory, - deps: [Platform], - }, - { - provide: APP_INITIALIZER, - multi: true, - deps: [ - NGXLogger, - SettingsProvider, - ConfigProvider, - TranslateService, - ScheduleSyncService, - ], - useFactory: initSettingsFactory, - }, -]; - /** * TODO */ @@ -195,9 +165,34 @@ const providers: Provider[] = [ : NgxLoggerLevel.TRACE, }), ], - providers: environment.use_fake_backend - ? [providers, fakeBackendProvider] - : providers, + providers: [ + Diagnostic, + { + provide: RouteReuseStrategy, + useClass: IonicRouteStrategy, + }, + { + provide: LocationStrategy, + useClass: PathLocationStrategy, + }, + { + provide: Browser, + useFactory: browserFactory, + deps: [Platform], + }, + { + provide: APP_INITIALIZER, + multi: true, + deps: [ + NGXLogger, + SettingsProvider, + ConfigProvider, + TranslateService, + ScheduleSyncService, + ], + useFactory: initSettingsFactory, + }, + ], }) export class AppModule { constructor(public debugDataCollectorService: DebugDataCollectorService) {} diff --git a/src/environments/environment.fake.ts b/src/environments/environment.fake.ts deleted file mode 100644 index 2672630e..00000000 --- a/src/environments/environment.fake.ts +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2018-2022 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 . - */ -// The file contents for the current environment will overwrite these during build. -// The build system defaults to the dev environment which uses `environment.ts`, but if you do -// `ng build --env=prod` then `environment.prod.ts` will be used instead. -// The list of which env maps to which file can be found in `.angular-cli.json`. - -export const environment = { - backend_url: 'https://mobile.server.uni-frankfurt.de', - daia_url: 'https://daia.hebis.de/DAIA2/UB_Frankfurt', - app_host: 'mobile.app.uni-frankfurt.de', - backend_version: '2.0.0', - use_fake_backend: true, - production: false, -}; - -/* - * In development mode, to ignore zone related error stack frames such as - * `zone.run`, `zoneDelegate.invokeTask` for easier debugging, you can - * import the following file, but please comment it out in production mode - * because it will have performance impact when throw error - */ -// import 'zone.js/plugins/zone-error'; // Included with Angular CLI. diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index ce7429b0..087795d4 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -21,8 +21,8 @@ export const environment = { backend_url: 'https://mobile.server.uni-frankfurt.de', daia_url: 'https://daia.hebis.de/DAIA2/UB_Frankfurt', app_host: 'mobile.app.uni-frankfurt.de', + custom_url_scheme: 'de.anyschool.app', backend_version: '2.0.0', - use_fake_backend: false, production: true, }; diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 4da36a93..044e2c3f 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -23,7 +23,6 @@ export const environment = { app_host: 'mobile.app.uni-frankfurt.de', custom_url_scheme: 'de.anyschool.app', backend_version: '2.0.0', - use_fake_backend: false, production: false, };