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

Use new resource_table component for user list #213

Merged
merged 6 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions .github/workflows/brakeman-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

# Customize the ruby version depending on your needs
- name: Set up Ruby
Expand All @@ -29,7 +29,7 @@ jobs:

- name: Setup Brakeman
env:
BRAKEMAN_VERSION: "6.1" # SARIF support is provided in Brakeman version 4.10+
BRAKEMAN_VERSION: "6.2.1" # SARIF support is provided in Brakeman version 4.10+
run: |
gem install brakeman --version $BRAKEMAN_VERSION

Expand All @@ -41,6 +41,6 @@ jobs:

# Upload the SARIF file generated in the previous step
- name: Upload SARIF
uses: github/codeql-action/upload-sarif@v2
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: output.sarif.json
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ jobs:
alchemy_branch:
- "7.0-stable"
- "7.1-stable"
- "7.2-stable"
ruby:
- "3.0"
- "3.1"
- "3.2"
- "3.3"
Expand Down Expand Up @@ -49,7 +49,7 @@ jobs:
MYSQL_ROOT_PASSWORD: password
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
Expand Down Expand Up @@ -95,11 +95,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install Ruby and gems
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.0"
ruby-version: "3.1"
bundler-cache: true
- name: Lint Ruby files
run: bundle exec standardrb
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require: standard

AllCops:
TargetRubyVersion: 3.0
TargetRubyVersion: 3.1

inherit_gem:
standard: config/base.yml
1 change: 1 addition & 0 deletions .standard.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
parallel: true
ruby_version: 3.1
ignore:
- "spec/dummy/**/*"
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ gem "rails", "~> #{rails_version}.0"
gem "listen", "~> 3.8"
gem "puma", "~> 6.0"

gem "sprockets-rails", "< 3.5.0"

# Specify your gem's dependencies in alchemy-solidus.gemspec
gemspec

Expand Down
4 changes: 4 additions & 0 deletions app/models/alchemy/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def ransackable_attributes(_auth_object = nil)
]
end

def ransortable_attributes(_auth_object = nil)
%w[last_sign_in_at]
end

alias_method :searchable_alchemy_resource_attributes, :ransackable_attributes

def ransackable_associations(_auth_object = nil)
Expand Down
34 changes: 34 additions & 0 deletions app/views/alchemy/admin/users/_resource_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| %>
tvdeyen marked this conversation as resolved.
Dismissed
Show resolved Hide resolved
<% 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" %>
28 changes: 28 additions & 0 deletions app/views/alchemy/admin/users/_table.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<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: "user", collection: @users %>
</tbody>
</table>
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
Loading