Skip to content

Commit

Permalink
Merge pull request #139 from RiwRiwara/AdminSystem
Browse files Browse the repository at this point in the history
Admin system
  • Loading branch information
RiwRiwara authored May 8, 2024
2 parents fb5c18f + 653b2fb commit e0d76ad
Show file tree
Hide file tree
Showing 15 changed files with 673 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/Admin/Event/AllEventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ public function __invoke(Request $request)
'all_events' => $all_events,
];

return view('admin.admin_events_dashboard', compact('events_data'));
return view('admin.events-dashboard', compact('events_data'));
}
}
48 changes: 48 additions & 0 deletions app/Http/Controllers/Admin/Event/EventDetailController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace App\Http\Controllers\Admin\Event;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Event;

class EventDetailController extends Controller
{
const TEMPLATE_PAGE = 'admin.event-detail';

public function __invoke(Request $request, $event_id)
{
$event = Event::where('event_id', $event_id)->firstOrFail();
$this->authorize('view', $event);

$event_types = $this->prepate_type_data($event);
$event->event_types = $event_types;

$Summary = $event->getSummary();

$page_data = [
'breadcrumbItems' => [
['label' => 'Events Dashboard', 'url' => route('events-dashboard')],
['label' => $event->event_name],
],
'event_types' => \App\Models\EventType::all(),
'badge_types' => \App\Models\Badge::all(),
'default_event_img' => config('azure.default_img.event_banner'),
];

return view(EventDetailController::TEMPLATE_PAGE, compact('page_data', 'event'));
}


private function prepate_type_data($event)
{
$event_types = $event->categories;
$event_types = explode(',', $event_types);

$event_types = collect($event_types)->map(function ($event_type) {
return 'type_' . $event_type;
});

return $event_types;
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/Admin/Users/AllUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ public function __invoke(Request $request)
'all_users' => $all_users,
];

return view('admin.admin_users_dashboard', compact('users_data'));
return view('admin.users-dashboard', compact('users_data'));
}
}
86 changes: 86 additions & 0 deletions app/Http/Controllers/Admin/Users/UserDetailController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace App\Http\Controllers\Admin\Users;

use App\Http\Controllers\Controller;
use App\Http\Requests\ProfileUpdateRequest;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Http\Request;
use App\Constants\Cities;
use App\Constants\Districts;
use App\Constants\Provinces;
use App\Constants\Gender;
use App\Constants\Time;
use App\Models\User;

class UserDetailController extends Controller
{
public function __invoke(Request $request, $user_id)
{

$user = User::where('user_id', $user_id)->first();
if (!$user) {
toastr()->addError('User not found');
return redirect()->back();
}
$isThai = app()->getLocale() === 'th';

$user->gender = Gender::getGenderById($user->gender);
$user->date_of_birth = (new Time($user->date_of_birth, $isThai))->getDateBirthObject();

$page_data = [
'isThai' => $isThai,
'provinces' => Provinces::provinces(),
'districts' => Cities::cities(),
'cities' => Districts::districts(),
'gender' => Gender::gender(),
'breadcrumbItems' => [
['label' => 'User Dashboard', 'url' => route('users-dashboard')],
['label' => $user->first_name . ' ' . $user->last_name],
]

];

return view('admin.profileDetail', compact('user', 'page_data'));
}
/**
* Update the user's profile information.
*/
public function update(ProfileUpdateRequest $request): RedirectResponse
{
$request->user()->fill($request->validated());

if ($request->user()->isDirty('email')) {
$request->user()->email_verified_at = null;
}

$request->user()->save();

toastr()->addSuccess(__('success.profile_update'));

return Redirect::route('profile.edit')->with('status', 'profile-updated');
}

/**
* Delete the user's account.
*/
public function destroy(Request $request): RedirectResponse
{
$request->validateWithBag('userDeletion', [
'password' => ['required', 'current_password'],
]);

$user = $request->user();

Auth::logout();

$user->delete();

$request->session()->invalidate();
$request->session()->regenerateToken();

return Redirect::to('/');
}
}
2 changes: 1 addition & 1 deletion app/Livewire/EditableFieldDropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function mount($fieldName, $label_show, $optionsObject)

$isThai = app()->getLocale() === 'th';
$field_Language = $isThai ? 'name_th' : 'name_en';
$this->value_show = auth()->user()->$fieldName[$field_Language];
// $this->value_show = auth()->user()->$fieldName[$field_Language];

$this->oldValue = auth()->user()->$fieldName;
$this->newValue = $this->oldValue;
Expand Down
2 changes: 1 addition & 1 deletion app/Policies/EventPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function viewAny(User $user): bool
public function view(User $user, Event $event) : bool
{
$is_own = $user->user_id === $event->organizer_id;
$is_admin = $user->role === 'admin';
$is_admin = $user->role_id == 1;
return $is_own || $is_admin;
}

Expand Down
1 change: 1 addition & 0 deletions lang/en/event.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
'add_type' => 'Seelct Event Type',
'detail' => 'Detail',
'event_name' => 'Event Name',
'event_org' => 'Organizer',
'event_location' => 'Event Location',

'specific' => 'Set Date',
Expand Down
1 change: 1 addition & 0 deletions lang/th/event.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
'add_type' => 'เลือกประเภทของอีเวนต์',
'detail' => 'รายละเอียด',
'event_name' => 'ชื่ออีเวนต์',
'event_org' => 'ผู้จัดอีเวนต์',
'event_location' => 'สถานที่จัดงาน',
'specific' => 'กำหนดวันที่',
'announce_after' => 'ประกาศภายหลัง',
Expand Down
Loading

0 comments on commit e0d76ad

Please sign in to comment.