Selaa lähdekoodia

Amélioration de la gestion des commentaires

omassot 7 vuotta sitten
vanhempi
commit
bc03d5f0ea

+ 1 - 0
backlog/settings.py

@@ -37,6 +37,7 @@ INSTALLED_APPS = [
     'django.contrib.messages',
     'django.contrib.staticfiles',
     'martor',
+    'widget_tweaks',
 ]
 
 MIDDLEWARE = [

+ 0 - 1
main/static/js/custom.js

@@ -73,5 +73,4 @@ $(document).ready( function () {
 		}
 	});
 	
-	
 });

+ 16 - 48
main/templates/_comment_div.html

@@ -3,14 +3,16 @@
 
 {% load martortags %}
 
-<div class="comment-section" data-obj-uuid="{{ obj.uuid }}">
+<div class="comment-section">
 	<ul class="comment-list">
-	{% for comment in obj.comments.all %}
+	{% for comment in obj.comments %}
 		<li class="comment flex-col" data-id="{{ comment.id }}">
 			<div class="flex-row">
 				<span class="comment-header"><i class="fa fa-comment"></i> {{ comment.author }}, le {{ comment.created }}</span>
-				<a class="disabled comment-edit-btn" href="" style="margin-left: 20px;"><i class="fa fa-pencil"></i></a>
-				<a class="disabled comment-del-btn" href="" style="margin-left: 10px;"><i class="fa fa-trash"></i></a>
+				{% if comment.author.id == request.user.id %}
+				    <a class="disabled comment-edit-btn" href="" style="margin-left: 20px;"><i class="fa fa-pencil"></i></a>
+					<a class="comment-del-btn" href="{% url 'comment_del' comment_id=comment.id %}" style="margin-left: 10px;"><i class="fa fa-trash"></i></a>
+				{% endif %}
 			</div>
 			<div class="comment-display">
 				{{ comment.content|safe_markdown }}
@@ -19,9 +21,10 @@
 	{% endfor %}
 	</ul>
 	
-	<form action="{% url 'comment_post' obj_uuid=obj.uuid %}" method="post" accept-charset="utf-8">
+	<form action="{% url 'comment_post' obj_uuid=obj.uuid %}" method="post" accept-charset="utf-8" enctype="multipart/form-data">
 		{% csrf_token %}
-		{{ comment_form.content }}
+		
+		{{ comment_form.as_p }}
 		
     	<div class="flex-row flex-end" style="margin-top: 10px;">
     		<input type="submit">
@@ -30,45 +33,10 @@
     
 </div>
 
-<!-- <script>
-	
-	// Nouveau commentaire
-    $(".comment-section input[type=submit]").click(function (event) {
-    	event.preventDefault();
-    	
-    	var section = $(this).closest(".comment-section");
-    	var form = section.find("form");
-     	var obj_uuid = section.data("obj-uuid");
-     	var csrf_token= form.find("input[name=csrfmiddlewaretoken]").attr('value');
-     	var target = form.attr('action');
-
-     	var content = form.find("textarea").val();
-        if (!content) {
-            return;
-        }
-        
-        $.ajax({
-            type: "POST",
-            url: target,
-            headers: {"X-CSRFToken": csrf_token},
-            data: '{"content": ' + JSON.stringify(content) + '}',
-            contentType: "application/json; charset=utf-8",
-            dataType: "json",
-            success: function (comment) {
-            	form.find("textarea").val("");
-            	location.reload();
-            },
-            failure: function (response) {
-            	// restore the default behavior
-                console.log(response.responseText);
-            	alert("An error occured (see the console for more informations)");
-            },
-            error: function (response) {
-            	// restore the default behavior
-            	console.log(response.responseText);
-            	alert("An error occured (see the console for more informations)");
-            }
-        });
-    });
-	
-</script> -->
+<script>
+	$(".comment-del-btn").click(function (event) {
+		if (confirm('Êtes vous sûr de vouloir supprimer le commentaire?')) {
+			return true;
+		}
+	});
+</script>

+ 23 - 23
main/templates/reports/report_index.html

@@ -1,24 +1,24 @@
-{% extends '_layout.html' %}
-
-{% block title %}
-	Index des rapports
-{% endblock %}
-
-{% block breadcrumb %}
-	<li><a href="{% url 'index' %}">Accueil</a></li>
-	<li><a>Rapports</a></li>
-{% endblock %}
-
-{% block main %}
-
-	<header style="margin-bottom: 25px;">
-		<h2>Rapports</h2>
-	</header>
-
-	<ul>
-		<li><a href="{% url 'report_sprints' %}">Historique des sprints</a></li>
-		<li><a href="{% url 'report_projects' %}">Revue de projets</a></li>
-	</ul>
-
-
+{% extends '_layout.html' %}
+
+{% block title %}
+	Index des rapports
+{% endblock %}
+
+{% block breadcrumb %}
+	<li><a href="{% url 'index' %}">Accueil</a></li>
+	<li><a>Rapports</a></li>
+{% endblock %}
+
+{% block main %}
+
+	<header style="margin-bottom: 25px;">
+		<h2>Rapports</h2>
+	</header>
+
+	<ul>
+		<li><a href="{% url 'report_sprints' %}">Historique des sprints</a></li>
+		<li><a href="{% url 'report_projects' %}">Revue de projets</a></li>
+	</ul>
+
+
 {% endblock %}

+ 95 - 51
main/templates/reports/report_projects.html

@@ -1,52 +1,96 @@
-{% extends '_layout.html' %}
-
-{% block title %}
-	Rapport: Projets
-{% endblock %}
-
-{% block breadcrumb %}
-	<li><a href="{% url 'index' %}">Accueil</a></li>
-	<li><a href="{% url 'reports' %}">Rapports</a></li>
-	<li><a>Revue de Projets</a></li>
-{% endblock %}
-
-{% block main %}
-{% load martortags %}
-
-<section id="backlog">
-	<header>
-		<div class="flex-row" style="margin-bottom: 20px;">
-			<h2 class="flex-extend">Revue de Projets</h2>
-		</div>
-	</header>
-	
-	<ul class="alt">
-	{% for epic in epics %}
-		<li class="epic-li">
-			<div class="flex-col" style="margin-bottom: 20px;">
-			
-				<div class="flex-row">
-					<h4>{{ epic.name }}</h4>
-				</div>
-				
-				<div style="margin-bottom: 20px;">
-					<div>Contributeurs: {{ epic.contributors }}</div>
-					<div>Stories (Total / En cours / Terminées): 
-					{{ epic.nb_stories }} / 
-					<span class="valid">{{ epic.nb_active_stories }}</span> / 
-					<span class="disabled">{{ epic.nb_closed_stories }}</span></div>
-				</div>
-				
-				{% if epic.description %}
-				<div style="padding: 0 20px;">
-					{{ epic.description|safe_markdown }}
-				</div>
-				{% endif %}
-				
-			</div>
-		</li>
-	{% endfor %}
-	</ul>
-	
-</section>
+{% extends '_layout.html' %}
+
+{% block title %}
+	Rapport: Projets
+{% endblock %}
+
+{% block breadcrumb %}
+	<li><a href="{% url 'index' %}">Accueil</a></li>
+	<li><a href="{% url 'reports' %}">Rapports</a></li>
+	<li><a>Revue de Projets</a></li>
+{% endblock %}
+
+{% block main %}
+{% load martortags %}
+
+<section id="backlog">
+	<header>
+		<div class="flex-row" style="margin-bottom: 20px;">
+			<h2 class="flex-extend">Revue de Projets</h2>
+		</div>
+	</header>
+
+	<canvas id="chart-activity" width="400" height="120"></canvas>
+	
+	<ul class="alt">
+	{% for epic in epics %}
+		<li class="epic-li">
+			<div class="flex-col" style="margin-bottom: 20px;">
+			
+				<div class="flex-row">
+					<h4>{{ epic.name }}</h4>
+				</div>
+				
+				<div style="margin-bottom: 20px;">
+					<div>Contributeurs: {{ epic.contributors }}</div>
+					<div>Stories (Total / En cours / Terminées): 
+					{{ epic.nb_stories }} / 
+					<span class="valid">{{ epic.nb_active_stories }}</span> / 
+					<span class="disabled">{{ epic.nb_closed_stories }}</span></div>
+				</div>
+				
+				{% if epic.description %}
+				<div style="padding: 0 20px;">
+					{{ epic.description|safe_markdown }}
+				</div>
+				{% endif %}
+				
+			</div>
+		</li>
+	{% endfor %}
+	</ul>
+	
+</section>
+
+<script>
+var ctx = document.getElementById("chart-activity").getContext('2d');
+var myChart = new Chart(ctx, {
+	type: 'line',
+    data: {
+        labels: [{% for epic in epics|dictsort:"id" %}{% if not forloop.last %}"Sprint #{{ sprint.id }}",{% endif %}{% endfor %}],
+        datasets: [{
+            label: 'Vélocité réelle',
+            data: [{% for sprint in sprints|dictsort:"id" %}{% if not forloop.last %}{{ sprint.real_velocity }},{% endif %}{% endfor %}],
+            backgroundColor: [
+            	'rgba(255, 255, 255, 0.2)'
+            ],
+            borderColor: [
+                'rgba(0,150,0,1)',
+            ],
+            borderWidth: 1
+        },
+        {
+            label: 'Vélocité prévue',
+            data: [{% for sprint in sprints|dictsort:"id" %}{% if not forloop.last %}{{ sprint.planned_velocity }},{% endif %}{% endfor %}],
+            backgroundColor: [
+                'rgba(255, 255, 255, 0.2)'
+            ],
+            borderColor: [
+            	'rgba(0,0,150,1)',
+            ],
+            borderWidth: 1
+        }]
+    },
+    options: {
+        scales: {
+            yAxes: [{
+                ticks: {
+                    beginAtZero:true
+                }
+            }]
+        }
+    }
+});
+</script>
+
 {% endblock %}

+ 1 - 2
main/urls.py

@@ -34,7 +34,6 @@ urlpatterns = [
     path('reports/sprints/', views.report_sprints, name='report_sprints'),
     path('reports/projects/', views.report_projects, name='report_projects'),
     path('comment-post/<obj_uuid>/', views.comment_post, name='comment_post'),
-#     path('comment-edit/<int:comment_id>/', views.comment_edit, name='comment_edit'),
-#     path('comment-del/<int:comment_id>/', views.comment_del, name='comment_del'),
+    path('comment-del/<int:comment_id>/', views.comment_del, name='comment_del'),
     path('search/', views.search, name='search'),
 ]

+ 7 - 25
main/views.py

@@ -100,8 +100,7 @@ def story_index(request):
 @login_required
 def story_details(request, story_id):
     story = get_object_or_404(Story, id=story_id)
-    comment_form = CommentForm()
-    return render(request, 'story_details.html', {'story': story, 'comment_form': comment_form})
+    return render(request, 'story_details.html', {'story': story, 'comment_form': CommentForm()})
 
 @login_required
 def story_create(request, epic_id=None):
@@ -163,8 +162,7 @@ def story_reopen(request, story_id):
 @login_required
 def epic_details(request, epic_id):
     epic = get_object_or_404(Epic, id=epic_id)
-    comment_form = CommentForm()
-    return render(request, 'epic_details.html', {'epic': epic, 'comment_form': comment_form})
+    return render(request, 'epic_details.html', {'epic': epic, 'comment_form': CommentForm()})
 
 @login_required
 def epic_create(request):
@@ -255,27 +253,11 @@ def comment_post(request, obj_uuid):
     comment.save()
     return redirect(request.META['HTTP_REFERER'])
 
-# @login_required
-# def comment_post(request, obj_uuid):
-#     data = json.loads(request.body.decode('utf-8'))
-#     comment = Comment()
-#     comment.obj_uuid = obj_uuid
-#     comment.author = get_object_or_404(User, username=request.user)
-#     comment.content = data["content"]
-#     comment.save()
-#     return HttpResponse(comment.to_json(),content_type="application/json")
-# 
-# def comment_edit(request, comment_id):
-#     data = json.loads(request.body.decode('utf-8'))
-#     comment = get_object_or_404(Comment, id=comment_id)
-#     comment.content= data["content"]
-#     comment.save()
-#     return HttpResponse(comment.to_json(),content_type="application/json")
-# 
-# def comment_del(_, comment_id):
-#     comment = get_object_or_404(Comment, id=comment_id)
-#     comment.delete()
-#     return HttpResponse("{}",content_type="application/json")
+@login_required
+def comment_del(request, comment_id):
+    comment = get_object_or_404(Comment, id=comment_id)
+    comment.delete()
+    return redirect(request.META['HTTP_REFERER'])
 
 @login_required
 def search(request):

+ 2 - 1
requirements.txt

@@ -2,4 +2,5 @@ psycopg2
 Django
 martor
 path.py>=11.1.0
-mod_wsgi
+mod_wsgi
+django-widget-tweaks