bug fix for LocationEditor

fix a problem that unable to add location when locations slice is empty.
This commit is contained in:
0xJacky 2022-08-18 17:10:49 +08:00
parent 1dc5f71688
commit 2d4c15e7f9
No known key found for this signature in database
GPG key ID: B6E4A6E4A561BAF0
2 changed files with 25 additions and 22 deletions

View file

@ -40,6 +40,20 @@ function remove(index: number) {
<a-empty v-if="!locations"/> <a-empty v-if="!locations"/>
<a-card v-for="(v,k) in locations" :key="k" <a-card v-for="(v,k) in locations" :key="k"
:title="$gettext('Location')" size="small"> :title="$gettext('Location')" size="small">
<template #extra>
<a-popconfirm @confirm="remove(k)"
:title="$gettext('Are you sure you want to remove this location?')"
:ok-text="$gettext('Yes')"
:cancel-text="$gettext('No')">
<a-button type="text">
<template #icon>
<DeleteOutlined style="font-size: 14px;"/>
</template>
</a-button>
</a-popconfirm>
</template>
<a-form layout="vertical"> <a-form layout="vertical">
<a-form-item :label="$gettext('Comments')"> <a-form-item :label="$gettext('Comments')">
<a-textarea v-model:value="v.comments" :bordered="false"/> <a-textarea v-model:value="v.comments" :bordered="false"/>
@ -48,19 +62,7 @@ function remove(index: number) {
<a-input addon-before="location" v-model:value="v.path"/> <a-input addon-before="location" v-model:value="v.path"/>
</a-form-item> </a-form-item>
<a-form-item :label="$gettext('Content')"> <a-form-item :label="$gettext('Content')">
<div class="input-wrapper"> <code-editor v-model:content="v.content" default-height="200px" style="width: 100%;"/>
<code-editor v-model:content="v.content" default-height="200px" style="width: 100%;"/>
<a-popconfirm @confirm="remove(k)"
:title="$gettext('Are you sure you want to remove this location?')"
:ok-text="$gettext('Yes')"
:cancel-text="$gettext('No')">
<a-button>
<template #icon>
<DeleteOutlined style="font-size: 14px;"/>
</template>
</a-button>
</a-popconfirm>
</div>
</a-form-item> </a-form-item>
</a-form> </a-form>
</a-card> </a-card>
@ -88,12 +90,5 @@ function remove(index: number) {
.ant-card { .ant-card {
margin: 10px 0; margin: 10px 0;
box-shadow: unset; box-shadow: unset;
.input-wrapper {
display: flex;
gap: 10px;
align-items: center;
width: 100%;
}
} }
</style> </style>

View file

@ -64,9 +64,17 @@ func (d *NgxDirective) TrimParams() {
} }
func NewNgxServer() *NgxServer { func NewNgxServer() *NgxServer {
return &NgxServer{commentQueue: &CommentQueue{linkedlistqueue.New()}} return &NgxServer{
Locations: make([]*NgxLocation, 0),
Directives: make([]*NgxDirective, 0),
commentQueue: &CommentQueue{linkedlistqueue.New()},
}
} }
func NewNgxConfig(filename string) *NgxConfig { func NewNgxConfig(filename string) *NgxConfig {
return &NgxConfig{FileName: filename, commentQueue: &CommentQueue{linkedlistqueue.New()}} return &NgxConfig{
FileName: filename,
commentQueue: &CommentQueue{linkedlistqueue.New()},
Upstreams: make([]*NgxUpstream, 0),
}
} }