Fakultas Ilmu Komputer UI

detail_materi.html 21.1 KB
Newer Older
1
{% extends 'base.html' %}
2
{% load static %} {% load humanize %}
3
4

{% block header %}
5
<link href="{% static 'css/sb-admin-2.min.css' %}" rel="stylesheet">
6
<link rel="stylesheet" type="text/css" href="{% static 'app/css/detail_materi.css' %}">
7
<link href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,400;0,500;1,100&display=swap" rel="stylesheet">
8
9
<script async defer crossorigin="anonymous"
    src="https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v6.0"></script>
10
<script src="{% static 'js/detail_materi.js'%}"></script>
11
12
13
{% endblock header %}

{% block title %}
14
{{materi_data.title}} | Digipus
15
{% endblock title %}
16
17

{% block content %}
18
19
20
21
{% block verification %} {% endblock verification %}
<div id="fb-root"></div>
<div class="container-fluid p-0 bg detail-materi-color">
    <nav class="navbar navbar-expand navbar-light bg-white topbar mb-4 static-top shadow">
22

23
24
        <!-- Sidebar Toggle (Topbar) -->
        <button id="sidebarToggleTop" class="btn btn-link d-md-none rounded-circle mr-3">
25
            <i class="fa fa-bars" aria-hidden="true"></i>
26
        </button>
27

28
        <div class="sidebar-brand-text mx-3">Diskominfo Kota Depok</div>
29

30
31
        <!-- Topbar Navbar -->
        <ul class="navbar-nav ml-auto">
32

33
            {% if request.user.is_contributor %}
34
35
36
37
38
39
40
41
42
            {% if materi_data.status == "DISAPPROVE" %}
            <li class="nav-item black-text">
                <a class="nav-link feedback" data-toggle="modal" data-target="#umpanBalikModal">
                    <span class="mr-2 d-none d-lg-inline text-gray-600 small">Umpan Balik Materi</span>
                </a>
                <div class="modal fade" id="umpanBalikModal" tabindex="-1" role="dialog"
                    aria-labelledby="exampleModalLabel" aria-hidden="true">
                    <div class="modal-dialog" role="document">
                        <div class="modal-content">
43
                            <div class="modal-header">
44
45
46
47
                                <h5 class="modal-title black-text" id="exampleModalLabel">Umpan Balik Materi</h5>
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                    <span aria-hidden="true">&times;</span>
                                </button>
48
49
                            </div>
                            <div class="modal-body">
50
                                {% for item in report %}
51
52
                                <p class="black-text">Alasan materi ditolak:</p>
                                <p class="black-text">{{ item.report.feedback }}</p>
53
54
55
                                <p class="black-text">Untuk merevisi materi, sila tekan tombol revisi di halaman riwayat
                                    unggah.</p>
                                {% endfor %}
56
57
                            </div>
                            <div class="modal-footer">
58
                                <button type="button" class="btn btn-danger" data-dismiss="modal">Tutup</button>
59
60
                            </div>
                        </div>
61
62
63
64
                    </div>
                </div>
            </li>
            {% endif %}
65
66
            {% endif %}

67
68
69
70
            <li class="nav-item">
                <a class="nav-link" href="/">
                    <span class="mr-2 d-none d-lg-inline text-gray-600 small">Halaman Katalog</span>
                </a>
71
72
            </li>

73
74
75
76
77
78
79
80
            {% if request.user.is_contributor %}
            <li class="nav-item">
                <a class="nav-link" href="/dashboard/">
                    <span class="mr-2 d-none d-lg-inline text-gray-600 small">Dasbor</span>
                </a>
            </li>
            {% endif %}

81
82
83
            <div class="topbar-divider d-none d-sm-block"></div>

            <!-- Nav Item - User Information -->
84
            {% if request.user.is_authenticated %}
85
            <li class="nav-item dropdown no-arrow">
86
87
88
89
90
91
92
93
94
95
                <a class="nav-link dropdown-toggle" href="/dashboard/">
                    <span class="mr-2 d-none d-lg-inline text-gray-600 small">{{ user.name }}</span>
                    {% if not user.default_profile_picture %}
                    <img class="img-profile rounded-circle" src="https://i.ibb.co/9wgPzyZ/default-image.png"
                        alt="User profile picture">
                    {% else %}
                    <img class="img-profile rounded-circle" src="{{ user.profile_picture.url }}"
                        alt="User profile picture">
                    {% endif %}
                </a>
96
            </li>
97
            {% endif %}
98

99
        </ul>
100

101
102
103
104
105
106
107
108
109
110
111
    </nav>
    <div class="row materi-data mr-4 ml-4 p-3 shadow-sm rounded">
        <div class="col col-3 cover">
            <img src={{materi_data.cover.url}} alt="cover">
        </div>
        <div class="col col-6 ml-3 book">
            <h2>{{materi_data.title}}</h2>
            <div class="category-wrapper">
                {% for category in materi_data.categories.all %}
                <span class="mr-1">#{{category.name}}</span>
                {% endfor %}
112
            </div>
113
114
115
116
117
118
119
120
            <div class="info-wrapper">
                <div class="info" id="1">
                    <dl class="col col-4">
                        <dt class="info-name">Penulis</dt>
                    </dl>
                    <dd>
                        <p class="info-content">{{materi_data.author}}</p>
                    </dd>
121
                </div>
122
123
124
125
126
127
128
                <div class="info" id="1">
                    <dl class="col col-4">
                        <dt class="info-name">Penerbit</dt>
                    </dl>
                    <dd>
                        <p class="info-content">{{materi_data.publisher}}</p>
                    </dd>
129
                </div>
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
                <div class="info" id="1">
                    <dl class="col col-4">
                        <dt class="info-name">Kontributor</dt>
                    </dl>
                    <dd>
                        <a class="info-content"
                            href="{% url 'katalog-per-kontributor' materi_data.uploader.email %}">{{materi_data.uploader.name}}</a>
                    </dd>
                </div>
                <div class="info" id="1">
                    <dl class="col col-4">
                        <dt class="info-name">Jumlah Halaman</dt>
                    </dl>
                    <dd>
                        <p class="info-content">{{materi_data.pages}}</p>
                    </dd>
                </div>
                <div class="info" id="1">
                    <dl class="col col-4">
                        <dt class="info-name">Ukuran File</dt>
                    </dl>
                    <dd>
                        <p class="info-content">{{materi_data.content.size|filesizeformat}}</p>
                    </dd>
                </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>
                <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&amp;src=sdkpreparse"
                                class="dropdown-item fb-xfbml-parse-ignore">Facebook</a>
172
                        </div>
173
174
175
176
177
178
179
180
181
182
183
184
                        <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>
185
186
                        <a class="dropdown-item"
                            href="{% url 'save-to-gdrive' materi_data.id %}">Google Drive</a>
187
                        <button class="dropdown-item btn-book" onclick="copyToClipboard('#url')">Bagikan Tautan</button>
188
189
                    </div>
                </div>
190
191
192
193
194
195
196
197
198
199
200
201
202
203
                <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>
204
205
206
207
208
209
210
211
212
213
                <form action="" method="POST">
                    <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>
                {% 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>
                {% endif %}
214

215
216
217
218
219
220
221
222
223
224
225
226
227
228
                {% if user.is_authenticated %}
                <div class="dropdown">
                    <button class="btn dropdown-toggle btn-book shadow-sm p-2 mr-2 bg-white rounded align-self-center"
                        type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                        <em id="button-rating-star-icon" class="align-self-center far fa-star"></em>
                        <span id="button-rating-text">Beri Rating</span>
                    </button>
                    <div id="star-dropdown" class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                        <div class="text-center btn-book">
                            <em onclick="postAddRating(1)" id="star-1" class="far fa-star fa-lg"></em>
                            <em onclick="postAddRating(2)" id="star-2" class="far fa-star fa-lg"></em>
                            <em onclick="postAddRating(3)" id="star-3" class="far fa-star fa-lg"></em>
                            <em onclick="postAddRating(4)" id="star-4" class="far fa-star fa-lg"></em>
                            <em onclick="postAddRating(5)" id="star-5" class="far fa-star fa-lg"></em>
229
230
231
                        </div>
                    </div>
                </div>
232
233
234
235
236
237
238
                {% else %}
                <button class="btn dropdown-toggle btn-book shadow-sm p-2 mr-2 bg-white rounded align-self-center"
                    type="button" id="dropdownMenuButton" aria-haspopup="true" aria-expanded="false" data-toggle="modal"
                    data-target="#notLoggedInModal">
                    <em class="align-self-center far fa-star"></em> Beri Rating
                </button>
                {% endif %}
239
240
            </div>
        </div>
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
    </div>
    <div class="row menu-wrapper mr-4 ml-4 p-3">
        <nav class="navbar navbar-expand-sm border-top border-bottom p-0 mt-3 mb-3">
            <ul class="navbar-nav">
                <li class="nav-item">
                    <a class="nav-link" href="#deskripsi">Deskripsi</a>
                </li>
                {% if materi_data.status == "APPROVE" %}
                <li class="nav-item">
                    <a class="nav-link" href="#komentar">Komentar</a>
                </li>
                {% endif %}
            </ul>
        </nav>
        <div id="deskripsi" class="container-fluid description-wrapper bg-white shadow-sm rounded p-3">
            <h1>Deskripsi</h1>
            <div class="col col-8 description">
                <p>{{materi_data.descriptions}}</p>
259
            </div>
260
261
262
        </div>
        {% if materi_data.status == "APPROVE" %}
        <div id="komentar" class="container-fluid comments-wrapper p-0">
263
            {% if is_authenticated %}
264
265
266
267
268
269
270
271
272
            <div class="add-comments col col-8 bg-white shadow-sm rounded p-3 mb-3">
                <form method="POST">
                    {% csrf_token %}
                    <h1>Komentar</h1>
                    <div class="form-group">
                        <textarea placeholder="Beri komentar..." class="form-control" id="exampleFormControlTextarea1"
                            rows="3" name="comment" required></textarea>
                        <button type="submit"
                            class="btn btn-link btn-book shadow-sm p-2 mt-2 bg-white rounded">Kirim</button>
273
                    </div>
274
275
                </form>
            </div>
276
277
278
            {% else %}
                <h3>Login terlebih dahulu untuk berkomentar</h3>
            {% endif %}
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
            {% for comment in comment_data %}
            <div class="col col-8 comment shadow-sm p-3 mb-1 bg-white rounded">
                <div class="d-flex bd-highlight mb-3 align-items-center user">
                    {% if comment.user != Null %}
                    {% if not user.default_profile_picture %}
                    <img class="profile" src="https://i.ibb.co/9wgPzyZ/default-image.png" alt="profile-picture">
                    {% else %}
                    <img class="profile" src="{{ comment.user.profile_picture.url }}" alt="profile-picture">
                    {% endif %}
                    {% else %}
                    <span style="background-color: #{{comment.profile}}" class="profile p-1 bd-highligh"></span>
                    {% endif %}
                    <p class="p-1 bd-highligh m-0"><b>{{comment.user.name}}</b></p>
                    <p class="p-1 bd-highligh m-0"></p>
                    <p class="timestamp p-1 bd-highligh m-0 text-muted">
                        {{ comment.timestamp|naturaltime }}
                    </p>
                    {% if user.is_admin %}
                    <a class="ml-auto p-1 bd-highlight close"
                        href="{% url 'delete-comment' materi_data.id comment.id %}">
                        <span aria-hidden="true">&times;</span>
                    </a>
                    {% endif %}
302
                </div>
303
304
305
                <p class="text">{{comment.comment}}</p>
            </div>
            {% endfor %}
306
        </div>
307
        {% endif %}
308
    </div>
309
310
311
312
</div>
<footer class="sticky-footer bg-white p-4">
    <div class="container my-auto">
        <div class="copyright text-center my-auto">
313
314
            <span>Copyright &copy; Diskominfo Kota Depok 2020</span>
        </div>
315
316
    </div>
</footer>
317

318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
<!-- Modal -->
<div class="modal fade" id="notLoggedInModal" tabindex="-1" role="dialog" aria-labelledby="notLoggedInModalLabel"
    aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="notLoggedInModalLabel">Belum Login</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                Login untuk memberikan rating
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Batal</button>
                <button type="button" class="btn btn-primary" onclick="window.location.href = '/login';">Login</button>
335
336
337
            </div>
        </div>
    </div>
338
</div>
339
{% endblock content %}
340
341
342
343
344
{% block extra_scripts %}
<script src="https://kit.fontawesome.com/bc2cedd6b2.js" crossorigin="anonymous"></script>
<script type="text/javascript">
    // using jQuery
    var csrftoken = jQuery("[name=csrfmiddlewaretoken]").val();
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371

    let currentRating = {{ materi_rating_score }};
    fillRatingStar(currentRating)

    function changeButtonIntoRated() {
        $('#button-rating-star-icon').addClass('fas');
        $('#button-rating-star-icon').removeClass('far');
        $('#button-rating-text').text("Rating Anda")
    }

    if (currentRating > 0) {
        changeButtonIntoRated()
    }

    $("#star-dropdown").click(function (e) {
        e.stopPropagation();
    });

    function clearRatingStar() {
        for (let i = 1; i <= 5; i++) {
            $('#star-' + i).addClass('far');
            $('#star-' + i).removeClass('fas');
        }
    }

    function fillRatingStar(ratingScore) {
        for (let i = 1; i <= ratingScore; i++) {
372
373
374
            $('#star-' + i).addClass('fas');
            $('#star-' + i).removeClass('far');
        }
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
    }

    function makeHoverStar(starAmount) {
        function hoverStar() {
            clearRatingStar()
            fillRatingStar(starAmount)
        }

        return hoverStar
    }

    function makeUnHoverStar(starAmount) {
        function unHoverStar() {
            clearRatingStar()
            fillRatingStar(currentRating)
        }

        return unHoverStar
    }

    $('#star-1').hover(makeHoverStar(1), makeUnHoverStar(1));
    $('#star-2').hover(makeHoverStar(2), makeUnHoverStar(2));
    $('#star-3').hover(makeHoverStar(3), makeUnHoverStar(3));
    $('#star-4').hover(makeHoverStar(4), makeUnHoverStar(4));
    $('#star-5').hover(makeHoverStar(5), makeUnHoverStar(5));
400
401
402
403
404
405
406
407
</script>
<script>
    function csrfSafeMethod(method) {
        // these HTTP methods do not require CSRF protection
        return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
    }
</script>
<script>
408
    $('#thumb').click(function () {
409

410
411
412
413
        $.ajaxSetup({
            beforeSend: function (xhr, settings) {
                if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
                    xhr.setRequestHeader("X-CSRFToken", csrftoken);
414
                }
415
            }
416
        });
417
418
419
420
421
422
423
424
425
426
427
        $.ajax({
            type: 'POST',
            url: "{% url 'PostLikeToggle' %}",
            data: {
                'materi_id': "{{ materi_data.id }}",
                'session_id': "{{ session_id }}"
            },
            success: LikePost,
            dataType: 'html'
        });
    });
428

429
430
431
432
433
    function postAddRating(rating_score) {
        $.ajaxSetup({
            beforeSend: function (xhr, settings) {
                if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
                    xhr.setRequestHeader("X-CSRFToken", csrftoken);
434
                }
435
            }
436
        });
437

438
439
440
441
442
443
444
445
446
447
448
449
        $.ajax({
            type: 'POST',
            url: "{% url 'rate-materi' %}",
            data: {
                'materi_id': "{{ materi_data.id }}",
                'rating_score': rating_score
            },
            success: function (data) {
                const response = JSON.parse(data)
                currentRating = response.rating_score
                makeUnHoverStar(currentRating)()
                changeButtonIntoRated()
450

451
452
453
454
            },
            dataType: 'html'
        });
    }
455

456
457
458
459
460
461
462
463
    function LikePost(data, jqXHR) {
        var data = $.parseJSON(data)
        if (data['liked']) {
            $('#thumbIcon').removeClass("fas fa-thumbs-up").addClass('far fa-thumbs-up')
            document.getElementById("thumb").firstChild.data = " Sukai"
        } else {
            $('#thumbIcon').removeClass("far fa-thumbs-up").addClass('fas fa-thumbs-up')
            document.getElementById("thumb").firstChild.data = " Disukai"
464
        }
465
466
467
468
469
470
471
472
473
474
    }
        
    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!");
    }
475
476

        
477
</script>
478
{% endblock extra_scripts %}