diff --git a/src/app/app-settings.service.ts b/src/app/app-settings.service.ts index 8e9aa82d..70d138ff 100644 --- a/src/app/app-settings.service.ts +++ b/src/app/app-settings.service.ts @@ -180,8 +180,15 @@ export class AppSettingsService { this.replaceConfig('appConfig', upgradedConfig, true); } } - - private loadConfigFromLocalStorage(type: string) { +/** + * Get configuration from local browser storage rather then in + * memory running config. + * + * @param {string} type Possible choices are: appConfig, widgetConfig, layoutConfig, themeConfig, zonesConfig, connectionConfig. + * @return {*} + * @memberof AppSettingsService + */ +public loadConfigFromLocalStorage(type: string) { let config = JSON.parse(localStorage.getItem(type)); if (config === null) { diff --git a/src/app/settings/config/config.component.html b/src/app/settings/config/config.component.html index 1c5c7b5a..d4a813a3 100644 --- a/src/app/settings/config/config.component.html +++ b/src/app/settings/config/config.component.html @@ -58,7 +58,7 @@

Upgradable Configurations Found

Save

Save current configuration to server

diff --git a/src/app/settings/config/config.component.ts b/src/app/settings/config/config.component.ts index 1cab56ef..9191f57b 100644 --- a/src/app/settings/config/config.component.ts +++ b/src/app/settings/config/config.component.ts @@ -130,13 +130,12 @@ export class SettingsConfigComponent implements OnInit, OnDestroy{ if (this.copyConfigForm.value.copySource === 'Local Storage') { if (this.copyConfigForm.value.copyDestination === 'Remote Storage') { // local to remote + this.saveConfig(this.getLocalConfigFromLocalStorage(), this.copyConfigForm.value.destinationTarget.scope, this.copyConfigForm.value.destinationTarget.name); if (this.copyConfigForm.value.destinationTarget.scope === 'user' && this.copyConfigForm.value.destinationTarget.name === 'default' && this.hasToken && !this.isTokenTypeDevice) { - this.notificationsService.sendSnackbarNotification("Local Storage cannot be copied to [user / default] when Sign in option is enabled. Use another copy source", 0, false); - } else { - this.saveConfig(this.getLocalConfig(), this.copyConfigForm.value.destinationTarget.scope, this.copyConfigForm.value.destinationTarget.name); + this.appSettingsService.reloadApp(); } - - } else if(this.copyConfigForm.value.copyDestination === 'Local Storage') { + } + else if(this.copyConfigForm.value.copyDestination === 'Local Storage') { // local to local this.notificationsService.sendSnackbarNotification("Local Storage cannot be copies to Local Storage ", 0, false); } @@ -149,7 +148,7 @@ export class SettingsConfigComponent implements OnInit, OnDestroy{ conf = config }); } catch (error) { - this.notificationsService.sendSnackbarNotification("Error retreiving configuration from server: " + error.statusText, 3000, false); + this.notificationsService.sendSnackbarNotification("Error retrieving configuration from server: " + error.statusText, 3000, false); return; } @@ -364,7 +363,17 @@ export class SettingsConfigComponent implements OnInit, OnDestroy{ }; } - public getLocalConfig(): IConfig { + public getActiveConfig(): IConfig { + let conf: IConfig; + if (this.appSettingsService.useSharedConfig) { + conf = this.getLocalConfigFromMemory(); + } else { + conf = this.getLocalConfigFromLocalStorage(); + } + return conf; + } + + public getLocalConfigFromMemory(): IConfig { let localConfig: IConfig = { "app": this.appSettingsService.getAppConfig(), "widget": this.appSettingsService.getWidgetConfig(), @@ -375,6 +384,17 @@ export class SettingsConfigComponent implements OnInit, OnDestroy{ return localConfig; } + public getLocalConfigFromLocalStorage(): IConfig { + let localConfig: IConfig = { + "app": this.appSettingsService.loadConfigFromLocalStorage('appConfig'), + "widget": this.appSettingsService.loadConfigFromLocalStorage('widgetConfig'), + "layout": this.appSettingsService.loadConfigFromLocalStorage('layoutConfig'), + "theme": this.appSettingsService.loadConfigFromLocalStorage('themeConfig'), + "zones": this.appSettingsService.loadConfigFromLocalStorage('zonesConfig'), + }; + return localConfig; + } + public onSourceSelectChange(event): void { if (event.value === 'Local Storage') { this.copyConfigForm.get('sourceTarget').disable(); diff --git a/src/app/storage.service.ts b/src/app/storage.service.ts index 5fb76ddc..f47b7b71 100644 --- a/src/app/storage.service.ts +++ b/src/app/storage.service.ts @@ -33,7 +33,7 @@ export class StorageService { //console.log(`[Storage Service] Send patch request:\n${JSON.stringify(arg.document)}`); return this.http.post(arg.url, arg.document) .pipe( - tap((_) => console.log("[Storage Service] Remote config patch request completed successfuly")), + tap((_) => console.log("[Storage Service] Remote config patch request completed successfully")), catchError((error) => this.handleError(error)) ); } @@ -45,7 +45,7 @@ export class StorageService { server.serverServiceEndpoint$.subscribe((status: IEndpointStatus) => { if (status.httpServiceUrl !== null) { this.serverEndpoint = status.httpServiceUrl.substring(0,status.httpServiceUrl.length - 4) + "applicationData/"; // this removes 'api/' from the end; - console.log("[Storage Service] Service stratup. AppData API set to: " + this.serverEndpoint); + console.log("[Storage Service] Service startup. AppData API set to: " + this.serverEndpoint); } if (status.operation === 2) { @@ -64,7 +64,7 @@ export class StorageService { // Patch request queue to insure JSON Patch requests to SK server don't run over each other and cause collisions/conflicts. SK does not handle multiple async applicationData access calls this.patchQueue$ .pipe( - concatMap((arg: IPatchAction) => this.patch(arg)) // insures orderly call senquencing + concatMap((arg: IPatchAction) => this.patch(arg)) // insures orderly call sequencing ) .subscribe(_ => { //console.log("[Storage Service] Subscription results received") @@ -72,10 +72,10 @@ export class StorageService { } /** - * Retreives server Application Data config lists for Kip in both Global + * Retrieves server Application Data config lists for Kip in both Global * and User scopes for the current app version. * - * @param {string} [forceConfigFileVersion] Optionnal parameter. Forces the + * @param {string} [forceConfigFileVersion] Optional parameter. Forces the * Signal K configuration file name to a specific version. If not set, configFileVersion * is used by default (set in app-settings and app-initNetwork services). * Old KIP versions used value of 1. @@ -99,7 +99,7 @@ export class StorageService { for(let cname of configNames) { serverConfigs.push({ scope: 'global', name: cname }); } - console.log(`[Storage Service] Retreived Global config list`); + console.log(`[Storage Service] Retrieved Global config list`); }) .catch( error => { @@ -111,7 +111,7 @@ export class StorageService { for(let cname of configNames) { serverConfigs.push({ scope: 'user', name: cname }); } - console.log(`[Storage Service] Retreived User config list`); + console.log(`[Storage Service] Retrieved User config list`); }) .catch( error => { @@ -122,16 +122,16 @@ export class StorageService { } /** - * Retreives version and name specific server Application Data config + * Retrieves version and name specific server Application Data config * from a given scope. * * @param {string} scope String value of either 'global' or 'user' * @param {string} configName String value of the config name - * @param {string} [forceConfigFileVersion] Optionnal parameter. Forces the + * @param {string} [forceConfigFileVersion] Optional parameter. Forces the * Signal K configuration file name to a specific version. If not set, configFileVersion * is used by default (set in app-settings and app-initNetwork services). * Old KIP versions used value of 1. - * @param {boolean} isInitLoad User for AppSettings config initialyzation. If True, config will be keept + * @param {boolean} isInitLoad User for AppSettings config initialization. If True, config will be kept * * @return {*} {IConfig} * @memberof StorageService @@ -146,7 +146,7 @@ export class StorageService { await lastValueFrom(this.http.get(url)) .then(remoteConfig => { conf = remoteConfig; - console.log(`[Storage Service] Retreived config [${configName}] from [${scope}] scope`); + console.log(`[Storage Service] Retrieved config [${configName}] from [${scope}] scope`); if (isInitLoad) { this.InitConfig = remoteConfig; } @@ -159,16 +159,16 @@ export class StorageService { /** * Send configuration data to the server Application Data service - * with a scope and name and optionnal file version. The configuration will be saved in the + * with a scope and name and optional file version. The configuration will be saved in the * current Kip app version file number (9.0.0.json) in applicationData subfolder on the server. * * @usage If the given ConfigName exists in the provided scope for the same version, - * the data will be overwriten/replaced, else it will be created on the server. + * the data will be overwritten/replaced, else it will be created on the server. * * @param {string} scope String value of either 'global' or 'user' * @param {string} configName String value of the config name * @param {IConfig} config config data to be saved - * @return {*} {null} returns null if operation is successfull or raises an error. + * @return {*} {null} returns null if operation is successful or raises an error. * @memberof StorageService */ public async setConfig(scope: string, configName: string, config: IConfig): Promise { @@ -187,10 +187,10 @@ export class StorageService { } /** - * Udpates JSON configuration entry section in the server application storage. This uses the JSON Patch standard. + * Updates JSON configuration entry section in the server application storage. This uses the JSON Patch standard. * * @param {string} ObjType string describing the type of configuration object. Value can be: IAppConfig, IThemeConfig, IWidgetConfig, ILayoutConfig, Array\, Array\, Array\, IZonesConfig, INotificationConfig - * @param {*} value unstrignified update object. The resulting outgoing POST request will automatically strignify. + * @param {*} value unstringified update object. The resulting outgoing POST request will automatically stringify. * @memberof StorageService */ public patchConfig(ObjType: string, value: any) { @@ -294,7 +294,7 @@ export class StorageService { * @param {string} configName name of the configuration. * @param {string} scope the storage scope to use. Can either be: 'user' or 'global'. * @param {string} operation string describing the type action to perform. values can be: 'add', 'replace' or 'remove'. - * @param {IConfig} config unstrignified config object. The resulting outgoing POST request will automatically strignify. + * @param {IConfig} config unstringified config object. The resulting outgoing POST request will automatically stringify. * @param {number} fileVersion Configuration file version. Supported are 9 for current and 1 for old configs. * @memberof StorageService */ @@ -346,7 +346,7 @@ export class StorageService { * * @param {string} scope destination storage scope of either global or user value * @param {string} name configuration name to delete - * @param {string} [forceConfigFileVersion] Optionnal parameter. Forces the + * @param {string} [forceConfigFileVersion] Optional parameter. Forces the * Signal K configuration file name to a specific version. If not set, configFileVersion * is used by default (set in app-settings and app-initNetwork services). * Old KIP versions used value of 1. diff --git a/src/app/widgets/widget-numeric/widget-numeric.component.ts b/src/app/widgets/widget-numeric/widget-numeric.component.ts index b98ff9b5..42f64e6d 100644 --- a/src/app/widgets/widget-numeric/widget-numeric.component.ts +++ b/src/app/widgets/widget-numeric/widget-numeric.component.ts @@ -143,11 +143,11 @@ export class WidgetNumericComponent extends BaseWidgetComponent implements OnIni private drawValue() { let maxTextWidth = Math.floor(this.canvasEl.nativeElement.width - (this.canvasEl.nativeElement.width * 0.15)); let maxTextHeight = Math.floor(this.canvasEl.nativeElement.height - (this.canvasEl.nativeElement.height * 0.2)); - let valueText: any; + let valueText: string; if (this.dataValue !== null) { //TODO: Check for lon/lat special case -- ugly setup. we should probably have a lon/lat widget for this! - let cUnit = this.widgetProperties.config.paths['numericPath'].convertUnitTo; + let cUnit: string = this.widgetProperties.config.paths['numericPath'].convertUnitTo; if (cUnit == 'latitudeSec' || cUnit == 'latitudeMin' || cUnit == 'longitudeSec' || cUnit == 'longitudeMin') { valueText = this.dataValue.toString(); } else {