Skip to content

Commit

Permalink
Merge pull request #200 from yungifez/dev
Browse files Browse the repository at this point in the history
Added ability to create custom timetable items, redesign to timetable management area, UI changes
  • Loading branch information
yungifez authored Jan 5, 2023
2 parents b1db363 + 368fcef commit ab55cec
Show file tree
Hide file tree
Showing 20 changed files with 236 additions and 97 deletions.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@ MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

LOGO_PATH="img/logo/logo.jpg"

#customize portal look and feel see https://github.com/jeroennoten/Laravel-AdminLTE/wiki/Layout-and-Styling-Configuration#admin-panel-classes

ADMINLTE_CLASSES_SIDEBAR="sidebar-dark-primary elevation-4"
ADMINLTE_CLASSES_TOPNAV="navbar-white navbar-light"
1 change: 1 addition & 0 deletions app/Http/Livewire/DeleteModal.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class DeleteModal extends Component
public $action;
public $item_name;
public $button_class;
public $delete_message;

public function render()
{
Expand Down
21 changes: 21 additions & 0 deletions app/Http/Livewire/ManageTimetable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,39 @@

class ManageTimetable extends Component
{
protected $listeners = ['timetableCellClicked' => 'setSelectFields'];
public Timetable $timetable;
public $timeSlots;
public ?int $timeSlot;
public $weekdays;
public $weekday;
public $subjects;
public $customItems;
public $types;
public $type;

public function mount(TimetableService $timetableService)
{
$this->timeSlots = $this->timetable->timeSlots->sortBy('start_time')->load('weekdays');
if ($this->timeSlots->isNotEmpty()) {
$this->timeSlot = $this->timeSlots->first()->id;
}
$this->weekdays = Weekday::all();
$this->subjects = $this->timetable->MyClass->subjects;
$this->customItems = $timetableService->getAllCustomTimetableItem();
$this->types = ['subject', 'customTimetableItem'];
$this->type = $this->types[0];
}

public function setSelectFields($records)
{
$this->timeSlot = $records['timeSlot']['id'];
$this->weekday = $records['weekday']['id'];
}

public function updatedTimeSlot()
{
//
}

public function render()
Expand Down
15 changes: 14 additions & 1 deletion app/Http/Livewire/ShowTimetable.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Livewire;

use App\Models\Timetable;
use App\Models\TimetableTimeSlot;
use App\Models\Weekday;
use App\Services\Timetable\TimetableService;
use Livewire\Component;
Expand All @@ -14,15 +15,27 @@ class ShowTimetable extends Component
public $subjects;
public $customItems;

/**
* Determine if to show the timetable.
*
* @var bool
*/
public bool $showDescription = true;

public function mount(TimetableService $timetableService)
{
$this->timeSlots = $this->timetable->timeSlots->sortBy('start_time')->load('weekdays');
// dd($this->timeSlots);
$this->weekdays = Weekday::all();
$this->subjects = $this->timetable->MyClass->subjects;
$this->subjects = $this->timetable->load('myClass')->MyClass->subjects;
$this->customItems = $timetableService->getAllCustomTimetableItem();
}

public function emitCellInformationDetail(TimetableTimeSlot $timeSlot, Weekday $weekday)
{
$this->emit('timetableCellClicked', ['timeSlot' => $timeSlot, 'weekday' => $weekday]);
}

public function render()
{
return view('livewire.show-timetable');
Expand Down
1 change: 1 addition & 0 deletions app/Http/Requests/ClassGroupStoreRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function rules()
return [
'name' => [
'required',
'max:255',
Rule::unique('class_groups')->where(fn ($query) => $query->where('school_id', $this->input('school_id') ?? auth()->user()->school_id)),
],
];
Expand Down
1 change: 1 addition & 0 deletions app/Http/Requests/MyClassStoreRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function rules()
return [
'name' => [
'required',
'max:255',
//checks if there is a class with a name in class group
Rule::unique('my_classes', 'name')->where(fn ($query) => $query->where('class_group_id', $classGroupId)),
],
Expand Down
1 change: 1 addition & 0 deletions app/Http/Requests/MyClassUpdateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function rules()
return [
'name' => [
'required',
'max:255',
//figure it out before changing
Rule::unique('my_classes', 'name')->ignore($myClassId)->where(fn ($query) => $query->where('class_group_id', $classGroupId)),
],
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Requests/SchoolStoreRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function rules()
{
return [
'name' => 'required|max:255',
'address' => 'required|min:8',
'address' => 'required|min:8|max:1000',
];
}
}
4 changes: 2 additions & 2 deletions app/Http/Requests/SchoolUpdateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public function rules()
{
return [
'name' => 'required|max:255',
'address' => 'required|min:8',
'initials' => 'required|min:2',
'address' => 'required|min:8|max:1000',
'initials' => 'required|min:2|max:30',
'phone' => 'nullable|regex:/^([0-9\s\-\+\(\)]*)$/|min:5',
];
}
Expand Down
1 change: 1 addition & 0 deletions app/Http/Requests/SectionStoreRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function rules()
return [
'name' => [
'required',
'max:255',
Rule::unique('sections', 'name')->where('my_class_id', $myClassId),
],
'my_class_id' => [
Expand Down
1 change: 1 addition & 0 deletions app/Http/Requests/SectionUpdateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function rules()
return [
'name' => [
'required',
'max:255',
Rule::unique('sections', 'name')->ignore($sectionId)->where('my_class_id', $myClassId),
],
];
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Requests/SemesterStoreRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SemesterStoreRequest extends FormRequest
public function rules()
{
return [
'name' => 'string|max:256',
'name' => 'string|max:255',
];
}
}
26 changes: 26 additions & 0 deletions app/Models/TimetableTimeSlot.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Models;

use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

Expand All @@ -14,6 +15,31 @@ class TimetableTimeSlot extends Model
'stop_time',
'timetable_id',
];
protected $getDateFormat = 'H:i';

public function startTime(): Attribute
{
return new Attribute(
get: fn ($value) => \Carbon\Carbon::parse($value)->format($this->getDateFormat),
set: fn ($value) => $value,
);
}

public function stopTime(): Attribute
{
return new Attribute(
get: fn ($value) => \Carbon\Carbon::parse($value)->format($this->getDateFormat),
set: fn ($value) => $value,
);
}

public function name(): Attribute
{
return new Attribute(
get: fn ($value) => sprintf('%s - %s', $this->start_time, $this->stop_time),
set: fn ($value) => "$this->start_time - $this->stop_time",
);
}

public function timetable()
{
Expand Down
21 changes: 21 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,25 @@ public function subjects(): BelongsToMany
{
return $this->belongsToMany(Subject::class);
}

public function adminlte_image()
{
return $this->defaultProfilePhotoUrl();
}

public function adminlte_desc()
{
$description = [];
if ($this->school) {
$description[] = $this->school->academicYear ? 'Academic year: '.$this->school->academicYear->name() : '';
$description[] = $this->school->semester ? 'Semester: '.$this->school->semester->name : '';
}

return $descriptionString = implode(', ', $description);
}

public function adminlte_profile_url()
{
return 'profile/username';
}
}
7 changes: 4 additions & 3 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ public function register()
Paginator::useBootstrap();
Schema::defaultStringLength(100);
Relation::enforceMorphMap([
'subject' => "App\Models\Subject",
'custom' => "App\Models\CustomTimetableItems",
'App\Models\User' => 'App\Models\User',
'subject' => "App\Models\Subject",
'custom' => "App\Models\CustomTimetableItems",
'App\Models\User' => 'App\Models\User',
'App\Models\AccountApplication' => 'App\Models\AccountApplication',
]);
}

Expand Down
16 changes: 8 additions & 8 deletions config/adminlte.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@
*/

'usermenu_enabled' => true,
'usermenu_header' => false,
'usermenu_header_class' => 'bg-primary',
'usermenu_image' => false,
'usermenu_desc' => false,
'usermenu_header' => true,
'usermenu_header_class' => 'bg-indigo',
'usermenu_image' => true,
'usermenu_desc' => true,
'usermenu_profile_url' => false,

/*
Expand All @@ -85,7 +85,7 @@

'layout_topnav' => null,
'layout_boxed' => null,
'layout_fixed_sidebar' => null,
'layout_fixed_sidebar' => true,
'layout_fixed_navbar' => null,
'layout_fixed_footer' => null,
'layout_dark_mode' => null,
Expand Down Expand Up @@ -127,9 +127,9 @@
'classes_content_wrapper' => '',
'classes_content_header' => '',
'classes_content' => '',
'classes_sidebar' => 'sidebar-dark-primary elevation-4',
'classes_sidebar' => env('ADMINLTE_CLASSES_SIDEBAR', 'sidebar-dark-primary elevation-4'),
'classes_sidebar_nav' => '',
'classes_topnav' => 'navbar-white navbar-light',
'classes_topnav' => env('ADMINLTE_CLASSES_TOPNAV', 'navbar-white navbar-light'),
'classes_topnav_nav' => 'navbar-expand',
'classes_topnav_container' => 'container',

Expand All @@ -148,7 +148,7 @@
'sidebar_mini' => 'lg',
'sidebar_collapse' => false,
'sidebar_collapse_auto_size' => false,
'sidebar_collapse_remember' => false,
'sidebar_collapse_remember' => true,
'sidebar_collapse_remember_no_transition' => true,
'sidebar_scrollbar_theme' => 'os-theme-light',
'sidebar_scrollbar_auto_hide' => 'l',
Expand Down
10 changes: 7 additions & 3 deletions resources/views/livewire/delete-modal.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@
<div>
<i class="fas fa-trash text-danger fa-6x py-3"></i>
</div>
<p>This item "{{$item_name ?? ''}}" and all related records would be deleted</p>
@isset($delete_message)
{{$delete_message}}
@else
<p>This item "{{$item_name ?? ''}}" and all related records would be deleted</p>
@endisset
</div>
<x-slot name="footerSlot">
<x-adminlte-button label="close" data-dismiss="modal" theme="secondary" class="mr-auto"/>
<x-adminlte-button label="Close" data-dismiss="modal" theme="secondary" class="mr-auto"/>
<form action="{{$action}}" method="post">
@csrf
@method('delete')
<x-adminlte-button label="continue with delete" type="submit" theme="danger"/>
<x-adminlte-button :label='"Continue With $button_label"' type="submit" theme="danger"/>
</form>
</x-slot>
</x-adminlte-modal>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/livewire/list-promotions-table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
],
],)</td>
<td>
@livewire('delete-modal', ['modal_id' => $promotion->id ,"action" => route('students.promotions.reset', $promotion->id), 'item_name' => "would be reset, all students returned to the old class", 'button_label' => "Reset"])
@livewire('delete-modal', ['modal_id' => $promotion->id ,"action" => route('students.promotions.reset', $promotion->id), 'delete_message' => "This promotion would be reset and all students returned back to original class", 'button_label' => "Reset"])
</td>
</tr>
@endforeach
Expand Down
Loading

0 comments on commit ab55cec

Please sign in to comment.