From 3681132fb92700c5f8a8b1812728b17efab945c5 Mon Sep 17 00:00:00 2001 From: Mathieu Nayrolles Date: Mon, 16 Jan 2017 14:03:17 -0500 Subject: [PATCH] feat(menu): A menu is now swipeable from the left side when logged. The menu contains links to social medias and logout/delete account button --- src/app/app.component.ts | 158 ++++++++++++++++++++++++++++++++++++--- src/app/app.scss | 15 ++++ 2 files changed, 164 insertions(+), 9 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 5867b58..9c9932a 100755 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,19 +1,73 @@ -import { Component, ViewChild } from '@angular/core'; -import { Platform, Nav } from 'ionic-angular'; -import { StatusBar, AppVersion, Keyboard } from 'ionic-native'; +import { Component, ViewChild, EventEmitter } from '@angular/core'; +import { Platform, Nav, AlertController, MenuController } from 'ionic-angular'; +import { StatusBar, AppVersion, Keyboard, InAppBrowser } from 'ionic-native'; +import { Storage } from '@ionic/storage'; import { LogInPage } from '../pages/login/login'; import { GAService, TwAPIService } from 'tw-core'; +import {TranslateService} from 'ng2-translate/ng2-translate'; @Component({ - template: `` + template: ` + + + + Menu + + + + + + + + + + + + + +

v.{{version}}

+
+
+` }) export class MyApp{ @ViewChild(Nav) nav: Nav; rootPage: any = LogInPage; + version:string; + public static userLogged = new EventEmitter(); constructor( - platform: Platform + private platform: Platform, + private twapi:TwAPIService, + private alertController: AlertController, + public menuController: MenuController, + private storage: Storage, + private translate: TranslateService ) { platform.ready().then(() => { @@ -21,14 +75,24 @@ export class MyApp{ // Here you can do any higher level native things you might need. StatusBar.styleDefault(); - TwAPIService.baseUrl = "https://toolwatch.io/api/"; - Keyboard.disableScroll(true); + this.menuController.enable(false); + + MyApp.userLogged.subscribe( + ()=>{this.menuController.enable(true)} + ); + AppVersion.getVersionNumber().then( - (version)=> GAService.appVersion = version + (version)=> { + GAService.appVersion = version; + this.version = version; + } ).catch( - (err)=> {GAService.appVersion = "0.0.0"} + (err)=> { + GAService.appVersion = "0.0.0"; + this.version = "0.0.0"; + } ); if(platform.is('ios')){ @@ -38,5 +102,81 @@ export class MyApp{ } }); } + + intagram(){ + window.open("https://instagram.com/toolwatchapp/"); + } + + pinterest(){ + window.open("https://www.pinterest.com/toolwatch/"); + } + + twitter(){ + window.open("https://twitter.com/ToolwatchApp"); + } + + facebook(){ + window.open("https://www.facebook.com/Toolwatch/"); + } + + contact(){ + let browser = new InAppBrowser('https://go.crisp.im/chat/embed/?website_id=-K4rBEcM_Qbt6JrISVzu', '_blank'); + + /** + * Don't do inject if user isn't logged yet + */ + if(GAService.userEmail != null && GAService.userName != null){ + + + let script:string = '' + + '$crisp.set("user:email", "'+ GAService.userEmail +'");' + + '$crisp.set("user:nickname", "'+ GAService.userName +'");' + +'' + browser.executeScript({code: script}); + } + this.menuController.close(); + + } + + beer(){ + new InAppBrowser('https://ko-fi.com/A872I1N', '_blank'); + this.menuController.close(); + } + + logout(){ + this.menuController.enable(false); + this.storage.remove("tw-api"); + this.nav.setRoot(LogInPage); + } + + deleteAccount(){ + let alert = this.alertController.create({ + title: this.translate.instant('Delete your account'), + message: this.translate.instant('delete-account-warning'), + buttons: + [ + { + text: this.translate.instant('cancel'), + role: 'cancel', + handler: () => { + console.log('Cancel clicked'); + } + }, + { + text: this.translate.instant('confirm'), + handler: () => { + + this.twapi.deleteAccount().then( + ()=>{ + alert.dismiss(); + this.logout(); + } + ); + } + } + ] + }); + alert.present(); + } } diff --git a/src/app/app.scss b/src/app/app.scss index 7492717..107da9f 100755 --- a/src/app/app.scss +++ b/src/app/app.scss @@ -25,4 +25,19 @@ button, .button-md{ .show-page{ background-color: white; +} + +.toolbar-background{ + background-color: #4d77a7 !important; +} + +.toolbar-title{ + color:white !important; +} + +#version{ + position: absolute; + bottom: 0%; + width: 100%; + text-align: center; } \ No newline at end of file