1- console . info ( "Config Editor 4.7.1 " ) ;
1+ console . info ( "Config Editor 5.0.0 " ) ;
22const LitElement = window . LitElement || Object . getPrototypeOf ( customElements . get ( "hui-masonry-view" ) ) ;
33const html = LitElement . prototype . html ;
44const css = LitElement . prototype . css ;
@@ -72,11 +72,11 @@ static get styles() {
7272}
7373
7474render ( ) {
75- const targetver = 4 ;
76- const hver = this . _hass ? this . _hass . states [ 'config_editor.version' ] : { state : 0 } ;
77- const dlink = html ` < a href =" https://github.com/junkfix/config-editor " > download </ a > ` ;
78- if ( ! hver || ! hver . state ) { return html `< ha-card > Missing 'config_editor:' in configuration.yaml ${ dlink } </ ha-card > ` ; }
79- if ( hver . state != targetver ) { return html ` < ha-card > Please ${ dlink } upgrade from ${ hver . state } to ${ targetver } </ ha-card > ` ; }
75+
76+ const targetver = 5 ;
77+
78+ if ( ! this . _hass ) { return html `` ; }
79+
8080 if ( this . fileList . length < 1 ) {
8181 this . openedFile = this . localGet ( 'Open' ) || '' ;
8282 this . edit . ext = this . localGet ( 'Ext' ) || 'yaml' ;
@@ -87,8 +87,13 @@ render(){
8787 }
8888 } else { this . List ( ) ; }
8989 }
90+ const hver = this . edit . cver ;
91+ const dlink = html `< a href ="https://github.com/junkfix/config-editor "> download</ a > ` ;
92+
9093 return html `
9194 < ha-card >
95+ ${ ( ! this . _hass . config . components . includes ( "config_editor" ) ) ? html `< div > Missing 'config_editor:' in configuration.yaml ${ dlink } </ div > ` : '' }
96+ ${ ( hver && hver != targetver ) ? html `< div > Please ${ dlink } upgrade from ${ hver } to ${ targetver } </ div > ` : '' }
9297 < div class ="top ">
9398 < div class ="pin ">
9499 < div class ="left "> < button @click ="${ this . reLoad } "> Reload</ button > </ div >
@@ -240,11 +245,14 @@ async Coder(){
240245async List ( ) {
241246 this . infoLine = 'List Loading...' ;
242247 const e = await this . cmd ( 'list' , '' , '' ) ;
243- this . infoLine = e . msg ;
244- this . fileList = e . file . slice ( ) . sort ( ) ;
245- this . saveList ( ) ;
246- if ( this . extOk ( this . openedFile ) ) {
247- setTimeout ( this . oldText , 500 , this ) ;
248+ if ( e ) {
249+ this . edit . cver = e . cver ;
250+ this . infoLine = e . msg ;
251+ this . fileList = e . file . slice ( ) . sort ( ) ;
252+ this . saveList ( ) ;
253+ if ( this . extOk ( this . openedFile ) ) {
254+ setTimeout ( this . oldText , 500 , this ) ;
255+ }
248256 }
249257}
250258
@@ -258,20 +266,23 @@ async Load(x) {
258266 if ( this . openedFile ) {
259267 this . infoLine = 'Loading: ' + this . openedFile ;
260268 const e = await this . cmd ( 'load' , '' , this . openedFile ) ;
261- this . openedFile = e . file ;
262- this . infoLine = e . msg ;
263- this . Toast ( this . infoLine , 1000 ) ;
264- const uns = { f :this . localGet ( 'Open' ) ,
265- d :this . localGet ( 'Text' ) } ;
266- if ( uns . f == this . openedFile && uns . d && uns . d != e . data ) {
267- this . localSet ( 'Unsaved' , uns . d ) ;
268- this . alertLine = html `< i @click ="${ this . Unsave } ">
269- Load unsaved from browser </ i > ` ;
270- } else {
271- this . localSet ( 'Text' , '' ) ; this . alertLine = '' ;
269+ if ( e ) {
270+ this . edit . cver = e . cver ;
271+ this . openedFile = e . file ;
272+ this . infoLine = e . msg ;
273+ this . Toast ( this . infoLine , 1000 ) ;
274+ const uns = { f :this . localGet ( 'Open' ) ,
275+ d :this . localGet ( 'Text' ) } ;
276+ if ( uns . f == this . openedFile && uns . d && uns . d != e . data ) {
277+ this . localSet ( 'Unsaved' , uns . d ) ;
278+ this . alertLine = html `< i @click ="${ this . Unsave } ">
279+ Load unsaved from browser </ i > ` ;
280+ } else {
281+ this . localSet ( 'Text' , '' ) ; this . alertLine = '' ;
282+ }
283+ this . renderRoot . querySelector ( '#code' ) . value = e . data ;
284+ this . code = e . data ;
272285 }
273- this . renderRoot . querySelector ( '#code' ) . value = e . data ;
274- this . code = e . data ;
275286 }
276287 this . edit . orgCode = this . code ;
277288 this . localSet ( 'Open' , this . openedFile ) ;
@@ -298,13 +309,15 @@ async Save() {
298309 if ( ! this . code ) { this . infoLine = '' ; this . infoLine = 'Text is empty!' ; return ; }
299310 this . infoLine = 'Saving: ' + this . openedFile ;
300311 const e = await this . cmd ( 'save' , this . code , this . openedFile ) ;
301- this . infoLine = e . msg ;
302- this . Toast ( this . infoLine , 2000 ) ;
303- if ( e . msg . includes ( 'Saved:' ) ) {
304- this . localSet ( 'Text' , '' ) ;
305- if ( savenew ) {
306- this . fileList . unshift ( this . openedFile ) ;
307- this . saveList ( ) ;
312+ if ( e ) {
313+ this . infoLine = e . msg ;
314+ this . Toast ( this . infoLine , 2000 ) ;
315+ if ( e . msg . includes ( 'Saved:' ) ) {
316+ this . localSet ( 'Text' , '' ) ;
317+ if ( savenew ) {
318+ this . fileList . unshift ( this . openedFile ) ;
319+ this . saveList ( ) ;
320+ }
308321 }
309322 }
310323 } else { this . openedFile = '' ; }
@@ -316,7 +329,7 @@ getCardSize() {
316329}
317330
318331setConfig ( config ) {
319- this . edit = { file : '' , hidefooter : false , readonly : false , basic : false , size : 0 , depth : 2 , ext : '' , orgCode : '' , coder :1 , ...config } ;
332+ this . edit = { file : '' , hidefooter : false , readonly : false , basic : false , size : 0 , depth : 2 , ext : '' , orgCode : '' , coder : 1 , cver : 0 , ...config } ;
320333 if ( this . edit . file ) {
321334 const f = this . edit . file . split ( '.' ) [ 1 ] ;
322335 if ( f ) {
0 commit comments