-
Notifications
You must be signed in to change notification settings - Fork 10
Add filter form to user panel #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
Open
sas2job
wants to merge
19
commits into
develop
Choose a base branch
from
add-filter-form-to-user-panel
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
8e3d819
Add controller for admin/users
sas2job e99b5c0
Add controller admin/users#index
sas2job c075ddb
Add route for admin/users#index
sas2job 073f2ed
Add view for admin/users#index
sas2job 46bc14b
Delete files
sas2job 7a9079b
Add pagination and order
sas2job 33e2952
Update view users list
sas2job af1d977
Add rspec tests
sas2job b589978
Notes corrected
sas2job a28f809
Fix empty string
sas2job 43ea006
Fix render for user
sas2job d4c015b
Fix views
sas2job 42c5523
Fix tbody
sas2job 3392720
capybara config in a separate file
sas2job 6e6c695
Fix quotes
sas2job f8ef4f7
require capybara
sas2job 00d1977
Add filter for first and last name
sas2job 2bbb796
Update locale for search
sas2job a769e83
Add order for role
sas2job File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| RSpec.configure do |config| | ||
| config.include Capybara::DSL, type: :request | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@XaoGao Когда добавляю роль и ищу по ней получаю ошибку:
Пишут что user - зарезервированное слово, вы не можете назвать им таблицу или поле.
Получается рядового usera надо как то иначе называть?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@XaoGao Интересный момент. По условиям задачи поиск в фильтре должен учитывать роль. Роль же под капотом имеет тип данных Integer, который регулируется
enum role: [:user, :moderator, :admin], то есть при ввводе в поле поиска admin должно отдаваться 2?