Skip to content
This repository has been archived by the owner on Nov 4, 2023. It is now read-only.

Commit

Permalink
feat: support config file selection using a "config" query (#530)
Browse files Browse the repository at this point in the history
Select a specific config based on the "config" query param.
  • Loading branch information
anthony2856 authored Nov 19, 2020
1 parent 813f315 commit 711e2b8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ Files served from the www folder (/local/ url), aren’t protected by the Home A

## Configure

`config.js` will initialize a global CONFIG object with the following fields:
`config.js` will initialize a global CONFIG object. If you want to have several config files, you can create another one next to `config.js` and name it for example `bedroom.js`. The specific config will be available at `http://HASS_IP:8123/local/tileboard/index.html?config=bedroom`.

This config object has the following fields:

```js
var CONFIG = {
Expand Down
13 changes: 8 additions & 5 deletions scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,24 @@ import '@mdi/font/scss/materialdesignicons.scss';

function onConfigLoadOrError (error) {
if (error) {
alert('Please make sure that you have "config.js" file and it is a valid javascript!\n' +
'If you are running TileBoard for the first time, please copy "config.example.js" into "dist/config.js"');
alert(`Please make sure that you have "${configName}.js" file and it is a valid javascript!
If you are running TileBoard for the first time, please copy "config.example.js" into "dist/${configName}.js"`);
return;
}
if (!window.CONFIG) {
alert('The "config.js" configuration file has loaded but window.CONFIG is not defined!\n' +
'Please make sure that it defines a CONFIG variable with proper configuration.');
alert(`The "${configName}.js" configuration file has loaded but window.CONFIG is not defined!
Please make sure that it defines a CONFIG variable with proper configuration.`);
return;
}
// @ts-ignore
window.window.initApp();
}

const url = new URL(document.location.href);
const configName = url.searchParams.get('config') || 'config';

const script = document.createElement('script');
script.src = './config.js?r=' + Date.now();
script.src = `./${configName}.js?r=${Date.now()}`;
script.onload = () => onConfigLoadOrError();
script.onerror = event => onConfigLoadOrError(event);
document.head.appendChild(script);

0 comments on commit 711e2b8

Please sign in to comment.