Skip to content

Commit

Permalink
Merge pull request #3206 from manyfold3d/admin-sidebar
Browse files Browse the repository at this point in the history
Redesign site settings area, to allow future expansion
  • Loading branch information
Floppy authored Nov 20, 2024
2 parents 6c87642 + 6cb0807 commit c29705e
Show file tree
Hide file tree
Showing 39 changed files with 454 additions and 2,192 deletions.
9 changes: 3 additions & 6 deletions app/controllers/libraries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ class LibrariesController < ApplicationController
skip_after_action :verify_policy_scoped, only: [:index]

def index
if Library.count === 0
redirect_to new_library_path
else
redirect_to models_path
end
redirect_to new_library_path and return if Library.count === 0
render layout: "settings"
end

def show
Expand Down Expand Up @@ -67,7 +64,7 @@ def scan_all

def destroy
@library.destroy
redirect_to libraries_path, notice: t(".success")
redirect_to settings_libraries_path, notice: t(".success")
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/models_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def create
)
end

redirect_to libraries_path, notice: t(".success")
redirect_to models_path, notice: t(".success")
end

def update
Expand Down
5 changes: 2 additions & 3 deletions app/controllers/settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def update
update_multiuser_settings(params[:multiuser])
update_analysis_settings(params[:analysis])
update_usage_settings(params[:usage])
redirect_to settings_path(@user), notice: t(".success")
redirect_back_or_to settings_path, notice: t(".success")
end

private
Expand Down Expand Up @@ -45,7 +45,6 @@ def update_usage_settings(settings)
end

def check_owner_permission
render plain: "401 Unauthorized", status: :unauthorized unless current_user.is_administrator?
authorize current_user
authorize :settings
end
end
6 changes: 6 additions & 0 deletions app/policies/library_policy.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
class LibraryPolicy < ApplicationPolicy
def index?
all_of(
user&.is_administrator?
)
end

def create?
all_of(
user&.is_administrator?,
Expand Down
23 changes: 23 additions & 0 deletions app/policies/settings_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class SettingsPolicy < ApplicationPolicy
def show?
update?
end

def analysis?
update?
end

def multiuser?
update?
end

def reporting?
update?
end

def update?
one_of(
user&.is_administrator?
)
end
end
47 changes: 47 additions & 0 deletions app/views/layouts/settings.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<h1><%= t ".title" %></h1>
<div class="row mt-2">
<div class="col col-auto border-end" id="sidebar">
<ul class="nav flex-column">
<li class="nav-item">
<%= link_to t(".organization"), settings_path, class: "nav-link" %>
</li>
<li class="nav-item">
<%= link_to t(".libraries"), settings_libraries_path, class: "nav-link" %>
</li>
<li class="nav-item">
<%= link_to t("settings.analysis.heading"), analysis_settings_path(anchor: "analysis"), class: "nav-link" %>
</li>
<li class="nav-item">
<%= link_to t("settings.multiuser.heading"), multiuser_settings_path(anchor: "multiuser"), class: "nav-link" %>
</li>
<li class="nav-item">
<%= link_to t("settings.reporting.heading"), reporting_settings_path(anchor: "reporting"), class: "nav-link" %>
</li>
</ul>
<% unless SiteSettings.demo_mode_enabled? %>
<hr>
<h5><%= t(".tools_heading") %></h5>
<ul class="nav flex-column">
<li class="nav-item">
<%= link_to t(".activeadmin"), admin_root_path, class: "nav-link" %>
</li>
<li class="nav-item">
<%= link_to t(".performance"), rails_performance_path, class: "nav-link" unless Rails.env.test? %>
</li>
<li class="nav-item">
<%= link_to t(".sidekiq"), sidekiq_web_path, class: "nav-link" %>
</li>
<%= if defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) && ApplicationRecord.connection.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
link_to safe_join([icon("database", t(".pghero")), t(".pghero")], " "),
pg_hero_path,
class: "btn btn-danger mb-3"
end %>
</ul>
<% end %>
</div>
<div class="col" id="content">
<%= yield %>
</div>
</div>

<% parent_layout "application" %>
69 changes: 69 additions & 0 deletions app/views/libraries/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<h3><%= t(".heading") %></h3>
<%= link_to t("libraries.general.new"), new_library_path, class: "btn btn-secondary float-end" if policy(:library).new? %>
<p class='lead'>
<%= t(".description") %>
</p>
<div class="row">
<% Library.find_each do |library| %>
<div class="col-md-6">
<div class="card">
<div class="card-header">
<%= icon(library.icon, library.icon) if library.icon %>
<%= library.name %>
</div>
<div class="card-body">
<%= link_to t("general.edit"), edit_library_path(library), {class: "btn btn-secondary float-end #{policy(:library).edit? ? "" : "disabled"}"} %>
<p>
<%= markdownify(library.notes) if library.notes %>
</p>
<table class="table">
<tr>
<td><%= t("activerecord.attributes.library.storage_service") %></td>
<td><%= t("libraries.storage_services.%{service}" % {service: library.storage_service}) %></td>
</tr>
<% if library.storage_service == "filesystem" %>
<tr>
<td><%= t("activerecord.attributes.library.path") %></td>
<td><code style="word-break: break-all"><%= library.path %></code></td>
</tr>
<% end %>
<% if library.storage_service == "s3" %>
<tr>
<td><%= t("activerecord.attributes.library.s3_endpoint") %></td>
<td><%= library.s3_endpoint %></td>
</tr>
<tr>
<td><%= t("activerecord.attributes.library.s3_bucket") %></td>
<td><%= library.s3_bucket %></td>
</tr>
<tr>
<td><%= t("activerecord.attributes.library.s3_region") %></td>
<td><%= library.s3_region %></td>
</tr>
<% end %>
<% if library.free_space %>
<tr>
<td><%= t(".free_space.label") %></td>
<td><%= number_to_human_size(library.free_space, precision: 2) %></td>
</tr>
<% end %>
<tr>
<td><%= t("activerecord.attributes.library.caption") %></td>
<td><%= library.caption %></td>
</tr>
<tr>
<td><%= t("activerecord.attributes.library.tag_regex") %></td>
<td>
<% library.tag_regex.each do |reg| %>
<%= link_to t(".tag_regex.check"), models_path(library: library, missingtag: reg), {class: "btn btn-outline-secondary"} %>
<code><%= reg %></code><br>
<% end %>
<%= if !library.tag_regex.empty? then link_to t(".tag_regex.search_missing"), models_path(library: library, missingtag: ""), {class: "btn btn-outline-secondary"} end %>
</td>
</tr>
</table>
</div>
</div>
</div>
<% end %>
</div>
21 changes: 0 additions & 21 deletions app/views/settings/_admin_tools.html.erb

This file was deleted.

15 changes: 0 additions & 15 deletions app/views/settings/_analysis_settings.html.erb

This file was deleted.

88 changes: 42 additions & 46 deletions app/views/settings/_folder_settings.html.erb
Original file line number Diff line number Diff line change
@@ -1,48 +1,44 @@
<div class="card mb-2">
<h3 class="card-header"><%= t(".title") %></h3>
<div class="card-body">
<p class='lead'>
<%= t ".summary" %>
</p>
<p>
<%= t ".details" %>
</p>
<ul>
<li>
<code>{tags}</code>: <%= t ".tokens.tags_html" %>
</li>
<li>
<code>{creator}</code>: <%= t ".tokens.creator" %>
</li>
<li>
<code>{collection}</code>: <%= t ".tokens.collection" %>
</li>
<li>
<code>{modelName}</code>: <%= t ".tokens.model_name" %>
</li>
<li>
<code>{modelId}</code>: <%= t ".tokens.model_id" %>
</li>
</ul>
<div class="row mb-2">
<%= form.label nil, t(".model_path_template.label"), for: "folders[model_path_template]", class: "col-sm-4 col-form-label" %>
<div class="col-sm-8 form-check form-switch">
<%= form.text_field "folders[model_path_template]", value: SiteSettings.model_path_template, class: "form-control" %>
</div>
</div>
<div class="row mb-2">
<%= form.label nil, t(".parse_metadata_from_path.label"), for: "folders[parse_metadata_from_path]", class: "col-sm-4 col-form-label" %>
<div class="col-sm-8 form-check form-switch">
<%= form.check_box "folders[parse_metadata_from_path]", checked: SiteSettings.parse_metadata_from_path, class: "form-check-input" %>
<small><%= t ".parse_metadata_from_path.help" %></small>
</div>
</div>
<div class="row mb-2">
<%= form.label nil, t(".safe_folder_names.label"), for: "folders[safe_folder_names]", class: "col-sm-4 col-form-label" %>
<div class="col-sm-8 form-check form-switch">
<%= form.check_box "folders[safe_folder_names]", checked: SiteSettings.safe_folder_names, class: "form-check-input" %>
<small><%= t(".safe_folder_names.help_html") %></small>
</div>
</div>
<h3><%= t(".title") %></h3>
<p class='lead'>
<%= t ".summary" %>
</p>
<p>
<%= t ".details" %>
</p>
<ul>
<li>
<code>{tags}</code>: <%= t ".tokens.tags_html" %>
</li>
<li>
<code>{creator}</code>: <%= t ".tokens.creator" %>
</li>
<li>
<code>{collection}</code>: <%= t ".tokens.collection" %>
</li>
<li>
<code>{modelName}</code>: <%= t ".tokens.model_name" %>
</li>
<li>
<code>{modelId}</code>: <%= t ".tokens.model_id" %>
</li>
</ul>
<div class="row mb-2">
<%= form.label nil, t(".model_path_template.label"), for: "folders[model_path_template]", class: "col-sm-4 col-form-label" %>
<div class="col-sm-8 form-check form-switch">
<%= form.text_field "folders[model_path_template]", value: SiteSettings.model_path_template, class: "form-control" %>
</div>
</div>
<div class="row mb-2">
<%= form.label nil, t(".parse_metadata_from_path.label"), for: "folders[parse_metadata_from_path]", class: "col-sm-4 col-form-label" %>
<div class="col-sm-8 form-check form-switch">
<%= form.check_box "folders[parse_metadata_from_path]", checked: SiteSettings.parse_metadata_from_path, class: "form-check-input" %>
<small><%= t ".parse_metadata_from_path.help" %></small>
</div>
</div>
<div class="row mb-2">
<%= form.label nil, t(".safe_folder_names.label"), for: "folders[safe_folder_names]", class: "col-sm-4 col-form-label" %>
<div class="col-sm-8 form-check form-switch">
<%= form.check_box "folders[safe_folder_names]", checked: SiteSettings.safe_folder_names, class: "form-check-input" %>
<small><%= t(".safe_folder_names.help_html") %></small>
</div>
</div>
Loading

0 comments on commit c29705e

Please sign in to comment.