-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support for include location in server {} block #48
- Loading branch information
Showing
3 changed files
with
129 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
frontend/src/views/domain/ngx_conf/directive/DirectiveEditorItem.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<script setup lang="ts"> | ||
import CodeEditor from '@/components/CodeEditor' | ||
import {DeleteOutlined, HolderOutlined} from '@ant-design/icons-vue' | ||
import {If} from '@/views/domain/ngx_conf' | ||
import {useGettext} from 'vue3-gettext' | ||
import {onMounted, ref, watch} from 'vue' | ||
import config from '@/api/config' | ||
import {message} from 'ant-design-vue' | ||
const {$gettext, interpolate} = useGettext() | ||
const props = defineProps(['directive', 'current_idx', 'index', 'ngx_directives']) | ||
function remove(index: number) { | ||
props.ngx_directives.splice(index, 1) | ||
} | ||
const content = ref('') | ||
function init() { | ||
if (props.directive.directive === 'include') | ||
config.get(props.directive.params).then(r => { | ||
content.value = r.config | ||
}) | ||
} | ||
onMounted(init) | ||
watch(props, init) | ||
function save() { | ||
config.save(props.directive.params, {content: content.value}).then(r => { | ||
content.value = r.config | ||
message.success($gettext('Saved successfully')) | ||
}).catch(r => { | ||
message.error(interpolate($gettext('Save error %{msg}'), {msg: r.message ?? ''})) | ||
}) | ||
} | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<div class="input-wrapper"> | ||
<code-editor v-if="directive.directive === If" v-model:content="directive.params" | ||
defaultHeight="100px" style="width: 100%;"/> | ||
|
||
<a-input v-else | ||
v-model:value="directive.params" @click="current_idx=index"> | ||
<template #addonBefore> | ||
<HolderOutlined/> | ||
{{ directive.directive }} | ||
</template> | ||
</a-input> | ||
|
||
<a-popconfirm @confirm="remove(index)" | ||
:title="$gettext('Are you sure you want to remove this directive?')" | ||
:ok-text="$gettext('Yes')" | ||
:cancel-text="$gettext('No')"> | ||
<a-button> | ||
<template #icon> | ||
<DeleteOutlined style="font-size: 14px;"/> | ||
</template> | ||
</a-button> | ||
</a-popconfirm> | ||
</div> | ||
<transition name="slide"> | ||
<div v-if="current_idx===index" class="directive-editor-extra"> | ||
<div class="extra-content"> | ||
<a-form layout="vertical"> | ||
<a-form-item :label="$gettext('Comments')"> | ||
<a-textarea v-model:value="directive.comments"/> | ||
</a-form-item> | ||
<a-form-item :label="$gettext('Include Content')" v-if="directive.directive==='include'"> | ||
<code-editor v-model:content="content" | ||
defaultHeight="200px" style="width: 100%;"/> | ||
<div class="save-btn"> | ||
<a-button @click="save">{{ $gettext('Save') }}</a-button> | ||
</div> | ||
</a-form-item> | ||
</a-form> | ||
</div> | ||
</div> | ||
</transition> | ||
</div> | ||
|
||
</template> | ||
|
||
<style lang="less" scoped> | ||
.directive-editor-extra { | ||
background-color: #fafafa; | ||
padding: 10px 20px; | ||
margin-bottom: 10px; | ||
.save-btn { | ||
display: flex; | ||
justify-content: flex-end; | ||
margin-top: 15px; | ||
} | ||
} | ||
.slide-enter-active, .slide-leave-active { | ||
transition: max-height .2s ease; | ||
overflow: hidden; | ||
} | ||
.slide-enter-from, .slide-leave-to { | ||
max-height: 0; | ||
} | ||
.slide-enter-to, .slide-leave-from { | ||
max-height: 600px; | ||
} | ||
.input-wrapper { | ||
display: flex; | ||
gap: 10px; | ||
align-items: center; | ||
margin: 15px 0; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters