Skip to content

Commit

Permalink
Godind/issue232 (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
godind authored Nov 26, 2023
1 parent 7d45488 commit 8c0fb81
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 30 deletions.
11 changes: 9 additions & 2 deletions src/app/app-settings.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/settings/config/config.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ <h3>Upgradable Configurations Found</h3>
<div class="flex-item">
<form
name="saveConfigForm"
(ngSubmit)="saveConfig(this.getLocalConfig(), saveConfigScope, saveConfigName)"
(ngSubmit)="saveConfig(this.getActiveConfig(), saveConfigScope, saveConfigName)"
#saveConfigForm="ngForm">
<h3>Save</h3>
<p style="margin-bottom: 16px;">Save current configuration to server</p>
Expand Down
34 changes: 27 additions & 7 deletions src/app/settings/config/config.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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(),
Expand All @@ -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();
Expand Down
36 changes: 18 additions & 18 deletions src/app/storage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
);
}
Expand All @@ -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) {
Expand All @@ -64,18 +64,18 @@ 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")
});
}

/**
* 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.
Expand All @@ -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 => {
Expand All @@ -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 => {
Expand All @@ -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
Expand All @@ -146,7 +146,7 @@ export class StorageService {
await lastValueFrom(this.http.get<any>(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;
}
Expand All @@ -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<null> {
Expand All @@ -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\<IUnitDefaults\>, Array\<IDataSet\>, Array\<IZone\>, 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) {
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/app/widgets/widget-numeric/widget-numeric.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8c0fb81

Please sign in to comment.