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

Refactor - Replace .success calls with .then/.catch #13

Merged
merged 11 commits into from
Jan 13, 2017

Conversation

AparnaKarve
Copy link
Contributor

@AparnaKarve AparnaKarve commented Dec 22, 2016

With Angular 1.6+, the $http .success and $http .error would not be supported anymore.

The PR currently addresses the .success calls in one controller.
The other controllers will follow suit.

Tackling the following controllers in this PR:

  • auth_key_pair_cloud_controller.js
  • ems_common_form_controller.js
  • host_form_controller.js
  • schedule_form_controller.js

@AparnaKarve
Copy link
Contributor Author

@miq-bot add_label wip,refactor

@miq-bot
Copy link
Member

miq-bot commented Dec 22, 2016

@AparnaKarve Cannot apply the following label because they are not recognized: refactor

@miq-bot miq-bot added the wip label Dec 22, 2016
@AparnaKarve AparnaKarve force-pushed the angular16_prep_refactor branch 2 times, most recently from 4f660e0 to b17c135 Compare January 4, 2017 01:38
@AparnaKarve AparnaKarve changed the title [WIP] Refactor - Preparing for a future angular version [WIP] Refactor - Replace .success calls with .then/.catch Jan 4, 2017
@AparnaKarve
Copy link
Contributor Author

@himdel Let me know what you think of these changes. If this looks good, I would like to replicate this approach across all angular controllers.

I've also tried to address some of the CodeClimate issues, specifically the ones that were easily addressable and pertaining to the changes made in this PR.

}
$scope.actionUrl = $scope.newRecord ? $scope.createUrl : $scope.updateUrl;
$scope.currentTab = "default";

function getEmsFormIdDataComplete(response, status, headers, config) {
Copy link
Contributor

Choose a reason for hiding this comment

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

(response, status, headers, config)

The docs say that the handler takes only one parameter, which is an object containing data, status, headers, config and statusText - not 4. Or am I reading it wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. I'll definitely go with what the Angular docs say.

My source was this, which could be outdated.


function getEmsFormDataFailed(e) {
miqService.sparkleOff();
console.log(e.message);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd do (e && e.message) || e here (or something like that): there's no guarantee the error will have a message field. (There is if it was a failure in http, but if the then function throws an exception, that one doesn't have to have a message.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We would always have e, although e.message could be questionable.

So I'll change it to --

if (e.message) {
  console.log(e.message);
}

@himdel
Copy link
Contributor

himdel commented Jan 5, 2017

@AparnaKarve the approach looks solid, except for that args oversight I have nothing to add 👍 :)

@AparnaKarve
Copy link
Contributor Author

@AparnaKarve the approach looks solid, except for that args oversight I have nothing to add 👍 :)

Thanks! I've implemented your suggestions.
I will now work on the other controllers.

@AparnaKarve
Copy link
Contributor Author

@himdel I'm thinking of dividing this task into smaller chunks. Here's why --

$ git grep -l "\.success(" *.js
app/assets/javascripts/controllers/auth_key_pair_cloud/auth_key_pair_cloud_controller.js
app/assets/javascripts/controllers/cloud_network/cloud_network_form_controller.js
app/assets/javascripts/controllers/cloud_subnet/cloud_subnet_form_controller.js
app/assets/javascripts/controllers/cloud_tenant/cloud_tenant_form_controller.js
app/assets/javascripts/controllers/cloud_topology/cloud_topology_controller.js
app/assets/javascripts/controllers/cloud_volume/cloud_volume_form_controller.js
app/assets/javascripts/controllers/configuration/time_profile_form_controller.js
app/assets/javascripts/controllers/container_dashboard/container_dashboard_controller.js
app/assets/javascripts/controllers/container_live_dashboard/container_live_dashboard_controller.js
app/assets/javascripts/controllers/container_topology/container_topology_controller.js
app/assets/javascripts/controllers/ems_common/ems_common_form_controller.js
app/assets/javascripts/controllers/ems_infra_dashboard/ems_infra_dashboard_controller.js
app/assets/javascripts/controllers/floating_ip/floating_ip_form_controller.js
app/assets/javascripts/controllers/host/host_form_controller.js
app/assets/javascripts/controllers/host_aggregate/host_aggregate_form_controller.js
app/assets/javascripts/controllers/infra_topology/infra_topology_controller.js
app/assets/javascripts/controllers/middleware_topology/middleware_topology_controller.js
app/assets/javascripts/controllers/network_router/network_router_form_controller.js
app/assets/javascripts/controllers/network_topology/network_topology_controller.js
app/assets/javascripts/controllers/ops/diagnostics_database_form_controller.js
app/assets/javascripts/controllers/ops/log_collection_form_controller.js
app/assets/javascripts/controllers/ops/pglogical_replication_form_controller.js
app/assets/javascripts/controllers/ops/tenant_form_controller.js
app/assets/javascripts/controllers/ops/tenant_quota_form_controller.js
app/assets/javascripts/controllers/orchestration_template/orchestration_template_copy_controller.js
app/assets/javascripts/controllers/ownership/ownership_form_controller.js
app/assets/javascripts/controllers/provider_foreman/provider_foreman_form_controller.js
app/assets/javascripts/controllers/reconfigure/reconfigure_form_controller.js
app/assets/javascripts/controllers/retirement/retirement_form_controller.js
app/assets/javascripts/controllers/schedule/schedule_form_controller.js
app/assets/javascripts/controllers/security_group/security_group_form_controller.js
app/assets/javascripts/controllers/service/service_form_controller.js
app/assets/javascripts/controllers/vm_cloud/vm_cloud_associate_floating_ip_form_controller.js
app/assets/javascripts/controllers/vm_cloud/vm_cloud_disassociate_floating_ip_form_controller.js
app/assets/javascripts/controllers/vm_cloud/vm_cloud_evacuate_form_controller.js
app/assets/javascripts/controllers/vm_cloud/vm_cloud_live_migrate_form_controller.js
app/assets/javascripts/miq_tree.js

$ git grep -l "\.success(" *.js|wc -l
      37

So close to 37 controllers need to be addressed.
It will be one ginormous PR if I tackle all of them in one go (and I for one know how you feel about such PRs 😄 )
Hence let's do this in baby steps (about 4 to 5 controllers in each PR) for an easier review. That said, I've covered 4 controllers in this PR.

@himdel
Copy link
Contributor

himdel commented Jan 10, 2017

@AparnaKarve agreed there, split any way you like ;)

Just one thing I'm noticing now.. can you move that error handler function to miqService please? (Or somewhere so that we don't define the same thing in all of the controllers.)

@AparnaKarve
Copy link
Contributor Author

can you move that error handler function to miqService please? (Or somewhere so that we don't define the same thing in all of the controllers.)

Yes, I thought about that too...moving the error handler to miqService, but somehow it didn't seem like an angular service material. (it seems like a very controller thing)
Wish there was a way to define a base controller where we could have all this common controller stuff.
Anyway, if I don't come up with a better approach, I guess I will include it in miqService for now.
Thanks.

@himdel
Copy link
Contributor

himdel commented Jan 10, 2017

@AparnaKarve yeah, kinda agreed but better there than in every controller :).

Or, if you're really unconfortable with putting this in a service, an alternative would be a global function, defined in miq_angular_application - just not sure that's better :).

As for a common controller .. yeah, agreed completely, in fact I was planning to do a BaseFormController (or something) ..but I guess it really makes sense only after we move to es6 and can use es6 classes. (We can do it before, but .. possibly confusing syntax..)

@AparnaKarve
Copy link
Contributor Author

in fact I was planning to do a BaseFormController (or something) ..but I guess it really makes sense only after we move to es6 and can use es6 classes.

Interesting!
Yeah, let's wait until we move to es6.

@miq-bot
Copy link
Member

miq-bot commented Jan 10, 2017

Checked commits AparnaKarve/manageiq-ui-classic@eadd9a1~...25eaa96 with ruby 2.2.5, rubocop 0.37.2, and haml-lint 0.16.1
0 files checked, 0 offenses detected
Everything looks good. 🍰

@AparnaKarve
Copy link
Contributor Author

@himdel I guess now would be a good time to un-WIP this.
Check out my last commit -- 25eaa96

@miq-bot remove_label wip

@AparnaKarve AparnaKarve changed the title [WIP] Refactor - Replace .success calls with .then/.catch Refactor - Replace .success calls with .then/.catch Jan 10, 2017
@miq-bot miq-bot removed the wip label Jan 10, 2017
@AparnaKarve
Copy link
Contributor Author

@himdel Ideally I would like this PR merged before I move on to the next set of controllers.
Can you please merge this if all the concerns have been addressed?
Thanks.

@himdel himdel self-assigned this Jan 12, 2017
@himdel himdel merged commit efabac9 into ManageIQ:master Jan 13, 2017
@himdel himdel added this to the Sprint 52 Ending Jan 16, 2017 milestone Jan 13, 2017
@himdel
Copy link
Contributor

himdel commented Jan 13, 2017

Sorry @AparnaKarve it took so long.. merged :)

LGTM 👍, tested in the UI.. (ems_common at least)

@AparnaKarve
Copy link
Contributor Author

@himdel Thanks for merging and thank you 🙏 especially for testing in the UI!

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

3 participants