Add saving json from monaco-editor
This commit is contained in:
parent
5d4dc81fdf
commit
0df2b6b1bf
5 changed files with 32 additions and 13 deletions
|
|
@ -1 +1 @@
|
|||
<div {{did-insert this.initEditor}} class="h-80" ...attributes></div>
|
||||
<div {{did-insert this.initEditor}} class="mb-4" ...attributes></div>
|
||||
|
|
|
|||
|
|
@ -8,10 +8,28 @@ export default class MonacoEditorComponent extends Component {
|
|||
this.editor = monaco.editor.create(el, {
|
||||
value: this.args.value,
|
||||
language: this.args.language,
|
||||
lineNumbers: 'off',
|
||||
roundedSelection: false,
|
||||
scrollBeyondLastLine: false,
|
||||
minimap: {
|
||||
enabled: false,
|
||||
},
|
||||
});
|
||||
|
||||
// Add onChange event
|
||||
if (this.args.onChange) {
|
||||
this.editor.onDidChangeModelContent(() => {
|
||||
this.args.onChange(this.editor.getValue());
|
||||
});
|
||||
}
|
||||
|
||||
// autoresize height of element
|
||||
const disposable = this.editor.onDidContentSizeChange(() => {
|
||||
const contentHeight = Math.min(320, this.editor.getContentHeight());
|
||||
el.style.height = `${contentHeight}px`;
|
||||
this.editor.layout();
|
||||
disposable.dispose();
|
||||
});
|
||||
}
|
||||
|
||||
willDestroy() {
|
||||
|
|
|
|||
|
|
@ -3,12 +3,7 @@ import { action } from '@ember/object';
|
|||
|
||||
export default class AdminIndexesItemDocumentsDocumentEditController extends Controller {
|
||||
@action
|
||||
save(event) {
|
||||
event.preventDefault();
|
||||
|
||||
const formData = new FormData(event.currentTarget);
|
||||
const data = formData.get('document');
|
||||
|
||||
this.model.index.saveDocument(data);
|
||||
save() {
|
||||
this.model.index.saveDocument(this.model.document);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,9 +48,13 @@ export default class Index {
|
|||
}
|
||||
|
||||
saveDocument(document) {
|
||||
if (typeof document === 'string') {
|
||||
document = JSON.parse(document);
|
||||
}
|
||||
|
||||
return query(`${this.path}/documents`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify([JSON.parse(document)]),
|
||||
body: JSON.stringify([document]),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<form {{on 'submit' this.save}}>
|
||||
<MonacoEditor @value={{stringify @model.document}} @language='json'/>
|
||||
<MonacoEditor
|
||||
@value={{stringify @model.document}}
|
||||
@language='json'
|
||||
@onChange={{set this.model 'document'}}
|
||||
/>
|
||||
|
||||
<Button type='submit' @text='Save' @style='primary' />
|
||||
</form>
|
||||
<Button type='submit' @text='Save' @style='primary' @onClick={{this.save}} />
|
||||
|
|
|
|||
Loading…
Reference in a new issue