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