Skip to content

Commit

Permalink
Use new resource_table component for user list
Browse files Browse the repository at this point in the history
If the new component is available we use that for
rendering the user list in the admin.
  • Loading branch information
tvdeyen committed Sep 5, 2024
1 parent 5bc53b4 commit 29bc721
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 29 deletions.
1 change: 1 addition & 0 deletions app/models/alchemy/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def ransackable_attributes(_auth_object = nil)
firstname
lastname
login
last_sign_in_at
]
end

Expand Down
34 changes: 34 additions & 0 deletions app/views/alchemy/admin/users/_table.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<%= render Alchemy::Admin::Resource::Table.new(@users, query: @query) do |table| %>

Check notice

Code scanning / Brakeman

Render path contains parameter value. Note

Render path contains parameter value.
<% table.icon_column do |user| %>
<%= render_icon(:user, style: user.logged_in? ? "solid" : "regular") %>
<% end %>
<% table.column :login, sortable: true do |user| %>
<% if can?(:edit, user) %>
<%= link_to_dialog user.login,
alchemy.edit_admin_user_path(user), {
title: Alchemy.t(:edit_user),
overflow: true,
size: "430x560"
},
title: Alchemy.t(:edit_user) %>
<% else %>
<%= user.login %>
<% end %>
<% end %>
<% table.column :firstname, class_name: "name", sortable: true %>
<% table.column :lastname, sortable: true %>
<% table.column :email, sortable: true %>
<% table.column :language do |user| %>
<%= Alchemy.t(user.language, scope: :translations, default: Alchemy.t(:unknown)) %>
<% end %>
<% table.column :last_sign_in_at, sortable: true do |user| %>
<%= user.last_sign_in_at.present? ? l(user.last_sign_in_at, format: :"alchemy.default") : Alchemy.t(:unknown) %>
<% end %>
<% table.column :role, header: Alchemy::User.human_attribute_name(:alchemy_roles) do |user| %>
<%= user.human_roles_string %>
<% end %>
<% table.delete_button tooltip: Alchemy.t(:delete_user), confirm_message: Alchemy.t(:confirm_to_delete_user) %>
<% table.edit_button tooltip: Alchemy.t(:edit_user), dialog_size: "430x560" %>
<% end %>

<%= paginate @users, theme: "alchemy" %>
35 changes: 6 additions & 29 deletions app/views/alchemy/admin/users/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,14 @@
<% end %>

<div id="archive_all" class="resources-table-wrapper">
<%= render "alchemy/admin/resources/table_header" %>
<% if @users.any? %>
<%= render "alchemy/admin/resources/table_header" %>

<table class="list" id="user_list">
<thead>
<tr>
<th class="icon"></th>
<th class="login">
<%= sort_link @query, :login, hide_indicator: true %>
</th>
<th class="name">
<%= sort_link @query, :firstname, hide_indicator: true %>
</th>
<th>
<%= sort_link @query, :lastname, hide_indicator: true %>
</th>
<th class="email">
<%= sort_link @query, :email, hide_indicator: true %>
</th>
<th><%= Alchemy::User.human_attribute_name('language') %></th>
<th>
<%= sort_link @query, :last_sign_in_at, hide_indicator: true %>
</th>
<th class="role"><%= Alchemy::User.human_attribute_name('roles') %></th>
<th class="tools"></th>
</tr>
</thead>
<tbody>
<%= render partial: 'alchemy/admin/users/user', collection: @users %>
</tbody>
</table>
<% if Alchemy::Admin.const_defined?(:Resource) %>
<%= render "resource_table" %>
<% else %>
<%= render "table" %>
<% end %>

<%= paginate @users, theme: 'alchemy' %>

Expand Down

0 comments on commit 29bc721

Please sign in to comment.