From 8e3d819889c28177dd63cddea6666a4f48a4caef Mon Sep 17 00:00:00 2001 From: Alex Smirnov Date: Sat, 25 Feb 2023 23:07:25 +0300 Subject: [PATCH 01/19] Add controller for admin/users --- app/assets/stylesheets/admin/users.scss | 3 +++ app/controllers/admin/users_controller.rb | 2 ++ app/helpers/admin/users_helper.rb | 2 ++ config/webpack/environment.js | 12 ------------ spec/helpers/admin/users_helper_spec.rb | 15 +++++++++++++++ spec/requests/admin/users_spec.rb | 7 +++++++ 6 files changed, 29 insertions(+), 12 deletions(-) create mode 100644 app/assets/stylesheets/admin/users.scss create mode 100644 app/controllers/admin/users_controller.rb create mode 100644 app/helpers/admin/users_helper.rb delete mode 100644 config/webpack/environment.js create mode 100644 spec/helpers/admin/users_helper_spec.rb create mode 100644 spec/requests/admin/users_spec.rb diff --git a/app/assets/stylesheets/admin/users.scss b/app/assets/stylesheets/admin/users.scss new file mode 100644 index 0000000..4b75194 --- /dev/null +++ b/app/assets/stylesheets/admin/users.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the admin/Users controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: https://sass-lang.com/ diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb new file mode 100644 index 0000000..b5bd3ac --- /dev/null +++ b/app/controllers/admin/users_controller.rb @@ -0,0 +1,2 @@ +class Admin::UsersController < ApplicationController +end diff --git a/app/helpers/admin/users_helper.rb b/app/helpers/admin/users_helper.rb new file mode 100644 index 0000000..5995c2a --- /dev/null +++ b/app/helpers/admin/users_helper.rb @@ -0,0 +1,2 @@ +module Admin::UsersHelper +end 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/helpers/admin/users_helper_spec.rb b/spec/helpers/admin/users_helper_spec.rb new file mode 100644 index 0000000..f26854e --- /dev/null +++ b/spec/helpers/admin/users_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the Admin::UsersHelper. For example: +# +# describe Admin::UsersHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe Admin::UsersHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/requests/admin/users_spec.rb b/spec/requests/admin/users_spec.rb new file mode 100644 index 0000000..4e8fcfe --- /dev/null +++ b/spec/requests/admin/users_spec.rb @@ -0,0 +1,7 @@ +require 'rails_helper' + +RSpec.describe "Admin::Users", type: :request do + describe "GET /index" do + pending "add some examples (or delete) #{__FILE__}" + end +end From e99b5c0f5c32cb5ed6340156280861a2e079fbba Mon Sep 17 00:00:00 2001 From: Alex Smirnov Date: Sun, 26 Feb 2023 23:07:03 +0300 Subject: [PATCH 02/19] Add controller admin/users#index --- app/controllers/admin/users_controller.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index b5bd3ac..df8493c 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -1,2 +1,5 @@ class Admin::UsersController < ApplicationController + def index + @users = User.all + end end From c075ddb2efb73fc4687f045d3ac715c865520e0b Mon Sep 17 00:00:00 2001 From: Alex Smirnov Date: Sun, 26 Feb 2023 23:07:53 +0300 Subject: [PATCH 03/19] Add route for admin/users#index --- config/routes.rb | 1 + 1 file changed, 1 insertion(+) 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 From 073f2ed65b983751f55dc840d12dd286faa98204 Mon Sep 17 00:00:00 2001 From: Alex Smirnov Date: Mon, 27 Feb 2023 23:09:45 +0300 Subject: [PATCH 04/19] Add view for admin/users#index --- app/views/admin/users/index.html.slim | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 app/views/admin/users/index.html.slim diff --git a/app/views/admin/users/index.html.slim b/app/views/admin/users/index.html.slim new file mode 100644 index 0000000..595b47f --- /dev/null +++ b/app/views/admin/users/index.html.slim @@ -0,0 +1,21 @@ +h1.text-center.mb-2 Users list +hr + table.table + thead + tr + th id + th email + th first name + th last name + th user name + th role + tbody + - @users.each do |user| + tr + td = user.id + td = user.email + td = user.first_name + td = user.last_name + td = user.username + td = user.role + From 46bc14b44d2c97c8d05efa13e44b215df5c3fe72 Mon Sep 17 00:00:00 2001 From: Alex Smirnov Date: Thu, 2 Mar 2023 22:15:38 +0300 Subject: [PATCH 05/19] Delete files --- app/assets/stylesheets/admin/users.scss | 3 --- app/helpers/admin/users_helper.rb | 2 -- spec/helpers/admin/users_helper_spec.rb | 15 --------------- 3 files changed, 20 deletions(-) delete mode 100644 app/assets/stylesheets/admin/users.scss delete mode 100644 app/helpers/admin/users_helper.rb delete mode 100644 spec/helpers/admin/users_helper_spec.rb diff --git a/app/assets/stylesheets/admin/users.scss b/app/assets/stylesheets/admin/users.scss deleted file mode 100644 index 4b75194..0000000 --- a/app/assets/stylesheets/admin/users.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the admin/Users controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: https://sass-lang.com/ diff --git a/app/helpers/admin/users_helper.rb b/app/helpers/admin/users_helper.rb deleted file mode 100644 index 5995c2a..0000000 --- a/app/helpers/admin/users_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module Admin::UsersHelper -end diff --git a/spec/helpers/admin/users_helper_spec.rb b/spec/helpers/admin/users_helper_spec.rb deleted file mode 100644 index f26854e..0000000 --- a/spec/helpers/admin/users_helper_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'rails_helper' - -# Specs in this file have access to a helper object that includes -# the Admin::UsersHelper. For example: -# -# describe Admin::UsersHelper do -# describe "string concat" do -# it "concats two strings with spaces" do -# expect(helper.concat_strings("this","that")).to eq("this that") -# end -# end -# end -RSpec.describe Admin::UsersHelper, type: :helper do - pending "add some examples to (or delete) #{__FILE__}" -end From 7a9079b5000815747c05e061c1eb471c0f771f07 Mon Sep 17 00:00:00 2001 From: Alex Smirnov Date: Mon, 6 Mar 2023 14:19:33 +0300 Subject: [PATCH 06/19] Add pagination and order --- app/controllers/admin/users_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index df8493c..3d286d9 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -1,5 +1,5 @@ class Admin::UsersController < ApplicationController def index - @users = User.all + @users = User.all.order("id ASC").page params[:page] end end From 33e2952285dba5c615c0e517df7c6b6ad47bb2de Mon Sep 17 00:00:00 2001 From: Alex Smirnov Date: Mon, 6 Mar 2023 15:12:03 +0300 Subject: [PATCH 07/19] Update view users list --- app/javascript/stylesheet/_user.scss | 3 +++ app/javascript/stylesheet/application.scss | 1 + app/views/admin/users/_user.html.slim | 27 ++++++++++++++++++++++ app/views/admin/users/index.html.slim | 22 +----------------- config/locales/en.yml | 11 +++++++++ 5 files changed, 43 insertions(+), 21 deletions(-) create mode 100644 app/javascript/stylesheet/_user.scss create mode 100644 app/views/admin/users/_user.html.slim diff --git a/app/javascript/stylesheet/_user.scss b/app/javascript/stylesheet/_user.scss new file mode 100644 index 0000000..4187ded --- /dev/null +++ b/app/javascript/stylesheet/_user.scss @@ -0,0 +1,3 @@ +.red-color { + color:red; +} \ No newline at end of file diff --git a/app/javascript/stylesheet/application.scss b/app/javascript/stylesheet/application.scss index 9fedead..cc1d0ed 100644 --- a/app/javascript/stylesheet/application.scss +++ b/app/javascript/stylesheet/application.scss @@ -7,3 +7,4 @@ @import "./project.scss"; @import "./actiontext.scss"; @import "./favorite.scss"; +@import "./user.scss"; diff --git a/app/views/admin/users/_user.html.slim b/app/views/admin/users/_user.html.slim new file mode 100644 index 0000000..5f8fd40 --- /dev/null +++ b/app/views/admin/users/_user.html.slim @@ -0,0 +1,27 @@ +h1.text-center.mb-2 = t(".title") +hr + table.table + thead + tr + th = t(".order") + th = t(".id") + th = t(".full_name") + th = t(".username") + th = t(".email") + th = t(".role") + th = t(".status") + tbody + - @users.each_with_index do |user,index| + tr + td = index + 1 + td = user.id + td = "#{user.first_name} #{user.last_name}" + td = user.username + td = user.email + td = user.role + - if user.delete_at.present? + td.text-center + i.fa.fa-times.red-color + + .d-flex.justify-content-center + = paginate @users diff --git a/app/views/admin/users/index.html.slim b/app/views/admin/users/index.html.slim index 595b47f..893eb2d 100644 --- a/app/views/admin/users/index.html.slim +++ b/app/views/admin/users/index.html.slim @@ -1,21 +1 @@ -h1.text-center.mb-2 Users list -hr - table.table - thead - tr - th id - th email - th first name - th last name - th user name - th role - tbody - - @users.each do |user| - tr - td = user.id - td = user.email - td = user.first_name - td = user.last_name - td = user.username - td = user.role - += render "user" \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index a313596..006bf0c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -135,6 +135,17 @@ en: confirm: not_found: "Invitation is not found" + admin: + users: + user: + title: "Users list" + order: "Ordinal number" + id: "ID" + full_name: "Full name" + username: "Username" + email: "E-mail" + role: "Role" + status: "Enable" api: v1: From af1d9775354c92ea2e0ba617dc065a3a4428912e Mon Sep 17 00:00:00 2001 From: Alex Smirnov Date: Sun, 12 Mar 2023 14:22:48 +0300 Subject: [PATCH 08/19] Add rspec tests --- spec/rails_helper.rb | 1 + spec/requests/admin/users_spec.rb | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index c749b03..96798a7 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -28,4 +28,5 @@ config.before(:suite) do DatabaseCleaner.clean_with(:truncation) end + config.include Capybara::DSL, :type => :request end diff --git a/spec/requests/admin/users_spec.rb b/spec/requests/admin/users_spec.rb index 4e8fcfe..0a5d3f3 100644 --- a/spec/requests/admin/users_spec.rb +++ b/spec/requests/admin/users_spec.rb @@ -1,7 +1,26 @@ require 'rails_helper' RSpec.describe "Admin::Users", type: :request do - describe "GET /index" do - pending "add some examples (or delete) #{__FILE__}" + 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 From b589978a6d76d2436e83c59938e06dfc96150909 Mon Sep 17 00:00:00 2001 From: Alex Smirnov Date: Sun, 12 Mar 2023 21:04:30 +0300 Subject: [PATCH 09/19] Notes corrected --- app/controllers/admin/users_controller.rb | 2 +- app/javascript/stylesheet/_user.scss | 3 --- app/javascript/stylesheet/application.scss | 1 - app/views/admin/users/_user.html.slim | 20 ++------------------ app/views/admin/users/index.html.slim | 20 +++++++++++++++++++- config/locales/en.yml | 3 ++- spec/requests/admin/users_spec.rb | 1 - 7 files changed, 24 insertions(+), 26 deletions(-) delete mode 100644 app/javascript/stylesheet/_user.scss diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 3d286d9..80de761 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -1,5 +1,5 @@ class Admin::UsersController < ApplicationController def index - @users = User.all.order("id ASC").page params[:page] + @users = User.order(:id).page params[:page] end end diff --git a/app/javascript/stylesheet/_user.scss b/app/javascript/stylesheet/_user.scss deleted file mode 100644 index 4187ded..0000000 --- a/app/javascript/stylesheet/_user.scss +++ /dev/null @@ -1,3 +0,0 @@ -.red-color { - color:red; -} \ No newline at end of file diff --git a/app/javascript/stylesheet/application.scss b/app/javascript/stylesheet/application.scss index cc1d0ed..9fedead 100644 --- a/app/javascript/stylesheet/application.scss +++ b/app/javascript/stylesheet/application.scss @@ -7,4 +7,3 @@ @import "./project.scss"; @import "./actiontext.scss"; @import "./favorite.scss"; -@import "./user.scss"; diff --git a/app/views/admin/users/_user.html.slim b/app/views/admin/users/_user.html.slim index 5f8fd40..5fc203a 100644 --- a/app/views/admin/users/_user.html.slim +++ b/app/views/admin/users/_user.html.slim @@ -1,27 +1,11 @@ -h1.text-center.mb-2 = t(".title") -hr - table.table - thead - tr - th = t(".order") - th = t(".id") - th = t(".full_name") - th = t(".username") - th = t(".email") - th = t(".role") - th = t(".status") - tbody - @users.each_with_index do |user,index| tr td = index + 1 td = user.id - td = "#{user.first_name} #{user.last_name}" + 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.red-color - - .d-flex.justify-content-center - = paginate @users + i.fa.fa-times.text-danger \ No newline at end of file diff --git a/app/views/admin/users/index.html.slim b/app/views/admin/users/index.html.slim index 893eb2d..43b4151 100644 --- a/app/views/admin/users/index.html.slim +++ b/app/views/admin/users/index.html.slim @@ -1 +1,19 @@ -= render "user" \ No newline at end of file += title t(".title") + +h3.text-center.mb-4 =t(".title") +hr + table.table + thead + tr + th = t(".order") + th = t(".id") + th = t(".full_name") + th = t(".username") + th = t(".email") + th = t(".role") + th = t(".status") + tbody + = render "user" + + .d-flex.justify-content-center + = paginate @users \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 006bf0c..f93a582 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -137,8 +137,9 @@ en: admin: users: - user: + index: title: "Users list" + user: order: "Ordinal number" id: "ID" full_name: "Full name" diff --git a/spec/requests/admin/users_spec.rb b/spec/requests/admin/users_spec.rb index 0a5d3f3..dc23aa4 100644 --- a/spec/requests/admin/users_spec.rb +++ b/spec/requests/admin/users_spec.rb @@ -6,7 +6,6 @@ end describe "GET /admin/users" do - it "http status success" do get admin_users_path expect(response).to have_http_status(:success) From a28f809ec9fc01fabb692fb2e5fda8eae859aac7 Mon Sep 17 00:00:00 2001 From: Alex Smirnov Date: Sun, 12 Mar 2023 22:24:15 +0300 Subject: [PATCH 10/19] Fix empty string --- app/views/admin/users/_user.html.slim | 2 +- app/views/admin/users/index.html.slim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/admin/users/_user.html.slim b/app/views/admin/users/_user.html.slim index 5fc203a..107b80b 100644 --- a/app/views/admin/users/_user.html.slim +++ b/app/views/admin/users/_user.html.slim @@ -8,4 +8,4 @@ td = user.role - if user.delete_at.present? td.text-center - i.fa.fa-times.text-danger \ No newline at end of file + i.fa.fa-times.text-danger diff --git a/app/views/admin/users/index.html.slim b/app/views/admin/users/index.html.slim index 43b4151..f9daaad 100644 --- a/app/views/admin/users/index.html.slim +++ b/app/views/admin/users/index.html.slim @@ -16,4 +16,4 @@ hr = render "user" .d-flex.justify-content-center - = paginate @users \ No newline at end of file + = paginate @users From 43ea006f1f0f50e464cfd45ebba6946dac7baab3 Mon Sep 17 00:00:00 2001 From: Alex Smirnov Date: Mon, 13 Mar 2023 09:56:51 +0300 Subject: [PATCH 11/19] Fix render for user --- app/views/admin/users/_user.html.slim | 1 - app/views/admin/users/index.html.slim | 33 ++++++++++++++------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/app/views/admin/users/_user.html.slim b/app/views/admin/users/_user.html.slim index 107b80b..2c17ea8 100644 --- a/app/views/admin/users/_user.html.slim +++ b/app/views/admin/users/_user.html.slim @@ -1,4 +1,3 @@ - - @users.each_with_index do |user,index| tr td = index + 1 td = user.id diff --git a/app/views/admin/users/index.html.slim b/app/views/admin/users/index.html.slim index f9daaad..2225949 100644 --- a/app/views/admin/users/index.html.slim +++ b/app/views/admin/users/index.html.slim @@ -1,19 +1,20 @@ -= title t(".title") +/ = title t(".title") h3.text-center.mb-4 =t(".title") -hr - table.table - thead - tr - th = t(".order") - th = t(".id") - th = t(".full_name") - th = t(".username") - th = t(".email") - th = t(".role") - th = t(".status") - tbody - = render "user" +/ hr +table.table + thead + tr + th = t(".order") + th = t(".id") + th = t(".full_name") + th = t(".username") + th = t(".email") + th = 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 +.d-flex.justify-content-center + = paginate @users From d4c015b6ba347298d7145800ccc0c4b65e94125b Mon Sep 17 00:00:00 2001 From: Alex Smirnov Date: Mon, 13 Mar 2023 11:02:53 +0300 Subject: [PATCH 12/19] Fix views --- app/views/admin/users/_user.html.slim | 20 ++++++++++---------- app/views/admin/users/index.html.slim | 2 -- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/app/views/admin/users/_user.html.slim b/app/views/admin/users/_user.html.slim index 2c17ea8..118bfa9 100644 --- a/app/views/admin/users/_user.html.slim +++ b/app/views/admin/users/_user.html.slim @@ -1,10 +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 +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 index 2225949..fbe1f66 100644 --- a/app/views/admin/users/index.html.slim +++ b/app/views/admin/users/index.html.slim @@ -4,7 +4,6 @@ h3.text-center.mb-4 =t(".title") / hr table.table thead - tr th = t(".order") th = t(".id") th = t(".full_name") @@ -12,7 +11,6 @@ table.table th = t(".email") th = t(".role") th = t(".status") - tbody - @users.each_with_index do |user,index| = render partial: "user", locals: { user: user, index: index } From 42c55239d90dbb00128159a6b16cff7c3cb2b2e5 Mon Sep 17 00:00:00 2001 From: Alex Smirnov Date: Mon, 13 Mar 2023 13:36:33 +0300 Subject: [PATCH 13/19] Fix tbody --- app/views/admin/users/index.html.slim | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/views/admin/users/index.html.slim b/app/views/admin/users/index.html.slim index fbe1f66..1748754 100644 --- a/app/views/admin/users/index.html.slim +++ b/app/views/admin/users/index.html.slim @@ -1,7 +1,4 @@ -/ = title t(".title") - h3.text-center.mb-4 =t(".title") -/ hr table.table thead th = t(".order") @@ -11,8 +8,9 @@ table.table th = t(".email") th = t(".role") th = t(".status") - - @users.each_with_index do |user,index| - = render partial: "user", locals: { user: user, index: index } + tbody + - @users.each_with_index do |user,index| + = render partial: "user", locals: { user: user, index: index } .d-flex.justify-content-center = paginate @users From 3392720b7e80361fefed4b282f5d30b13b6cc556 Mon Sep 17 00:00:00 2001 From: Alex Smirnov Date: Sun, 4 Jun 2023 13:39:20 +0300 Subject: [PATCH 14/19] capybara config in a separate file --- spec/rails_helper.rb | 1 - spec/support/capybara.rb | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 spec/support/capybara.rb diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 96798a7..c749b03 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -28,5 +28,4 @@ config.before(:suite) do DatabaseCleaner.clean_with(:truncation) end - config.include Capybara::DSL, :type => :request 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 From 6e6c6951123249dc81551b1213e0a7301d907416 Mon Sep 17 00:00:00 2001 From: Alex Smirnov Date: Sun, 4 Jun 2023 13:54:07 +0300 Subject: [PATCH 15/19] Fix quotes --- spec/requests/admin/users_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/requests/admin/users_spec.rb b/spec/requests/admin/users_spec.rb index dc23aa4..0d8c58a 100644 --- a/spec/requests/admin/users_spec.rb +++ b/spec/requests/admin/users_spec.rb @@ -13,13 +13,13 @@ it "displays 25 users on the first page" do visit admin_users_path - expect(page).to have_selector('tbody tr', count: 25) + 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) + click_link "2" + expect(page).to have_selector("tbody tr", count: 1) end end end From f8ef4f7bac3bd40b82541965fb893bd2f4287326 Mon Sep 17 00:00:00 2001 From: Alex Smirnov Date: Sun, 4 Jun 2023 14:17:30 +0300 Subject: [PATCH 16/19] require capybara --- spec/rails_helper.rb | 1 + 1 file changed, 1 insertion(+) 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! From 00d19772587d8518ef989840168bb994dbdbbf83 Mon Sep 17 00:00:00 2001 From: Alex Smirnov Date: Sun, 4 Jun 2023 20:38:34 +0300 Subject: [PATCH 17/19] Add filter for first and last name --- app/controllers/admin/users_controller.rb | 3 ++- app/views/admin/users/_search_form.html.slim | 8 ++++++++ app/views/admin/users/index.html.slim | 5 +++++ config/locales/en.yml | 3 +++ 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 app/views/admin/users/_search_form.html.slim diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 80de761..ece5b38 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -1,5 +1,6 @@ class Admin::UsersController < ApplicationController def index - @users = User.order(:id).page params[:page] + @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/index.html.slim b/app/views/admin/users/index.html.slim index 1748754..ee7dc08 100644 --- a/app/views/admin/users/index.html.slim +++ b/app/views/admin/users/index.html.slim @@ -1,4 +1,9 @@ h3.text-center.mb-4 =t(".title") + +hr += render partial: "search_form" +hr + table.table thead th = t(".order") diff --git a/config/locales/en.yml b/config/locales/en.yml index f93a582..bd907ca 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, role, status" + search_title: "Search" favorites: index: title: "Favorites" From 2bbb796b9850c5029461b356e684908a9e29b726 Mon Sep 17 00:00:00 2001 From: Alex Smirnov Date: Thu, 15 Jun 2023 10:19:31 +0300 Subject: [PATCH 18/19] Update locale for search --- config/locales/en.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index bd907ca..614af1b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -98,7 +98,7 @@ en: your_project: "Your projects" common_projects: "Common projects" index: - search_field: "Full name, role, status" + search_field: "Full name" search_title: "Search" favorites: index: From a769e83532dfafd7098d393a284e4c43d31a689d Mon Sep 17 00:00:00 2001 From: Alex Smirnov Date: Thu, 15 Jun 2023 16:24:08 +0300 Subject: [PATCH 19/19] Add order for role --- app/views/admin/users/index.html.slim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/users/index.html.slim b/app/views/admin/users/index.html.slim index ee7dc08..021263c 100644 --- a/app/views/admin/users/index.html.slim +++ b/app/views/admin/users/index.html.slim @@ -11,7 +11,7 @@ table.table th = t(".full_name") th = t(".username") th = t(".email") - th = t(".role") + th = sort_link(@search, :role, t(".role")) th = t(".status") tbody - @users.each_with_index do |user,index|