Skip to content

Commit

Permalink
Merge pull request #3 from JayJull/v2-task
Browse files Browse the repository at this point in the history
V2 task
  • Loading branch information
punkestu authored Dec 1, 2024
2 parents 2af38fd + bd39c73 commit 2abe06c
Show file tree
Hide file tree
Showing 20 changed files with 588 additions and 117 deletions.
8 changes: 8 additions & 0 deletions app/Http/Controllers/NotificationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers;

use App\Models\Notification;
use App\Models\TaskNotification;
use Illuminate\Http\Request;

class NotificationController extends Controller
Expand All @@ -20,4 +21,11 @@ public function index()
}
return view('notification.index', compact('notifications'));
}

public function index_task()
{
$tasks = TaskNotification::where('user_id', auth()->user()->id)->get();
TaskNotification::where('user_id', auth()->user()->id)->update(['is_read' => true]);
return view('notification.task', ['notifications' => $tasks]);
}
}
6 changes: 5 additions & 1 deletion app/Http/Controllers/Rotasi/CabangController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Models\Cabang;
use App\Models\Kelas;
use App\Models\Konsep;
use App\Models\Task;
use Illuminate\Support\Facades\DB;

class CabangController extends Controller
Expand Down Expand Up @@ -254,13 +255,15 @@ public function delete($id)
public function konsep($id)
{
$konseps = Konsep::where('cabang_id', $id)->get();
return view('rotasi.cabang.konsep', ['konseps' => $konseps, 'cabang_id' => $id]);
$tasks = Task::all();
return view('rotasi.cabang.konsep', ['konseps' => $konseps, 'cabang_id' => $id, 'tasks' => $tasks]);
}

public function uploadKonsep($id, Request $request)
{
$request->validate([
'name' => 'required',
'task' => 'required|exists:tasks,id',
'berkas' => 'file|mimes:pdf|max:2048',
]);

Expand All @@ -279,6 +282,7 @@ public function uploadKonsep($id, Request $request)
$konsep->name = $request->name;
$konsep->cabang_id = $id;
$konsep->berkas = $berkas;
$konsep->task_id = $request->task;
$konsep->save();
return redirect()->back()->with('success', 'Konsep berhasil ditambahkan');
}
Expand Down
58 changes: 58 additions & 0 deletions app/Http/Controllers/TaskController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace App\Http\Controllers;

use App\Models\Task;
use App\Models\TaskNotification;
use App\Models\User;
use Illuminate\Http\Request;

class TaskController extends Controller
{
//
public function index()
{
$tasks = Task::all();
return view('personel.task.index', compact('tasks'));
}

public function detail($id)
{
$task = Task::find($id);
return view('personel.task.detail', compact('task'));
}

public function store(Request $request)
{
$request->validate([
"berkas" => "file|mimes:pdf,jpg,jpeg,png",
"deskripsi" => "required"
]);

if ($request->hasFile("berkas")) {
$file = $request->file('berkas');
$fileName = time() . '_' . $file->getClientOriginalName();
$berkas = "/storage/" . $file->storeAs('files', $fileName, 'public');
} else {
$request->validate([
"url" => "required"
]);
$berkas = $request->url;
}

$task = Task::create([
"deskripsi" => $request->deskripsi,
"berkas" => $berkas,
]);

$users = User::all();
foreach ($users as $user){
TaskNotification::create([
"user_id" => $user->id,
"task_id" => $task->id,
]);
}

return redirect()->route("task");
}
}
1 change: 1 addition & 0 deletions app/Models/Konsep.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ class Konsep extends Model
"name",
"berkas",
"cabang_id",
'task_id',
];
}
16 changes: 16 additions & 0 deletions app/Models/Task.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Models;

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

class Task extends Model
{
use HasFactory;

protected $fillable = [
'berkas', 'deskripsi'
];

}
26 changes: 26 additions & 0 deletions app/Models/TaskNotification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Models;

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

class TaskNotification extends Model
{
use HasFactory;
protected $fillable = [
'user_id',
'task_id',
'is_read'
];

public function task()
{
return $this->belongsTo(Task::class);
}

public function notread()
{
return $this->where("is_read", false)->get();
}
}
5 changes: 5 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,9 @@ public function profile()
{
return $this->hasOne(Profile::class);
}

public function notReadTaskNotifications()
{
return $this->hasMany(TaskNotification::class)->where('is_read', false);
}
}
29 changes: 29 additions & 0 deletions database/migrations/2024_11_27_113506_create_tasks_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('tasks', function (Blueprint $table) {
$table->id();
$table->string('berkas');
$table->text('deskripsi');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('tasks');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('konseps', function (Blueprint $table) {
$table->foreignId('task_id')->nullable()->constrained();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('konseps', function (Blueprint $table) {
$table->dropColumn('task_id');
});
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('task_notifications', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained();
$table->foreignId('task_id')->constrained();
$table->boolean('is_read')->default(0);

$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('task_notifications');
}
};
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion resources/views/components/header.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class="max-h-0 duration-300 absolute flex flex-col gap-1 bg-white mt-4 text-gray
($adminHasUnreadNotifications) ||
(auth()->user()->profile &&
auth()->user()->profile->cabang &&
auth()->user()->profile->cabang->notreadnotifications->count() > 0);
auth()->user()->profile->cabang->notreadnotifications->count() > 0) || (auth()->user()->notReadTaskNotifications->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 Down
6 changes: 5 additions & 1 deletion resources/views/notification/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
<body class="font-sans tracking-wider">
@include('components/header', ['static' => true])
@include('components.modal-component')
<main class="px-8 py-16">
<main class="px-8 py-16">
<h1 class="text-3xl font-semibold mb-2">Notifikasi</h1>
<div class="text-xl font-semibold text-gray-800 px-4 py-2 bg-gray-100 flex gap-4">
<a href="/rotasi/notification" class="underline">Notifikasi</a>
<a href="/rotasi/notification/task">Notifikasi Task</a>
</div>
<section class="flex flex-col gap-4 min-h-[50vh]">
@forelse ($notifications as $notification)
<div
Expand Down
34 changes: 34 additions & 0 deletions resources/views/notification/task.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">

<head>
@include('components/head')
<title>Air Mutasi | Profil</title>
</head>

<body class="font-sans tracking-wider">
@include('components/header', ['static' => true])
@include('components.modal-component')
<main class="px-8 py-16">
<h1 class="text-3xl font-semibold mb-2">Notifikasi Task</h1>
<div class="text-xl font-semibold text-gray-800 px-4 py-2 bg-gray-100 flex gap-4">
<a href="/rotasi/notification">Notifikasi</a>
<a href="/rotasi/notification/task" class="underline">Notifikasi Task</a>
</div>
<section class="flex flex-col gap-4 min-h-[50vh]">
@forelse ($notifications as $notification)
<a href="/personel/task/{{ $notification->task->id }}"
class="flex flex-col gap-2 p-4 bg-[#003285] text-white rounded-md">
<p>{{ $notification->task->deskripsi }}</p>
<p class="text-sm opacity-50 self-end">{{ $notification->created_at->diffForHumans() }}</p>
</a>
@empty
<p>Belum ada notifikasi</p>
@endforelse
</main>
@include('components.footer')
<script src="/script/nav.js"></script>
<script src="/script/chatbot.js"></script>
</body>

</html>
1 change: 1 addition & 0 deletions resources/views/personel/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class="py-2.5 px-5 ms-3 text-sm font-medium text-gray-900 focus:outline-none bg-
<div class="text-xl font-semibold text-gray-800 px-4 py-2 bg-gray-100 flex gap-4">
<a href="/personel" class="underline">Personel</a>
<a href="/personel/konsep">Konsep</a>
<a href="/personel/task">Task</a>
</div>
<div class="flex justify-between items-center px-4 py-2 bg-gray-100">
<form action="" class="gap-2 flex">
Expand Down
Loading

0 comments on commit 2abe06c

Please sign in to comment.