Implement comments
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
{% block importmap %}{{ importmap('app') }}{% endblock %}
|
||||
{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
<body data-turbo="false">
|
||||
<nav class="navbar navbar-expand-lg bg-body-tertiary">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="{{ path('app_species_index') }}">Herbarium</a>
|
||||
|
4
templates/comment/_delete_form.html.twig
Normal file
4
templates/comment/_delete_form.html.twig
Normal file
@@ -0,0 +1,4 @@
|
||||
<form method="post" action="{{ path('app_post_comment_delete', {'id': comment.id}) }}" onsubmit="return confirm('Are you sure you want to delete this comment?');">
|
||||
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ comment.id) }}">
|
||||
<button class="btn btn-danger">Delete</button>
|
||||
</form>
|
17
templates/comment/comment.html.twig
Normal file
17
templates/comment/comment.html.twig
Normal file
@@ -0,0 +1,17 @@
|
||||
<turbo-frame id="comment_{{ comment.id }}">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">
|
||||
{{ comment.author.email }} le {{ comment.createdAt | date }}
|
||||
{% if comment.createdAt != comment.editedAt %}
|
||||
(modifié le {{ comment.editedAt | date }})
|
||||
{% endif %}
|
||||
</h5>
|
||||
<p class="card-text">{{ comment.content }}</p>
|
||||
{% if is_granted('COMMENT_EDIT', comment) %}
|
||||
<a href="{{ path('app_post_comment_edit', {'id': comment.id}) }}" class="btn btn-primary">Modifier</a>
|
||||
{{ include('comment/_delete_form.html.twig') }}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</turbo-frame>
|
3
templates/comment/deleted.stream.html.twig
Normal file
3
templates/comment/deleted.stream.html.twig
Normal file
@@ -0,0 +1,3 @@
|
||||
{% block success_stream %}
|
||||
<turbo-stream action="remove" target="comment_{{ comment }}"></turbo-stream>
|
||||
{% endblock %}
|
11
templates/comment/edit.html.twig
Normal file
11
templates/comment/edit.html.twig
Normal file
@@ -0,0 +1,11 @@
|
||||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block title %}Edit Comment{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<h1>Edit Comment</h1>
|
||||
|
||||
<turbo-frame id="comment_{{ comment.id }}">
|
||||
{{ include('post/_form.html.twig', {'button_label': 'Update'}) }}
|
||||
</turbo-frame>
|
||||
{% endblock %}
|
7
templates/comment/new.stream.html.twig
Normal file
7
templates/comment/new.stream.html.twig
Normal file
@@ -0,0 +1,7 @@
|
||||
{% block success_stream %}
|
||||
<turbo-stream action="append" targets="#comments">
|
||||
<template>
|
||||
{{ include('comment/comment.html.twig') }}
|
||||
</template>
|
||||
</turbo-stream>
|
||||
{% endblock %}
|
@@ -1,4 +1,4 @@
|
||||
{{ form_start(form) }}
|
||||
{{ form_widget(form) }}
|
||||
<button class="btn">{{ button_label|default('Save') }}</button>
|
||||
<button class="btn btn-primary">{{ button_label|default('Save') }}</button>
|
||||
{{ form_end(form) }}
|
||||
|
@@ -4,16 +4,16 @@
|
||||
|
||||
{% block body %}
|
||||
{% for post in posts.iterator %}
|
||||
<div class="card" style="width: 42rem; margin: 20px 0 50px 100px;">
|
||||
<div class="card mb-4">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">{{ post.species ? post.species.vernacularName : 'Post' }}</h5>
|
||||
<h5 class="card-title"><a href="{{ path('app_post_show', {id: post.id}) }}">{{ post.species ? post.species.vernacularName : 'Post' }}</a></h5>
|
||||
<h6 class="card-subtitle mb-2 text-muted">{{ post.foundDate | date("d/m/Y \\à H \\h") }}</h6>
|
||||
<p class="card-subtitle mb-2 text-muted">{{ post.latitude }}, {{ post.longitude }}, {{ post.altitude }}m</p>
|
||||
<p class="card-text">{{ post.commentary }}</p>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
28 ❤️
|
||||
128 💬
|
||||
{{ post.comments.count() }} 💬
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
@@ -43,4 +43,17 @@
|
||||
<a href="{{ path('app_post_edit', {'id': post.id}) }}">edit</a>
|
||||
|
||||
{{ include('post/_delete_form.html.twig') }}
|
||||
|
||||
<div data-turbo="true">
|
||||
<div id="comments">
|
||||
{% for comment in post.comments %}
|
||||
{{ include('/comment/comment.html.twig') }}
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
{{ form_start(form) }}
|
||||
{{ form_widget(form) }}
|
||||
<button type="submit" class="btn btn-primary">Comment</button>
|
||||
{{ form_end(form) }}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
Reference in New Issue
Block a user