Skip to content

Commit

Permalink
patch
Browse files Browse the repository at this point in the history
  • Loading branch information
punkestu committed Nov 14, 2024
1 parent 8d730e4 commit 7fb24f7
Show file tree
Hide file tree
Showing 20 changed files with 91 additions and 15 deletions.
5 changes: 4 additions & 1 deletion app/Http/Controllers/NotificationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ class NotificationController extends Controller
{
public function index()
{
if(auth()->user()->profile->cabang) {
if (auth()->user()->profile && auth()->user()->profile->cabang) {
$notifications = auth()->user()->profile->cabang->notifications;
Notification::where('to', auth()->user()->profile->cabang->id)->update(['is_read' => true]);
} else if(auth()->user()->role->name == 'admin'){
$notifications = Notification::where('to', null)->order->get();
Notification::where('to', null)->update(['is_read' => true]);
} else {
$notifications = [];
}
Expand Down
22 changes: 22 additions & 0 deletions app/Http/Controllers/Rotasi/PengajuanController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Cabang;
use App\Models\Notification;
use App\Models\Pengajuan;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
Expand Down Expand Up @@ -119,6 +120,13 @@ public function input(Request $request)
]);
$pengajuanAlt->kompetensis()->createMany($kompetensi);
$pengajuan["secondary_pengajuan_id"] = $pengajuanAlt->id;
Notification::create([
'status' => $pengajuan['status'],
'to' => null,
'cabang_asal_id' => $pengajuan['lokasi_awal_id'],
'cabang_tujuan_id' => $request['lokasi_tujuan_alt_id'],
'pengajuan_id' => $pengajuanAlt->id
]);
} else {
$pengajuan["secondary_pengajuan_id"] = null;
}
Expand All @@ -140,6 +148,13 @@ public function input(Request $request)
]);
$pengajuanAlt2->kompetensis()->createMany($kompetensi);
$pengajuan["th3_pengajuan_id"] = $pengajuanAlt2->id;
Notification::create([
'status' => $pengajuan['status'],
'to' => null,
'cabang_asal_id' => $pengajuan['lokasi_awal_id'],
'cabang_tujuan_id' => $request['lokasi_tujuan_alt2_id'],
'pengajuan_id' => $pengajuanAlt2->id
]);
} else {
$pengajuan["th3_pengajuan_id"] = null;
}
Expand All @@ -161,6 +176,13 @@ public function input(Request $request)
'th3_pengajuan_id' => $pengajuan['th3_pengajuan_id']
]);
$pengajuan->kompetensis()->createMany($kompetensi);
Notification::create([
'status' => $pengajuan['status'],
'to' => null,
'cabang_asal_id' => $pengajuan['lokasi_awal_id'],
'cabang_tujuan_id' => $pengajuan['lokasi_tujuan_id'],
'pengajuan_id' => $pengajuan->id
]);
DB::commit();

return redirect()->back()->with('success', 'Data berhasil disimpan');
Expand Down
8 changes: 8 additions & 0 deletions app/Http/Controllers/Rotasi/SelektifAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ public function selektif($id, Request $request)
'cabang_tujuan_id' => $pengajuan->lokasi_tujuan_id,
'pengajuan_id' => $pengajuan->id
]);

$notification = Notification::create([
'status' => $request->status,
'to' => null,
'cabang_asal_id' => $pengajuan->lokasi_awal_id,
'cabang_tujuan_id' => $pengajuan->lokasi_tujuan_id,
'pengajuan_id' => $pengajuan->id
]);
$notification->save();
if ($pengajuan->lokasi_awal_id != $pengajuan->lokasi_tujuan_id) {
$notification = Notification::create([
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Cabang.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Cabang extends Model

public function notifications()
{
return $this->hasMany(Notification::class, 'to');
return $this->hasMany(Notification::class, 'to')->orderBy('created_at', 'desc');
}

public function notreadnotifications()
Expand Down
37 changes: 37 additions & 0 deletions app/Providers/NotificationProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace App\Providers;

use App\Models\Notification;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\ServiceProvider;

class NotificationProvider extends ServiceProvider
{
/**
* Register services.
*/
public function register(): void
{
//
}

/**
* Bootstrap services.
*/
public function boot(): void
{
view()->composer('*', function ($view) {
if (Auth::check()) {
$user = Auth::user();

$hasUnreadNotifications = false;
if ($user->role->name === 'admin') {
$hasUnreadNotifications = Notification::where('to', null)->where('is_read', false)->count() > 0;
}

$view->with('adminHasUnreadNotifications', $hasUnreadNotifications);
}
});
}
}
1 change: 1 addition & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
Webklex\PDFMerger\Providers\PDFMergerServiceProvider::class,
App\Providers\NotificationProvider::class,
])->toArray(),

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function up(): void
Schema::create('notifications', function (Blueprint $table) {
$table->id();
$table->string("status");
$table->foreignId("to")->constrained("cabangs")->onDelete("cascade");
$table->foreignId("to")->nullable()->constrained("cabangs")->onDelete("cascade");
$table->boolean("is_read")->default(false);
$table->foreignId("cabang_asal_id")->constrained("cabangs")->onDelete("cascade");
$table->foreignId("cabang_tujuan_id")->constrained("cabangs")->onDelete("cascade");
Expand Down
Binary file added public/images/backgrounds/LOGIN.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed public/images/backgrounds/LOGIN.png
Binary file not shown.
Binary file added public/images/slider/1.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/slider/2.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/slider/3.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/slider/4.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/slider/5.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/slider/6.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/slider/7.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions resources/views/auth/login.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<body class="font-sans tracking-wider">
@include('components.modal-component')
<main class="h-screen flex justify-between">
<img src="/images/thumbnail1.jpeg" alt="bg" class="-z-10 absolute w-screen h-screen object-cover">
<img src="/images/backgrounds/LOGIN.jpeg" alt="bg" class="-z-10 absolute w-screen h-screen object-cover">
<form action="/login" method="post"
class="h-full bg-opacity-70 backdrop-blur-lg w-full sm:w-1/2 xl:w-1/3 flex flex-col justify-center gap-4 bg-white px-8 py-16 shadow-black shadow-md">
class="h-full bg-opacity-50 backdrop-blur-lg w-full sm:w-1/2 xl:w-1/3 flex flex-col justify-center gap-4 bg-white px-8 py-16 shadow-black shadow-md">
<a href="/" class="flex justify-center"><img src="/images/logo.svg" alt="logo" class="max-h-12"></a>
@csrf
<div
Expand Down
12 changes: 7 additions & 5 deletions resources/views/components/header.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ class="max-h-0 duration-300 absolute flex flex-col gap-1 bg-white mt-4 text-gray
@auth
@php
$hasNotification =
auth()->user()->profile &&
auth()->user()->profile->cabang &&
auth()->user()->profile->cabang->notreadnotifications->count() > 0;
($adminHasUnreadNotifications) ||
(auth()->user()->profile &&
auth()->user()->profile->cabang &&
auth()->user()->profile->cabang->notreadnotifications->count() > 0);
@endphp
<a href="/rotasi/notification"
class="flex aspect-square border-2 rounded-full p-1 {{ $hasNotification ? 'border-red-500' : 'border-gray-800' }}">
Expand All @@ -37,8 +38,9 @@ class="flex aspect-square border-2 rounded-full p-1 {{ $hasNotification ? 'borde
<path
d="M17.133 12.632v-1.8a5.406 5.406 0 0 0-4.154-5.262.955.955 0 0 0 .021-.106V3.1a1 1 0 0 0-2 0v2.364a.955.955 0 0 0 .021.106 5.406 5.406 0 0 0-4.154 5.262v1.8C6.867 15.018 5 15.614 5 16.807 5 17.4 5 18 5.538 18h12.924C19 18 19 17.4 19 16.807c0-1.193-1.867-1.789-1.867-4.175ZM8.823 19a3.453 3.453 0 0 0 6.354 0H8.823Z" />
</svg>
@if (
auth()->user()->profile && auth()->user()->profile->cabang && auth()->user()->profile->cabang->notreadnotifications->count() > 0)
@if (auth()->user()->profile &&
auth()->user()->profile->cabang &&
auth()->user()->profile->cabang->notreadnotifications->count() > 0)
<p class="bg-blue-500 w-2 h-2 rounded-full"></p>
@endif
</a>
Expand Down
11 changes: 7 additions & 4 deletions resources/views/notification/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
<h1 class="text-3xl font-semibold mb-2">Notifikasi</h1>
<section class="flex flex-col gap-4 min-h-[50vh]">
@forelse ($notifications as $notification)
<div class="flex flex-col gap-2 p-4 bg-[#003285] text-white rounded-md">
<div
class="flex flex-col gap-2 p-4 {{ $notification->status == 'dapat' ? 'bg-[#003285]' : ($notification->status == 'tidak' ? 'Tidak bg-red-900' : ($notification->status == 'diajukan' ? 'bg-gray-800' : 'bg-green-900')) }} text-white rounded-md">
<div class="flex flex-wrap gap-6">
<aside>
<p>Status:</p>
<strong>{{ $notification->status == 'dapat' ? 'Diterima' : ($notification->status == 'tidak' ? 'Tidak Diterima' : 'Disetujui') }}</strong>
<strong>{{ $notification->status == 'dapat' ? 'Diterima' : ($notification->status == 'tidak' ? 'Tidak Diterima' : ($notification->status == 'diajukan' ? 'Diajukan' : 'Disetujui')) }}</strong>
</aside>
<aside>
<p>Atas nama:</p>
Expand All @@ -26,11 +27,13 @@
<aside>
<p>Dari:</p>
<strong>{{ $notification->pengajuan->lokasiAwal->nama }}
({{ $notification->pengajuan->posisi_sekarang }})</strong>
({{ $notification->pengajuan->posisi_sekarang }})
</strong>
</aside>
<aside>
<p>Ke:</p>
<strong>{{ $notification->pengajuan->lokasiTujuan->nama }} ({{ $notification->pengajuan->posisi_tujuan }})</strong>
<strong>{{ $notification->pengajuan->lokasiTujuan->nama }}
({{ $notification->pengajuan->posisi_tujuan }})</strong>
</aside>
</div>
<p class="text-sm opacity-50 self-end">{{ $notification->created_at->diffForHumans() }}</p>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/welcome.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<aside class="md:w-2/5 aspect-video flex" id="carousel">
@for ($i = 0; $i < 2; $i++)
<img class="{{ $i != 0 ? 'w-0' : '' }} object-cover rounded-md duration-300"
src="/images/thumbnail{{ $i + 1 }}.jpeg" alt="thumbnail-{{ $i }}">
src="/images/slider/{{ $i + 1 }}.jpeg" alt="thumbnail-{{ $i }}">
@endfor
</aside>
</section>
Expand Down

0 comments on commit 7fb24f7

Please sign in to comment.