Skip to content

Commit 0cf2fe8

Browse files
committed
Flow changes done in UI based on discussion
1 parent e7ce8ae commit 0cf2fe8

8 files changed

Lines changed: 117 additions & 37 deletions

File tree

server/src/main/java/com/cloud/api/query/dao/UserVmJoinDaoImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,8 @@ public UserVmResponse newUserVmResponse(ResponseView view, String objectName, Us
465465

466466
if (userVm.getLeaseExpiryDate() != null) {
467467
userVmResponse.setLeaseExpiryAction(userVm.getLeaseExpiryAction());
468-
long leaseDuration = getLeaseDuration(userVmResponse.getCreated(), userVmResponse.getLeaseExpiryDate());
469468
userVmResponse.setLeaseExpiryDate(userVm.getLeaseExpiryDate());
469+
long leaseDuration = getLeaseDuration(userVm.getCreated(), userVm.getLeaseExpiryDate());
470470
userVmResponse.setLeaseDuration(leaseDuration);
471471
}
472472

@@ -483,7 +483,7 @@ public UserVmResponse newUserVmResponse(ResponseView view, String objectName, Us
483483
private long getLeaseDuration(Date created, Date leaseExpiryDate) {
484484
LocalDate createdDate = created.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
485485
LocalDate expiryDate = leaseExpiryDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
486-
return ChronoUnit.DAYS.between(createdDate, expiryDate);
486+
return ChronoUnit.DAYS.between(createdDate, expiryDate) - 1;
487487
}
488488

489489
private void addVnfInfoToserVmResponse(UserVmJoinVO userVm, UserVmResponse userVmResponse) {

ui/public/locales/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2646,12 +2646,14 @@
26462646
"label.bucket.policy": "Bucket Policy",
26472647
"label.usersecretkey": "Secret Key",
26482648
"label.create.bucket": "Create Bucket",
2649+
"label.isLeaseFeatureEnabled": "Enable Lease",
26492650
"label.instance.lease": "Instance lease",
26502651
"label.instance.lease.never": "Never expires (use -1)",
26512652
"label.instance.lease.stop": "stop",
26522653
"label.leaseduration": "Lease duration",
26532654
"label.leaseexpirydate": "Lease expiry date",
26542655
"label.leaseexpiryaction": "Lease expiry action",
2656+
"label.remainingdays": "Remaining",
26552657
"message.acquire.ip.failed": "Failed to acquire IP.",
26562658
"message.action.acquire.ip": "Please confirm that you want to acquire new IP.",
26572659
"message.action.cancel.maintenance": "Your host has been successfully canceled for maintenance. This process can take up to several minutes.",

ui/src/components/view/InfoCard.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@
9393
<a-tag v-if="resource.archived" :color="this.$config.theme['@warning-color']">
9494
{{ $t('label.archived') }}
9595
</a-tag>
96-
<a-tag v-if="resource.leaseduration">
97-
{{ resource.leaseduration }}
96+
<a-tag v-if="resource.leaseduration" :color="this.$config.theme['@warning-color']">
97+
{{ $t('label.remainingdays') + ': '+ (resource.leaseduration) }}
9898
</a-tag>
9999
<a-tooltip placement="right" >
100100
<template #title>
@@ -236,7 +236,7 @@
236236
{{ resource.leaseduration + ' ' + $t('label.days') }}
237237
</div>
238238
</div>
239-
<div class="resource-detail-item" v-if="'leaseexpiryaction' in resource && resource.leaseexpiryaction != ''">
239+
<div class="resource-detail-item" v-if="'leaseexpiryaction' in resource && resource.leaseexpiryaction !== undefined">
240240
<div class="resource-detail-item__label">{{ $t('label.leaseexpiryaction') }}</div>
241241
<div class="resource-detail-item__details">
242242
<font-awesome-icon

ui/src/components/view/ListView.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
<span v-else :style="{ 'margin-right': record.ostypename ? '5px' : '0' }">
6666
<os-logo v-if="record.ostypename" :osName="record.ostypename" size="xl" />
6767
</span>
68-
6968
<span v-if="record.hasannotations">
7069
<span v-if="record.id">
7170
<router-link :to="{ path: $route.path + '/' + record.id }">{{ text }}</router-link>
@@ -100,6 +99,11 @@
10099
<warning-outlined style="color: #f5222d"/>
101100
</a-tooltip>
102101
</span>
102+
<font-awesome-icon
103+
v-if="record.leaseduration"
104+
:icon="['fa-solid', 'fa-bomb']"
105+
class="anticon leaseduration"
106+
:style="[$store.getters.darkMode ? { color: 'rgba(255, 255, 255, 0.65)' } : { color: '#888' }]" />
103107
</span>
104108
</span>
105109
</template>
@@ -1127,4 +1131,8 @@ export default {
11271131
color: #f50000;
11281132
padding: 10%;
11291133
}
1134+
1135+
.leaseduration {
1136+
margin-left: 5px;
1137+
}
11301138
</style>

ui/src/views/compute/DeployVM.vue

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,13 @@
603603
@change="val => { dynamicscalingenabled = val }"/>
604604
</a-form-item>
605605
</a-form-item>
606-
<a-row :gutter="12" v-if="isLeaseFeatureEnabled">
606+
<a-form-item name="showLeaseOptions" ref="showLeaseOptions" v-if="isLeaseFeatureEnabled">
607+
<template #label>
608+
<tooltip-label :title="$t('label.isLeaseFeatureEnabled')" />
609+
</template>
610+
<a-switch v-model:checked="showLeaseOptions" @change="onToggleLeaseData"/>
611+
</a-form-item>
612+
<a-row :gutter="12" v-if="showLeaseOptions">
607613
<a-col :md="12" :lg="12">
608614
<a-form-item name="leaseduration" ref="leaseduration">
609615
<template #label>
@@ -1125,9 +1131,11 @@ export default {
11251131
]
11261132
},
11271133
isLeaseFeatureEnabled: false,
1128-
leaseduration: -1,
1134+
showLeaseOptions: false,
1135+
leaseduration: undefined,
11291136
leaseexpiryaction: '',
1130-
expiryActions: ['STOP', 'DESTROY']
1137+
expiryActions: ['STOP', 'DESTROY'],
1138+
defaultLeaseDuration: undefined
11311139
}
11321140
},
11331141
computed: {
@@ -1684,21 +1692,18 @@ export default {
16841692
var leasedurationParams = { name: 'instance.lease.duration', accountid: store.getters.userInfo.accountid }
16851693
api('listConfigurations', leasedurationParams).then(json => {
16861694
var value = json?.listconfigurationsresponse?.configuration?.[0].value || null
1687-
this.leaseduration = value
1688-
1695+
this.defaultLeaseDuration = value
16891696
if (value > -1) {
16901697
var leaseActionParams = { name: 'instance.lease.expiryaction', accountid: store.getters.userInfo.accountid }
16911698
api('listConfiguration', leaseActionParams).then(json => {
16921699
var value = json?.listconfigurationsresponse?.configuration?.[0].value || null
1693-
this.leaseexpiryaction = value
1700+
this.defaultLeaseExpiryaction = value
16941701
}).catch(() => {
1695-
this.leaseexiryaction = 'STOP'
1702+
this.defaultLeaseExpiryaction = 'STOP'
16961703
})
16971704
}
16981705
}).catch(() => {
1699-
this.leaseduration = -1
1700-
}).finally(() => {
1701-
this.form.leaseduration = this.leaseduration
1706+
this.defaultLeaseDuration = -1
17021707
})
17031708
}
17041709
}).catch((error) => {
@@ -1800,13 +1805,13 @@ export default {
18001805
this.fetchBootModes()
18011806
this.fetchInstaceGroups()
18021807
this.fetchIoPolicyTypes()
1808+
this.populateLeaseFeatureProps()
18031809
nextTick().then(() => {
18041810
['name', 'keyboard', 'boottype', 'bootmode', 'userdata', 'iothreadsenabled', 'iodriverpolicy', 'nicmultiqueuenumber', 'nicpackedvirtqueues'].forEach(this.fillValue)
18051811
this.form.boottype = this.defaultBootType ? this.defaultBootType : this.options.bootTypes && this.options.bootTypes.length > 0 ? this.options.bootTypes[0].id : undefined
18061812
this.form.bootmode = this.defaultBootMode ? this.defaultBootMode : this.options.bootModes && this.options.bootModes.length > 0 ? this.options.bootModes[0].id : undefined
18071813
this.instanceConfig = toRaw(this.form)
18081814
})
1809-
this.populateLeaseFeatureProps()
18101815
},
18111816
isDynamicallyScalable () {
18121817
return this.serviceOffering && this.serviceOffering.dynamicscalingenabled && this.template && this.template.isdynamicallyscalable && this.dynamicScalingVmConfigValue
@@ -2897,14 +2902,16 @@ export default {
28972902
this.showRootDiskSizeChanger = false
28982903
}
28992904
if (offering && offering.leaseduration > -1) {
2905+
this.leaseduration = offering.leaseduration
29002906
this.form.leaseduration = offering.leaseduration
2901-
29022907
if (offering.leaseexpiryaction !== undefined) {
2908+
this.leaseexpiryaction = offering.leaseexpiryaction
29032909
this.form.leaseexpiryaction = offering.leaseexpiryaction
29042910
}
2911+
this.showLeaseOptions = true
29052912
} else {
2906-
this.form.leaseduration = this.leaseduration
2907-
this.form.leaseexpiryaction = this.leaseexpiryaction
2913+
this.showLeaseOptions = false
2914+
this.onToggleLeaseData()
29082915
}
29092916
this.form.rootdisksizeitem = this.showRootDiskSizeChanger && this.rootDiskSizeFixed > 0
29102917
this.formModel = toRaw(this.form)
@@ -2949,6 +2956,15 @@ export default {
29492956
parent.$message.success(parent.$t('label.copied.clipboard'))
29502957
}
29512958
})
2959+
},
2960+
onToggleLeaseData () {
2961+
if (this.showLeaseOptions === false) {
2962+
this.form.leaseduration = undefined
2963+
this.form.leaseexpiryaction = undefined
2964+
} else {
2965+
this.form.leaseduration = this.leaseduration === undefined ? this.defaultLeaseDuration : this.leaseduration
2966+
this.form.leaseexpiryaction = this.leaseexpiryaction
2967+
}
29522968
}
29532969
}
29542970
}

ui/src/views/compute/EditVM.vue

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,13 @@
117117
</template>
118118
<a-switch v-model:checked="form.deleteprotection" />
119119
</a-form-item>
120-
<a-row :gutter="12" v-if="isLeaseFeatureEnabled">
120+
<a-form-item name="showLeaseOptions" ref="showLeaseOptions" v-if="isLeaseFeatureEnabled">
121+
<template #label>
122+
<tooltip-label :title="$t('label.isLeaseFeatureEnabled')" />
123+
</template>
124+
<a-switch v-model:checked="showLeaseOptions" @change="onToggleLeaseData"/>
125+
</a-form-item>
126+
<a-row :gutter="12" v-if="showLeaseOptions">
121127
<a-col :md="12" :lg="12">
122128
<a-form-item name="leaseduration" ref="leaseduration">
123129
<template #label>
@@ -133,7 +139,7 @@
133139
<template #label>
134140
<tooltip-label :title="$t('label.leaseexpiryaction')" />
135141
</template>
136-
<a-select v-model:value="form.leaseexpiryaction">
142+
<a-select v-model:value="form.leaseexpiryaction" :defaultValue="expiryActions">
137143
<a-select-option v-for="action in expiryActions" :key="action" :label="action" />
138144
</a-select>
139145
</a-form-item>
@@ -188,8 +194,10 @@ export default {
188194
loading: false,
189195
opts: []
190196
},
191-
leaseduration: -1,
192-
leaseexpiryaction: '',
197+
isLeaseFeatureEnabled: false,
198+
showLeaseOptions: false,
199+
leaseduration: undefined,
200+
leaseexpiryaction: undefined,
193201
expiryActions: ['STOP', 'DESTROY']
194202
}
195203
},
@@ -357,15 +365,16 @@ export default {
357365
})
358366
},
359367
async populateLeaseFeatureProps () {
368+
if (this.resource.leaseduration !== undefined && this.resource.leaseduration >= 0) {
369+
this.showLeaseOptions = this.isLeaseFeatureEnabled = true
370+
this.leaseduration = this.resource.leaseduration
371+
this.leaseexpiryaction = this.resource.leaseexpiryaction
372+
return
373+
}
360374
var params = { name: 'instance.lease.enabled' }
361375
api('listConfigurations', params).then(json => {
362376
var value = json?.listconfigurationsresponse?.configuration?.[0].value || null
363377
this.isLeaseFeatureEnabled = value === 'true'
364-
365-
if (this.form.leaseduration >= -1) {
366-
return
367-
}
368-
369378
if (this.isLeaseFeatureEnabled) {
370379
var leasedurationParams = { name: 'instance.lease.duration', accountid: this.$store.getters.userInfo.accountid }
371380
api('listConfigurations', leasedurationParams).then(json => {
@@ -378,7 +387,7 @@ export default {
378387
var value = json?.listconfigurationsresponse?.configuration?.[0].value || null
379388
this.leaseexpiryaction = value
380389
}).catch(() => {
381-
this.leaseexiryaction = 'STOP'
390+
this.leaseexpiryaction = 'STOP'
382391
})
383392
}
384393
}).catch(() => {
@@ -445,6 +454,15 @@ export default {
445454
},
446455
onCloseAction () {
447456
this.$emit('close-action')
457+
},
458+
onToggleLeaseData () {
459+
if (this.showLeaseOptions === false) {
460+
this.form.leaseduration = -1
461+
this.form.leaseexpiryaction = undefined
462+
} else {
463+
this.form.leaseduration = this.leaseduration
464+
this.form.leaseexpiryaction = this.leaseexpiryaction
465+
}
448466
}
449467
}
450468
}

ui/src/views/compute/wizard/ComputeOfferingSelection.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@
3636
<template v-if="column.key === 'cpu'"><appstore-outlined /> {{ $t('label.cpu') }}</template>
3737
<template v-if="column.key === 'ram'"><bulb-outlined /> {{ $t('label.memory') }}</template>
3838
</template>
39+
<template #displayText="{ record }">
40+
<span>{{ record.name }}</span>
41+
<a-tag v-if="record.leaseduration" :color="this.$config.theme['@warning-color']" style="margin-left: 5px">
42+
{{ $t('label.remainingdays') + ': '+ (record.leaseduration) }}
43+
</a-tag>
44+
</template>
3945
</a-table>
4046

4147
<div style="display: block; text-align: right;">
@@ -119,7 +125,8 @@ export default {
119125
key: 'name',
120126
dataIndex: 'name',
121127
title: this.$t('label.serviceofferingid'),
122-
width: '40%'
128+
width: '40%',
129+
slots: { customRender: 'displayText' }
123130
},
124131
{
125132
key: 'cpu',
@@ -186,12 +193,14 @@ export default {
186193
if (this.allowAllOfferings) {
187194
disabled = false
188195
}
196+
// var computedName = (item.leaseduration !== undefined) ? item.name + ': ' + item.leaseduration : item.name
189197
return {
190198
key: item.id,
191199
name: item.name,
192200
cpu: cpuNumberValue.length > 0 ? `${cpuNumberValue} CPU x ${cpuSpeedValue} Ghz` : '',
193201
ram: ramValue.length > 0 ? `${ramValue} MB` : '',
194-
disabled: disabled
202+
disabled: disabled,
203+
leaseduration: item.leaseduration
195204
}
196205
})
197206
},

ui/src/views/offering/AddComputeOffering.vue

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,13 @@
349349
</template>
350350
<a-switch v-model:checked="form.purgeresources"/>
351351
</a-form-item>
352-
<a-row :gutter="12" v-if="isLeaseFeatureEnabled">
352+
<a-form-item name="showLeaseOptions" ref="showLeaseOptions" v-if="isLeaseFeatureEnabled">
353+
<template #label>
354+
<tooltip-label :title="$t('label.isLeaseFeatureEnabled')"/>
355+
</template>
356+
<a-switch v-model:checked="showLeaseOptions" @change="onToggleLeaseData"/>
357+
</a-form-item>
358+
<a-row :gutter="12" v-if="showLeaseOptions">
353359
<a-col :md="12" :lg="12">
354360
<a-form-item name="leaseduration" ref="leaseduration">
355361
<template #label>
@@ -719,7 +725,7 @@ export default {
719725
qosType: '',
720726
isDomainAdminAllowedToInformTags: false,
721727
isLeaseFeatureEnabled: false,
722-
leaseduration: -1,
728+
showLeaseOptions: false,
723729
expiryActions: ['STOP', 'DESTROY']
724730
}
725731
},
@@ -835,17 +841,26 @@ export default {
835841
api('listConfigurations', params).then(json => {
836842
var value = json?.listconfigurationsresponse?.configuration?.[0].value || null
837843
this.isLeaseFeatureEnabled = value === 'true'
838-
839844
if (this.isLeaseFeatureEnabled) {
840845
var leasedurationParams = { name: 'instance.lease.duration', accountid: store.getters.userInfo.accountid }
841846
api('listConfigurations', leasedurationParams).then(json => {
842847
var value = json?.listconfigurationsresponse?.configuration?.[0].value || null
843848
this.leaseduration = value
844849
}).catch(() => {
845-
this.leaseduration = -1
850+
this.leaseduration = undefined
846851
}).finally(() => {
847852
this.form.leaseduration = this.leaseduration
848853
})
854+
855+
var leaseactionParams = { name: 'instance.lease.expiryaction', accountid: store.getters.userInfo.accountid }
856+
api('listConfigurations', leaseactionParams).then(json => {
857+
var value = json?.listconfigurationsresponse?.configuration?.[0].value || null
858+
this.leaseexpiryaction = value
859+
}).catch(() => {
860+
this.leaseexpiryaction = undefined
861+
}).finally(() => {
862+
this.form.leaseexpiryaction = this.leaseexpiryaction
863+
})
849864
}
850865
}).catch((error) => {
851866
this.$notifyError(error)
@@ -1002,7 +1017,6 @@ export default {
10021017
this.formRef.value.validate().then(() => {
10031018
const formRaw = toRaw(this.form)
10041019
const values = this.handleRemoveFields(formRaw)
1005-
console.log('test values: ', values)
10061020
var params = {
10071021
issystem: this.isSystem,
10081022
name: values.name,
@@ -1174,6 +1188,19 @@ export default {
11741188
return Promise.reject(this.$t('message.error.number'))
11751189
}
11761190
return Promise.resolve()
1191+
},
1192+
onToggleLeaseData () {
1193+
if (this.showLeaseOptions === false) {
1194+
this.form.leaseduration = undefined
1195+
this.form.leaseexpiryaction = undefined
1196+
} else {
1197+
if (this.form.leaseduration === undefined) {
1198+
this.form.leaseduration = this.leaseduration
1199+
}
1200+
if (this.form.leaseexpiryaction === undefined) {
1201+
this.form.leaseexpiryaction = this.leaseexpiryaction
1202+
}
1203+
}
11771204
}
11781205
}
11791206
}

0 commit comments

Comments
 (0)