Skip to content

Commit 2d4c15e

Browse files
committed
bug fix for LocationEditor
fix a problem that unable to add location when locations slice is empty.
1 parent 1dc5f71 commit 2d4c15e

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

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

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,20 @@ function remove(index: number) {
4040
<a-empty v-if="!locations"/>
4141
<a-card v-for="(v,k) in locations" :key="k"
4242
:title="$gettext('Location')" size="small">
43+
44+
<template #extra>
45+
<a-popconfirm @confirm="remove(k)"
46+
:title="$gettext('Are you sure you want to remove this location?')"
47+
:ok-text="$gettext('Yes')"
48+
:cancel-text="$gettext('No')">
49+
<a-button type="text">
50+
<template #icon>
51+
<DeleteOutlined style="font-size: 14px;"/>
52+
</template>
53+
</a-button>
54+
</a-popconfirm>
55+
</template>
56+
4357
<a-form layout="vertical">
4458
<a-form-item :label="$gettext('Comments')">
4559
<a-textarea v-model:value="v.comments" :bordered="false"/>
@@ -48,19 +62,7 @@ function remove(index: number) {
4862
<a-input addon-before="location" v-model:value="v.path"/>
4963
</a-form-item>
5064
<a-form-item :label="$gettext('Content')">
51-
<div class="input-wrapper">
52-
<code-editor v-model:content="v.content" default-height="200px" style="width: 100%;"/>
53-
<a-popconfirm @confirm="remove(k)"
54-
:title="$gettext('Are you sure you want to remove this location?')"
55-
:ok-text="$gettext('Yes')"
56-
:cancel-text="$gettext('No')">
57-
<a-button>
58-
<template #icon>
59-
<DeleteOutlined style="font-size: 14px;"/>
60-
</template>
61-
</a-button>
62-
</a-popconfirm>
63-
</div>
65+
<code-editor v-model:content="v.content" default-height="200px" style="width: 100%;"/>
6466
</a-form-item>
6567
</a-form>
6668
</a-card>
@@ -88,12 +90,5 @@ function remove(index: number) {
8890
.ant-card {
8991
margin: 10px 0;
9092
box-shadow: unset;
91-
92-
.input-wrapper {
93-
display: flex;
94-
gap: 10px;
95-
align-items: center;
96-
width: 100%;
97-
}
9893
}
9994
</style>

server/pkg/nginx/type.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,17 @@ func (d *NgxDirective) TrimParams() {
6464
}
6565

6666
func NewNgxServer() *NgxServer {
67-
return &NgxServer{commentQueue: &CommentQueue{linkedlistqueue.New()}}
67+
return &NgxServer{
68+
Locations: make([]*NgxLocation, 0),
69+
Directives: make([]*NgxDirective, 0),
70+
commentQueue: &CommentQueue{linkedlistqueue.New()},
71+
}
6872
}
6973

7074
func NewNgxConfig(filename string) *NgxConfig {
71-
return &NgxConfig{FileName: filename, commentQueue: &CommentQueue{linkedlistqueue.New()}}
75+
return &NgxConfig{
76+
FileName: filename,
77+
commentQueue: &CommentQueue{linkedlistqueue.New()},
78+
Upstreams: make([]*NgxUpstream, 0),
79+
}
7280
}

0 commit comments

Comments
 (0)