Fakultas Ilmu Komputer UI

Commit 0d663715 authored by MUHAMMAD EZRA RIZKIATAMA PUTRA's avatar MUHAMMAD EZRA RIZKIATAMA PUTRA
Browse files

[GREEN] Implemented Like Count on Detail Materi page

parent 3c3be705
Pipeline #60009 passed with stages
in 27 minutes and 36 seconds
......@@ -33,7 +33,6 @@ div.review {
<!-- Topbar Navbar -->
<ul class="navbar-nav ml-auto">
{% if request.user.is_contributor %}
{% if materi_data.status == "DISAPPROVE" %}
<li class="nav-item black-text">
......@@ -164,6 +163,14 @@ div.review {
<p class="info-content">{{materi_data.content.size|filesizeformat}}</p>
</dd>
</div>
<div class="info" id="1">
<dl class="col col-4">
<dt class="info-name">Jumlah Like</dt>
</dl>
<dd>
<p class="info-content">{{materi_data.like_count}}</p>
</dd>
</div>
<div class="info" id="1">
<dl class="col col-4">
<dt class="info-name">Jumlah Download</dt>
......@@ -225,11 +232,11 @@ div.review {
<input type="hidden" name="action" value="like">
</form>
{% if has_liked %}
<button id="thumb" class="btn btn-link btn-book shadow-sm p-2 mr-2 bg-white rounded"><i id="thumbIcon"
aria-hidden="true" class="fas fa-thumbs-up"></i> Disukai</button>
<button id="thumb" class="btn btn-link btn-book shadow-sm p-2 mr-2 bg-white rounded" onClick="postLike()"><i id="thumbIcon"
aria-hidden="true" class="fas fa-thumbs-up"></i><span> Disukai</span></button>
{% else %}
<button id="thumb" class="btn btn-link btn-book shadow-sm p-2 mr-2 bg-white rounded"><i id="thumbIcon"
aria-hidden="true" class="far fa-thumbs-up"></i> Sukai</button>
<button id="thumb" class="btn btn-link btn-book shadow-sm p-2 mr-2 bg-white rounded" onClick="postLike()"><i id="thumbIcon"
aria-hidden="true" class="far fa-thumbs-up"></i><span> Sukai</span></button>
{% endif %}
{% if user.is_authenticated %}
......@@ -331,7 +338,7 @@ div.review {
<div>
<button id="thumb-like-comment-{{ comment.id }}" class="btn btn-link btn-book shadow-sm p-2 mr-2 bg-white rounded" onClick="postLikeComment({{ comment.id }})">
<div class="d-flex flex-row">
{% if has_liked.comment.id %}
{% if has_liked_comment.comment.id %}
<i id="thumb-like-comment-icon-{{ comment.id }}" aria-hidden="true" class="fas fa-thumbs-up"></i>
{% else %}
<i id="thumb-like-comment-icon-{{ comment.id }}" aria-hidden="true" class="far fa-thumbs-up"></i>
......@@ -341,7 +348,7 @@ div.review {
</button>
<button id="thumb-dislike-comment-{{ comment.id }}" class="btn btn-link btn-book shadow-sm p-2 mr-2 bg-white rounded" onClick="postDislikeComment({{ comment.id }})">
<div class="d-flex flex-row">
{% if has_disliked.comment.id %}
{% if has_disliked_comment.comment.id %}
<i id="thumb-dislike-comment-icon-{{ comment.id }}" aria-hidden="true" class="fas fa-thumbs-down"></i>
{% else %}
<i id="thumb-dislike-comment-icon-{{ comment.id }}" aria-hidden="true" class="far fa-thumbs-down"></i>
......@@ -509,8 +516,7 @@ div.review {
}
</script>
<script>
$('#thumb').click(function () {
function postLike() {
$.ajaxSetup({
beforeSend: function (xhr, settings) {
if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
......@@ -528,7 +534,7 @@ div.review {
success: LikePost,
dataType: 'html'
});
});
}
function postLikeComment(comment_id) {
$.ajaxSetup({
......@@ -599,12 +605,15 @@ div.review {
function LikePost(data, jqXHR) {
var data = $.parseJSON(data)
var likeCount = parseInt($('.info-content')[6].textContent)
if (data['liked']) {
$('#thumbIcon').removeClass("fas fa-thumbs-up").addClass('far fa-thumbs-up')
document.getElementById("thumb").firstChild.data = " Sukai"
$('#thumb>span').text(" Sukai")
$('.info-content')[6].textContent = likeCount - 1
} else {
$('#thumbIcon').removeClass("far fa-thumbs-up").addClass('fas fa-thumbs-up')
document.getElementById("thumb").firstChild.data = " Disukai"
$('#thumb>span').text(" Disukai")
$('.info-content')[6].textContent = likeCount + 1
}
}
......
......@@ -134,8 +134,8 @@ class DetailMateri(TemplateView):
has_disliked, has_liked = DetailMateriService.find_comment_like_dislike(query_set_for_comment, self.request.session)
context["comment_data"] = query_set_for_comment
context["review_data"] = query_set_for_review
context["has_liked"] = has_liked
context["has_disliked"] = has_disliked
context["has_liked_comment"] = has_liked
context["has_disliked_comment"] = has_disliked
return self.render_to_response(context=context)
......
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