shwstppr commented on a change in pull request #273:
URL: https://github.com/apache/cloudstack-primate/pull/273#discussion_r411306920



##########
File path: src/views/compute/wizard/ComputeOfferingSelection.vue
##########
@@ -0,0 +1,164 @@
+// 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 the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// 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.
+
+<template>
+  <div>
+    <a-input-search
+      style="width: 25vw;float: right;margin-bottom: 10px; z-index: 8"
+      placeholder="Search"
+      v-model="filter"
+      @search="handleSearch" />
+    <a-table
+      :columns="columns"
+      :dataSource="tableSource"
+      :pagination="{showSizeChanger: true}"
+      :rowSelection="rowSelection"
+      :loading="loading"
+      size="middle"
+      @change="handleTableChange"
+      :scroll="{ y: 225 }"
+    >
+      <span slot="cpuTitle"><a-icon type="appstore" /> {{ $t('cpu') }}</span>
+      <span slot="ramTitle"><a-icon type="bulb" /> {{ $t('memory') }}</span>
+    </a-table>
+  </div>
+</template>
+
+<script>
+export default {
+  name: 'ComputeOfferingSelection',
+  props: {
+    computeItems: {
+      type: Array,
+      default: () => []
+    },
+    value: {
+      type: String,
+      default: ''
+    },
+    loading: {
+      type: Boolean,
+      default: false
+    },
+    preFillContent: {
+      type: Object,
+      default: () => {}
+    }
+  },
+  data () {
+    return {
+      filter: '',
+      columns: [
+        {
+          dataIndex: 'name',
+          title: this.$t('serviceOfferingId'),
+          width: '40%'
+        },
+        {
+          dataIndex: 'cpu',
+          slots: { title: 'cpuTitle' },
+          width: '30%'
+        },
+        {
+          dataIndex: 'ram',
+          slots: { title: 'ramTitle' },
+          width: '30%'
+        }
+      ],
+      selectedRowKeys: []
+    }
+  },
+  computed: {
+    options () {
+      return {
+        page: 1,
+        pageSize: 10,
+        keyword: ''
+      }
+    },
+    tableSource () {
+      return this.computeItems.map((item) => {
+        var cpuNumberValue = item.cpunumber + ''
+        var cpuSpeedValue = (item.cpuspeed !== null && item.cpuspeed !== 
undefined && item.cpuspeed > 0) ? parseFloat(item.cpuspeed / 1000.0).toFixed(2) 
+ '' : ''
+        var ramValue = item.memory + ''
+        if (item.iscustomized === true) {
+          cpuNumberValue = ''
+          ramValue = ''
+          if ('serviceofferingdetails' in item &&
+            'mincpunumber' in item.serviceofferingdetails &&
+            'maxcpunumber' in item.serviceofferingdetails) {
+            cpuNumberValue = item.serviceofferingdetails.mincpunumber + '-' + 
item.serviceofferingdetails.maxcpunumber
+          }
+          if ('serviceofferingdetails' in item &&
+            'minmemory' in item.serviceofferingdetails &&
+            'maxmemory' in item.serviceofferingdetails) {
+            ramValue = item.serviceofferingdetails.minmemory + '-' + 
item.serviceofferingdetails.maxmemory
+          }
+        }
+        return {
+          key: item.id,
+          name: item.name,
+          cpu: cpuNumberValue.length > 0 ? `${cpuNumberValue} CPU x 
${cpuSpeedValue} Ghz` : '',
+          ram: ramValue.length > 0 ? `${ramValue} MB` : ''
+        }
+      })
+    },
+    rowSelection () {
+      return {
+        type: 'radio',
+        selectedRowKeys: this.selectedRowKeys,
+        onChange: this.onSelectRow
+      }
+    }
+  },
+  watch: {
+    value (newValue, oldValue) {
+      if (newValue && newValue !== oldValue) {
+        this.selectedRowKeys = [newValue]
+      }
+    },
+    loading () {
+      if (!this.loading && this.preFillContent.computeofferingid) {
+        this.selectedRowKeys = [this.preFillContent.computeofferingid]
+        this.$emit('select-compute-item', 
this.preFillContent.computeofferingid)
+      }

Review comment:
       A minor improvement here can be selecting first element on list refresh 
when there is no `this.preFillContent.computeofferingid` and previously 
selected offering is not available in the list. Else deployVM API is fired with 
previous value without even selecting anything in the new list.
   Since offerings and network can depend on selected same behaviour could be 
seen with other parameters(disk, network) as well




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to