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

Fix and modernise cloud volume forms #950

Merged
merged 1 commit into from
Apr 20, 2017

Conversation

gberginc
Copy link
Contributor

@gberginc gberginc commented Apr 6, 2017

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1443188

Introduction of the ability to create cloud volumes for a specific block storage manager broke the remaining forms dealing with cloud volumes. The reason for this was that the Angular controller required additional parameter specifying the target block storage manager.

In an attempt to update these forms, various issues were raised (e.g. display of form fields in the new vs. edit form, use of legacy form control tags, mixing of the API and rails controller data, ...). This resulted in a more comprehensive update of the cloud volume forms, introducing two main enhancements (besides fixing the forms):

  • Use of APIs in Angular controller: some of the data was provided by rails controller while the other was already retrieved through and API. This commit tries to use API as much as possible.

  • Use of "controller as vm": when rewriting the controller it was easy to introduce this change to bring cloud volume views and controller closer to the current best practices

I've made five videos showing different operations on cloud volumes (all show OpenStack Cinder and Amazon EBS):

  1. Creating new cloud volumes http://x.k00.fr/lph6r
  2. Editing cloud volume http://x.k00.fr/gx691
  3. Attaching cloud volumes http://x.k00.fr/q1tz7
  4. Detaching cloud volumes http://x.k00.fr/gh2m6
  5. Creating snapshots http://x.k00.fr/8krc7

This replaces two other PRs that actually lead to the decision to make more massive change:

@miq-bot add_label wip

@miq-bot miq-bot added the wip label Apr 6, 2017
@gberginc
Copy link
Contributor Author

gberginc commented Apr 6, 2017

@miha-plesko This is the one that we discussed earlier today. Please, have a look at the changes and do another round of testing.

@gberginc gberginc force-pushed the fix/cloud_volume_forms branch from bbc2fe3 to 128f446 Compare April 6, 2017 20:18
@gberginc gberginc changed the title [WIP] Fix and modernise cloud volume forms Fix and modernise cloud volume forms Apr 6, 2017
@gberginc
Copy link
Contributor Author

gberginc commented Apr 6, 2017

@miq-bot remove_label wip
@miq-bot add_label storage

@miq-bot miq-bot added storage and removed wip labels Apr 6, 2017
aws_encryption: false,
incremental: false,
// storage_manager_id: storageManagerId,
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove

@gberginc gberginc force-pushed the fix/cloud_volume_forms branch 2 times, most recently from ba50938 to 2089688 Compare April 10, 2017 05:12
@dclarizio dclarizio requested a review from AparnaKarve April 11, 2017 17:52
@dclarizio dclarizio self-assigned this Apr 11, 2017
@AparnaKarve
Copy link
Contributor

@gberginc Thank you for those comprehensive videos that you put together.
I will be commencing my testing/reviewing very soon.

break;
}
};

$scope.canModifyVolumeSize = function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you define this function on vm?

vm.canModifyVolumeSize = function() {

// editin Amazon EBS volume whose type is not magnetic (all other volume types
// can be resized on the fly).
return vm.newRecord ||
(vm.cloudVolumeModel.emstype == 'ManageIQ::Providers::Amazon::StorageManager::Ebs' &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Use ===

$scope.angularForm.$setPristine(true);
miqService.miqFlash("warn", "All changes have been reset");
};

$scope.storageManagerChanged = 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.

Define the function on vm instead of $scope.

vm.storageManagerChanged = function(id) {

.then(getStorageManagerFormData)
.catch(miqService.handleFailure);
};

$scope.sizeChanged = function(size) {
Copy link
Contributor

Choose a reason for hiding this comment

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

vm.sizeChanged = function(size) {

"ng-model" => "vm.cloudVolumeModel.storage_manager_id",
"ng-options" => "mgr.id as mgr.name for mgr in vm.storageManagers",
"ng-change" => "storageManagerChanged(vm.cloudVolumeModel.storage_manager_id)",
"required" => "",
Copy link
Contributor

Choose a reason for hiding this comment

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

Even though you have the required here, for some reason it does not show up as a Required field for me.
screen shot 2017-04-12 at 12 22 35 pm

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem was with the way I was setting the storage manager id. Thanks to @miha-plesko for discovering this: 7e54df7

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice @miha-plesko!

@@ -1,4 +1,8 @@
%form#form_div{:name => "angularForm", 'ng-controller' => "cloudVolumeFormController"}
%form#form_div{:name => "angularForm",
Copy link
Contributor

Choose a reason for hiding this comment

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

Where exactly is this form in the UI?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's used for OpenStack provider: Restore from a backup of this Cloud Volume. I am unable to actually create a backup on our OpenStack testbed, so I could only ensure that the functions are being called exactly the same as they were called before.

@AparnaKarve
Copy link
Contributor

@gberginc To complete the vm related changes in their entirety, I would recommend using the buttons partial layouts/angular/generic_form_buttons that I mentioned to you about once.
That way all the button functions $scope.addClicked, $scope.saveClicked could be converted to vm.addClicked, vm.saveClicked etc.
The eventual goal would be to completely remove $scope where it's currently injected in the controller.

Functionality-wise, this is working great.

%input.form-control{"bs-switch" => "",
:data => {:on_text => _('Yes'), :off_text => _('No'), :size => 'mini'},
:type => "checkbox",
:name => "encryption",
Copy link
Contributor

Choose a reason for hiding this comment

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

Please change the name to aws_encryption here.
Since the checkchange directive looks for the same name that has been specified in the model.

:type => "checkbox",
:name => "encryption",
'ng-model' => "vm.cloudVolumeModel.aws_encryption",
'ng-disabled' => "!vm.newRecord",
Copy link
Contributor

Choose a reason for hiding this comment

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

Also noticed that ng-disabled does not seem to work.
I can change the value when I'm in edit mode.

If I remove the bs-switch and have a regular checkbox instead, ng-disabled works.
I'm looking into it...

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, so to disable bs-switch, you need to use the switch-readonly directive in place of ng-disabled

So swap ng-disabled with switch-readonly
'switch-readonly' => "!vm.newRecord"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, this was something I forgot to ask you, what is the correct way to disable the switch. Thanks for finding this out: 1089882

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AparnaKarve There is an issue with this as well. Pressing space key on the bs-switch field will still toggle it.

@AparnaKarve
Copy link
Contributor

@gberginc I've attached a patch here that shows how to use the layouts/angular/generic_form_buttons partial in the context of vm.

buttons_patch.diff.txt

@gberginc
Copy link
Contributor Author

@AparnaKarve I've resolved your comments regarding transition to vm of the custom callbacks and most other minor things. I now need to check the buttons partial.

@gberginc
Copy link
Contributor Author

@AparnaKarve Since using the generic buttons for new and edit, other forms failed to provide reset functionality as they still relied on the $scope.resetClicked handler. Thus I just created another commit that completely removes $scope: 8530f1b.

@AparnaKarve
Copy link
Contributor

Thus I just created another commit that completely removes $scope: 8530f1b

Yes, that looks just about right.

Excellent work on removing $scope out of the picture. Thanks.

Can you go through the codeclimate issues? Some of them seem quite legit. (like the missing semicolon ones)

@gberginc gberginc force-pushed the fix/cloud_volume_forms branch from 8530f1b to e622a62 Compare April 14, 2017 03:31
@gberginc
Copy link
Contributor Author

@AparnaKarve codeclimate is now green, including that space after unary ! (still hurts me, but I trust that's the proper way 😄).

Please have a look at the comment regarding bs-switch: #950 (comment). It may be an issue in other parts of the UI so perhaps something that should be made into an issue for someone to look into.

@bronaghs
Copy link

@miq-bot add_label blocker

@bronaghs
Copy link

@miq-bot add_label fine/yes

@dclarizio
Copy link

@AparnaKarve thx for all the reviewing, this looks like it's getting close. Ping me when ready . . . Thx, Dan

@bronaghs
Copy link

@AparnaKarve
Copy link
Contributor

@gberginc I was thinking that we could remove the parseInt(storageManagerId, 10); related code and make the following changes:

In the JS --

-    var managerId = parseInt(storageManagerId, 10);
-    if (! isNaN(managerId)) {
-      vm.cloudVolumeModel.storage_manager_id = managerId;
-    }
+    vm.cloudVolumeModel.storage_manager_id = storageManagerId;

In the haml --

-            "ng-options"  => "mgr.id as mgr.name for mgr in vm.storageManagers",
+            "ng-options"  => "mgr.id|number as mgr.name for mgr in vm.storageManagers",

number is an angular filter that we can directly apply to mgr.id.

@AparnaKarve
Copy link
Contributor

As far as the bs-switch goes, it looks like, in addition to 'switch-readonly' you also need ng-disabled.
So let's add 'ng-disabled' => "!vm.newRecord", back.

Introduction of the ability to create cloud volumes for a specific block
storage manager broke the remaining forms dealing with cloud volumes.
The reason for this was that the Angular controller required additional
parameter specifying the target block storage manager.

In an attempt to update these forms, various issues were raised (e.g.
display of form fields in the new vs. edit form, use of legacy form
control tags, mixing of the API and rails controller data, ...). This
resulted in a more comprehensive update of the cloud volume forms,
introducing two main enhancements (besides fixing the forms):

* Use of APIs in Angular controller: some of the data was provided by
rails controller while the other was already retrieved through and API.
This commit tries to use API as much as possible.

* Use of "controller as vm": when rewriting the controller it was easy
to introduce this change to bring cloud volume views and controller
closer to the current best practices

This patch completely removes previous dependency on the `$scope` in the
vm controller. Generic buttons are now used for `new` and `edit` forms
For all other operations, the buttons section of forms have been updated
to ensure `vm` can be used in all parts of the view controller.
@gberginc gberginc force-pushed the fix/cloud_volume_forms branch from e622a62 to 24b23ea Compare April 19, 2017 07:43
@gberginc
Copy link
Contributor Author

@AparnaKarve fixed according to your comment and discussion in Gitter. Also tested the provisioning of the new cloud volume (with #1061 applied).

@miq-bot
Copy link
Member

miq-bot commented Apr 19, 2017

Checked commit gberginc@24b23ea with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
3 files checked, 0 offenses detected
Everything looks good. 👍

@gberginc gberginc closed this Apr 19, 2017
@gberginc gberginc reopened this Apr 19, 2017
@gberginc gberginc closed this Apr 19, 2017
@gberginc gberginc reopened this Apr 19, 2017
@AparnaKarve
Copy link
Contributor

@gberginc It looks like we have addressed all known issues and then some :) especially with the controller as vm based changes that you made. Appreciate your initiative on that.

@dclarizio This is good to merge.

@dclarizio dclarizio added the bug label Apr 20, 2017
@dclarizio dclarizio merged commit 6d5faea into ManageIQ:master Apr 20, 2017
@dclarizio dclarizio added this to the Sprint 59 Ending Apr 24, 2017 milestone Apr 20, 2017
@gberginc
Copy link
Contributor Author

Thanks @AparnaKarve, it really was a pleasure working on this one with you!

simaishi pushed a commit that referenced this pull request Apr 20, 2017
@simaishi
Copy link
Contributor

Fine backport details:

$ git log -1
commit 52e95b03c5992b1f137f04a828f6728eaa625a38
Author: Dan Clarizio <[email protected]>
Date:   Thu Apr 20 03:07:48 2017 -0700

    Merge pull request #950 from gberginc/fix/cloud_volume_forms
    
    Fix and modernise cloud volume forms
    (cherry picked from commit 6d5faea247e6007b5b3ebd3b1c17e074c99770b7)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1444172

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.

7 participants