diff --git a/app/templates/app/detail_materi.html b/app/templates/app/detail_materi.html index 46b34166304e97709ea025c364b3aef162832abf..8a0ae43f0a22f2525fc5fe5026cb4bad9002d0ab 100644 --- a/app/templates/app/detail_materi.html +++ b/app/templates/app/detail_materi.html @@ -185,30 +185,20 @@ <button class="dropdown-item btn-book" onclick="copyToClipboard('#url')">Bagikan Tautan</button> </div> </div> - <div class="buttons d-flex flex-row bd-highlight mb-1"> - <a href="{% url 'view-materi' materi_data.id %}" class="btn btn-link btn-book shadow-sm p-2 mr-2 bg-white rounded">Baca</a> - <a href="{% url 'download-materi' materi_data.id %}" class="btn btn-link btn-book shadow-sm p-2 mr-2 bg-white rounded">Unduh</a> - <button class="btn btn-link btn-book shadow-sm p-2 mr-2 bg-white rounded" onclick="CitateAPA('{{citationAPA}}')">Citate APA</button> - <div class="dropdown"> - <button class="btn dropdown-toggle btn-book shadow-sm p-2 mr-2 bg-white rounded" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> - Bagikan - </button> - <div class="dropdown-menu" aria-labelledby="dropdownMenuButton"> - <div class="fb-share-button" data-href="{% url 'detail-materi' materi_data.id %}" data-layout="button" data-size="small"> - <a target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fdigipus-staging-2.herokuapp.com%2Fmateri%2F{{materi_data.id}}%2F&src=sdkpreparse" class="dropdown-item fb-xfbml-parse-ignore">Facebook</a> - </div> - <a class="twitter-share-button dropdown-item" - href="https://twitter.com/intent/tweet?text=Cek%20materi%20ini%20yuk%20https%3A%2F%2Fdigipus-staging-2.herokuapp.com%2Fmateri%2F{{materi_data.id}}%2F" - target="_blank" - data-size="large"> - Twitter - </a> - <a class="dropdown-item" href="whatsapp://send?text=Cek materi ini yuk! https://digipus-staging-2.herokuapp.com{{request.path}}" target="_blank">Whatsapp</a> - <a class="dropdown-item" href="https://social-plugins.line.me/lineit/share?url=https%3A%2F%2Fdigipus-staging-2.herokuapp.com%2Fmateri%2F{{materi_data.id}}%2F" target="_blank">Line</a> - <p id="url" style="display: none">https://digipus-staging-2.herokuapp.com{{request.path}}</p> - <a class="dropdown-item" - href="{% url 'save-to-gdrive' materi_data.id %}">Google Drive</a> - <button class="dropdown-item btn-book" onclick="copyToClipboard('#url')">Bagikan Tautan</button> + <div class="dropdown"> + <button class="btn dropdown-toggle btn-book shadow-sm p-2 mr-2 bg-white rounded" type="button" + id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> + Sitasi + </button> + <div class="dropdown-menu" aria-labelledby="dropdownMenuButton"> + <div class="buttons"> + <button class="dropdown-item" onclick="getCitation('{{citationAPA}}')">Citate APA</button> + </div> + <div class="buttons"> + <button class="dropdown-item" onclick="getCitation('{{citationIEEE}}')">Citate IEEE</button> + </div> + </div> + </div> <form action="" method="POST"> <input type="hidden" name="action" value="like"> </form> @@ -466,9 +456,16 @@ $('#thumbIcon').removeClass("far fa-thumbs-up").addClass('fas fa-thumbs-up') document.getElementById("thumb").firstChild.data = " Disukai" } - function CitateAPA(text){ - alert('Hasil citasi : '+text); - } + } + + function getCitation(text){ + var $temp = $("<input>"); + $("body").append($temp); + $temp.val(text).select(); + document.execCommand("copy"); + $temp.remove(); + window.alert("Hasil sitasi: "+ text + "\n\nBerhasil disalin ke clipboard!"); + } </script> diff --git a/app/tests.py b/app/tests.py index fbdb1f1f00677c3adc3de78f2113c479df8b9c8d..69dc1d1ccca8fb6288215680807d03fa5d5c617f 100644 --- a/app/tests.py +++ b/app/tests.py @@ -277,6 +277,41 @@ class DetailMateriTest(TestCase): self.materi_with_published_date.publisher self.assertIn(expected, response.context["citationAPA"]) + + def test_citation_IEEE_button(self): + response = self.client.get(self.url) + self.assertContains(response, "Citate IEEE") + + def test_citation_IEEE_materi_has_no_published_date(self): + response = self.client.get(self.url) + current_date = datetime.now() + current_day = str(current_date.day) + current_month = current_date.strftime("%b") + current_year = str(current_date.year) + + expected = "Agas, " + \ + "Materi 1. " + \ + "Kelas SC, n.d. " + \ + "Accessed on: " + current_month + ". " + current_day + ", " + current_year + \ + ". [Online]. " + \ + "Available: http://testserver" + self.url + self.assertIn(expected, response.context["citationIEEE"]) + + def test_citation_IEEE_materi_has_published_date(self): + response = self.client.get(self.materi_with_published_date_url) + current_date = datetime.now() + current_day = str(current_date.day) + current_month = current_date.strftime("%b") + current_year = str(current_date.year) + published_date = self.materi_with_published_date.published_date.strftime('%Y') + + expected = "Agas, " + \ + "Materi 1. " + \ + "Kelas SC, " + published_date + ". " +\ + "Accessed on: " + current_month + ". " + current_day + ", " + current_year + \ + ". [Online]. " + \ + "Available: http://testserver" + self.materi_with_published_date_url + self.assertIn(expected, response.context["citationIEEE"]) def test_tombol_bagikan_google_drive(self): response = Client().get(self.url) diff --git a/app/views.py b/app/views.py index fcbc5e3092c673d6fd04e9cb211225a13216ea56..90ab4581fcbc9582420cf266ecb51a6e7c10c206 100644 --- a/app/views.py +++ b/app/views.py @@ -1,5 +1,6 @@ import mimetypes import os +import datetime from django.conf import settings from django.contrib import messages @@ -137,6 +138,7 @@ class DetailMateri(TemplateView): publishedDate = materi.published_date.strftime('%Y-%m-%d %H:%M') citationAPA = materi.author+' . (' + publishedDate +') . ' + materi.title +' . '+materi.publisher context["citationAPA"] = citationAPA + context["citationIEEE"] = get_citation_ieee(self.request, materi) context['materi_rating_score'] = 0 if self.request.user.is_authenticated: @@ -209,6 +211,37 @@ def delete_comment(request, pk_materi, pk_comment): comment.delete() return HttpResponseRedirect(url) +def get_citation_ieee(request, materi): + current_date = datetime.datetime.now() + current_day = str(current_date.day) + current_month = current_date.strftime("%b") + current_year = str(current_date.year) + published_date = "" + if(materi.published_date == None): + published_date = "n.d" + else : + published_date = materi.published_date.strftime('%Y') + + author_list = materi.author.split(",") + author_list_abbrv = "" + for author_name in author_list: + author_name_split = author_name.split(" ") + author_name_abbrv = "" + for j, name in enumerate(author_name_split): + if j < (len(author_name_split)-1): + abbrv_name = name[0].upper() + author_name_abbrv = author_name_abbrv + abbrv_name + ". " + else: + author_name_abbrv = author_name_abbrv + name + author_list_abbrv = author_list_abbrv + author_name_abbrv + ", " + + citation_result = author_list_abbrv + \ + materi.title + ". " + \ + materi.publisher + ", " + published_date + ". " + \ + "Accessed on: " + current_month + ". " + current_day + ", " + current_year + \ + ". [Online]. " + \ + "Available: " + request.build_absolute_uri() + return citation_result def add_rating_materi(request): if request.method == 'POST' and request.user.is_authenticated: