Updated screens create action to handle image attachment

Necessary to attach a processed image to your screen. This improves the UI experience by being able to download and upload images for screens interchangeably. For HTML, data, and unprocessed images you'll want to the use the API or Extensions UI.

The associated unit spec is no longer needed because we are not using htmx for this.

Milestone: minor
This commit is contained in:
Brooke Kuhlmann
2026-02-02 13:20:21 -07:00
parent cf166dcd1a
commit adbcc3ab59
3 changed files with 16 additions and 41 deletions
+14 -8
View File
@@ -17,6 +17,7 @@ module Terminus
required(:model_id).filled :integer
required(:label).filled :string
required(:name).filled :string
required(:image).filled :hash
end
end
@@ -24,8 +25,8 @@ module Terminus
parameters = request.params
if parameters.valid?
repository.create parameters[:screen]
response.render index_view, **view_settings(request)
save parameters[:screen]
response.render index_view, screens: repository.all
else
error response, parameters
end
@@ -33,10 +34,16 @@ module Terminus
private
def view_settings request
settings = {screens: repository.all}
settings[:layout] = false if htmx.request? request.env, :request, "true"
settings
# :reek:FeatureEnvy
# :reek:TooManyStatements
def save attributes
image = attributes.delete :image
record = repository.create attributes
tempfile = image[:tempfile]
extension = File.extname tempfile
record.upload tempfile, metadata: {"filename" => "#{record.name}#{extension}"}
repository.update record.id, image_data: record.image_attributes
end
def error response, parameters
@@ -44,8 +51,7 @@ module Terminus
models: model_repository.all,
screen: nil,
fields: parameters[:screen],
errors: parameters.errors[:screen],
layout: false
errors: parameters.errors[:screen]
end
end
end
+2 -2
View File
@@ -10,13 +10,13 @@
<div class="bit-body">
<div class="screens">
<%= form_for :screen, routes.path(:screens), class: "bit-card bit-form screen" do |form| %>
<%= form_for :screen, routes.path(:screens), class: "bit-card bit-form" do |form| %>
<h1 class="label">New Screen</h1>
<%= render "screens/shared/fields", form:, models:, screen:, fields: fields.value, errors: %>
<div class="form-actions">
<%= render "shared/actions/save", form:, path: routes.path(:screen_create) %>
<%= form.submit "Save", class: "bit-button-accept" %>
<%= link_to "Cancel", routes.path(:screens), class: "bit-button-decline" %>
</div>
<% end %>
-31
View File
@@ -1,31 +0,0 @@
# frozen_string_literal: true
require "hanami_helper"
RSpec.describe Terminus::Actions::Screens::Create, :db do
subject(:action) { described_class.new }
describe "#call" do
let(:model) { Factory[:model] }
let :params do
{
screen: {
model_id: model.id,
label: "Test",
name: "test"
}
}
end
it "renders default response" do
response = Rack::MockRequest.new(action).post("", params:)
expect(response.body).to include("<!DOCTYPE html>")
end
it "renders htmx response" do
response = Rack::MockRequest.new(action).post("", "HTTP_HX_REQUEST" => "true", params:)
expect(response.body).to have_htmx_title("Screens")
end
end
end