Skip to content
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

Add styling and additional logic to search for users #152

Merged
merged 43 commits into from
Feb 6, 2021
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
6653bbf
Add workaround for flash message issue
Alexander-Dubrawski Jan 22, 2021
0f0c436
First draft search engine
Alexander-Dubrawski Jan 22, 2021
c10eb20
Adjust code
Alexander-Dubrawski Jan 22, 2021
64ce24c
Use wildcards in pulic search
Alexander-Dubrawski Jan 22, 2021
9b8fed8
Refactor code
Alexander-Dubrawski Jan 22, 2021
6fec237
Add search button
Alexander-Dubrawski Jan 22, 2021
1b90e15
Simplify code
Alexander-Dubrawski Jan 23, 2021
efbf245
First draft search bar styling
Alexander-Dubrawski Jan 23, 2021
5611fa2
Adjust search bar styling
Alexander-Dubrawski Jan 23, 2021
b1d12aa
Seperate style from element
Alexander-Dubrawski Jan 23, 2021
25bbcb0
First draft diplay users
Alexander-Dubrawski Jan 23, 2021
83c92f3
Do some fancy css stuff
Alexander-Dubrawski Jan 23, 2021
2777973
Improve styling
Alexander-Dubrawski Jan 23, 2021
fae5832
Add add user button
Alexander-Dubrawski Jan 23, 2021
66cbb7a
Remove user from set
Alexander-Dubrawski Jan 23, 2021
751c8ad
Resolve merge conflicts
Alexander-Dubrawski Jan 29, 2021
35a7307
Fix navbar bug
Alexander-Dubrawski Jan 29, 2021
6c35394
Formatting, formatting and formatting
Alexander-Dubrawski Jan 29, 2021
ca5f1f3
Format code
Alexander-Dubrawski Jan 29, 2021
56ab0d6
Adjust styling
Alexander-Dubrawski Jan 29, 2021
f303c94
Move styles to external file
Alexander-Dubrawski Jan 29, 2021
7d822c7
Format code
Alexander-Dubrawski Jan 29, 2021
15e7b4e
Add translation
Alexander-Dubrawski Jan 29, 2021
504808d
Fix lint issues
Alexander-Dubrawski Jan 29, 2021
4d55b85
Merge branch 'dev' into Add_styling_search_for_users
Alexander-Dubrawski Jan 29, 2021
f9b8c34
Ajust some tests
Alexander-Dubrawski Jan 29, 2021
a9bb65c
Fix tests
Alexander-Dubrawski Jan 29, 2021
173aaab
Adjust tests
Alexander-Dubrawski Jan 29, 2021
7e3eca8
Now, please?
Alexander-Dubrawski Jan 29, 2021
2190319
Resolver merge conflicts
Alexander-Dubrawski Feb 3, 2021
5219ae2
Use search logic built by Scrumbledore's Army
Alexander-Dubrawski Feb 3, 2021
993f730
Remove DS Store
Alexander-Dubrawski Feb 3, 2021
d4e8f75
Refactore code
Alexander-Dubrawski Feb 3, 2021
fe36cde
Resolve merge conflicts
Alexander-Dubrawski Feb 5, 2021
6c6e1b7
Use partials
Alexander-Dubrawski Feb 5, 2021
d11b483
Fix bug
Alexander-Dubrawski Feb 5, 2021
07f9728
Small improvments
Alexander-Dubrawski Feb 5, 2021
9386cbc
Some more code improvments
Alexander-Dubrawski Feb 5, 2021
a89e593
Small code adjustments
Alexander-Dubrawski Feb 5, 2021
ab57760
Remove footer adjustment
Alexander-Dubrawski Feb 5, 2021
c7b64a9
Adjust code
Alexander-Dubrawski Feb 5, 2021
b0d010c
Yes, yes, yes, ...
Alexander-Dubrawski Feb 5, 2021
a648760
Fix twice display of user
Alexander-Dubrawski Feb 6, 2021
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
20 changes: 20 additions & 0 deletions app/assets/stylesheets/users.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
// Place all the styles related to the Users controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/

felixauringer marked this conversation as resolved.
Show resolved Hide resolved
.form-tag {
display: flex;
width: 100%;
}
.text-field {
flex: 5;
margin: 3px;
}
.submit-button {
flex: 1;
margin: 3px;
}
.stack {
display: flex;
flex-direction: column;
}
.stack > * + * {
margin-top: .5rem;
}
9 changes: 8 additions & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
class UsersController < ApplicationController
include SocialAccountsHelper
before_action :authorize
before_action except: %i[show index search]
Alexander-Dubrawski marked this conversation as resolved.
Show resolved Hide resolved
helper_method :generate_link, :supported_social_networks

def show; end
def show
Alexander-Dubrawski marked this conversation as resolved.
Show resolved Hide resolved
@user = User.find(params[:id])
end

def edit
return unless authorize_to_update!
Expand Down Expand Up @@ -37,6 +40,10 @@ def update_status
end

def index
unless current_user
redirect_to(new_user_session_path)
Alexander-Dubrawski marked this conversation as resolved.
Show resolved Hide resolved
return
end
@users = User.all
@users_to_add = (@users - [current_user]).reject do |user|
current_user.sent_contact_request?(user)
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/_flash_messages.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
<h4><%= log %></h4>
<% end %>
</div>
<% end %>
<% end %>
Alexander-Dubrawski marked this conversation as resolved.
Show resolved Hide resolved
65 changes: 48 additions & 17 deletions app/views/layouts/_footer.html.erb
Original file line number Diff line number Diff line change
@@ -1,29 +1,60 @@
<style>
Alexander-Dubrawski marked this conversation as resolved.
Show resolved Hide resolved
.footer-nav-link::after {
content: '';
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
}
.nav-bar-entry {
position: relative;
}
</style>

<% if user_signed_in? %>
<div id="navigation">
<ul class="nav nav-pills nav-justified">
<li class="nav-item">
<a class="nav-link <%= active_link_to_class(root_path, active: :exclusive)%>" href="<%= root_url %>">
<i class="fa fa-home"></i>
</a></li>
<label class="nav-bar-entry">
<!-- new path to this when dashboard is rewritten -->
Alexander-Dubrawski marked this conversation as resolved.
Show resolved Hide resolved
<a class="nav-link footer-nav-link <%= active_link_to_class(root_path, active: :exclusive)%>" href="<%= root_url %>">
<i class="fa fa-home"></i>
</a>
</label>
</li>
<li class="nav-item">
<a class="nav-link <%= active_link_to_class(chat_path, active: :exclusive)%>" href="<%= chat_path %>">
<i class="fa fa-comments"></i>
</a></li>
<!-- please update the path when reworked the chat -->
Alexander-Dubrawski marked this conversation as resolved.
Show resolved Hide resolved
<label class="nav-bar-entry">
<a class="nav-link footer-nav-link <%= active_link_to_class(root_path, active: :exclusive)%>" href="<%= chat_path %>">
Alexander-Dubrawski marked this conversation as resolved.
Show resolved Hide resolved
<i class="fa fa-comments"></i>
</a>
</label>
</li>
<li class="nav-item">
<a class="nav-link <%= active_link_to_class(user_contacts_path(current_user), active: :exclusive)%>"
href="<%= user_contacts_path(current_user) %>">
<i class="fa fa-address-book"></i>
</a></li>
<label class="nav-bar-entry">
<a class="nav-link footer-nav-link <%= active_link_to_class(user_contacts_path(current_user), active: :exclusive)%>"
href="<%= user_contacts_path(current_user) %>">
<i class="fa fa-address-book"></i>
</a>
</label>
</li>
<li class="nav-item">
<!-- please add the right path here when history view created -->
<a class="nav-link" href="">
<i class="fa fa-history"></i>
</a></li>
<label class="nav-bar-entry">
<a class="nav-link footer-nav-link" href="">
<i class="fa fa-history"></i>
</a>
</label>
</li>
<li class="nav-item">
<a class="nav-link <%= active_link_to_class(edit_user_path(current_user), active: :exclusive)%>"
href="<%= edit_user_path(current_user) %>">
<i class="fa fa-cog"></i>
</a></li>
<label class="nav-bar-entry">
<a class="nav-link footer-nav-link <%= active_link_to_class(edit_user_path(current_user), active: :exclusive)%>"
href="<%= edit_user_path(current_user) %>">
<i class="fa fa-cog"></i>
</a>
</label>
Alexander-Dubrawski marked this conversation as resolved.
Show resolved Hide resolved
</li>
</ul>
</div>
<% end %>
Alexander-Dubrawski marked this conversation as resolved.
Show resolved Hide resolved
50 changes: 13 additions & 37 deletions app/views/users/search.html.erb
Original file line number Diff line number Diff line change
@@ -1,42 +1,18 @@
<div class="jumbotron">
<h2><%= I18n.t('user.lists') %></h2>
<%= stylesheet_link_tag 'users', media: 'all', 'data-turbolinks-track': 'reload' %>

<%# https://getbootstrap.com/docs/5.0/layout/grid/#auto-layout-columns %>
<div class="stack">
<%= form_tag(search_users_path, method: "get", class: "form-tag justify-content-between") do %>
<%= text_field_tag :search, params[:search] , placeholder: I18n.t('user.search.place_holder'), class: "text-field form-control my-2 my-sm-0"%>
<%= submit_tag I18n.t('user.search.index') , class: "submit-button btn btn-outline-secondary my-2 my-sm-0"%>
<% end %>

<% @users.each do |user| %>
<%= render partial: 'users/card', locals: { user: user, mode: :overview } %>
<% end %>

<div class="row">
<div class="col">
<%= form_tag(search_users_path, method: "get") do %>
<%= label_tag(:search, I18n.t('user.search.for') ) %>
<%= text_field_tag :search, params[:search] %>
<%= submit_tag I18n.t('user.search.index') %>
<% end %>
</div>
</div>
<% @users_to_add.each do |user| %>
<%= render partial: 'users/card', locals: { user: user, mode: :add } %>
<% end %>

<table>
<thead>
<tr>
<th><%= I18n.t('user.attributes.username') %></th>
<th><%= I18n.t('user.attributes.firstname')%></th>
<th><%= I18n.t('user.attributes.lastname')%></th>
<th><%= I18n.t('user.attributes.email')%></th>
</tr>
</thead>
<tbody>

<% @users.each do |user| %>
<tr>
<td><%= user.username%></td>
<td><%= user.firstname%></td>
<td><%= user.lastname%></td>
<td><%= user.email %></td>
<% if @users_to_add.include? user %>
<td><%= button_to '+', user_contact_requests_path(user), method: :post, id: user.id %></td>
<% end %>
</tr>
<% end %>

</tbody>
</table>
</div>

1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ en:
search:
index: 'Search'
for: 'Search for:'
place_holder: 'Username, email, ...'
Alexander-Dubrawski marked this conversation as resolved.
Show resolved Hide resolved
contact_request:
approved: 'Contact request approved'
denied: 'Contact request denied'
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
devise_for :users
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
root to: 'home#dashboard'
get 'search', to: 'users#search'
Alexander-Dubrawski marked this conversation as resolved.
Show resolved Hide resolved

resources :users, only: %i[show edit update index] do
patch 'status', to: 'users#update_status', as: 'update_status', on: :member
Expand Down
7 changes: 7 additions & 0 deletions spec/features/user_search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@

describe 'without filter' do
let!(:users) { FactoryBot.create_list(:user, 3) }
let(:second_user) { FactoryBot.create :user }
Alexander-Dubrawski marked this conversation as resolved.
Show resolved Hide resolved

before { visit search_users_path }

it 'is possible to filter by username' do
Alexander-Dubrawski marked this conversation as resolved.
Show resolved Hide resolved
visit search_users_path(search: second_user.username[0..2])
# It is possible to search for the user via its user name but the user name it self is not displayed.
expect(page).to have_text(second_user.firstname)
end

it 'shows all other users when no filter is given' do
users.each { |user| expect(page).to have_text(user.email) }
end
Expand Down
14 changes: 11 additions & 3 deletions spec/views/users/search.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@

RSpec.describe 'users/search', type: :view do
let(:users) { FactoryBot.create_list(:user, 3) }
let(:contacts) { FactoryBot.create_list(:user, 3) }
let(:user1) { FactoryBot.create :user }
Alexander-Dubrawski marked this conversation as resolved.
Show resolved Hide resolved

before do
assign(:users, users)
assign(:users, contacts)
Alexander-Dubrawski marked this conversation as resolved.
Show resolved Hide resolved
assign(:users_to_add, users)
sign_in users.first
sign_in user1
Alexander-Dubrawski marked this conversation as resolved.
Show resolved Hide resolved
render
end

it 'renders a list of users before searching' do
it 'renders a list of contacts' do
Alexander-Dubrawski marked this conversation as resolved.
Show resolved Hide resolved
contacts.each do |contact|
expect(rendered).to match contact.email
end
end

it 'renders a list of users' do
users.each do |user|
expect(rendered).to match user.email
end
Expand Down