Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(north, south): support edit node name #423

Merged
merged 1 commit into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/api/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ export const deleteDriver = (node: string) => {
return http.delete('/node', { data: { name: node } })
}

// USELESS
export const updateDriver = (data: { id: number; name: string }) => {
export const updateDriver = (data: { name: string; new_name: string }) => {
return http.put('/node', data)
}

Expand Down
4 changes: 2 additions & 2 deletions src/composables/config/useDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ export const useNodeDebugLogLevel = () => {

export const useDriverName = () => {
const isNotSupportRemoveNode = computed(() => (nodeName: string) => {
const nodeNameLowerCase = nodeName.toLocaleLowerCase()
const nodeNameLowerCase = nodeName?.toLocaleLowerCase()
const whiteList = ['data-stream-processing', 'monitor']
return whiteList.includes(nodeNameLowerCase)
})

const isMonitorNode = (nodeName: string) => nodeName.toLowerCase() === 'monitor'
const isMonitorNode = (nodeName: string) => nodeName?.toLowerCase() === 'monitor'

return {
isNotSupportRemoveNode,
Expand Down
2 changes: 1 addition & 1 deletion src/composables/config/useNodeList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const useFillNodeListStatusData = () => {
const itemStatusData: DriverStateData = {
running: !itemStatus ? 1 : itemStatus.running,
link: !itemStatus ? 0 : itemStatus.link,
rtt: Number(itemStatus.rtt) || 0,
rtt: Number(itemStatus?.rtt) || 0,
}
const node = Object.assign(item, itemStatusData)
return Promise.resolve(node)
Expand Down
23 changes: 23 additions & 0 deletions src/composables/config/useNorthDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ export default (autoLoad = true, needRefreshStatus = false) => {

let refreshStatusTimer: undefined | number

const showDialog = ref(false)
const showEditDialog = ref(false)
const editDriverData: Ref<{ name: string }> = ref({ name: '' })
const addConfig = () => {
showDialog.value = true
}
const editDialog = (node: DriverItemInList) => {
showEditDialog.value = true
editDriverData.value = { name: node.name }
}

const nodePlugin = computed(
() => (nodeName: string) => northDriverList.value.find((item: DriverItemInList) => item.name === nodeName)?.plugin,
)
Expand Down Expand Up @@ -62,6 +73,11 @@ export default (autoLoad = true, needRefreshStatus = false) => {
getNorthDriverList()
}, 500)

const reloadDriverList = () => {
getNorthDriverList()
editDriverData.value = { name: '' }
}

const startTimer = () => {
refreshStatusTimer = window.setInterval(async () => {
northDriverList.value = await fillNodeListStatusData(northDriverList.value)
Expand Down Expand Up @@ -144,12 +160,19 @@ export default (autoLoad = true, needRefreshStatus = false) => {
isListLoading,
getNorthDriverList,
dbGetNorthDriverList,
reloadDriverList,
isMQTTPugin,
nodePlugin,
goGroupPage,
goNodeConfig,
modifyNodeLogLevel,
deleteDriver,
sortDataByKey,

addConfig,
showDialog,
editDialog,
showEditDialog,
editDriverData,
}
}
25 changes: 25 additions & 0 deletions src/composables/config/useSouthDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ export default (autoLoad = true, needRefreshStatus = false) => {
const southDriverList: Ref<Array<DriverItemInList>> = ref([])
const isListLoading: Ref<boolean> = ref(false)

// add | edit driver
const showDialog = ref(false)
const showEditDialog = ref(false)
const editDriverData: Ref<{ name: string }> = ref({ name: '' })
const addConfig = () => {
showDialog.value = true
}
const editDialog = (node: DriverItemInList) => {
showEditDialog.value = true
editDriverData.value = { name: node.name }
}

const pageController = computed({
get: () => store.state.paginationData,
set: (val) => {
Expand Down Expand Up @@ -159,6 +171,11 @@ export default (autoLoad = true, needRefreshStatus = false) => {
dbGetSouthDriverList()
}

const reloadDriverList = () => {
getSouthDriverList()
editDriverData.value = { name: '' }
}

if (autoLoad) {
getSouthDriverList()
}
Expand All @@ -183,10 +200,18 @@ export default (autoLoad = true, needRefreshStatus = false) => {
isListLoading,
getSouthDriverList,
dbGetSouthDriverList,
reloadDriverList,

goGroupPage,
goNodeConfig,
modifyNodeLogLevel,
deleteDriver,
sortDataByKey,

addConfig,
showDialog,
editDialog,
showEditDialog,
editDriverData,
}
}
8 changes: 8 additions & 0 deletions src/i18n/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export default {
zh: '添加应用',
en: 'Add App',
},
editApp: {
zh: '编辑应用',
en: 'Edit App',
},
workStatus: {
zh: '工作状态',
en: 'Status',
Expand Down Expand Up @@ -107,6 +111,10 @@ export default {
zh: '新增设备',
en: 'New Device',
},
editDevice: {
zh: '编辑设备',
en: 'Edit Device',
},
addr: {
zh: '地址',
en: 'Addr',
Expand Down
28 changes: 22 additions & 6 deletions src/views/config/components/EditNodeNameDialog.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<el-dialog v-model="showDialog" :width="500" custom-class="common-dialog" :title="$t('common.edit')" :z-index="2000">
<el-dialog v-model="showDialog" :width="500" custom-class="common-dialog" :title="dialogTitle" :z-index="2000">
<emqx-form ref="formCom" :model="form" :rules="rules" @submit.prevent>
<emqx-form-item prop="name" :label="$t('common.name')" required>
<emqx-input v-model.trim="form.name" />
Expand All @@ -23,30 +23,45 @@ import { ElDialog } from 'element-plus'
import { useI18n } from 'vue-i18n'
import { updateDriver } from '@/api/config'
import { EmqxMessage } from '@emqx/emqx-ui'
import { DriverDirection } from '@/types/enums'
import { cloneDeep } from 'lodash'

const { t } = useI18n()
const props = defineProps({
modelValue: {
type: Boolean,
required: true,
},
type: {
type: Number as PropType<DriverDirection>,
required: true,
},
nodeName: {
type: String,
required: true,
},
node: {
type: Object as PropType<{ id: number; name: string }>,
type: Object as PropType<{ name: string }>,
required: true,
},
})
const emit = defineEmits(['update:modelValue', 'updated'])

const form = ref({
id: 0,
name: '',
})
const formCom = ref()

const rules = computed(() => {
return {
name: [{ required: true, message: t('config.nameRequired') }],
}
})

const dialogTitle = computed(() =>
props.type === DriverDirection.North ? t('config.editApp') : t('config.editDevice'),
)

const isSubmitting = ref(false)

const showDialog = computed({
Expand All @@ -60,16 +75,17 @@ watch(showDialog, (val) => {
if (!val) {
formCom.value.resetField()
} else {
form.value = props.node
form.value = cloneDeep(props.node)
}
})

const submit = async () => {
try {
await formCom.value.validate()
isSubmitting.value = true
await updateDriver(form.value)
EmqxMessage.success(t('common.submitSuccess'))

await updateDriver({ name: props.nodeName, new_name: form.value.name })
EmqxMessage.success(t('common.updateSuccess'))
showDialog.value = false
emit('updated')
} catch (error) {
Expand Down
Loading