mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 17:56:46 +00:00
Load ozw-log in new window, and add tail-like button. (#1652)
* Load log in new window, and add tail * avoid duplicate code
This commit is contained in:
parent
4077105db1
commit
8505750958
@ -27,23 +27,17 @@ class OzwLog extends PolymerElement {
|
|||||||
padding-bottom: 24px;
|
padding-bottom: 24px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.help-text {
|
|
||||||
padding: 5px 24px;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
<ha-config-section is-wide="[[isWide]]">
|
<ha-config-section is-wide="[[isWide]]">
|
||||||
<span slot="header">OZW Log</span>
|
<span slot="header">OZW Log</span>
|
||||||
<paper-card>
|
<paper-card>
|
||||||
<div class="device-picker">
|
<div class="device-picker">
|
||||||
<paper-input label="Number of last log lines." type="number" min="0" max="1000" step="10" value="{{numLogLines}}">
|
<paper-input label="Number of last log lines." type="number" min="0" max="1000" step="10" value="{{_numLogLines}}">
|
||||||
</paper-input>
|
</paper-input>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-actions">
|
<div class="card-actions">
|
||||||
<paper-button raised="" on-click="refreshLog">Refresh</paper-button>
|
<paper-button raised="true" on-click="_openLogWindow">Load</paper-button>
|
||||||
</div>
|
<paper-button raised="true" on-click="_tailLog" disabled="{{_completeLog}}">Tail</paper-button>
|
||||||
<div class="help-text">
|
|
||||||
<pre>[[ozwLogs]]</pre>
|
|
||||||
</div>
|
|
||||||
</paper-card>
|
</paper-card>
|
||||||
</ha-config-section>
|
</ha-config-section>
|
||||||
`;
|
`;
|
||||||
@ -58,25 +52,53 @@ class OzwLog extends PolymerElement {
|
|||||||
value: false,
|
value: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
ozwLogs: {
|
_ozwLogs: String,
|
||||||
type: String,
|
|
||||||
value: 'Refresh to pull log'
|
_completeLog: {
|
||||||
|
type: Boolean,
|
||||||
|
value: true
|
||||||
},
|
},
|
||||||
|
|
||||||
numLogLines: {
|
_numLogLines: {
|
||||||
type: Number,
|
type: Number,
|
||||||
value: 0
|
value: 0,
|
||||||
|
observer: '_isCompleteLog'
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_intervalId: String,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshLog() {
|
async _tailLog() {
|
||||||
this.ozwLogs = 'Loading ozw log...';
|
const ozwWindow = await this._openLogWindow();
|
||||||
this.hass.callApi('GET', 'zwave/ozwlog?lines=' + this.numLogLines)
|
this.setProperties({
|
||||||
.then((info) => {
|
_intervalId: setInterval(() => { this._refreshLog(ozwWindow); }, 1500) });
|
||||||
this.ozwLogs = info;
|
}
|
||||||
});
|
|
||||||
|
async _openLogWindow() {
|
||||||
|
const info = await this.hass.callApi('GET', 'zwave/ozwlog?lines=' + this._numLogLines);
|
||||||
|
this.setProperties({ _ozwLogs: info });
|
||||||
|
const ozwWindow = window.open('', 'OpenZwave internal log', 'toolbar');
|
||||||
|
ozwWindow.document.title = 'OpenZwave internal logfile';
|
||||||
|
ozwWindow.document.body.innerText = this._ozwLogs;
|
||||||
|
return ozwWindow;
|
||||||
|
}
|
||||||
|
|
||||||
|
async _refreshLog(ozwWindow) {
|
||||||
|
if (ozwWindow.closed === true) {
|
||||||
|
clearInterval(this._intervalId);
|
||||||
|
this.setProperties({ _intervalId: null });
|
||||||
|
} else {
|
||||||
|
const info = await this.hass.callApi('GET', 'zwave/ozwlog?lines=' + this._numLogLines);
|
||||||
|
this.setProperties({ _ozwLogs: info });
|
||||||
|
ozwWindow.document.body.innerText = this._ozwLogs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_isCompleteLog() {
|
||||||
|
if (this._numLogLines !== '0') {
|
||||||
|
this.setProperties({ _completeLog: false });
|
||||||
|
} else { this.setProperties({ _completeLog: true }); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
customElements.define('ozw-log', OzwLog);
|
customElements.define('ozw-log', OzwLog);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user