Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing #83

Merged
merged 10 commits into from
Jan 7, 2024
3 changes: 2 additions & 1 deletion app/Http/Controllers/LabController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public function show(Lab $lab)
{
$labs = Lab::all();
$timeMappings = TimeMappings::$timeMappings;
return view('home.lab', compact('lab', 'labs', 'timeMappings'));
$title = $lab->name;
return view('home.lab', compact('lab', 'labs', 'timeMappings', 'title'));
}

/**
Expand Down
59 changes: 59 additions & 0 deletions app/Livewire/Counter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace App\Livewire;

use Carbon\Carbon;
use Livewire\Component;
use App\Models\LabsBooking;
use Livewire\Attributes\On;


class Counter extends Component
{
public $count = 5;


public function loadMore()
{
$this->count += 5;
}

public function cancelBooking($id)
{
$booking = LabsBooking::find($id);
$booking->delete();
}

public function render()
{

$now = Carbon::now();

$upcomingHistories = LabsBooking::with('lab')
->where('user_id', auth()->user()->id)
->where(function ($query) use ($now) {
$query->where('booking_date', '>=', $now->format('Y-m-d'))
->orWhere(function ($subquery) use ($now) {
$subquery->where('booking_date', '=', $now->format('Y-m-d'))
->where('start_time', '>', $now->format('H:i:s'));
});
})
->orderBy('booking_date', 'asc')
->get();

$expiredHistories = LabsBooking::with('lab')
->where('user_id', auth()->user()->id)
->where(function ($query) use ($now) {
$query->where('booking_date', '<', $now->format('Y-m-d'))
->orWhere(function ($subquery) use ($now) {
$subquery->whereDate('booking_date', '=', $now->format('Y-m-d'))
->whereTime('start_time', '<', $now->format('H:i:s'));
});
})
->orderBy('booking_date', 'desc')
->take($this->count)->get();


return view('livewire.counter', compact('upcomingHistories', 'expiredHistories'));
}
}
12 changes: 10 additions & 2 deletions app/Livewire/Navbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
namespace App\Livewire;

use Carbon\Carbon;
use App\Models\Lab;
use Livewire\Component;
use Livewire\Attributes\On;

class Navbar extends Component
{
Expand All @@ -17,6 +15,16 @@ public function mount()
$this->startDate = Carbon::now()->startOfWeek()->addWeeks($this->currentWeek - 1);
}

public function getAllRoom()
{
$this->dispatch('getAllRoom');
}

public function getRoom($bulding)
{
$this->dispatch('getRoom', ['bulding' => $bulding]);
}

public function prevWeek()
{
$this->dispatch('prevWeek');
Expand Down
14 changes: 14 additions & 0 deletions app/Livewire/ScheduleCalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ public function getLabScheduleDetail($labId, $date, $day)
$this->dispatch('show-detail-schedule', $labId, $date, $day, $data);
}

#[On('getRoom')]
public function getRoom($bulding)
{
$this->labs = Lab::where('description', $bulding)->get();
$this->mount();
}

#[On('getAllRoom')]
public function getAllRoom()
{
$this->labs = Lab::all();
$this->mount();
}

public function render()
{
return view('livewire.schedule-calendar');
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"require": {
"php": "^8.1",
"guzzlehttp/guzzle": "^7.2",
"hisorange/browser-detect": "^5.0",
"itsgoingd/clockwork": "^5.1",
"laravel/framework": "^10.10",
"laravel/sanctum": "^3.2",
Expand Down
Loading
Loading