junkfix 2025-03-17 17:22:21 +00:00 committed by GitHub
parent d91b063053
commit 23091abbf9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,4 +1,4 @@
console.info("Config Editor 4.7.1"); console.info("Config Editor 5.0.0");
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;
const css = LitElement.prototype.css; const css = LitElement.prototype.css;
@ -72,11 +72,11 @@ static get styles() {
} }
render(){ render(){
const targetver=4;
const hver=this._hass ? this._hass.states['config_editor.version']:{state:0}; const targetver=5;
const dlink=html`<a href="https://github.com/junkfix/config-editor">download</a>`;
if(!hver || !hver.state){return html`<ha-card>Missing 'config_editor:' in configuration.yaml ${dlink}</ha-card>`;} if(!this._hass){return html``;}
if(hver.state != targetver){return html`<ha-card>Please ${dlink} upgrade from ${hver.state} to ${targetver}</ha-card>`;}
if(this.fileList.length<1){ if(this.fileList.length<1){
this.openedFile = this.localGet('Open')||''; this.openedFile = this.localGet('Open')||'';
this.edit.ext = this.localGet('Ext')||'yaml'; this.edit.ext = this.localGet('Ext')||'yaml';
@ -87,8 +87,13 @@ render(){
} }
}else{this.List();} }else{this.List();}
} }
const hver=this.edit.cver;
const dlink=html`<a href="https://github.com/junkfix/config-editor">download</a>`;
return html` return html`
<ha-card> <ha-card>
${(!this._hass.config.components.includes("config_editor")) ? html`<div>Missing 'config_editor:' in configuration.yaml ${dlink}</div>` : ''}
${(hver && hver != targetver) ? html`<div>Please ${dlink} upgrade from ${hver} to ${targetver}</div>` : ''}
<div class="top"> <div class="top">
<div class="pin"> <div class="pin">
<div class="left"><button @click="${this.reLoad}">Reload</button></div> <div class="left"><button @click="${this.reLoad}">Reload</button></div>
@ -240,11 +245,14 @@ async Coder(){
async List(){ async List(){
this.infoLine = 'List Loading...'; this.infoLine = 'List Loading...';
const e=await this.cmd('list','',''); const e=await this.cmd('list','','');
this.infoLine = e.msg; if(e){
this.fileList = e.file.slice().sort(); this.edit.cver = e.cver;
this.saveList(); this.infoLine = e.msg;
if(this.extOk(this.openedFile)){ this.fileList = e.file.slice().sort();
setTimeout(this.oldText, 500, this); this.saveList();
if(this.extOk(this.openedFile)){
setTimeout(this.oldText, 500, this);
}
} }
} }
@ -258,20 +266,23 @@ async Load(x) {
if(this.openedFile){ if(this.openedFile){
this.infoLine = 'Loading: '+this.openedFile; this.infoLine = 'Loading: '+this.openedFile;
const e=await this.cmd('load','',this.openedFile); const e=await this.cmd('load','',this.openedFile);
this.openedFile = e.file; if(e){
this.infoLine = e.msg; this.edit.cver = e.cver;
this.Toast(this.infoLine,1000); this.openedFile = e.file;
const uns={f:this.localGet('Open'), this.infoLine = e.msg;
d:this.localGet('Text')}; this.Toast(this.infoLine,1000);
if(uns.f == this.openedFile && uns.d && uns.d != e.data){ const uns={f:this.localGet('Open'),
this.localSet('Unsaved', uns.d); d:this.localGet('Text')};
this.alertLine = html`<i @click="${this.Unsave}">  if(uns.f == this.openedFile && uns.d && uns.d != e.data){
Load unsaved from browser </i>`; this.localSet('Unsaved', uns.d);
}else{ this.alertLine = html`<i @click="${this.Unsave}"> 
this.localSet('Text','');this.alertLine = ''; Load unsaved from browser </i>`;
}else{
this.localSet('Text','');this.alertLine = '';
}
this.renderRoot.querySelector('#code').value=e.data;
this.code = e.data;
} }
this.renderRoot.querySelector('#code').value=e.data;
this.code = e.data;
} }
this.edit.orgCode = this.code; this.edit.orgCode = this.code;
this.localSet('Open', this.openedFile); this.localSet('Open', this.openedFile);
@ -298,13 +309,15 @@ async Save() {
if(!this.code){this.infoLine=''; this.infoLine = 'Text is empty!'; return;} if(!this.code){this.infoLine=''; this.infoLine = 'Text is empty!'; return;}
this.infoLine = 'Saving: '+this.openedFile; this.infoLine = 'Saving: '+this.openedFile;
const e=await this.cmd('save', this.code, this.openedFile); const e=await this.cmd('save', this.code, this.openedFile);
this.infoLine = e.msg; if(e){
this.Toast(this.infoLine,2000); this.infoLine = e.msg;
if(e.msg.includes('Saved:')){ this.Toast(this.infoLine,2000);
this.localSet('Text',''); if(e.msg.includes('Saved:')){
if(savenew){ this.localSet('Text','');
this.fileList.unshift(this.openedFile); if(savenew){
this.saveList(); this.fileList.unshift(this.openedFile);
this.saveList();
}
} }
} }
}else{this.openedFile='';} }else{this.openedFile='';}
@ -316,7 +329,7 @@ getCardSize() {
} }
setConfig(config) { setConfig(config) {
this.edit = {file: '', hidefooter: false, readonly: false, basic: false, size: 0, depth: 2, ext: '', orgCode: '', coder:1, ...config}; this.edit = {file: '', hidefooter: false, readonly: false, basic: false, size: 0, depth: 2, ext: '', orgCode: '', coder: 1, cver: 0, ...config};
if(this.edit.file){ if(this.edit.file){
const f=this.edit.file.split('.')[1]; const f=this.edit.file.split('.')[1];
if(f){ if(f){