diff --git a/config-editor-card.js b/config-editor-card.js index c2a1b14..c6e5831 100644 --- a/config-editor-card.js +++ b/config-editor-card.js @@ -1,4 +1,4 @@ -console.info("Config Editor 1.8"); +console.info("Config Editor 3.0"); const LitElement = window.LitElement || Object.getPrototypeOf(customElements.get("hui-masonry-view") ); const html = LitElement.prototype.html; @@ -26,10 +26,14 @@ constructor() { } render() { - if(!this._hass.states['config_editor.version']){return html`Missing 'config_editor:' in configuration.yaml for github.com/htmltiger/config-editor`;} + const hver=this._hass.states['config_editor.version'] + if(!hver){return html`Missing 'config_editor:' in configuration.yaml for github.com/htmltiger/config-editor`;} + if(hver.state != '3'){console.log(hver);return html`Please upgrade github.com/htmltiger/config-editor`;} if(this.fileList.length<1){ this.openedFile = localStorage.getItem('config_editorOpen'); this.edit.plainBox = localStorage.getItem('config_editorPlain') ? true : false; + this.edit.ext = localStorage.getItem('config_editorExt'); + if(!this.edit.ext){this.edit.ext='yaml';} if(!this.openedFile){ this.openedFile = ''; } @@ -40,7 +44,11 @@ render() {
${this.edit.plainBox ? html`` : html``} -
+
+ +
${this.alertLine}
@@ -57,6 +65,14 @@ render() { `; } +extChange(e){ + this.edit.ext = e.target.value; + localStorage.setItem('config_editorExt',this.edit.ext); + this.openedFile = ''; + this.oldText(this); + this.List(); +} + plainChange(e){ if(this.edit.plainBox = !this.edit.plainBox){ localStorage.setItem('config_editorPlain','1'); @@ -95,10 +111,10 @@ async Coder(){ } async List(){ this.infoLine = 'List Loading...'; - 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: '', ext: this.edit.ext})); this.infoLine = e.msg; this.fileList = e.file.slice().sort(); - if(this.openedFile){ + if(this.openedFile.endsWith("."+this.edit.ext)){ setTimeout(this.oldText, 500, this); } } @@ -108,7 +124,7 @@ async Load(x) { this.openedFile = x.target.value if(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, ext: this.edit.ext})); this.openedFile = e.file; this.infoLine = e.msg; const uns={f:localStorage.getItem('config_editorOpen'),d:localStorage.getItem('config_editorText')}; @@ -134,7 +150,7 @@ async Save() { if(this.openedFile && this.openedFile.endsWith(".yaml")){ if(!this.code){this.infoLine='';this.infoLine = 'Text is empty!'; return;} this.infoLine = 'Saving: '+this.openedFile; - const e=(await this._hass.callWS({type: "config_editor/ws", action: 'save', data: this.code, file: this.openedFile})); + const e=(await this._hass.callWS({type: "config_editor/ws", action: 'save', data: this.code, file: this.openedFile, ext: this.edit.ext})); this.infoLine = e.msg; localStorage.removeItem('config_editorText'); }else{this.openedFile='';} @@ -146,7 +162,7 @@ getCardSize() { } setConfig(config) { - this.edit = {options: config, plainBox: false}; + this.edit = {options: config, plainBox: false, ext: ''}; this.Coder(); }