-
Notifications
You must be signed in to change notification settings - Fork 442
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
[webui] Refactoring user requests datatables #2680
Conversation
@evanrolfe please have a look! |
57af8a8
to
f6aa274
Compare
f6aa274
to
8f8a9a6
Compare
@@ -0,0 +1,140 @@ | |||
class RequestsDatatable | |||
delegate :sprite_tag, :common_parts, :user_with_realname_and_icon, :fuzzy_time, | |||
:project_or_package_link, :params, :link_to, :request_show_path, to: :@view |
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 dont understand what this is for?
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.
These are view helper methods which I use e.g. in show_column
or requester_column
8f8a9a6
to
8aa80f1
Compare
Nice work on this, the code is definitely not easy to work with! I have some suggestions with your class design though, the I would split So I would use move the view methods to a json erb view file like it was done originally i.e. (Warning: Code not tested.) |
8aa80f1
to
8f8665c
Compare
@@ -0,0 +1,79 @@ | |||
class RequestsDataTable |
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.
Can this go into a submodule i.e. BsRequest::DataTable
and also: BsRequest::DataTableRow
? Or something like that?
@requests ||= fetch_requests | ||
end | ||
|
||
def length |
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.
does this method ever get used?
else | ||
super | ||
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.
IMO these two methods make the class more complicated than it needs to be.. There are simpler alternatives I think i.e.
- Just call
row.request.X
since@request
is anattr_reader
- use
def_delegators
to delegate the desired methods to@request
- Use SimpleDelegator to make this a decorator class for a request
context 'sort direction' do | ||
context 'defaults to sort by :created_at :desc' do | ||
before do | ||
@data = RequestsDataTable.new({ format: :json, length: 10, start: 0 }, user).rows |
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.
Why is format: :json
a param here? It doesn't ever get used by this class does it?
target_package: target_package) | ||
} | ||
|
||
context 'sort direction' do |
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.
Can you please have a look at the betterspecs guidelines for rspec because this isn't the way context is meant to be used.
Here is an example of how the spec could be written to follow the rspec guidelines (and also I've added tests for the untested public methods on this class - draw
, records_total
, count_requests
:
https://gist.github.com/evanrolfe/eb422ca6766cd063b1f90012e9a97bf9
@requests = @displayed_user.send(request_method, search) | ||
@requests_count = @requests.count | ||
@requests = @requests.offset(params[:start].to_i).limit(params[:length].to_i).reorder(sorting_field => sorting_dir) | ||
@data = RequestsDataTable.new(params, @displayed_user) |
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.
Can we call this something more descriptive? i.e. @requests_data_table
?
] | ||
<% unless index == @data.rows.length - 1 %> | ||
, | ||
<% 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.
looks like something is wrong with the indentation here?
f94e544
to
4478970
Compare
- Moved logic from controller to RequestsDatatable class - Fix request sorting ordering by column (introduced by 509370a) Fixes openSUSE#2572
4478970
to
4f07d4c
Compare
LGTM (assuming the build passes) |
This is a leftover from openSUSE#2680.
This is a leftover from openSUSE#2680.
This is a leftover from openSUSE#2680.
Fixes Sorting in request lists broken #2572