feat(menu): add context menu

Closes #3
This commit is contained in:
Sebastian Lange
2019-05-27 16:38:47 +02:00
parent 3ce3c9ba16
commit 1dbf4515fe
27 changed files with 2261 additions and 767 deletions

View File

@@ -14,12 +14,13 @@
*/
import {Injectable} from '@angular/core';
import {Geolocation} from '@ionic-native/geolocation/ngx';
import {Events} from '@ionic/angular';
import {
SCSetting,
SCSettingValue,
SCSettingValues,
} from '@openstapps/core';
import deepmerge from 'deepmerge';
import deepMerge from 'deepmerge';
import {ConfigProvider} from '../config/config.provider';
import {StorageProvider} from '../storage/storage.provider';
@@ -164,10 +165,12 @@ export class SettingsProvider {
* @param storage TODO
* @param configProvider TODO
* @param geoLocation TODO
* @param events TODO
*/
constructor(private readonly storage: StorageProvider,
private readonly configProvider: ConfigProvider,
private readonly geoLocation: Geolocation) {
private readonly geoLocation: Geolocation,
private readonly events: Events) {
this.categoriesOrder = [];
this.settingsCache = {};
}
@@ -246,8 +249,9 @@ export class SettingsProvider {
}
await this.saveSettingValues();
}
this.initialized = true;
// publish provider initialised
this.events.publish('stapps.settings.initialised');
}
/**
@@ -339,7 +343,7 @@ export class SettingsProvider {
*
* @throws Exception if setting is not provided
*/
public async getValue(category: string, name: string): Promise<unknown> {
public async getValue(category: string, name: string): Promise<SCSettingValue | SCSettingValues> {
await this.init();
if (this.settingExists(category, name)) {
// return a copy of the settings value
@@ -395,7 +399,7 @@ export class SettingsProvider {
const savedSettingsValues: SettingValuesContainer =
await this.storage.get<SettingValuesContainer>(STORAGE_KEY_SETTING_VALUES);
const cacheSettingsValues = this.getSettingValuesFromCache();
const mergedSettingValues = deepmerge(savedSettingsValues, cacheSettingsValues);
const mergedSettingValues = deepMerge(savedSettingsValues, cacheSettingsValues);
await this.storage
.put<SettingValuesContainer>(STORAGE_KEY_SETTING_VALUES, mergedSettingValues);
} else {
@@ -412,7 +416,8 @@ export class SettingsProvider {
}
/**
* Sets a valid value of a setting and persists changes in storage
* Sets a valid value of a setting and persists changes in storage. Also the changes get published bey Events
*
* @param category Category key name
* @param name Setting key name
* @param value Value to be set
@@ -426,8 +431,11 @@ export class SettingsProvider {
const setting: SCSetting = this.settingsCache[category].settings[name];
const isValueValid = SettingsProvider.validateValue(setting, value);
if (isValueValid) {
// set and persist new value
this.settingsCache[category].settings[name].value = value;
await this.saveSettingValues();
// publish setting changes
this.events.publish('stapps.settings.changed', category, name, value);
} else {
throw new Error(`Value "${value}" of type
${typeof value} is not valid for ${setting.inputType}`);