Skip to content

Commit

Permalink
Merge branch 'develop' into ruby-2.4.1#147050603
Browse files Browse the repository at this point in the history
  • Loading branch information
patmbolger authored Jun 19, 2017
2 parents 12b5bee + d604caa commit 60d04a0
Show file tree
Hide file tree
Showing 21 changed files with 573 additions and 110 deletions.
4 changes: 4 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ $(function() {
// the prior pagination page (DOM element) with the new page.
$('body').on('ajax:success', '.companies_pagination', function (e, data) {
$('#companies_list').html(data);
// In case there is tooltip(s) in rendered element:
$('[data-toggle="tooltip"]').tooltip();
});

$('body').on('ajax:success', '.applications_pagination', function (e, data) {
$('#membership_applications_list').html(data);
// In case there is tooltip(s) in rendered element:
$('[data-toggle="tooltip"]').tooltip();
});

// Enable all Bootstrap tooltips
Expand Down
11 changes: 10 additions & 1 deletion app/assets/stylesheets/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@ select {
margin-top: 0;
}

/* style for row (div) using flex model, with contained elements
* aligned horizontally by center.
* https://www.w3schools.com/css/css3_flexbox.asp
*/
.center-aligned-container {
display: flex;
align-items: center;
}

/*!
*nicelabel JQuery Plugin
*
Expand Down Expand Up @@ -264,4 +273,4 @@ select {
}
.admin {
padding-top:80px;
}
}
10 changes: 7 additions & 3 deletions app/controllers/companies_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
class CompaniesController < ApplicationController
include PaginationUtility

before_action :set_company, only: [:show, :edit, :update, :destroy]
before_action :authorize_company, only: [:update, :show, :edit, :destroy]


def index
authorize Company

@search_params = Company.ransack(params[:q])
action_params, @items_count, items_per_page = process_pagination_params('company')

@search_params = Company.ransack(action_params)

# only select companies that are 'complete'; see the Company.complete scope

@all_companies = @search_params.result(distinct: true)
Expand All @@ -20,12 +25,11 @@ def index
# allowing sorting on an associated table column ("region" in this case)
# https://github.com/activerecord-hackery/ransack#problem-with-distinct-selects


@all_visible_companies = @all_companies.address_visible

@all_visible_companies.each { | co | geocode_if_needed co }

@companies = @all_companies.page(params[:page]).per_page(10)
@companies = @all_companies.page(params[:page]).per_page(items_per_page)

render partial: 'companies_list' if request.xhr?
end
Expand Down
69 changes: 69 additions & 0 deletions app/controllers/concerns/pagination_utility.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
module PaginationUtility
extend ActiveSupport::Concern

# This constant is used to specify "all" items to be shown in a view that
# uses the will_paginate gem for listing a collection. That has to be a number.
# This particular number is used when the user selects "All" in the
# items-per-page selection.
ALL_ITEMS = 10_000.freeze

DEFAULT_ITEMS_SELECTION = 10.freeze # Default items-per-page setting

def process_pagination_params(entity)

# This method is used in controller actions involved in pagination of
# collection tables (e.g., companies, member_applications).

# It is passed a string that indicates the type of paginated collection,
# e.g. "company", "membership_application".

# It returns:
# 1) search params hash, for use with ransack gems "ransack" method,
# 2) the user's last items-per-page selection (an integer or 'All'),
# 3) the actual number of items-per-page to show in the table.

# This method uses the session to store (and recover) search criteria
# and per-page items selection. These need to be persisted across action
# invocations in order to accommodate the multiple ways in which a
# typical controller "index" action might be called.

# For instance, the companies_controller "index" action is called when:
# 1) loading the index page,
# 2) moving to another pagination page in the companies listing table (XHR),
# 3) sorting on one of the table columns,
# 4) executing a companies search from the index page, and,
# 5) changing per-page items count in the pagination table on that page (XHR).

entity_items_selection = (entity + '_items_selection').to_sym
entity_search_criteria = (entity + '_search_criteria').to_sym

if params[:items_count] # << user has selected a per-page items count
items_count = params[:items_count]
items_selection = items_count == 'All' ? 'All' : items_count.to_i

session[entity_items_selection] = items_selection

search_criteria = JSON.parse(session[entity_search_criteria])

search_params = search_criteria ?
ActionController::Parameters.new(search_criteria) : nil

# Reset params hash so that sort_link works correctly in the view
# (the sort links are built using, as one input, the controller params)
params[:q] = search_params
params.delete(:items_count)

else
items_selection = session[entity_items_selection] ?
session[entity_items_selection] : DEFAULT_ITEMS_SELECTION

session[entity_search_criteria] = params[:q].to_json

search_params = params[:q]
end

items_per_page = items_selection == 'All' ? ALL_ITEMS : items_selection

[ search_params, items_selection, items_per_page ]
end
end
9 changes: 7 additions & 2 deletions app/controllers/membership_applications_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class MembershipApplicationsController < ApplicationController
include PaginationUtility

before_action :get_membership_application, except: [:information, :index, :new, :create]
before_action :authorize_membership_application, only: [:update, :show, :edit]

Expand All @@ -13,12 +15,15 @@ def new
def index
authorize MembershipApplication

@search_params = MembershipApplication.ransack(params[:q])
action_params, @items_count, items_per_page =
process_pagination_params('membership_application')

@search_params = MembershipApplication.ransack(action_params)

@membership_applications = @search_params
.result
.includes(:business_categories)
.page(params[:page]).per_page(10)
.page(params[:page]).per_page(items_per_page)

render partial: 'membership_applications_list' if request.xhr?
end
Expand Down
11 changes: 10 additions & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module ApplicationHelper


def flash_class(level)
case level.to_sym
when :notice then
Expand Down Expand Up @@ -121,5 +120,15 @@ def unique_css_id(active_record_item)
"#{active_record_item.class.name.downcase}-#{unique_id}"
end

# Returns a string of option tags for a 'select' element.
# The select element allows the user to select the number of items to
# appear on each pagination page.
# The 'count' argument is the currently-select items count.

ITEMS_COUNT = [ ['10', 10], ['25', 25], ['50', 50], ['All', 'All'] ].freeze

def paginate_count_options(count=10)
options_for_select(ITEMS_COUNT, count)
end

end
22 changes: 22 additions & 0 deletions app/views/application/_paginate_footer.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.row.center-aligned-container

.col-sm-8.col-sm-offset-2{ style: 'text-align: center;' }
= will_paginate entities,
renderer: BootstrapPagination::Rails,
link_options: { 'data-remote': true,
class: paginate_class }

.col-sm-2{ style: 'text-align: right;' }
-# override min-width from 'custom.css' - too wide
= select_tag(:items_count, paginate_count_options(items_count),
data: { remote: true,
url: url },
style: 'min-width: 50px;',
class: paginate_class )

%span.glyphicon.glyphicon-info-sign{ title: "#{t('items_per_page_tooltip')}",
data: {toggle: 'tooltip'} }
-#
for background on will_paginate method args, see:
https://gist.github.com/jeroenr/3142686, and
https://github.com/bootstrap-ruby/will_paginate-bootstrap
14 changes: 5 additions & 9 deletions app/views/companies/_companies_list.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,9 @@
%td= link_to "#{t('edit')}", edit_company_path(company)
%td= link_to "#{t('delete')}", company, method: :delete,
data: { :confirm => "#{t('confirm_are_you_sure')}" }
.center
= will_paginate @companies,
renderer: BootstrapPagination::Rails,
link_options: { 'data-remote': true,
class: 'companies_pagination' }

-#
for background on above statement, see:
https://gist.github.com/jeroenr/3142686, and
https://github.com/bootstrap-ruby/will_paginate-bootstrap
= render partial: 'application/paginate_footer',
locals: { entities: @companies,
paginate_class: 'companies_pagination',
items_count: @items_count,
url: companies_path }
54 changes: 26 additions & 28 deletions app/views/companies/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@
.index.company#companies
%header.entry-header
- unless current_user.try(:admin)
%h1.entry-title= t('.title')
- if current_user.try(:admin)
%h1.entry-title= t('.admin_title')

%header.entry-header
- unless current_user.try(:admin)
%h1.entry-title= t('.title')
- if current_user.try(:admin)
%h1.entry-title= t('.admin_title')
.entry-content

.entry-content
.row
= render 'map_companies',
markers: location_and_markers_for(@all_visible_companies)

.row
= render 'map_companies',
markers: location_and_markers_for(@all_visible_companies)

- unless current_user.try(:admin)

- unless current_user.try(:admin)
.search-instructions
%h3
#{t('.h_companies_listed_below')}
%br
#{t('.how_to_search')}

.search-instructions
%h3
#{t('.h_companies_listed_below')}
%br
#{t('.how_to_search')}
%button.btn.hide-search-form.btn-success.btn-xs.pull-right{ id: 'toggle_search_form',
href: '#company_search_form',
style: 'color:black; text-transform:none;' }
#{t('toggle.company_search_form.hide')}

%button.btn.hide-search-form.btn-success.btn-xs.pull-right{ id: 'toggle_search_form',
href: '#company_search_form',
style: 'color:black; text-transform:none;' }
#{t('toggle.company_search_form.hide')}
.panel.panel-default.search-panel{ id: 'company_search_form' }

.panel.panel-default.search-panel{ id: 'company_search_form' }
= render 'search_form'

= render 'search_form'


- if @companies.empty?
%strong
#{t('.no_search_results')}
- else
= render partial: 'companies_list'
- if @companies.empty?
%strong
#{t('.no_search_results')}
- else
= render partial: 'companies_list'
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
%td.state= t("membership_applications.state.#{membership_application.state}")
%td.action= link_to "#{t('manage')}", membership_application_path(membership_application.id)

.center
= will_paginate @membership_applications,
renderer: BootstrapPagination::Rails,
link_options: { 'data-remote': true,
class: 'applications_pagination' }
= render partial: 'application/paginate_footer',
locals: { entities: @membership_applications,
paginate_class: 'applications_pagination',
items_count: @items_count,
url: membership_applications_path }
2 changes: 1 addition & 1 deletion config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
lock '3.6.1'

set :rbenv_type, :user
set :rbenv_ruby, '2.3.1'
set :rbenv_ruby, '2.4.0'

set :application, 'shf'
set :repo_url, '[email protected]:AgileVentures/shf-project.git'
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ en:
next_label: "Next »"
page_gap: "&hellip;"

items_per_page_tooltip: 'Select number of items per page'

ckeditor:
page_title: 'CKEditor Files Manager'
confirm_delete: 'Delete file?'
Expand Down
2 changes: 2 additions & 0 deletions config/locales/sv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ sv:
next_label: "Nästa »"
page_gap: "&hellip;"

items_per_page_tooltip: 'Välj antal objekt per sida'

ckeditor:
page_title: 'CKEditor Filer'
confirm_delete: 'Radera fil?'
Expand Down
Loading

0 comments on commit 60d04a0

Please sign in to comment.