From 71c38dce84f215ab6ebc274d5ae6ffa613f0ecbf Mon Sep 17 00:00:00 2001 From: Sebastian Roehl Date: Thu, 18 Jan 2018 12:21:38 +0100 Subject: [PATCH] Add component and service for privileges --- web/angular/src/app/app.module.ts | 7 ++-- web/angular/src/app/location.service.ts | 1 - web/angular/src/app/privileges.service.ts | 31 +++++++++++++++++ .../views/components/map/map.component.html | 15 +++++---- .../app/views/components/map/map.component.ts | 33 ++++++++++++------- .../components/shares/shares.component.html | 12 +++++++ .../components/shares/shares.component.ts | 15 +++++++++ 7 files changed, 92 insertions(+), 22 deletions(-) create mode 100644 web/angular/src/app/privileges.service.ts create mode 100644 web/angular/src/app/views/components/shares/shares.component.html create mode 100644 web/angular/src/app/views/components/shares/shares.component.ts diff --git a/web/angular/src/app/app.module.ts b/web/angular/src/app/app.module.ts index c23740c..e8cf680 100755 --- a/web/angular/src/app/app.module.ts +++ b/web/angular/src/app/app.module.ts @@ -22,11 +22,13 @@ import { RegisterComponent } from './views/pages/register/register.component'; import { HomepageComponent } from './views/components/homepage/homepage.component'; import { ProfileComponent } from './views/components/profile/profile.component'; import { StatisticComponent } from './views/components/statistic/statistic.component'; +import { SharesComponent } from './views/components/shares/shares.component'; import {NotAuthGuard} from "./notAuth.guard"; import {ParentAuthGuard} from "./parentAuth.guard"; import {ApiClientService} from "../api/index"; import {MapComponent} from "./views/components/map/map.component"; import {LocationService} from "./location.service"; +import { PrivilegesService } from './privileges.service'; import {VerifyEmailComponent} from "./views/pages/verify-email/verify-email.component"; import {ResetPasswordComponent} from "./views/pages/reset-password/reset-password.component"; import {ResetPasswordEmailComponent} from "./views/pages/reset-password-email/reset-password-email.component"; @@ -92,7 +94,8 @@ const APP_COMPONENTS = [ ResetPasswordEmailComponent, AdminComponent, UserManagementComponent, - PlaceComponent + PlaceComponent, + SharesComponent ]; // Import directives @@ -156,7 +159,7 @@ import { DatepickerModule, BsDatepickerModule } from 'ngx-bootstrap/datepicker'; {provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true}, { provide: LOCALE_ID, useValue: 'de' }, // add our application services (api access, logging, authentication) - ApiClientService, ConsoleService, AuthGuard, NotAuthGuard, ParentAuthGuard, AuthService, LocationService + ApiClientService, ConsoleService, AuthGuard, NotAuthGuard, ParentAuthGuard, AuthService, LocationService, PrivilegesService ], bootstrap: [ AppComponent ] }) diff --git a/web/angular/src/app/location.service.ts b/web/angular/src/app/location.service.ts index 23b21f2..3a292b1 100755 --- a/web/angular/src/app/location.service.ts +++ b/web/angular/src/app/location.service.ts @@ -28,7 +28,6 @@ export class LocationService { getLocation(shareId: string): void { this.apiClientService.getShareLocation(shareId).subscribe(result => { this.location.next(result.body); - this.consoleService.log(`Fetched location: \n ${this.location.getValue()}`); }, error => { this.consoleService.log(`Error finding the share with id ${shareId}.`); if (error instanceof HttpErrorResponse) { diff --git a/web/angular/src/app/privileges.service.ts b/web/angular/src/app/privileges.service.ts new file mode 100644 index 0000000..ee1c132 --- /dev/null +++ b/web/angular/src/app/privileges.service.ts @@ -0,0 +1,31 @@ +import { Injectable } from '@angular/core'; +import { ApiClientService } from '../api/index'; +import { ConsoleService } from './console.service'; +import { BehaviorSubject } from 'rxjs/BehaviorSubject'; +import { HttpErrorResponse } from '@angular/common/http'; +import { Privilege } from '../api/models/privilege.model'; +import { PrivilegePage } from '../api/models/privilegepage.model'; + +@Injectable() +export class PrivilegesService { + + constructor(private consoleService: ConsoleService, private apiClientService: ApiClientService) { } + + privileges: BehaviorSubject = new BehaviorSubject(null); + error: BehaviorSubject = new BehaviorSubject(null); + + getPrivilegesForCurrentUser(pageOffset: number, pageSize: number) { + this.apiClientService.getCurrentUserPrivileges(pageOffset, pageSize).subscribe(privileges => { + this.privileges.next(privileges.body); + }, error => { + this.consoleService.log('Could not get privileges for current user.'); + if (error instanceof HttpErrorResponse) { + const message = error.status + ': ' + error.statusText; + this.consoleService.log('HttpError: ' + message); + this.error.next(message); + } else { + this.consoleService.log('Unknown error getting the privileges for the current user.'); + } + }); + } +} diff --git a/web/angular/src/app/views/components/map/map.component.html b/web/angular/src/app/views/components/map/map.component.html index 4b00d54..2fad873 100755 --- a/web/angular/src/app/views/components/map/map.component.html +++ b/web/angular/src/app/views/components/map/map.component.html @@ -1,10 +1,11 @@
-
-
-
-
-
+
+
+
+
+
+
@@ -15,10 +16,10 @@