Skip to content

Commit

Permalink
Merge pull request #33 from Rena-Yuan/feature/flow-to-attachment
Browse files Browse the repository at this point in the history
v1.11.0 - Feature/add flow to attachment
  • Loading branch information
Rena-Yuan authored May 11, 2022
2 parents c64795c + 099be5e commit 621f750
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 70 deletions.
4 changes: 2 additions & 2 deletions frontend/src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ export const saveImage = (id, imageData) => {
})
}

export const createIssue = (templateInfo, issue, attachments, snapshots) => {
export const createIssue = (templateInfo, issue, attachments, exportAttachments) => {
return axios({
url: API_PREFIX + '/issue',
method: 'POST',
data: {
template: templateInfo,
issue,
attachments,
snapshots
exportAttachments
}
})
}
Expand Down
20 changes: 17 additions & 3 deletions frontend/src/components/event/EventInspector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,24 @@ export default {
})
}
if (eventObj.snapshot) {
this.$bus.$emit('addSnapshot', eventObj)
let fileName = `snapshot_${eventObj.id}`
this.$bus.$emit('addExportAttachments', {
attachmentName: fileName,
attachmentObj: eventObj,
attachmentType: 'lb'
})
}
if (eventObj.attachments) {
this.$bus.$emit('addAttachments', eventObj.attachments)
if (eventObj.export) {
// Export to attachment with a specified type.
if (eventObj.export.hasOwnProperty('converter')) {
let fileName = `${eventObj.channel}_${eventObj.id}`
this.$bus.$emit('addExportAttachments', {
attachmentName: fileName,
attachmentObj: eventObj,
// TODO: How to get other type's of file
attachmentType: 'json'
})
}
}
},
showContextMenu (event) {
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/form/AttachmentModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
:src="'/plugins/bugit/api/attachments/' + this.attachmentId"
/>
</p>
<p v-else-if="isSnapshot">
<p v-else-if="isJson">
<CodeEditor read-only language="json" v-model="this.attachmentContent" style="height:500px"/>
</p>
<p v-else>
Expand All @@ -22,7 +22,7 @@
</div>
<div slot="footer">
<p v-if="isImageFile">
<Button long type="success" @click="saveImage()">Save</Button>
<Button long type="success" @click="saveImage">Save</Button>
</p>
<p v-else>
<Button long style="background-color:#dcdee2" @click="isDisplayFile = false">Close</Button>
Expand Down Expand Up @@ -65,7 +65,7 @@ export default {
return imageFileSuffix.indexOf(nameSuffix) > -1
},
isSnapshot () {
isJson () {
if (this.attachmentContent) {
this.attachmentContent = JSON.stringify(this.attachmentContent, null, 2)
return true
Expand Down
21 changes: 10 additions & 11 deletions frontend/src/components/form/AttachmentsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<AttachmentItem :attachment="attachment" :index="index"/>
</p>
</div>
<div v-if="snapshots.length">
<p v-for="(snapshot, index) in snapshots" :key="index" class="attachment-line">
<SnapshotItem :snapshot="snapshot" :index="index"/>
<div v-if="exportAttachments.length">
<p v-for="(exportAttachment, index) in exportAttachments" :key="index" class="attachment-line">
<ExportAttachmentItem :exportAttachment="exportAttachment" :index="index"/>
</p>
</div>
<Upload
Expand All @@ -30,33 +30,32 @@

<script>
import AttachmentItem from '@/components/form/AttachmentItem.vue'
import SnapshotItem from '@/components/form/SnapshotItem.vue'
import ExportAttachmentItem from '@/components/form/ExportAttachmentItem.vue'
export default {
components: {
AttachmentItem,
SnapshotItem
ExportAttachmentItem
},
created () {
this.$io.on('attachments', this.addAttachment)
this.$bus.$on('addAttachments', this.addAttachment)
this.$bus.$on('addSnapshot', this.addSnapshot)
this.$bus.$on('addExportAttachments', this.addExportAttachment)
this.$store.dispatch('loadAttachment')
},
computed: {
attachments () {
return this.$store.state.form.attachmentsList
},
snapshots () {
return this.$store.state.form.snapshotList
exportAttachments () {
return this.$store.state.form.exportAttachmentList
}
},
methods: {
addAttachment () {
this.$store.dispatch('loadAttachment')
},
addSnapshot (snapshot) {
this.$store.commit('addSnapshot', snapshot)
addExportAttachment (exportAttachment) {
this.$store.dispatch('addExportAttachment', exportAttachment)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
<span class="attachment-item">
<template v-if="editMode">
<span class="attachment-name">
<Input style="padding-right:3px" v-model="name" size="small" type="text" />
<Input style="padding-right:3px" v-model="baseName" size="small" type="text">
<span slot="append">.{{extensionName}}</span>
</Input>
</span>
<span class="attachment-actions">
<Tooltip content="Preview" placement="top">
Expand Down Expand Up @@ -73,19 +75,23 @@

<script>
export default {
props: ['snapshot', 'index'],
props: ['exportAttachment', 'index'],
data () {
return {
'name': this.snapshot.name
'baseName': this.exportAttachment.name,
'extensionName': this.exportAttachment.attachmentType
}
},
computed: {
name () {
return `${this.baseName}.${this.extensionName}`
},
editMode: {
get () {
return this.$store.state.form.snapshotList[this.index].editMode
return this.$store.state.form.exportAttachmentList[this.index].editMode
},
set (val) {
this.$store.commit('setSnapshotEditMode', {
this.$store.commit('setExportAttachmentEditMode', {
index: this.index,
mode: val
})
Expand All @@ -94,22 +100,23 @@ export default {
},
methods: {
deleteAttach () {
this.$store.commit('deleteSnapshot', this.index)
this.$store.commit('deleteExportAttachment', this.index)
},
displayAttach () {
this.$bus.$emit('displayAttach', this.snapshot)
this.$bus.$emit('displayAttach', this.exportAttachment)
},
rename () {
this.editMode = true
},
cancelRename () {
this.name = this.snapshot.name
this.baseName = this.exportAttachment.name
this.editMode = false
},
saveName () {
this.$store.dispatch('renameSnapshot', {
this.$store.dispatch('renameExportAttachment', {
index: this.index,
newName: this.name
baseName: this.baseName,
extensionName: this.extensionName
})
}
}
Expand Down
89 changes: 59 additions & 30 deletions frontend/src/store/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default {
formValue: {},
attachmentsList: [],
inEditModeAttachments: [],
snapshotList: [],
exportAttachmentList: [],
loadAttachmentCount: 0,
shownFileName: null,
submitLock: false,
Expand Down Expand Up @@ -116,22 +116,22 @@ export default {
setAttachmentEditMode (state, { index, mode }) {
state.attachmentsList[index].editMode = mode
},
addSnapshot (state, snapshot) {
let fileName = 'snapshot_' + snapshot.id
state.snapshotList.push({
'name': fileName,
'editMode': false,
'eventObj': snapshot
addExportAttachment (state, { attachmentName, attachmentObj, attachmentType }) {
state.exportAttachmentList.push({
'name': attachmentName,
'eventObj': attachmentObj,
'attachmentType': attachmentType,
'editMode': false
})
},
deleteSnapshot (state, index) {
state.snapshotList.splice(index, 1)
deleteExportAttachment (state, index) {
state.exportAttachmentList.splice(index, 1)
},
setSnapshotName (state, { index, newName }) {
state.snapshotList[index].name = newName
setExportAttachmentName (state, { index, baseName }) {
state.exportAttachmentList[index].name = baseName
},
setSnapshotEditMode (state, { index, mode }) {
state.snapshotList[index].editMode = mode
setExportAttachmentEditMode (state, { index, mode }) {
state.exportAttachmentList[index].editMode = mode
}
},
actions: {
Expand Down Expand Up @@ -206,9 +206,13 @@ export default {
bus.$emit('message', 'Submitting issue ...')
commit('setSubmitLock', true)
api.createIssue(state.templates[state.selectedTemplateIndex], state.templateDetail,
state.attachmentsList, state.snapshotList)
state.attachmentsList, state.exportAttachmentList)
.then(response => {
bus.$emit('message', response.data)
for (let failAttach of response.data.export_fail_attachments) {
let extensionName = String(failAttach.split('.').slice(-1))
bus.$emit('msg.error', `Add ${failAttach} to attachment error: cannot convert data to a ${extensionName} file.`)
}
bus.$emit('message', response.data.message)
commit('setSubmitLock', false)
}).catch(response => {
bus.$emit('message', response.data)
Expand All @@ -232,26 +236,33 @@ export default {
},
isNameValid ({ state }, name) {
if (!name || name.trim().length === 0) {
return Promise.reject('File name cannot be empty')
return Promise.reject(new Error('File name cannot be empty'))
}
if (name.trim().length > 255) {
return Promise.reject(new Error('File name is too long (255 characters limited)'))
}
for (const i in state.illegalChars) {
if (name.indexOf(state.illegalChars[i]) > -1) {
return Promise.reject(`Illegal character [${state.illegalChars[i]}] in file name.`)
return Promise.reject(new Error(`Illegal character [${state.illegalChars[i]}] in file name.`))
}
}
return Promise.resolve()
},
isNameNotExists ({ state }, { name, sourceList, index }) {
for (let i in sourceList) {
if (sourceList[i].name.toLowerCase() === name.toLowerCase() && i.toString() !== index.toString()) {
return Promise.reject('A file with the same name exists')
let fullName = sourceList[i].name
if (sourceList[i].hasOwnProperty('attachmentType')) {
fullName += `.${sourceList[i].attachmentType}`
}
if (fullName.toLowerCase() === name.toLowerCase() && i.toString() !== index.toString()) {
return Promise.reject(new Error('A file with the same name exists'))
}
}
return Promise.resolve()
},
renameAttachment ({ state, commit, dispatch }, { index, baseName, extensionName }) {
dispatch('isNameValid', baseName).then(() => {
let newName = `${baseName}.${extensionName}`
let newName = `${baseName.trim()}.${extensionName}`
dispatch('isNameNotExists', {
name: newName,
sourceList: state.attachmentsList,
Expand All @@ -278,30 +289,48 @@ export default {
bus.$emit('msg.error', response.data)
})
}).catch(err => {
bus.$emit('msg.error', `Rename attachment to [${newName}] error: ${err}`)
bus.$emit('msg.error', `Rename attachment to [${newName}] ${err}`)
})
}).catch(err => {
bus.$emit('msg.error', `Rename attachment error: ${err}`)
bus.$emit('msg.error', `Rename attachment ${err}`)
})
},
renameSnapshot ({ state, commit, dispatch }, { index, newName }) {
dispatch('isNameValid', newName).then(() => {
addExportAttachment ({ state, commit, dispatch }, { attachmentName, attachmentObj, attachmentType }) {
let fullName = `${attachmentName.trim()}.${attachmentType}`
if (fullName.trim().length > 255) {
bus.$emit('msg.error', `Add export attachment error: File name is too long (255 characters limited)`)
return
}
dispatch('isNameNotExists', {
name: fullName,
sourceList: state.exportAttachmentList,
index: -1
}).then(() => {
commit('addExportAttachment', { attachmentName, attachmentObj, attachmentType })
}).catch(() => {
let newBaseName = `${attachmentName.trim()} copy`
dispatch('addExportAttachment', { attachmentName: newBaseName, attachmentObj, attachmentType })
})
},
renameExportAttachment ({ state, commit, dispatch }, { index, baseName, extensionName }) {
dispatch('isNameValid', baseName).then(() => {
let newName = `${baseName.trim()}.${extensionName}`
dispatch('isNameNotExists', {
name: newName,
sourceList: state.snapshotList,
sourceList: state.exportAttachmentList,
index: index
}).then(() => {
commit('setSnapshotName', { index, newName })
commit('setSnapshotEditMode', {
commit('setExportAttachmentName', { index, baseName })
commit('setExportAttachmentEditMode', {
index: index,
mode: false
})
bus.$emit('msg.success', `Rename snapshot to [${newName}] success!`)
bus.$emit('msg.success', `Rename attachment to [${newName}] success!`)
}).catch(err => {
bus.$emit('msg.error', `Rename snapshot to [${newName}] error: ${err}`)
bus.$emit('msg.error', `Rename attachment to [${newName}] ${err}`)
})
}).catch(err => {
bus.$emit('msg.error', `Rename snapshot error: ${err}`)
bus.$emit('msg.error', `Rename attachment ${err}`)
})
},
saveCache ({ state, dispatch, commit }) {
Expand Down
25 changes: 20 additions & 5 deletions lyrebird_bugit/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,25 @@ def issue():

issue_data = issue_req['issue']
attachments = issue_req['attachments']
snapshots = issue_req['snapshots']
export_attachments = issue_req['exportAttachments']

all_bugit_message = ''

# Export Snapshot
for snapshot in snapshots:
attachments.append(attachment.export_snapshot(snapshot))
# Export Snapshot/Json/... attachment files
export_fail_attachments = []
for attachment_item in export_attachments:
if attachment_item.get('attachmentType') == 'lb':
# Export Snapshot
attachments.append(attachment.export_snapshot(attachment_item))
else:
# Export to specified file
file_item = attachment.export_attachment_file(attachment_item)
if 'id' in file_item:
attachments.append(file_item)
else:
# export fail item do not have 'id' key
export_fail_attachments.append(file_item['name'])

# Set bugit script context
context = {'issue': issue_data, 'attachments': attachments}
# Set submit actions
Expand Down Expand Up @@ -120,7 +132,10 @@ def issue():
})
#Delete Snapshot
attachment.remove_attach()
return application.make_ok_response(message=f'Create issue success! {all_bugit_message}')
return application.make_ok_response(
message=f'Create issue success! {all_bugit_message}',
export_fail_attachments=export_fail_attachments
)


def take_screenshot(platform, device_id):
Expand Down
Loading

0 comments on commit 621f750

Please sign in to comment.