Skip to content

Commit 4247ec0

Browse files
shwstppryadvr
andcommitted
image: handle copy and delete actions for template/iso zone tab (apache#284)
Fixes apache#279 Implements copy and delete actions in the template/iso zones tab. Also implements template/iso filter by dropdown. Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com> Co-authored-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent eb5a943 commit 4247ec0

7 files changed

Lines changed: 520 additions & 155 deletions

File tree

ui/src/config/router.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export function generateRouterMap (section) {
6161
docHelp: child.docHelp,
6262
permission: child.permission,
6363
resourceType: child.resourceType,
64+
filters: child.filters,
6465
params: child.params ? child.params : {},
6566
columns: child.columns,
6667
details: child.details,
@@ -122,6 +123,7 @@ export function generateRouterMap (section) {
122123
map.meta.resourceType = section.resourceType
123124
map.meta.details = section.details
124125
map.meta.actions = section.actions
126+
map.meta.filters = section.filters
125127
map.meta.treeView = section.treeView ? section.treeView : false
126128
map.meta.tabs = section.treeView ? section.tabs : {}
127129

ui/src/config/section/image.js

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ export default {
2727
title: 'Templates',
2828
icon: 'save',
2929
permission: ['listTemplates'],
30-
params: { templatefilter: 'executable' },
30+
params: { templatefilter: 'self' },
3131
resourceType: 'Template',
32+
filters: ['self', 'shared', 'featured', 'community'],
3233
columns: ['name', 'ostypename', 'status', 'hypervisor', 'account', 'domain', 'order'],
3334
details: ['name', 'id', 'displaytext', 'checksum', 'hypervisor', 'format', 'ostypename', 'size', 'isready', 'passwordenabled', 'directdownload', 'isextractable', 'isdynamicallyscalable', 'ispublic', 'isfeatured', 'crosszones', 'type', 'account', 'domain', 'created'],
3435
related: [{
@@ -95,21 +96,6 @@ export default {
9596
popup: true,
9697
show: (record, store) => { return (['Admin', 'DomainAdmin'].includes(store.userInfo.roletype) && (record.domainid === store.userInfo.domainid && record.account === store.userInfo.account) || record.templatetype !== 'BUILTIN') },
9798
component: () => import('@/views/image/UpdateTemplateIsoPermissions')
98-
},
99-
{
100-
api: 'copyTemplate',
101-
icon: 'copy',
102-
label: 'Copy Template',
103-
args: ['sourcezoneid', 'destzoneids'],
104-
dataView: true
105-
},
106-
{
107-
api: 'deleteTemplate',
108-
icon: 'delete',
109-
label: 'Delete Template',
110-
args: ['zoneid'],
111-
dataView: true,
112-
groupAction: true
11399
}
114100
]
115101
},
@@ -118,8 +104,9 @@ export default {
118104
title: 'ISOs',
119105
icon: 'usb',
120106
permission: ['listIsos'],
121-
params: { isofilter: 'executable' },
107+
params: { isofilter: 'self' },
122108
resourceType: 'ISO',
109+
filters: ['self', 'shared', 'featured', 'community'],
123110
columns: ['name', 'ostypename', 'account', 'domain'],
124111
details: ['name', 'id', 'displaytext', 'checksum', 'ostypename', 'size', 'bootable', 'isready', 'directdownload', 'isextractable', 'ispublic', 'isfeatured', 'crosszones', 'account', 'domain', 'created'],
125112
related: [{
@@ -180,24 +167,10 @@ export default {
180167
icon: 'reconciliation',
181168
label: 'Update ISO Permissions',
182169
dataView: true,
170+
args: ['op', 'accounts', 'projectids'],
183171
popup: true,
184172
show: (record, store) => { return (['Admin', 'DomainAdmin'].includes(store.userInfo.roletype) && (record.domainid === store.userInfo.domainid && record.account === store.userInfo.account) || record.templatetype !== 'BUILTIN') },
185173
component: () => import('@/views/image/UpdateTemplateIsoPermissions')
186-
},
187-
{
188-
api: 'copyIso',
189-
icon: 'copy',
190-
label: 'Copy ISO',
191-
args: ['sourcezoneid', 'destzoneids'],
192-
dataView: true
193-
},
194-
{
195-
api: 'deleteIso',
196-
icon: 'delete',
197-
label: 'Delete ISO',
198-
args: ['zoneid'],
199-
dataView: true,
200-
groupAction: true
201174
}
202175
]
203176
},

ui/src/locales/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,9 @@
12791279
"filter": "Filter",
12801280
"featured": "Featured",
12811281
"community": "Community",
1282+
"self": "Mine",
12821283
"selfexecutable": "Self",
1284+
"shared": "Shared",
12831285
"sharedexecutable": "Shared",
12841286
"fixed": "Fixed Offering",
12851287
"customconstrained": "Custom Constrained",

ui/src/views/AutogenView.vue

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<div>
2020
<a-card class="breadcrumb-card">
2121
<a-row>
22-
<a-col :span="14" style="padding-left: 6px">
22+
<a-col :span="12" style="padding-left: 6px">
2323
<breadcrumb :resource="resource">
2424
<a-tooltip placement="bottom" slot="end">
2525
<template slot="title">
@@ -37,7 +37,7 @@
3737
</a-tooltip>
3838
</breadcrumb>
3939
</a-col>
40-
<a-col :span="10">
40+
<a-col :span="12">
4141
<span style="float: right">
4242
<action-button
4343
style="margin-bottom: 5px"
@@ -47,6 +47,17 @@
4747
:dataView="dataView"
4848
:resource="resource"
4949
@exec-action="execAction"/>
50+
<a-select
51+
v-if="filters && filters.length > 0"
52+
placeholder="Filter By"
53+
:value="$t(selectedFilter)"
54+
style="min-width: 100px; margin-left: 10px"
55+
@change="changeFilter">
56+
<a-icon slot="suffixIcon" type="filter" />
57+
<a-select-option v-for="filter in filters" :key="filter">
58+
{{ $t(filter) }}
59+
</a-select-option>
60+
</a-select>
5061
<a-input-search
5162
style="width: 20vw; margin-left: 10px"
5263
placeholder="Search"
@@ -305,6 +316,8 @@ export default {
305316
showAction: false,
306317
dataView: false,
307318
treeView: false,
319+
selectedFilter: '',
320+
filters: [],
308321
actions: [],
309322
treeData: [],
310323
treeSelected: {},
@@ -337,6 +350,7 @@ export default {
337350
this.searchQuery = ''
338351
this.page = 1
339352
this.itemCount = 0
353+
this.selectedFilter = ''
340354
this.fetchData()
341355
}
342356
},
@@ -347,7 +361,7 @@ export default {
347361
}
348362
},
349363
methods: {
350-
fetchData () {
364+
fetchData (params = { listall: true }) {
351365
if (this.routeName !== this.$route.name) {
352366
this.routeName = this.$route.name
353367
this.items = []
@@ -357,11 +371,12 @@ export default {
357371
}
358372
this.apiName = ''
359373
this.actions = []
374+
this.filters = this.$route.meta.filters || []
360375
this.columns = []
361376
this.columnKeys = []
362377
this.treeData = []
363378
this.treeSelected = {}
364-
var params = { listall: true }
379+
365380
if (Object.keys(this.$route.query).length > 0) {
366381
Object.assign(params, this.$route.query)
367382
} else if (this.$route.meta.params) {
@@ -393,6 +408,26 @@ export default {
393408
return
394409
}
395410
411+
if (['listTemplates', 'listIsos'].includes(this.apiName) && !this.dataView) {
412+
if (['Admin'].includes(this.$store.getters.userInfo.roletype)) {
413+
this.filters = ['all', ...this.filters]
414+
if (this.selectedFilter === '') {
415+
this.selectedFilter = 'all'
416+
}
417+
}
418+
if (this.selectedFilter === '') {
419+
this.selectedFilter = 'self'
420+
}
421+
}
422+
423+
if (this.selectedFilter && this.filters.length > 0) {
424+
if (this.$route.path.startsWith('/template')) {
425+
params.templatefilter = this.selectedFilter
426+
} else if (this.$route.path.startsWith('/iso')) {
427+
params.isofilter = this.selectedFilter
428+
}
429+
}
430+
396431
if (this.searchQuery !== '') {
397432
if (this.apiName === 'listRoles') {
398433
params.name = this.searchQuery
@@ -450,12 +485,6 @@ export default {
450485
delete params.treeView
451486
}
452487
453-
if (['listTemplates', 'listIsos'].includes(this.apiName) && !this.dataView) {
454-
if (['Admin'].includes(this.$store.getters.userInfo.roletype)) {
455-
params.templatefilter = 'all'
456-
}
457-
}
458-
459488
api(this.apiName, params).then(json => {
460489
var responseName
461490
var objectName
@@ -524,6 +553,13 @@ export default {
524553
this.loading = false
525554
})
526555
},
556+
removeStringStartSubstringIfPresent (str, searchstr) {
557+
var index = str.indexOf(searchstr)
558+
if (index !== 0) {
559+
return str
560+
}
561+
return str.slice(index + searchstr.length)
562+
},
527563
onSearch (value) {
528564
this.searchQuery = value
529565
this.page = 1
@@ -576,7 +612,7 @@ export default {
576612
}
577613
}
578614
this.currentAction.loading = false
579-
if (action.dataView && action.icon === 'edit') {
615+
if (action.dataView && ['copy', 'edit'].includes(action.icon)) {
580616
this.fillEditFormFieldValues()
581617
}
582618
},
@@ -585,8 +621,11 @@ export default {
585621
return
586622
}
587623
var paramName = param.name
624+
var extractedParamName = paramName.replace('ids', '').replace('id', '').toLowerCase()
625+
extractedParamName = this.removeStringStartSubstringIfPresent(extractedParamName, 'source')
626+
extractedParamName = this.removeStringStartSubstringIfPresent(extractedParamName, 'dest')
588627
var params = { listall: true }
589-
const possibleName = 'list' + paramName.replace('ids', '').replace('id', '').toLowerCase() + 's'
628+
const possibleName = 'list' + extractedParamName + 's'
590629
var possibleApi
591630
if (this.currentAction.mapping && param.name in this.currentAction.mapping && this.currentAction.mapping[param.name].api) {
592631
possibleApi = this.currentAction.mapping[param.name].api
@@ -668,6 +707,7 @@ export default {
668707
let fieldName = null
669708
if (field.type === 'uuid' || field.type === 'list' || field.name === 'account' || (this.currentAction.mapping && field.name in this.currentAction.mapping)) {
670709
fieldName = field.name.replace('ids', 'name').replace('id', 'name')
710+
fieldName = this.removeStringStartSubstringIfPresent(fieldName, 'source')
671711
} else {
672712
fieldName = field.name
673713
}
@@ -774,6 +814,10 @@ export default {
774814
}
775815
})
776816
},
817+
changeFilter (filter) {
818+
this.selectedFilter = filter
819+
this.fetchData()
820+
},
777821
changePage (page, pageSize) {
778822
this.page = page
779823
this.pageSize = pageSize

0 commit comments

Comments
 (0)