RoutingRule.vue 11.3 KB
Newer Older
M
min 已提交
1 2 3 4 5 6
<!--
  - Licensed to the Apache Software Foundation (ASF) under one or more
  - contributor license agreements.  See the NOTICE file distributed with
  - this work for additional information regarding copyright ownership.
  - The ASF licenses this file to You under the Apache License, Version 2.0
  - (the "License"); you may not use this file except in compliance with
N
nzomkxia 已提交
7
  - the License.  You may obtain a copy of the License at
M
min 已提交
8
  -
N
nzomkxia 已提交
9
  -     http://www.apache.org/licenses/LICENSE-2.0
M
min 已提交
10
  -
N
nzomkxia 已提交
11 12 13 14 15
  - Unless required by applicable law or agreed to in writing, software
  - distributed under the License is distributed on an "AS IS" BASIS,
  - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  - See the License for the specific language governing permissions and
  - limitations under the License.
M
min 已提交
16 17 18 19
  -->

<template>
  <v-container grid-list-xl fluid >
20
      <v-layout row wrap>
M
min 已提交
21
        <v-flex xs12 >
N
nzomkxia 已提交
22
          <search v-model="filter" :submit="submit" label="Search dubbo service"></search>
23 24
        </v-flex>
      </v-layout>
B
beiwei30 已提交
25 26 27

    <v-flex lg12>
      <v-card>
B
beiwei30 已提交
28 29 30 31 32 33 34
        <v-toolbar flat color="transparent" class="elevation-0">
          <v-toolbar-title><span class="headline">Search Result</span></v-toolbar-title>
          <v-divider
            class="mx-2"
            inset
            vertical
          ></v-divider>
B
beiwei30 已提交
35 36 37 38 39 40 41 42 43
          <v-spacer></v-spacer>
          <v-btn outline color="primary" @click.stop="openDialog" class="mb-2">CREATE</v-btn>
        </v-toolbar>

        <v-card-text class="pa-0">
          <v-data-table
            :headers="headers"
            :items="routingRules"
            hide-actions
B
beiwei30 已提交
44
            class="elevation-0"
B
beiwei30 已提交
45 46 47
          >
            <template slot="items" slot-scope="props">
              <td class="text-xs-left">{{ props.item.service }}</td>
N
nzomkxia 已提交
48
              <td class="text-xs-left">{{ props.item.group }}</td>
B
beiwei30 已提交
49
              <td class="text-xs-left">{{ props.item.priority }}</td>
N
nzomkxia 已提交
50
              <td class="text-xs-left">{{ props.item.enabled }}</td>
B
beiwei30 已提交
51
              <td class="justify-center px-0">
N
nzomkxia 已提交
52
                <v-tooltip bottom v-for="op in operations" :key="op.id">
N
nzomkxia 已提交
53 54
                  <v-icon small class="mr-2" slot="activator" @click="itemOperation(op.icon(props.item), props.item)">
                    {{op.icon(props.item)}}
B
beiwei30 已提交
55
                  </v-icon>
N
nzomkxia 已提交
56
                  <span>{{op.tooltip(props.item)}}</span>
B
beiwei30 已提交
57
                </v-tooltip>
B
beiwei30 已提交
58 59 60 61 62 63 64
              </td>
            </template>
          </v-data-table>
        </v-card-text>
      </v-card>
    </v-flex>

65
    <v-dialog   v-model="dialog" width="800px" persistent >
M
min 已提交
66 67
      <v-card>
        <v-card-title class="justify-center">
B
beiwei30 已提交
68
          <span class="headline">Create New Routing Rule</span>
M
min 已提交
69 70
        </v-card-title>
        <v-card-text >
M
min 已提交
71
          <v-text-field
B
beiwei30 已提交
72 73
            label="Service Unique ID"
            hint="A service ID in form of service:version, version is optional"
M
min 已提交
74
            required
M
min 已提交
75
            v-model="service"
M
min 已提交
76 77
          ></v-text-field>
          <v-text-field
B
beiwei30 已提交
78 79
            label="Application Name"
            hint="Application name the service belongs to"
M
min 已提交
80 81
            required
            v-model="application"
M
min 已提交
82
          ></v-text-field>
B
beiwei30 已提交
83 84

          <v-subheader class="pa-0 mt-3">RULE CONTENT</v-subheader>
N
nzomkxia 已提交
85
          <ace-editor v-model="ruleText" :readonly="readonly"></ace-editor>
86

M
min 已提交
87 88 89
        </v-card-text>
        <v-card-actions>
          <v-spacer></v-spacer>
N
nzomkxia 已提交
90 91
          <v-btn color="blue darken-1" flat @click.native="closeDialog">Close</v-btn>
          <v-btn color="blue darken-1" flat @click.native="saveItem">Save</v-btn>
M
min 已提交
92 93 94
        </v-card-actions>
      </v-card>
    </v-dialog>
N
nzomkxia 已提交
95

N
nzomkxia 已提交
96 97 98 99 100 101
    <v-dialog v-model="warn" persistent max-width="500px">
      <v-card>
        <v-card-title class="headline">{{this.warnTitle}}</v-card-title>
        <v-card-text >{{this.warnText}}</v-card-text>
        <v-card-actions>
          <v-spacer></v-spacer>
N
nzomkxia 已提交
102 103
          <v-btn color="green darken-1" flat @click.native="closeWarn">CANCLE</v-btn>
          <v-btn color="green darken-1" flat @click.native="deleteItem(warnStatus)">CONFIRM</v-btn>
N
nzomkxia 已提交
104 105 106
        </v-card-actions>
      </v-card>
    </v-dialog>
N
nzomkxia 已提交
107

M
min 已提交
108 109 110 111
  </v-container>

</template>
<script>
N
nzomkxia 已提交
112
  import yaml from 'js-yaml'
N
nzomkxia 已提交
113 114 115
  import AceEditor from '@/components/public/AceEditor'
  import Search from '@/components/public/Search'
  import {AXIOS} from '../http-common'
M
min 已提交
116
  export default {
M
min 已提交
117
    components: {
N
nzomkxia 已提交
118 119
      AceEditor,
      Search
M
min 已提交
120
    },
M
min 已提交
121 122
    data: () => ({
      dropdown_font: [ 'Service', 'App', 'IP' ],
N
nzomkxia 已提交
123
      ruleKeys: ['enabled', 'force', 'dynamic', 'runtime', 'group', 'version', 'rule', 'priority'],
124 125
      pattern: 'Service',
      filter: '',
M
min 已提交
126
      dialog: false,
N
nzomkxia 已提交
127
      warn: false,
N
nzomkxia 已提交
128
      updateId: -1,
M
min 已提交
129 130
      application: '',
      service: '',
N
nzomkxia 已提交
131 132
      warnTitle: '',
      warnText: '',
N
nzomkxia 已提交
133
      warnStatus: {},
M
min 已提交
134
      height: 0,
B
beiwei30 已提交
135
      operations: [
N
nzomkxia 已提交
136
        {id: 0,
N
nzomkxia 已提交
137 138 139
          icon: function (item) {
            return 'visibility'
          },
N
nzomkxia 已提交
140 141 142 143
          tooltip: function (item) {
            return 'View'
          }},
        {id: 1,
N
nzomkxia 已提交
144 145 146
          icon: function (item) {
            return 'edit'
          },
N
nzomkxia 已提交
147 148 149 150
          tooltip: function (item) {
            return 'Edit'
          }},
        {id: 2,
N
nzomkxia 已提交
151 152 153 154 155 156
          icon: function (item) {
            if (item.enabled) {
              return 'block'
            }
            return 'check_circle_outline'
          },
N
nzomkxia 已提交
157 158 159 160 161 162 163
          tooltip: function (item) {
            if (item.enabled === true) {
              return 'Disable'
            }
            return 'Enable'
          }},
        {id: 3,
N
nzomkxia 已提交
164 165 166
          icon: function (item) {
            return 'delete'
          },
N
nzomkxia 已提交
167 168 169
          tooltip: function (item) {
            return 'Delete'
          }}
B
beiwei30 已提交
170
      ],
171 172
      routingRules: [
      ],
N
nzomkxia 已提交
173
      template:
N
nzomkxia 已提交
174
        'enabled: true/false\n' +
M
min 已提交
175 176 177 178 179
        'priority:\n' +
        'runtime: false/true\n' +
        'force: true/false\n' +
        'dynamic: true/false\n' +
        'conditions:\n' +
N
nzomkxia 已提交
180 181 182 183 184
        ' - \'=> host != 172.22.3.91\'\n' +
        ' - \'host != 10.20.153.10,10.20.153.11 =>\'\n' +
        ' - \'host = 10.20.153.10,10.20.153.11 =>\'\n' +
        ' - \'application != kylin => host != 172.22.3.95,172.22.3.96\'\n' +
        ' - \'method = find*,list*,get*,is* => host = 172.22.3.94,172.22.3.95,172.22.3.96\'',
N
nzomkxia 已提交
185
      ruleText: '',
N
nzomkxia 已提交
186
      readonly: false,
M
min 已提交
187 188
      headers: [
        {
N
nzomkxia 已提交
189 190
          text: 'Service Name',
          value: 'service',
B
beiwei30 已提交
191
          align: 'left'
192 193
        },
        {
N
nzomkxia 已提交
194 195
          text: 'Group',
          value: 'group',
B
beiwei30 已提交
196
          align: 'left'
N
nzomkxia 已提交
197

M
min 已提交
198 199
        },
        {
200 201
          text: 'Priority',
          value: 'priority',
B
beiwei30 已提交
202
          sortable: false
M
min 已提交
203 204
        },
        {
N
nzomkxia 已提交
205 206
          text: 'Enabled',
          value: 'enabled',
B
beiwei30 已提交
207
          sortable: false
M
min 已提交
208 209 210 211
        },
        {
          text: 'Operation',
          value: 'operation',
B
beiwei30 已提交
212
          sortable: false
M
min 已提交
213 214 215 216
        }
      ]
    }),
    methods: {
M
min 已提交
217
      submit: function () {
N
nzomkxia 已提交
218
        this.search(this.filter, true)
219
      },
N
nzomkxia 已提交
220
      search: function (filter, rewrite) {
N
nzomkxia 已提交
221
        AXIOS.get('/routes/search?serviceName=' + filter)
N
nzomkxia 已提交
222 223 224
          .then(response => {
            this.routingRules = response.data
            if (rewrite) {
N
nzomkxia 已提交
225
              this.$router.push({path: 'routingRule', query: {service: filter}})
N
nzomkxia 已提交
226 227 228
            }
          })
      },
N
nzomkxia 已提交
229 230
      closeDialog: function () {
        this.ruleText = this.template
N
nzomkxia 已提交
231
        this.updateId = -1
N
nzomkxia 已提交
232
        this.service = ''
N
nzomkxia 已提交
233
        this.dialog = false
N
nzomkxia 已提交
234
        this.readonly = false
N
nzomkxia 已提交
235
      },
M
min 已提交
236 237
      openDialog: function () {
        this.dialog = true
238
      },
N
nzomkxia 已提交
239 240 241 242 243 244 245 246 247 248 249
      openWarn: function (title, text) {
        this.warnTitle = title
        this.warnText = text
        this.warn = true
      },
      closeWarn: function () {
        this.warnTitle = ''
        this.warnText = ''
        this.warn = false
      },
      saveItem: function () {
N
nzomkxia 已提交
250
        let rule = yaml.safeLoad(this.ruleText)
N
nzomkxia 已提交
251
        rule.service = this.service
N
nzomkxia 已提交
252 253 254 255 256 257 258 259 260 261 262 263 264 265
        if (this.updateId !== -1) {
          rule.id = this.updateId
          AXIOS.post('/routes/update', rule)
            .then(response => {
              if (response.data) {
                this.search(this.service, true)
              }
              this.closeDialog()
            })
        } else {
          AXIOS.post('/routes/create', rule)
            .then(response => {
              if (response.data) {
                this.search(this.service, true)
N
nzomkxia 已提交
266
                this.filter = this.service
N
nzomkxia 已提交
267 268 269 270
              }
              this.closeDialog()
            })
        }
N
nzomkxia 已提交
271
      },
N
nzomkxia 已提交
272 273 274 275 276 277 278
      itemOperation: function (icon, item) {
        switch (icon) {
          case 'visibility':
            AXIOS.get('/routes/detail?id=' + item.id)
              .then(response => {
                let route = response.data
                this.service = route.service
N
nzomkxia 已提交
279 280
                delete route.service
                this.ruleText = yaml.safeDump(route)
N
nzomkxia 已提交
281
                this.readonly = true
N
nzomkxia 已提交
282 283 284 285
                this.dialog = true
              })
            break
          case 'edit':
N
nzomkxia 已提交
286 287
            let id = {}
            id.id = item.id
N
nzomkxia 已提交
288
            AXIOS.get('/routes/detail?id=' + item.id)
N
nzomkxia 已提交
289
              .then(response => {
N
nzomkxia 已提交
290 291
                let route = response.data
                this.service = route.service
N
nzomkxia 已提交
292 293
                delete route.service
                this.ruleText = yaml.safeDump(route)
N
nzomkxia 已提交
294
                this.readonly = false
N
nzomkxia 已提交
295
                this.dialog = true
N
nzomkxia 已提交
296
                this.updateId = item.id
N
nzomkxia 已提交
297 298 299
              })
            break
          case 'block':
N
nzomkxia 已提交
300 301 302 303
            this.openWarn(' Are you sure to block Routing Rule', 'service: ' + item.service)
            this.warnStatus.operation = 'disable'
            this.warnStatus.id = item.id
            break
N
nzomkxia 已提交
304
          case 'check_circle_outline':
N
nzomkxia 已提交
305 306
            this.openWarn(' Are you sure to enable Routing Rule', 'service: ' + item.service)
            this.warnStatus.operation = 'enable'
N
nzomkxia 已提交
307
            this.warnStatus.id = item.id
N
nzomkxia 已提交
308 309
            break
          case 'delete':
N
nzomkxia 已提交
310
            this.openWarn(' Are you sure to Delete Routing Rule', 'service: ' + item.service)
N
nzomkxia 已提交
311 312
            this.warnStatus.operation = 'delete'
            this.warnStatus.id = item.id
313
        }
M
min 已提交
314 315
      },
      setHeight: function () {
M
min 已提交
316
        this.height = window.innerHeight * 0.5
N
nzomkxia 已提交
317
      },
N
nzomkxia 已提交
318 319
      deleteItem: function (warnStatus) {
        if (warnStatus.operation === 'delete') {
N
nzomkxia 已提交
320 321 322
          let id = {}
          id.id = warnStatus.id
          AXIOS.post('/routes/delete', id)
N
nzomkxia 已提交
323 324 325 326
            .then(response => {
              this.warn = false
              this.search(this.filter, false)
            })
N
nzomkxia 已提交
327 328 329 330 331 332 333 334 335 336 337 338
        } else if (warnStatus.operation === 'disable') {
          let id = {}
          id.id = warnStatus.id
          AXIOS.post('/routes/disable', id)
            .then(response => {
              this.warn = false
              this.search(this.filter, false)
            })
        } else if (warnStatus.operation === 'enable') {
          let id = {}
          id.id = warnStatus.id
          AXIOS.post('/routes/enable', id)
N
nzomkxia 已提交
339 340 341 342 343
            .then(response => {
              this.warn = false
              this.search(this.filter, false)
            })
        }
M
min 已提交
344 345 346 347
      }
    },
    created () {
      this.setHeight()
N
nzomkxia 已提交
348 349
    },
    mounted: function () {
N
nzomkxia 已提交
350
      this.ruleText = this.template
N
nzomkxia 已提交
351 352 353
      let query = this.$route.query
      let service = ''
      Object.keys(query).forEach(function (key) {
N
nzomkxia 已提交
354
        if (key === 'service') {
N
nzomkxia 已提交
355 356 357 358 359 360 361
          service = query[key]
        }
      })
      if (service !== '') {
        this.filter = service
        this.search(service, false)
      }
M
min 已提交
362 363 364 365
    }

  }
</script>