diff --git a/src/app/components/library/playlist.php b/src/app/components/library/playlist.php index 1e9f64e74925fed71245ea08a2a5389f7e1e938f..1f5c858f1f45840c9dc70e6e84f835ccc4c7384f 100644 --- a/src/app/components/library/playlist.php +++ b/src/app/components/library/playlist.php @@ -15,6 +15,6 @@ </div> <?php else : ?> <h5> - no results found. + you don't have any playlist. </h5> <?php endif;?> \ No newline at end of file diff --git a/src/app/components/playlist/playlist.php b/src/app/components/playlist/playlist.php index be04d8bcea14396ad6ab79b23fecdc167732ef36..a4dd9e9a1ddbb6704d86f52b378d9b9d672a8ff2 100644 --- a/src/app/components/playlist/playlist.php +++ b/src/app/components/playlist/playlist.php @@ -7,6 +7,8 @@ <link rel="stylesheet" type="text/css" href="<?= BASE_URL ?>/styles/globals.css"> <!-- Page-specific CSS --> <link rel="stylesheet" type="text/css" href="<?= BASE_URL ?>/styles/library/library.css"> + <script type="module" src="<?= BASE_URL ?>/javascript/library/library.js" defer> </script> + <title>Playlist</title> </head> <body> @@ -15,7 +17,7 @@ <main> - <div class="playlist-container"> + <div class="playlist-container" data-id="<?=$_GET["playlist_id"]?>"> <?php include(dirname(__DIR__) . "/playlist/playlist_content.php")?> </div> </main> diff --git a/src/app/components/playlist/playlist_content.php b/src/app/components/playlist/playlist_content.php index fb216c4ba37de95941bb3c829e69c30ff3fb0adb..375f8971528e2ef88758f125e0438ceadf455043 100644 --- a/src/app/components/playlist/playlist_content.php +++ b/src/app/components/playlist/playlist_content.php @@ -1,4 +1,5 @@ <link rel="stylesheet" type="text/css" href="<?= BASE_URL ?>/styles/library/library.css"> +<link href='https://unpkg.com/boxicons@2.1.4/css/boxicons.min.css' rel='stylesheet'> <?php if (!empty($this->data)): ?> <div class="user-playlist"> @@ -10,6 +11,7 @@ <div class="info"> <div class="sh5"><?=$podcast['title']?> </div> </div> + <i class='bx bx-trash' data-id="<?=$podcast["id_podcast"]?>"></i> </div> <?php endforeach; ?> </div> @@ -17,4 +19,6 @@ <h5> your playlist is empty. </h5> -<?php endif;?> \ No newline at end of file +<?php endif;?> + +<script type="module" src="<?= BASE_URL ?>/javascript/library/library.js" defer> </script> diff --git a/src/app/controllers/library/get_library.php b/src/app/controllers/library/get_library.php index 60363e8d741fdfd0a1be1940f788008038f3dc4d..466cbab67861b0b6ce3f27e2e0967f6cb9d87dfe 100644 --- a/src/app/controllers/library/get_library.php +++ b/src/app/controllers/library/get_library.php @@ -5,7 +5,6 @@ class GetLibraryController public function call() { require_once __DIR__ . "/../../views/library/library_view.php"; - require_once __DIR__ . "/../../models/playlist.php"; $data = []; session_start(); @@ -22,7 +21,7 @@ class GetLibraryController $view = new LibraryView($data); $view->render(); }else{ - header("Location: "); + header("Location: " . BASE_URL . "/login"); } } diff --git a/src/app/controllers/playlist/post_playlist.php b/src/app/controllers/playlist/post_playlist.php new file mode 100644 index 0000000000000000000000000000000000000000..fada90eac7ea0b386395aaa40ca9bbb6518341bb --- /dev/null +++ b/src/app/controllers/playlist/post_playlist.php @@ -0,0 +1,36 @@ +<?php + +class PostPlaylistController +{ + public function call() + { + + session_start(); + if(!isset($_SESSION["user_id"])){ + header("Location: " . BASE_URL . "/login"); + + return; + } + + $idPodcast = ""; + $idPlaylist = ""; + + if(isset($_POST["id_playlist"]) && isset($_POST["id_podcast"])){ + $idPlaylist = $_POST["id_playlist"]; + $idPodcast = $_POST["id_podcast"]; + } + + $model = new PlaylistModel(); + + try{ + $model->removePodcastFromPlaylist($idPodcast, $idPlaylist); + http_response_code(201); + exit; + }catch(PDOException $e){ + $e->getMessage(); + http_response_code(200); + exit; + } + + } +} diff --git a/src/app/core/app.php b/src/app/core/app.php index f9ae5cd6309ef3b8936187ba6eab4e3a7f5df84c..c4a2e71fc68d7ad7726534275048161852a57a64 100644 --- a/src/app/core/app.php +++ b/src/app/core/app.php @@ -41,6 +41,7 @@ class App $router->post("public/signup", new PostSignupController()); $router->get("public/library", new GetLibraryController()); $router->get("public/playlist", new GetPlaylistController()); + $router->post("public/playlist", new PostPlaylistController()); $router->directRequest($url); } diff --git a/src/app/init.php b/src/app/init.php index 7e17c3d2699de94ff7eec4a6b743b14fc846129d..7171820dc797013d307af8d60fcee095f5a9c83f 100644 --- a/src/app/init.php +++ b/src/app/init.php @@ -33,6 +33,7 @@ require_once __DIR__ . "/controllers/login/post_login.php"; require_once __DIR__ . "/controllers/library/get_library.php"; require_once __DIR__ . "/controllers/playlist/get_playlist.php"; +require_once __DIR__ . "/controllers/playlist/post_playlist.php"; require_once __DIR__ . "/controllers/library/get_library.php"; require_once __DIR__ . "/controllers/signup/get_signup.php"; require_once __DIR__ . "/controllers/signup/post_signup.php"; diff --git a/src/public/javascript/library/library.js b/src/public/javascript/library/library.js new file mode 100644 index 0000000000000000000000000000000000000000..906458bd1d23dfa46bbfd6d7981687e7e3ae8074 --- /dev/null +++ b/src/public/javascript/library/library.js @@ -0,0 +1,38 @@ +"use strict" + +import { showErrorToast, showSuccessToast } from "../toast.mjs"; + + +document.addEventListener("DOMContentLoaded", (e) =>{ + + const trashEl = document.querySelectorAll('.bx-trash'); + const playlistContainer = document.querySelector('.playlist-container') + + if(trashEl.length !== 0){ + trashEl.forEach(function(trash){ + trash.addEventListener("click", (e) => { + e.preventDefault(); + + const data = new FormData(); + + const xhr = new XMLHttpRequest(); + + data.append("id_podcast", trash.dataset.id); + data.append("id_playlist", playlistContainer.dataset.id); + + xhr.open("POST", "/public/playlist", true); + + xhr.onload = function () { + if (xhr.readyState === XMLHttpRequest.DONE) { + if (xhr.status === 201) { + showSuccessToast("Podcast berhasil dihapus dari playlist!"); + }else{ // status code 200, some error + showErrorToast("Podcast gagal dihapus dari playlist!"); + } + } + } + xhr.send(data); + }) + }) + } +}); \ No newline at end of file