-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements initial implementation of users admin CRUD (#46)
* [#7] Adds route to admin users, and link to admin user index to the layout. * [#7] removes password_digest column from users table. * [#7] Adds Admin users index and show pages. * [#7] Removes to_csv method from User model. * [#6] Fixes a crash on facility card component * [#6] Removes unneeded columns from facilities. (r_pets, r_id, r_cart, r_phone, r_wifi, and *_note columns). * [#7] Adds Vancouver and New Westminster zones to seeds. * [#7] Implements fake_data:users and fake_data:facilities rake tasks to help populate development database. * [#7] Implements ability to create, update and delete users. * [#6] Fixes a crash on Facility validation when any of the clean_data columns has a nil value. * [#7] Improves view components for Status of Users and Facilities. * [#7] Refactors User form to shared partials. * [#7] Implements ability to Reset Password of users. * [#7] Implements website_url method on Facility model to handle website column content. * [#7] Fixes a potential mass-assignment vulnerability as pointed by brakeman.
- Loading branch information
Showing
37 changed files
with
803 additions
and
74 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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,15 @@ | ||
# frozen_string_literal: true | ||
|
||
class Users::ShowComponent < ViewComponent::Base | ||
attr_reader :user | ||
|
||
def initialize(user:) | ||
super() | ||
|
||
@user = user | ||
end | ||
|
||
def card_id | ||
dom_id(user) | ||
end | ||
end |
59 changes: 59 additions & 0 deletions
59
app/components/users/show_component/show_component.html.erb
This file contains 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,59 @@ | ||
<div class='columns'> | ||
<div class='column'> | ||
<%= render Shared::CardComponent.new(title: 'User Details') do |card| %> | ||
<% card.button(title: 'Reset Password', path: new_admin_user_password_path(user)) %> | ||
<% card.button(title: 'Edit', path: edit_admin_user_path(user)) %> | ||
<% card.button(title: 'Delete', path: admin_user_path(user.id), method: :delete, icon_class: 'fa-trash-alt') %> | ||
|
||
<table class='table'> | ||
<tr> | ||
<th>Name:</th> | ||
<td><%= user.name %></td> | ||
</tr> | ||
|
||
<tr> | ||
<th>Email:</th> | ||
<td><%= user.email %></td> | ||
</tr> | ||
|
||
<tr> | ||
<th>Organization:</th> | ||
<td><%= user.organization %></td> | ||
</tr> | ||
|
||
<tr> | ||
<th>Phone Number:</th> | ||
<td><%= user.phone_number %></td> | ||
</tr> | ||
</table> | ||
<% end %> | ||
</div> | ||
|
||
<div class='column'> | ||
<!-- Descriptions --> | ||
<%= render Shared::CardComponent.new(title: 'Info') do |card| %> | ||
<table class='table'> | ||
<tr> | ||
<th>Status</th> | ||
<td> | ||
<%= render Users::StatusComponent.new(user, show_title: true) %> | ||
</td> | ||
</tr> | ||
|
||
<tr> | ||
<th>Admin:</th> | ||
<td><%= user.admin.to_s.titleize %></td> | ||
</tr> | ||
|
||
<tr> | ||
<th>Last Updated</th> | ||
<td> | ||
<time datetime="<%= user.updated_at %>"> | ||
<%= user.updated_at %> | ||
</time> | ||
</td> | ||
</tr> | ||
</table> | ||
<% end %> | ||
</div> | ||
</div> |
This file contains 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,67 @@ | ||
# frozen_string_literal: true | ||
|
||
class Users::StatusComponent < Shared::StatusComponent | ||
STATUS_CLASSES = { | ||
verified: "fa-user-check", | ||
not_verified: "fa-user-times" | ||
}.freeze | ||
|
||
COLOR_CLASSES = { | ||
verified: "has-text-info-dark", | ||
not_verified: "has-text-danger-dark" | ||
}.freeze | ||
|
||
SIZE_CLASSES = { | ||
large: "fa-lg" | ||
}.freeze | ||
|
||
attr_reader :user | ||
|
||
def initialize(user, show_title: false, size: :large) | ||
super(nil, show_title: show_title, size: size) | ||
|
||
@user = user | ||
# # Overrides status from superclass | ||
@status = user.verified? ? :verified : :not_verified | ||
end | ||
|
||
# def call | ||
# @show_title.present? ? call_title : call_icon | ||
# end | ||
# | ||
# def call_icon | ||
# tag.span class: "icon" do | ||
# tag.i class: "fas #{size_classes} #{status_classes}" | ||
# end | ||
# end | ||
# | ||
# def call_title | ||
# tag.span class: "icon-text has-text" do | ||
# call_icon + tag.span(title) | ||
# end | ||
# end | ||
|
||
private | ||
|
||
# def size_classes | ||
# SIZE_CLASSES[@size] | ||
# end | ||
|
||
# Overrides superclass | ||
def title | ||
@status.to_s.titleize | ||
# @status ? "Yes" : "No" | ||
end | ||
|
||
def status_classes | ||
STATUS_CLASSES[status] | ||
end | ||
|
||
def color_classes | ||
COLOR_CLASSES[status] | ||
end | ||
|
||
def status | ||
user.verified? ? :verified : :not_verified | ||
end | ||
end |
This file contains 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,34 @@ | ||
class Users::TableComponent < ViewComponent::Base | ||
attr_reader :users | ||
|
||
def initialize(users:) | ||
super() | ||
|
||
@users = users | ||
end | ||
|
||
class UserRowComponent < ViewComponent::Base | ||
attr_reader :user, :table_component | ||
|
||
def initialize(user, table_component:) | ||
super() | ||
|
||
@user = user | ||
@table_component = table_component | ||
end | ||
|
||
def more_menu_component | ||
@more_menu_component ||= MoreMenuComponent.new(user: user) | ||
end | ||
end | ||
|
||
class MoreMenuComponent < ViewComponent::Base | ||
attr_reader :user | ||
|
||
def initialize(user: nil) | ||
super() | ||
|
||
@user = user | ||
end | ||
end | ||
end |
19 changes: 19 additions & 0 deletions
19
app/components/users/table_component/more_menu_component.html.erb
This file contains 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,19 @@ | ||
<div class="dropdown is-hoverable is-right"> | ||
<div class="dropdown-trigger"> | ||
<button class="button no-border transparent" aria-haspopup="true" aria-controls="dropdown-menu4"> | ||
<span class="icon is-small"> | ||
<i class="fas fa-ellipsis-v"></i> | ||
</span> | ||
</button> | ||
</div> | ||
<div class="dropdown-menu" role="menu"> | ||
<div class="dropdown-content position-relative stretched-link"> | ||
<div class="dropdown-item"> | ||
<span class="icon is-small"> | ||
<i class="fas fa-info-circle"></i> | ||
</span> | ||
<%#= distribution.show_link %> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
Oops, something went wrong.