mirror of
https://github.com/jwetzell/showbridge-webui.git
synced 2026-08-22 22:49:00 +00:00
load and save config to localStorage
This commit is contained in:
@@ -24,67 +24,38 @@ export class ConfigService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadConfig() {
|
loadConfig() {
|
||||||
// TODO(jwetzell): load from local storage
|
const configString = localStorage.getItem('config');
|
||||||
|
if (configString) {
|
||||||
|
try {
|
||||||
|
const config = JSON.parse(configString);
|
||||||
|
const valid = this.schemaService.validate(config);
|
||||||
|
if (valid) {
|
||||||
|
console.log('Loaded config from local storage', config);
|
||||||
|
this.updateCurrentlyShownConfig(config);
|
||||||
|
} else {
|
||||||
|
console.error('Config in local storage is invalid', config);
|
||||||
|
this.setEmptyConfig();
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Failed to parse config from local storage', e);
|
||||||
|
this.setEmptyConfig();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.setEmptyConfig();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setEmptyConfig() {
|
||||||
|
console.log('Setting empty config');
|
||||||
this.updateCurrentlyShownConfig({
|
this.updateCurrentlyShownConfig({
|
||||||
modules: [
|
modules: [],
|
||||||
{
|
|
||||||
id: 'http',
|
|
||||||
type: 'http.server',
|
|
||||||
params: {
|
|
||||||
port: 8080,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'http',
|
|
||||||
type: 'http.server',
|
|
||||||
params: {
|
|
||||||
port: 8080,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'http',
|
|
||||||
type: 'http.server',
|
|
||||||
params: {
|
|
||||||
port: 8080,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'http',
|
|
||||||
type: 'http.server',
|
|
||||||
params: {
|
|
||||||
port: 8080,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'http',
|
|
||||||
type: 'http.server',
|
|
||||||
params: {
|
|
||||||
port: 8080,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'http',
|
|
||||||
type: 'http.server',
|
|
||||||
params: {
|
|
||||||
port: 8080,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'http',
|
|
||||||
type: 'http.server',
|
|
||||||
params: {
|
|
||||||
port: 8080,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
routes: [],
|
routes: [],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
saveConfig(config: Config) {
|
saveConfig(config: Config) {
|
||||||
// TODO(jwetzell): save to local storage
|
localStorage.setItem('config', JSON.stringify(config));
|
||||||
console.log('saveConfig');
|
console.log('Config saved to local storage', config);
|
||||||
console.log(config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateCurrentlyShownConfig(config: Config) {
|
updateCurrentlyShownConfig(config: Config) {
|
||||||
|
|||||||
Reference in New Issue
Block a user