Cleaned up states-cards.html

This commit is contained in:
Paulus Schoutsen 2014-11-19 19:01:46 -08:00
parent 04e58bd375
commit 67bb64ab6b

View File

@ -54,53 +54,39 @@
</template> </template>
<script> <script>
Polymer({ Polymer({
raw_states: [],
states: [],
filter: null, filter: null,
filter_substates: null,
filterChanged: function(oldVal, newVal) { computed: {
this.refilterStates(); states: "getStates(api.states, filter)"
}, },
ready: function() { getStates: function(states, filter) {
this.editCallback = this.editCallback.bind(this); if(!states) {
}, return [];
}
domReady: function() { if(!filter) {
this.raw_states = this.api.states // if no filter, return all non-group states
return states.filter(function(state) {
this.api.addEventListener('states-updated', this.statesUpdated.bind(this)) return state.domain != 'group';
this.refilterStates();
},
statesUpdated: function() {
this.raw_states = this.api.states;
this.refilterStates();
},
refilterStates: function() {
if(this.filter == null) {
// all states except groups
this.states = this.raw_states.filter(function(state) {
return state.domain != 'group'
}); });
} else { } else {
// we have a filter, return the parent filter and its children
var filter_state = this.api.getState(this.filter); var filter_state = this.api.getState(this.filter);
var map_states = function(entity_id) { var map_states = function(entity_id) {
return this.api.getState(entity_id); return this.api.getState(entity_id);
}.bind(this) }.bind(this);
// take the parent state and append it's children return [filter_state].concat(
this.states = [filter_state].concat( filter_state.attributes.entity_id.map(map_states));
filter_state.attributes.entity_id.map(map_states))
} }
}, },
ready: function() {
this.editCallback = this.editCallback.bind(this);
},
editCallback: function(entityId) { editCallback: function(entityId) {
this.api.showEditStateDialog(entityId); this.api.showEditStateDialog(entityId);
}, },