Skip to content

Commit

Permalink
Merge pull request #6 from ktg/master
Browse files Browse the repository at this point in the history
  • Loading branch information
Toshbrown authored Oct 2, 2017
2 parents 00fe6e7 + 1876baa commit 6e58ae9
Show file tree
Hide file tree
Showing 3 changed files with 324 additions and 420 deletions.
63 changes: 44 additions & 19 deletions src/www/js/app-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,38 +51,63 @@ function appConfigDisplay(manifest, sensors) {
method: "POST",
body: JSON.stringify(manifest),
})
.then((res) => {
.then(() => {
router.navigate('/' + manifest['databox-type'] + '/installed');
});
});

let menus = document.getElementsByClassName('mdc-simple-menu');
for (const menuElement of menus) {
const menu = new mdc.menu.MDCSimpleMenu(menuElement);
menuElement.parentElement.addEventListener('click', () => menu.open = !menu.open);
}


let menuItems = document.getElementsByClassName('mdc-list-item');
for(const menuItem of menuItems) {
if(menuItem.getAttribute('role') === 'menuitem') {
menuItem.addEventListener('click', () => {
const clientid = menuItem.getAttribute('datasource');
for(const datasource of manifest.datasources) {
if(datasource.clientid === clientid) {
const sensorHref = menuItem.getAttribute('sensor');
let selects = document.getElementsByTagName('select');
for(const selectElements of selects) {
selectElements.addEventListener('change', (event) => {
const selectElement = event.currentTarget;
const clientid = selectElement.getAttribute('datasource');
for(const datasource of manifest.datasources) {
if(datasource.clientid === clientid) {
if(selectElement.selectedIndex === 0) {
datasource.hypercat = null;
appConfigDisplay(manifest, sensors);
} else {
const sensorHref = selectElement.value;
for (const sensor of sensors) {
if(sensor.href === sensorHref) {
datasource.hypercat = sensor;
appConfigDisplay(manifest, sensors);
break;
}
}
break;
}
break;
}
});
}
}
});
}

const MDCSelect = mdc.select.MDCSelect;
let mdcSelects = document.getElementsByClassName('mdc-select');
for(const mdcSelect of mdcSelects) {
const select = new MDCSelect(mdcSelect);
select.listen('MDCSelect:change', () => {
const selectElement = select;
const clientid = mdcSelect.getAttribute('datasource');
for(const datasource of manifest.datasources) {
if(datasource.clientid === clientid) {
const sensorHref = selectElement.value;
for (const sensor of sensors) {
if(sensor.href === sensorHref) {
datasource.hypercat = sensor;
appConfigDisplay(manifest, sensors);
break;
}
}
break;
}
}
});
}

for(const mdcSelect of mdcSelects) {
mdcSelect.style.minWidth = mdcSelect.style.width;
mdcSelect.style.width = null;
}
}

Expand Down
Loading

0 comments on commit 6e58ae9

Please sign in to comment.