mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 02:15:48 +02:00
feat: update notification template for config sync
This commit is contained in:
parent
1c1da92363
commit
c9370a0562
7 changed files with 84 additions and 93 deletions
|
@ -13,13 +13,13 @@ export const detailRender = (args: customRender) => {
|
|||
return syncCertificateSuccess(args.text)
|
||||
case 'Sync Certificate Error':
|
||||
return syncCertificateError(args.text)
|
||||
case 'Sync Rename Configuration Success':
|
||||
case 'Rename Remote Config Success':
|
||||
return syncRenameConfigSuccess(args.text)
|
||||
case 'Sync Rename Configuration Error':
|
||||
case 'Rename Remote Config Error':
|
||||
return syncRenameConfigError(args.text)
|
||||
case 'Sync Configuration Success':
|
||||
case 'Sync Config Success':
|
||||
return syncConfigSuccess(args.text)
|
||||
case 'Sync Configuration Error':
|
||||
case 'Sync Config Error':
|
||||
return syncConfigError(args.text)
|
||||
default:
|
||||
return args.text
|
||||
|
|
|
@ -13,7 +13,7 @@ export interface StdCurdProps<T> extends StdTableProps<T> {
|
|||
modalMask?: boolean
|
||||
exportExcel?: boolean
|
||||
importExcel?: boolean
|
||||
|
||||
disableTrash?: boolean
|
||||
disableAdd?: boolean
|
||||
onClickAdd?: () => void
|
||||
|
||||
|
@ -201,7 +201,7 @@ const localOverwriteParams = reactive(props.overwriteParams ?? {})
|
|||
@click="add"
|
||||
>{{ $gettext('Add') }}</a>
|
||||
<slot name="extra" />
|
||||
<template v-if="!disableDelete">
|
||||
<template v-if="!disableDelete && !disableTrash">
|
||||
<a
|
||||
v-if="!getParams.trash"
|
||||
@click="getParams.trash = true"
|
||||
|
|
|
@ -33,6 +33,7 @@ const pageSize = computed({
|
|||
v-model:pageSize="pageSize"
|
||||
:disabled="loading"
|
||||
:current="pagination.current_page"
|
||||
show-size-changer
|
||||
:size="size"
|
||||
:total="pagination.total"
|
||||
@change="change"
|
||||
|
|
|
@ -20,7 +20,6 @@ export interface StdTableProps<T = any> {
|
|||
title?: string
|
||||
mode?: string
|
||||
rowKey?: string
|
||||
|
||||
api: Curd<T>
|
||||
columns: Column[]
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
|
|
|
@ -2,41 +2,8 @@
|
|||
import { message } from 'ant-design-vue'
|
||||
import StdCurd from '@/components/StdDesign/StdDataDisplay/StdCurd.vue'
|
||||
import notification from '@/api/notification'
|
||||
import type { Column } from '@/components/StdDesign/types'
|
||||
import type { customRender } from '@/components/StdDesign/StdDataDisplay/StdTableTransformer'
|
||||
import { datetime, mask } from '@/components/StdDesign/StdDataDisplay/StdTableTransformer'
|
||||
import { NotificationType } from '@/constants'
|
||||
import { useUserStore } from '@/pinia'
|
||||
import { detailRender } from '@/components/Notification/detailRender'
|
||||
|
||||
const columns: Column[] = [{
|
||||
title: () => $gettext('Type'),
|
||||
dataIndex: 'type',
|
||||
customRender: mask(NotificationType),
|
||||
sortable: true,
|
||||
pithy: true,
|
||||
}, {
|
||||
title: () => $gettext('Title'),
|
||||
dataIndex: 'title',
|
||||
customRender: (args: customRender) => {
|
||||
return h('span', $gettext(args.text))
|
||||
},
|
||||
pithy: true,
|
||||
}, {
|
||||
title: () => $gettext('Details'),
|
||||
dataIndex: 'details',
|
||||
customRender: detailRender,
|
||||
pithy: true,
|
||||
}, {
|
||||
title: () => $gettext('Created at'),
|
||||
dataIndex: 'created_at',
|
||||
sortable: true,
|
||||
customRender: datetime,
|
||||
pithy: true,
|
||||
}, {
|
||||
title: () => $gettext('Action'),
|
||||
dataIndex: 'action',
|
||||
}]
|
||||
import notificationColumns from '@/views/notification/notificationColumns'
|
||||
|
||||
const { unreadCount } = storeToRefs(useUserStore())
|
||||
|
||||
|
@ -60,10 +27,11 @@ watch(unreadCount, () => {
|
|||
<StdCurd
|
||||
ref="curd"
|
||||
:title="$gettext('Notification')"
|
||||
:columns="columns"
|
||||
:columns="notificationColumns"
|
||||
:api="notification"
|
||||
disabled-modify
|
||||
disable-modify
|
||||
disable-add
|
||||
disable-trash
|
||||
>
|
||||
<template #extra>
|
||||
<APopconfirm
|
||||
|
|
58
app/src/views/notification/notificationColumns.tsx
Normal file
58
app/src/views/notification/notificationColumns.tsx
Normal file
|
@ -0,0 +1,58 @@
|
|||
import { Tag } from 'ant-design-vue'
|
||||
import type { Column } from '@/components/StdDesign/types'
|
||||
import type { customRender } from '@/components/StdDesign/StdDataDisplay/StdTableTransformer'
|
||||
import { datetime } from '@/components/StdDesign/StdDataDisplay/StdTableTransformer'
|
||||
import { NotificationTypeT } from '@/constants'
|
||||
import { detailRender } from '@/components/Notification/detailRender'
|
||||
|
||||
const columns: Column[] = [{
|
||||
title: () => $gettext('Type'),
|
||||
dataIndex: 'type',
|
||||
customRender: (args: customRender) => {
|
||||
if (args.text === NotificationTypeT.Error) {
|
||||
return <Tag color="error">
|
||||
{ $gettext('Error') }
|
||||
</Tag>
|
||||
}
|
||||
else if (args.text === NotificationTypeT.Warning) {
|
||||
return <Tag color="warning">
|
||||
{ $gettext('Warning') }
|
||||
</Tag>
|
||||
}
|
||||
else if (args.text === NotificationTypeT.Info) {
|
||||
return <Tag color="info">
|
||||
{ $gettext('Info')}
|
||||
</Tag>
|
||||
}
|
||||
else if (args.text === NotificationTypeT.Success) {
|
||||
return <Tag color="success">
|
||||
{ $gettext('Success') }
|
||||
</Tag>
|
||||
}
|
||||
},
|
||||
sortable: true,
|
||||
pithy: true,
|
||||
}, {
|
||||
title: () => $gettext('Title'),
|
||||
dataIndex: 'title',
|
||||
customRender: (args: customRender) => {
|
||||
return h('span', $gettext(args.text))
|
||||
},
|
||||
pithy: true,
|
||||
}, {
|
||||
title: () => $gettext('Details'),
|
||||
dataIndex: 'details',
|
||||
customRender: detailRender,
|
||||
pithy: true,
|
||||
}, {
|
||||
title: () => $gettext('Created at'),
|
||||
dataIndex: 'created_at',
|
||||
sortable: true,
|
||||
customRender: datetime,
|
||||
pithy: true,
|
||||
}, {
|
||||
title: () => $gettext('Action'),
|
||||
dataIndex: 'action',
|
||||
}]
|
||||
|
||||
export default columns
|
|
@ -94,7 +94,7 @@ func SyncRenameOnRemoteServer(origPath, newPath string, syncNodeIds []int) (err
|
|||
newPath, nginxConfPath)
|
||||
}
|
||||
|
||||
payload := &SyncConfigPayload{
|
||||
payload := &RenameConfigPayload{
|
||||
Filepath: origPath,
|
||||
NewFilepath: newPath,
|
||||
}
|
||||
|
@ -159,65 +159,30 @@ func (p *SyncConfigPayload) deploy(env *model.Environment, c *model.Config, payl
|
|||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
notification.Error("Sync Configuration Error", string(notificationPayloadBytes))
|
||||
notification.Error("Sync Config Error", string(notificationPayloadBytes))
|
||||
return
|
||||
}
|
||||
|
||||
notification.Success("Sync Configuration Success", string(notificationPayloadBytes))
|
||||
notification.Success("Sync Config Success", string(notificationPayloadBytes))
|
||||
|
||||
// handle rename
|
||||
if p.NewFilepath == "" || p.Filepath == p.NewFilepath {
|
||||
return
|
||||
}
|
||||
|
||||
payloadBytes, err = json.Marshal(gin.H{
|
||||
"base_path": filepath.Dir(p.Filepath),
|
||||
"old_filepath": filepath.Base(p.Filepath),
|
||||
"new_filepath": filepath.Base(p.NewFilepath),
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
payload := &RenameConfigPayload{
|
||||
Filepath: p.Filepath,
|
||||
NewFilepath: p.NewFilepath,
|
||||
}
|
||||
url, err = env.GetUrl("/api/config_rename")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
req, err = http.NewRequest(http.MethodPost, url, bytes.NewBuffer(payloadBytes))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
req.Header.Set("X-Node-Secret", env.Token)
|
||||
resp, err = client.Do(req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
respBody, err = io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
err = payload.rename(env)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
notificationPayload = &SyncNotificationPayload{
|
||||
StatusCode: resp.StatusCode,
|
||||
ConfigName: c.Name,
|
||||
EnvName: env.Name,
|
||||
RespBody: string(respBody),
|
||||
}
|
||||
|
||||
notificationPayloadBytes, err = json.Marshal(notificationPayload)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
notification.Error("Sync Rename Configuration Error", string(notificationPayloadBytes))
|
||||
return
|
||||
}
|
||||
|
||||
notification.Success("Sync Rename Configuration Success", string(notificationPayloadBytes))
|
||||
|
||||
return
|
||||
type RenameConfigPayload struct {
|
||||
Filepath string `json:"filepath"`
|
||||
NewFilepath string `json:"new_filepath"`
|
||||
}
|
||||
|
||||
type SyncRenameNotificationPayload struct {
|
||||
|
@ -228,7 +193,7 @@ type SyncRenameNotificationPayload struct {
|
|||
RespBody string `json:"resp_body"`
|
||||
}
|
||||
|
||||
func (p *SyncConfigPayload) rename(env *model.Environment) (err error) {
|
||||
func (p *RenameConfigPayload) rename(env *model.Environment) (err error) {
|
||||
// handle rename
|
||||
if p.NewFilepath == "" || p.Filepath == p.NewFilepath {
|
||||
return
|
||||
|
@ -282,11 +247,11 @@ func (p *SyncConfigPayload) rename(env *model.Environment) (err error) {
|
|||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
notification.Error("Sync Rename Configuration Error", string(notificationPayloadBytes))
|
||||
notification.Error("Rename Remote Config Error", string(notificationPayloadBytes))
|
||||
return
|
||||
}
|
||||
|
||||
notification.Success("Sync Rename Configuration Success", string(notificationPayloadBytes))
|
||||
notification.Success("Rename Remote Config Success", string(notificationPayloadBytes))
|
||||
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue