From 6eb4dcf1772a73897ec33d21cdf3a3afec83fa81 Mon Sep 17 00:00:00 2001 From: Paul Thiel Date: Mon, 18 Apr 2016 18:05:00 +0200 Subject: [PATCH] feat(): add impressum page and add menu icons update(): change style of username update(): add JWTDecoder service and get username from the jwt --- app/pages/contact/contact.html | 54 ++++++++++++++++++++ app/pages/contact/contact.ts | 49 ++++++++++++++++++ app/pages/representation/representation.html | 27 +++++++--- app/pages/representation/representation.ts | 21 +++++++- app/services/JWTDecoder.ts | 9 ++++ app/services/SessionAccessor.ts | 1 - config.xml | 1 + 7 files changed, 151 insertions(+), 11 deletions(-) create mode 100644 app/pages/contact/contact.html create mode 100644 app/pages/contact/contact.ts create mode 100644 app/services/JWTDecoder.ts diff --git a/app/pages/contact/contact.html b/app/pages/contact/contact.html new file mode 100644 index 0000000..fd329a5 --- /dev/null +++ b/app/pages/contact/contact.html @@ -0,0 +1,54 @@ + + + Vertretungsplan + + +
+ + + {{ currentUser }} + +
+
+ + + + + + + +
+ + + + + Kontakt + + + + + +
+
+ Diese App wurde von Paul Gschwendtner und Paul Thiel programmiert. +
+ + + +
+ +
\ No newline at end of file diff --git a/app/pages/contact/contact.ts b/app/pages/contact/contact.ts new file mode 100644 index 0000000..8cd883d --- /dev/null +++ b/app/pages/contact/contact.ts @@ -0,0 +1,49 @@ +import {Page, NavController, MenuController} from 'ionic-angular/index'; +import {SessionAccessor} from '../../services/SessionAccessor'; +import {JWTDecoder} from '../../services/JWTDecoder' +import {LoginPage} from "../login/login"; +import {RepresentationPage} from "../representation/representation"; + +@Page({ + templateUrl: 'build/pages/contact/contact.html', + providers: [SessionAccessor, JWTDecoder] +}) +export class ContactPage { + + isMenuAnimating: boolean = false; + currentUser: string; + currentClass: string; + + constructor(private nav: NavController, + private session: SessionAccessor, + private jwtDecoder: JWTDecoder, + private menu: MenuController) { + + session.getToken().then((token) => { + this.currentUser = JSON.parse(jwtDecoder.decodeToken(token)).username; + this.currentClass = JSON.parse(jwtDecoder.decodeToken(token)).class; + }); + } + + showRepresentations() { + this.menu.close().then(() => { + this.nav.setRoot(RepresentationPage); + }); + } + + toggleMenu() { + if (this.isMenuAnimating) return; + + this.isMenuAnimating = true; + this.menu.toggle().then(() => { + this.isMenuAnimating = false; + }); + } + + logout() { + this.session.setToken(null); + this.menu.close().then(() => { + this.nav.setRoot(LoginPage); + }); + } +} \ No newline at end of file diff --git a/app/pages/representation/representation.html b/app/pages/representation/representation.html index ce34f48..9cf831f 100644 --- a/app/pages/representation/representation.html +++ b/app/pages/representation/representation.html @@ -1,17 +1,33 @@ - + Vertretungsplan + +
+ + + {{ currentUser }} + +
+
+ +
- - diff --git a/app/pages/representation/representation.ts b/app/pages/representation/representation.ts index 8efe99a..6c1c338 100644 --- a/app/pages/representation/representation.ts +++ b/app/pages/representation/representation.ts @@ -1,20 +1,24 @@ import {Page, NavController, Modal, MenuController} from "ionic-angular/index"; import {BackendConnector} from "../../services/BackendConnector"; import {SessionAccessor} from "../../services/SessionAccessor"; +import {JWTDecoder} from '../../services/JWTDecoder'; import {DateUtil} from "../../services/DateUtil"; import {ToTitlePipe} from "../../pipes/ToTitlePipe"; import {ToIconPipe} from "../../pipes/ToIconPipe"; import {AsyncDefaultPipe} from "../../pipes/AsyncDefaultPipe"; import {MoreDetailsModal} from "../../modals/moredetails"; import {LoginPage} from "../login/login"; +import {ContactPage} from '../contact/contact'; @Page({ templateUrl: 'build/pages/representation/representation.html', - providers: [BackendConnector, SessionAccessor, DateUtil], + providers: [BackendConnector, SessionAccessor, DateUtil, JWTDecoder], pipes: [ToTitlePipe, ToIconPipe, AsyncDefaultPipe] }) export class RepresentationPage { + currentUser: string; + currentClass: string; viewDay: string = 'today'; todayDate: Date; tomorrowDate: Date; @@ -27,13 +31,15 @@ export class RepresentationPage { private nav: NavController, private session: SessionAccessor, private dateUtil: DateUtil, + private jwtDecoder: JWTDecoder, private menu: MenuController) { - this.todayDate = dateUtil.getTodayDate(); this.tomorrowDate = dateUtil.getTomorrowDate(); session.getToken().then((token) => { + this.currentUser = JSON.parse(jwtDecoder.decodeToken(token)).username; + this.currentClass = JSON.parse(jwtDecoder.decodeToken(token)).class; this.todayPromise = backend.sendRepresentationRequest(this.todayDate, token); this.tomorrowPromise = backend.sendRepresentationRequest(this.tomorrowDate, token); }); @@ -60,4 +66,15 @@ export class RepresentationPage { this.nav.setRoot(LoginPage); }); } + + showRepresentations() { + //Add refreshing representations + this.toggleMenu(); + } + + showImpressum() { + this.menu.close().then(() => { + this.nav.setRoot(ContactPage); + }); + } } \ No newline at end of file diff --git a/app/services/JWTDecoder.ts b/app/services/JWTDecoder.ts new file mode 100644 index 0000000..71d5459 --- /dev/null +++ b/app/services/JWTDecoder.ts @@ -0,0 +1,9 @@ +import {Injectable} from "angular2/core"; + +@Injectable() +export class JWTDecoder { + + decodeToken(token: string): string { + return window.atob(token.split('.')[1]); + } +} \ No newline at end of file diff --git a/app/services/SessionAccessor.ts b/app/services/SessionAccessor.ts index b623a7b..a3ca555 100644 --- a/app/services/SessionAccessor.ts +++ b/app/services/SessionAccessor.ts @@ -31,5 +31,4 @@ export class SessionAccessor { this.localStorage.set('VP_TOKEN', token); this.sqlStorage.set('VP_TOKEN', token); } - } \ No newline at end of file diff --git a/config.xml b/config.xml index 20786a9..e46c28a 100644 --- a/config.xml +++ b/config.xml @@ -5,6 +5,7 @@ Paul Gschwendtner +