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

Hawkular hostname detection changes #1304

Merged
merged 1 commit into from Jun 7, 2017

Conversation

moolitayer
Copy link

@moolitayer moolitayer commented May 7, 2017

In container providers, before this change, if the hostname of a Hawkular endpoint is empty upon submission - we will attempt to detect it from a route leading to it in OpenShift. There is no indication to the user on the detection and no way of seeing the detected value pre submission.

This PR moves detection to be a button that only fills the form value.

no default hostname/port to use for detection - detect button is disabled
manageiq containers providers

detection available
detection_available

after detection validate becomes enabled
validate

bug: https://bugzilla.redhat.com/show_bug.cgi?id=1437138

@moolitayer
Copy link
Author

@miq-bot add_label wip

@moolitayer
Copy link
Author

@miq-bot remove_label wip

@moolitayer moolitayer changed the title [WIP] Hawkular hostname detection changes Hawkular hostname detection changes May 8, 2017
@moolitayer
Copy link
Author

@zeari can you please review this change?

@miq-bot miq-bot removed the wip label May 8, 2017
@zeari
Copy link

zeari commented May 8, 2017

@moolitayer Screenshots please!
Thanks

@zeari
Copy link

zeari commented May 8, 2017

@moolitayer Overall look good. Im just not sure how this handles various errors. for example if someone tries to use detect when they didnt fill out provider details correctly.

anyway this need a UI review. @dclarizio @himdel PTAL

@moolitayer
Copy link
Author

@moolitayer Overall look good. Im just not sure how this handles various errors. for example if someone tries to use detect when they didnt fill out provider details correctly.

The detect button will be grayed out if hostname and or port weren't inserted

@moolitayer
Copy link
Author

@cben can you review these changes?

return nil unless ems.class.respond_to?(:openshift_connect)
endpoint = Endpoint.new(endpoint_hash)
# TODO: move to backend
def get_hostname_from_routes(ems)
Copy link
Contributor

Choose a reason for hiding this comment

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

@moolitayer Can you move this method and all the other container specific code in this PR to ems_container_controller?

Copy link
Author

Choose a reason for hiding this comment

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

Done

@moolitayer
Copy link
Author

@miq-bot add_label compute/containers, enhancement, fine/yes
(per bz)

@dclarizio
Copy link

@moolitayer can you please review the codeclimate issues, some look easy to fix? Thx, Dan

It may be just me, but when does the Detect button light up? Is it when the user has a port entered as well as a Name and type, above? Hard to tell from the screen shot. Does the disabled button have hover text to let you know what it takes to light it up?

If the detection end point times out or has errors, what is the end user experience? Are we spinning or waiting for a potentially long time?

miqService.sparkleOn();
miqService.detectWithRest($event, $scope.actionUrl)
.then(function success(data) {
$scope.$apply(function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suddenly 4 space indent? ;)

@@ -66,6 +66,12 @@ ManageIQ.angular.app.service('miqService', ['$timeout', '$document', '$q', funct
}, 200);
};

this.detectWithRest = function($event, url) {
angular.element('#button_name').val('detect');
Copy link
Contributor

Choose a reason for hiding this comment

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

and here

@@ -77,6 +77,16 @@
"checkchange" => "",
"prefix" => prefix.to_s,
"reset-validation-status" => "#{prefix}_auth_status"}
- detect = "detectClicked({target: '.detect_button'}, true)"
Copy link
Contributor

Choose a reason for hiding this comment

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

The indent level should be the same as that %span on the next line, otherwise, it looks like you're declaring a variable for a block that is no longer there.

@@ -77,6 +77,16 @@
"checkchange" => "",
"prefix" => prefix.to_s,
"reset-validation-status" => "#{prefix}_auth_status"}
- detect = "detectClicked({target: '.detect_button'}, true)"
%span
%miq-button.detect_button{:ng_if => defined?(detection) ? true : false,
Copy link
Contributor

Choose a reason for hiding this comment

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

We're doing - foo ||= false for the other variables on the beginning of this partial - can you do the same for detection please? (So that you don't need that defined?).

Also.. if you're trying to use ng-if, it has to be 'ng-if', not :ng_if .. and that true and false should probably be in quotes, unless you're interested in the presence of such attribute, instead of its value.

@moolitayer moolitayer force-pushed the detect_hawkular branch 2 times, most recently from f1b0f9f to 10f005a Compare May 10, 2017 17:11
@@ -522,6 +542,11 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', '
$scope.angularForm[$scope.authType + '_auth_status'].$setViewValue(updatedValue);
};

$scope.updateHawkularHostname = function(value) {
$scope.angularForm['hawkular_hostname'].$setViewValue(value);
$('#hawkular_hostname').val(value);
Copy link
Author

Choose a reason for hiding this comment

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

@himdel is there a better way for the above?

Copy link
Contributor

Choose a reason for hiding this comment

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

@moolitayer You could use

angular.element('#hawkular_hostname').val(value);

which is also recommended by CodeClimate.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks @AparnaKarve

Copy link
Contributor

Choose a reason for hiding this comment

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

Uh... but.. why not simply use $scope.emsCommonModel.hawkular_hostname = value? Since hawkular_hostname is an input with ng-model, no reason to access it magically...

Copy link
Contributor

Choose a reason for hiding this comment

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

no reason to access it magically

Sure, if just the assignment $scope.emsCommonModel.hawkular_hostname = value works, why not?

@moolitayer
Copy link
Author

@moolitayer can you please review the codeclimate issues, some look easy to fix? Thx, Dan

It may be just me, but when does the Detect button light up? Is it when the user has a port entered as well as a Name and type, above? Hard to tell from the screen shot. Does the disabled button have hover text to let you know what it takes to light it up?

If the detection end point times out or has errors, what is the end user experience? Are we spinning or waiting for a potentially long time?

The detection is using fields from the other endpoint, so the button becomes available when those fields are available. I tested error flows (detection fails) and error messages are showing. There is no timeout so the spinner will not go away. I added disabled and enabled titles.

%span
%miq-button.detect_button{"ng-if" => detection ? 'true' : 'false',
:name => _("Detect"),
:on_click => detect,
Copy link
Author

Choose a reason for hiding this comment

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

@himdel these attribute names seem to work.
Do you want them changed to strings with -?
(:on_click, :disabled_title, :enabled_title:)

Copy link
Contributor

Choose a reason for hiding this comment

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

Aaah.. according to https://docs.angularjs.org/api/ng/type/$compile.directive.Attributes , angular accepts dashes, underscores or colons .. so .. yeah, good to know.

But, we always use the dash version, so.. if you don't mind, to prevent potential confusion..

@moolitayer moolitayer closed this May 29, 2017
@moolitayer moolitayer reopened this May 29, 2017
@moolitayer
Copy link
Author

@himdel @cben please take a look

$scope.detectClicked = function($event) {
miqService.sparkleOn();
miqService.detectWithRest($event, $scope.actionUrl)
.then(function success(data) {
Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps should also have a failure callback? (to display a flash)

Copy link
Author

Choose a reason for hiding this comment

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

This callback also handles detection failure as an error is returned (tested) similarly to the validate function

as for failure to get the response there's not much we can do if we can't talk to the server - so I think it is good enough to do the same as the validate callback.

def get_hostname_from_routes(ems)
return nil, "Route detection not applicable for provider type" unless ems.class.respond_to?(:openshift_connect)
[
ems.connect(:service => :openshift).get_route('hawkular-metrics', 'openshift-infra').try(:spec).try(:host),
Copy link
Contributor

Choose a reason for hiding this comment

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

hooray :-)

:name => _("Detect"),
"on-click" => detect,
:enabled => "isDetectionEnabled()",
"disabled-title" => _("Detection not available for provider type"),
Copy link
Contributor

Choose a reason for hiding this comment

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

is this the reason it would be visible but disabled?
I think for other providers you just hide it & this should explain this fields you have to fill.

@cben
Copy link
Contributor

cben commented May 29, 2017

2 tiny comments but this has long Looked Good To Me... Let me know if you want me to try it out.

@moolitayer
Copy link
Author

@himdel @cben please take a look

@moolitayer
Copy link
Author

@himdel please take a look

@himdel
Copy link
Contributor

himdel commented Jun 6, 2017

So... the styling is a bit broken when both Detect and Required are shown..

bad-required

EDIT: Required is broken regardless. In all the other fields, Required is on the new line, not to the right of the input.

@himdel
Copy link
Contributor

himdel commented Jun 6, 2017

This should fix the styling problem:

diff --git a/app/views/layouts/angular-bootstrap/_endpoints_angular.html.haml b/app/views/layouts/angular-bootstrap/_endpoints_angular.html.haml
index 170ccd58a0..a1edd3f234 100644
--- a/app/views/layouts/angular-bootstrap/_endpoints_angular.html.haml
+++ b/app/views/layouts/angular-bootstrap/_endpoints_angular.html.haml
@@ -79,6 +79,11 @@
                           "checkchange"             => "",
                           "prefix"                  => prefix.to_s,
                           "reset-validation-status" => "#{prefix}_auth_status"}
+      %span.help-block{"ng-show" => "angularForm.#{prefix}_hostname.$error.required"}
+        = _("Required")
+      %span.help-block{"ng-show" => "angularForm.#{prefix}_hostname.$error.detectedSpaces"}
+        = _("Spaces are prohibited")
+
     - detect = "detectClicked({target: '.detect_button'})"
     %span
       %miq-button.detect_button{"ng-if" => detection ? 'true' : 'false',
@@ -90,11 +95,6 @@
                   :xs              => 'true',
                   :primary         => 'true'}
 
-      %span.help-block{"ng-show" => "angularForm.#{prefix}_hostname.$error.required"}
-        = _("Required")
-      %span.help-block{"ng-show" => "angularForm.#{prefix}_hostname.$error.detectedSpaces"}
-        = _("Spaces are prohibited")
-
 %div{"ng-if" => defined?(apiport_hide) ? false : true}
   .form-group{"ng-class" => "{'has-error': angularForm.#{prefix}_api_port.$invalid}",
               "ng-if" => "emsCommonModel.emstype == 'openstack'              || " + |

this.detectWithRest = function($event, url) {
angular.element('#button_name').val('detect');
miqSparkleOn();
return miqRESTAjaxButton(url, $event.target, 'json');
Copy link
Contributor

@himdel himdel Jun 6, 2017

Choose a reason for hiding this comment

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

When wrapping a function returning a non-angular Promise, it's a good idea to wrap the result in an angular promise - so that you don't need that $scope.$apply when calling it.

return $q.when(miqRESTAjaxButton(url, $event.target, 'json')); should work ;)

miqService.sparkleOn();
miqService.detectWithRest($event, $scope.actionUrl)
.then(function success(data) {
$scope.$apply(function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

"enabled-title" => _("Detect Endpoint"),
:xs => 'true',
:primary => 'true'}

%span.help-block{"ng-show" => "angularForm.#{prefix}_hostname.$error.required"}
Copy link
Contributor

Choose a reason for hiding this comment

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

(these error %spans need to be siblings of the %input, not cousins) (#1304 (comment))

@moolitayer
Copy link
Author

Thanks for the catch @himdel, seems fine now:

manageiq containers providers

kindly rereview

@miq-bot
Copy link
Member

miq-bot commented Jun 7, 2017

Checked commit moolitayer@9c30024 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
5 files checked, 0 offenses detected
Everything looks fine. ⭐

@himdel
Copy link
Contributor

himdel commented Jun 7, 2017

@moolitayer Thanks, LGTM, just one little detail I notice.. this does not work for Kubernetes, only OpenShift... so you can look at the detect button, see the "Required information missing" label, and wonder what else it needs :).

Maybe make that disabled-title something like "Required information missing; currently only supported for Openshift"? Or, maybe better, ng-if="emsCommonModel.emstype == 'openshift'"?

@moolitayer
Copy link
Author

Detection isn't available if a required filed is missing OR the provider type is kubernetes.
I first had the second option in the error message but changed it after a review comment.

I could allow the detection for kubernetes and return a message from the server if that is a good solution.

Note that in a real life scenario someone using kubernetes would disable hawkular since it is not available there (hmm... we should probably disable hawkular when someone selects kubernetes )

@himdel
Copy link
Contributor

himdel commented Jun 7, 2017

Aaah.. hawkular is not used with kubernetes at all?

If so, then it makes sense to just merge this and remove that hawkular code in a separate PR, right?

@moolitayer
Copy link
Author

yes to remove the hawkular option when kubernetes is selected

@himdel himdel merged commit 93aa552 into ManageIQ:master Jun 7, 2017
@himdel himdel added this to the Sprint 63 Ending Jun 19, 2017 milestone Jun 7, 2017
@moolitayer
Copy link
Author

@miq-bot add_label fine/no

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

8 participants