Commit c0179cf4 authored by Klaus Stein's avatar Klaus Stein
Browse files

Creating contacts works somehow

parent cb18cbd5
......@@ -8,11 +8,16 @@ class CommentsController < ApplicationController
# GET /comments/1 or /comments/1.json
def show
@parent = @comment.commentable
end
# GET /comments/new
def new
if map_id = params[:map_id] and map = Map.find(map_id)
@parent = map
end
@comment = Comment.new
@comments = @parent&.comments || Comment.all
end
# GET /comments/1/edit
......@@ -22,16 +27,26 @@ class CommentsController < ApplicationController
# POST /comments or /comments.json
def create
@comment = Comment.new(comment_params)
@comment.user = current_user
respond_to do |format|
if @comment.save
format.html { redirect_to @comment, notice: "Comment was successfully created." }
format.json { render :show, status: :created, location: @comment }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @comment.errors, status: :unprocessable_entity }
end
puts '################################################'
puts "map_id: #{params[:map_id]}"
if map_id = params[:map_id] and @parent = Map.find(map_id)
@comment.commentable = @parent
end
@comments = @parent&.comments || Comment.all
@comment.save
# respond_to do |format|
# if @comment.save
# format.html { redirect_to @comment, notice: "Comment was successfully created." }
# format.json { render :show, status: :created, location: @comment }
# else
# format.html { render :new, status: :unprocessable_entity }
# format.json { render json: @comment.errors, status: :unprocessable_entity #}
# end
# end
end
# PATCH/PUT /comments/1 or /comments/1.json
......
......@@ -99,10 +99,31 @@ main.show.map {
}
}
}
td.comment {
font-style: italic;
}
.comments {
border: 1px solid #baa;
border-radius: 1rem;
overflow: hidden;
summary {
background: #baa;
padding: 1rem;
}
.body {
padding: 1rem;
}
.field.auto-filled { display: none; }
.field textarea {
width: 100%;
margin-bottom: 1rem;
}
.comment {
p {
font-style: italic;
}
}
}
}
form.map {
......
<section id="<%= dom_id(comment) %>" class="comment" data-stream-enter-class="animate-item-in" data-stream-exit-class="animate-item-out">
<header>
<span class="user"><%= comment.user.username %></span>
<span class="date"><%= comment.updated_at %></span>
</header>
<p><%= comment.text %></p>
</section>
<span data-stream-enter-class="animate-item-in" data-stream-exit-class="animate-item-out"><%= pluralize(comments.count, 'comments') %></span>
<%= turbo_frame_tag comment do %>
<%= form_with(model: comment) do |form| %>
<%= form_with(model: comment.new_record? ? [parent, comment] : comment) do |form| %>
<% if comment.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(comment.errors.count, "error") %> prohibited this comment from being saved:</h2>
......@@ -11,22 +11,25 @@
</ul>
</div>
<% end %>
<div class="field">
<%= form.label :text %>
<%= form.text_area :text %>
</div>
<div class="field">
<div class="field auto-filled">
<%= form.label :user_id %>
<%= form.text_field :user_id %>
</div>
<div class="field">
<div class="field auto-filled">
<%= form.label :commentable_id %>
<%= form.text_field :commentable_id %>
</div>
<div class="field auto-filled">
<%= form.label :commentable_type %>
<%= form.text_field :commentable_type %>
</div>
<div class="actions">
<%= form.submit %>
</div>
......
<section id="comments-list">
<% comments.each do |comment| %>
<%= render 'comments/comment', comment: comment %>
<% end %>
</section>
<%= turbo_stream.prepend("comments-list", partial: "comments/comment", locals: { comment: @comment }) %>
<%= turbo_stream.update("comments-count", partial: "comments/count", locals: { comments: @comments }) %>
<%= turbo_stream.update("new_comment", partial: "comments/form", locals: { comment: Comment.new, parent: @parent }) %>
......@@ -33,6 +33,15 @@
<%= turbo_frame_tag :new_comment do %>
<div>
<%= link_to "new comment", new_comment_path %>
<%= link_to "new comment", new_polymorphic_path([@parent]) %>
<br>
<%= link_to "new comment",
case @parent
when Map
new_map_comment_path(@parent)
else
new_comment_path
end
%>
</div>
<% end %>
......@@ -45,12 +45,18 @@
</figure>
<% end %>
</div>
<details open="open" class="comments">
<summary id="comments-count"><%= render 'comments/count',comments: @map.comments %></summary>
<div class="body">
<% if current_user %>
<%= render 'comments/form', comment: Comment.new, parent: @map %>
<% end %>
<hr />
<%= render 'comments/list', comments: @map.comments.order(updated_at: :desc) %>
</div>
</details>
<% if @map.comments.any? %>
<details>
<summary></summary>
</details>
<% end %>
<table class="data">
<% @map.itemdates.each do |itemdate| %>
<tr><th>Date:</th><td><%= itemdate.edtfdate.edtf %> (<%= itemdate.description %>)</td></tr>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment