A self-hosted media server and file management system
Vue ffmpegfile-serverjellyfinlaravelmediamedia-playermedia-servermediabrowsermediaservermusicmusic-librarymusic-playermusicplayerself-hostedvuejs
Add a basic full history page
aminnausine33652cc0316
diff --git a/app/Http/Resources/RecordResource.php b/app/Http/Resources/RecordResource.phpindex b369aa3d..db7d1334 100644--- a/app/Http/Resources/RecordResource.php+++ b/app/Http/Resources/RecordResource.php@@ -26,7 +26,8 @@ class RecordResource extends JsonResource'video_id' => (string)$this->video->id,'video_name' => $this->video->name,'folder_id' => $this->video->folder_id,- 'folder_name' => $this->video->folder->name+ 'folder_name' => $this->video->folder->name,+ 'category_name' => $this->video->folder->category->name]];}diff --git a/public/js/history.js b/public/js/history.jsnew file mode 100644index 00000000..11bede9c--- /dev/null+++ b/public/js/history.js@@ -0,0 +1,242 @@+var token = ''+var folderData = [];++/*+ Video Retrieval Structure :++ Requires :+ - directory+ - folder name++ Path :+ -> DOMContentLoaded+ -> loadCategoryFolders() - get folders in directory and then+ -> parseFolders() - create ui components for each folder from last request+ -> loadVideosAndParse() - parses the given folder name to a folder from last request and creates a datatable to correspond to it+ - gets videos that have given folder's id and creates ui components (table rows) and then+ -> initVideos() - initialises ui functionality for each video row++ Video History Structure :+++*/++document.addEventListener("DOMContentLoaded", function(event) {+ try {+ loadHistory();++ if(document.getElementById('dark-mode-toggle')){+ document.getElementById('dark-mode-toggle').addEventListener('click', () => { toggleDarkMode(); });+ toggleDarkMode();+ }+ } catch (error) {+ toastr['error']('Unable to load data.');+ console.log(error);+ return;+ }++ //#region UI Navigation++ $("#user_header").on('click', function(){+ document.querySelector("#user_dropdown").classList.toggle("hidden");+ });++ $("#btn-nav-back").on('click', function(){+ cycleSideBar("folders");+ });++ window.addEventListener('click', function(e){+ try {+ let dropdown = this.document.querySelector("#user_dropdown")+ if (!this.document.querySelector("#user_options").contains(e.target)){+ dropdown.classList.add("hidden");+ }+ } catch (error) {+ console.log(error);+ }+ });++ //#endregion+});++//#region UI Navigation++function showLogin(){+ window.location.href = "/login";+}++function showSignup(){+ window.location.href = "/register";+}++//#endregion++async function loadHistory(){+ if(!user) return;+ const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');+ fetch(`/api/records`, {+ method: 'get',+ headers: {+ 'Accept': 'application/json',+ 'Content-Type': 'application/json',+ 'X-CSRF-TOKEN': csrfToken+ }+ }).then((response) =>+ response.json()+ ).then((json) => {+ // console.log(json);+ if(json.success == true){+ parseHistory(json.data);+ console.log('loading history');+ }+ }).catch((error) => {+ console.log(error);+ });+}++async function addToHistory(id){+ if(!user) return;+ const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');++ fetch(`/api/records`, {+ method: 'post',+ headers: {+ 'Accept': 'application/json',+ 'Content-Type': 'application/json',+ 'X-CSRF-TOKEN': csrfToken+ },+ body: JSON.stringify({+ 'video_id': id,+ })+ }).then((response) =>+ response.json()+ ).then((json) => {+ // console.log(json);+ if(json.success == true) {+ // toastr['success']('Added to history!');+ // loadHistory();+ parseHistory([json.data], false);+ };+ }).catch((error) => {+ console.log(error);+ });+}++function parseHistory(data, empty = true) {+ let destination = '#content-history';+ let recordTemplate = function(videoName, folderName, timeSpan, date) {+ return `+ <div class="flex flex-wrap rounded-xl dark:bg-neutral-800 dark:hover:bg-neutral-700 hover:bg-slate-200 bg-slate-100 dark:text-white shadow p-3 w-full divide-y divide-gray-300 group flex-grow cursor-pointer">+ <section class="flex justify-between items-baseline w-full">+ <h2 class="text-xl text-left truncate">${videoName}</h2>+ <h2 class="text-xl text-right truncate">${date}</h2>+ </section>+ <aside class="flex justify-between items-center w-full pt-1">+ <h3 class="text-lg text-left text-neutral-500 truncate">${folderName}</h3>+ <h3 class="text-lg text-right text-neutral-500 text-nowrap line-clamp-1 truncate">${timeSpan}</h3>+ <span class="hidden flex space-x-1">+ <button class="hover:bg-orange-500 hover:stroke-none border-orange-500 border-2 rounded shadow px-2">Watch</button>+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">+ <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 13.5 12 21m0 0-7.5-7.5M12 21V3" />+ </svg>+ </span>+ </aside>+ </div>+ `+ }++ if(empty) $(destination).empty();++ for (let recordCount = 0; recordCount < data.length; recordCount++) {+ const videoName = data[recordCount].relationships.video_name;+ const folderName = data[recordCount].relationships.folder_name;+ const categoryName = data[recordCount].relationships.category_name;+ const rawDate = (new Date(data[recordCount].attributes.created_at.replace(' ', 'T')));+ const rawAge = Date.now() - rawDate.getTime();++ const weeks = Math.round(rawAge / (1000 * 3600 * 24 * 7));+ const days = Math.round(rawAge / (1000 * 3600 * 24));+ const hours = Math.round(rawAge / (1000 * 3600));+ const minutes = Math.round(rawAge / (1000 * 60));+ const seconds = Math.round(rawAge / (1000));++ const timeSpan = weeks > 0 ? `${weeks} week${weeks > 1 ? 's' : ''} ago` : days > 0 ? `${days} day${days > 1 ? 's' : ''} ago` : hours > 0 ? `${hours} hour${hours > 1 ? 's' : ''} ago` : minutes > 0 ? `${minutes}m ago` : `${seconds}s ago`++ let recordElement = recordTemplate(videoName, folderName, timeSpan, `${rawDate.toLocaleDateString([], {year: "numeric", month: '2-digit', day: '2-digit', hour: '2-digit', hour12:false, minute:'2-digit'})}`);+ if(empty) $(destination).append(recordElement)+ else {+ $(destination).children().last().remove();+ $(destination).prepend(recordElement);+ }++ $(destination).children().last().on('click', () => {+ window.location.href = `/${categoryName}/${folderName}`+ })+ }+}++function toggleDarkMode(){+ let rootHTML = document.querySelector('html');+ try {+ let darkModeToggle = document.getElementById('dark-mode-toggle');+ let currElemClass = !darkModeToggle.checked ? 'light-mode' : 'dark-mode';+ let nextElemClass = !darkModeToggle.checked ? 'dark-mode' : 'light-mode';+ let currBtnClass = !darkModeToggle.checked ? 'btn-light' : 'btn-dark';+ let nextBtnClass = !darkModeToggle.checked ? 'btn-dark' : 'btn-light';++ darkModeToggle.checked ? rootHTML.classList.remove("dark", "tw-dark") : rootHTML.classList.add("dark", "tw-dark");++ let elems = document.querySelectorAll('.' + currElemClass);+ let btns = document.querySelectorAll('.' + currBtnClass);++ for (let el of elems) {+ el.classList.replace(currElemClass, nextElemClass);+ }++ for (let btn of btns) {+ btn.classList.replace(currBtnClass, nextBtnClass);+ }+ } catch (error) {+ let darkModeToggle = {checked: true}+ let currElemClass = !darkModeToggle.checked ? 'light-mode' : 'dark-mode';+ let nextElemClass = !darkModeToggle.checked ? 'dark-mode' : 'light-mode';+ let currBtnClass = !darkModeToggle.checked ? 'btn-light' : 'btn-dark';+ let nextBtnClass = !darkModeToggle.checked ? 'btn-dark' : 'btn-light';++ darkModeToggle.checked ? rootHTML.classList.remove("dark", "tw-dark") : rootHTML.classList.add("dark", "tw-dark");++ let elems = document.querySelectorAll('.' + currElemClass);+ let btns = document.querySelectorAll('.' + currBtnClass);++ for (let el of elems) {+ el.classList.replace(currElemClass, nextElemClass);+ }++ for (let btn of btns) {+ btn.classList.replace(currBtnClass, nextBtnClass);+ }+ }+}++function getDarkModeSettings(){+ try {+ let darkModeToggle = document.getElementById('dark-mode-toggle');+ let currElemClass = darkModeToggle.checked ? 'light-mode' : 'dark-mode';+ let currBtnClass = darkModeToggle.checked ? 'btn-light' : 'btn-dark';++ return {+ elementClass: currElemClass,+ btnClass: currBtnClass+ }+ } catch (error) {++ let darkModeToggle = true;+ let currElemClass = darkModeToggle ? 'light-mode' : 'dark-mode';+ let currBtnClass = darkModeToggle ? 'btn-light' : 'btn-dark';++ return {+ elementClass: currElemClass,+ btnClass: currBtnClass+ }+ }+}\ No newline at end of filediff --git a/resources/views/home.blade.php b/resources/views/home.blade.phpindex ee6e9657..814c674c 100644--- a/resources/views/home.blade.php+++ b/resources/views/home.blade.php@@ -11,7 +11,7 @@<script>var user = false;</script>@endauth<main class="p-6 flex gap-6 flex-row-reverse flex-wrap-reverse lg:flex-nowrap snap-y">- <section id="list-card" class="invisible dark:bg-neutral-900 shadow-xl p-3 pb-6 rounded-2xl light-mode w-full lg:w-72 shrink-0 space-y-2 scroll-mt-6">+ <section id="list-card" class="invisible dark:bg-neutral-900 shadow-xl p-3 pb-6 rounded-2xl light-mode w-full lg:w-1/6 lg:max-w-72 shrink-0 space-y-2 scroll-mt-6"><div class="flex p-1 text-ri"><h1 id="sidebar-title" class="text-2xl w-full">Folders</h1></div>@@ -79,7 +79,7 @@<button class="text-gray-700 flex justify-between w-full px-4 py-2 text-sm leading-5 text-left" role="menuitem">Account settings</button><button class="text-gray-700 flex justify-between w-full px-4 py-2 text-sm leading-5 text-left" role="menuitem">Collections</button><button class="text-gray-700 flex justify-between w-full px-4 py-2 text-sm leading-5 text-left" role="menuitem">Dashboard</button>- <button class="text-gray-700 flex justify-between w-full px-4 py-2 text-sm leading-5 text-left" role="menuitem">Full History</button>+ <button class="text-gray-700 flex justify-between w-full px-4 py-2 text-sm leading-5 text-left" role="menuitem" onclick="window.location.href = '/history' ">Full History</button><button class="text-gray-700 flex justify-between w-full px-4 py-2 text-sm leading-5 text-left" role="menuitem"><a href="/jobs/indexFiles" class="w-full h-full">Index Files</a></button><span role="menuitem" tabindex="-1" class="flex justify-between w-full px-4 py-2 text-sm leading-5 text-left text-gray-700 cursor-not-allowed opacity-50" aria-disabled="true">New feature (soon)</span></section>@@ -179,6 +179,6 @@</section></section>- <section id="left-card" class="w-full lg:w-72 shrink-0 hidden lg:block"></section>+ <section id="left-card" class="w-full lg:w-1/6 lg:max-w-72 shrink-0 hidden lg:block"></section></main></x-app-layout>\ No newline at end of filediff --git a/resources/views/profile/history.blade.php b/resources/views/profile/history.blade.phpnew file mode 100644index 00000000..94c51385--- /dev/null+++ b/resources/views/profile/history.blade.php@@ -0,0 +1,98 @@+<x-app-layout>+ <script src="{{ URL::asset('js/history.js') }}"></script>+ <script>+ var stateThumbnailDir = "{{ URL::asset('storage/thumbnails/folders') }}/"+ </script>+ @auth+ <script>var user = true;</script>+ @else+ <script>var user = false;</script>+ @endauth+ <main class="p-6 flex gap-6 flex-row-reverse flex-wrap-reverse lg:flex-nowrap snap-y">+ <section id="right-card" class="w-full lg:w-72 shrink-0 hidden lg:block"></section>+ <section id="content-card" class=" dark:bg-neutral-900 shadow-xl p-6 pt-3 rounded-2xl light-mode w-full">+ <nav id="navbar">+ <div class="flex p-1 gap-y-3 flex-wrap justify-between">+ <h1 id="title" class="text-2xl">Full User History</h1>+ <span class="flex flex-wrap sm:flex-nowrap sm:max-w-sm items-center gap-2 sm:shrink-0">+ <section id="user_options" class="group inline-block relative" data-dropdown-toggle="user_dropdown" aria-haspopup="true">+ <button id="user_header" class="flex space-x-2 text-2xl text-slate-900 dark:text-white hover:text-orange-600 dark:hover:text-orange-600 items-center justify-center" >+ @auth+ <span id="user_name">{{ Auth::user()->name }}</span>+ @else+ <span id="user_name_unauth" class="w-[10vw] text-right">Guest</span>+ @endauth++ <img src="{{ URL::asset('storage/avatars/12345.jpg')}}" class="h-7 w-7 rounded-full sm:mx-0 sm:shrink-0 ring-2 ring-orange-600/60 shadow-lg object-cover" alt="profile picture">+ </button>+ <div role="menu" id="user_dropdown" aria-orientation="vertical" aria-labelledby="user_options" class="hidden absolute left-0 z-30 mt-4 w-56 origin-top-right divide-y divide-gray-300 rounded-md shadow-lg ring-1 bg-white ring-black ring-opacity-5 focus:outline-none text-gray-700">++ @auth+ <!-- <div class="divide-y divide-gray-300" role="menu" id="user-menu-auth"> -->+ <section class="flex flex-wrap gap-1 p-4 justify-between">+ <p class="text-sm leading-5 text-orange-500">Logged in as: </p>+ <p class="text-sm font-medium leading-5 text-gray-900 truncate">{{ Auth::user()->email }}</p>+ </section>+ <section class="py-1">+ <button class="text-gray-700 flex justify-between w-full px-4 py-2 text-sm leading-5 text-left" role="menuitem">Account settings</button>+ <button class="text-gray-700 flex justify-between w-full px-4 py-2 text-sm leading-5 text-left" role="menuitem">Collections</button>+ <button class="text-gray-700 flex justify-between w-full px-4 py-2 text-sm leading-5 text-left" role="menuitem">Dashboard</button>+ <button class="text-gray-700 flex justify-between w-full px-4 py-2 text-sm leading-5 text-left font-bold" role="menuitem">Full History</button>+ <button class="text-gray-700 flex justify-between w-full px-4 py-2 text-sm leading-5 text-left" role="menuitem"><a href="/jobs/indexFiles" class="w-full h-full">Index Files</a></button>+ <span role="menuitem" tabindex="-1" class="flex justify-between w-full px-4 py-2 text-sm leading-5 text-left text-gray-700 cursor-not-allowed opacity-50" aria-disabled="true">New feature (soon)</span>+ </section>+ <section class="py-1">+ <button class="text-gray-700 flex justify-between w-full px-4 py-2 text-sm leading-5 text-left" onclick="logout();" role="menuitem">Log out</button>+ </section>+ <!-- </div> -->+ @else+ <!-- <div role="menu" id="user-menu-unauth" class="text-gray-700"> -->+ <section class="">+ <button class="rounded-t-md hover:bg-neutral-100 flex justify-between w-full px-4 py-2 text-sm leading-5 text-left" onclick="showLogin();" role="menuitem">Log in</button>+ <button class="rounded-b-md hover:bg-neutral-100 flex justify-between w-full px-4 py-2 text-sm leading-5 text-left" onclick="showSignup();" role="menuitem">Sign up</button>+ </section>+ <!-- </div> -->+ @endauth+ </div>++ </section>+++ <section id="navbar-video" class="flex items-center space-x-2">+ <button id="btn-nav-folders" class="flex justify-center items-center shrink-0 h-8 w-8 rounded-lg shadow-lg bg-red-300 hover:bg-red-200" aria-label="folders">+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" height="24" width="24" class="stroke-slate-900">+ <path stroke-linecap="round" stroke-linejoin="round" d="M3.75 9.776c.112-.017.227-.026.344-.026h15.812c.117 0 .232.009.344.026m-16.5 0a2.25 2.25 0 0 0-1.883 2.542l.857 6a2.25 2.25 0 0 0 2.227 1.932H19.05a2.25 2.25 0 0 0 2.227-1.932l.857-6a2.25 2.25 0 0 0-1.883-2.542m-16.5 0V6A2.25 2.25 0 0 1 6 3.75h3.879a1.5 1.5 0 0 1 1.06.44l2.122 2.12a1.5 1.5 0 0 0 1.06.44H18A2.25 2.25 0 0 1 20.25 9v.776" />+ </svg>+ </button>+ @auth+ <button id="btn-nav-history" class="flex justify-center items-center shrink-0 h-8 w-8 rounded-lg shadow-lg bg-purple-300 hover:bg-purple-200" aria-label="watch history">+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" height="24" width="24" class="fill-slate-900">+ <path d="M0 0h24v24H0z" fill="none" />+ <path fill-rule="evenodd" d="M13 3c-4.97 0-9 4.03-9 9H1l3.89 3.89.07.14L9 12H6c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42C8.27 19.99 10.51 21 13 21c4.97 0 9-4.03 9-9s-4.03-9-9-9zm-1 5v5l4.28 2.54.72-1.21-3.5-2.08V8H12z" />+ </svg>+ </button>+ <button id="btn-nav-settings" class=" hidden flex justify-center items-center shrink-0 h-8 w-8 rounded-lg shadow-lg bg-red-300 hover:bg-red-200" aria-label="settings">+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" height="24" width="24" class="fill-slate-900">+ <path fill-rule="evenodd" d="M3 6.75A.75.75 0 0 1 3.75 6h16.5a.75.75 0 0 1 0 1.5H3.75A.75.75 0 0 1 3 6.75ZM3 12a.75.75 0 0 1 .75-.75h16.5a.75.75 0 0 1 0 1.5H3.75A.75.75 0 0 1 3 12Zm0 5.25a.75.75 0 0 1 .75-.75h16.5a.75.75 0 0 1 0 1.5H3.75a.75.75 0 0 1-.75-.75Z" clip-rule="evenodd" />+ </svg>+ </button>+ @endauth+ </section>++ <div class="toggle-switch shrink-0">+ <label class="switch-label">+ <input type="checkbox" class="checkbox invisible" id="dark-mode-toggle">+ <span class="slider"></span>+ </label>+ </div>+ </span>+ </div>+ <hr class="mt-2 mb-3">+ </nav>+ <section id="content-history" class=" space-y-2 cursor-pointer min-h-[80vh] pt-8">++ </section>+ </section>+ <section id="left-card" class="w-full lg:w-72 shrink-0 hidden lg:block"></section>+ </main>+</x-app-layout>\ No newline at end of filediff --git a/routes/web.php b/routes/web.phpindex caa1a8d3..9b04ddc9 100644--- a/routes/web.php+++ b/routes/web.php@@ -32,6 +32,7 @@ Route::middleware('auth')->group(function () {Route::post('/logout', [AuthController::class, 'destroy'])->name('logout');Route::get('/jobs/indexFiles', [DirectoryController::class, 'indexFiles']);Route::get('/welcome', function () { return view('welcome'); });+ Route::get('/history', function () { return view('profile/history'); });// Route::get('/legacy', [DirectoryController::class, 'showDirectory'])->defaults('dir', 'legacy')->defaults('folder_name', 'Unsorted');// Route::get('/legacy/{folder_name}', [DirectoryController::class, 'showDirectory'])->defaults('dir', 'legacy')->defaults('folder_name', 'Unsorted');});