From 0130570d5578311a9700a7d40b456111093c7f1c Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 18 Oct 2017 17:33:08 +0200 Subject: [PATCH 1/7] Implement pagination & search for users list --- app/assets/javascripts/app/app.js.coffee | 49 --------- app/controllers/users_controller.rb | 12 ++- app/helpers/users_helper.rb | 36 ++----- app/views/users/_user_rows.html.erb | 123 +++++++++++------------ app/views/users/index.html.erb | 73 ++------------ app/views/users/index.js.erb | 2 - config/locales/ca.yml | 6 +- config/locales/en.yml | 56 +++++------ config/locales/es.yml | 14 +-- config/locales/pt-BR.yml | 6 +- 10 files changed, 127 insertions(+), 250 deletions(-) delete mode 100644 app/views/users/index.js.erb diff --git a/app/assets/javascripts/app/app.js.coffee b/app/assets/javascripts/app/app.js.coffee index bee55ffcb..3f41c7d5b 100644 --- a/app/assets/javascripts/app/app.js.coffee +++ b/app/assets/javascripts/app/app.js.coffee @@ -1,51 +1,2 @@ -angular.module('timeoverflow').controller 'UserListCtrl', ["$scope", "$modal", "$http", "$location", ($scope, $modal, $http, $location) -> - - $scope.sortBy = (field) -> - $scope.sort = if $scope.sort == field then "-#{field}" else field - $scope.filterTerm = '' - $scope.$location = $location - - ['filterTerm', 'sort'].map (prop) -> - Object.defineProperty($scope, prop, - get: -> - if prop == 'sort' and $location.search()[prop] == undefined - 'member_id' - else - $location.search()[prop] - set: (val) -> $location.search(prop, val || null) - ) - - $scope.toggle_manager = (user) -> - $modal.open( - templateUrl: 'confirm_toggle_manager.html' - size: 'sm' - scope: $scope - controller: ["$scope", ($scope) -> $scope.username = user.username] - ).result - .then(-> $http.put(user.toggle_manager_link)) - .then(-> user.manager = !user.manager) - - $scope.toggle_active = (user) -> - $modal.open( - templateUrl: 'confirm_toggle_active.html' - size: 'sm' - scope: $scope - controller: ["$scope", ($scope) -> $scope.username = user.username] - ).result - .then(-> $http.put(user.toggle_active_link)) - .then(-> user.active = !user.active) -] - # override this in a view where the organizations are needed angular.module('timeoverflow').value 'Organizations', [] - -angular.module('timeoverflow').filter 'timeBalance', -> - (seconds) -> - if seconds isnt 0 - minutes = Math.abs(seconds) / 60 - hours = (minutes / 60) >> 0 - minutes %= 60 - minutes >>= 0; - if seconds < 0 then "-#{hours}:#{minutes}" else "#{hours}:#{minutes}" - else - "—" diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 68f6fb828..6d818c160 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,12 +1,10 @@ class UsersController < ApplicationController before_filter :authenticate_user! - def scoped_users - current_organization.users - end - def index - @users = scoped_users + @search = scoped_users.ransack(params[:q]) + @users = @search.result(distinct: false).page(params[:page]).per(25) + @memberships = current_organization.members. where(user_id: @users.map(&:id)). includes(:account).each_with_object({}) do |mem, ob| @@ -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" diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 947b95fa0..ac3d541a0 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -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 - 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 diff --git a/app/views/users/_user_rows.html.erb b/app/views/users/_user_rows.html.erb index 0f7ada7b8..d1f305e46 100644 --- a/app/views/users/_user_rows.html.erb +++ b/app/views/users/_user_rows.html.erb @@ -1,64 +1,63 @@ - - - - - {{user.member_id}} - - - {{user.username}} - - - - {{user.email}} - - - {{user.unconfirmed_email}} - - - {{user.phone}} - {{user.alt_phone}} - {{user.balance | timeBalance}} - <% if current_user.manages?(current_organization) %> - - - <%= glyph :pencil %> - <%= t "global.edit" %> - - "> - <%= glyph :ban_circle %> - <%= t "global.cancel_membership" %> - - - - <%= glyph :arrow_down %> - <%= t "global.demote" %> - - - <%= glyph :arrow_up %> - <%= t "global.promote" %> - - - - - <%= glyph :remove %> - <%= t ".deactivate" %> - - - <%= glyph :ok %> - <%= t ".activate" %> - - +<% users.each do |user| %> + <% membership = @memberships[user.id] %> + + <%= content_tag(:tr, class: membership.active? ? "" : "bg-danger") do %> + + <%= image_tag avatar_url(user, 32), width: 32, height: 32 %> + <%= membership.member_uid %> + + <% if !membership.active? %><% end %> + <%= link_to user.username, user_path(user) %> + + + <% if user.unconfirmed_email %> + + <%= user.unconfirmed_email %> + + <% else %> + + <%= user.email %> + + <% end %> + + <%= user.phone %> + <%= user.alt_phone %> + <%= time_balance(membership.account_balance.to_i) %> + <% if current_user.manages?(current_organization) %> + + <%= link_to edit_user_path(user), class: "action" do %> + <%= glyph :pencil %> + <%= t "global.edit" %> + <% end %> + + <% if membership.active? %> + <%= link_to toggle_manager_member_path(membership), class: "action", method: :put, data: { confirm: t('users.index.manage_warning', username: user.username) } do %> + <% if !!membership.manager %> + <%= glyph :arrow_down %> + <%= t "global.demote" %> + <% else %> + <%= glyph :arrow_up %> + <%= t "global.promote" %> + <% end %> + <% end %> + <% else %> + <%= link_to cancel_member_path(membership), class: "action", data: { confirm: t('.cancel_warning', user: user.username) }, method: :delete do %> + <%= glyph :ban_circle %> + <%= t("global.cancel_membership") %> + <% end %> + <% end %> + + <%= link_to toggle_active_member_path(membership), class: "action", method: :put, data: { confirm: t('users.index.active_warning', username: user.username) } do %> + <% if membership.active? %> + <%= glyph :remove %> + <%= t ".deactivate" %> + <% else %> + <%= glyph :ok %> + <%= t ".activate" %> + <% end %> + <% end %> + + <% end %> <% end %> - +<% end %> diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 546e630fa..316bf2e29 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -1,23 +1,14 @@ -
+

<%= User.model_name.human.pluralize %> — <%= link_to current_organization.name, organization_path(current_organization) %> - <% if params[:q].present? %> - - <%= glyph :search %> - <%= params[:q] %> - - <% end %>

-
- - - - - +
diff --git a/app/views/users/index.js.erb b/app/views/users/index.js.erb deleted file mode 100644 index 8652f5c3e..000000000 --- a/app/views/users/index.js.erb +++ /dev/null @@ -1,2 +0,0 @@ -$('table.users tbody').append("<%= j(render 'users/user_rows', users: @users) %>"); -$('table.users a[rel=next]').replaceWith("<%= link_to_next_page @users, t('.more'), remote: true, class: 'btn btn-default', params: params %>"); diff --git a/config/locales/ca.yml b/config/locales/ca.yml index 4a9a35cf8..5dec95ead 100644 --- a/config/locales/ca.yml +++ b/config/locales/ca.yml @@ -487,10 +487,10 @@ ca: give_time: Donar Temps a index: actions: Accions - active_warning_angular: Vas a canviar l'estat del compte de l'usuari {{username}} - cancel_warning_angular: Vas a eliminar del banc a l'usuari {{username}} + active_warning: Vas a canviar l'estat del compte de l'usuari %{username} + cancel_warning: Vas a eliminar del banc a l'usuari %{username} create: Crear nou usuari - manage_warning_angular: Vas a canviar els permisos de l'usuari {{username}} + manage_warning: Vas a canviar els permisos de l'usuari %{username} user_created: Usuari %{uid} %{name} guardat new: cancel: Cancel·lar diff --git a/config/locales/en.yml b/config/locales/en.yml index 31ea4fdfa..25e3338b9 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -65,7 +65,7 @@ en: identity_document: Identity Document last_sign_in_at: Last login notifications: Receive notifications - organization: + organization: phone: Phone registration_date: Registration date registration_number: User code @@ -218,20 +218,20 @@ en: registrations: destroyed: Bye! Your account was successfully cancelled. We hope to see you again soon. edit: - cancel_account: - current_password: - edit_user: - help_current_password: - help_password: - password: - password_confirmation: - unhappy: - update: + cancel_account: + current_password: + edit_user: + help_current_password: + help_password: + password: + password_confirmation: + unhappy: + update: new: - password: - password_confirmation: - sign_me_up: - sign_up: + password: + password_confirmation: + sign_me_up: + sign_up: signed_up: Welcome! You have signed up successfully. signed_up_but_inactive: You have signed up successfully. However, we could not sign you in because your account is not yet activated. signed_up_but_locked: You have signed up successfully. However, we could not sign you in because your account is locked. @@ -315,14 +315,14 @@ en: report: report_title: REPORT locales: - ar: + ar: ca: Catalan en: English es: Spanish - eu: - fr: - gl: - pt: + eu: + fr: + gl: + pt: pt-BR: Portuguese mailers_globals: footer: @@ -467,7 +467,7 @@ en: terms: accept: Accept show: - accept: + accept: transfers: computation: hour: @@ -487,10 +487,10 @@ en: give_time: Give time to index: actions: Actions - active_warning_angular: You are going to change user account status for {{username}} - cancel_warning_angular: You are going to delete account from the Time Bank for user {{username}} + active_warning: You are going to change user account status for %{username} + cancel_warning: You are going to delete account from the Time Bank for user %{username} create: Create new user - manage_warning_angular: You are going to change privileges for user {{username}} + manage_warning: You are going to change privileges for user %{username} user_created: User %{uid} %{name} saved new: cancel: Cancel @@ -524,8 +524,8 @@ en: manage_warning: You are going to change privileges for user %{user} views: pagination: - first: - last: - next: - previous: - truncate: + first: + last: + next: + previous: + truncate: diff --git a/config/locales/es.yml b/config/locales/es.yml index 63612b342..cf1d6a8df 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -65,7 +65,7 @@ es: identity_document: DNI last_sign_in_at: Fecha último login notifications: Recibir notificaciones - organization: + organization: phone: Teléfono registration_date: Fecha de alta registration_number: Código de usuario @@ -127,7 +127,7 @@ es: sing_out: Desconectar menus: offers_by_tag_link: - tags: + tags: navbar: admin: Administrar administration: Administración @@ -246,7 +246,7 @@ es: remember_me: Recordarme sign_in: Entrar user: - signed_in: + signed_in: shared: links: didnt_receive_confirmation_instructions: Volver a enviar correo de confirmación @@ -472,7 +472,7 @@ es: terms: accept: Aceptar show: - accept: + accept: transfers: computation: hour: @@ -492,10 +492,10 @@ es: give_time: Dar Tiempo a index: actions: Acciones - active_warning_angular: Va a cambiar el estado de la cuenta del usuario {{username}} - cancel_warning_angular: Va a eliminar del banco al usuario {{username}} + active_warning: Va a cambiar el estado de la cuenta del usuario %{username} + cancel_warning: Va a eliminar del banco al usuario %{username} create: Crear nuevo usuario - manage_warning_angular: Va a cambiar los privilegios del usuario {{username}} + manage_warning: Va a cambiar los privilegios del usuario %{username} user_created: Usuario %{uid} %{name} guardado new: cancel: Cancelar diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index 518f2dae2..1791758e2 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -492,10 +492,10 @@ pt-BR: give_time: Dar Tempo a index: actions: Ações - active_warning_angular: Mudará o estado da conta do usuário {{username}} - cancel_warning_angular: Eliminará o usuário do banco {{username}} + active_warning: Mudará o estado da conta do usuário %{username} + cancel_warning: Eliminará o usuário do banco %{username} create: Criar novo usuário - manage_warning_angular: Mudará os privilégios do usuário {{username}} + manage_warning: Mudará os privilégios do usuário %{username} user_created: Usuário %{uid} %{name} guardado new: cancel: Cancelar From 310db059abe5fa9599d63462559e841c7ef1d920 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Wed, 18 Oct 2017 18:04:14 +0200 Subject: [PATCH 2/7] Remove angular traces --- app/assets/javascripts/app/app.js.coffee | 2 - app/assets/javascripts/application.js.coffee | 6 +- app/assets/javascripts/libs.js | 3 - app/assets/stylesheets/application.css.scss | 9 +- app/views/layouts/application.html.erb | 8 +- vendor/assets/javascripts/angular.min.js | 210 - .../javascripts/ng-rails-csrf.js.coffee | 17 - .../javascripts/ui-bootstrap-tpls-0.11.0.js | 4116 ----------------- 8 files changed, 6 insertions(+), 4365 deletions(-) delete mode 100644 app/assets/javascripts/app/app.js.coffee delete mode 100644 vendor/assets/javascripts/angular.min.js delete mode 100644 vendor/assets/javascripts/ng-rails-csrf.js.coffee delete mode 100644 vendor/assets/javascripts/ui-bootstrap-tpls-0.11.0.js diff --git a/app/assets/javascripts/app/app.js.coffee b/app/assets/javascripts/app/app.js.coffee deleted file mode 100644 index 3f41c7d5b..000000000 --- a/app/assets/javascripts/app/app.js.coffee +++ /dev/null @@ -1,2 +0,0 @@ -# override this in a view where the organizations are needed -angular.module('timeoverflow').value 'Organizations', [] diff --git a/app/assets/javascripts/application.js.coffee b/app/assets/javascripts/application.js.coffee index 8fcd14578..d37fff8f0 100644 --- a/app/assets/javascripts/application.js.coffee +++ b/app/assets/javascripts/application.js.coffee @@ -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'); @@ -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() \ No newline at end of file + event.preventDefault() diff --git a/app/assets/javascripts/libs.js b/app/assets/javascripts/libs.js index d54523d4c..63a46c808 100644 --- a/app/assets/javascripts/libs.js +++ b/app/assets/javascripts/libs.js @@ -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 diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss index 73c38db59..d6bbe170c 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.css.scss @@ -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%; } @@ -166,7 +161,7 @@ html { font-weight: 400; height: 7.5rem; } - + .form-control:focus { border-color: none; box-shadow: none; @@ -622,7 +617,7 @@ form .checkbox input[type="checkbox"] { .material-icons { font-size: 3rem; } - + .checkbox { color: $form-login-gray-text; font-size: 1.6rem; diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 71b40ce46..c9aa9882d 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -23,9 +23,7 @@ <%= javascript_include_tag 'libs' %> <%= javascript_include_tag 'application' %> - + <%= render 'navbar' %>
<%= render 'layouts/messages' %> @@ -37,7 +35,7 @@