-
Notifications
You must be signed in to change notification settings - Fork 357
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
Fixed links to point to correct provider controller based upon type. #4760
Fixed links to point to correct provider controller based upon type. #4760
Conversation
d68b450
to
d18ec8e
Compare
@h-kataria , I am concerned that similar functionality already exists in Furthermore the code in the Therefor I suggest investigating if a fix for the BZ can be implemented using the existing code rather that adding similar logic on the Javascript side. |
var action = '/'; | ||
var descriptors = providerType.split('::'); | ||
|
||
switch (descriptors.pop()) { |
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 don't like this client-side specification because it has to be in sync with the controllers all the time. What do you think about using the restful_redirect_controller
instead? This way the switch could be completely removed and the redirect decision logic could live in that controller.
Oh, I see @martinpovolny had the exact same idea 🤣 |
eddc392
to
932e0b1
Compare
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 think if you try to use singular_route_key
, you could probably make the code just a few lines and move it under the ˙index˙ route.
action = '/' | ||
descriptors = params['provider_type'].split('::') | ||
|
||
case descriptors.last |
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.
What about
provider_type.constantize.model_name.singular_route_key
?
config/routes.rb
Outdated
@@ -2830,6 +2830,7 @@ | |||
:restful_redirect => { | |||
:get => %w( | |||
index | |||
provider_url |
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 don't really like the new route thing, any reason why this isn't under index
?
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.
@skateman i kept it separate from index
method because that method expects different params and is being used to redirect to a page based upon model that's passed in. provider_url
sets a link that is being used by list of Alerts, not sure if it's a good idea to mix the both methods.
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.
And what about passing them the same params? Like ˙ExtManagementSystemas
modeland the
id`. And use the method I wrote above to determine the URL.
932e0b1
to
e83b2c1
Compare
@skateman please review/test. Thanks for the help! |
@@ -488,6 +488,15 @@ function alertsCenterService(API, $q, $timeout, $document, $uibModal, $http) { | |||
} | |||
} | |||
|
|||
var providerLink = function(providerType, providerId, newAlert) { |
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.
You no longer need the providerType
argument
var providerLink = function(providerType, providerId, newAlert) { | |
var providerLink = function(providerId, newAlert) { |
@@ -532,7 +540,7 @@ function alertsCenterService(API, $q, $timeout, $document, $uibModal, $http) { | |||
} | |||
|
|||
updateAlertStatus(newAlert); | |||
|
|||
providerLink(objectClassifiedType, alertData.ems_id, newAlert); |
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.
providerLink(objectClassifiedType, alertData.ems_id, newAlert); | |
providerLink(alertData.ems_id, newAlert); |
@@ -488,6 +488,15 @@ function alertsCenterService(API, $q, $timeout, $document, $uibModal, $http) { | |||
} | |||
} | |||
|
|||
var providerLink = function(providerType, providerId, newAlert) { | |||
$http.get('/restful_redirect/index?model=ExtManagementSystem&id=' + providerId) | |||
.then(updateNewAlert); |
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.
.then(updateNewAlert); | |
.then(function(response) { | |
newAlert.objectLink = response.data.data; | |
}); |
020b8b9
to
0bae925
Compare
@@ -532,7 +538,7 @@ function alertsCenterService(API, $q, $timeout, $document, $uibModal, $http) { | |||
} | |||
|
|||
updateAlertStatus(newAlert); | |||
|
|||
providerLink(alertData.ems_id, newAlert); |
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.
What about having the link straight to '/restful_redirect/index?model=ExtManagementSystem&id=' + providerId
and just use redirect_to
so it is consistent?
c1fea76
to
e571eb4
Compare
I know that Real Programmers aren't afraid to use GOTO's, but I am not a fan of that style and this looks almost like that. So what about creating a private case xy
when a
handle_error unless record
blah
when b
...
else
handle_error
end |
e571eb4
to
6e5928b
Compare
unless record | ||
handle_error | ||
return | ||
end |
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.
end | |
return handle_error unless |
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.
Or maybe
end | |
record ? redirect_to() : handle_error |
handle_error | ||
return | ||
end | ||
redirect_to(polymorphic_path(record)) | ||
when 'ServiceTemplateTransformationPlanRequest' | ||
req = ServiceTemplateTransformationPlanRequest.select(:source_id).find(params[:id]) | ||
redirect_to(:controller => 'migration', :action => 'index', :anchor => "plan/#{req.source_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.
I think you might have to add the error handling here as well...
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.
Up to you if in a separate commit or here
end | ||
end | ||
|
||
def handle_error |
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 seriously thought you can come up with a better name than I, but it's okay 🤣
Added a method in restful_redirect_controller that can be called from JS service to determine provider link. Moved fallback code to redirect to dashboard show with flash message out of switch. Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1637609
6e5928b
to
efa4d7a
Compare
end | ||
end | ||
|
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.
private |
Added controller spec tests Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1637609
293f8f0
to
c186097
Compare
Checked commits h-kataria/manageiq-ui-classic@efa4d7a~...c186097 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 |
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.
…s_list Fixed links to point to correct provider controller based upon type. (cherry picked from commit 5a0d67d) Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1637609
Hammer backport details:
|
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1637609