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 Turbo Frame for picture dialog for #2950

Merged
merged 1 commit into from
Jul 1, 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
2 changes: 1 addition & 1 deletion app/controllers/alchemy/admin/pictures_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class PicturesController < Alchemy::Admin::ResourcesController
before_action :load_resource,
only: [:show, :edit, :update, :url, :destroy]

before_action :set_size, only: [:index, :show, :edit_multiple]
before_action :set_size, only: [:index, :show, :edit_multiple, :update]

authorize_resource class: Alchemy::Picture

Expand Down
26 changes: 14 additions & 12 deletions app/views/alchemy/admin/pictures/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<%= alchemy_form_for [:admin, @picture] do |f| %>
<%= f.input :name %>
<%= render "picture_description_field", f: f %>
<%= render Alchemy::Admin::TagsAutocomplete.new(additional_class: "input") do %>
<%= f.label :tag_list %>
<%= f.text_field :tag_list, value: f.object.tag_list.join(",") %>
<small class="hint"><%= Alchemy.t('Please seperate the tags with commata') %></small>
<%= turbo_frame_tag(@picture) do %>
<%= alchemy_form_for [:admin, @picture] do |f| %>
<%= f.input :name %>
<%= render "picture_description_field", f: f %>
<%= render Alchemy::Admin::TagsAutocomplete.new(additional_class: "input") do %>
<%= f.label :tag_list %>
<%= f.text_field :tag_list, value: f.object.tag_list.join(",") %>
<small class="hint"><%= Alchemy.t('Please seperate the tags with commata') %></small>
<% end %>
<%= hidden_field_tag :q, search_filter_params[:q] %>
<%= hidden_field_tag :size, @size %>
<%= hidden_field_tag :tagged_with, search_filter_params[:tagged_with] %>
<%= hidden_field_tag :filter, search_filter_params[:filter] %>
<%= f.submit Alchemy.t(:save) %>
<% end %>
<%= hidden_field_tag :q, search_filter_params[:q] %>
<%= hidden_field_tag :size, @size %>
<%= hidden_field_tag :tagged_with, search_filter_params[:tagged_with] %>
<%= hidden_field_tag :filter, search_filter_params[:filter] %>
<%= f.submit Alchemy.t(:save) %>
<% end %>
2 changes: 1 addition & 1 deletion app/views/alchemy/admin/pictures/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
$(".selected_item_tools").toggleClass("hidden")
return false;
});
$('.thumbnail_background').on("click", function(event) {
$('#picture_archive').on("click", ".thumbnail_background", function(event) {
var url = $(this).attr('href');
var overlay = new Alchemy.ImageOverlay(url);
overlay.open();
Expand Down
6 changes: 0 additions & 6 deletions app/views/alchemy/admin/pictures/update.js.erb

This file was deleted.

6 changes: 6 additions & 0 deletions app/views/alchemy/admin/pictures/update.turbo_stream.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<alchemy-growl type=<%= @message[:type] %>>
<%= @message[:body] %>
</alchemy-growl>
<%= turbo_stream.replace("picture_#{@picture.id}") do %>
<%= render "picture", picture: @picture %>
<% end %>
19 changes: 19 additions & 0 deletions spec/features/admin/picture_library_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,23 @@
expect(page).to have_field("Description", with: "This is an amazing image.")
end
end

describe "Updating Pictures", :js do
let!(:picture) { create(:alchemy_picture) }

scenario "allows to update a pictures name" do
visit alchemy.admin_pictures_path
page.find("a.thumbnail_background").click
expect(page).to have_field("Name")
fill_in "Name", with: "my-amazing-image"
click_button "Save"
within "#flash_notices" do
expect(page).to have_content("Picture updated successfully")
end
find(".zoomed-picture-background").click
within "#picture_#{picture.id} .picture_name" do
expect(page).to have_content("my-amazing-image")
end
end
end
end