Changed links to chapters, button to synchronize chapters from courses list, dark mode.

This commit is contained in:
Krzysztof Płaczek
2022-12-07 19:57:57 +01:00
parent 25e28f8193
commit d4d8330d83
7 changed files with 50 additions and 29 deletions

View File

@@ -4,11 +4,14 @@ namespace App\Http\Controllers;
use App\Http\SymfonyCastDl\SymfonyCastDlService; use App\Http\SymfonyCastDl\SymfonyCastDlService;
use App\Models\Chapter; use App\Models\Chapter;
use App\Models\Course;
class ChapterController extends Controller class ChapterController extends Controller
{ {
public function index(Chapter $chapter, SymfonyCastDlService $symfonyCastDlService) public function index(Course $course, int $chapter, SymfonyCastDlService $symfonyCastDlService)
{ {
$chapter = $course->chapters->firstWhere('order', $chapter);
$symfonyCastDlService->videoSize($chapter); $symfonyCastDlService->videoSize($chapter);
if ($chapter->sync_offline) { if ($chapter->sync_offline) {
$symfonyCastDlService->downloadFile($chapter); $symfonyCastDlService->downloadFile($chapter);

View File

@@ -16,11 +16,11 @@ class CourseController extends Controller
return view('course.index', compact('course')); return view('course.index', compact('course'));
} }
public function sync(Course $course) public function sync(Course $course): \Illuminate\Http\RedirectResponse
{ {
$course->chapters->each->update(['sync_offline' => 1]); $course->chapters->each->update(['sync_offline' => 1]);
$course->chapters->each(fn($chapter) => DownloadVideoFile::dispatch($chapter->id)); $course->chapters->each(fn($chapter) => DownloadVideoFile::dispatch($chapter->id));
return redirect(route('course.index', ['course' => $course])); return redirect()->back();
} }
} }

View File

@@ -1,28 +1,40 @@
<x-layout> <x-layout>
<h1> <h1>
<a href="/">List</a> &raquo; <a <a href="/" class="text-decoration-none">List</a> &raquo; <a class="text-decoration-none"
href="{{ route('course.index', ['course' => $chapter->course_id]) }}">{{ $chapter->course->name }}</a> href="{{ route('course.index', ['course' => $chapter->course_id]) }}">{{ $chapter->course->name }}</a>
<br> <br>
<small class="text-muted">{{ $chapter->title }}</small> <small class="text-muted">{{ $chapter->title }}</small>
</h1> </h1>
<div> <div>
<div class="float-none"> <div class="container-fluid">
<div class="row">
<div class="col">
@if($prev) @if($prev)
<div class="float-start m-2"><a href="{{ route('course.chapter', ['chapter' => $prev->id]) }}">Prev</a> <div class="float-start m-2"><a
</div> href="{{ route('course.chapter', ['course' => $chapter->course_id, 'chapter' => $prev->order]) }}"
@endif class="btn btn-primary">Prev</a>
@if($next)
<div class="float-end m-2"><a href="{{ route('course.chapter', ['chapter' => $next->id]) }}">Next</a>
</div> </div>
@endif @endif
</div> </div>
<div class="col">
<div class="mx-auto" style="width: 500px;">
@if($chapter->is_video_file) @if($chapter->is_video_file)
<div class="d-flex justify-content-center">
<video class="mx-auto" width="500" controls> <video class="mx-auto" width="500" controls>
<source src="{{ $chapter->video_url }}" type="video/mp4"/> <source src="{{ $chapter->video_url }}" type="video/mp4"/>
</video> </video>
</div>
@endif
</div>
<div class="col">
@if($next)
<div class="float-end m-2"><a
href="{{ route('course.chapter', ['course' => $chapter->course_id, 'chapter' => $next->order]) }}"
class="btn btn-primary">Next</a>
</div>
@endif @endif
</div> </div>
</div> </div>
</div>
</div>
</x-layout> </x-layout>

View File

@@ -2,9 +2,10 @@
<html lang="en"> <html lang="en">
<head> <head>
<title>{{ $title ?? 'Symfonycast.local' }}</title> <title>{{ $title ?? 'Symfonycast.local' }}</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous"> crossorigin="anonymous">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-dark-5@1.1.3/dist/css/bootstrap-nightfall.min.css"
rel="stylesheet" media="(prefers-color-scheme: dark)">
</head> </head>
<body> <body>
{{ $slot }} {{ $slot }}

View File

@@ -1,6 +1,6 @@
<x-layout> <x-layout>
<h1> <h1>
<a href="/">List</a> &raquo; {{ $course->name }} <a href="/" class="text-decoration-none">List</a> &raquo; {{ $course->name }}
</h1> </h1>
<a href="{{ route('course.sync', ['course' => $course->id]) }}">Sync all chapters offline</a> <a href="{{ route('course.sync', ['course' => $course->id]) }}">Sync all chapters offline</a>
@@ -16,7 +16,7 @@
</thead> </thead>
@foreach($course->chapters()->get() as $chapter) @foreach($course->chapters()->get() as $chapter)
<tr> <tr>
<td><a href="{{ route('course.chapter', ['chapter' => $chapter->id]) }}">{{ $chapter->title }}</a></td> <td><a href="{{ route('course.chapter', ['course' => $course->id, 'chapter' => $chapter->order]) }}" class="text-decoration-none">{{ $chapter->title }}</a></td>
<td>{{ $chapter->duration }}</td> <td>{{ $chapter->duration }}</td>
<td>{{ $chapter->sync_offline?'Yes':'no' }}</td> <td>{{ $chapter->sync_offline?'Yes':'no' }}</td>
<td>{{ $chapter->is_video_file?'Yes':'-' }}</td> <td>{{ $chapter->is_video_file?'Yes':'-' }}</td>

View File

@@ -6,7 +6,8 @@
<th>Id</th> <th>Id</th>
<th></th> <th></th>
<th>Name</th> <th>Name</th>
<th>status</th> <th>Status</th>
<th>Sync</th>
<th>Chapters</th> <th>Chapters</th>
<th>Published at</th> <th>Published at</th>
<th>Estimate file size</th> <th>Estimate file size</th>
@@ -18,9 +19,13 @@
<td class="align-middle">{{ $course->id }}</td> <td class="align-middle">{{ $course->id }}</td>
<td><img src="{{ $course->thumbnail }}" alt="{{ $course->name }}" class="img-thumbnail" <td><img src="{{ $course->thumbnail }}" alt="{{ $course->name }}" class="img-thumbnail"
style="width: 70px;"></td> style="width: 70px;"></td>
<td class="align-middle"><a <td class="align-middle"><a class="text-decoration-none"
href="{{ route('course.index', ['course' => $course->id]) }}">{{ $course->name }}</a></td> href="{{ route('course.index', ['course' => $course->id]) }}">{{ $course->name }}</a>
</td>
<td class="align-middle">{{ $course->status }}</td> <td class="align-middle">{{ $course->status }}</td>
<td class="align-middle"><a class="btn btn-outline-primary"
href="{{ route('course.sync', ['course' => $course->id]) }}">Sync all
chapters offline</a></td>
<td class="align-middle">{{ $course->chapters_count }} / {{ $course->numberofchapters }}</td> <td class="align-middle">{{ $course->chapters_count }} / {{ $course->numberofchapters }}</td>
<td class="align-middle"><abbr <td class="align-middle"><abbr
title="{{ $course->published_at?->format('Y-m-d') }}">{{ $course->published_at?->diffForHumans() }}</abbr> title="{{ $course->published_at?->format('Y-m-d') }}">{{ $course->published_at?->diffForHumans() }}</abbr>

View File

@@ -21,7 +21,7 @@ Route::get('/', [Index::class, 'index']);
Route::prefix('course')->name('course.')->group(function () { Route::prefix('course')->name('course.')->group(function () {
Route::get('/{course}', [CourseController::class, 'index'])->name('index'); Route::get('/{course}', [CourseController::class, 'index'])->name('index');
Route::get('/{course}/sync', [CourseController::class, 'sync'])->name('sync'); Route::get('/{course}/sync', [CourseController::class, 'sync'])->name('sync');
Route::get('/{course}/chapter/{chapter}', [ChapterController::class, 'index'])->name('chapter');
}); });
Route::get('/chapter/{chapter}', [ChapterController::class, 'index'])->name('course.chapter');