-
-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add multi language image descriptions
- Loading branch information
Showing
26 changed files
with
247 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
app/controllers/alchemy/admin/picture_descriptions_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module Alchemy | ||
module Admin | ||
class PictureDescriptionsController < Alchemy::Admin::ResourcesController | ||
def index | ||
load_resource | ||
end | ||
|
||
def edit | ||
@picture_description = @picture.descriptions.find_or_initialize_by(language_id: params[:language_id]) | ||
end | ||
|
||
private | ||
|
||
def load_resource | ||
@picture = Alchemy::Picture.find(params[:picture_id]) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module Alchemy | ||
class PictureDescription < ActiveRecord::Base | ||
belongs_to :picture, class_name: "Alchemy::Picture" | ||
belongs_to :language, class_name: "Alchemy::Language" | ||
|
||
validates_uniqueness_of :picture_id, scope: :language_id | ||
end | ||
end |
11 changes: 11 additions & 0 deletions
11
app/views/alchemy/admin/picture_descriptions/_form.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<% field_name_prefix = "picture[descriptions_attributes][#{picture_description_counter}]" %> | ||
<% if picture_description.persisted? %> | ||
<%= hidden_field field_name_prefix, :id, value: picture_description.id %> | ||
<% else %> | ||
<%= hidden_field field_name_prefix, :language_id, value: picture_description.language_id %> | ||
<%= hidden_field field_name_prefix, :picture_id, value: picture_description.picture_id %> | ||
<% end %> | ||
<%= label field_name_prefix, :text, Alchemy::PictureDescription.human_attribute_name(:text), class: "control-label" %> | ||
<%= text_area field_name_prefix, :text, value: picture_description.text, rows: 3 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<turbo-frame id="picture_descriptions"> | ||
<%= render "form", { | ||
picture_description: @picture_description, | ||
picture_description_counter: @picture.descriptions.index(@picture_description) | ||
} %> | ||
</turbo-frame> |
29 changes: 28 additions & 1 deletion
29
app/views/alchemy/admin/pictures/_picture_description_field.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,28 @@ | ||
<%= f.input :description %> | ||
<div class="input"> | ||
<label class="inline-label" style="float: right"> | ||
<%= Alchemy::Language.model_name.human %> | ||
<%= select_tag :language_id, options_from_collection_for_select( | ||
Alchemy::Language.published, :id, ->(l) { l.code.upcase }, | ||
selected: @picture_description.language_id, | ||
), data: { | ||
url: alchemy.edit_admin_picture_description_url(id: "__ID__", picture_id: @picture) | ||
}, disabled: Alchemy::Language.count < 2 %> | ||
</label> | ||
|
||
<turbo-frame id="picture_descriptions"> | ||
<%= render "alchemy/admin/picture_descriptions/form", | ||
picture_description_counter: @picture.descriptions.index(@picture_description), | ||
picture_description: @picture_description %> | ||
</turbo-frame> | ||
</div> | ||
|
||
<script type="module"> | ||
const select = document.querySelector("#language_id") | ||
|
||
select.addEventListener("change", () => { | ||
const url = new URL(select.dataset.url) | ||
url.searchParams.set("language_id", select.value) | ||
console.log("url", url) | ||
Turbo.visit(url, { frame: "picture_descriptions" }) | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
db/migrate/20240314105244_create_alchemy_picture_descriptions.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class CreateAlchemyPictureDescriptions < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :alchemy_picture_descriptions do |t| | ||
t.belongs_to :picture, null: false, foreign_key: {to_table: :alchemy_pictures} | ||
t.belongs_to :language, null: false, foreign_key: {to_table: :alchemy_languages} | ||
t.text :text | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 0 additions & 5 deletions
5
spec/dummy/db/migrate/20240208101342_add_description_to_picture.rb
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
spec/dummy/db/migrate/20240411155901_create_alchemy_picture_descriptions.alchemy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# This migration comes from alchemy (originally 20240314105244) | ||
class CreateAlchemyPictureDescriptions < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :alchemy_picture_descriptions do |t| | ||
t.belongs_to :picture, null: false, foreign_key: {to_table: :alchemy_pictures} | ||
t.belongs_to :language, null: false, foreign_key: {to_table: :alchemy_languages} | ||
t.text :text | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.