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\Models\Chapter;
use App\Models\Course;
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);
if ($chapter->sync_offline) {
$symfonyCastDlService->downloadFile($chapter);

View File

@@ -16,11 +16,11 @@ class CourseController extends Controller
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(fn($chapter) => DownloadVideoFile::dispatch($chapter->id));
return redirect(route('course.index', ['course' => $course]));
return redirect()->back();
}
}

View File

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

View File

@@ -2,9 +2,10 @@
<html lang="en">
<head>
<title>{{ $title ?? 'Symfonycast.local' }}</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"
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>
<body>
{{ $slot }}

View File

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

View File

@@ -6,7 +6,8 @@
<th>Id</th>
<th></th>
<th>Name</th>
<th>status</th>
<th>Status</th>
<th>Sync</th>
<th>Chapters</th>
<th>Published at</th>
<th>Estimate file size</th>
@@ -18,9 +19,13 @@
<td class="align-middle">{{ $course->id }}</td>
<td><img src="{{ $course->thumbnail }}" alt="{{ $course->name }}" class="img-thumbnail"
style="width: 70px;"></td>
<td class="align-middle"><a
href="{{ route('course.index', ['course' => $course->id]) }}">{{ $course->name }}</a></td>
<td class="align-middle"><a class="text-decoration-none"
href="{{ route('course.index', ['course' => $course->id]) }}">{{ $course->name }}</a>
</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"><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::get('/{course}', [CourseController::class, 'index'])->name('index');
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');