Gilad Chaplik has uploaded a new change for review. Change subject: webadmin,userportal: filter quota in quota dropdown (#847511) ......................................................................
webadmin,userportal: filter quota in quota dropdown (#847511) https://bugzilla.redhat.com/847511 quota drop down should be populated with the backend query, but in case the list of quota is missing the current quota of the object, it will be inserted to the list automatically. mainly used in edit and in the user portal: edit an object (e.g. vm) the object has a quota that the user doesn't have consume quota on. so the list that will be fetched from the server won't have that quota, so in the ui we will insert it to the list and select it by default Change-Id: I823c82c00f632258f7b885ae2ef5a7cb833a0762 Signed-off-by: Gilad Chaplik <gchap...@redhat.com> --- M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/DiskModel.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ExistingVmModelBehavior.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/NewTemplateVmModelBehavior.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/NewVmModelBehavior.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/PoolModelBehaviorBase.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/TemplateVmModelBehavior.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmModelBehaviorBase.java 7 files changed, 50 insertions(+), 26 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/84/7184/1 diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/DiskModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/DiskModel.java index b609d97..7a00116 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/DiskModel.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/DiskModel.java @@ -539,7 +539,7 @@ }); } - private void getStorageQuota(final Guid defaultQuotaId) { + private void getStorageQuota(final Guid defaultQuota) { storage_domains storageDomain = (storage_domains) getStorageDomain().getSelectedItem(); if (storageDomain != null) { Frontend.RunQuery(VdcQueryType.GetAllRelevantQuotasForStorage, @@ -549,18 +549,30 @@ @Override public void OnSuccess(Object innerModel, Object innerReturnValue) { - ArrayList<Quota> list = + ArrayList<Quota> quotaList = (ArrayList<Quota>) ((VdcQueryReturnValue) innerReturnValue).getReturnValue(); - if (list != null) { - getQuota().setItems(list); - if (defaultQuotaId != null) { - for (Quota quota : list) { - if (quota.getId().equals(defaultQuotaId)) { - getQuota().setSelectedItem(quota); - break; - } + if (quotaList != null && !quotaList.isEmpty()) { + getQuota().setItems(quotaList); + } + if (defaultQuota != null) { + boolean hasQuotaInList = false; + for (Quota quota : quotaList) { + if (quota.getId().equals(defaultQuota)) { + getQuota().setSelectedItem(quota); + hasQuotaInList = true; + break; } } + if (!hasQuotaInList) { + Quota quota = new Quota(); + quota.setId(defaultQuota); + if (getDisk() instanceof DiskImageBase) { + quota.setQuotaName(((DiskImageBase) getDisk()).getQuotaName()); + } + quotaList.add(quota); + getQuota().setItems(quotaList); + getQuota().setSelectedItem(quota); + } } } })); diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ExistingVmModelBehavior.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ExistingVmModelBehavior.java index 349de48..dfb3925 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ExistingVmModelBehavior.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ExistingVmModelBehavior.java @@ -194,7 +194,7 @@ UpdateDefaultHost(); UpdateCustomProperties(); UpdateNumOfSockets(); - updateQuotaByCluster(vm.getQuotaId()); + updateQuotaByCluster(vm.getQuotaId(), vm.getQuotaName()); updateCpuPinningVisibility(); } diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/NewTemplateVmModelBehavior.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/NewTemplateVmModelBehavior.java index 2675ebe..1fe8c36 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/NewTemplateVmModelBehavior.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/NewTemplateVmModelBehavior.java @@ -153,7 +153,6 @@ if (disk.getDiskStorageType() == DiskStorageType.IMAGE) { DiskImage diskImage = (DiskImage) disk; - EntityModel size = new EntityModel(); size.setEntity(diskImage.getSizeInGigabytes()); diskModel.setSize(size); @@ -179,7 +178,7 @@ @Override public void Cluster_SelectedItemChanged() { - updateQuotaByCluster(vm.getQuotaId()); + updateQuotaByCluster(null, null); } @Override diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/NewVmModelBehavior.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/NewVmModelBehavior.java index b9e17f3..9118a78 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/NewVmModelBehavior.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/NewVmModelBehavior.java @@ -187,7 +187,7 @@ UpdateCustomProperties(); UpdateMinAllocatedMemory(); UpdateNumOfSockets(); - updateQuotaByCluster(null); + updateQuotaByCluster(null, ""); updateCpuPinningVisibility(); } diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/PoolModelBehaviorBase.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/PoolModelBehaviorBase.java index 2aa3a48..b616090 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/PoolModelBehaviorBase.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/PoolModelBehaviorBase.java @@ -107,7 +107,7 @@ protected void setupWindowModelFrom(VmBase vmBase) { if (vmBase != null) { - updateQuotaByCluster(vmBase.getQuotaId()); + updateQuotaByCluster(vmBase.getQuotaId(), vmBase.getQuotaName()); // Copy VM parameters from template. getModel().getOSType().setSelectedItem(vmBase.getos()); getModel().getNumOfSockets().setEntity(vmBase.getnum_of_sockets()); @@ -216,7 +216,8 @@ UpdateMinAllocatedMemory(); UpdateNumOfSockets(); if ((VmTemplate) getModel().getTemplate().getSelectedItem() != null) { - updateQuotaByCluster(((VmTemplate) getModel().getTemplate().getSelectedItem()).getQuotaId()); + VmTemplate template = (VmTemplate) getModel().getTemplate().getSelectedItem(); + updateQuotaByCluster(template.getQuotaId(), template.getQuotaName()); } } diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/TemplateVmModelBehavior.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/TemplateVmModelBehavior.java index 4ecd830..f4a102e 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/TemplateVmModelBehavior.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/TemplateVmModelBehavior.java @@ -108,7 +108,7 @@ { UpdateDefaultHost(); UpdateNumOfSockets(); - updateQuotaByCluster(template.getQuotaId()); + updateQuotaByCluster(template.getQuotaId(), template.getQuotaName()); } @Override diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmModelBehaviorBase.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmModelBehaviorBase.java index f989182..cd15931 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmModelBehaviorBase.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmModelBehaviorBase.java @@ -138,7 +138,7 @@ } - private List<Iterable<Entry<String, String>>> cachedTimeZones = Arrays.asList(null, null); + private final List<Iterable<Entry<String, String>>> cachedTimeZones = Arrays.asList(null, null); final int windowsTimezones = 0; final int generalTimezones = 1; @@ -181,7 +181,7 @@ { getModel().getTimeZone() .setSelectedItem(Linq.FirstOrDefault(cachedTimeZones.get(index), - new Linq.TimeZonePredicate(oldTimeZoneKey))); + new Linq.TimeZonePredicate(oldTimeZoneKey))); } else { @@ -249,15 +249,15 @@ protected void InitPriority(int priority) { - AsyncDataProvider.GetMaxVmPriority(new AsyncQuery(new Object[] {getModel(), priority}, + AsyncDataProvider.GetMaxVmPriority(new AsyncQuery(new Object[] { getModel(), priority }, new INewAsyncCallback() { @Override public void OnSuccess(Object target, Object returnValue) { - Object[] array = (Object[])target; - UnitVmModel model = (UnitVmModel)array[0]; - int vmPriority = (Integer)array[1]; - cachedMaxPriority = (Integer)returnValue; + Object[] array = (Object[]) target; + UnitVmModel model = (UnitVmModel) array[0]; + int vmPriority = (Integer) array[1]; + cachedMaxPriority = (Integer) returnValue; int value = AsyncDataProvider.GetRoundedPriority(vmPriority, cachedMaxPriority); EntityModel tempVar = new EntityModel(); @@ -703,7 +703,7 @@ return list; } - protected void updateQuotaByCluster(final Guid defaultQuota) { + protected void updateQuotaByCluster(final Guid defaultQuota, final String quotaName) { if (getModel().getQuota().getIsAvailable()) { VDSGroup cluster = (VDSGroup) getModel().getCluster().getSelectedItem(); if (cluster == null) { @@ -718,14 +718,26 @@ UnitVmModel vmModel = (UnitVmModel) model; ArrayList<Quota> quotaList = (ArrayList<Quota>) ((VdcQueryReturnValue) returnValue).getReturnValue(); - vmModel.getQuota().setItems(quotaList); + if (quotaList != null && !quotaList.isEmpty()) { + vmModel.getQuota().setItems(quotaList); + } if (defaultQuota != null) { + boolean hasQuotaInList = false; for (Quota quota : quotaList) { if (quota.getId().equals(defaultQuota)) { vmModel.getQuota().setSelectedItem(quota); + hasQuotaInList = true; break; } } + if (!hasQuotaInList) { + Quota quota = new Quota(); + quota.setId(defaultQuota); + quota.setQuotaName(quotaName); + quotaList.add(quota); + vmModel.getQuota().setItems(quotaList); + vmModel.getQuota().setSelectedItem(quota); + } } } })); -- To view, visit http://gerrit.ovirt.org/7184 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I823c82c00f632258f7b885ae2ef5a7cb833a0762 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Gilad Chaplik <gchap...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches