Skip to content

Refactor Users#index to paginate and filter on the backend. Closes #266 #272

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

Merged
merged 8 commits into from
Jan 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 0 additions & 51 deletions app/assets/javascripts/app/app.js.coffee

This file was deleted.

6 changes: 1 addition & 5 deletions app/assets/javascripts/application.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@
#= require datepicker
#= require give_time
#= require tags
#= require_tree ./app

angular.module "timeoverflow", ["ng-rails-csrf", 'ui.bootstrap']

$(document).on 'click', 'a[data-popup]', (event) ->
window.open($(this).attr('href'), 'popup', 'width=600,height=600')
event.preventDefault()


$(document).on 'click', 'span.show-password', (event) ->
if $(this).hasClass('checked')
$(this).removeClass('checked');
Expand All @@ -20,4 +16,4 @@ $(document).on 'click', 'span.show-password', (event) ->
$(this).addClass('checked');
$(this).prev('input').attr('type', 'text');
$(this).find('.material-icons').html("visibility_off")
event.preventDefault()
event.preventDefault()
3 changes: 0 additions & 3 deletions app/assets/javascripts/libs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,3 @@
//= require highcharts
//= require highcharts-exporting
//= require select2
//= require angular.min
//= require ui-bootstrap-tpls-0.11.0
//= require ng-rails-csrf
13 changes: 6 additions & 7 deletions app/assets/stylesheets/application.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ $pages-anchor-hover: #8a8a8a;
$features-background: #f5f5f5;
$features-separator: #d8d8d8;

[ng-cloak],
.ng-cloak {
visibility: hidden !important;
}

html {
font-size:62.5%;
}
Expand Down Expand Up @@ -166,7 +161,7 @@ html {
font-weight: 400;
height: 7.5rem;
}

.form-control:focus {
border-color: none;
box-shadow: none;
Expand Down Expand Up @@ -264,6 +259,10 @@ html {
padding: 10px;
}

.table-responsive {
overflow-x: inherit;
}

table.users {
padding: 10px;
}
Expand Down Expand Up @@ -631,7 +630,7 @@ form .checkbox input[type="checkbox"] {
.material-icons {
font-size: 3rem;
}

.checkbox {
color: $form-login-gray-text;
font-size: 1.6rem;
Expand Down
22 changes: 12 additions & 10 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
class UsersController < ApplicationController
before_filter :authenticate_user!

def scoped_users
current_organization.users
end

def index
@users = scoped_users
@memberships = current_organization.members.
where(user_id: @users.map(&:id)).
includes(:account).each_with_object({}) do |mem, ob|
ob[mem.user_id] = mem
end
@search = current_organization.users.ransack(params[:q])

@users = @search
.result(distinct: false)
.joins(members: :account)
.eager_load(members: :account)
.page(params[:page])
.per(25)
end

def show
Expand Down Expand Up @@ -75,6 +73,10 @@ def give_time

private

def scoped_users
current_organization.users
end

def user_params
fields_to_permit = %w"gender username email date_of_birth phone
alt_phone active description notifications"
Expand Down
36 changes: 8 additions & 28 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
@@ -1,34 +1,14 @@
module UsersHelper
# TODO refactor or eliminate - poosibly the second.
def users_as_json
@users = (admin? || superadmin?) ? @users : @users.actives
@users.map do |user|
membership = @memberships[user.id]
{
id: user.id,
avatar: avatar_url(user),
member_id: membership.member_uid,
username: user.username,
email: user.email_if_real,
unconfirmed_email: user.unconfirmed_email,
phone: user.phone,
alt_phone: user.alt_phone,
balance: membership.account_balance.to_i,

url: user_path(user),
edit_link: edit_user_path(user),
cancel_link: cancel_member_path(membership),
toggle_manager_link: toggle_manager_member_path(membership),
manager: !!membership.manager,
toggle_active_link: toggle_active_member_path(membership),
active: membership.active?,
valid_email: user.has_valid_email?
}
end.to_json.html_safe
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to make sure we also get rid of the private methods this might use.


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private

def time_balance(seconds)
if seconds.zero?
"—"
else
[seconds / (60 * 60), (seconds / 60) % 60].map{|value| value.to_s.rjust(2, "0") }.join(":")
end
end

def edit_user_path(user)
can_edit_user?(user) ? super : ""
end
Expand Down
4 changes: 2 additions & 2 deletions app/views/application/menus/_language_switcher.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<li>
<div class="language-selector">
<div class="dropdown dropdown-language-selector">
<a class="btn btn-default dropdown-toggle language" type="button" id="dropdownLanguage">
<a class="btn btn-default dropdown-toggle language" type="button" id="dropdownLanguage" data-toggle="dropdown">
<span><%= t("locales.#{locale}") %></span>
<b class="caret"></b>
</a>
Expand All @@ -16,4 +16,4 @@
</ul>
</div>
</div>
</li>
</li>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<li class="dropdown">
<a class="dropdown-toggle" href="#">
<a class="dropdown-toggle" href="#" data-toggle="dropdown">
<%= glyph :wrench %>
<%= t "application.navbar.admin" %>
<b class="caret"></b>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<li class="dropdown">
<a class="dropdown-toggle" href="#">
<a class="dropdown-toggle" href="#" data-toggle="dropdown">
<%= glyph :paperclip %>
<%= t "application.navbar.reports" %>
<b class="caret"></b>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<li class="dropdown">
<a class="dropdown-toggle" href="#">
<a class="dropdown-toggle" href="#" data-toggle="dropdown">
<%= glyph :stats %>
<%= t "application.navbar.statistics" %>
<b class="caret"></b>
Expand Down
2 changes: 1 addition & 1 deletion app/views/application/menus/_user_admin_menu.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<li class="dropdown">
<a class="dropdown-toggle" href="#">
<a class="dropdown-toggle" href="#" data-toggle="dropdown">
<%= image_tag avatar_url(current_user), style: "margin: -8px auto" %>
<%= current_user.email %>
<b class="caret"></b>
Expand Down
2 changes: 1 addition & 1 deletion app/views/inquiries/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</form>
<ul class="nav navbar-nav">
<li class="dropdown">
<a class="dropdown-toggle" href="#">
<a class="dropdown-toggle" href="#" data-toggle="dropdown">
<%= @category ? @category.name : Category.model_name.human %>
<span class="caret"></span>
</a>
Expand Down
8 changes: 3 additions & 5 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
<%= javascript_include_tag 'libs' %>
<%= javascript_include_tag 'application' %>
</head>
<body class="<%= get_body_css_class(controller.controller_name) %>" data-action="<%= params[:controller] %>-<%= params[:action] %>"
ng-app="timeoverflow"
ng-cloak>
<body class="<%= get_body_css_class(controller.controller_name) %>" data-action="<%= params[:controller] %>-<%= params[:action] %>">
<%= render 'navbar' %>
<div class="container content">
<%= render 'layouts/messages' unless devise_controller? %>
Expand All @@ -37,7 +35,7 @@
</div>
</div>
<div class="footer container-fluid">
<div class="container">
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-4 col-md-4 col-lg-4 footer-left-col">
<p>
Expand All @@ -60,7 +58,7 @@
</div>
</div>
</div>
<div class="back-overlay"></div>
<div class="back-overlay"></div>
<!-- Piwik -->
<script type="text/javascript">
var _paq = _paq || [];
Expand Down
2 changes: 1 addition & 1 deletion app/views/offers/dashboard.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</form>
<ul class="nav navbar-nav">
<li class="dropdown">
<a class="dropdown-toggle" href="#">
<a class="dropdown-toggle" href="#" data-toggle="dropdown">
<%= @category ? @category.name : Category.model_name.human %>
<span class="caret"></span>
</a>
Expand Down
2 changes: 1 addition & 1 deletion app/views/offers/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</form>
<ul class="nav navbar-nav">
<li class="dropdown">
<a class="dropdown-toggle" href="#">
<a class="dropdown-toggle" href="#" data-toggle="dropdown">
<%= @category ? @category.name : Category.model_name.human %>
<span class="caret"></span>
</a>
Expand Down
Loading