-
Notifications
You must be signed in to change notification settings - Fork 356
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
Network Router: Use API; Fix fixed IPs subnet #2422
Conversation
Looks like maybe the routes for |
@mansam, right, was on my list but forgot. Thanks |
@mansam, I removed the routes, thanks. |
More PRs to follow for the controller to component' and then move the rest of the http requests (create/update/delete) to API only. |
@miq-bot add_label refactoring |
@mansam, @himdel, @martinpovolny, could you please assign someone for review please. Thanks |
@AparnaKarve, @Hyperkid123, @ZitaNemeckova : please, review |
.catch(miqService.handleFailure); | ||
API.get("/api/network_routers/" + networkRouterFormId + "?attributes=name,ems_id,admin_state_up,cloud_network_id,extra_attributes,cloud_tenant,ext_management_system,cloud_subnets").then(function(data) { | ||
Object.assign(vm.networkRouterModel, data); | ||
if (data.extra_attributes.external_gateway_info && data.extra_attributes.external_gateway_info !== {}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be careful {} === {}
is always false
. You can use lodash function _.isEmpty(data.extra_attributes.external_gateway_info)
to find out if it is an empty hash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, using lodash, thanks
Buttons Edit: Resolved. Code climate issues can be ignored. Code wise: Looking for values at Not sure how much it should be enforced... But there is missing |
|
||
var getCloudSubnetsByNetworkID = function(id) { | ||
if (id) { | ||
API.get("/api/cloud_subnets?expand=resources&attributes=name,ems_ref&filter[]=cloud_network_id=" + id).then(function(data) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using better vm.modelCopy after rebase.
I've started using init() in other places, done it here too.
Not using angularForm data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing return
} | ||
|
||
var getCloudNetworksByEms = function(id) { | ||
if (id) { | ||
API.get("/api/cloud_networks?expand=resources&attributes=name,ems_ref&filter[]=external_facing=true&filter[]=ems_id=" + id).then(function(data) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to wait for API call to be finished before the next then is called it should return Promise
like this return API.get(...
and return getCloudNetworksByEms(...
when you call it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using return with Promise
allows to pass the value to the next then
, there is not need here for passing such data which only populate fields (or select lists).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't clear, sorry :) It's not about the data being sent back but about having control over them and knowing that you already have them. You want to populate fields before you display form and switch off spinner. Without suggested return
s there is no guarantee that all fields will be populated before user sees them and they may change under his nose. Please add return
s :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you mean with the chaining happening only if Promise is returned. Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Misssing return
} | ||
}; | ||
|
||
var getSubnetByRef = function(ref) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above too :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing return
} | ||
}).then(function() { | ||
if (vm.networkRouterModel.external_gateway) { | ||
getSubnetByRef(vm.networkRouterModel.extra_attributes.external_gateway_info.external_fixed_ips[0].subnet_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return getSubnetByRef(...
so it waits on Promise
that you should return from this function. If you want one .then
to be finished before next one starts.
}).catch(miqService.handleFailure); | ||
} | ||
}; | ||
|
||
vm.addClicked = function() { | ||
var url = 'create/new' + '?button=add'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be one string. No need for +
. Could you please fix it? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@ZitaNemeckova, please review all suggestions have been addressed. I can't wait to have migrated all those networks controller to components, especially from a test view point. |
vm.available_tenants = data.resources; | ||
})(id); | ||
} | ||
miqService.sparkleOff(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also here is no use of Promise
and no guarantee that all data will be set before miqService.sparkleOff()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var providerTenants = miqService.getProviderTenants(function(data) {
vm.available_tenants = data.resources;
})(id);
Promise.all([getCloudNetworksByEms(id), providerTenants])
.then(miqService.sparkleOff)
But both must return API calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes the sparkleOn/Off flow was really bad, and this is actually quite messy in general. Since API request are already Promise I have simplified it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sparkleOn/sparkleOff pair is still not doing anything and can be removed :)
(Or better yet, fixed to do the right thing :))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@gildub I cannot add new network Router. Always ends with this error:
I see only difference in send data |
@gildub There are still |
Retested create/update |
This pull request is not mergeable. Please rebase and repush. |
Checked commits https://github.com/gildub/manageiq-ui-classic/compare/f7747a1a774e1b833b0b2a58ea923d2cb8f01dde~...3633a9fdc4db85921d55eadb0639062f8e7cf3d2 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 |
The reason is: at creation time there are no Provider relationship yet and therefore there are no The same approach has been used in other places. |
"ng-change" => "vm.filterCloudNetworkChanged(vm.networkRouterModel.cloud_network_id)", | ||
"pf-select" => true, | ||
"ng-selected" => "vm.networkRouterModel.cloud_network_id", | ||
"ng-required" => "vm.networkRouterModel.enable_snat == true", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gildub Did you remove ng-required
on purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ZitaNemeckova, yes the network is part of the gateway information which is optional
The form works fine. I could not find anything that is not mentioned here. But i would appreciate some specs for the JavaScript side. Even though there is just a small amount of logic, i think it would be nice to cover it and make it a bit more future proof. |
@Hyperkid123, the driver here is to re-factor to add API get, the next step will be to replace with controller to component conversion (such as [1] for example) where the framework for testing is much better therefore I think it might not worth the effort. [1] #2828 |
@gildub that sounds great |
@ZitaNemeckova, @Hyperkid123, then if everybody is happy any chance we can merge? Thanks |
I think its fine. There some codeclimate issues that should be fixed though (the missing semicolons for example, not the similar code warnings etc.). But i think it should be merged. |
Networks > Network Routers
Replaces http calls in RoR controller by API calls
See #737
Also:
Before:
Now: