Skip to content

Commit b0a61fa

Browse files
RitchieVincentyadvr
andcommitted
component: sort order in list view (apache#104)
Adds order column in zone/template/offerings list view tables. Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com> Co-authored-by: Rohit Yadav <rohit@apache.org>
1 parent b5a4381 commit b0a61fa

5 files changed

Lines changed: 142 additions & 5 deletions

File tree

ui/src/components/view/ListView.vue

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,33 @@
117117
<router-link :to="{ path: '/zone/' + record.zoneid }">{{ text }}</router-link>
118118
</a>
119119

120+
<div slot="order" slot-scope="text, record" class="shift-btns">
121+
<a-tooltip placement="top">
122+
<template slot="title">Move to top</template>
123+
<a-button
124+
shape="round"
125+
icon="double-left"
126+
@click="moveItemTop(record)"
127+
class="shift-btn shift-btn--rotated"></a-button>
128+
</a-tooltip>
129+
<a-tooltip placement="top">
130+
<template slot="title">Move to bottom</template>
131+
<a-button
132+
shape="round"
133+
icon="double-right"
134+
@click="moveItemBottom(record)"
135+
class="shift-btn shift-btn--rotated"></a-button>
136+
</a-tooltip>
137+
<a-tooltip placement="top">
138+
<template slot="title">Move up one row</template>
139+
<a-button shape="round" icon="caret-up" @click="moveItemUp(record)" class="shift-btn"></a-button>
140+
</a-tooltip>
141+
<a-tooltip placement="top">
142+
<template slot="title">Move down one row</template>
143+
<a-button shape="round" icon="caret-down" @click="moveItemDown(record)" class="shift-btn"></a-button>
144+
</a-tooltip>
145+
</div>
146+
120147
<template slot="value" slot-scope="text, record">
121148
<a-input
122149
v-if="editableValueKey === record.key"
@@ -181,6 +208,7 @@ export default {
181208
default: false
182209
}
183210
},
211+
inject: ['parentFetchData', 'parentToggleLoading'],
184212
data () {
185213
return {
186214
selectedRowKeys: [],
@@ -233,6 +261,90 @@ export default {
233261
editValue (record) {
234262
this.editableValueKey = record.key
235263
this.editableValue = record.value
264+
},
265+
handleUpdateOrder (id, index) {
266+
this.parentToggleLoading()
267+
let apiString = ''
268+
switch (this.$route.name) {
269+
case 'template':
270+
apiString = 'updateTemplate'
271+
break
272+
case 'iso':
273+
apiString = 'updateIso'
274+
break
275+
case 'zone':
276+
apiString = 'updateZone'
277+
break
278+
case 'computeoffering':
279+
case 'systemoffering':
280+
apiString = 'updateServiceOffering'
281+
break
282+
case 'diskoffering':
283+
apiString = 'updateDiskOffering'
284+
break
285+
case 'networkoffering':
286+
apiString = 'updateNetworkOffering'
287+
break
288+
case 'vpcoffering':
289+
apiString = 'updateVPCOffering'
290+
break
291+
default:
292+
apiString = 'updateTemplate'
293+
}
294+
295+
api(apiString, {
296+
id,
297+
sortKey: index
298+
}).catch(error => {
299+
console.error(error)
300+
}).finally(() => {
301+
this.parentFetchData()
302+
this.parentToggleLoading()
303+
})
304+
},
305+
moveItemUp (record) {
306+
const data = this.items
307+
const index = data.findIndex(item => item.id === record.id)
308+
if (index === 0) return
309+
310+
data.splice(index - 1, 0, data.splice(index, 1)[0])
311+
312+
data.forEach((item, index) => {
313+
this.handleUpdateOrder(item.id, index + 1)
314+
})
315+
},
316+
moveItemDown (record) {
317+
const data = this.items
318+
const index = data.findIndex(item => item.id === record.id)
319+
if (index === data.length - 1) return
320+
321+
data.splice(index + 1, 0, data.splice(index, 1)[0])
322+
323+
data.forEach((item, index) => {
324+
this.handleUpdateOrder(item.id, index + 1)
325+
})
326+
},
327+
moveItemTop (record) {
328+
const data = this.items
329+
const index = data.findIndex(item => item.id === record.id)
330+
if (index === 0) return
331+
332+
data.unshift(data.splice(index, 1)[0])
333+
334+
data.forEach((item, index) => {
335+
this.handleUpdateOrder(item.id, index + 1)
336+
})
337+
},
338+
moveItemBottom (record) {
339+
const data = this.items
340+
const index = data.findIndex(item => item.id === record.id)
341+
if (index === data.length - 1) return
342+
343+
data.push(data.splice(index, 1)[0])
344+
345+
data.forEach((item, index) => {
346+
this.handleUpdateOrder(item.id, index + 1)
347+
})
236348
}
237349
}
238350
}
@@ -255,3 +367,27 @@ export default {
255367
background-color: #f9f9f9;
256368
}
257369
</style>
370+
371+
<style scoped lang="scss">
372+
.shift-btns {
373+
display: flex;
374+
}
375+
.shift-btn {
376+
display: flex;
377+
align-items: center;
378+
justify-content: center;
379+
width: 20px;
380+
height: 20px;
381+
font-size: 12px;
382+
383+
&:not(:last-child) {
384+
margin-right: 5px;
385+
}
386+
387+
&--rotated {
388+
font-size: 10px;
389+
transform: rotate(90deg);
390+
}
391+
392+
}
393+
</style>

ui/src/config/section/image.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default {
2727
permission: ['listTemplates'],
2828
params: { templatefilter: 'executable' },
2929
resourceType: 'Template',
30-
columns: ['name', 'ostypename', 'status', 'hypervisor', 'account', 'domain'],
30+
columns: ['name', 'ostypename', 'status', 'hypervisor', 'account', 'domain', 'order'],
3131
details: ['name', 'id', 'displaytext', 'checksum', 'hypervisor', 'format', 'ostypename', 'size', 'isready', 'passwordenabled', 'directdownload', 'isextractable', 'isdynamicallyscalable', 'ispublic', 'isfeatured', 'crosszones', 'type', 'account', 'domain', 'created'],
3232
related: [{
3333
name: 'vm',

ui/src/config/section/infra/zones.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default {
2020
title: 'Zones',
2121
icon: 'global',
2222
permission: ['listZonesMetrics', 'listZones'],
23-
columns: ['name', 'state', 'networktype', 'clusters', 'cpuused', 'cpumaxdeviation', 'cpuallocated', 'cputotal', 'memoryused', 'memorymaxdeviation', 'memoryallocated', 'memorytotal'],
23+
columns: ['name', 'state', 'networktype', 'clusters', 'cpuused', 'cpumaxdeviation', 'cpuallocated', 'cputotal', 'memoryused', 'memorymaxdeviation', 'memoryallocated', 'memorytotal', 'order'],
2424
details: ['name', 'id', 'allocationstate', 'networktype', 'guestcidraddress', 'localstorageenabled', 'securitygroupsenabled', 'dns1', 'dns2', 'internaldns1', 'internaldns2'],
2525
related: [{
2626
name: 'physicalnetwork',

ui/src/config/section/offering.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default {
2727
icon: 'cloud',
2828
permission: ['listServiceOfferings'],
2929
params: { isrecursive: 'true' },
30-
columns: ['name', 'displaytext', 'cpunumber', 'cpuspeed', 'memory', 'tags', 'domain', 'zone'],
30+
columns: ['name', 'displaytext', 'cpunumber', 'cpuspeed', 'memory', 'tags', 'domain', 'zone', 'order'],
3131
details: ['name', 'id', 'displaytext', 'offerha', 'provisioningtype', 'storagetype', 'iscustomized', 'limitcpuuse', 'cpunumber', 'cpuspeed', 'memory', 'tags', 'domain', 'zone', 'created'],
3232
related: [{
3333
name: 'vm',
@@ -67,7 +67,7 @@ export default {
6767
icon: 'setting',
6868
permission: ['listServiceOfferings', 'listInfrastructure'],
6969
params: { issystem: 'true', isrecursive: 'true' },
70-
columns: ['name', 'systemvmtype', 'cpunumber', 'cpuspeed', 'memory', 'storagetype', 'tags'],
70+
columns: ['name', 'systemvmtype', 'cpunumber', 'cpuspeed', 'memory', 'storagetype', 'tags', 'order'],
7171
details: ['name', 'id', 'displaytext', 'systemvmtype', 'provisioningtype', 'storagetype', 'iscustomized', 'limitcpuuse', 'cpunumber', 'cpuspeed', 'memory', 'tags', 'domain', 'zone', 'created'],
7272
actions: [{
7373
api: 'createServiceOffering',
@@ -98,7 +98,7 @@ export default {
9898
icon: 'hdd',
9999
permission: ['listDiskOfferings'],
100100
params: { isrecursive: 'true' },
101-
columns: ['name', 'displaytext', 'disksize', 'tags', 'domain', 'zone'],
101+
columns: ['name', 'displaytext', 'disksize', 'tags', 'domain', 'zone', 'order'],
102102
details: ['name', 'id', 'displaytext', 'disksize', 'provisioningtype', 'storagetype', 'iscustomized', 'tags', 'domain', 'zone', 'created'],
103103
related: [{
104104
name: 'volume',

ui/src/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,7 @@
710710
"offerha": "Offer HA",
711711
"offeringType": "Compute offering type",
712712
"operation": "Operation",
713+
"order": "Order",
713714
"osTypeId": "OS Type",
714715
"oscategoryid": "OS Preference",
715716
"ostypeid": "OS Type",

0 commit comments

Comments
 (0)