3535 v-model:value =" form.intervaltype"
3636 button-style =" solid"
3737 @change =" handleChangeIntervalType" >
38- <a-radio-button value =" hourly" >
38+ <a-radio-button value =" hourly" :disabled = " isIntervalDisabled('hourly') " >
3939 {{ $t('label.hourly') }}
4040 </a-radio-button >
41- <a-radio-button value =" daily" >
41+ <a-radio-button value =" daily" :disabled = " isIntervalDisabled('daily') " >
4242 {{ $t('label.daily') }}
4343 </a-radio-button >
44- <a-radio-button value =" weekly" >
44+ <a-radio-button value =" weekly" :disabled = " isIntervalDisabled('weekly') " >
4545 {{ $t('label.weekly') }}
4646 </a-radio-button >
47- <a-radio-button value =" monthly" >
47+ <a-radio-button value =" monthly" :disabled = " isIntervalDisabled('monthly') " >
4848 {{ $t('label.monthly') }}
4949 </a-radio-button >
5050 </a-radio-group >
5454 <a-form-item :label =" $t('label.time')" ref =" time" name =" time" >
5555 <a-input-number
5656 style =" width : 100% "
57+ :disabled =" isIntervalDisabled(form.intervaltype)"
5758 v-model:value =" form.time"
5859 :placeholder =" $t('label.minute.past.hour')"
5960 :min =" 1"
7071 <a-time-picker
7172 use12Hours
7273 format =" h:mm A"
74+ :disabled =" isIntervalDisabled(form.intervaltype)"
7375 v-model:value =" form.timeSelect"
7476 style =" width : 100% ;" />
7577 </a-form-item >
7981 <a-select
8082 v-model:value =" form['day-of-week']"
8183 showSearch
84+ :disabled =" isIntervalDisabled(form.intervaltype)"
8285 optionFilterProp =" label"
8386 :filterOption =" (input, option) => {
8487 return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0
9497 <a-select
9598 v-model:value =" form['day-of-month']"
9699 showSearch
100+ :disabled =" isIntervalDisabled(form.intervaltype)"
97101 optionFilterProp =" label"
98102 :filterOption =" (input, option) => {
99103 return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0
@@ -180,6 +184,10 @@ export default {
180184 type: Boolean ,
181185 default: false
182186 },
187+ dataSource: {
188+ type: Array ,
189+ required: true
190+ },
183191 resource: {
184192 type: Object ,
185193 required: true
@@ -210,6 +218,38 @@ export default {
210218 this .fetchTimeZone ()
211219 this .fetchBackupOffering ()
212220 },
221+ mounted () {
222+ if (this .form .intervaltype && this .isIntervalDisabled (this .form .intervaltype )) {
223+ const nextAvailable = this .getNextAvailableIntervalType (this .form .intervaltype )
224+ if (nextAvailable) {
225+ this .form .intervaltype = nextAvailable
226+ this .handleChangeIntervalType ()
227+ }
228+ }
229+ },
230+ watch: {
231+ dataSource: {
232+ handler () {
233+ if (this .form .intervaltype && this .getNextAvailableIntervalType && this .isIntervalDisabled (this .form .intervaltype )) {
234+ const nextAvailable = this .getNextAvailableIntervalType (this .form .intervaltype )
235+ if (nextAvailable) {
236+ this .form .intervaltype = nextAvailable
237+ this .handleChangeIntervalType ()
238+ }
239+ }
240+ },
241+ deep: true
242+ },
243+ ' form.intervaltype' (newVal) {
244+ if (newVal && this .getNextAvailableIntervalType && this .isIntervalDisabled (newVal)) {
245+ const nextAvailable = this .getNextAvailableIntervalType (newVal)
246+ if (nextAvailable) {
247+ this .form .intervaltype = nextAvailable
248+ this .handleChangeIntervalType ()
249+ }
250+ }
251+ }
252+ },
213253 inject: [' refreshSchedule' , ' closeSchedule' ],
214254 computed: {
215255 isQuiesceVmSupported () {
@@ -274,18 +314,38 @@ export default {
274314 })
275315 }
276316 },
277- handleChangeIntervalType (e ) {
278- switch (this .form .intervaltype ) {
279- case ' weekly' :
280- this .fetchDayOfWeek ()
281- break
282- case ' monthly' :
283- this .intervalValue = ' MONTHLY'
284- this .fetchDayOfMonth ()
285- break
286- default :
287- break
317+ handleChangeIntervalType () {
318+ if (this .form .intervaltype === ' weekly' ) {
319+ this .fetchDayOfWeek ()
320+ } else if (this .form .intervaltype === ' monthly' ) {
321+ this .fetchDayOfMonth ()
322+ }
323+ },
324+ getNextAvailableIntervalType (currentIntervalType ) {
325+ const intervalTypes = [' hourly' , ' daily' , ' weekly' , ' monthly' ]
326+ const currentIndex = intervalTypes .indexOf (currentIntervalType ? currentIntervalType .toLowerCase () : ' ' )
327+ const startIndex = currentIndex >= 0 ? currentIndex : - 1
328+
329+ for (let i = 1 ; i <= intervalTypes .length ; i++ ) {
330+ const nextIndex = (startIndex + i) % intervalTypes .length
331+ const nextIntervalType = intervalTypes[nextIndex]
332+
333+ if (! this .isIntervalDisabled (nextIntervalType)) {
334+ return nextIntervalType
335+ }
336+ }
337+ return null
338+ },
339+ isIntervalDisabled (intervalType ) {
340+ intervalType = intervalType .toUpperCase ()
341+ if (this .dataSource ? .length === 0 ) {
342+ return false
343+ }
344+ const dataSource = this .dataSource .filter (item => item .intervaltype === intervalType)
345+ if (dataSource && dataSource .length > 0 ) {
346+ return true
288347 }
348+ return false
289349 },
290350 handleSubmit (e ) {
291351 if (this .actionLoading ) return
@@ -294,7 +354,7 @@ export default {
294354 const values = this .handleRemoveFields (formRaw)
295355 const params = {}
296356 params .virtualmachineid = this .resource .id
297- params .intervaltype = values .intervaltype
357+ params .intervaltype = values .intervaltype . toUpperCase ()
298358 params .maxbackups = values .maxbackups
299359 params .timezone = values .timezone
300360 if (values .quiescevm ) {
0 commit comments