From 3d54ee9668c44260abb569f34ae0a0112a7862f7 Mon Sep 17 00:00:00 2001 From: Sean Engelhardt Date: Thu, 23 Aug 2018 16:49:51 +0200 Subject: [PATCH] Add viewport service, adjust proxy and environment --- client/proxy.conf.json | 6 ++-- client/src/app/core/core.module.ts | 2 ++ client/src/app/core/services/auth.service.ts | 5 +-- .../src/app/core/services/operator.service.ts | 5 +-- .../core/services/viewport.service.spec.ts | 15 ++++++++ .../src/app/core/services/viewport.service.ts | 30 ++++++++++++++++ client/src/app/site/site.component.html | 29 +++++++-------- client/src/app/site/site.component.ts | 36 ++++++++++--------- client/src/environments/environment.ts | 3 +- 9 files changed, 90 insertions(+), 41 deletions(-) create mode 100644 client/src/app/core/services/viewport.service.spec.ts create mode 100644 client/src/app/core/services/viewport.service.ts diff --git a/client/proxy.conf.json b/client/proxy.conf.json index a5180e715..ef96b287f 100644 --- a/client/proxy.conf.json +++ b/client/proxy.conf.json @@ -1,13 +1,13 @@ { - "/users/login": { + "/apps/users/login": { "target": "http://localhost:8000", "secure": false }, - "/users/logout": { + "/apps/users/logout": { "target": "http://localhost:8000", "secure": false }, - "/users/whoami": { + "/apps/users/whoami": { "target": "http://localhost:8000", "secure": false }, diff --git a/client/src/app/core/core.module.ts b/client/src/app/core/core.module.ts index 28352a857..f98b78c4f 100644 --- a/client/src/app/core/core.module.ts +++ b/client/src/app/core/core.module.ts @@ -12,6 +12,7 @@ import { OperatorService } from './services/operator.service'; import { WebsocketService } from './services/websocket.service'; import { AddHeaderInterceptor } from './http-interceptor'; import { DataSendService } from './services/data-send.service'; +import { ViewportService } from './services/viewport.service'; /** Global Core Module. Contains all global (singleton) services * @@ -26,6 +27,7 @@ import { DataSendService } from './services/data-send.service'; DataStoreService, DataSendService, OperatorService, + ViewportService, WebsocketService, { provide: HTTP_INTERCEPTORS, diff --git a/client/src/app/core/services/auth.service.ts b/client/src/app/core/services/auth.service.ts index e02b6b83d..b418ffc52 100644 --- a/client/src/app/core/services/auth.service.ts +++ b/client/src/app/core/services/auth.service.ts @@ -5,6 +5,7 @@ import { catchError, tap } from 'rxjs/operators'; import { OperatorService } from 'app/core/services/operator.service'; import { OpenSlidesComponent } from '../../openslides.component'; +import { environment } from 'environments/environment'; /** * Authenticates an OpenSlides user with username and password @@ -44,7 +45,7 @@ export class AuthService extends OpenSlidesComponent { username: username, password: password }; - return this.http.post('/users/login/', user).pipe( + return this.http.post(environment.urlPrefix + '/users/login/', user).pipe( tap(resp => this.operator.storeUser(resp.user)), catchError(this.handleError()) ); @@ -60,6 +61,6 @@ export class AuthService extends OpenSlidesComponent { //TODO not yet used logout(): Observable { this.operator.clear(); - return this.http.post('/users/logout/', {}); + return this.http.post(environment.urlPrefix + '/users/logout/', {}); } } diff --git a/client/src/app/core/services/operator.service.ts b/client/src/app/core/services/operator.service.ts index 30d25ee31..420f2693c 100644 --- a/client/src/app/core/services/operator.service.ts +++ b/client/src/app/core/services/operator.service.ts @@ -5,6 +5,7 @@ import { tap, catchError, share } from 'rxjs/operators'; import { OpenSlidesComponent } from 'app/openslides.component'; import { Group } from 'app/shared/models/users/group'; import { User } from '../../shared/models/users/user'; +import { environment } from 'environments/environment'; /** * The operator represents the user who is using OpenSlides. @@ -74,10 +75,10 @@ export class OperatorService extends OpenSlidesComponent { } /** - * calls `/users/whoami` to find out the real operator + * calls `/apps/users/whoami` to find out the real operator */ public whoAmI(): Observable { - return this.http.get('/users/whoami/').pipe( + return this.http.get(environment.urlPrefix + '/users/whoami/').pipe( tap(whoami => { if (whoami && whoami.user) { this.storeUser(whoami.user as User); diff --git a/client/src/app/core/services/viewport.service.spec.ts b/client/src/app/core/services/viewport.service.spec.ts new file mode 100644 index 000000000..9bf530451 --- /dev/null +++ b/client/src/app/core/services/viewport.service.spec.ts @@ -0,0 +1,15 @@ +import { TestBed, inject } from '@angular/core/testing'; + +import { ViewportService } from './viewport.service'; + +describe('ViewportService', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [ViewportService] + }); + }); + + it('should be created', inject([ViewportService], (service: ViewportService) => { + expect(service).toBeTruthy(); + })); +}); diff --git a/client/src/app/core/services/viewport.service.ts b/client/src/app/core/services/viewport.service.ts new file mode 100644 index 000000000..14b360001 --- /dev/null +++ b/client/src/app/core/services/viewport.service.ts @@ -0,0 +1,30 @@ +import { Injectable } from '@angular/core'; +import { BreakpointObserver, Breakpoints, BreakpointState } from '@angular/cdk/layout'; + +@Injectable({ + providedIn: 'root' +}) +export class ViewportService { + /** + * True if Viewport equals mobile or small resolution. + */ + private _isMobile = false; + + constructor(private breakpointObserver: BreakpointObserver) {} + + checkForChange() { + this.breakpointObserver + .observe([Breakpoints.Small, Breakpoints.HandsetPortrait]) + .subscribe((state: BreakpointState) => { + if (state.matches) { + this._isMobile = true; + } else { + this._isMobile = false; + } + }); + } + + get isMobile() { + return this._isMobile; + } +} diff --git a/client/src/app/site/site.component.html b/client/src/app/site/site.component.html index 18a4f37c1..fcc467f34 100644 --- a/client/src/app/site/site.component.html +++ b/client/src/app/site/site.component.html @@ -1,5 +1,5 @@ - + @@ -42,39 +42,39 @@ + (click)='toggleSideNav()'> Home - + Agenda - + Motions + (click)='vp.isMobile ? sideNav.toggle() : null'> Assignments - + Participants - + Files + (click)='toggleSideNav()'> Settings + (click)='toggleSideNav()'> Projector @@ -83,18 +83,15 @@