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 all 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/

.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;
}
7 changes: 5 additions & 2 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ def index
end

def search
@users = User.search(params[:search]).where.not(id: current_user.id)
@users_to_add = @users.reject do |user|
other_users = User.search(params[:search]).where.not(id: current_user.id)
@users_to_add = other_users.reject do |user|
current_user.sent_contact_request?(user)
end
@users = other_users.select do |user|
current_user.sent_contact_request?(user)
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/_footer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
</a></li>
</ul>
</div>
<% end %>
<% end %>
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.placeholder'), 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:'
placeholder: 'Username, email, ...'
contact_request:
approved: 'Contact request approved'
denied: 'Contact request denied'
Expand Down