File tree Expand file tree Collapse file tree 13 files changed +110
-34
lines changed Expand file tree Collapse file tree 13 files changed +110
-34
lines changed Original file line number Diff line number Diff line change @@ -3,9 +3,11 @@ package cluster
33import (
44 "github.com/0xJacky/Nginx-UI/api"
55 "github.com/0xJacky/Nginx-UI/internal/analytic"
6+ "github.com/0xJacky/Nginx-UI/internal/cluster"
67 "github.com/0xJacky/Nginx-UI/internal/cosy"
78 "github.com/0xJacky/Nginx-UI/model"
89 "github.com/0xJacky/Nginx-UI/query"
10+ "github.com/0xJacky/Nginx-UI/settings"
911 "github.com/gin-gonic/gin"
1012 "github.com/spf13/cast"
1113 "net/http"
@@ -75,3 +77,19 @@ func DeleteEnvironment(c *gin.Context) {
7577
7678 c .JSON (http .StatusNoContent , nil )
7779}
80+
81+ func LoadEnvironmentFromSettings (c * gin.Context ) {
82+ err := settings .ReloadCluster ()
83+ if err != nil {
84+ api .ErrHandler (c , err )
85+ return
86+ }
87+
88+ cluster .RegisterPredefinedNodes ()
89+
90+ go analytic .RestartRetrieveNodesStatus ()
91+
92+ c .JSON (http .StatusOK , gin.H {
93+ "message" : "ok" ,
94+ })
95+ }
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import "github.com/gin-gonic/gin"
55func InitRouter (r * gin.RouterGroup ) {
66 // Environment
77 r .GET ("environments" , GetEnvironmentList )
8+ r .POST ("environments/load_from_settings" , LoadEnvironmentFromSettings )
89 envGroup := r .Group ("environment" )
910 {
1011 envGroup .GET ("/:id" , GetEnvironment )
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import en_US from 'ant-design-vue/es/locale/en_US'
1010
1111import { useSettingsStore } from ' @/pinia'
1212import gettext from ' @/gettext'
13+ import loadTranslations from ' @/api/translations'
1314
1415const media = window .matchMedia (' (prefers-color-scheme: dark)' )
1516
@@ -49,6 +50,8 @@ const lang = computed(() => {
4950
5051const settings = useSettingsStore ()
5152const is_theme_dark = computed (() => settings .theme === ' dark' )
53+
54+ loadTranslations ()
5255 </script >
5356
5457<template >
Original file line number Diff line number Diff line change 1+ import http from '@/lib/http'
12import type { ModelBase } from '@/api/curd'
23import Curd from '@/api/curd'
34
@@ -14,6 +15,17 @@ export interface Node {
1415 token : string
1516 response_at ?: Date
1617}
17- const environment : Curd < Environment > = new Curd ( '/environment' )
18+
19+ class EnvironmentCurd extends Curd < Environment > {
20+ constructor ( ) {
21+ super ( '/environment' )
22+ }
23+
24+ load_from_settings ( ) {
25+ return http . post ( `${ this . plural } /load_from_settings` )
26+ }
27+ }
28+
29+ const environment : EnvironmentCurd = new EnvironmentCurd ( )
1830
1931export default environment
Original file line number Diff line number Diff line change 1+ import gettext from '@/gettext'
2+
3+ export default async function loadTranslations ( ) {
4+ const route = useRoute ( )
5+
6+ if ( gettext . current !== 'en' ) {
7+ await fetch ( `${ import . meta. env . VITE_API_ROOT } /translation/${ gettext . current } ` ) . then ( async r => {
8+ gettext . translations [ gettext . current ] = await r . json ( )
9+ } )
10+
11+ if ( route ?. meta ?. name )
12+ document . title = `${ route . meta . name ?.( ) } | Nginx UI`
13+ }
14+
15+ watch ( route , ( ) => {
16+ if ( route ?. meta ?. name )
17+ document . title = `${ route . meta . name ?.( ) } | Nginx UI`
18+ } )
19+ }
Original file line number Diff line number Diff line change 11<script setup lang="ts">
2- import { ref , watch } from ' vue'
2+ import { watch } from ' vue'
33
44import { useSettingsStore } from ' @/pinia'
5- import http from ' @/lib/http'
65import gettext from ' @/gettext'
6+ import loadTranslations from ' @/api/translations'
77
88const settings = useSettingsStore ()
99
1010const route = useRoute ()
1111
12- const current = ref (gettext .current )
12+ const current = computed ({
13+ get() {
14+ return gettext .current
15+ },
16+ set(v ) {
17+ gettext .current = v
18+ },
19+ })
1320
1421const languageAvailable = gettext .available
1522
16- async function init() {
17- if (current .value !== ' en' ) {
18- await http .get (` /translation/${current .value } ` ).then (r => {
19- gettext .translations [current .value ] = r
20- })
21-
22- document .title = ` ${route .meta .name ?.()} | Nginx UI `
23- }
24- }
25-
26- init ()
27-
2823watch (current , v => {
29- init ()
24+ loadTranslations ()
3025 settings .set_language (v )
3126 gettext .current = v
3227
3328 const name = route .meta .name as never as () => string
3429
3530 document .title = ` ${name ()} | Nginx UI `
3631})
37-
3832 </script >
3933
4034<template >
Original file line number Diff line number Diff line change 11<script setup lang="tsx">
22import { h } from ' vue'
3- import { Badge , Tag } from ' ant-design-vue'
3+ import { Badge , Tag , message } from ' ant-design-vue'
44import type { customRender } from ' @/components/StdDesign/StdDataDisplay/StdTableTransformer'
55import { datetime } from ' @/components/StdDesign/StdDataDisplay/StdTableTransformer'
66import environment from ' @/api/environment'
@@ -130,14 +130,28 @@ const columns: Column[] = [{
130130 dataIndex: ' action' ,
131131}]
132132
133+ const curd = ref ()
134+ function load_from_settings() {
135+ environment .load_from_settings ().then (() => {
136+ curd .value .get_list ()
137+ message .success ($gettext (' Load successfully' ))
138+ }).catch (e => {
139+ message .error (` ${$gettext (' Server error' )} ${e ?.message } ` )
140+ })
141+ }
133142 </script >
134143
135144<template >
136145 <StdCurd
146+ ref =" curd"
137147 :title =" $gettext('Environment')"
138148 :api =" environment"
139149 :columns =" columns"
140- />
150+ >
151+ <template #extra >
152+ <a @click =" load_from_settings" >{{ $gettext('Load from settings') }}</a >
153+ </template >
154+ </StdCurd >
141155</template >
142156
143157<style lang="less" scoped>
Original file line number Diff line number Diff line change @@ -5,8 +5,6 @@ const route = useRoute()
55const info = computed (() => {
66 if (typeof route .meta .error === ' function' )
77 return route .meta .error ()
8- else if (typeof route .meta .error === ' string' )
9- return route .meta .error
108 else
119 return $gettext (' File Not Found' )
1210})
Original file line number Diff line number Diff line change 1- package kernal
1+ package cluster
22
33import (
44 "github.com/0xJacky/Nginx-UI/internal/logger"
@@ -10,7 +10,7 @@ import (
1010 "strings"
1111)
1212
13- func registerPredefinedClusterNodes () {
13+ func RegisterPredefinedNodes () {
1414 if len (settings .ClusterSettings .Node ) == 0 {
1515 return
1616 }
Original file line number Diff line number Diff line change 1- package kernal
1+ package cluster
22
33import (
44 "github.com/0xJacky/Nginx-UI/settings"
You can’t perform that action at this time.
0 commit comments