Skip to content

Commit

Permalink
Merge pull request #50 from ZhaoYangyang0403/feature/load-form-when-i…
Browse files Browse the repository at this point in the history
…nterface-is-unavailable

v1.14.0 - Load form when the interface is unavailable
  • Loading branch information
yumiguan authored Jul 18, 2023
2 parents 0c3b750 + bb67d3b commit 7e5ed19
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
12 changes: 12 additions & 0 deletions frontend/src/components/Bugit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export default {
this.$bus.$on('msg.success', this.successMessage)
this.$bus.$on('msg.info', this.infoMessage)
this.$bus.$on('msg.error', this.errorMessage)
this.$bus.$on('msg.loading', this.loadingMessage)
this.$bus.$on('msg.destroy', this.destroyMessage)
},
mounted () {
document.addEventListener('keydown', this.onKeyDown)
Expand Down Expand Up @@ -81,6 +83,13 @@ export default {
closable: true
})
},
loadingMessage (msg) {
this.$Message.loading({
content: msg,
duration: 0,
closable: true
})
},
displayMessage (data) {
if (data.hasOwnProperty('code')) {
if (data.code === 1000) {
Expand Down Expand Up @@ -109,6 +118,9 @@ export default {
closable: true
})
}
},
destroyMessage () {
this.$Message.destroy()
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions frontend/src/components/form/RichTextEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:format="['jpg','jpeg','png']"
accept=".jpg,.jpeg,.png"
:show-upload-list="false"
:before-upload="loadingFile"
:on-success="handleSuccess"
:on-error="handleError"
style="display: none;"
Expand Down Expand Up @@ -50,9 +51,9 @@ export default {
}
}
}
}
},
placeholder: 'Enter your description...'
},
placeholder: 'Enter your description...'
}
}
},
created () {
Expand All @@ -64,10 +65,15 @@ export default {
this.$store.commit('setDescValue', this.quill)
},
methods: {
loadingFile () {
this.$bus.$emit('msg.loading', 'Loading image...')
},
handleSuccess (response, file, fileList) {
this.$store.dispatch('updateImgToDesc', file)
this.$bus.$emit('msg.destroy')
},
handleError (error, file) {
this.$bus.$emit('msg.destroy')
this.$bus.$emit('msg.error', 'Import ' + file.name + ' error: ' + error)
},
initEvent () {
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/store/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,11 @@ export default {
commit('setTemplateDetail', [])
commit('setLoadTemplate', true)
api.getTemplate(path, state.selectedCache).then(response => {
commit('setTemplateDetail', response.data)
commit('setTemplateDetail', response.data.template_detail)
commit('setLoadTemplate', false)
if (response.data.message) {
bus.$emit('msg.info', response.data.message)
}
}).catch(error => {
bus.$emit('message', 'Load template detail error: ' + error)
commit('setLoadTemplate', false)
Expand All @@ -216,6 +219,7 @@ export default {
let imgId = attachmentsList[i].id
commit('addDescImgId', imgId)
let apiPath = `/plugins/bugit/api/attachments/${imgId}`
quill.focus()
let length = quill.getSelection().index
quill.insertEmbed(length, 'image', apiPath)
quill.setSelection(length + 1)
Expand Down Expand Up @@ -264,6 +268,8 @@ export default {
let extensionName = String(failAttach.split('.').slice(-1))
bus.$emit('msg.error', `Add ${failAttach} to attachment error: cannot convert data to a ${extensionName} file.`)
}
} else if (response.data.template_detail) {
commit('setTemplateDetail', response.data.template_detail)
}
bus.$emit('message', response.data)
commit('setSubmitLock', false)
Expand Down
14 changes: 13 additions & 1 deletion lyrebird_bugit/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,18 @@ def template():
template_detail = template.form({'cache': template_detail})
else:
template_detail = template.form()

# 'template_loaded' fields will be ensured to have a uniform value by the script.
if template_detail[0]['template_loaded']:
message = None
else:
message = 'Template loads failed! Please try again later.'

cache.selected_template(template_path, draft_name)
return jsonify(template_detail)
return application.make_ok_response(
message=message,
template_detail=template_detail
)


def issue():
Expand Down Expand Up @@ -114,6 +123,9 @@ def issue():
except Exception as e:
if e.__class__.__name__ == 'BugitFormInputError':
return application.make_fail_response(str(e))
if e.__class__.__name__ == 'SubmitError':
return application.make_fail_response(str(e.args[0]['message']),
template_detail=e.args[0]['template_detail'])
error_message = traceback.format_exc()
trace = "<br/>".join(error_message.split("\n"))
lyrebird.report({
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name='lyrebird-bugit',
version='1.13.0',
version='1.14.0',
packages=['lyrebird_bugit'],
url='https://github.com/Meituan-Dianping/lyrebird-bugit',
author='HBQA',
Expand Down

0 comments on commit 7e5ed19

Please sign in to comment.