Skip to content

Commit

Permalink
Merge pull request #527 from HZ-HBO-ICT/feature/frontend-edition-bugf…
Browse files Browse the repository at this point in the history
…ixing

Feature/Bugfix - Frontend edition bugfixing
  • Loading branch information
IGORnvk authored Jul 17, 2024
2 parents b036160 + 24c0e2a commit 82fcab5
Show file tree
Hide file tree
Showing 29 changed files with 525 additions and 379 deletions.
13 changes: 9 additions & 4 deletions app/Http/Controllers/CompanyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\View\View;
use App\Models\Edition;

class CompanyController extends Controller
{
/**
* Returns the public facing company index page
* @return View
*/
public function index() : View
public function index()
{
$edition = Edition::current();

if (!$edition) {
return redirect(route('welcome'))
->dangerBanner("Companies are not available yet.");
}

return view('teams.public.index', ['teams' => collect()]);
}
}
5 changes: 3 additions & 2 deletions app/Http/Controllers/Crew/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ class UserController extends Controller
/**
* Returns the page with a list of users
*
* @param string|null $role
* @return View
*/
public function index(): View
public function index(?string $role = null): View
{
if (Auth::user()->cannot('viewAny', User::class)) {
abort(403);
}

return view('crew.users.index');
return view('crew.users.index', compact('role'));
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/Hub/ParticipantController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ParticipantController extends Controller
*/
public function programme(): View
{
$presentations = Auth::user()->participating_in;
$presentations = Auth::user()->participating_in->sortBy('start');

return view('myhub.programme', compact('presentations'));
}
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/ProgrammeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function enroll(Presentation $presentation)
->banner("Something went wrong with enrolling for {$presentation->name}");
}

return redirect(route('programme.presentation.show', compact('presentation')))
return redirect(route('programme'))
->banner("You have successfully enrolled for {$presentation->name}");
}

Expand All @@ -87,7 +87,7 @@ public function disenroll(Presentation $presentation)

Auth::user()->leavePresentation($presentation);

return redirect(route('programme.presentation.show', compact('presentation')))
return redirect(route('programme'))
->banner("You have successfully deregistered from the {$presentation->name}");
}
}
11 changes: 6 additions & 5 deletions app/Http/Controllers/SpeakerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@

use App\Models\Edition;
use App\Models\UserPresentation;
use Illuminate\Http\Request;
use Illuminate\View\View;

class SpeakerController extends Controller
{
/**
* Returns the public facing speakers index page
*
* @return View
*/
public function index(): View
public function index()
{
$speakers = collect();
$edition = Edition::current();

if (!$edition) {
return redirect(route('welcome'))
->dangerBanner("Speakers are not available yet.");
}

if (optional(Edition::current())->is_final_programme_released) {
$speakers = UserPresentation::where('role', 'speaker')
->whereHas('presentation', function ($query) {
Expand Down
24 changes: 4 additions & 20 deletions app/Livewire/Forms/KeynoteForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class KeynoteForm extends Form
#[Validate(['required', 'string', 'min:3', 'max:700'])]
public $keynote_description;


#[Validate(['required', 'max:2048', 'image', 'mimes:jpg,jpeg,png'])]
public $keynote_photo_path;

Expand Down Expand Up @@ -62,27 +63,10 @@ public function update()
*/
public function updateKeynotePhoto(UploadedFile $photo, string $storagePath = 'profile-photos'): void
{
tap($this->keynote_photo_path, function ($previous) use ($photo, $storagePath) {
$this->edition->forceFill([
'keynote_photo_path' => $photo->storePublicly(
$storagePath,
['disk' => $this->profilePhotoDisk()]
),
])->save();
$path = $this->keynote_photo_path->store('logos', 'public');

if ($previous) {
Storage::disk($this->profilePhotoDisk())->delete($previous);
}
});
}
$this->edition->update(['keynote_photo_path' => $path]);

/**
* Returns a disk where to store the new photo
*
* @return \Illuminate\Config\Repository|\Illuminate\Contracts\Foundation\Application|\Illuminate\Foundation\Application|mixed|string
*/
protected function profilePhotoDisk(): mixed
{
return isset($_ENV['VAPOR_ARTIFACT_NAME']) ? 's3' : config('jetstream.profile_photo_disk', 'public');
$this->reset(['keynote_photo_path']);
}
}
1 change: 1 addition & 0 deletions app/Livewire/Users/UserFilteringList.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class UserFilteringList extends Component
public function mount()
{
$this->users = User::all()->sortBy('name');
$this->filter();
}

/**
Expand Down
30 changes: 30 additions & 0 deletions app/Models/Edition.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* @property boolean $is_participant_registration_opened
* @property boolean $is_company_registration_opened
* @property boolean $is_requesting_presentation_opened
* @property boolean $is_in_progress
* @property boolean $is_over
* @property string $displayed_state
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
Expand Down Expand Up @@ -144,6 +146,34 @@ public function isRequestingPresentationOpened(): Attribute
);
}

/**
* Determine whether the edition is in progress
* TODO: change the '||' to '&&' once the automation of the state change is implemented
*
* @return Attribute
*/
public function isInProgress(): Attribute
{
return Attribute::make(
get: fn() => $this->state == Edition::STATE_EXECUTION
|| (Carbon::now() >= $this->start_at && Carbon::now() <= $this->end_at)
);
}

/**
* Determine whether the edition is over
* NOTE: possibly redundant method in case state change is automated
*
* @return Attribute
*/
public function isOver(): Attribute
{
return Attribute::make(
get: fn() => $this->state == Edition::STATE_ARCHIVE
|| Carbon::now() >= $this->end_at
);
}

/**
* Gets an instance that represents the current edition, meaning the
* edition that is currently opened for registration, in state of enrollment or executed
Expand Down
4 changes: 2 additions & 2 deletions app/Models/Presentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function noConflicts(User $user): bool
$speakingStart = Carbon::parse($user->presenter_of->start);
$speakingEnd = Carbon::parse($user->presenter_of->start)
->copy()
->addMinutes($this->duration);
->addMinutes($user->presenter_of->duration);

if ($presentationEnd > $speakingStart && $presentationStart < $speakingEnd) {
return false;
Expand All @@ -189,7 +189,7 @@ public function noConflicts(User $user): bool
$enrolledStart = Carbon::parse($enrolledPresentation->start);
$enrolledEnd = Carbon::parse($enrolledPresentation->start)
->copy()
->addMinutes($this->duration);
->addMinutes($enrolledPresentation->duration);

if ($presentationEnd > $enrolledStart && $presentationStart < $enrolledEnd) {
return false;
Expand Down
16 changes: 3 additions & 13 deletions app/Policies/PresentationPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,9 @@ public function view(User $user, Presentation $presentation): bool
}
}

if (!Edition::current()) {
return $user->is_crew
|| $user->isPresenterOf($presentation);
}

return $user->is_crew
|| $user->isPresenterOf($presentation)
|| Edition::current()->is_final_programme_released;
|| optional(Edition::current())->is_final_programme_released;
}

/**
Expand All @@ -76,15 +71,10 @@ public function update(User $user, Presentation $presentation): bool
return false;
}

if (!Edition::current()) {
return $user->is_crew ||
$user->isPresenterOf($presentation);
}

return $user->is_crew ||
(
$user->isPresenterOf($presentation)
&& !Edition::current()->is_final_programme_released
&& !optional(Edition::current())->is_final_programme_released
);
}

Expand Down Expand Up @@ -119,7 +109,7 @@ public function request(User $user): bool
}

// Deny if the deadline for requesting has passed or not arrived yet
if (Edition::current() && !Edition::current()->is_requesting_presentation_opened) {
if (!optional(Edition::current())->is_requesting_presentation_opened) {
return false;
}

Expand Down
19 changes: 17 additions & 2 deletions app/View/Components/SidebarLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace App\View\Components;

use App\Models\Presentation;
use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\Component;

class SidebarLink extends Component
Expand All @@ -21,13 +23,26 @@ class SidebarLink extends Component
public function __construct($type, $route, $label, $icon, $roleColour, $param = '')
{
$this->route = $route;
$this->label = $label;
$this->param = $param;
$this->label = empty($label) && $param instanceof Presentation ? $this->determineLabelLength() : $label;
$this->icon = $icon;
$this->roleColour = $roleColour;
$this->param = $param;
$this->type = $type;
}

/**
* Determine how long should the label be
* so that it stays on one line in the side menu
*
* @return string
*/
public function determineLabelLength(): string
{
return strlen('View ' . $this->param->name) > 20 ?
substr('View ' . $this->param->name, 0, 20) . '...'
: 'View ' . $this->param->name;
}

/**
* Get the view / contents that represent the component.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
{{ $label }}
</dd>
<dd class="{{ $selectedStyle['viewAllBgColor'] }} {{ $selectedStyle['viewAllTextColor'] }} {{ $selectedStyle['viewAllBgDark'] }} w-full py-4 rounded-b-lg mt-4 font-bold text-sm">
<a href="{{ empty($param) ? route($route) : route($route, $param) }}" class="text-center block">
<a href="{{ empty($param) ? route($route) : route($route, $param) }}" class="text-center block" wire:navigate.hover>
View all
</a>
</dd>
Expand Down
Loading

0 comments on commit 82fcab5

Please sign in to comment.