Skip to content

Commit

Permalink
Merge pull request #465 from latis-sw/develop
Browse files Browse the repository at this point in the history
Merge for 2.0.2
  • Loading branch information
bvfergus authored and GitHub Enterprise committed Jul 6, 2017
2 parents 18e1f60 + 5d1cfe6 commit 3748461
Show file tree
Hide file tree
Showing 18 changed files with 257 additions and 50 deletions.
82 changes: 75 additions & 7 deletions app/assets/javascripts/urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@ $(document).on("click", ".cancel-new-url", function(e) {
e.preventDefault();
$(this).closest("tr").remove();
});
$(document).on({
ajaxStart: function () {
$('body').css( 'cursor', 'progress' );
$('a').css( 'cursor', 'progress' );
$('button').css( 'cursor', 'progress' );
},
ajaxStop: function () {
$('body').css( 'cursor', '' );
$('a').css( 'cursor', '' );
$('button').css( 'cursor', '' );
}
});

$(document).on("submit", "form", function(e) {
$(this).find(":submit").prop("disabled", true);
});

$(document).on("click", ".cancel-edit", function(e) {
e.preventDefault();
Expand Down Expand Up @@ -92,6 +108,7 @@ $(document).on('shown.bs.tab', function(e) {
}
})

//these three should be one function.
function transferUrl(transferPath, keywords) {
$.ajax({
url: transferPath,
Expand All @@ -101,7 +118,15 @@ function transferUrl(transferPath, keywords) {
dataType: 'script'
});
}

function batchDelete(batchDeletePath, keywords) {
$.ajax({
url: batchDeletePath,
data: {
keywords: keywords
},
dataType: 'script'
});
}
function moveUrl(movePath, keywords) {
$.ajax({
url: movePath,
Expand All @@ -126,6 +151,8 @@ function changeGroup(groupPath, keyword) {
function initializeUrlDataTable(sortColumn, sortOrder, actionColumn, keywordColumn, showMoveButton, collectionSelect) {
var transferText = '<i class="fa fa-exchange"></i> ' + I18n.t("views.urls.transfer_button");
var moveText = '<i class="fa fa-share-square-o "></i> ' + I18n.t("views.urls.move_button");
var batchDeleteText = '<i class="fa fa-trash-o "></i> ' + I18n.t("views.urls.batch_delete_button");
var bulkActionsText = I18n.t("views.urls.bulk_actions") + '<i class="fa fa-sort-desc "></i> ';

var $urlsTable = $('#urls-table');
var userTable = $urlsTable.DataTable({
Expand Down Expand Up @@ -204,6 +231,8 @@ function initializeUrlDataTable(sortColumn, sortOrder, actionColumn, keywordColu
}
},
fnDrawCallback: function() {
enableDisableTableOptions();

//for all the select pickers in the table
$("table#urls-table .selectpicker").each(function(index, selectPicker) {

Expand Down Expand Up @@ -231,7 +260,7 @@ function initializeUrlDataTable(sortColumn, sortOrder, actionColumn, keywordColu
return false;
}

//else, update its old stored value.
//else, update its old stored value.
$target.data("prev", this.value);
});
});
Expand All @@ -254,6 +283,23 @@ function initializeUrlDataTable(sortColumn, sortOrder, actionColumn, keywordColu
$(".loading-indicator-wrapper").remove();
}
});

//function for disabling bulk table options dropdown
function enableDisableTableOptions(){
var selectedRows = userTable.rows('.selected');
if (selectedRows[0].length){
$(".table-options").removeClass("disabled");
}
else{
$(".table-options").addClass("disabled");

}
}

//use the function for disabling bulk table options dropdown
userTable.on('select', enableDisableTableOptions);
userTable.on('deselect', enableDisableTableOptions);

$('table.data-table').on("page.dt", function(e) {
userTable.rows().deselect();
$("#select-all").prop("checked", false);
Expand All @@ -267,7 +313,7 @@ function initializeUrlDataTable(sortColumn, sortOrder, actionColumn, keywordColu
var transfer_button = {
extend: 'selected',
text: transferText,
className: 'btn-primary js-transfer-urls',
className: 'btn js-transfer-urls',
action: function(e, dt, node, config) {
var keywords = [];
userTable.rows('.selected').data().map(function(row) {
Expand All @@ -279,7 +325,7 @@ function initializeUrlDataTable(sortColumn, sortOrder, actionColumn, keywordColu

var move_button = {
extend: 'selected',
className: 'btn-primary js-move-urls',
className: 'btn js-move-urls',
text: moveText,
action: function(e, dt, node, config) {
var keywords = [];
Expand All @@ -291,15 +337,38 @@ function initializeUrlDataTable(sortColumn, sortOrder, actionColumn, keywordColu
}
}

var batch_delete_button = {
extend: 'selected',
className: 'btn btn-danger js-delete-urls',
text: batchDeleteText,
action: function(e, dt, node, config) {
var keywords = [];
userTable.rows('.selected').data().map(function(row) {
keywords.push(row['DT_RowData']['keyword'])
});

batchDelete($('.route-info').data('new-batch-delete-path'), keywords);
}
}

buttons = []
if (showMoveButton) {
buttons = [transfer_button, move_button]
buttons = [transfer_button, move_button, batch_delete_button]
} else {
buttons = [transfer_button]
}

new $.fn.dataTable.Buttons(userTable, {
var dropdown_button = {
extend: 'collection',
text: bulkActionsText,
className: 'table-options',
autoClose: true,
fade: 200,
buttons: buttons
}

new $.fn.dataTable.Buttons(userTable, {
buttons: [dropdown_button]
});

userTable
Expand All @@ -310,7 +379,6 @@ function initializeUrlDataTable(sortColumn, sortOrder, actionColumn, keywordColu
$(".col-sm-6 .dt-buttons").removeClass("btn-group");
}


$(document).ready(function() {
//url share actions
$("[data-toggle='tooltip']").tooltip();
Expand Down
8 changes: 8 additions & 0 deletions app/assets/stylesheets/layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ though the color below doesn't improve much.
margin-right: 5%;
}

.padding-left-right{
padding-left:20px;
padding-right:20px;
}
#left_text {
text-align: left;
font-size: 1em;
Expand Down Expand Up @@ -702,6 +706,10 @@ div.dataTables_wrapper{
}
}

.modal-body{
word-wrap:break-word;
}

#starburst-close {
display: none;
}
Expand Down
45 changes: 43 additions & 2 deletions app/assets/stylesheets/urls.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
@import 'variables';

button:disabled {
opacity: 0.65;
}

.url {
display: inline;
}
Expand Down Expand Up @@ -207,6 +211,7 @@ table.dataTable{
// box-shadow: 1px 1px 2px rgba(0,0,0,0.1), -1px 1px 2px rgba(0,0,0,0.1);
font-size:13px;
border: 1px solid #ddd;

.short-url{
font-weight:500;
// white-space:nowrap;
Expand All @@ -224,6 +229,10 @@ table.dataTable{
/* display: inline-block; */
}
}
tbody tr td .dropdown .dropdown-menu.dropdown-menu-right a{
color:black;
}

.long-url{
margin-top:1px;
a{
Expand Down Expand Up @@ -313,7 +322,6 @@ table.dataTable{
input{
margin:0;
}

}
.z-hero-title{
color: #666;
Expand All @@ -326,14 +334,46 @@ table.dataTable{
width:300px !important;
}
}
.table-options{
&.disabled{
cursor: not-allowed;
}
i{
margin-left: 5px !important;
vertical-align: top;
}
}
.dt-button-collection.dropdown-menu{
padding:0;
overflow:hidden;
li.btn{
padding:0;
display:block;
text-align:left;
a{
padding: 14px 32px;
}
&.btn-danger{
border-radius:0;
border:none;
color:white;
a{
color:white;
&:hover{
background-color: transparent;
}
}
}

}
}
@media screen and (max-width:900px){
.table-row-edit-main{
.super-input{
input.js-new-url-keyword, input.js-new-group-name{
width:100px;
}
}

}
}
table.dataTable thead .sorting:after, table.dataTable thead .sorting_asc:after, table.dataTable thead .sorting_desc:after, table.dataTable thead .sorting_asc_disabled:after, table.dataTable thead .sorting_desc_disabled:after{
Expand Down Expand Up @@ -737,6 +777,7 @@ $superInputHeight: 50px;
overflow:hidden;
}
}

.dropdown-menu{
padding:0;
a{
Expand Down
29 changes: 29 additions & 0 deletions app/controllers/batch_delete_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class BatchDeleteController < ApplicationController
def new
@urls = Url
.where(keyword: params[:keywords])

respond_to do |format|
format.html
format.js { render 'batch_delete/new', layout: false }
end
end

def create
Url.where(keyword: params[:keywords]).destroy_all
respond_to do |format|
format.js do
redirect_to urls_path
end
#
# respond_to do |format|
# if
# format.js do
# redirect_to urls_path
# end
# else
# format.js { render 'batch_delete/new', layout: false }
# end
end
end
end
28 changes: 28 additions & 0 deletions app/views/batch_delete/_new_modal.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close" ><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel"><%= t('views.batch_delete.new.title')%> </h4>
</div>
<%= form_tag batch_delete_index_path, data: {remote: true}, id: 'batch_delete' do |f| %>
<div class="modal-body">
<h5><%= t('views.batch_delete.new.urls_title')%></h4>
<% @urls.map do |url| %>
<dl class="padding-left-right">
<div>
<span>
<input type="hidden" name="keywords[]" value="<%= url.keyword %>">
<%= full_url(url) %>
</span>
</div>
</dl>
<br/>
<% end %>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal"><%= t('views.collection_moves.new.cancel') %></button>
<input type="submit" class="btn btn-danger" value="<%= t('views.batch_delete.new.submit') %>" data-confirm="<%= t('views.batch_delete.new.submit_confirm') %>">
</div>
<% end %>
</div>
</div>
2 changes: 2 additions & 0 deletions app/views/batch_delete/new.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$("#index-modal").html($("<%= escape_javascript(render(partial: 'batch_delete/new_modal')) %>"))
$("#index-modal").modal()
1 change: 1 addition & 0 deletions app/views/layouts/_navigation_top.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><%= t('views.application.nav.help') %>
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="<%= pages_path(page: :whats_new) %>"><%= t('views.application.nav.whatsnew') %></a></li>
<li><a href="<%= faq_path %>"><%= t('views.application.nav.faq') %></a></li>
<li><a href='mailto:[email protected]'><%= t('views.application.nav.contact_us') %></a></li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion app/views/urls/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</table>
</div>

<%= content_tag :div, class: "route-info", data: {new_transfer_request_path: new_transfer_request_path, new_move_to_group_path: new_move_to_group_path, new_group_path: new_group_path} do %>
<%= content_tag :div, class: "route-info", data: {new_transfer_request_path: new_transfer_request_path, new_move_to_group_path: new_move_to_group_path, new_group_path: new_group_path, new_batch_delete_path: new_batch_delete_path} do %>
<% end %>

<%= content_tag :div, class: "collection-selected", data: {collection_selected: params[:collection]} do %>
Expand Down
1 change: 1 addition & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ class Application < Rails::Application

# Set default time zone
config.time_zone = 'Central Time (US & Canada)'
config.middleware.insert_before Rack::Runtime, 'InvalidDataInterceptor'
end
end
17 changes: 17 additions & 0 deletions config/initializers/invalid_data_interceptor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class InvalidDataInterceptor
def initialize(app)
@app = app
end

def call(env)
query = Rack::Utils.parse_nested_query(env['QUERY_STRING'].to_s) rescue :bad_query

headers = { 'Content-Type' => 'text/plain' }

if query == :bad_query
[400, headers, ['Bad Request']]
else
@app.call(env)
end
end
end
Loading

0 comments on commit 3748461

Please sign in to comment.