Browse Source

feat: update notification template for config sync

Jacky 11 months ago
parent
commit
c9370a0562

+ 4 - 4
app/src/components/Notification/detailRender.ts

@@ -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

+ 2 - 2
app/src/components/StdDesign/StdDataDisplay/StdCurd.vue

@@ -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"

+ 1 - 0
app/src/components/StdDesign/StdDataDisplay/StdPagination.vue

@@ -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"

+ 0 - 1
app/src/components/StdDesign/StdDataDisplay/StdTable.vue

@@ -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

+ 4 - 36
app/src/views/notification/Notification.vue

@@ -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 - 0
app/src/views/notification/notificationColumns.tsx

@@ -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

+ 15 - 50
internal/config/sync.go

@@ -94,7 +94,7 @@ func SyncRenameOnRemoteServer(origPath, newPath string, syncNodeIds []int) (err
 			newPath, nginxConfPath)
 	}
 
-	payload := &SyncConfigPayload{
+	payload := &RenameConfigPayload{
 		Filepath:    origPath,
 		NewFilepath: newPath,
 	}
@@ -159,67 +159,32 @@ 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
-	}
-	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
+	payload := &RenameConfigPayload{
+		Filepath:    p.Filepath,
+		NewFilepath: p.NewFilepath,
 	}
-	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{
-		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))
+	err = payload.rename(env)
 
 	return
 }
 
+type RenameConfigPayload struct {
+	Filepath    string `json:"filepath"`
+	NewFilepath string `json:"new_filepath"`
+}
+
 type SyncRenameNotificationPayload struct {
 	StatusCode int    `json:"status_code"`
 	OrigPath   string `json:"orig_path"`
@@ -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
 }