Info and filtering by course tracks, table of content on chapter view with links and previous and next buttons.

This commit is contained in:
Krzysztof Płaczek
2023-01-23 13:23:57 +01:00
parent d4d8330d83
commit 5902bf7c2b
9 changed files with 1024 additions and 477 deletions

View File

@@ -9,9 +9,9 @@ use Illuminate\Http\Request;
class Index extends Controller
{
public function index()
public function index(string $track = null)
{
$courses = Course::with('chapters')->withCount('chapters')->get();
$courses = Course::where('tracks', 'like', '%'.$track.'%')->with('chapters')->withCount('chapters')->get();
return view('index', compact(['courses']));
}

View File

@@ -28,6 +28,7 @@ class HtmlParser
$course->thumbnail = $courseItem->first('img.course-list-item-img')->attr('src');
$course->link = last(explode('/', $courseItem->first('a')->attr('href')));
$course->status = $courseItem->attr('data-status');
$course->tracks = $courseItem->attr('data-tracks');
$course->course_id = $courseItem->attr('data-id');
$course->numberofchapters = $courseItem->attr('data-chapter-count');
$course->timeswatched = $courseItem->attr('data-times-watched');

View File

@@ -14,6 +14,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
* @property string $thumbnail
* @property string $link
* @property string $status
* @property string $tracks
* @property integer $numberofchapters
* @property integer $timeswatched
* @property Date $published_at
@@ -28,6 +29,7 @@ class Course extends Model
'thumbnail',
'link',
'status',
'tracks',
'numberofchapters',
'timeswatched',
'published_at',

View File

@@ -9,6 +9,7 @@
"license": "MIT",
"require": {
"php": "^8.0.2",
"doctrine/dbal": "^3.5",
"guzzlehttp/guzzle": "^7.2",
"imangazaliev/didom": "^2.0",
"laravel/framework": "^9.19",

1449
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,22 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('courses', function (Blueprint $table) {
$table->text('tracks')->after('status')->nullable();
});
}
public function down(): void
{
Schema::table('courses', function (Blueprint $table) {
$table->removeColumn('tracks');
});
}
};

View File

@@ -25,6 +25,19 @@
</div>
@endif
<div>
<table class="table table-sm">
@foreach($chapters as $courseChapter)
<tr class="@if($courseChapter->id === $chapter->id)table-dark @endif">
<td>
<a href="{{ route('course.chapter', ['course' => $courseChapter->course_id, 'chapter' => $courseChapter->order ]) }}" class="text-decoration-none">{{ $courseChapter->title }}</a>
</td>
<td class="text-end">{{ $courseChapter->duration }}</td>
</tr>
@endforeach
</table>
</div>
</div>
<div class="col">
@if($next)
@@ -35,6 +48,7 @@
@endif
</div>
</div>
</div>
</div>
</x-layout>

View File

@@ -7,6 +7,7 @@
<th></th>
<th>Name</th>
<th>Status</th>
<th>Tracks</th>
<th>Sync</th>
<th>Chapters</th>
<th>Published at</th>
@@ -23,6 +24,11 @@
href="{{ route('course.index', ['course' => $course->id]) }}">{{ $course->name }}</a>
</td>
<td class="align-middle">{{ $course->status }}</td>
<td class="align-middle">
@foreach( explode(',', $course->tracks) as $track)
<a href="/track/{{ $track }}" class="badge rounded-pill bg-secondary">{{ $track }}</a>
@endforeach
</td>
<td class="align-middle"><a class="btn btn-outline-primary"
href="{{ route('course.sync', ['course' => $course->id]) }}">Sync all
chapters offline</a></td>
@@ -41,6 +47,7 @@
<td></td>
<td></td>
<td></td>
<td></td>
<td class="align-middle text-end pe-4">{{ formatFileSize($courses->sum('total_size')) }}</td>
<td class="align-middle text-end pe-4">{{formatFileSize(folderSize(public_path()))}}</td>
</tr>

View File

@@ -18,6 +18,7 @@ use Illuminate\Support\Facades\Route;
Route::get('/download', [Index::class, 'download']);
Route::get('/', [Index::class, 'index']);
Route::get('/track/{track}', [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');