6464 <a-select
6565 v-else
6666 v-decorator =" ['zoneid', {
67+ initialValue: selectedZone,
6768 rules: [{ required: true, message: `${$t('message.error.select')}` }]
6869 }]"
6970 showSearch
@@ -767,8 +768,8 @@ export default {
767768 disksize: null
768769 },
769770 options: {
770- templates: [] ,
771- isos: [] ,
771+ templates: {} ,
772+ isos: {} ,
772773 hypervisors: [],
773774 serviceOfferings: [],
774775 diskOfferings: [],
@@ -834,16 +835,6 @@ export default {
834835 defaultnetworkid: ' ' ,
835836 networkConfig: [],
836837 dataNetworkCreated: [],
837- tabList: [
838- {
839- key: ' templateid' ,
840- tab: this .$t (' label.templates' )
841- },
842- {
843- key: ' isoid' ,
844- tab: this .$t (' label.isos' )
845- }
846- ],
847838 tabKey: ' templateid' ,
848839 dataPreFill: {},
849840 showDetails: false ,
@@ -1054,9 +1045,40 @@ export default {
10541045 templateConfigurationExists () {
10551046 return this .vm .templateid && this .templateConfigurations && this .templateConfigurations .length > 0
10561047 },
1048+ templateId () {
1049+ return this .$route .query .templateid || null
1050+ },
1051+ isoId () {
1052+ return this .$route .query .isoid || null
1053+ },
10571054 networkId () {
10581055 return this .$route .query .networkid || null
10591056 },
1057+ tabList () {
1058+ let tabList = []
1059+ if (this .templateId ) {
1060+ tabList = [{
1061+ key: ' templateid' ,
1062+ tab: this .$t (' label.templates' )
1063+ }]
1064+ } else if (this .isoId ) {
1065+ tabList = [{
1066+ key: ' isoid' ,
1067+ tab: this .$t (' label.isos' )
1068+ }]
1069+ } else {
1070+ tabList = [{
1071+ key: ' templateid' ,
1072+ tab: this .$t (' label.templates' )
1073+ },
1074+ {
1075+ key: ' isoid' ,
1076+ tab: this .$t (' label.isos' )
1077+ }]
1078+ }
1079+
1080+ return tabList
1081+ },
10601082 showSecurityGroupSection () {
10611083 return (this .networks .length > 0 && this .zone .securitygroupsenabled ) || (this .zone && this .zone .networktype === ' Basic' )
10621084 },
@@ -1275,12 +1297,57 @@ export default {
12751297 },
12761298 fillValue (field ) {
12771299 this .form .getFieldDecorator ([field], { initialValue: this .dataPreFill [field] })
1300+ this .form .setFieldsValue ({ [field]: this .dataPreFill [field] })
1301+ },
1302+ fetchZoneByQuery () {
1303+ return new Promise (resolve => {
1304+ let zones = []
1305+ let apiName = ' '
1306+ const params = {}
1307+ if (this .templateId ) {
1308+ apiName = ' listTemplates'
1309+ params .listall = true
1310+ params .templatefilter = ' all'
1311+ params .id = this .templateId
1312+ } else if (this .isoId ) {
1313+ params .listall = true
1314+ params .isofilter = ' all'
1315+ params .id = this .isoId
1316+ apiName = ' listIsos'
1317+ } else if (this .networkId ) {
1318+ params .listall = true
1319+ params .id = this .networkId
1320+ apiName = ' listNetworks'
1321+ }
1322+
1323+ api (apiName, params).then (json => {
1324+ let objectName
1325+ const responseName = [apiName .toLowerCase (), ' response' ].join (' ' )
1326+ for (const key in json[responseName]) {
1327+ if (key === ' count' ) {
1328+ continue
1329+ }
1330+ objectName = key
1331+ break
1332+ }
1333+ const data = json? .[responseName]? .[objectName] || []
1334+ zones = data .map (item => item .zoneid )
1335+ return resolve (zones)
1336+ }).catch (() => {
1337+ return resolve (zones)
1338+ })
1339+ })
12781340 },
1279- fetchData () {
1280- this .fetchZones ()
1341+ async fetchData () {
1342+ const zones = await this .fetchZoneByQuery ()
1343+ if (zones && zones .length === 1 ) {
1344+ this .selectedZone = zones[0 ]
1345+ this .dataPreFill .zoneid = zones[0 ]
1346+ }
12811347 if (this .dataPreFill .zoneid ) {
12821348 this .fetchDataByZone (this .dataPreFill .zoneid )
12831349 } else {
1350+ this .fetchZones (null , zones)
12841351 _ .each (this .params , (param , name ) => {
12851352 if (param .isLoad ) {
12861353 this .fetchOptions (param, name)
@@ -1304,16 +1371,8 @@ export default {
13041371 },
13051372 async fetchDataByZone (zoneId ) {
13061373 this .fillValue (' zoneid' )
1307- this .options .zones = await this .fetchZones ()
1308- this .zoneId = zoneId
1309- this .zoneSelected = true
1310- this .tabKey = ' templateid'
1311- await _ .each (this .params , (param , name ) => {
1312- if (! (' isLoad' in param) || param .isLoad ) {
1313- this .fetchOptions (param, name, [' zones' ])
1314- }
1315- })
1316- await this .fetchAllTemplates ()
1374+ this .options .zones = await this .fetchZones (zoneId)
1375+ this .onSelectZoneId (zoneId)
13171376 },
13181377 fetchBootTypes () {
13191378 this .options .bootTypes = [
@@ -1352,7 +1411,25 @@ export default {
13521411 this .fetchOptions (param, ' networks' )
13531412 },
13541413 resetData () {
1355- this .vm = {}
1414+ this .vm = {
1415+ name: null ,
1416+ zoneid: null ,
1417+ zonename: null ,
1418+ hypervisor: null ,
1419+ templateid: null ,
1420+ templatename: null ,
1421+ keyboard: null ,
1422+ keypair: null ,
1423+ group: null ,
1424+ affinitygroupids: [],
1425+ affinitygroup: [],
1426+ serviceofferingid: null ,
1427+ serviceofferingname: null ,
1428+ ostypeid: null ,
1429+ ostypename: null ,
1430+ rootdisksize: null ,
1431+ disksize: null
1432+ }
13561433 this .zoneSelected = false
13571434 this .form .resetFields ()
13581435 this .fetchData ()
@@ -1734,12 +1811,25 @@ export default {
17341811 })
17351812 })
17361813 },
1737- fetchZones () {
1814+ fetchZones (zoneId , listZoneAllow ) {
1815+ this .zones = []
17381816 return new Promise ((resolve ) => {
17391817 this .loading .zones = true
17401818 const param = this .params .zones
1741- api (param .list , { listall: true , showicon: true }).then (json => {
1742- this .zones = json .listzonesresponse .zone || []
1819+ const args = { listall: true , showicon: true }
1820+ if (zoneId) args .id = zoneId
1821+ api (param .list , args).then (json => {
1822+ const zoneResponse = json .listzonesresponse .zone || []
1823+ if (listZoneAllow && listZoneAllow .length > 0 ) {
1824+ zoneResponse .map (zone => {
1825+ if (listZoneAllow .includes (zone .id )) {
1826+ this .zones .push (zone)
1827+ }
1828+ })
1829+ } else {
1830+ this .zones = zoneResponse
1831+ }
1832+
17431833 resolve (this .zones )
17441834 }).catch (function (error ) {
17451835 console .log (error .stack )
@@ -1821,6 +1911,7 @@ export default {
18211911 args .templatefilter = templateFilter
18221912 args .details = ' all'
18231913 args .showicon = ' true'
1914+ args .id = this .templateId
18241915
18251916 return new Promise ((resolve , reject ) => {
18261917 api (' listTemplates' , args).then ((response ) => {
@@ -1841,6 +1932,7 @@ export default {
18411932 args .isoFilter = isoFilter
18421933 args .bootable = true
18431934 args .showicon = ' true'
1935+ args .id = this .isoId
18441936
18451937 return new Promise ((resolve , reject ) => {
18461938 api (' listIsos' , args).then ((response ) => {
@@ -1894,10 +1986,9 @@ export default {
18941986 })
18951987 },
18961988 filterOption (input , option ) {
1897- console .log (option)
1898- // return (
1899- // option.componentOptions.children[0].text.toUpperCase().indexOf(input.toUpperCase()) >= 0
1900- // )
1989+ return (
1990+ option .componentOptions .children [0 ].text .toUpperCase ().indexOf (input .toUpperCase ()) >= 0
1991+ )
19011992 },
19021993 onSelectZoneId (value ) {
19031994 this .dataPreFill = {}
@@ -1916,6 +2007,9 @@ export default {
19162007 isoid: undefined
19172008 })
19182009 this .tabKey = ' templateid'
2010+ if (this .isoId ) {
2011+ this .tabKey = ' isoid'
2012+ }
19192013 _ .each (this .params , (param , name ) => {
19202014 if (this .networkId && name === ' networks' ) {
19212015 param .options = {
@@ -1926,7 +2020,11 @@ export default {
19262020 this .fetchOptions (param, name, [' zones' ])
19272021 }
19282022 })
1929- this .fetchAllTemplates ()
2023+ if (this .tabKey === ' templateid' ) {
2024+ this .fetchAllTemplates ()
2025+ } else {
2026+ this .fetchAllIsos ()
2027+ }
19302028 },
19312029 onSelectPodId (value ) {
19322030 this .podId = value
0 commit comments