Skip to content

Commit

Permalink
Merge pull request #3002 from manyfold3d/creator-profile
Browse files Browse the repository at this point in the history
Creator profile
  • Loading branch information
Floppy authored Oct 21, 2024
2 parents 382f3f8 + 78ab4ec commit ecc2076
Show file tree
Hide file tree
Showing 49 changed files with 183 additions and 475 deletions.
7 changes: 7 additions & 0 deletions app/assets/stylesheets/models.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ div.form-control.tag-container {
padding: 0;
}

.action-card .card-text {
display: flex;
flex-direction: column;
row-gap: 1rem;
align-items: start;
}

.preview-card {
min-height: 100%;
background: none;
Expand Down
4 changes: 2 additions & 2 deletions app/components/model_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
<div class="col-auto">
<small>
<ul class="list-unstyled">
<% if @creator.nil? && @model.creator %>
<% if @model.creator %>
<li>
<%= helpers.icon "person", Creator.model_name.human %>
<%= link_to @model.creator.name, models_path((@filters || {}).merge(creator: @model.creator)),
<%= link_to @model.creator.name, @model.creator,
"aria-label": [Creator.model_name.human, @model.creator.name].join(": ") %>
</li>
<% end %>
Expand Down
35 changes: 35 additions & 0 deletions app/controllers/concerns/model_listable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module ModelListable
extend ActiveSupport::Concern

included do
include TagListable
include Filterable
end

private

def prepare_model_list
# Work out policies for showing buttons up front
@can_destroy = policy(Model).destroy?
@can_edit = policy(Model).edit?

# Ordering
@models = case session["order"]
when "recent"
@models.order(created_at: :desc)
else
@models.order(name_lower: :asc)
end

@tags, @unrelated_tag_count = generate_tag_list(@models, @filter_tags)
@tags, @kv_tags = split_key_value_tags(@tags)

if helpers.pagination_settings["models"]
page = params[:page] || 1
@models = @models.page(page).per(helpers.pagination_settings["per_page"])
end

# Load extra data
@models = @models.includes [:library, :model_files, :preview_file, :creator, :collection]
end
end
8 changes: 5 additions & 3 deletions app/controllers/creators_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class CreatorsController < ApplicationController
include Filterable
include TagListable
include ModelListable
include Permittable

before_action :get_creator, except: [:index, :new, :create]
Expand Down Expand Up @@ -33,7 +32,10 @@ def index
end

def show
redirect_to models_path(creator: params[:id])
@models = policy_scope(Model).where(creator: @creator)
prepare_model_list
@additional_filters = {creator: @creator}
render layout: "card_list_page"
end

def new
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/follows_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ def get_target
followable = params[:followable_class].constantize
followable_param = params[:followable_class].parameterize + "_id"
id = params[followable_param]
@target = policy_scope(followable).find(id)
@target = policy_scope(followable).find_param(id)
end
end
28 changes: 2 additions & 26 deletions app/controllers/models_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
require "fileutils"

class ModelsController < ApplicationController
include Filterable
include TagListable
include ModelListable
include Permittable

before_action :get_model, except: [:bulk_edit, :bulk_update, :index, :new, :create]
Expand All @@ -13,31 +12,8 @@ class ModelsController < ApplicationController
after_action :verify_policy_scoped, only: [:bulk_edit, :bulk_update]

def index
# Work out policies for showing buttons up front
@can_destroy = policy(Model).destroy?
@can_edit = policy(Model).edit?

@models = filtered_models @filters

# Ordering
@models = case session["order"]
when "recent"
@models.order(created_at: :desc)
else
@models.order(name_lower: :asc)
end

@tags, @unrelated_tag_count = generate_tag_list(@models, @filter_tags)
@tags, @kv_tags = split_key_value_tags(@tags)

if helpers.pagination_settings["models"]
page = params[:page] || 1
@models = @models.page(page).per(helpers.pagination_settings["per_page"])
end

# Load extra data
@models = @models.includes [:library, :model_files, :preview_file, :creator, :collection]

prepare_model_list
render layout: "card_list_page"
end

Expand Down
4 changes: 2 additions & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def markdownify(text)
end

def card(style, title = nil, options = {}, &content)
id = "card-#{SecureRandom.hex(4)}"
card_class = "card mb-4"
id = options[:id] || "card-#{SecureRandom.hex(4)}"
card_class = ["card", "mb-4", options[:class]].join(" ")
if options[:skip_link]
skiplink = skip_link(options[:skip_link][:target], options[:skip_link][:text])
card_class += " skip-link-container"
Expand Down
8 changes: 8 additions & 0 deletions app/models/creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,12 @@ def self.ransackable_attributes(_auth_object = nil)
def self.ransackable_associations(_auth_object = nil)
["links", "models"]
end

def to_param
slug
end

def self.find_param(param)
find_by!(slug: param)
end
end
10 changes: 0 additions & 10 deletions app/views/application/_content_header.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +0,0 @@
<div class="col-9">
<div class="row row-cols-2 align-items-baseline">
<% if !current_page?(root_path) %>
<div class="ms-auto col col-auto mt-2 mb-2">
<%= link_to icon("book", t(".sort.name")), @filters.merge(order: "name"), class: "btn #{(session["order"] == "name") ? "btn-secondary" : "btn-outline-secondary"} btn-sm" %>
<%= link_to icon("clock", t(".sort.time")), @filters.merge(order: "recent"), class: "btn #{(session["order"] == "recent") ? "btn-secondary" : "btn-outline-secondary"} btn-sm" %>
</div>
<% end %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/application/_filters_card.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<% if @filters[:creator] %>
<div class="row">
<div class="col-auto"><%= icon "person", Creator.model_name.human %></div>
<div class="col" aria-label="<%= Creator.model_name.human %>"><%= @creator ? @creator.name.careful_titleize : t(".unknown") %></div>
<div class="col" aria-label="<%= Creator.model_name.human %>"><%= @creator ? link_to(@creator.name.careful_titleize, @creator) : t(".unknown") %></div>
<div class="col-auto"><%= link_to icon("trash", t(".remove_creator_filter")), @filters.except(:creator), {class: "text-danger"} %></div>
</div>
<% end %>
Expand Down
4 changes: 4 additions & 0 deletions app/views/application/_order_buttons.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="float-end mb-3">
<%= link_to icon("book", t(".sort.name")), @filters.merge(order: "name"), class: "btn #{(session["order"] == "name") ? "btn-secondary" : "btn-outline-secondary"} btn-sm" %>
<%= link_to icon("clock", t(".sort.time")), @filters.merge(order: "recent"), class: "btn #{(session["order"] == "recent") ? "btn-secondary" : "btn-outline-secondary"} btn-sm" %>
</div>
2 changes: 1 addition & 1 deletion app/views/application/_tag_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<% end %>
<%- tag_html_opts = {data: {bulk_item_tags: defined?(model_id) ? model_id&.to_s : nil}} %>
<%- heatmap = defined?(show_count) ? heatmap : tag_cloud_settings["heatmap"] %>
<%= safe_join(tags.map { |tag| render TagComponent.new(tag: tag, filters: @filters, html_options: tag_html_opts, show_count: heatmap, filter_in_place: @filter_in_place) }, " ") if tags %>
<%= safe_join(tags.map { |tag| render TagComponent.new(tag: tag, filters: @filters.merge(@additional_filters), html_options: tag_html_opts, show_count: heatmap, filter_in_place: @filter_in_place) }, " ") if tags %>
<% if defined?(kv_tags) && kv_tags %>
<ul class="list-unstyled">
<% tiers.each do |tier| %>
Expand Down
22 changes: 11 additions & 11 deletions app/views/collections/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<% content_for :page_header do %>
<%= render "application/content_header" %>
<% end %>
<% content_for :items do %>
<div class="skip-link-container">
<%= skip_link "sidebar", t(".skip_collections") %>
<% if pagination_settings["collections"] %>
<%= paginate @collections %>
<% end %>
<div class="clearfix">
<%= skip_link "sidebar", t(".skip_collections") %>
<%= render "order_buttons" %>
<% if pagination_settings["collections"] %>
<%= paginate @collections %>
<% end %>
</div>
<div class="row row-cols-1 row-cols-md-2 row-cols-lg-3 mb-4">
<%= render "unassigned" if (!pagination_settings["collections"] || @collections.first_page?) && !@filters[:collection] %>
<% if @filters[:collection] && @collection %>
Expand All @@ -21,10 +20,11 @@
</div>
<% end %>
<% content_for :actions do %>
<%= link_to t("collections.general.new"), new_collection_path, class: "btn btn-primary" if policy(:collection).new? %>
<% end %>
<% content_for :sidebar do %>
<%= card :secondary, t(".actions_heading") do %>
<%= link_to t("collections.general.new"), new_collection_path, class: "btn btn-primary mb-3 me-3" if policy(:collection).new? %>
<% end %>
<%= render "filters_card" %>
<%= render "tags_card" %>
<% end %>
7 changes: 2 additions & 5 deletions app/views/creators/_creator.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
<div class="card-body">
<div class="card-title"><%= creator.name %></div>
<% if creator.caption %>
<h6 class="card-subtitle mb-2 text-muted"><%= sanitize creator.caption %></h6>
<% end %>
<% if creator.notes %>
<p class="card-text"><%= markdownify creator.notes %></p>
<small class="card-subtitle mb-2 text-muted"><%= sanitize creator.caption %></small>
<% end %>
<ul class='links'>
<% creator.links.each do |link| %>
<li><%= link_to t("sites.%{site}" % {site: link.site}), link.url %></li>
<% end %>
</ul>
<%= link_to "#{policy_scope(Model).where(creator: creator).count} #{Model.model_name.human count: policy_scope(Model).where(creator: creator).count}", models_path(creator: creator), {class: "btn btn-primary", "aria-label": translate(".models_button.label", name: creator.name)} if policy(creator).show? %>
<%= link_to "#{policy_scope(Model).where(creator: creator).count} #{Model.model_name.human count: policy_scope(Model).where(creator: creator).count}", creator, {class: "btn btn-primary", "aria-label": translate(".models_button.label", name: creator.name)} if policy(creator).show? %>
<%= link_to icon("pencil-fill", t(".edit_button.text")), edit_creator_path(creator), {class: "btn btn-outline-secondary", "aria-label": translate(".edit_button.label", name: creator.name)} if policy(creator).edit? %>
</div>
</div>
Expand Down
22 changes: 11 additions & 11 deletions app/views/creators/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<% content_for :page_header do %>
<%= render "application/content_header" %>
<% end %>
<% content_for :items do %>
<div class="skip-link-container">
<%= skip_link "sidebar", t(".skip_creators") %>
<% if pagination_settings["creators"] %>
<%= paginate @creators %>
<% end %>
<div class="clearfix">
<%= skip_link "sidebar", t(".skip_creators") %>
<%= render "order_buttons" %>
<% if pagination_settings["creators"] %>
<%= paginate @creators %>
<% end %>
</div>
<div class="row row-cols-1 row-cols-md-2 row-cols-lg-3 mb-4">
<%= render "unassigned" if !pagination_settings["creators"] || @creators.first_page? %>
<%= render @creators %>
Expand All @@ -18,10 +17,11 @@
</div>
<% end %>
<% content_for :actions do %>
<%= link_to t("creators.general.new"), new_creator_path, class: "btn btn-primary" if policy(:creator).new? %>
<% end %>
<% content_for :sidebar do %>
<%= card :secondary, t(".actions_heading") do %>
<%= link_to t("creators.general.new"), new_creator_path, class: "btn btn-primary mb-3 me-3" if policy(:creator).new? %>
<% end %>
<%= render "filters_card" %>
<%= render "tags_card" %>
<% end %>
24 changes: 24 additions & 0 deletions app/views/creators/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<%= content_for :items do %>
<div class="card mb-3">
<div class="card-body row">
<div class="col col-md-3">
<%= content_tag(:div, class: "text-center") do %>
<%= content_tag(:h2) { @creator.name } %>
<p><small>@<%= @creator.actor.at_address if SiteSettings.federation_enabled? %></small></p>
<%= render FollowButtonComponent.new(follower: current_user, target: @creator) %>
<% end %>
</div>
<div class="col col-md-9">
<%= content_tag(:p, class: "lead") { @creator.caption } if @creator.caption %>
<%= content_tag(:p, class: "card-text") { markdownify @creator.notes } if @creator.notes %>
<%= "#{policy_scope(Model).where(creator: @creator).count} #{Model.model_name.human count: policy_scope(Model).where(creator: @creator).count}" %>
</div>
</div>
</div>
<% end %>
<% content_for :actions do %>
<%= link_to safe_join([icon("pencil", t(".edit")), t(".edit")], " "), edit_creator_path(@creator), class: "btn btn-primary" if policy(@creator).edit? %>
<% end %>
<%= render "models/list" %>
1 change: 0 additions & 1 deletion app/views/home/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<div class="row bg-body-tertiary pt-3 mb-3 text-center">
<%= render "application/content_header" %>
<h1 class="d-none d-lg-block"><%= site_name %></h1>
<p class='lead'><%= site_tagline %></p>
<% if SiteSettings.demo_mode_enabled? %>
Expand Down
6 changes: 3 additions & 3 deletions app/views/layouts/card_list_page.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<%= yield :page_header %>

<div class="row row-cols-md-2">
<div class="row row-cols-md-2 mt-2">
<div class="col-md-9" id="item_list">
<%= yield :items %>
</div>
<div class="col-md-3" id="sidebar">
<% action_content = yield :actions %>
<%= card(:secondary, t(".actions_heading"), class: "action-card") { action_content } if action_content.present? %>
<%= yield :sidebar %>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/model_files/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<%= render partial: "problem", collection: @file.problems.visible(problem_settings) %>
<%= card :secondary, t(".actions_heading") do %>
<%= card :secondary, t("layouts.card_list_page.actions_heading") do %>
<%= link_to safe_join([icon("cloud-download", t("general.download")), t("general.download")], " "), model_model_file_path(@model, @file, @file.extension&.to_sym, download: "true"), {class: "btn btn-secondary"} %>
<% if policy(@file).edit? && ["stl", "obj"].include?(@file.extension) %>
<%= link_to safe_join([icon("arrow-left-right", t(".convert")), t(".convert")], " "), model_model_files_path(@model, convert: {id: @file.to_param, to: "threemf"}), method: :post, class: "btn btn-warning" %>
Expand Down
36 changes: 36 additions & 0 deletions app/views/models/_list.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<% content_for :items do %>
<% if @models.empty? %>
<div class="alert alert-info">
<%= icon "person-arms-up", "" %>
<%= t(".no_results_html") %>
</div>
<% else %>
<div class="skip-link-container">
<div class="clearfix">
<%= skip_link "sidebar", t(".skip_models") %>
<%= render "order_buttons" %>
<% if pagination_settings["models"] %>
<%= paginate @models %>
<% end %>
</div>
<div class="row row-cols-1 row-cols-md-2 row-cols-lg-3 mb-4">
<%= render ModelComponent.with_collection(@models, can_edit: @can_edit, can_destroy: @can_destroy) %>
</div>
<% if pagination_settings["models"] %>
<%= paginate @models %>
<% end %>
</div>
<% end %>
<% end %>
<% content_for :actions do %>
<%= link_to t(".bulk_edit"), edit_models_path(@filters.merge(@additional_filters)), class: "btn btn-secondary" if policy(:model).edit? %>
<% if @collection %>
<%= render FollowButtonComponent.new(follower: current_user, target: @collection, name: @collection.name) %>
<% end %>
<% end %>
<% content_for :sidebar do %>
<%= render "filters_card" %>
<%= render "tags_card" %>
<% end %>
Loading

0 comments on commit ecc2076

Please sign in to comment.