From ccc29be2976aba89365112122d02692c14b45831 Mon Sep 17 00:00:00 2001 From: James Smith Date: Mon, 13 Jan 2025 09:20:16 +0000 Subject: [PATCH 1/2] refactor renderable check into ModelFile --- app/components/model_component.html.erb | 2 +- app/helpers/application_helper.rb | 9 --------- app/models/model_file.rb | 4 ++++ app/views/application/_object_preview.html.erb | 2 +- app/views/collections/_collection.html.erb | 2 +- app/views/model_files/show.html.erb | 2 +- app/views/models/_file.html.erb | 2 +- spec/helpers/application_helper_spec.rb | 14 -------------- spec/models/model_file_spec.rb | 12 ++++++++++++ 9 files changed, 21 insertions(+), 28 deletions(-) diff --git a/app/components/model_component.html.erb b/app/components/model_component.html.erb index 8e2e32af7..b487ba190 100644 --- a/app/components/model_component.html.erb +++ b/app/components/model_component.html.erb @@ -4,7 +4,7 @@ <% if file.is_image? %> <%= content_tag :div, nil, class: "card-img-top card-img-top-background", style: "background-image: url(#{model_model_file_path(@model, file, format: file.extension)})" %> <%= image_tag model_model_file_path(@model, file, format: file.extension), class: "card-img-top image-preview #{"sensitive" if helpers.needs_hiding?(@model)}", alt: file.name %> - <% elsif helpers.renderable?(file.extension) %> + <% elsif file.is_renderable? %>
"> <%= render partial: "object_preview", locals: {model: @model, file: file} %>
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 12bf244ef..e73e262e0 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -81,15 +81,6 @@ def card(style, title = nil, options = {}, &content) end end - def renderable?(format) - case format - when "stl", "obj", "3mf", "ply", "gltf", "glb" - true - else - false - end - end - def text_input_row(form, name, options = {}) content_tag :div, class: "row mb-3 input-group" do safe_join [ diff --git a/app/models/model_file.rb b/app/models/model_file.rb index 990ec9586..32f783e9b 100644 --- a/app/models/model_file.rb +++ b/app/models/model_file.rb @@ -84,6 +84,10 @@ def is_3d_model? SupportedMimeTypes.model_extensions.include? extension end + def is_renderable? + ["stl", "obj", "3mf", "ply", "gltf", "glb"].include? extension + end + def mime_type Mime::Type.lookup_by_extension(extension) end diff --git a/app/views/application/_object_preview.html.erb b/app/views/application/_object_preview.html.erb index 9ef73ad3a..18efd6b50 100644 --- a/app/views/application/_object_preview.html.erb +++ b/app/views/application/_object_preview.html.erb @@ -1,4 +1,4 @@ -<% if renderable?(file.extension) %> +<% if file.is_renderable? %>
<%= content_tag :div, nil, class: "card-img-top card-img-top-background", style: "background-image: url(#{model_model_file_path(model, file, format: file.extension)})" %> <%= image_tag model_model_file_path(model, file, format: file.extension), class: "card-img-top image-preview ", alt: file.name %> - <% elsif renderable?(file.extension) %> + <% elsif file.is_renderable? %>
<%= render partial: "object_preview", locals: {model: model, file: file} %>
diff --git a/app/views/model_files/show.html.erb b/app/views/model_files/show.html.erb index 3be5a6ef9..1809f9279 100644 --- a/app/views/model_files/show.html.erb +++ b/app/views/model_files/show.html.erb @@ -15,7 +15,7 @@ <%= video_tag model_model_file_path(@model, @file, format: @file.extension), alt: @file.name, style: "width: 100%", controls: true %> <% elsif @file.is_document? %> <%= tag.iframe src: model_model_file_path(@model, @file, format: @file.extension), alt: @file.name, style: "width: 100%; aspect-ratio: 0.707" %> - <% elsif renderable?(@file.extension) %> + <% elsif @file.is_renderable? %> <% if @file.presupported_version || @file.unsupported_version %>