Update config-editor-card.js

This commit is contained in:
htmltiger 2022-01-08 19:11:27 +00:00 committed by GitHub
parent f85f77a1e9
commit 45cadbd735
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,4 +1,4 @@
console.info("Config Editor 1.4"); console.info("Config Editor 1.5");
const LitElement = window.LitElement || Object.getPrototypeOf(customElements.get("hui-masonry-view") ); const LitElement = window.LitElement || Object.getPrototypeOf(customElements.get("hui-masonry-view") );
const html = LitElement.prototype.html; const html = LitElement.prototype.html;
@ -25,12 +25,17 @@ constructor() {
render() { render() {
if(!this._hass.states['config_editor.version']){return html`<ha-card>Missing 'config_editor:' in configuration.yaml for github.com/htmltiger/config-editor</ha-card>`;} if(!this._hass.states['config_editor.version']){return html`<ha-card>Missing 'config_editor:' in configuration.yaml for github.com/htmltiger/config-editor</ha-card>`;}
if(this.fileList.length<1){ if(this.fileList.length<1){
this.List() this.openedFile = localStorage.getItem('config_editorOpen');
if(!this.openedFile){
this.openedFile = '';
}
this.List();
} }
return html` return html`
<ha-card> <ha-card>
<ha-code-editor id="code" mode="yaml" @value-changed=${this.updateText}></ha-code-editor> <ha-code-editor id="code" mode="yaml" @value-changed=${this.updateText}></ha-code-editor>
<div style="position: -webkit-sticky; position: sticky; bottom: 0; z-index:2; background: var( --ha-card-background, var(--card-background-color, white) )"> <div style="position: -webkit-sticky; position: sticky; bottom: 0; z-index:2; background: var(--app-header-background-color); color: var(--app-header-text-color, white)">
<code>#${this.infoLine}</code> <code>#${this.infoLine}</code>
<div> <div>
<button @click="${this.List}">Get List</button> <button @click="${this.List}">Get List</button>
@ -46,6 +51,12 @@ render() {
updateText(e) { updateText(e) {
this.code = e.detail.value; this.code = e.detail.value;
localStorage.setItem('config_editorText', this.code);
}
async oldText(dhis){
dhis.renderRoot.querySelector('#code').value=dhis.code;
dhis.infoLine = html`<b style='background:#ff7a81'>Auto loaded from this browser!</b>`;
} }
async Coder(){ async Coder(){
@ -64,17 +75,24 @@ async List(){
const e=(await this._hass.callWS({type: "config_editor/ws", action: 'list', data: '', file: ''})); const e=(await this._hass.callWS({type: "config_editor/ws", action: 'list', data: '', file: ''}));
this.fileList = e.file.slice().sort(); this.fileList = e.file.slice().sort();
this.infoLine = e.msg; this.infoLine = e.msg;
if(this.openedFile){
this.code = localStorage.getItem('config_editorText');
setTimeout(this.oldText, 1000, this);
}
} }
async Load(x) { async Load(x) {
this.code = ''; this.renderRoot.querySelector('#code').value='';this.infoLine = ''; this.code = ''; this.renderRoot.querySelector('#code').value='';this.infoLine = '';
this.openedFile = x.target.value this.openedFile = x.target.value
if(!this.openedFile){return;} if(this.openedFile){
this.infoLine = 'Loading: '+this.openedFile; this.infoLine = 'Loading: '+this.openedFile;
const e=(await this._hass.callWS({type: "config_editor/ws", action: 'load', data: '', file: this.openedFile})); const e=(await this._hass.callWS({type: "config_editor/ws", action: 'load', data: '', file: this.openedFile}));
this.openedFile = e.file; this.openedFile = e.file;
this.infoLine = e.msg; this.infoLine = e.msg;
this.renderRoot.querySelector('#code').value=e.data; this.renderRoot.querySelector('#code').value=e.data;
this.code = e.data; this.code = e.data;
}
localStorage.setItem('config_editorOpen', this.openedFile);
localStorage.setItem('config_editorText', this.code);
} }
async Save() { async Save() {
if(this.renderRoot.querySelector('#code').value != this.code){ if(this.renderRoot.querySelector('#code').value != this.code){