From 3ce3c9ba165f7c13e7a7490facbe86744fd1c98d Mon Sep 17 00:00:00 2001 From: Sebastian Lange Date: Mon, 27 May 2019 16:29:54 +0200 Subject: [PATCH] refactor(menu): refactor main manu --- src/app/_helpers/fake-backend.interceptor.ts | 113 +++++++++++++++++- .../menu/navigation/navigation.component.ts | 41 +++++-- .../modules/menu/navigation/navigation.html | 43 +++++-- src/assets/i18n/de.json | 7 ++ src/assets/i18n/en.json | 7 ++ 5 files changed, 191 insertions(+), 20 deletions(-) diff --git a/src/app/_helpers/fake-backend.interceptor.ts b/src/app/_helpers/fake-backend.interceptor.ts index d61665d8..dd4a2c67 100644 --- a/src/app/_helpers/fake-backend.interceptor.ts +++ b/src/app/_helpers/fake-backend.interceptor.ts @@ -60,7 +60,118 @@ const sampleIndexResponse: SCIndexResponse = { features: { widgets: true, }, - menus: [], + menus: [ + { + icon: 'menu', + id: 'main', + items: [ + { + icon: 'search', + route: '/search', + title: 'search', + translations: { + de: { + title: 'Suche', + }, + en: { + title: 'search', + }, + }, + }, + { + icon: 'map', + route: '/map', + title: 'campus map', + translations: { + de: { + title: 'Campus Karte', + }, + en: { + title: 'campus map', + }, + }, + }, + { + icon: 'cafe', + route: '/canteen', + title: 'canteen', + translations: { + de: { + title: 'Mensa', + }, + en: { + title: 'canteen', + }, + }, + }, + ], + name: '', + translations: { + de: { + name: 'Hauptmenü', + }, + en: { + name: 'main menu', + }, + }, + }, + { + icon: 'person', + id: 'personal', + items: [ + { + icon: 'settings', + route: '/settings', + title: 'settings', + translations: { + de: { + title: 'Einstellungen', + }, + en: { + title: 'settings', + }, + }, + }, + ], + name: 'Your Study-App', + translations: { + de: { + name: 'Deine Studi-App', + }, + en: { + name: 'Your Study-App', + }, + }, + }, + { + icon: '', + id: 'meta', + items: [ + { + icon: 'information', + route: '/about', + title: 'about', + translations: { + de: { + title: 'Über StApps', + }, + en: { + title: 'About StApps', + }, + }, + }, + ], + name: '', + translations: { + de: { + name: '', + }, + en: { + name: '', + }, + }, + }, + ], name: 'StApps - Technische Universität Berlin', privacyPolicyUrl: 'https://stappsbe01.innocampus.tu-berlin.de/_static/privacy.md', settings: [ diff --git a/src/app/modules/menu/navigation/navigation.component.ts b/src/app/modules/menu/navigation/navigation.component.ts index a262cd6e..2e2a0523 100644 --- a/src/app/modules/menu/navigation/navigation.component.ts +++ b/src/app/modules/menu/navigation/navigation.component.ts @@ -13,6 +13,17 @@ * this program. If not, see . */ import {Component} from '@angular/core'; +import {LangChangeEvent, TranslateService} from '@ngx-translate/core'; +import { + SCAppConfigurationMenuCategory, + SCThing, + SCThingTranslator, + SCTranslations, +} from '@openstapps/core'; +import {Logger} from '@openstapps/logger'; +import {ConfigProvider} from '../../config/config.provider'; + +const logger = new Logger(); /** * Generated class for the MenuPage page. @@ -20,22 +31,28 @@ import {Component} from '@angular/core'; * See https://ionicframework.com/docs/components/#navigation for more info on * Ionic pages and navigation. */ - @Component({ selector: 'stapps-navigation', + styleUrls: ['navigation.scss'], templateUrl: 'navigation.html', }) export class NavigationComponent { - /** - * TODO - */ - public pages = [ - {title: 'Search', url: '/search', icon: 'search'}, - {title: 'Settings', url: '/settings', icon: 'settings'}, - ]; + language: keyof SCTranslations = 'en'; + menu: SCAppConfigurationMenuCategory[]; + translator: SCThingTranslator; - constructor() { - // Nothing yet. + constructor(private configProvider: ConfigProvider, + public translateService: TranslateService) { + this.loadMenuEntries().then(() => + logger.log('menuEntries loaded from config: ' + JSON.stringify(this.menu))).catch((error) => { + logger.error(error); + + }); + translateService.onLangChange.subscribe((event: LangChangeEvent) => { + this.language = event.lang as keyof SCTranslations; + this.translator = new SCThingTranslator(this.language, 'en'); + }); + this.translator = new SCThingTranslator('en', 'en'); } /** @@ -46,6 +63,10 @@ export class NavigationComponent { // console.log('ionViewDidLoad MenuPage'); } + async loadMenuEntries() { + this.menu = await this.configProvider.getValue('menus') as SCAppConfigurationMenuCategory[]; + } + // openPage(page) { // this.nav.setRoot(page.component); // } diff --git a/src/app/modules/menu/navigation/navigation.html b/src/app/modules/menu/navigation/navigation.html index 65f7c141..610ca2bf 100644 --- a/src/app/modules/menu/navigation/navigation.html +++ b/src/app/modules/menu/navigation/navigation.html @@ -9,15 +9,40 @@ - - - - - - {{p.title}} - - - + + + {{category.translations[language].name | titlecase}} + + + + + {{item.translations[language].title | titlecase}} + + + + + + {{category.translations[language].name | titlecase}} + + + + + {{item.translations[language].title | titlecase}} + + + + + + {{category.translations[language].name | titlecase}} + + + + + {{item.translations[language].title | titlecase}} + + + + diff --git a/src/assets/i18n/de.json b/src/assets/i18n/de.json index a6319ba7..a663ab3d 100644 --- a/src/assets/i18n/de.json +++ b/src/assets/i18n/de.json @@ -15,6 +15,13 @@ } } }, + "menu": { + "context": { + "title": "Kontext Menü", + "sort": "Sortierung", + "filter": "Filter" + } + }, "settings": { "resetAlert.title": "Alle Einstellungen zurücksetzen?", "resetAlert.message": "Sind Sie sich sicher, alle Einstellungen auf ihre Anfangswerte zurückzusetzen?", diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index e5c20755..0827c9e2 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -15,6 +15,13 @@ } } }, + "menu": { + "context": { + "title": "Context Menu", + "sort": "Sort", + "filter": "Filter" + } + }, "settings": { "resetAlert.title": "Reset all settings?", "resetAlert.message": "Are you shure to reset all settings to defaults values?",