diff options
author | Stéphane Nguyen <stephane1.nguyen@orange.com> | 2016-11-25 18:03:16 +0100 |
---|---|---|
committer | zarrouk <mzarrouk.ext@orange.com> | 2017-01-19 20:40:24 +0100 |
commit | eddef8fa302ad32365ecc3d61d509a42558d8510 (patch) | |
tree | f904a74c03b39f93803c75c4b1c8e11ba6891746 | |
parent | 11f6e3de485b435ed82ec52712509286188e2f7e (diff) | |
download | horizon-eddef8fa302ad32365ecc3d61d509a42558d8510.tar.gz |
Snapshot not selected by default when launching it from images
In images tab, when launching an instance snapshot,
the images is not selected by default in the source
tab of the launch instance wizard.
Change-Id: I9c1bcdd4e22ebf7034146c14a43d8a405ae2a8be
Closes-Bug: #1644882
2 files changed, 47 insertions, 6 deletions
diff --git a/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/source/source.controller.js b/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/source/source.controller.js index 1a03ec879..391b8e711 100644 --- a/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/source/source.controller.js +++ b/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/source/source.controller.js @@ -340,6 +340,21 @@ } ); + var imageSnapshotsWatcher = $scope.$watchCollection( + function getImageSnapshots() { + return $scope.model.imageSnapshots; + }, + function onImageSnapshotsChange() { + $scope.initPromise.then(function () { + $scope.$applyAsync(function () { + if ($scope.launchContext.imageId) { + setSourceImageSnapshotWithId($scope.launchContext.imageId); + } + }); + }); + } + ); + var volumeWatcher = $scope.$watchCollection( function getVolumes() { return $scope.model.volumes; @@ -393,6 +408,7 @@ allocatedWatcher(); bootSourceWatcher(); imagesWatcher(); + imageSnapshotsWatcher(); volumeWatcher(); snapshotWatcher(); }); @@ -524,6 +540,18 @@ } } + function setSourceImageSnapshotWithId(id) { + var pre = findSourceById($scope.model.imageSnapshots, id); + if (pre) { + changeBootSource(bootSourceTypes.INSTANCE_SNAPSHOT, [pre]); + $scope.model.newInstanceSpec.source_type = { + type: bootSourceTypes.INSTANCE_SNAPSHOT, + label: gettext('Snapshot') + }; + ctrl.currentBootSource = bootSourceTypes.INSTANCE_SNAPSHOT; + } + } + function setSourceVolumeWithId(id) { var pre = findSourceById($scope.model.volumes, id); if (pre) { diff --git a/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/source/source.controller.spec.js b/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/source/source.controller.spec.js index 70f6b578f..b874c1332 100644 --- a/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/source/source.controller.spec.js +++ b/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/source/source.controller.spec.js @@ -52,7 +52,7 @@ allowedBootSources: [{type: 'image', label: 'Image'}], newInstanceSpec: { source: [], source_type: '' }, images: [ { id: 'image-1' }, { id: 'image-2' } ], - imageSnapshots: [], + imageSnapshots: [ { id: 'imageSnapshot-1' } ], volumes: [ { id: 'volume-1' }, { id: 'volume-2' } ], volumeSnapshots: [ {id: 'snapshot-2'} ], novaLimits: { @@ -180,6 +180,19 @@ }); }); + it('defaults source to imageSnapshot-1 if launchContext.imageId = imageSnapshot-1', + function() { + scope.launchContext = { imageId: 'imageSnapshot-1' }; + deferred.resolve(); + + $browser.defer.flush(); + + expect(ctrl.tableData.allocated[0]).toEqual({ id: 'imageSnapshot-1' }); + expect(scope.model.newInstanceSpec.source_type.type).toBe('snapshot'); + expect(ctrl.currentBootSource).toBe('snapshot'); + } + ); + it('defaults source to volume-2 if launchContext.volumeId = volume-2', function() { scope.launchContext = { volumeId: 'volume-2' }; deferred.resolve(); @@ -204,19 +217,19 @@ describe('Scope Functions', function() { describe('watches', function() { - beforeEach( function() { + beforeEach(function() { // Initialize the watchers with default data scope.model.newInstanceSpec.source_type = null; scope.model.allowedBootSources = [{type: 'test_type', label: 'test'}]; scope.$apply(); }); - it("establishes seven watches", function () { + it("establishes eight watches", function () { // Count calls to $watch (note: $watchCollection // also calls $watch) - expect(scope.$watch.calls.count()).toBe(7); + expect(scope.$watch.calls.count()).toBe(8); }); - it("establishes four watch collections", function () { - expect(scope.$watchCollection.calls.count()).toBe(4); + it("establishes five watch collections", function () { + expect(scope.$watchCollection.calls.count()).toBe(5); }); it('should set source type on new allowedbootsources', function() { expect(angular.equals(scope.model.newInstanceSpec.source_type, |