From 0610c8b76f88d87eff46430cf1e6bdd8f254faaf Mon Sep 17 00:00:00 2001 From: spekulaas Date: Mon, 3 Jan 2022 02:03:00 +0100 Subject: [PATCH] finished initializing cards from storage --- AuthentesApp/src/app/app.component.ts | 14 +-- .../src/app/modalsGame/modalsGame.page.ts | 41 ++++++++- AuthentesApp/src/app/services/game.service.ts | 43 +++++++-- AuthentesApp/src/app/values/values.page.html | 6 +- AuthentesApp/src/app/values/values.page.ts | 87 +++---------------- 5 files changed, 101 insertions(+), 90 deletions(-) diff --git a/AuthentesApp/src/app/app.component.ts b/AuthentesApp/src/app/app.component.ts index 4a255a5..c503cf3 100644 --- a/AuthentesApp/src/app/app.component.ts +++ b/AuthentesApp/src/app/app.component.ts @@ -1,5 +1,7 @@ import { Component } from '@angular/core'; import { StatusBar } from '@ionic-native/status-bar/ngx'; +import { Platform } from '@ionic/angular'; +import { StorageService } from './services/storage.service'; @Component({ selector: 'app-root', @@ -7,11 +9,13 @@ import { StatusBar } from '@ionic-native/status-bar/ngx'; styleUrls: ['app.component.scss'], }) export class AppComponent { - constructor(statusbar: StatusBar) { - // platform.ready().then(() => { - // Okay, so the platform is ready and our plugins are available. - // Here you can do any higher level native things you might need. - statusbar.hide(); + constructor(private statusbar: StatusBar, private platform: Platform, private storage: StorageService) {} + + async ngOnInit() { + await this.platform.ready(); + console.log("[App] Initializing Authentes app..."); + this.statusbar.hide(); + await this.storage.init(); } } diff --git a/AuthentesApp/src/app/modalsGame/modalsGame.page.ts b/AuthentesApp/src/app/modalsGame/modalsGame.page.ts index 71c5392..33b0044 100644 --- a/AuthentesApp/src/app/modalsGame/modalsGame.page.ts +++ b/AuthentesApp/src/app/modalsGame/modalsGame.page.ts @@ -39,10 +39,47 @@ export class ModalsGamePage { // check if game cookie exists // create cookie with data if non existing // continue or restart with cookie - await console.log(this.game.checkGameStorage(game)); - console.log("pardon?"); + switch(await this.game.checkGameStorage(game)){ + case "continue":{ + // dont have to do anything cookie already exists + break; + } + case "create":{ + //create game storage + await this.game.createGameStorage(game); + break; + } + case "restart":{ + // remove and create a new cookie + await this.game.removeGameStorage(game); + await this.game.createGameStorage(game); + break; + } + default:{ + // stay in modal do nothing + return; + } + } + // when all the steps are done and clicked on play, dismiss modal and open page this.dismiss(); + + // initialize the corrosponding game + switch (game) { + case "Wellnesswheel": + + break; + case "Lifeline": + + break; + case "Beliefs": + + break; + case "Values": + await this.game.initValuesGame(); + break; + } + // routing is in lowercase, set text to lower this.router.navigateByUrl(`/${game.toLowerCase()}`); } diff --git a/AuthentesApp/src/app/services/game.service.ts b/AuthentesApp/src/app/services/game.service.ts index 863e215..7c42687 100644 --- a/AuthentesApp/src/app/services/game.service.ts +++ b/AuthentesApp/src/app/services/game.service.ts @@ -1,23 +1,56 @@ import { Injectable } from '@angular/core'; +import { map } from 'rxjs/operators'; import { StorageService } from './storage.service'; import { AlertService } from './alert.service'; +interface ValuesCard { + title: string; +} + @Injectable({ providedIn: 'root' }) export class GameService { + + cardset: Array = []; constructor(private storage: StorageService, private alert: AlertService) {} + // main functions for all the games public async checkGameStorage(game: string){ if(await this.storage.get(`${game.toUpperCase()}GAME_TOKEN`)){ // continue or restart - console.log(await this.alert.presentAlertConfirm("Game found", "Do u want to continue or restart?", "restart", "continue")); - return "storage found"; - } + return await this.alert.presentAlertConfirm("Game found", "Do u want to continue or restart?", "restart", "continue"); + } // standard create new - return "no storage"; - + return "create"; + } + + public async removeGameStorage(game: string){ + await this.storage.remove(`${game.toUpperCase()}GAME_TOKEN`); + } + + // finish when backend is completed + public async createGameStorage(game: string){ + // return await this.http.post(`${config.endpoint}/...`, data).pipe( + + // map((data) => { + + // if (data["Status"] == "Success") { + // console.log(data["Data"]); + await this.storage.set(`${game.toUpperCase()}GAME_TOKEN`, { status: "sorting", cards:[{"title":"Temp_card_1"}, {"title":"Temp_card_2"}, {"title":"Temp_card_3"}, {"title":"Temp_card_4"}, {"title":"Temp_card_5"}, {"title":"Temp_card_6"}, {"title":"Temp_card_7"}, {"title":"Temp_card_8"}]}); + // } + // return data; + // }), + + // ).toPromise(); + } + + public async initValuesGame(){ + console.log("[GameService] Initializing Value game..."); + this.cardset = await this.storage.get("VALUESGAME_TOKEN"); + console.log(this.cardset["cards"]); + this.cardset = this.cardset["cards"]; } } \ No newline at end of file diff --git a/AuthentesApp/src/app/values/values.page.html b/AuthentesApp/src/app/values/values.page.html index bfe37a9..01af74f 100644 --- a/AuthentesApp/src/app/values/values.page.html +++ b/AuthentesApp/src/app/values/values.page.html @@ -35,8 +35,8 @@
-
+

{{ card.title }}

{{ card.description }}

@@ -46,7 +46,7 @@
-

{{ cardset.length }} / 5

+

{{ this.game.cardset.length }} / 5