Skip to content

Commit

Permalink
fix: resolve file load / ready state issues
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Bassett <craig.bassett@gmail.com>
  • Loading branch information
cadriel committed Apr 8, 2021
1 parent 73e03e4 commit 645741e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/components/widgets/filesystem/FileEditor.vue
Expand Up @@ -117,6 +117,7 @@ export default class FileEditor extends Vue {
editorMounted () {
if (this.editor) {
this.$emit('ready')
this.editor.onDidChangeModelContent(event => {
const value = this.editor?.getValue()
this.emitChange(value, event)
Expand Down
27 changes: 17 additions & 10 deletions src/components/widgets/filesystem/FileEditorDialog.vue
Expand Up @@ -34,12 +34,14 @@
</app-btn>
<app-btn
v-if="!readonly && !printerPrinting && rootProperties.showSaveRestart"
:disabled="loading || !editorReady"
@click="emitSave(true)">
<v-icon small :left="!isMobile">$restart</v-icon>
<span class="d-none d-md-inline-block">{{ $t('app.general.btn.save_restart') }}</span>
</app-btn>
<app-btn
v-if="!readonly"
:disabled="loading || !editorReady"
@click="emitSave(false)">
<v-icon small :left="!isMobile">$save</v-icon>
<span class="d-none d-md-inline-block">{{ $t('app.general.btn.save') }}</span>
Expand All @@ -54,10 +56,10 @@

<file-editor
v-if="contents !== undefined"
:value="contents"
@input="updatedContent = $event"
v-model="updatedContent"
:filename="filename"
:readonly="readonly">
:readonly="readonly"
@ready="editorReady = true">
</file-editor>

</v-card>
Expand All @@ -69,12 +71,12 @@ import { Component, Mixins, Prop } from 'vue-property-decorator'
import StateMixin from '@/mixins/state'
// Lazy Load the file editor.
const FileEditor = () => import(
/* webpackPreload: true */
/* webpackChunkName: "chunk-fileeditor" */
'./FileEditor.vue'
)
// import FileEditor from './FileEditor.vue'
// const FileEditor = () => import(
// /* webpackPreload: true */
// /* webpackChunkName: "chunk-fileeditor" */
// './FileEditor.vue'
// )
import FileEditor from './FileEditor.vue'
@Component({
components: {
Expand All @@ -100,7 +102,8 @@ export default class FileEditorDialog extends Mixins(StateMixin) {
@Prop({ type: Boolean, default: false })
public readonly!: boolean
updatedContent = ''
updatedContent = this.contents
editorReady = false
get rootProperties () {
return this.$store.getters['files/getRootProperties'](this.root)
Expand All @@ -110,6 +113,10 @@ export default class FileEditorDialog extends Mixins(StateMixin) {
return this.$vuetify.breakpoint.sm
}
mounted () {
this.updatedContent = this.contents
}
emitClose () {
this.$emit('input', false)
}
Expand Down
26 changes: 14 additions & 12 deletions src/components/widgets/filesystem/FileSystem.vue
Expand Up @@ -438,18 +438,20 @@ export default class FileSystem extends Mixins(StateMixin, FilesMixin, ServicesM
}
async handleSaveFileChanges (contents: string, restart: boolean) {
const file = new File([contents], this.fileEditorDialogState.filename)
if (!restart && this.fileEditorDialogState.open) this.fileEditorDialogState.loading = true
await this.uploadFile(file, this.visiblePath, this.currentRoot, false)
this.fileEditorDialogState.loading = false
if (restart) {
if (
this.fileEditorDialogState.filename &&
this.fileEditorDialogState.filename === 'moonraker.conf'
) {
this.serviceRestartMoonraker()
} else {
this.firmwareRestartKlippy()
if (contents.length > 0) {
const file = new File([contents], this.fileEditorDialogState.filename)
if (!restart && this.fileEditorDialogState.open) this.fileEditorDialogState.loading = true
await this.uploadFile(file, this.visiblePath, this.currentRoot, false)
this.fileEditorDialogState.loading = false
if (restart) {
if (
this.fileEditorDialogState.filename &&
this.fileEditorDialogState.filename === 'moonraker.conf'
) {
this.serviceRestartMoonraker()
} else {
this.firmwareRestartKlippy()
}
}
}
}
Expand Down

0 comments on commit 645741e

Please sign in to comment.