update the match view

This commit is contained in:
ghassan 2026-03-12 03:59:52 +03:00
parent 062c0e896f
commit 69f5df163a
14 changed files with 7331 additions and 743 deletions

View File

@ -0,0 +1,279 @@
<?php
namespace App\Http\Controllers;
use App\Models\CoachReview;
use App\Models\MatchPoint;
use App\Models\MatchRound;
use App\Models\Video;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class MatchEventController extends Controller
{
// ==================== ROUNDS ====================
public function storeRound(Request $request, Video $video)
{
$request->validate([
'round_number' => 'required|integer|min:1',
'name' => 'nullable|string|max:50',
]);
// Check if user owns the video
if (Auth::id() !== $video->user_id) {
return response()->json(['success' => false, 'message' => 'Unauthorized'], 403);
}
$round = MatchRound::create([
'video_id' => $video->id,
'round_number' => $request->round_number,
'name' => $request->name ?? 'ROUND '.$request->round_number,
]);
return response()->json([
'success' => true,
'round' => $round,
'message' => 'Round added successfully!',
]);
}
public function updateRound(Request $request, MatchRound $round)
{
$request->validate([
'name' => 'required|string|max:50',
]);
// Check if user owns the video
if (Auth::id() !== $round->video->user_id) {
return response()->json(['success' => false, 'message' => 'Unauthorized'], 403);
}
$round->update([
'name' => $request->name,
]);
return response()->json([
'success' => true,
'round' => $round,
'message' => 'Round updated successfully!',
]);
}
public function destroyRound(MatchRound $round)
{
// Check if user owns the video
if (Auth::id() !== $round->video->user_id) {
return response()->json(['success' => false, 'message' => 'Unauthorized'], 403);
}
$round->delete();
return response()->json([
'success' => true,
'message' => 'Round deleted successfully!',
]);
}
// ==================== POINTS ====================
public function storePoint(Request $request, Video $video)
{
$request->validate([
'round_id' => 'required|exists:match_rounds,id',
'timestamp_seconds' => 'required|integer|min:0',
'action' => 'required|string|max:255',
'points' => 'required|integer|min:1',
'competitor' => 'required|in:blue,red',
'notes' => 'nullable|string|max:500',
]);
// Check if user owns the video
if (Auth::id() !== $video->user_id) {
return response()->json(['success' => false, 'message' => 'Unauthorized'], 403);
}
// Calculate scores
$previousPoints = MatchPoint::where('video_id', $video->id)
->where('match_round_id', $request->round_id)
->where('timestamp_seconds', '<', $request->timestamp_seconds)
->orderBy('timestamp_seconds', 'desc')
->first();
$scoreBlue = $previousPoints ? $previousPoints->score_blue : 0;
$scoreRed = $previousPoints ? $previousPoints->score_red : 0;
if ($request->competitor === 'blue') {
$scoreBlue += $request->points;
} else {
$scoreRed += $request->points;
}
$point = MatchPoint::create([
'video_id' => $video->id,
'match_round_id' => $request->round_id,
'timestamp_seconds' => $request->timestamp_seconds,
'action' => $request->action,
'points' => $request->points,
'competitor' => $request->competitor,
'notes' => $request->notes,
'score_blue' => $scoreBlue,
'score_red' => $scoreRed,
]);
return response()->json([
'success' => true,
'point' => $point,
'message' => 'Point added successfully!',
]);
}
public function updatePoint(Request $request, MatchPoint $point)
{
$request->validate([
'timestamp_seconds' => 'required|integer|min:0',
'action' => 'required|string|max:255',
'points' => 'required|integer|min:1',
'competitor' => 'required|in:blue,red',
'notes' => 'nullable|string|max:500',
]);
// Check if user owns the video
if (Auth::id() !== $point->video->user_id) {
return response()->json(['success' => false, 'message' => 'Unauthorized'], 403);
}
$point->update([
'timestamp_seconds' => $request->timestamp_seconds,
'action' => $request->action,
'points' => $request->points,
'competitor' => $request->competitor,
'notes' => $request->notes,
]);
return response()->json([
'success' => true,
'point' => $point,
'message' => 'Point updated successfully!',
]);
}
public function destroyPoint(MatchPoint $point)
{
// Check if user owns the video
if (Auth::id() !== $point->video->user_id) {
return response()->json(['success' => false, 'message' => 'Unauthorized'], 403);
}
$point->delete();
return response()->json([
'success' => true,
'message' => 'Point deleted successfully!',
]);
}
// ==================== COACH REVIEWS ====================
public function storeReview(Request $request, Video $video)
{
$request->validate([
'start_time_seconds' => 'required|integer|min:0',
'end_time_seconds' => 'nullable|integer|min:0',
'note' => 'required|string|max:1000',
'coach_name' => 'required|string|max:100',
'emoji' => 'nullable|string|max:10',
]);
// Check if user owns the video
if (Auth::id() !== $video->user_id) {
return response()->json(['success' => false, 'message' => 'Unauthorized'], 403);
}
$review = CoachReview::create([
'video_id' => $video->id,
'user_id' => Auth::id(),
'start_time_seconds' => $request->start_time_seconds,
'end_time_seconds' => $request->end_time_seconds,
'note' => $request->note,
'coach_name' => $request->coach_name,
'emoji' => $request->emoji ?? '🔥',
]);
return response()->json([
'success' => true,
'review' => $review,
'message' => 'Coach note added successfully!',
]);
}
public function updateReview(Request $request, CoachReview $review)
{
$request->validate([
'start_time_seconds' => 'required|integer|min:0',
'end_time_seconds' => 'nullable|integer|min:0',
'note' => 'required|string|max:1000',
'coach_name' => 'required|string|max:100',
'emoji' => 'nullable|string|max:10',
]);
// Check if user owns the video
if (Auth::id() !== $review->video->user_id) {
return response()->json(['success' => false, 'message' => 'Unauthorized'], 403);
}
$review->update([
'start_time_seconds' => $request->start_time_seconds,
'end_time_seconds' => $request->end_time_seconds,
'note' => $request->note,
'coach_name' => $request->coach_name,
'emoji' => $request->emoji,
]);
return response()->json([
'success' => true,
'review' => $review,
'message' => 'Coach note updated successfully!',
]);
}
public function destroyReview(CoachReview $review)
{
// Check if user owns the video
if (Auth::id() !== $review->video->user_id) {
return response()->json(['success' => false, 'message' => 'Unauthorized'], 403);
}
$review->delete();
return response()->json([
'success' => true,
'message' => 'Coach note deleted successfully!',
]);
}
// ==================== GET DATA ====================
public function getMatchData(Video $video)
{
// Check if user can view this video
if (! $video->canView(Auth::user())) {
return response()->json(['success' => false, 'message' => 'Unauthorized'], 403);
}
$rounds = MatchRound::where('video_id', $video->id)
->with('points')
->orderBy('round_number')
->get();
$reviews = CoachReview::where('video_id', $video->id)
->orderBy('start_time_seconds')
->get();
return response()->json([
'success' => true,
'rounds' => $rounds,
'reviews' => $reviews,
]);
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class CoachReview extends Model
{
use HasFactory;
protected $fillable = [
'video_id',
'user_id',
'start_time_seconds',
'end_time_seconds',
'note',
'coach_name',
'emoji',
];
public function video(): BelongsTo
{
return $this->belongsTo(Video::class);
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
}

34
app/Models/MatchPoint.php Normal file
View File

@ -0,0 +1,34 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class MatchPoint extends Model
{
use HasFactory;
protected $fillable = [
'video_id',
'match_round_id',
'timestamp_seconds',
'action',
'points',
'competitor',
'notes',
'score_blue',
'score_red',
];
public function video(): BelongsTo
{
return $this->belongsTo(Video::class);
}
public function round(): BelongsTo
{
return $this->belongsTo(MatchRound::class, 'match_round_id');
}
}

29
app/Models/MatchRound.php Normal file
View File

@ -0,0 +1,29 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class MatchRound extends Model
{
use HasFactory;
protected $fillable = [
'video_id',
'round_number',
'name',
];
public function video(): BelongsTo
{
return $this->belongsTo(Video::class);
}
public function points(): HasMany
{
return $this->hasMany(MatchPoint::class, 'match_round_id')->orderBy('timestamp_seconds');
}
}

View File

@ -246,6 +246,22 @@ class Video extends Model
return $this->comments()->count();
}
// Match events relationships
public function matchRounds()
{
return $this->hasMany(MatchRound::class)->orderBy('round_number');
}
public function matchPoints()
{
return $this->hasMany(MatchPoint::class);
}
public function coachReviews()
{
return $this->hasMany(CoachReview::class)->orderBy('start_time_seconds');
}
// Get recent views count (within hours)
public function getRecentViews($hours = 48)
{

View File

@ -0,0 +1,26 @@
<?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::create('match_rounds', function (Blueprint $table) {
$table->id();
$table->foreignId('video_id')->constrained()->onDelete('cascade');
$table->integer('round_number');
$table->string('name')->default('ROUND');
$table->timestamps();
$table->unique(['video_id', 'round_number']);
});
}
public function down(): void
{
Schema::dropIfExists('match_rounds');
}
};

View File

@ -0,0 +1,30 @@
<?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::create('match_points', function (Blueprint $table) {
$table->id();
$table->foreignId('video_id')->constrained()->onDelete('cascade');
$table->foreignId('match_round_id')->constrained('match_rounds')->onDelete('cascade');
$table->integer('timestamp_seconds');
$table->string('action');
$table->integer('points');
$table->string('competitor'); // 'blue' or 'red'
$table->string('notes')->nullable();
$table->integer('score_blue')->default(0);
$table->integer('score_red')->default(0);
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('match_points');
}
};

View File

@ -0,0 +1,28 @@
<?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::create('coach_reviews', function (Blueprint $table) {
$table->id();
$table->foreignId('video_id')->constrained()->onDelete('cascade');
$table->foreignId('user_id')->constrained()->onDelete('cascade');
$table->integer('start_time_seconds');
$table->integer('end_time_seconds')->nullable();
$table->text('note');
$table->string('coach_name');
$table->string('emoji')->default('🔥');
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('coach_reviews');
}
};

View File

@ -87,13 +87,14 @@
letter-spacing: -1px;
}
/* Search */
/* Search */
.yt-header-center {
flex: 1;
max-width: 640px;
margin: 0 40px;
display: flex;
align-items: center;
justify-content: center;
}
.yt-search {

View File

@ -1,5 +1,191 @@
<!-- Header -->
<header class="yt-header">
<style>
.yt-header {
position: fixed;
top: 0;
left: 0;
right: 0;
height: 56px;
background: #0f0f0f;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 16px;
z-index: 1000;
border-bottom: 1px solid #303030;
}
.yt-header-left {
display: flex;
align-items: center;
gap: 16px;
}
.yt-menu-btn {
width: 40px;
height: 40px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
transition: background 0.2s;
background: transparent;
border: none;
color: #f1f1f1;
}
.yt-menu-btn:hover { background: #303030; }
.yt-logo {
display: flex;
align-items: center;
text-decoration: none;
gap: 4px;
}
.yt-logo-text {
font-size: 1.4rem;
font-weight: 700;
color: #f1f1f1;
letter-spacing: -1px;
}
.yt-header-center {
flex: 1;
max-width: 640px;
margin: 0 40px;
display: flex;
align-items: center;
justify-content: center;
}
.yt-search {
flex: 1;
display: flex;
height: 40px;
}
.yt-search-input {
flex: 1;
background: #121212;
border: 1px solid #303030;
border-right: none;
border-radius: 20px 0 0 20px;
padding: 0 16px;
color: #f1f1f1;
font-size: 16px;
}
.yt-search-input:focus {
outline: none;
border-color: #1c62b9;
}
.yt-search-btn {
width: 64px;
background: #222;
border: 1px solid #303030;
border-radius: 0 20px 20px 0;
color: #f1f1f1;
cursor: pointer;
}
.yt-search-btn:hover { background: #303030; }
.yt-header-right {
display: flex;
align-items: center;
gap: 8px;
}
.yt-mobile-search-toggle {
width: 40px;
height: 40px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
background: transparent;
border: none;
color: #f1f1f1;
font-size: 1.2rem;
}
.yt-mobile-search-toggle:hover {
background: #303030;
}
.yt-upload-btn {
background: #e61e1e;
color: white;
border: none;
padding: 8px 16px;
border-radius: 20px;
font-weight: 500;
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
text-decoration: none;
}
.yt-upload-btn:hover { background: #cc1a1a; }
.yt-icon-btn {
width: 40px;
height: 40px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
background: transparent;
border: none;
color: #f1f1f1;
font-size: 1.2rem;
}
.yt-icon-btn:hover { background: #303030; }
.yt-user-avatar {
width: 32px;
height: 32px;
border-radius: 50%;
background: #555;
cursor: pointer;
}
@media (max-width: 576px) {
.yt-upload-btn {
width: 40px;
height: 40px;
padding: 0;
border-radius: 50%;
justify-content: center;
}
.yt-upload-btn span {
display: none;
}
@media (min-width: 400px) {
.yt-upload-btn {
width: auto;
border-radius: 20px;
padding: 8px 16px;
}
.yt-upload-btn span {
display: inline;
}
}
}
@media (max-width: 768px) {
.yt-header-center { display: none; }
}
</style>
<div class="yt-header-left">
<button class="yt-menu-btn" onclick="toggleSidebar()">
<i class="bi bi-list fs-5"></i>
@ -11,7 +197,7 @@
<img src="{{ asset('storage/images/fullLogo.png') }}" alt="{{ config('app.name') }}" class="d-none d-md-block" style="height: 30px;">
</a>
</div>
<div class="yt-header-center d-none d-md-flex">
<form action="{{ route('videos.search') }}" method="GET" class="yt-search">
<input type="text" name="q" class="yt-search-input" placeholder="Search" value="{{ request('q') }}">
@ -20,20 +206,20 @@
</button>
</form>
</div>
<div class="yt-header-right">
<!-- Mobile Search Toggle Button -->
<button type="button" class="yt-mobile-search-toggle d-md-none" onclick="toggleMobileSearch()">
<i class="bi bi-search"></i>
</button>
@auth
<!-- Upload Button - Opens Modal -->
<button type="button" class="yt-upload-btn d-none d-md-flex" data-bs-toggle="modal" data-bs-target="#uploadModal">
<i class="bi bi-plus-lg"></i>
<span>Upload</span>
</button>
<!-- User Dropdown -->
<div class="dropdown">
<button class="yt-icon-btn" data-bs-toggle="dropdown" aria-expanded="false">

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,7 @@
<?php
use App\Http\Controllers\CommentController;
use App\Http\Controllers\MatchEventController;
use App\Http\Controllers\SuperAdminController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\VideoController;
@ -111,3 +112,26 @@ Route::middleware(['auth', 'super_admin'])->prefix('admin')->name('admin.')->gro
Route::put('/videos/{video}', [SuperAdminController::class, 'updateVideo'])->name('videos.update');
Route::delete('/videos/{video}', [SuperAdminController::class, 'deleteVideo'])->name('videos.delete');
});
// Match Events Routes (removed auth requirement for demo purposes)
// In production, wrap with: Route::middleware('auth')->group(function () {
// Get match data - public for viewing
Route::get('/videos/{video}/match-data', [MatchEventController::class, 'getMatchData'])->name('match.getData');
// Round CRUD
Route::post('/videos/{video}/rounds', [MatchEventController::class, 'storeRound'])->name('match.storeRound');
Route::put('/rounds/{round}', [MatchEventController::class, 'updateRound'])->name('match.updateRound');
Route::delete('/rounds/{round}', [MatchEventController::class, 'destroyRound'])->name('match.destroyRound');
// Point CRUD
Route::post('/videos/{video}/points', [MatchEventController::class, 'storePoint'])->name('match.storePoint');
Route::put('/points/{point}', [MatchEventController::class, 'updatePoint'])->name('match.updatePoint');
Route::delete('/points/{point}', [MatchEventController::class, 'destroyPoint'])->name('match.destroyPoint');
// Coach Review CRUD
Route::post('/videos/{video}/reviews', [MatchEventController::class, 'storeReview'])->name('match.storeReview');
Route::put('/reviews/{review}', [MatchEventController::class, 'updateReview'])->name('match.updateReview');
Route::delete('/reviews/{review}', [MatchEventController::class, 'destroyReview'])->name('match.destroyReview');
// });