Skip to content

Commit

Permalink
bug fix for LocationEditor
Browse files Browse the repository at this point in the history
fix a problem that unable to add location when locations slice is empty.
  • Loading branch information
0xJacky committed Aug 18, 2022
1 parent 1dc5f71 commit 2d4c15e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
35 changes: 15 additions & 20 deletions frontend/src/views/domain/ngx_conf/LocationEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ function remove(index: number) {
<a-empty v-if="!locations"/>
<a-card v-for="(v,k) in locations" :key="k"
: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-item :label="$gettext('Comments')">
<a-textarea v-model:value="v.comments" :bordered="false"/>
Expand All @@ -48,19 +62,7 @@ function remove(index: number) {
<a-input addon-before="location" v-model:value="v.path"/>
</a-form-item>
<a-form-item :label="$gettext('Content')">
<div class="input-wrapper">
<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>
<code-editor v-model:content="v.content" default-height="200px" style="width: 100%;"/>
</a-form-item>
</a-form>
</a-card>
Expand Down Expand Up @@ -88,12 +90,5 @@ function remove(index: number) {
.ant-card {
margin: 10px 0;
box-shadow: unset;
.input-wrapper {
display: flex;
gap: 10px;
align-items: center;
width: 100%;
}
}
</style>
12 changes: 10 additions & 2 deletions server/pkg/nginx/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,17 @@ func (d *NgxDirective) TrimParams() {
}

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 {
return &NgxConfig{FileName: filename, commentQueue: &CommentQueue{linkedlistqueue.New()}}
return &NgxConfig{
FileName: filename,
commentQueue: &CommentQueue{linkedlistqueue.New()},
Upstreams: make([]*NgxUpstream, 0),
}
}

0 comments on commit 2d4c15e

Please sign in to comment.