Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cloud tenant filtering for various network object forms #1343

Merged
merged 8 commits into from May 24, 2017

Conversation

tzumainn
Copy link
Contributor

.then(getCloudTenantsByEms)
.catch(miqService.handleFailure);

miqService.sparkleOff();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sparkleOff here doesn't make sense, calling sparkleOn and sparkleOff in the same tick pretty much means it will never start to spin.

I guess you want to sparkleOff in getCloudTenantsByEms.

@@ -22,16 +22,21 @@
%h3
= _('Placement')
.form-horizontal
.form-group{"ng-if" => "networkRouterModel.ems_id"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably wanted to add ng-if to the next line, instead of adding an empty form-group?

@@ -105,4 +105,18 @@ ManageIQ.angular.app.controller('networkRouterFormController', ['$http', '$scope
$scope.available_subnets = data.available_subnets;
miqService.sparkleOff();
}

$scope.filterNetworkManagerChanged = function(id) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A method with this name already exists on line 64 (network_router)

@@ -66,4 +66,19 @@ ManageIQ.angular.app.controller('floatingIpFormController', ['$http', '$scope',
$scope.available_networks = data.available_networks;
miqService.sparkleOff();
}


$scope.filterNetworkManagerChanged = function(id) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A method with this name already exists on line 47 (floating_ip)

@himdel
Copy link
Contributor

himdel commented May 18, 2017

I'm also seeing a lot of the same code here being added to 5 or so places.

Any chance it could be shared? The views use different field names so maybe no point in doing a partial with magic params there.. but for example the JS code is always the same, and could be shared via miqService for example..

(Something like..

miqService.filterNetworkManagerChanged = function(scope) {
  return function(id) {
    miqService.sparkleOn();

    API.get("/api/providers/" + id + "/cloud_tenants?expand=resources&attributes=id,name")
      .then(getCloudTenantsByEms)
      .catch(miqService.handleFailure);
  };

  function getCloudTenantsByEms(data) {
    scope.available_tenants = data.resources;
    miqService.sparkleOff();
  }
};

(in miq_service.js)

And then you can do $scope.filterNetworkManagerChanged = miqService.filterNetworkManagerChanged($scope); in all those controllers and that's it :).

And maybe a similar thing could be done on the Ruby side?
)


EDIT: or maybe..

miqService.getProviderTenants = function(callback) {
  return function(id) {
    miqService.sparkleOn();

    API.get("/api/providers/" + id + "/cloud_tenants?expand=resources&attributes=id,name")
      .then(getCloudTenantsByEms)
      .catch(miqService.handleFailure);
  };

  function getCloudTenantsByEms(data) {
    callback(data);
    miqService.sparkleOff();
  }
};

...

$scope.filterNetworkManagerChanged = miqService.getProviderTenants(function(data) {
  $scope.available_tenants = data;
});

(If we want to be able to customize the field name on the controller, or add custom per-controller actions.)

@tzumainn
Copy link
Contributor Author

Thanks for the review! I've done some initial cleanup; I'll work on reducing code duplication next, and let you know when it's ready for another review.

@@ -66,6 +66,10 @@ ManageIQ.angular.app.controller('networkRouterFormController', ['$http', '$scope
$http.get('/network_router/network_router_networks_by_ems/' + id)
.then(getNetworkRouterFormByEmsData)
.catch(miqService.handleFailure);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@himdel I'm a bit confused as to how to refactor this function to use miqService.getProviderTenants - any hints? : )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, figured it out!

@tzumainn
Copy link
Contributor Author

@himdel I believe I've resolved the issues you brought up, so I think this is ready for another look. Thanks again for your comments, and just let me know if there's anything I'm missing!

@miq-bot
Copy link
Member

miq-bot commented May 19, 2017

This pull request is not mergeable. Please rebase and repush.

@@ -51,6 +51,10 @@ ManageIQ.angular.app.controller('floatingIpFormController', ['$http', '$scope',
$http.get('/floating_ip/networks_by_ems/' + id)
.then(getNetworkByEmsFormData)
.catch(miqService.handleFailure);

miqService.getProviderTenants(function(data) {
$scope.available_tenants = data.resources;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, just merged a PR converting floating ip to controllerAs.. This will need to be vm.available_tenants = data.resources now..

@@ -68,17 +68,20 @@
%h3
= _('Placement')
.form-horizontal
.form-group
.form-group{"ng-if" => "floatingIpModel.ems_id"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this one will be vm.floatingIpModel.ems_id

"required" => "",
:miqrequired => true,
:checkchange => true,
'ng-options' => 'tenant.id as tenant.name for tenant in available_tenants',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And vm.available_tenants.

@tzumainn
Copy link
Contributor Author

@himdel thanks for the heads up! changes made

@himdel
Copy link
Contributor

himdel commented May 19, 2017

@tzumainn And thanks for the quick fix :)

I will wait for travis and give this a spin in the UI but I think it looks good! 👍

@himdel
Copy link
Contributor

himdel commented May 22, 2017

@tzumainn Just one bug.. We need to deal with the undefined value - when you select a provider, and then change back to <Choose>, it will now generate a request to /api/providers/undefined/cloud_tenants?expand=resources&attributes=id,name (note that undefined), and error with "Invalid ExtManagementSystem id undefined specified".

Can you add some condition to handle that?

Perhaps something like...

this.getProviderTenants = function(callback) {
  return function(id) {
    if (! id) {
      callback([]);
      return;
    }

    miqService.sparkleOn();
......

@tzumainn
Copy link
Contributor Author

Ah, that makes sense - added the check!

@himdel
Copy link
Contributor

himdel commented May 22, 2017

The test failure is unrelated, but can you please fix that "Expected indentation of 8 spaces but found 1 tab" CC complains about? (Don't care about the others, but we really shouldn't be mixing tabs and spaces :).)

@tzumainn
Copy link
Contributor Author

@himdel Oh, whoops - fixed!

@miq-bot
Copy link
Member

miq-bot commented May 22, 2017

Checked commits tzumainn/manageiq-ui-classic@5b9f9b6~...dd2e9b5 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
6 files checked, 1 offense detected

app/controllers/application_controller/network.rb

@himdel himdel closed this May 23, 2017
@himdel himdel reopened this May 23, 2017
@himdel
Copy link
Contributor

himdel commented May 23, 2017

Thanks, LGTM, restarting travis 👍

@himdel himdel merged commit dc8cd44 into ManageIQ:master May 24, 2017
@himdel himdel added this to the Sprint 62 Ending Jun 5, 2017 milestone May 24, 2017
@tzumainn
Copy link
Contributor Author

@dclarizio I don't think this can make it into euwe easily, as there's quite a long line of dependencies and the UI has changed quite a bit since.

@@ -124,4 +124,23 @@ ManageIQ.angular.app.service('miqService', ['$timeout', '$document', '$q', funct

return $q.reject(e);
};

this.getProviderTenants = function(callback) {
return function(id) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@himdel @tzumainn I just happened to notice these functions in miqService that are very specific to a particular controller.
miqService needs to be as generic as possible I think.

@tzumainn Would it be possible to take these functions out of miqService and create a new service (tenantService maybe?) that you could inject in the angular controllers that need it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, this is specific to 4 different controllers, but yeah, maybe a separate service would make sense.

@tzumainn Any idea what's common in those 4 controllers? (Thinking about naming, should that be a CloudService or a NetworkingService or... :))

@tzumainn
Copy link
Contributor Author

I guess "CloudService" would make the most sense?

@simaishi
Copy link
Contributor

@tzumainn Marking as euwe/conflict... as you pointed out, there are conflicts in multiple files.

@dclarizio
Copy link

@dclarizio I don't think this can make it into euwe easily, as there's quite a long line of dependencies and the UI has changed quite a bit since.

@tzumainn well, then we either have to close the 5.7 BZ as WONTFIX or create a special euwe PR . . . up to you as you opened the BZ I think 😄

@tzumainn
Copy link
Contributor Author

tzumainn commented Jun 2, 2017

@miq-bot remove_label euwe/yes

@simaishi
Copy link
Contributor

simaishi commented Jun 8, 2017

@tzumainn Looks like some of the changes here depend on #791, which is fine/no. Please create a separate Fine specific PR (referencing this one).

@tzumainn
Copy link
Contributor Author

@simaishi Looks like #791 should be fine/yes now, so hopefully this can be merged without conflict!

simaishi pushed a commit that referenced this pull request Jun 14, 2017
Add cloud tenant filtering for various network object forms
(cherry picked from commit dc8cd44)

https://bugzilla.redhat.com/show_bug.cgi?id=1458377
@simaishi
Copy link
Contributor

Fine backport details:

$ git log -1
commit e42426967f90f057fbc0f23e1611c84a59c1349e
Author: Martin Hradil <himdel@seznam.cz>
Date:   Wed May 24 09:07:23 2017 +0000

    Merge pull request #1343 from tzumainn/network-tenant-filtering
    
    Add cloud tenant filtering for various network object forms
    (cherry picked from commit dc8cd44621f0515959ec6f274132205ee9b3a0a4)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1458377

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants