Move last changed / last updated out of state table (#7649)

This commit is contained in:
Bram Kragten 2020-11-11 14:42:27 +01:00 committed by GitHub
parent a0e67d4c03
commit bae29c6d62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 154 additions and 101 deletions

View File

@ -12,6 +12,7 @@ import { showAlertDialog } from "../../../dialogs/generic/show-dialog-box";
import { EventsMixin } from "../../../mixins/events-mixin"; import { EventsMixin } from "../../../mixins/events-mixin";
import LocalizeMixin from "../../../mixins/localize-mixin"; import LocalizeMixin from "../../../mixins/localize-mixin";
import "../../../styles/polymer-ha-style"; import "../../../styles/polymer-ha-style";
import { formatDateTimeWithSeconds } from "../../../common/datetime/format_date_time";
import { mdiInformationOutline } from "@mdi/js"; import { mdiInformationOutline } from "@mdi/js";
import { computeRTL } from "../../../common/util/compute_rtl"; import { computeRTL } from "../../../common/util/compute_rtl";
@ -33,14 +34,25 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
} }
.inputs { .inputs {
width: 100%;
max-width: 400px; max-width: 400px;
} }
.info {
padding: 0 16px;
}
mwc-button { mwc-button {
margin-top: 8px; margin-top: 8px;
} }
.table-wrapper {
width: 100%;
overflow: auto;
}
.entities th { .entities th {
padding: 0 8px;
text-align: left; text-align: left;
font-size: var( font-size: var(
--paper-input-container-shared-input-style_-_font-size --paper-input-container-shared-input-style_-_font-size
@ -65,7 +77,7 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
} }
.entities td { .entities td {
padding: 4px; padding: 4px;
min-width: 220px; min-width: 200px;
word-break: break-word; word-break: break-word;
} }
.entities ha-svg-icon { .entities ha-svg-icon {
@ -81,112 +93,133 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
.entities a { .entities a {
color: var(--primary-color); color: var(--primary-color);
} }
:host([narrow]) .state-wrapper {
flex-direction: column;
}
:host([narrow]) .info {
padding: 0;
}
</style> </style>
<div class="inputs"> <p>
<p> [[localize('ui.panel.developer-tools.tabs.states.description1')]]<br />
[[localize('ui.panel.developer-tools.tabs.states.description1')]]<br /> [[localize('ui.panel.developer-tools.tabs.states.description2')]]
[[localize('ui.panel.developer-tools.tabs.states.description2')]] </p>
</p> <div class="state-wrapper flex layout horizontal">
<div class="inputs">
<ha-entity-picker <ha-entity-picker
autofocus autofocus
hass="[[hass]]" hass="[[hass]]"
value="{{_entityId}}" value="{{_entityId}}"
on-change="entityIdChanged" on-change="entityIdChanged"
allow-custom-entity allow-custom-entity
></ha-entity-picker> ></ha-entity-picker>
<paper-input <paper-input
label="[[localize('ui.panel.developer-tools.tabs.states.state')]]" label="[[localize('ui.panel.developer-tools.tabs.states.state')]]"
required required
autocapitalize="none" autocapitalize="none"
autocomplete="off" autocomplete="off"
autocorrect="off" autocorrect="off"
spellcheck="false" spellcheck="false"
value="{{_state}}" value="{{_state}}"
class="state-input" class="state-input"
></paper-input> ></paper-input>
<p> <p>
[[localize('ui.panel.developer-tools.tabs.states.state_attributes')]] [[localize('ui.panel.developer-tools.tabs.states.state_attributes')]]
</p> </p>
<ha-code-editor <ha-code-editor
mode="yaml" mode="yaml"
value="[[_stateAttributes]]" value="[[_stateAttributes]]"
error="[[!validJSON]]" error="[[!validJSON]]"
on-value-changed="_yamlChanged" on-value-changed="_yamlChanged"
></ha-code-editor> ></ha-code-editor>
<mwc-button on-click="handleSetState" disabled="[[!validJSON]]" raised <mwc-button on-click="handleSetState" disabled="[[!validJSON]]" raised
>[[localize('ui.panel.developer-tools.tabs.states.set_state')]]</mwc-button >[[localize('ui.panel.developer-tools.tabs.states.set_state')]]</mwc-button
> >
</div>
<div class="info">
<template is="dom-if" if="[[_entity]]">
<p>
<b
>[[localize('ui.panel.developer-tools.tabs.states.last_changed')]]:</b
><br />[[lastChangedString(_entity)]]
</p>
<p>
<b
>[[localize('ui.panel.developer-tools.tabs.states.last_updated')]]:</b
><br />[[lastUpdatedString(_entity)]]
</p>
</template>
</div>
</div> </div>
<h1> <h1>
[[localize('ui.panel.developer-tools.tabs.states.current_entities')]] [[localize('ui.panel.developer-tools.tabs.states.current_entities')]]
</h1> </h1>
<table class="entities"> <div class="table-wrapper">
<tr> <table class="entities">
<th>[[localize('ui.panel.developer-tools.tabs.states.entity')]]</th>
<th>[[localize('ui.panel.developer-tools.tabs.states.state')]]</th>
<th hidden$="[[narrow]]">
[[localize('ui.panel.developer-tools.tabs.states.attributes')]]
<paper-checkbox checked="{{_showAttributes}}"></paper-checkbox>
</th>
</tr>
<tr>
<th>
<paper-input
label="[[localize('ui.panel.developer-tools.tabs.states.filter_entities')]]"
type="search"
value="{{_entityFilter}}"
></paper-input>
</th>
<th>
<paper-input
label="[[localize('ui.panel.developer-tools.tabs.states.filter_states')]]"
type="search"
value="{{_stateFilter}}"
></paper-input>
</th>
<th hidden$="[[!computeShowAttributes(narrow, _showAttributes)]]">
<paper-input
label="[[localize('ui.panel.developer-tools.tabs.states.filter_attributes')]]"
type="search"
value="{{_attributeFilter}}"
></paper-input>
</th>
</tr>
<tr hidden$="[[!computeShowEntitiesPlaceholder(_entities)]]">
<td colspan="3">
[[localize('ui.panel.developer-tools.tabs.states.no_entities')]]
</td>
</tr>
<template is="dom-repeat" items="[[_entities]]" as="entity">
<tr> <tr>
<td> <th>[[localize('ui.panel.developer-tools.tabs.states.entity')]]</th>
<ha-svg-icon <th>[[localize('ui.panel.developer-tools.tabs.states.state')]]</th>
on-click="entityMoreInfo" <th hidden$="[[narrow]]">
alt="[[localize('ui.panel.developer-tools.tabs.states.more_info')]]" [[localize('ui.panel.developer-tools.tabs.states.attributes')]]
title="[[localize('ui.panel.developer-tools.tabs.states.more_info')]]" <paper-checkbox checked="{{_showAttributes}}"></paper-checkbox>
path="[[informationOutlineIcon()]]" </th>
></ha-svg-icon>
<a href="#" on-click="entitySelected">[[entity.entity_id]]</a>
</td>
<td>
[[entity.state]]<br /><br />
<span class="secondary">
last_changed: [[lastChangedString(entity)]]<br />
last_updated: [[lastUpdatedString(entity)]]
</span>
</td>
<template
is="dom-if"
if="[[computeShowAttributes(narrow, _showAttributes)]]"
>
<td>[[attributeString(entity)]]</td>
</template>
</tr> </tr>
</template> <tr>
</table> <th>
<paper-input
label="[[localize('ui.panel.developer-tools.tabs.states.filter_entities')]]"
type="search"
value="{{_entityFilter}}"
></paper-input>
</th>
<th>
<paper-input
label="[[localize('ui.panel.developer-tools.tabs.states.filter_states')]]"
type="search"
value="{{_stateFilter}}"
></paper-input>
</th>
<th hidden$="[[!computeShowAttributes(narrow, _showAttributes)]]">
<paper-input
label="[[localize('ui.panel.developer-tools.tabs.states.filter_attributes')]]"
type="search"
value="{{_attributeFilter}}"
></paper-input>
</th>
</tr>
<tr hidden$="[[!computeShowEntitiesPlaceholder(_entities)]]">
<td colspan="3">
[[localize('ui.panel.developer-tools.tabs.states.no_entities')]]
</td>
</tr>
<template is="dom-repeat" items="[[_entities]]" as="entity">
<tr>
<td>
<ha-svg-icon
on-click="entityMoreInfo"
alt="[[localize('ui.panel.developer-tools.tabs.states.more_info')]]"
title="[[localize('ui.panel.developer-tools.tabs.states.more_info')]]"
path="[[informationOutlineIcon()]]"
></ha-svg-icon>
<a href="#" on-click="entitySelected">[[entity.entity_id]]</a>
</td>
<td>
[[entity.state]]
</td>
<template
is="dom-if"
if="[[computeShowAttributes(narrow, _showAttributes)]]"
>
<td>[[attributeString(entity)]]</td>
</template>
</tr>
</template>
</table>
</div>
`; `;
} }
@ -226,6 +259,10 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
value: "", value: "",
}, },
_entity: {
type: Object,
},
_state: { _state: {
type: String, type: String,
value: "", value: "",
@ -247,6 +284,11 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
"computeEntities(hass, _entityFilter, _stateFilter, _attributeFilter)", "computeEntities(hass, _entityFilter, _stateFilter, _attributeFilter)",
}, },
narrow: {
type: Boolean,
reflectToAttribute: true,
},
rtl: { rtl: {
reflectToAttribute: true, reflectToAttribute: true,
computed: "_computeRTL(hass)", computed: "_computeRTL(hass)",
@ -257,6 +299,7 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
entitySelected(ev) { entitySelected(ev) {
const state = ev.model.entity; const state = ev.model.entity;
this._entityId = state.entity_id; this._entityId = state.entity_id;
this._entity = state;
this._state = state.state; this._state = state.state;
this._stateAttributes = safeDump(state.attributes); this._stateAttributes = safeDump(state.attributes);
ev.preventDefault(); ev.preventDefault();
@ -264,6 +307,7 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
entityIdChanged() { entityIdChanged() {
if (this._entityId === "") { if (this._entityId === "") {
this._entity = undefined;
this._state = ""; this._state = "";
this._stateAttributes = ""; this._stateAttributes = "";
return; return;
@ -272,6 +316,7 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
if (!state) { if (!state) {
return; return;
} }
this._entity = state;
this._state = state.state; this._state = state.state;
this._stateAttributes = safeDump(state.attributes); this._stateAttributes = safeDump(state.attributes);
} }
@ -391,11 +436,17 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
} }
lastChangedString(entity) { lastChangedString(entity) {
return new Date(entity.last_changed).toISOString(); return formatDateTimeWithSeconds(
new Date(entity.last_changed),
this.hass.language
);
} }
lastUpdatedString(entity) { lastUpdatedString(entity) {
return new Date(entity.last_updated).toISOString(); return formatDateTimeWithSeconds(
new Date(entity.last_updated),
this.hass.language
);
} }
formatAttributeValue(value) { formatAttributeValue(value) {

View File

@ -3061,7 +3061,9 @@
"filter_attributes": "Filter attributes", "filter_attributes": "Filter attributes",
"no_entities": "No entities", "no_entities": "No entities",
"more_info": "More Info", "more_info": "More Info",
"alert_entity_field": "Entity is a mandatory field" "alert_entity_field": "Entity is a mandatory field",
"last_updated": "[%key:ui::dialogs::more_info_control::last_updated%]",
"last_changed": "[%key:ui::dialogs::more_info_control::last_changed%]"
}, },
"templates": { "templates": {
"title": "Template", "title": "Template",