code review fixes

This commit is contained in:
Dennis Karpienski 2016-04-12 12:12:20 +02:00
parent 9197d358d2
commit 87067ea16f
2 changed files with 31 additions and 10 deletions

View File

@ -24,6 +24,10 @@
.has-volume_level .volume { .has-volume_level .volume {
max-height: 40px; max-height: 40px;
} }
.source-input {
margin-left: 10px;
}
</style> </style>
<template> <template>
<div class$='[[computeClassNames(stateObj)]]'> <div class$='[[computeClassNames(stateObj)]]'>
@ -65,9 +69,9 @@
</paper-slider> </paper-slider>
</div> </div>
<div class='controls layout horizontal justified' hidden$='[[!supportsSelectSource]]'> <div class='controls layout horizontal justified' hidden$='[[!supportsSelectSource]]'>
<paper-icon-button icon="mdi:login-variant"></paper-icon-button> <iron-icon icon="mdi:login-variant"></iron-icon>
<paper-dropdown-menu style="margin-left: 10px;" no-label-float selected-item-label='{{selectedSource}}' on-tap='stopPropagation'> <paper-dropdown-menu class="source-input" no-label-float label='[[source]]'>
<paper-menu class="dropdown-content" selected="[[computeSelectedSource(stateObj)]]"> <paper-menu class="dropdown-content" selected="{{sourceIndex}}">
<template is='dom-repeat' items='[[stateObj.attributes.source_list]]'> <template is='dom-repeat' items='[[stateObj.attributes.source_list]]'>
<paper-item>[[item]]</paper-item> <paper-item>[[item]]</paper-item>
</template> </template>

View File

@ -30,6 +30,17 @@ export default new Polymer({
value: false, value: false,
}, },
source: {
type: String,
value: '',
},
sourceIndex: {
type: Number,
value: 0,
observer: 'handleSourceChanged',
},
volumeSliderValue: { volumeSliderValue: {
type: Number, type: Number,
value: 0, value: 0,
@ -85,11 +96,6 @@ export default new Polymer({
value: false, value: false,
}, },
selectedSource: {
type: String,
observer: 'handleSourceChanged',
},
}, },
stateObjChanged(newVal) { stateObjChanged(newVal) {
@ -101,6 +107,8 @@ export default new Polymer({
this.hasMediaControl = hasMediaStates.indexOf(newVal.state) !== -1; this.hasMediaControl = hasMediaStates.indexOf(newVal.state) !== -1;
this.volumeSliderValue = newVal.attributes.volume_level * 100; this.volumeSliderValue = newVal.attributes.volume_level * 100;
this.isMuted = newVal.attributes.is_volume_muted; this.isMuted = newVal.attributes.is_volume_muted;
this.source = newVal.attributes.source;
this.sourceIndex = newVal.attributes.source_list.indexOf(this.source)
this.supportsPause = (newVal.attributes.supported_media_commands & 1) !== 0; this.supportsPause = (newVal.attributes.supported_media_commands & 1) !== 0;
this.supportsVolumeSet = (newVal.attributes.supported_media_commands & 4) !== 0; this.supportsVolumeSet = (newVal.attributes.supported_media_commands & 4) !== 0;
this.supportsVolumeMute = (newVal.attributes.supported_media_commands & 8) !== 0; this.supportsVolumeMute = (newVal.attributes.supported_media_commands & 8) !== 0;
@ -166,11 +174,20 @@ export default new Polymer({
this.callService('media_next_track'); this.callService('media_next_track');
}, },
handleSourceChanged(sourceInput) { handleSourceChanged(sourceIndex) {
// Selected Option will transition to '' before transitioning to new value // Selected Option will transition to '' before transitioning to new value
if (sourceInput === '' || sourceInput === this.stateObj.attributes.source) { if (!this.stateObj
|| sourceIndex < 0
|| sourceIndex >= this.stateObj.attributes.source_list.length
) {
return; return;
} }
var sourceInput = this.stateObj.attributes.source_list[sourceIndex];
if (sourceInput == this.stateObj.attributes.source) {
return;
}
this.callService('select_source', { source: sourceInput }); this.callService('select_source', { source: sourceInput });
}, },