Browse Source

bug fix for LocationEditor

fix a problem that unable to add location when locations slice is empty.
0xJacky 2 years ago
parent
commit
2d4c15e7f9
2 changed files with 25 additions and 22 deletions
  1. 15 20
      frontend/src/views/domain/ngx_conf/LocationEditor.vue
  2. 10 2
      server/pkg/nginx/type.go

+ 15 - 20
frontend/src/views/domain/ngx_conf/LocationEditor.vue

@@ -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"/>
@@ -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>
@@ -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>

+ 10 - 2
server/pkg/nginx/type.go

@@ -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),
+	}
 }