diff --git a/app/components/file-preview/component.js b/app/components/file-preview/component.js index d94a7bd..ba40f5a 100644 --- a/app/components/file-preview/component.js +++ b/app/components/file-preview/component.js @@ -95,9 +95,46 @@ export default Component.extend({ view.expand(true); view.withRootName = false; - view.readonly = true; + view.readonly = this.get('hideEditor'); this.set('jsonTreeView', view); + }, + + onShowEditor: observer('showEditor', function(){ + if (this.get('fileLoaded') && this.get('isJSON') && this.get('jsonShowTree')) { + this.set('jsonTreeView.readonly', !this.get('showEditor')); + } + }), + + actions: { + + saveChanges () { + const path = this.get('metaData.path'); + + if (this.get('isJSON') && this.get('jsonShowTree')) { + const content = JSON.stringify(this.get('jsonTreeView.value')); + + this.get('storage.client') + .storeFile('application/json', path, content) + .then(etag => { + this.setProperties({ + 'metaData.etag': etag, + fileContent: content, + showEditor: false + }); + }).catch(err => { + alert('Failed to update the file. Check the console for more info'); + console.error(err); + }); + } else { + console.warn('not implemented'); + } + }, + + cancelEditor () { + this.set('showEditor', false); + } + } }); diff --git a/app/components/file-preview/template.hbs b/app/components/file-preview/template.hbs index 1bd9acd..3b3581a 100644 --- a/app/components/file-preview/template.hbs +++ b/app/components/file-preview/template.hbs @@ -18,4 +18,11 @@ {{fileContent}} {{/if}} {{/if}} + + {{#if showEditor}} +
+ + +
+ {{/if}} {{/if}} \ No newline at end of file diff --git a/app/controllers/inspect.js b/app/controllers/inspect.js index d48a774..1769242 100644 --- a/app/controllers/inspect.js +++ b/app/controllers/inspect.js @@ -53,7 +53,6 @@ export default Controller.extend({ showEditor () { this.set('documentShowEditor', true); - // TODO init editing }, cancelEditor () { diff --git a/app/styles/_layout.scss b/app/styles/_layout.scss index 7a0dd8c..007332e 100644 --- a/app/styles/_layout.scss +++ b/app/styles/_layout.scss @@ -99,7 +99,7 @@ padding: 1.5rem 1px; &.content { - overflow: auto; + overflow: hidden; } &.meta { diff --git a/app/styles/components/_file-preview.scss b/app/styles/components/_file-preview.scss index 15df465..07324d2 100644 --- a/app/styles/components/_file-preview.scss +++ b/app/styles/components/_file-preview.scss @@ -11,4 +11,12 @@ max-width: 100%; } + #json-tree-view { + overflow: auto; + } + + .actions { + margin-top: 2rem; + } + } diff --git a/app/templates/inspect.hbs b/app/templates/inspect.hbs index 1e91cc1..f557e58 100644 --- a/app/templates/inspect.hbs +++ b/app/templates/inspect.hbs @@ -42,7 +42,7 @@
@@ -62,6 +62,9 @@
{{file-preview metaData=model.documentMetaData isJSON=documentIsJSON + isEditable=documentIsEditableHide + showEditor=documentShowEditor + hideEditor=documentHideEditor jsonShowTree=jsonShowTree jsonShowSource=jsonShowSource}}