|
| 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> |
0 commit comments