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)
|
return syncCertificateSuccess(args.text)
|
||||||
case 'Sync Certificate Error':
|
case 'Sync Certificate Error':
|
||||||
return syncCertificateError(args.text)
|
return syncCertificateError(args.text)
|
||||||
case 'Sync Rename Configuration Success':
|
case 'Rename Remote Config Success':
|
||||||
return syncRenameConfigSuccess(args.text)
|
return syncRenameConfigSuccess(args.text)
|
||||||
case 'Sync Rename Configuration Error':
|
case 'Rename Remote Config Error':
|
||||||
return syncRenameConfigError(args.text)
|
return syncRenameConfigError(args.text)
|
||||||
case 'Sync Configuration Success':
|
case 'Sync Config Success':
|
||||||
return syncConfigSuccess(args.text)
|
return syncConfigSuccess(args.text)
|
||||||
case 'Sync Configuration Error':
|
case 'Sync Config Error':
|
||||||
return syncConfigError(args.text)
|
return syncConfigError(args.text)
|
||||||
default:
|
default:
|
||||||
return args.text
|
return args.text
|
||||||
|
|
|
@ -13,7 +13,7 @@ export interface StdCurdProps<T> extends StdTableProps<T> {
|
||||||
modalMask?: boolean
|
modalMask?: boolean
|
||||||
exportExcel?: boolean
|
exportExcel?: boolean
|
||||||
importExcel?: boolean
|
importExcel?: boolean
|
||||||
|
disableTrash?: boolean
|
||||||
disableAdd?: boolean
|
disableAdd?: boolean
|
||||||
onClickAdd?: () => void
|
onClickAdd?: () => void
|
||||||
|
|
||||||
|
@ -201,7 +201,7 @@ const localOverwriteParams = reactive(props.overwriteParams ?? {})
|
||||||
@click="add"
|
@click="add"
|
||||||
>{{ $gettext('Add') }}</a>
|
>{{ $gettext('Add') }}</a>
|
||||||
<slot name="extra" />
|
<slot name="extra" />
|
||||||
<template v-if="!disableDelete">
|
<template v-if="!disableDelete && !disableTrash">
|
||||||
<a
|
<a
|
||||||
v-if="!getParams.trash"
|
v-if="!getParams.trash"
|
||||||
@click="getParams.trash = true"
|
@click="getParams.trash = true"
|
||||||
|
|
|
@ -33,6 +33,7 @@ const pageSize = computed({
|
||||||
v-model:pageSize="pageSize"
|
v-model:pageSize="pageSize"
|
||||||
:disabled="loading"
|
:disabled="loading"
|
||||||
:current="pagination.current_page"
|
:current="pagination.current_page"
|
||||||
|
show-size-changer
|
||||||
:size="size"
|
:size="size"
|
||||||
:total="pagination.total"
|
:total="pagination.total"
|
||||||
@change="change"
|
@change="change"
|
||||||
|
|
|
@ -20,7 +20,6 @@ export interface StdTableProps<T = any> {
|
||||||
title?: string
|
title?: string
|
||||||
mode?: string
|
mode?: string
|
||||||
rowKey?: string
|
rowKey?: string
|
||||||
|
|
||||||
api: Curd<T>
|
api: Curd<T>
|
||||||
columns: Column[]
|
columns: Column[]
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
|
|
@ -2,41 +2,8 @@
|
||||||
import { message } from 'ant-design-vue'
|
import { message } from 'ant-design-vue'
|
||||||
import StdCurd from '@/components/StdDesign/StdDataDisplay/StdCurd.vue'
|
import StdCurd from '@/components/StdDesign/StdDataDisplay/StdCurd.vue'
|
||||||
import notification from '@/api/notification'
|
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 { useUserStore } from '@/pinia'
|
||||||
import { detailRender } from '@/components/Notification/detailRender'
|
import notificationColumns from '@/views/notification/notificationColumns'
|
||||||
|
|
||||||
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',
|
|
||||||
}]
|
|
||||||
|
|
||||||
const { unreadCount } = storeToRefs(useUserStore())
|
const { unreadCount } = storeToRefs(useUserStore())
|
||||||
|
|
||||||
|
@ -60,10 +27,11 @@ watch(unreadCount, () => {
|
||||||
<StdCurd
|
<StdCurd
|
||||||
ref="curd"
|
ref="curd"
|
||||||
:title="$gettext('Notification')"
|
:title="$gettext('Notification')"
|
||||||
:columns="columns"
|
:columns="notificationColumns"
|
||||||
:api="notification"
|
:api="notification"
|
||||||
disabled-modify
|
disable-modify
|
||||||
disable-add
|
disable-add
|
||||||
|
disable-trash
|
||||||
>
|
>
|
||||||
<template #extra>
|
<template #extra>
|
||||||
<APopconfirm
|
<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)
|
newPath, nginxConfPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
payload := &SyncConfigPayload{
|
payload := &RenameConfigPayload{
|
||||||
Filepath: origPath,
|
Filepath: origPath,
|
||||||
NewFilepath: newPath,
|
NewFilepath: newPath,
|
||||||
}
|
}
|
||||||
|
@ -159,67 +159,32 @@ func (p *SyncConfigPayload) deploy(env *model.Environment, c *model.Config, payl
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
notification.Error("Sync Configuration Error", string(notificationPayloadBytes))
|
notification.Error("Sync Config Error", string(notificationPayloadBytes))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
notification.Success("Sync Configuration Success", string(notificationPayloadBytes))
|
notification.Success("Sync Config Success", string(notificationPayloadBytes))
|
||||||
|
|
||||||
// handle rename
|
// handle rename
|
||||||
if p.NewFilepath == "" || p.Filepath == p.NewFilepath {
|
if p.NewFilepath == "" || p.Filepath == p.NewFilepath {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadBytes, err = json.Marshal(gin.H{
|
payload := &RenameConfigPayload{
|
||||||
"base_path": filepath.Dir(p.Filepath),
|
Filepath: p.Filepath,
|
||||||
"old_filepath": filepath.Base(p.Filepath),
|
NewFilepath: p.NewFilepath,
|
||||||
"new_filepath": filepath.Base(p.NewFilepath),
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
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 {
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
notificationPayload = &SyncNotificationPayload{
|
err = payload.rename(env)
|
||||||
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RenameConfigPayload struct {
|
||||||
|
Filepath string `json:"filepath"`
|
||||||
|
NewFilepath string `json:"new_filepath"`
|
||||||
|
}
|
||||||
|
|
||||||
type SyncRenameNotificationPayload struct {
|
type SyncRenameNotificationPayload struct {
|
||||||
StatusCode int `json:"status_code"`
|
StatusCode int `json:"status_code"`
|
||||||
OrigPath string `json:"orig_path"`
|
OrigPath string `json:"orig_path"`
|
||||||
|
@ -228,7 +193,7 @@ type SyncRenameNotificationPayload struct {
|
||||||
RespBody string `json:"resp_body"`
|
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
|
// handle rename
|
||||||
if p.NewFilepath == "" || p.Filepath == p.NewFilepath {
|
if p.NewFilepath == "" || p.Filepath == p.NewFilepath {
|
||||||
return
|
return
|
||||||
|
@ -282,11 +247,11 @@ func (p *SyncConfigPayload) rename(env *model.Environment) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
notification.Error("Sync Rename Configuration Error", string(notificationPayloadBytes))
|
notification.Error("Rename Remote Config Error", string(notificationPayloadBytes))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
notification.Success("Sync Rename Configuration Success", string(notificationPayloadBytes))
|
notification.Success("Rename Remote Config Success", string(notificationPayloadBytes))
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue