-
Notifications
You must be signed in to change notification settings - Fork 442
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[webui] Refactoring user requests datatables
- Moved logic from controller to RequestsDatatable class - Fix request sorting ordering by column (introduced by 509370a) Fixes #2572
- Loading branch information
Showing
20 changed files
with
428 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
$( document ).ready(function() { | ||
var url = $('.requests-datatable').first().data('source'); | ||
var options = { | ||
order: [[0,'desc']], | ||
info: false, | ||
columnDefs: [ | ||
// We only allow ordering for created, requester and priority. | ||
// Columns: created, source, target, requester, type, priority. | ||
{ orderable: false, targets: [1,2,4,6,] } | ||
], | ||
paging: 25, | ||
pagingType: "full_numbers", | ||
processing: true, | ||
serverSide: true, | ||
ajax: { | ||
url: url, | ||
data: { dataTableId: null } | ||
} | ||
}; | ||
|
||
options.ajax.data.dataTableId = 'requests_in_table'; | ||
$('#requests_in_table').dataTable(options); | ||
|
||
options.ajax.data.dataTableId = 'requests_out_table'; | ||
$('#requests_out_table').dataTable(options); | ||
|
||
options.ajax.data.dataTableId = 'requests_declined_table'; | ||
$('#requests_declined_table').dataTable(options); | ||
|
||
options.ajax.data.dataTableId = 'all_requests_table'; | ||
$('#all_requests_table').dataTable(options); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/api/app/controllers/webui/users/bs_requests_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Webui | ||
module Users | ||
class BsRequestsController < WebuiController | ||
before_action :check_display_user | ||
|
||
def index | ||
@requests_data_table = BsRequest::DataTable.new(params, @displayed_user) | ||
respond_to do |format| | ||
format.json | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
class BsRequest | ||
class DataTable | ||
def initialize(params, user) | ||
@params = params | ||
@user = user | ||
end | ||
|
||
def rows | ||
requests.map { |request| BsRequest::DataTableRow.new(request) } | ||
end | ||
|
||
def draw | ||
@params[:draw].to_i + 1 | ||
end | ||
|
||
def records_total | ||
requests_query.count | ||
end | ||
|
||
def count_requests | ||
requests_query(search).count | ||
end | ||
|
||
private | ||
|
||
def requests | ||
@requests ||= fetch_requests | ||
end | ||
|
||
def requests_query(search = nil) | ||
request_methods = { | ||
'all_requests_table' => :requests, | ||
'requests_out_table' => :outgoing_requests, | ||
'requests_declined_table' => :declined_requests, | ||
'requests_in_table' => :incoming_requests, | ||
'reviews_in_table' => :involved_reviews | ||
} | ||
|
||
request_method = request_methods[@params[:dataTableId]] || :requests | ||
@user.send(request_method, search) | ||
end | ||
|
||
def fetch_requests | ||
requests_query(search).offset(offset).limit(limit).reorder(sort_column => sort_direction).includes(:bs_request_actions) | ||
end | ||
|
||
def search | ||
@params[:search] ? @params[:search][:value] : '' | ||
end | ||
|
||
def offset | ||
@params[:start].to_i | ||
end | ||
|
||
def limit | ||
@params[:length].to_i | ||
end | ||
|
||
def order_params | ||
@params.fetch(:order, {}).fetch('0', {}) | ||
end | ||
|
||
def sort_column | ||
# defaults to :created_at | ||
{ | ||
0 => :created_at, | ||
3 => :creator, | ||
5 => :priority | ||
}[order_params.fetch(:column, nil).to_i] | ||
end | ||
|
||
def sort_direction | ||
# defaults to :desc | ||
order_params[:dir].try(:to_sym) == :asc ? :asc : :desc | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
class BsRequest | ||
class DataTableRow | ||
attr_accessor :request | ||
delegate :created_at, :number, :creator, :priority, to: :request | ||
|
||
def initialize(request) | ||
@request = request | ||
end | ||
|
||
def source_package | ||
cache[:source_package] | ||
end | ||
|
||
def source_project | ||
cache[:source_project] | ||
end | ||
|
||
def request_type | ||
cache[:request_type] | ||
end | ||
|
||
def target_project | ||
cache[:target_project] | ||
end | ||
|
||
def target_package | ||
cache[:target_package] | ||
end | ||
|
||
private | ||
|
||
def cache | ||
@cache ||= ApplicationController.helpers.common_parts(request) | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
%table.requests-datatable.compact{ 'data-source' => user_requests_path(@displayed_user), id: id, width: '100%'} | ||
%thead | ||
%tr | ||
%th Created | ||
%th Source | ||
%th Target | ||
%th Requester | ||
%th Type | ||
%th Priority | ||
%th | ||
%tbody |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.