Skip to content
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
27 changes: 27 additions & 0 deletions app/javascript/controllers/parking_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
static targets = ["countInput"]

connect() {
this.updateInputState()
}

toggle(event) {
this.updateInputState()
}

updateInputState() {
const selected = this.element.querySelector("input[name='photo_spot[parking_flag]']:checked")
if (selected && selected.value === "1") {
this.countInputTarget.disabled = false
this.countInputTarget.classList.remove("bg-gray-200", "text-gray-500")
this.countInputTarget.classList.add("bg-white", "text-black")
} else {
this.countInputTarget.disabled = true
this.countInputTarget.value = ""
this.countInputTarget.classList.remove("bg-white", "text-black")
this.countInputTarget.classList.add("bg-gray-200", "text-gray-500")
}
}
}
23 changes: 20 additions & 3 deletions app/views/admin/photo_spots/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,26 @@
<%= form.label :tags, 'タグ(カンマ区切り)', class: 'block font-semibold mb-1' %>
<%= form.text_field :tags, class: "block shadow-sm rounded-md border px-3 py-2 w-full border-gray-300 focus:outline-blue-600" %>
</div>
<div>
<%= form.label :parking_flag, '駐車場の有無', class: 'block font-semibold mb-1' %>
<%= form.text_field :parking_flag, class: "block shadow-sm rounded-md border px-3 py-2 w-full border-gray-300 focus:outline-blue-600" %>
<div data-controller="parking">
<div class="flex gap-4 mb-2">
<label>
<%= form.radio_button :parking_flag, 1, data: { action: "change->parking#toggle" }, checked: form.object.parking_flag == 1 %> ある
</label>
<label>
<%= form.radio_button :parking_flag, 0, data: { action: "change->parking#toggle" }, checked: form.object.parking_flag == 0 %> ない
</label>
<label>
<%= form.radio_button :parking_flag, nil, data: { action: "change->parking#toggle" }, checked: form.object.parking_flag.nil? %> わからない
</label>
</div>
<div class="w-32">
<%= form.label :parking_count, '台数' %>
<%= form.number_field :parking_count,
min: 1,
data: { parking_target: "countInput" },
disabled: form.object.parking_flag != 1,
class: form.object.parking_flag == 1 ? "bg-white text-black border rounded px-2 py-1" : "bg-gray-200 text-gray-500 border rounded px-2 py-1" %>
</div>
</div>
<div>
<%= form.label :images, '画像(最大5枚・JPEG/PNG/GIF)', class: 'block font-semibold mb-1' %>
Expand Down
82 changes: 47 additions & 35 deletions app/views/admin/photo_spots/_photo_spot.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,45 +27,57 @@
<dd><%= photo_spot.tags %></dd>
<dt class="font-semibold">時間帯</dt>
<dd>
<%= photo_spot.timestart ? photo_spot.timestart.strftime("%H:%M") : "未設定" %> 〜
<%= photo_spot.timeend ? photo_spot.timeend.strftime("%H:%M") : "未設定" %>
<%= photo_spot.timestart ? photo_spot.timestart.strftime("%H:%M") : "未設定" %> 〜
<%= photo_spot.timeend ? photo_spot.timeend.strftime("%H:%M") : "未設定" %>
</dd>
<dt class="font-semibold">おすすめの季節</dt>
<dt class="font-semibold">駐車場</dt>
<dd>
<% case photo_spot.season %>
<% when 'spring' %>
<% when 'summer' %>
<% when 'autumn' %>
<% when 'winter' %>
<% else %>
未設定
<% end %>
</dd>
</dl>
</div>
<% if photo_spot.parking_flag == 1 %>
駐車場あり
<% if photo_spot.parking_count%>
:<%= photo_spot.parking_count %> 台
<% end %>
<% elsif photo_spot.parking_flag == 0 %>
駐車場なし
</div>
<% end %>
</dd>
<dt class="font-semibold">おすすめの季節</dt>
<dd>
<% case photo_spot.season %>
<% when 'spring' %>
<% when 'summer' %>
<% when 'autumn' %>
<% when 'winter' %>
<% else %>
未設定
<% end %>
</dd>
</dl>
</div>
<%# モーダルウィンドウのHTML部分 %>
<div data-image-modal-target="modal"
</div>
<%# モーダルウィンドウのHTML部分 %>
<div data-image-modal-target="modal"
class="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black bg-opacity-75 hidden">
<div class="relative w-full h-full max-w-5xl">
<div class="relative w-full h-full flex items-center justify-center">
<img data-image-modal-target="image" class="max-w-full max-h-screen object-contain" alt="Enlarged image">
<%# 閉じるボタン %>
<button data-action="click->image-modal#close" class="absolute top-4 right-4 text-white text-4xl">
&times;
</button>
<%# 左右の矢印ボタン %>
<button data-action="click->image-modal#previous" data-image-modal-target="prevBtn" class="absolute left-4 top-1/2 -translate-y-1/2 text-white text-5xl">
&lsaquo;
</button>
<button data-action="click->image-modal#next" data-image-modal-target="nextBtn" class="absolute right-4 top-1/2 -translate-y-1/2 text-white text-5xl">
&rsaquo;
</button>
</div>
<div class="relative w-full h-full max-w-5xl">
<div class="relative w-full h-full flex items-center justify-center">
<img data-image-modal-target="image" class="max-w-full max-h-screen object-contain" alt="Enlarged image">
<%# 閉じるボタン %>
<button data-action="click->image-modal#close" class="absolute top-4 right-4 text-white text-4xl">
&times;
</button>
<%# 左右の矢印ボタン %>
<button data-action="click->image-modal#previous" data-image-modal-target="prevBtn" class="absolute left-4 top-1/2 -translate-y-1/2 text-white text-5xl">
&lsaquo;
</button>
<button data-action="click->image-modal#next" data-image-modal-target="nextBtn" class="absolute right-4 top-1/2 -translate-y-1/2 text-white text-5xl">
&rsaquo;
</button>
</div>
</div>
</div>
</div>
12 changes: 5 additions & 7 deletions app/views/admin/photo_spots/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@
<% @photo_spots.each do |photo_spot| %>
<div class="flex flex-col md:flex-row justify-between items-center py-6 gap-4 w-full">
<div class="flex-1 min-w-0">
<%= render partial: 'photo_spot', locals: { photo_spot: photo_spot } %>
<!-- 画像サムネイル -->
<% if photo_spot.images.attached? %>
<div class="flex flex-wrap gap-2 mt-2">
<% photo_spot.images.each do |img| %><%= image_tag img.variant(resize_to_limit: [80,80]), class: "rounded shadow border w-20 h-20 object-cover", alt: photo_spot.name %>
<%= render partial: 'photo_spot', locals: { photo_spot: photo_spot } %>
<!-- 画像サムネイル -->
<% if photo_spot.images.attached? %>
<div class="flex flex-wrap gap-2 mt-2">
</div>
<% end %>
</div>
<% end %>
</div>
<div class="flex flex-col md:flex-row gap-2 w-full md:w-auto">
<%= link_to t('admin.photo_spots.index.show', default: '詳細'), admin_photo_spot_path(photo_spot), class: "rounded-md px-4 py-2 bg-gray-100 hover:bg-gray-200 text-gray-800 font-medium text-center w-full md:w-auto" %>
Expand Down
19 changes: 14 additions & 5 deletions app/views/photo_spots/_spot_card.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@
<div class="flex-1 min-w-0">
<h2 class="text-lg font-semibold mb-2 text-gray-900 truncate"><%= photo_spot.name %></h2>
<div class="text-sm text-gray-600 mb-2 line-clamp-2"><%= truncate(photo_spot.detail, length: 60) %></div>
<% if photo_spot.tags.present? %>
<div class="text-xs text-gray-500 mb-2">
<span class="font-medium">タグ:</span> <%= photo_spot.tags %>
</div>
<% end %>
<div class="flex items-center">
<% if photo_spot.reviews.any? %>
<%= render partial: "shared/rating_stars", locals: { rating: (photo_spot.reviews.average(:rating)&.round || 0) } %>
Expand All @@ -24,6 +19,20 @@
<span class="text-xs text-gray-400">未評価</span>
<% end %>
</div>
<% if photo_spot.tags.present? %>
<div class="text-xs text-gray-500 mb-2">
<span class="font-medium">タグ:</span> <%= photo_spot.tags %>
</div>
<% end %>
<% if photo_spot.parking_flag == 1 %>
<div class="text-xs text-gray-500 mb-2">
<span class="font-medium">駐車場あり</span>
</div>
<% elsif photo_spot.parking_flag == 0 %>
<div class="text-xs text-gray-500 mb-2">
<span class="font-medium">駐車場なし</span>
</div>
<% end %>
</div>
</div>
<% end %>
Loading