Updated composer packaged, updated home view table.

This commit is contained in:
Krzysztof Płaczek
2023-03-31 08:44:31 +02:00
parent 5784cf8ed3
commit dce3cdd929
4 changed files with 558 additions and 388 deletions

View File

@@ -45,14 +45,21 @@ class Course extends Model
return $this->hasMany(Chapter::class); return $this->hasMany(Chapter::class);
} }
public function totalSize(): Attribute protected function totalSize(): Attribute
{ {
return Attribute::make( return Attribute::make(
get: fn() => $this->chapters->sum('video_size'), get: fn() => $this->chapters->sum('video_size'),
); );
} }
public function totalSizeHuman(): Attribute protected function tracks(): Attribute
{
return Attribute::make(
get: fn(string $tracks) => empty($tracks) ? [] : explode(',', $tracks),
);
}
protected function totalSizeHuman(): Attribute
{ {
return Attribute::make( return Attribute::make(
get: fn() => formatFileSize($this->total_size), get: fn() => formatFileSize($this->total_size),

893
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,53 +1,43 @@
<x-layout> <x-layout>
<h1>List of Courses</h1> <h1><a class="text-decoration-none" href="{{route('index')}}">List of Courses</a> <small class="text-muted">{{ request()->has('track')?:request()->track }}</small></h1>
<table class="table table-sm"> <table class="table table-sm">
<thead> <thead>
<tr> <tr>
<th>Id</th>
<th></th> <th></th>
<th>Name</th> <th>Name</th>
<th>Status</th>
<th>Tracks</th> <th>Tracks</th>
<th>Sync</th> <th>Sync</th>
<th>Chapters</th>
<th>Published at</th>
<th>Estimate file size</th> <th>Estimate file size</th>
<th>Actual size</th> <th>Actual size</th>
</tr> </tr>
</thead> </thead>
@foreach($courses as $course) @foreach($courses as $course)
<tr> <tr>
<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 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"> <td class="align-middle">
@foreach( explode(',', $course->tracks) as $track) <a class="text-decoration-none" href="{{ route('course.index', ['course' => $course->id]) }}">{{ $course->name }}</a>
<a href="/track/{{ $track }}" class="badge rounded-pill bg-secondary text-decoration-none">{{ $track }}</a> <p class="text-muted">
course status: <span class="fw-lighter">{{ $course->status }}</span>
published: <span class="fw-lighter"><abbr title="{{ $course->published_at?->format('Y-m-d') }}">{{ $course->published_at?->diffForHumans() }}</abbr></span>
synced chapters: <span class="fw-lighter">{{ $course->chapters_to_sync }} of {{ $course->numberofchapters }}</span>
</p>
</td>
<td class="align-middle">
@foreach($course->tracks as $track)
<a href="{{ route('index.track', ['track' => $track]) }}" class="badge rounded-pill bg-secondary text-decoration-none">{{ $track }}</a>
@endforeach @endforeach
</td> </td>
<td class="align-middle"><a class="btn btn-outline-primary" <td class="align-middle"><a class="btn btn-outline-primary"
href="{{ route('course.sync', ['course' => $course->id]) }}">Sync all href="{{ route('course.sync', ['course' => $course->id]) }}">Sync all
chapters offline</a></td> chapters offline</a></td>
<td class="align-middle">{{ $course->chapters_to_sync }} / {{ $course->numberofchapters }}</td>
<td class="align-middle"><abbr
title="{{ $course->published_at?->format('Y-m-d') }}">{{ $course->published_at?->diffForHumans() }}</abbr>
</td>
<td class="align-middle text-end pe-4">{{ $course->total_size_human }}</td> <td class="align-middle text-end pe-4">{{ $course->total_size_human }}</td>
<td class="align-middle text-end pe-4">{{formatFileSize(folderSize(public_path('videos'.DIRECTORY_SEPARATOR.$course->id)))}}</td> <td class="align-middle text-end pe-4">{{formatFileSize(folderSize(public_path('videos'.DIRECTORY_SEPARATOR.$course->id)))}}</td>
</tr> </tr>
@endforeach @endforeach
<tr> <tr>
<td></td> <td colspan="4"></td>
<td></td>
<td></td>
<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($courses->sum('total_size')) }}</td>
<td class="align-middle text-end pe-4">{{formatFileSize(folderSize(public_path()))}}</td> <td class="align-middle text-end pe-4">{{formatFileSize(folderSize(public_path()))}}</td>
</tr> </tr>

View File

@@ -7,8 +7,8 @@ use App\Http\Controllers\Index;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
Route::get('/download', [Index::class, 'download']); Route::get('/download', [Index::class, 'download']);
Route::get('/', [Index::class, 'index']); Route::get('/', [Index::class, 'index'])->name('index');
Route::get('/track/{track}', [Index::class, 'index']); Route::get('/track/{track}', [Index::class, 'index'])->name('index.track');
Route::prefix('course')->group(function () { Route::prefix('course')->group(function () {
Route::get('/{course}', CourseController::class)->name('course.index'); Route::get('/{course}', CourseController::class)->name('course.index');
Route::get('/{course}/sync', Sync::class)->name('course.sync'); Route::get('/{course}/sync', Sync::class)->name('course.sync');