Skip to content

Commit f5a2a63

Browse files
committed
feat: config templates #53, #34, #33
1 parent 594c61a commit f5a2a63

File tree

21 files changed

+416
-92
lines changed

21 files changed

+416
-92
lines changed

.air.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ bin = "tmp/main"
1313
# Customize binary.
1414
full_bin = "APP_ENV=dev APP_USER=air ./tmp/main"
1515
# Watch these filename extensions.
16-
include_ext = ["go", "tpl", "tmpl", "html"]
16+
include_ext = ["go", "tpl", "tmpl", "html", "conf"]
1717
# Ignore these filename extensions or directories.
1818
exclude_dir = ["assets", "tmp", "vendor", "frontend/node_modules", "upload"]
1919
# Watch these directories if you specified.

frontend/components.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ declare module '@vue/runtime-core' {
2828
ALayoutFooter: typeof import('ant-design-vue/es')['LayoutFooter']
2929
ALayoutHeader: typeof import('ant-design-vue/es')['LayoutHeader']
3030
ALayoutSider: typeof import('ant-design-vue/es')['LayoutSider']
31+
AList: typeof import('ant-design-vue/es')['List']
32+
AListItem: typeof import('ant-design-vue/es')['ListItem']
3133
AMenu: typeof import('ant-design-vue/es')['Menu']
3234
AMenuItem: typeof import('ant-design-vue/es')['MenuItem']
3335
AModal: typeof import('ant-design-vue/es')['Modal']

frontend/src/api/template.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import Curd from '@/api/curd'
2+
import http from '@/lib/http'
3+
4+
class Template extends Curd {
5+
get_config_list() {
6+
return http.get('template/configs')
7+
}
8+
9+
get_block_list() {
10+
return http.get('template/blocks')
11+
}
12+
13+
get_config(name: string) {
14+
return http.get('template/config/' + name)
15+
}
16+
17+
get_block(name: string) {
18+
return http.get('template/block/' + name)
19+
}
20+
21+
}
22+
23+
const template = new Template('/template')
24+
25+
export default template

frontend/src/components/SetLanguage/SetLanguage.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<script setup lang="ts">
22
import gettext from '@/gettext'
33
4-
54
import {ref, watch} from 'vue'
65
76
import {useSettingsStore} from '@/pinia'

frontend/src/layouts/BaseLayout.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const lang = computed(() => {
3939
4040
</script>
4141
<template>
42-
<a-config-provider :locale="lang">
42+
<a-config-provider :locale="lang" :autoInsertSpaceInButton="false">
4343
<a-layout style="min-height: 100%;">
4444
<div class="drawer-sidebar">
4545
<a-drawer

frontend/src/views/domain/DomainAdd.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import ngx from '@/api/ngx'
88
import {computed, reactive, ref} from 'vue'
99
import {message} from 'ant-design-vue'
1010
import {useRouter} from 'vue-router'
11+
import template from '@/api/template'
1112
1213
const {$gettext, interpolate} = useGettext()
1314
@@ -39,7 +40,7 @@ function init() {
3940
4041
function save() {
4142
ngx.build_config(ngx_config).then(r => {
42-
domain.save(config.name, {content: r.content, enabled: true}).then(() => {
43+
domain.save(config.name, {name: config.name, content: r.content, enabled: true}).then(() => {
4344
message.success($gettext('Saved successfully'))
4445
4546
domain.enable(config.name).then(() => {
@@ -89,15 +90,13 @@ const has_server_name = computed(() => {
8990
<a-step :title="$gettext('Configure SSL')"/>
9091
<a-step :title="$gettext('Finished')"/>
9192
</a-steps>
92-
9393
<template v-if="current_step===0">
9494
<a-form layout="vertical">
9595
<a-form-item :label="$gettext('Configuration Name')">
9696
<a-input v-model:value="config.name"/>
9797
</a-form-item>
9898
</a-form>
9999

100-
101100
<directive-editor :ngx_directives="ngx_config.servers[0].directives"/>
102101
<br/>
103102
<location-editor :locations="ngx_config.servers[0].locations"/>

frontend/src/views/domain/cert/IssueCert.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ const modalClosable = ref(false)
166166
<a-modal
167167
:title="$gettext('Obtaining certificate')"
168168
v-model:visible="modalVisible"
169+
:mask-closable="modalClosable"
169170
:footer="null" :closable="modalClosable" force-render>
170171
<a-progress
171172
:stroke-color="progressStrokeColor"
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<script setup lang="ts">
2+
import {useGettext} from 'vue3-gettext'
3+
import template from '@/api/template'
4+
import {computed, ref} from 'vue'
5+
import {storeToRefs} from 'pinia'
6+
import {useSettingsStore} from '@/pinia'
7+
import Template from '@/views/template/Template.vue'
8+
import DirectiveEditor from '@/views/domain/ngx_conf/directive/DirectiveEditor.vue'
9+
import LocationEditor from '@/views/domain/ngx_conf/LocationEditor.vue'
10+
import CodeEditor from '@/components/CodeEditor/CodeEditor.vue'
11+
12+
const {$gettext} = useGettext()
13+
const {language} = storeToRefs(useSettingsStore())
14+
const props = defineProps(['ngx_config', 'current_server_index'])
15+
16+
const blocks = ref([])
17+
const data: any = ref({})
18+
const visible = ref(false)
19+
20+
function get_block_list() {
21+
template.get_block_list().then(r => {
22+
blocks.value = r.data
23+
})
24+
}
25+
26+
get_block_list()
27+
28+
function view(name: string) {
29+
visible.value = true
30+
template.get_block(name).then(r => {
31+
data.value = r
32+
})
33+
}
34+
35+
const trans_description = computed(() => {
36+
return (item: any) => item.description?.[language.value] ?? item.description?.en ?? ''
37+
})
38+
39+
async function add() {
40+
41+
if (data.value.custom) {
42+
props.ngx_config.custom += '\n' + data.value.custom
43+
}
44+
45+
props.ngx_config.custom = props.ngx_config.custom.trim()
46+
47+
if (data.value.locations) {
48+
props.ngx_config.servers[props.current_server_index].locations.push(...data.value.locations)
49+
}
50+
51+
if (data.value.directives) {
52+
props.ngx_config.servers[props.current_server_index].directives.push(...data.value.directives)
53+
}
54+
55+
visible.value = false
56+
}
57+
</script>
58+
59+
<template>
60+
<div>
61+
<h2 v-translate>Config Templates</h2>
62+
<div class="config-list-wrapper">
63+
<a-list
64+
:grid="{ gutter: 16, xs: 1, sm: 2, md: 2, lg: 2, xl: 2, xxl: 2, xxxl: 2 }"
65+
:data-source="blocks"
66+
>
67+
<template #renderItem="{ item }">
68+
<a-list-item>
69+
<a-card size="small" :title="item.name">
70+
<template #extra>
71+
<a-button type="link" @click="view(item.filename)">View</a-button>
72+
</template>
73+
<p>{{ $gettext('Author') }}: {{ item.author }}</p>
74+
<p>{{ $gettext('Description') }}: {{ trans_description(item) }}</p>
75+
</a-card>
76+
</a-list-item>
77+
</template>
78+
</a-list>
79+
</div>
80+
<a-modal
81+
:title="data.name"
82+
v-model:visible="visible"
83+
:mask="false"
84+
:ok-text="$gettext('Add')"
85+
@ok="add"
86+
>
87+
<p>{{ $gettext('Author') }}: {{ data.author }}</p>
88+
<p>{{ $gettext('Description') }}: {{ trans_description(data) }}</p>
89+
<template v-if="data.custom">
90+
<h2>{{ $gettext('Custom') }}</h2>
91+
<code-editor v-model:content="data.custom" default-height="150px"/>
92+
</template>
93+
<directive-editor v-if="data.directives" :ngx_directives="data.directives" :readonly="true"/>
94+
<br/>
95+
<location-editor v-if="data.locations" :locations="data.locations" :readonly="true"/>
96+
</a-modal>
97+
</div>
98+
</template>
99+
100+
<style lang="less" scoped>
101+
.config-list-wrapper {
102+
max-height: 200px;
103+
overflow-y: scroll;
104+
overflow-x: hidden;
105+
}
106+
</style>

frontend/src/views/domain/ngx_conf/LocationEditor.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import draggable from 'vuedraggable'
77
88
const {$gettext} = useGettext()
99
10-
const props = defineProps(['locations'])
10+
const props = defineProps(['locations', 'readonly'])
1111
1212
let location = reactive({
1313
comments: '',
@@ -52,7 +52,7 @@ function remove(index: number) {
5252
<HolderOutlined/>
5353
{{ $gettext('Location') }}
5454
</template>
55-
<template #extra>
55+
<template #extra v-if="!readonly">
5656
<a-popconfirm @confirm="remove(index)"
5757
:title="$gettext('Are you sure you want to remove this location?')"
5858
:ok-text="$gettext('Yes')"
@@ -94,7 +94,7 @@ function remove(index: number) {
9494
</a-form>
9595
</a-modal>
9696

97-
<div>
97+
<div v-if="!readonly">
9898
<a-button block @click="add">{{ $gettext('Add Location') }}</a-button>
9999
</div>
100100
</template>

frontend/src/views/domain/ngx_conf/NgxConfigEditor.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {useRoute, useRouter} from 'vue-router'
66
import {useGettext} from 'vue3-gettext'
77
import Cert from '@/views/domain/cert/Cert.vue'
88
import LogEntry from '@/views/domain/ngx_conf/LogEntry.vue'
9+
import ConfigTemplate from '@/views/domain/ngx_conf/ConfigTemplate.vue'
10+
import CodeEditor from '@/components/CodeEditor/CodeEditor.vue'
911
1012
const {$gettext} = useGettext()
1113
@@ -151,6 +153,9 @@ watch(current_server_index, () => {
151153
<a-switch @change="change_tls"/>
152154
</a-form-item>
153155

156+
<h2>{{ $gettext('Custom') }}</h2>
157+
<code-editor v-model:content="ngx_config.custom" default-height="150px"/>
158+
154159
<a-tabs v-model:activeKey="current_server_index">
155160
<a-tab-pane :tab="'Server '+(k+1)" v-for="(v,k) in props.ngx_config.servers" :key="k">
156161
<log-entry
@@ -175,9 +180,11 @@ watch(current_server_index, () => {
175180
<h3 v-translate>Comments</h3>
176181
<a-textarea v-model:value="v.comments" :bordered="false"/>
177182
</template>
178-
179183
<directive-editor :ngx_directives="v.directives"/>
180184
<br/>
185+
<config-template :ngx_config="ngx_config"
186+
:current_server_index="current_server_index"/>
187+
<br/>
181188
<location-editor :locations="v.locations"/>
182189
</div>
183190

0 commit comments

Comments
 (0)