diff --git a/README.md b/README.md index 5f74a52..89c91db 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,13 @@ It is also possible to add this using `+ Add Card` UI and choose `Custom: Config #### To create a new file choose the first blank in dropdown menu and type some text and hit Save - +#### Advanced Config + +| Name | Default | Description +| ---- | ------- | ----------- +| file | | autoload file eg. `home-assistant.log` +| readonly | `false` | read only +| hidefooter | `false` | +| basic | `false` | Force basic editor Please backup your files before using as there is no undo. diff --git a/config-editor-card.js b/config-editor-card.js index 321d367..ef28817 100644 --- a/config-editor-card.js +++ b/config-editor-card.js @@ -1,4 +1,4 @@ -console.info("Config Editor 3.5"); +console.info("Config Editor 3.6"); const LitElement = window.LitElement || Object.getPrototypeOf(customElements.get("hui-masonry-view") ); const html = LitElement.prototype.html; const css = LitElement.prototype.css; @@ -35,8 +35,9 @@ static get styles() { overflow-wrap:normal; white-space:pre} .top{min-height:calc(100vh - var(--header-height))} - .pin{text-align:right} + .pin{display:flex} .pin label{cursor:pointer} + .right{text-align:right;flex-grow:1} .bar{ position:-webkit-sticky; position:sticky; @@ -56,7 +57,7 @@ render() { if(this.fileList.length<1){ this.openedFile = this.localGet('Open')||''; this.edit.ext = this.localGet('Ext')||'yaml'; - this.edit.plainBox = this.localGet('Plain')||''; + this.edit.basic = this.localGet('Basic')||''; if(this.fileList = JSON.parse(this.localGet('List'+this.edit.ext))){ if(this.openedFile.endsWith("."+this.edit.ext)){ setTimeout(this.oldText, 500, this); @@ -68,21 +69,25 @@ render() {
+
+
- + +
- ${this.edit.plainBox ? - html``: - html``} + ${this.edit.basic ? + html``: + html``}
+ ${this.edit.hidefooter ? '' : html`
${this.alertLine}
@@ -91,11 +96,11 @@ render() { ${[''].concat(this.fileList).map(value => html``)} - - + ${!this.edit.readonly ? + html``:''}
#${this.infoLine} -
+ `}
`; @@ -109,15 +114,15 @@ extChange(e){ this.List(); } -plainChange(){ - this.edit.plainBox = this.edit.plainBox?'':'1'; - this.localSet('Plain', this.edit.plainBox); +basicChange(){ + this.edit.basic = this.edit.basic?'':'1'; + this.localSet('Basic', this.edit.basic); this.List(); } updateText(e) { e.stopPropagation(); - this.code = this.edit.plainBox ? e.target.value : e.detail.value; + this.code = this.edit.basic ? e.target.value : e.detail.value; if(this.openedFile){this.localSet('Text', this.code);} } @@ -146,6 +151,9 @@ saveList(){ this.localSet('List'+this.edit.ext, JSON.stringify(this.fileList)); } +reLoad(e){ + this.Load({target:{value:this.openedFile},reload:1}); +} oldText(dhis){ dhis.Load({target:{value:dhis.openedFile}}); } @@ -181,7 +189,7 @@ async Coder(){ const d=document.createElement("ha-panel-config"); await d.routerOptions.routes.automation.load(); if(!customElements.get(c)){ - this.localSet('Plain', 1); + this.localSet('Basic', 1); console.log('failed '+c); } } @@ -198,7 +206,7 @@ async List(){ } async Load(x) { - if(x.target.value == this.openedFile && this.code){return;} + if(x.target.value == this.openedFile && this.code && !x.hasOwnProperty('reload')){return;} if(this.edit.orgCode.trim() != this.code.trim()){ if(!confirm("Switch without Saving?")){x.target.value = this.openedFile; return;} } @@ -227,7 +235,7 @@ async Load(x) { } async Save() { - if(this.renderRoot.querySelector('#code').value != this.code){ + if(this.renderRoot.querySelector('#code').value != this.code || this.edit.readonly){ this.infoLine='Something not right!'; return; } @@ -259,7 +267,14 @@ getCardSize() { } setConfig(config) { - this.edit = {options: config, plainBox: false, ext: '', orgCode: ''}; + this.edit = {file: '', hidefooter: false, readonly: false, basic: false, ext: '', orgCode: '', ...config}; + if(this.edit.file){ + const f=this.edit.file.split('.')[1]; + if(f){ + this.localSet('Open', this.edit.file); + this.localSet('Ext', f); + } + } this.Coder(); }