Last active
November 20, 2017 12:57
-
-
Save gladimdim/c3bdc62ba2e77585870f2c2cf3e2fc97 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Element as PolymerElement} from '../node_modules/@polymer/polymer/polymer-element.js'; | |
class AggregationPickerControl extends PolymerElement { | |
static get template() { | |
return ` | |
<div id="aggregations"> | |
</div> | |
`; | |
} | |
constructor() { | |
super(); | |
} | |
static get properties() { | |
return { | |
aggregations: { | |
observer: "aggregationsSet", | |
Type: Array | |
}, | |
currentAggregation: { | |
Type: String | |
} | |
}; | |
} | |
aggregationsSet(aggrs) { | |
const aggrNames = aggrs.map((aggr) => aggr.getName()); | |
const rootElement = document.createElement("select"); | |
rootElement.setAttribute("name", "aggregations"); | |
for (let name of aggrNames) { | |
const optionElement = document.createElement("option"); | |
if (this.currentAggregation === name) { | |
optionElement.setAttribute("selected", "selected"); | |
} | |
optionElement.textContent = name; | |
rootElement.appendChild( | |
optionElement | |
); | |
} | |
this.$.aggregations.innerHTML = ''; | |
this.$.aggregations.appendChild(rootElement); | |
rootElement.addEventListener("change", (newValue) => { | |
this.dispatchEvent(new CustomEvent("selected", {detail: newValue.target.value})); | |
}); | |
} | |
} | |
customElements.define("aggregation-picker-control", AggregationPickerControl); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment