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

Maintain pagination when an user role changes #3120

Merged

Conversation

ilausuch
Copy link
Contributor

https://progress.opensuse.org/issues/47210

Problem: In the user administration page. When a role is changed
the page is reloaded loosing the page in the paginator.

Solution: Programmatically summit the form to prevent the page
reload. This solves the problem

@codecov
Copy link

codecov bot commented May 27, 2020

Codecov Report

Merging #3120 into master will increase coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3120      +/-   ##
==========================================
+ Coverage   91.89%   91.92%   +0.03%     
==========================================
  Files         211      211              
  Lines       12921    12924       +3     
==========================================
+ Hits        11874    11881       +7     
+ Misses       1047     1043       -4     
Impacted Files Coverage Δ
lib/OpenQA/Worker/Job.pm 75.51% <100.00%> (+0.59%) ⬆️
lib/OpenQA/WebAPI/Plugin/Helpers.pm 95.91% <0.00%> (+0.40%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cafc562...42e1242. Read the comment docs.

url: form.attr('action'),
data: jQuery.param(data),
error: function(err){
rollback();
Copy link
Contributor

@Martchus Martchus May 27, 2020

Choose a reason for hiding this comment

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

This doesn't work. The reason is likely that the rollback() function uses this but is not invoked with a this parameter.

}
});
} else
rollback();
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as the previous comment regarding calling rollback(). Besides, please use braces here for symmetry.

Copy link
Contributor Author

@ilausuch ilausuch May 27, 2020

Choose a reason for hiding this comment

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

Ahh a last change before commit, fixing this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, yes, this is working, but I could rewrite in a better way

Copy link
Contributor

Choose a reason for hiding this comment

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

I gave it a local test and it wasn't working (as well as the other rollback()).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hope now works for you. Now this stores the form in a variable before to be used in the callbacks.

$(this).parent('form').submit();
} else {

function rollback(){
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use a space like ) {.

var form = $(this).parent('form');
var data = form.serializeArray();

$.ajax({
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the rollback() function relies on the class being set to default that class needs to be updated when this AJAX call succeeds.

Copy link
Contributor Author

@ilausuch ilausuch May 27, 2020

Choose a reason for hiding this comment

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

yes, right

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is solved now. I am using removeClass and addClass from jquery, but if is necessary could be replaced by native javascript operations

@ilausuch ilausuch force-pushed the users_mantain_page_in_pagination branch from 659895f to b37ec17 Compare May 28, 2020 08:14
@ilausuch
Copy link
Contributor Author

Additionally I added a small piece of html to show an beautiful red alert if something happens on updating the role.

@ilausuch
Copy link
Contributor Author

Do you thing should be necessary expanse the test to include that the default class changes?

@@ -9,6 +9,14 @@
<div class="col-sm-12">
<h2><%= title %></h2>

<div id="error" class="alert alert-danger" role="alert" style="display:none">
Copy link
Contributor

Choose a reason for hiding this comment

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

The generic way this error is handled means that this is not necessarily an "Internal server error". Either distinguish the errors or keep it simple, e.g. "An error occurred when changing the user role.". I also wouldn't include the link to the bug tracker. After all the server might just be not reachable because the client's internet connection went off. And I would prefer to simply show a flash message using addFlash('danger', …); instead of creating the elements manually.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I didn't have notice of addFlash, very useful

@Martchus
Copy link
Contributor

Do you thing should be necessary expanse the test to include that the default class changes?

Likely it isn't necessary to have automatic tests for every detail.

@ilausuch ilausuch force-pushed the users_mantain_page_in_pagination branch from b37ec17 to 66779a9 Compare May 28, 2020 10:35

$.ajax({
type: 'POST',
url: form.attr('action')+'sddsds',
Copy link
Contributor

Choose a reason for hiding this comment

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

+'sddsds' ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, sorry

@ilausuch ilausuch force-pushed the users_mantain_page_in_pagination branch from 66779a9 to e940123 Compare May 28, 2020 12:12
@okurz
Copy link
Member

okurz commented Jun 5, 2020

so one test failed "scheduler". That should be fixed meanwhile in master. We can retrigger the failing test which we did now or just rebase. I am not sure what changes @Martchus would still expect if any

https://progress.opensuse.org/issues/47210

Problem: In the user administration page. When a role is changed
the page is reloaded loosing the page in the paginator.

Solution: Programmatically summit the form to prevent the page
reload. This solves the problem.
@ilausuch ilausuch force-pushed the users_mantain_page_in_pagination branch from e940123 to 42e1242 Compare June 5, 2020 08:46
@ilausuch
Copy link
Contributor Author

ilausuch commented Jun 5, 2020

Re-based and pushed

Copy link
Contributor

@Martchus Martchus left a comment

Choose a reason for hiding this comment

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

Seems to work now.

@kalikiana kalikiana merged commit 8307215 into os-autoinst:master Jun 5, 2020
@ilausuch ilausuch deleted the users_mantain_page_in_pagination branch November 5, 2020 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants