Edit files via the JSON tree view editor
This commit is contained in:
parent
ddecda8220
commit
c979b13df5
@ -95,9 +95,46 @@ export default Component.extend({
|
|||||||
view.expand(true);
|
view.expand(true);
|
||||||
|
|
||||||
view.withRootName = false;
|
view.withRootName = false;
|
||||||
view.readonly = true;
|
view.readonly = this.get('hideEditor');
|
||||||
|
|
||||||
this.set('jsonTreeView', view);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -18,4 +18,11 @@
|
|||||||
<code>{{fileContent}}</code>
|
<code>{{fileContent}}</code>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
|
{{#if showEditor}}
|
||||||
|
<div class="actions">
|
||||||
|
<button {{action "saveChanges"}}>Save changes</button>
|
||||||
|
<button {{action "cancelEditor"}}>Cancel editing</button>
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
{{/if}}
|
{{/if}}
|
@ -53,7 +53,6 @@ export default Controller.extend({
|
|||||||
|
|
||||||
showEditor () {
|
showEditor () {
|
||||||
this.set('documentShowEditor', true);
|
this.set('documentShowEditor', true);
|
||||||
// TODO init editing
|
|
||||||
},
|
},
|
||||||
|
|
||||||
cancelEditor () {
|
cancelEditor () {
|
||||||
|
@ -99,7 +99,7 @@
|
|||||||
padding: 1.5rem 1px;
|
padding: 1.5rem 1px;
|
||||||
|
|
||||||
&.content {
|
&.content {
|
||||||
overflow: auto;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.meta {
|
&.meta {
|
||||||
|
@ -11,4 +11,12 @@
|
|||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#json-tree-view {
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.actions {
|
||||||
|
margin-top: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
<div class="button-group editable">
|
<div class="button-group editable">
|
||||||
<button disabled={{documentHideEditor}}
|
<button disabled={{documentHideEditor}}
|
||||||
class="{{if documentHideEditor "active"}}"
|
class="{{if documentHideEditor "active"}}"
|
||||||
title="{{if documentShowEditor "Cancel editing"}}"
|
title="{{if documentHideEditor "Cancel editing"}}"
|
||||||
{{action "cancelEditor"}}>
|
{{action "cancelEditor"}}>
|
||||||
{{partial "icons/eye"}}
|
{{partial "icons/eye"}}
|
||||||
</button>
|
</button>
|
||||||
@ -62,6 +62,9 @@
|
|||||||
<section class="content">
|
<section class="content">
|
||||||
{{file-preview metaData=model.documentMetaData
|
{{file-preview metaData=model.documentMetaData
|
||||||
isJSON=documentIsJSON
|
isJSON=documentIsJSON
|
||||||
|
isEditable=documentIsEditableHide
|
||||||
|
showEditor=documentShowEditor
|
||||||
|
hideEditor=documentHideEditor
|
||||||
jsonShowTree=jsonShowTree
|
jsonShowTree=jsonShowTree
|
||||||
jsonShowSource=jsonShowSource}}
|
jsonShowSource=jsonShowSource}}
|
||||||
</section>
|
</section>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user