Skip to content

Commit

Permalink
[webui] refactor requests table code to allow it to be used by other …
Browse files Browse the repository at this point in the history
…parts of app
  • Loading branch information
evanrolfe committed Apr 27, 2017
1 parent b05c5f9 commit bc39a66
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 57 deletions.
1 change: 1 addition & 0 deletions src/api/app/assets/javascripts/webui/application.js.erb
Expand Up @@ -40,6 +40,7 @@
//= require webui/application/main
//= require webui/application/repository_tab
//= require webui/application/user
//= require webui/application/requests_table
<% require_asset 'webui/application/image_templates' if Feature.active?(:image_templates) %>

function remove_dialog() {
Expand Down
40 changes: 40 additions & 0 deletions src/api/app/assets/javascripts/webui/application/requests_table.js
@@ -0,0 +1,40 @@
$( document ).ready(function() {
$('.requests-datatable').each(function(index){
// 1. Create DataTable
var url = $(this).data('source');
var dataTableId = $(this).attr('id');
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,
pageLength: 25,
pagingType: "full_numbers",
processing: true,
serverSide: true,
ajax: {
url: url,
data: { dataTableId: dataTableId }
}
};
var table = $(this).dataTable(options);

// 2. Reload button
var reload_button = $('.result_reload[data-table=' + dataTableId + ']')
var loading_spinner = $(reload_button).siblings('.result_spinner');

reload_button.click(function(){
reload_button.hide();
loading_spinner.show();

table.api().ajax.reload(function(){
reload_button.show();
loading_spinner.hide();
}, false);
});
});
});
56 changes: 5 additions & 51 deletions src/api/app/assets/javascripts/webui/application/user.js
@@ -1,53 +1,7 @@
$( 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,
pageLength: 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);

options.ajax.data.dataTableId = 'reviews_in_table';
$('#reviews_in_table').dataTable(options);

$('.result_reload').click(function() {
var that = this;
$(this).hide();
$(this).siblings('.result_spinner').show();
var table = $(this).data('table');

$('#' + table).DataTable().ajax.reload(function(){
$(that).show();
$(that).siblings('.result_spinner').hide();
}, false);
});

$('#requests li a').click(function (event) {
$(this).parent().parent().find('.result_reload').hide();
$(this).siblings('.result_reload').show();
});
// Show reload button when tab is changed
$('#requests li a').click(function (event) {
$(this).parent().parent().find('.result_reload').hide();
$(this).siblings('.result_reload').show();
});
});
@@ -1,4 +1,4 @@
%table.requests-datatable.compact{data: {source: user_requests_path(@displayed_user)}, id: id, width: '100%'}
%table.requests-datatable.compact{ 'data-source' => source_url, id: id, width: '100%'}
%thead
%tr
%th Created
Expand Down
10 changes: 5 additions & 5 deletions src/api/app/views/webui/user/show.html.haml
Expand Up @@ -104,7 +104,7 @@
= sprite_tag('reload', title: 'Reload', class: 'result_reload', data: { table: 'reviews_in_table' })
= image_tag('ajax-loader.gif', class: 'result_spinner hidden')
.tab#reviews-in
= render(partial: 'requests', locals: { id: 'reviews_in_table' })
= render(partial: 'webui/shared/requests_table', locals: { id: 'reviews_in_table', source_url: user_requests_path(@displayed_user) })

.grid_16.alpha.omega.box.box-shadow
#requests
Expand All @@ -127,13 +127,13 @@
= sprite_tag('reload', title: 'Reload', class: 'result_reload hidden', data: { table: 'all_requests_table' })
= image_tag('ajax-loader.gif', class: 'result_spinner hidden')
.tab#requests-in
= render(partial: 'requests', locals: { id: 'requests_in_table' })
= render(partial: 'webui/shared/requests_table', locals: { id: 'requests_in_table', source_url: user_requests_path(@displayed_user) })
.tab#requests-out
= render(partial: 'requests', locals: { id: 'requests_out_table' })
= render(partial: 'webui/shared/requests_table', locals: { id: 'requests_out_table', source_url: user_requests_path(@displayed_user) })
.tab#requests-declined
= render(partial: 'requests', locals: { id: 'requests_declined_table' })
= render(partial: 'webui/shared/requests_table', locals: { id: 'requests_declined_table', source_url: user_requests_path(@displayed_user) })
.tab#all-requests
= render(partial: 'requests', locals: { id: 'all_requests_table' })
= render(partial: 'webui/shared/requests_table', locals: { id: 'all_requests_table', source_url: user_requests_path(@displayed_user) })

- if @patchinfos.present?
.grid_16.alpha.omega.box.box-shadow
Expand Down

0 comments on commit bc39a66

Please sign in to comment.