diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb new file mode 100644 index 0000000..ece5b38 --- /dev/null +++ b/app/controllers/admin/users_controller.rb @@ -0,0 +1,6 @@ +class Admin::UsersController < ApplicationController + def index + @search = User.ransack(params[:q]) + @users = @search.result(distinct: true).page(params[:page]) + end +end diff --git a/app/views/admin/users/_search_form.html.slim b/app/views/admin/users/_search_form.html.slim new file mode 100644 index 0000000..f369c83 --- /dev/null +++ b/app/views/admin/users/_search_form.html.slim @@ -0,0 +1,8 @@ += search_form_for @search, url: admin_users_path, data: { controller: "search" } do |f| + .input-group + .input-group-prepend + span.input-group-text = t("users.index.search_title") + = f.search_field :first_name_or_last_name_cont, class: "form-control", data: { "search-target": "name" }, placeholder: t("users.index.search_field") + .input-group-append + = f.submit t("button.search"), class: "btn btn-primary" + button[class="btn btn-outline-secondary" data-action="click->search#clear"] = t("button.clear") diff --git a/app/views/admin/users/_user.html.slim b/app/views/admin/users/_user.html.slim new file mode 100644 index 0000000..118bfa9 --- /dev/null +++ b/app/views/admin/users/_user.html.slim @@ -0,0 +1,10 @@ +tr + td = index + 1 + td = user.id + td = user.full_name + td = user.username + td = user.email + td = user.role + - if user.delete_at.present? + td.text-center + i.fa.fa-times.text-danger diff --git a/app/views/admin/users/index.html.slim b/app/views/admin/users/index.html.slim new file mode 100644 index 0000000..021263c --- /dev/null +++ b/app/views/admin/users/index.html.slim @@ -0,0 +1,21 @@ +h3.text-center.mb-4 =t(".title") + +hr += render partial: "search_form" +hr + +table.table + thead + th = t(".order") + th = t(".id") + th = t(".full_name") + th = t(".username") + th = t(".email") + th = sort_link(@search, :role, t(".role")) + th = t(".status") + tbody + - @users.each_with_index do |user,index| + = render partial: "user", locals: { user: user, index: index } + +.d-flex.justify-content-center + = paginate @users diff --git a/config/locales/en.yml b/config/locales/en.yml index a313596..614af1b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -97,6 +97,9 @@ en: position: "Position: %{position}" your_project: "Your projects" common_projects: "Common projects" + index: + search_field: "Full name" + search_title: "Search" favorites: index: title: "Favorites" @@ -135,6 +138,18 @@ en: confirm: not_found: "Invitation is not found" + admin: + users: + index: + title: "Users list" + user: + order: "Ordinal number" + id: "ID" + full_name: "Full name" + username: "Username" + email: "E-mail" + role: "Role" + status: "Enable" api: v1: diff --git a/config/routes.rb b/config/routes.rb index 456f434..290086e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -65,6 +65,7 @@ put :toggle, to: "background_jobs#toggle" end end + resources :users, only: [:index] end # TODO: check user is admin diff --git a/config/webpack/environment.js b/config/webpack/environment.js deleted file mode 100644 index 1a297bf..0000000 --- a/config/webpack/environment.js +++ /dev/null @@ -1,12 +0,0 @@ -const { environment } = require('@rails/webpacker') - -const webpack = require("webpack") - -environment.plugins.append("Provide", new webpack.ProvidePlugin({ - $: 'jquery', - jQuery: 'jquery', - Popper: ['popper.js', 'default'] -})) - -module.exports = environment - diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index c749b03..e7f56be 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -13,6 +13,7 @@ require_relative "./support/desvise" require_relative "./support/view_component_helper" require_relative "./support/api_helper" +require_relative "./support/capybara" begin ActiveRecord::Migration.maintain_test_schema! diff --git a/spec/requests/admin/users_spec.rb b/spec/requests/admin/users_spec.rb new file mode 100644 index 0000000..0d8c58a --- /dev/null +++ b/spec/requests/admin/users_spec.rb @@ -0,0 +1,25 @@ +require 'rails_helper' + +RSpec.describe "Admin::Users", type: :request do + before do + create_list(:user, 26) + end + + describe "GET /admin/users" do + it "http status success" do + get admin_users_path + expect(response).to have_http_status(:success) + end + + it "displays 25 users on the first page" do + visit admin_users_path + expect(page).to have_selector("tbody tr", count: 25) + end + + it "displays 1 user on the second page" do + visit admin_users_path + click_link "2" + expect(page).to have_selector("tbody tr", count: 1) + end + end +end diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb new file mode 100644 index 0000000..a3441ad --- /dev/null +++ b/spec/support/capybara.rb @@ -0,0 +1,3 @@ +RSpec.configure do |config| + config.include Capybara::DSL, type: :request +end