Skip to content

Commit c9c83c9

Browse files
committed
feat: added restart nginx btn
1 parent d6b68b8 commit c9c83c9

File tree

14 files changed

+210
-50
lines changed

14 files changed

+210
-50
lines changed

frontend/components.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export {}
88
declare module '@vue/runtime-core' {
99
export interface GlobalComponents {
1010
AAlert: typeof import('ant-design-vue/es')['Alert']
11+
ABadge: typeof import('ant-design-vue/es')['Badge']
1112
ABreadcrumb: typeof import('ant-design-vue/es')['Breadcrumb']
1213
ABreadcrumbItem: typeof import('ant-design-vue/es')['BreadcrumbItem']
1314
AButton: typeof import('ant-design-vue/es')['Button']
@@ -37,6 +38,7 @@ declare module '@vue/runtime-core' {
3738
AModal: typeof import('ant-design-vue/es')['Modal']
3839
APagination: typeof import('ant-design-vue/es')['Pagination']
3940
APopconfirm: typeof import('ant-design-vue/es')['Popconfirm']
41+
APopover: typeof import('ant-design-vue/es')['Popover']
4042
AProgress: typeof import('ant-design-vue/es')['Progress']
4143
AResult: typeof import('ant-design-vue/es')['Result']
4244
ARow: typeof import('ant-design-vue/es')['Row']
@@ -59,6 +61,7 @@ declare module '@vue/runtime-core' {
5961
CodeEditorCodeEditor: typeof import('./src/components/CodeEditor/CodeEditor.vue')['default']
6062
FooterToolbarFooterToolBar: typeof import('./src/components/FooterToolbar/FooterToolBar.vue')['default']
6163
LogoLogo: typeof import('./src/components/Logo/Logo.vue')['default']
64+
NginxControlNginxControl: typeof import('./src/components/NginxControl/NginxControl.vue')['default']
6265
PageHeaderPageHeader: typeof import('./src/components/PageHeader/PageHeader.vue')['default']
6366
RouterLink: typeof import('vue-router')['RouterLink']
6467
RouterView: typeof import('vue-router')['RouterView']

frontend/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
"vue3-apexcharts": "^1.4.1",
3333
"vue3-gettext": "^2.3.4",
3434
"vuedraggable": "^4.1.0",
35-
"xterm": "^5.0.0",
36-
"xterm-addon-attach": "^0.7.0",
37-
"xterm-addon-fit": "^0.6.0"
35+
"xterm": "^5.1.0",
36+
"xterm-addon-attach": "^0.8.0",
37+
"xterm-addon-fit": "^0.7.0"
3838
},
3939
"devDependencies": {
4040
"@vitejs/plugin-vue": "^4.0.0",

frontend/src/api/ngx.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,18 @@ const ngx = {
1313
return http.post('/ngx/format_code', {content})
1414
},
1515

16+
status() {
17+
return http.get('/nginx/status')
18+
},
19+
1620
reload() {
1721
return http.post('/nginx/reload')
1822
},
1923

24+
restart() {
25+
return http.post('/nginx/restart')
26+
},
27+
2028
test() {
2129
return http.post('/nginx/test')
2230
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<script setup lang="ts">
2+
import gettext from '@/gettext'
3+
4+
const {$gettext} = gettext
5+
import ngx from '@/api/ngx'
6+
import logLevel from '@/views/config/constants'
7+
import {message} from 'ant-design-vue'
8+
import {ReloadOutlined} from '@ant-design/icons-vue'
9+
import Template from '@/views/template/Template.vue'
10+
import {ref, watch} from 'vue'
11+
12+
function get_status() {
13+
ngx.status().then(r => {
14+
if (r?.running === true) {
15+
status.value = 0
16+
} else {
17+
status.value = -1
18+
}
19+
})
20+
}
21+
22+
function reload_nginx() {
23+
status.value = 1
24+
ngx.reload().then(r => {
25+
if (r.level < logLevel.Warn) {
26+
message.success($gettext('Nginx reloaded successfully'))
27+
} else if (r.level === logLevel.Warn) {
28+
message.warn(r.message)
29+
} else {
30+
message.error(r.message)
31+
}
32+
}).catch(e => {
33+
message.error($gettext('Server error') + ' ' + e?.message)
34+
}).finally(() => {
35+
status.value = 0
36+
})
37+
}
38+
39+
function restart_nginx() {
40+
status.value = 2
41+
ngx.restart().then(r => {
42+
if (r.level < logLevel.Warn) {
43+
message.success($gettext('Nginx restarted successfully'))
44+
} else if (r.level === logLevel.Warn) {
45+
message.warn(r.message)
46+
} else {
47+
message.error(r.message)
48+
}
49+
}).catch(e => {
50+
message.error($gettext('Server error') + ' ' + e?.message)
51+
}).finally(() => {
52+
status.value = 0
53+
})
54+
}
55+
56+
const status = ref(0)
57+
58+
const visible = ref(false)
59+
60+
watch(visible, (v) => {
61+
if (v) get_status()
62+
})
63+
</script>
64+
65+
<template>
66+
<a-popover
67+
v-model:visible="visible"
68+
@confirm="reload_nginx"
69+
placement="bottomRight"
70+
>
71+
<template #content>
72+
<div class="content-wrapper">
73+
<h4>{{ $gettext('Nginx Control') }}</h4>
74+
<a-badge v-if="status===0" color="green" :text="$gettext('Running')"/>
75+
<a-badge v-else-if="status===1" color="blue" :text="$gettext('Reloading')"/>
76+
<a-badge v-else-if="status===2" color="orange" :text="$gettext('Restarting')"/>
77+
<a-badge v-else color="red" :text="$gettext('Stopped')"/>
78+
</div>
79+
<a-space>
80+
<a-button size="small" @click="restart_nginx" type="link">{{ $gettext('Restart') }}</a-button>
81+
<a-button size="small" @click="reload_nginx" type="link">{{ $gettext('Reload') }}</a-button>
82+
</a-space>
83+
</template>
84+
<a>
85+
<ReloadOutlined/>
86+
</a>
87+
</a-popover>
88+
</template>
89+
90+
<style lang="less" scoped>
91+
a {
92+
color: #000000;
93+
}
94+
95+
.dark {
96+
a {
97+
color: #fafafa;
98+
}
99+
}
100+
101+
.content-wrapper {
102+
text-align: center;
103+
padding-top: 5px;
104+
padding-bottom: 5px;
105+
106+
h4 {
107+
margin-bottom: 5px;
108+
}
109+
}
110+
</style>

frontend/src/layouts/HeaderLayout.vue

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ import SetLanguage from '@/components/SetLanguage/SetLanguage.vue'
33
import gettext from '@/gettext'
44
import {message} from 'ant-design-vue'
55
import auth from '@/api/auth'
6-
import {HomeOutlined, LogoutOutlined, MenuUnfoldOutlined, ReloadOutlined} from '@ant-design/icons-vue'
6+
import {HomeOutlined, LogoutOutlined, MenuUnfoldOutlined} from '@ant-design/icons-vue'
77
import {useRouter} from 'vue-router'
8-
import ngx from '@/api/ngx'
9-
import logLevel from '@/views/config/constants'
8+
import NginxControl from '@/components/NginxControl/NginxControl.vue'
109
1110
const {$gettext} = gettext
1211
@@ -19,20 +18,6 @@ function logout() {
1918
router.push('/login')
2019
})
2120
}
22-
23-
function reload_nginx() {
24-
ngx.reload().then(r => {
25-
if (r.level < logLevel.Warn) {
26-
message.success($gettext('Nginx reloaded successfully'))
27-
} else if (r.level === logLevel.Warn) {
28-
message.warn(r.message)
29-
} else {
30-
message.error(r.message)
31-
}
32-
}).catch(e => {
33-
message.error($gettext('Server error') + ' ' + e?.message)
34-
})
35-
}
3621
</script>
3722

3823
<template>
@@ -48,17 +33,7 @@ function reload_nginx() {
4833
<HomeOutlined/>
4934
</a>
5035

51-
<a-popconfirm
52-
:title="$gettext('Do you want to reload Nginx?')"
53-
:ok-text="$gettext('Yes')"
54-
:cancel-text="$gettext('No')"
55-
@confirm="reload_nginx"
56-
placement="bottomRight"
57-
>
58-
<a>
59-
<ReloadOutlined/>
60-
</a>
61-
</a-popconfirm>
36+
<NginxControl/>
6237

6338
<a @click="logout">
6439
<LogoutOutlined/>

frontend/src/lib/http/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import axios, {AxiosRequestConfig} from 'axios'
22
import {useUserStore} from '@/pinia'
33
import {storeToRefs} from 'pinia'
4+
import NProgress from 'nprogress'
5+
import 'nprogress/nprogress.css'
46

57
import router from '@/routes'
68

@@ -25,6 +27,7 @@ let instance = axios.create({
2527

2628
instance.interceptors.request.use(
2729
config => {
30+
NProgress.start()
2831
if (token) {
2932
(config.headers as any).Authorization = token.value
3033
}
@@ -37,9 +40,11 @@ instance.interceptors.request.use(
3740

3841
instance.interceptors.response.use(
3942
response => {
43+
NProgress.done()
4044
return Promise.resolve(response.data)
4145
},
4246
async error => {
47+
NProgress.done()
4348
switch (error.response.status) {
4449
case 401:
4550
case 403:

frontend/src/version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":"1.7.5","build_id":77,"total_build":147}
1+
{"version":"1.7.5","build_id":81,"total_build":151}

frontend/src/views/pty/Terminal.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,13 @@ const fit = _.throttle(function () {
3535
3636
function initTerm() {
3737
term = new Terminal({
38-
rendererType: 'canvas',
3938
convertEol: true,
4039
fontSize: 14,
4140
cursorStyle: 'block',
4241
scrollback: 1000,
4342
theme: {
44-
background: '#000',
45-
},
43+
background: '#000'
44+
}
4645
})
4746
4847
term.loadAddon(fitAddon)

frontend/version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":"1.7.5","build_id":77,"total_build":147}
1+
{"version":"1.7.5","build_id":81,"total_build":151}

frontend/yarn.lock

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3019,20 +3019,20 @@ wrappy@1:
30193019
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
30203020
integrity sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==
30213021

3022-
xterm-addon-attach@^0.7.0:
3022+
xterm-addon-attach@^0.8.0:
3023+
version "0.8.0"
3024+
resolved "https://registry.yarnpkg.com/xterm-addon-attach/-/xterm-addon-attach-0.8.0.tgz#86e0ed08460efffb7d4bad74a57b600226594def"
3025+
integrity sha512-k8N5boSYn6rMJTTNCgFpiSTZ26qnYJf3v/nJJYexNO2sdAHDN3m1ivVQWVZ8CHJKKnZQw1rc44YP2NtgalWHfQ==
3026+
3027+
xterm-addon-fit@^0.7.0:
30233028
version "0.7.0"
3024-
resolved "https://registry.yarnpkg.com/xterm-addon-attach/-/xterm-addon-attach-0.7.0.tgz#6775b3c5f1e9f91ae4cd9089f5ecb49fda8d2946"
3025-
integrity sha512-Yh3Kvq2e28onjnmGizQKZwlRMp9gmuZEHVX0BVZbo463YSjkqfhQS3T2wMLuO+j8AokccXsMa1z0bH1/+MMYuQ==
3026-
3027-
xterm-addon-fit@^0.6.0:
3028-
version "0.6.0"
3029-
resolved "https://registry.yarnpkg.com/xterm-addon-fit/-/xterm-addon-fit-0.6.0.tgz#142e1ce181da48763668332593fc440349c88c34"
3030-
integrity sha512-9/7A+1KEjkFam0yxTaHfuk9LEvvTSBi0PZmEkzJqgafXPEXL9pCMAVV7rB09sX6ATRDXAdBpQhZkhKj7CGvYeg==
3031-
3032-
xterm@^5.0.0:
3033-
version "5.0.0"
3034-
resolved "https://registry.yarnpkg.com/xterm/-/xterm-5.0.0.tgz#0af50509b33d0dc62fde7a4ec17750b8e453cc5c"
3035-
integrity sha512-tmVsKzZovAYNDIaUinfz+VDclraQpPUnAME+JawosgWRMphInDded/PuY0xmU5dOhyeYZsI0nz5yd8dPYsdLTA==
3029+
resolved "https://registry.yarnpkg.com/xterm-addon-fit/-/xterm-addon-fit-0.7.0.tgz#b8ade6d96e63b47443862088f6670b49fb752c6a"
3030+
integrity sha512-tQgHGoHqRTgeROPnvmtEJywLKoC/V9eNs4bLLz7iyJr1aW/QFzRwfd3MGiJ6odJd9xEfxcW36/xRU47JkD5NKQ==
3031+
3032+
xterm@^5.1.0:
3033+
version "5.1.0"
3034+
resolved "https://registry.yarnpkg.com/xterm/-/xterm-5.1.0.tgz#3e160d60e6801c864b55adf19171c49d2ff2b4fc"
3035+
integrity sha512-LovENH4WDzpwynj+OTkLyZgJPeDom9Gra4DMlGAgz6pZhIDCQ+YuO7yfwanY+gVbn/mmZIStNOnVRU/ikQuAEQ==
30363036

30373037
yallist@^3.0.2:
30383038
version "3.1.1"

0 commit comments

Comments
 (0)