feat(usermanagement): tambahkan fitur manajemen posisi
- Tambahkan model `Position` dengan atribut `code`, `name`, `level`, serta logging aktivitas dan relasi ke `roles`. - Tambahkan migrasi untuk membuat tabel `positions` dengan soft deletes. - Tambahkan `PositionExport` untuk kebutuhan ekspor data posisi ke Excel dengan penyaringan berdasarkan kata kunci. - Buat `PositionsController` untuk CRUD posisi, termasuk validasi, ekspor, dan data API untuk DataTables. - Metode: `index`, `create`, `store`, `edit`, `update`, `destroy`, `export`, `dataForDatatables`. - Tambahkan validasi berbasis request `PositionRequest` untuk memastikan data valid sebelum disimpan/diubah. - Tambahkan tampilan blade untuk daftar posisi (`index.blade.php`) dan form tambah/edit posisi (`create.blade.php`) dengan dukungan DataTables dan SweetAlert. - Perbarui file `module.json` untuk menambahkan menu "Positions" di User Management. - Tambahkan breadcrumbs untuk halaman posisi (daftar, tambah, edit) di file `breadcrumbs.php`. - Perbarui `routes/web.php` untuk menambahkan route terkait posisi. Fitur ini memungkinkan pengelolaan posisi lengkap termasuk CRUD, ekspor, dan integrasi dengan DataTables.
This commit is contained in:
66
app/Exports/PositionExport.php
Normal file
66
app/Exports/PositionExport.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Usermanagement\Exports;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Modules\Usermanagement\Models\Position;
|
||||
|
||||
class PositionExport implements WithColumnFormatting, WithHeadings, FromCollection, WithMapping
|
||||
{
|
||||
protected $search;
|
||||
|
||||
public function __construct($search = null)
|
||||
{
|
||||
$this->search = $search;
|
||||
}
|
||||
|
||||
public function collection()
|
||||
{
|
||||
$query = Position::query();
|
||||
|
||||
if (!empty($this->search)) {
|
||||
$search = $this->search;
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->whereRaw('LOWER(code) LIKE ?', ['%' . strtolower($search) . '%'])
|
||||
->orWhereRaw('LOWER(name) LIKE ?', ['%' . strtolower($search) . '%'])
|
||||
->orWhereRaw('CAST(level AS TEXT) LIKE ?', ['%' . $search . '%']);
|
||||
});
|
||||
}
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
return [
|
||||
$row->id,
|
||||
$row->code,
|
||||
$row->name,
|
||||
$row->level,
|
||||
$row->created_at
|
||||
];
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'ID',
|
||||
'Code',
|
||||
'Name',
|
||||
'Tingkat Jabatan',
|
||||
'Created At'
|
||||
];
|
||||
}
|
||||
|
||||
public function columnFormats(): array
|
||||
{
|
||||
return [
|
||||
'A' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER,
|
||||
'D' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER,
|
||||
'E' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_DATETIME
|
||||
];
|
||||
}
|
||||
}
|
||||
332
app/Http/Controllers/PositionsController.php
Normal file
332
app/Http/Controllers/PositionsController.php
Normal file
@@ -0,0 +1,332 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Usermanagement\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Modules\Usermanagement\Exports\PositionExport;
|
||||
use Modules\Usermanagement\Http\Requests\PositionRequest;
|
||||
use Modules\Usermanagement\Models\Position;
|
||||
|
||||
/**
|
||||
* Class PositionsController
|
||||
*
|
||||
* This controller is responsible for managing positions within the application.
|
||||
*
|
||||
* @package Modules\Usermanagement\Http\Controllers
|
||||
*/
|
||||
class PositionsController extends Controller
|
||||
{
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Auth\Authenticatable|null
|
||||
*/
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* PositionsController constructor.
|
||||
*
|
||||
* Initializes the user property with the authenticated user.
|
||||
*/
|
||||
/*public function __construct()
|
||||
{
|
||||
$this->middleware(function ($request, $next) {
|
||||
$this->user = Auth::guard('web')->user();
|
||||
return $next($request);
|
||||
});
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
// Get the authenticated user
|
||||
$user = Auth::guard('web')->user();
|
||||
|
||||
// Check if the authenticated user has the required permission to view positions
|
||||
if (is_null($user) || !$user->can('positions.read')) {
|
||||
abort(403, 'Sorry! You are not allowed to view positions.');
|
||||
}
|
||||
|
||||
// Fetch all positions from the database
|
||||
$positions = Position::all();
|
||||
|
||||
// Return the view for displaying the positions
|
||||
return view('usermanagement::positions.index', compact('positions'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Modules\Usermanagement\Http\Requests\PositionRequest $request
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(PositionRequest $request)
|
||||
{
|
||||
// Get the authenticated user
|
||||
$user = Auth::guard('web')->user();
|
||||
|
||||
// Check if the authenticated user has the required permission to store positions
|
||||
if (is_null($user) || !$user->can('positions.create')) {
|
||||
abort(403, 'Sorry! You are not allowed to store positions.');
|
||||
}
|
||||
|
||||
// Get validated data
|
||||
$validated = $request->validated();
|
||||
|
||||
try {
|
||||
// If no errors, save the position to the database
|
||||
$position = Position::create($validated);
|
||||
|
||||
// Redirect to the positions index page with a success message
|
||||
return redirect()->route('users.positions.index')
|
||||
->with('success', 'Position created successfully.');
|
||||
} catch (Exception $e) {
|
||||
// If an error occurs, redirect back with an error message
|
||||
return redirect()->back()
|
||||
->with('error', 'An error occurred while creating the position: ' . $e->getMessage())
|
||||
->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
// Get the authenticated user
|
||||
$user = Auth::guard('web')->user();
|
||||
|
||||
// Check if the authenticated user has the required permission to create positions
|
||||
if (is_null($user) || !$user->can('positions.create')) {
|
||||
abort(403, 'Sorry! You are not allowed to create positions.');
|
||||
}
|
||||
|
||||
// Return the view for creating a new position
|
||||
return view('usermanagement::positions.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
// Get the authenticated user
|
||||
$user = Auth::guard('web')->user();
|
||||
|
||||
// Check if the authenticated user has the required permission to view positions
|
||||
if (is_null($user) || !$user->can('positions.read')) {
|
||||
abort(403, 'Sorry! You are not allowed to view positions.');
|
||||
}
|
||||
|
||||
// Find the position by ID
|
||||
$position = Position::findOrFail($id);
|
||||
|
||||
// Return the view for displaying the position
|
||||
return view('usermanagement::positions.show', compact('position'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
// Get the authenticated user
|
||||
$user = Auth::guard('web')->user();
|
||||
|
||||
// Check if the authenticated user has the required permission to edit positions
|
||||
if (is_null($user) || !$user->can('positions.update')) {
|
||||
abort(403, 'Sorry! You are not allowed to edit positions.');
|
||||
}
|
||||
|
||||
// Find the position by ID
|
||||
$position = Position::findOrFail($id);
|
||||
|
||||
// Return the view for editing the position
|
||||
return view('usermanagement::positions.create', compact('position'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Modules\Usermanagement\Http\Requests\PositionRequest $request
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(PositionRequest $request, $id)
|
||||
{
|
||||
// Get the authenticated user
|
||||
$user = Auth::guard('web')->user();
|
||||
|
||||
// Check if the authenticated user has the required permission to update positions
|
||||
if (is_null($user) || !$user->can('positions.update')) {
|
||||
abort(403, 'Sorry! You are not allowed to update positions.');
|
||||
}
|
||||
|
||||
// Find the position by ID
|
||||
$position = Position::findOrFail($id);
|
||||
|
||||
// Get validated data
|
||||
$validated = $request->validated();
|
||||
|
||||
try {
|
||||
// If no errors, update the position in the database
|
||||
$position->update($validated);
|
||||
|
||||
// Redirect to the positions index page with a success message
|
||||
return redirect()->route('users.positions.index')
|
||||
->with('success', 'Position updated successfully.');
|
||||
} catch (Exception $e) {
|
||||
// If an error occurs, redirect back with an error message
|
||||
return redirect()->back()
|
||||
->with('error', 'An error occurred while updating the position: ' . $e->getMessage())
|
||||
->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
// Get the authenticated user
|
||||
$user = Auth::guard('web')->user();
|
||||
|
||||
// Check if the authenticated user has the required permission to delete positions
|
||||
if (is_null($user) || !$user->can('positions.delete')) {
|
||||
abort(403, 'Sorry! You are not allowed to delete positions.');
|
||||
}
|
||||
|
||||
// Find the position by ID
|
||||
$position = Position::findOrFail($id);
|
||||
|
||||
try {
|
||||
// If no errors, delete the position from the database
|
||||
$position->delete();
|
||||
|
||||
// Redirect to the positions index page with a success message
|
||||
return redirect()->route('users.positions.index')
|
||||
->with('success', 'Position deleted successfully.');
|
||||
} catch (Exception $e) {
|
||||
// If an error occurs, redirect back with an error message
|
||||
return redirect()->back()
|
||||
->with('error', 'An error occurred while deleting the position: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process support datatables ajax request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function dataForDatatables(Request $request)
|
||||
{
|
||||
// Get the authenticated user
|
||||
$user = Auth::guard('web')->user();
|
||||
|
||||
// Check if the authenticated user has the required permission to view positions
|
||||
if (is_null($user) || !$user->can('positions.read')) {
|
||||
abort(403, 'Sorry! You are not allowed to view positions.');
|
||||
}
|
||||
|
||||
// Retrieve data from the database
|
||||
$query = Position::query();
|
||||
|
||||
// Apply search filter if provided
|
||||
if ($request->has('search') && !empty($request->get('search'))) {
|
||||
$search = $request->get('search');
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->whereRaw('LOWER(code) LIKE ?', ['%' . strtolower($search) . '%'])
|
||||
->orWhereRaw('LOWER(name) LIKE ?', ['%' . strtolower($search) . '%'])
|
||||
->orWhereRaw('CAST(level AS TEXT) LIKE ?', ['%' . $search . '%']);
|
||||
});
|
||||
}
|
||||
|
||||
// Apply sorting if provided
|
||||
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
|
||||
$order = $request->get('sortOrder');
|
||||
$column = $request->get('sortField');
|
||||
$query->orderBy($column, $order);
|
||||
}
|
||||
|
||||
// Get the total count of records
|
||||
$totalRecords = $query->count();
|
||||
|
||||
// Apply pagination if provided
|
||||
if ($request->has('page') && $request->has('size')) {
|
||||
$page = $request->get('page');
|
||||
$size = $request->get('size');
|
||||
$offset = ($page - 1) * $size; // Calculate the offset
|
||||
|
||||
$query->skip($offset)->take($size);
|
||||
}
|
||||
|
||||
// Get the filtered count of records
|
||||
$filteredRecords = $query->count();
|
||||
|
||||
// Get the data for the current page
|
||||
$positions = $query->get();
|
||||
|
||||
// Calculate the page count
|
||||
$pageCount = ceil($totalRecords / $request->get('size'));
|
||||
|
||||
// Calculate the current page number
|
||||
$currentPage = 0 + 1;
|
||||
|
||||
// Return the response data as a JSON object
|
||||
return response()->json([
|
||||
'draw' => $request->get('draw'),
|
||||
'recordsTotal' => $totalRecords,
|
||||
'recordsFiltered' => $filteredRecords,
|
||||
'pageCount' => $pageCount,
|
||||
'page' => $currentPage,
|
||||
'totalCount' => $totalRecords,
|
||||
'data' => $positions,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Export positions to Excel.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse
|
||||
*/
|
||||
public function export(Request $request)
|
||||
{
|
||||
// Get the authenticated user
|
||||
$user = Auth::guard('web')->user();
|
||||
|
||||
// Check if the authenticated user has the required permission to export positions
|
||||
if (is_null($user) || !$user->can('positions.export')) {
|
||||
abort(403, 'Sorry! You are not allowed to export positions.');
|
||||
}
|
||||
|
||||
// Get search parameter from request
|
||||
$search = $request->get('search');
|
||||
|
||||
return Excel::download(new PositionExport($search), 'positions.xlsx');
|
||||
}
|
||||
}
|
||||
39
app/Http/Requests/PositionRequest.php
Normal file
39
app/Http/Requests/PositionRequest.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Usermanagement\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class PositionRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = [
|
||||
'name' => 'required|string',
|
||||
'level' => 'required|integer',
|
||||
];
|
||||
|
||||
if ($this->method() === 'PUT') {
|
||||
$rules['code'] = 'required|string|unique:positions,code,' . $this->id;
|
||||
} else {
|
||||
$rules['code'] = 'required|string|unique:positions,code';
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
42
app/Models/Position.php
Normal file
42
app/Models/Position.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Usermanagement\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Spatie\Activitylog\LogOptions;
|
||||
use Spatie\Activitylog\Traits\LogsActivity;
|
||||
|
||||
class Position extends Model
|
||||
{
|
||||
use SoftDeletes, LogsActivity;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'code',
|
||||
'name',
|
||||
'level',
|
||||
];
|
||||
|
||||
/**
|
||||
* Retrieve the activity log options for this position.
|
||||
*
|
||||
* @return LogOptions The activity log options.
|
||||
*/
|
||||
public function getActivitylogOptions(): LogOptions
|
||||
{
|
||||
return LogOptions::defaults()->logAll()->useLogName('User Management|Positions : ');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the roles associated with this position.
|
||||
*/
|
||||
public function roles()
|
||||
{
|
||||
return $this->hasMany(Role::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('positions', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('code')->unique();
|
||||
$table->string('name');
|
||||
$table->integer('level');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('positions');
|
||||
}
|
||||
};
|
||||
126
module.json
126
module.json
@@ -1,61 +1,71 @@
|
||||
{
|
||||
"name": "Usermanagement",
|
||||
"alias": "usermanagement",
|
||||
"database": "",
|
||||
"description": "",
|
||||
"keywords": [],
|
||||
"priority": 0,
|
||||
"providers": [
|
||||
"Modules\\Usermanagement\\Providers\\UsermanagementServiceProvider"
|
||||
],
|
||||
"files": [],
|
||||
"menu": {
|
||||
"main": [],
|
||||
"master": [],
|
||||
"system": [
|
||||
{
|
||||
"title": "User Management",
|
||||
"path": "users",
|
||||
"icon": "ki-filled ki-users text-lg text-primary",
|
||||
"classes": "",
|
||||
"attributes": [],
|
||||
"permission": "",
|
||||
"roles": [
|
||||
"administrator"
|
||||
],
|
||||
"sub": [
|
||||
{
|
||||
"title": "Users",
|
||||
"path": "users",
|
||||
"classes": "",
|
||||
"attributes": [],
|
||||
"permission": "",
|
||||
"roles": [
|
||||
"administrator"
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "Roles",
|
||||
"path": "users.roles",
|
||||
"classes": "",
|
||||
"attributes": [],
|
||||
"permission": "",
|
||||
"roles": [
|
||||
"administrator"
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "Permissions",
|
||||
"path": "users.permissions",
|
||||
"classes": "",
|
||||
"attributes": [],
|
||||
"permission": "",
|
||||
"roles": [
|
||||
"administrator"
|
||||
]
|
||||
}
|
||||
"name": "Usermanagement",
|
||||
"alias": "usermanagement",
|
||||
"database": "",
|
||||
"description": "",
|
||||
"keywords": [],
|
||||
"priority": 0,
|
||||
"providers": [
|
||||
"Modules\\Usermanagement\\Providers\\UsermanagementServiceProvider"
|
||||
],
|
||||
"files": [],
|
||||
"menu": {
|
||||
"main": [],
|
||||
"master": [],
|
||||
"system": [
|
||||
{
|
||||
"title": "User Management",
|
||||
"path": "users",
|
||||
"icon": "ki-filled ki-users text-lg text-primary",
|
||||
"classes": "",
|
||||
"attributes": [],
|
||||
"permission": "",
|
||||
"roles": [
|
||||
"administrator"
|
||||
],
|
||||
"sub": [
|
||||
{
|
||||
"title": "Users",
|
||||
"path": "users",
|
||||
"classes": "",
|
||||
"attributes": [],
|
||||
"permission": "",
|
||||
"roles": [
|
||||
"administrator"
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "Positions",
|
||||
"path": "users.positions",
|
||||
"classes": "",
|
||||
"attributes": [],
|
||||
"permission": "",
|
||||
"roles": [
|
||||
"administrator"
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "Roles",
|
||||
"path": "users.roles",
|
||||
"classes": "",
|
||||
"attributes": [],
|
||||
"permission": "",
|
||||
"roles": [
|
||||
"administrator"
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "Permissions",
|
||||
"path": "users.permissions",
|
||||
"classes": "",
|
||||
"attributes": [],
|
||||
"permission": "",
|
||||
"roles": [
|
||||
"administrator"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
68
resources/views/positions/create.blade.php
Normal file
68
resources/views/positions/create.blade.php
Normal file
@@ -0,0 +1,68 @@
|
||||
@extends('layouts.main')
|
||||
|
||||
@section('breadcrumbs')
|
||||
{{ Breadcrumbs::render(request()->route()->getName()) }}
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<div class="w-full grid gap-5 lg:gap-7.5 mx-auto">
|
||||
<form action="{{ isset($position->id) ? route('users.positions.update', $position->id) : route('users.positions.store') }}" method="POST" id="position_form">
|
||||
@csrf
|
||||
@if(isset($position->id))
|
||||
<input type="hidden" name="id" value="{{ $position->id }}">
|
||||
@method('PUT')
|
||||
@endif
|
||||
<div class="card pb-2.5">
|
||||
<div class="card-header" id="basic_settings">
|
||||
<h3 class="card-title">
|
||||
{{ isset($position->id) ? 'Edit' : 'Add' }} Position
|
||||
</h3>
|
||||
<div class="flex items-center gap-2">
|
||||
<a href="{{ route('users.positions.index') }}" class="btn btn-xs btn-info">Back</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body grid gap-5">
|
||||
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||
<label class="form-label max-w-56">
|
||||
Code
|
||||
</label>
|
||||
<div class="flex flex-wrap items-baseline w-full">
|
||||
<input class="input @error('code') border-danger @enderror" type="text" name="code" value="{{ $position->code ?? '' }}">
|
||||
@error('code')
|
||||
<em class="alert text-danger text-sm">{{ $message }}</em>
|
||||
@enderror
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||
<label class="form-label max-w-56">
|
||||
Name
|
||||
</label>
|
||||
<div class="flex flex-wrap items-baseline w-full">
|
||||
<input class="input @error('name') border-danger @enderror" type="text" name="name" value="{{ $position->name ?? '' }}">
|
||||
@error('name')
|
||||
<em class="alert text-danger text-sm">{{ $message }}</em>
|
||||
@enderror
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||
<label class="form-label max-w-56">
|
||||
Level
|
||||
</label>
|
||||
<div class="flex flex-wrap items-baseline w-full">
|
||||
<input class="input @error('level') border-danger @enderror" type="number" name="level" value="{{ $position->level ?? '' }}">
|
||||
@error('level')
|
||||
<em class="alert text-danger text-sm">{{ $message }}</em>
|
||||
@enderror
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end">
|
||||
<button type="submit" class="btn btn-primary">
|
||||
Save
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@endsection
|
||||
165
resources/views/positions/index.blade.php
Normal file
165
resources/views/positions/index.blade.php
Normal file
@@ -0,0 +1,165 @@
|
||||
@extends('layouts.main')
|
||||
|
||||
@section('breadcrumbs')
|
||||
{{ Breadcrumbs::render('users.positions') }}
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<div class="container-fluid">
|
||||
<div class="grid">
|
||||
<div class="card card-grid min-w-full" data-datatable="false" data-datatable-page-size="5" data-datatable-state-save="true" id="positions-table" data-api-url="{{ route('users.positions.datatables') }}">
|
||||
<div class="card-header py-5 flex-wrap">
|
||||
<h3 class="card-title">
|
||||
List of Positions
|
||||
</h3>
|
||||
<div class="flex flex-wrap gap-2 lg:gap-5">
|
||||
<div class="flex">
|
||||
<label class="input input-sm"> <i class="ki-filled ki-magnifier"> </i>
|
||||
<input placeholder="Search positions" id="search" type="text" value="">
|
||||
</label>
|
||||
</div>
|
||||
<div class="flex flex-wrap gap-2.5 lg:gap-5">
|
||||
<div class="h-[100%] border border-r-gray-200"> </div>
|
||||
<a class="btn btn-sm btn-light" id="export-btn" href="{{ route('users.positions.export') }}"> Export to Excel </a>
|
||||
<a class="btn btn-sm btn-primary" href="{{ route('users.positions.create') }}"> Add Position </a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="scrollable-x-auto">
|
||||
<table class="table table-auto table-border align-middle text-gray-700 font-medium text-sm" data-datatable-table="true">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="w-14">
|
||||
<input class="checkbox checkbox-sm" data-datatable-check="true" type="checkbox"/>
|
||||
</th>
|
||||
<th class="min-w-[150px]" data-datatable-column="code">
|
||||
<span class="sort"> <span class="sort-label"> Code </span>
|
||||
<span class="sort-icon"> </span> </span>
|
||||
</th>
|
||||
<th class="min-w-[250px]" data-datatable-column="name">
|
||||
<span class="sort"> <span class="sort-label"> Name </span>
|
||||
<span class="sort-icon"> </span> </span>
|
||||
</th>
|
||||
<th class="min-w-[100px]" data-datatable-column="level">
|
||||
<span class="sort"> <span class="sort-label"> Tingkat Jabatan </span>
|
||||
<span class="sort-icon"> </span> </span>
|
||||
</th>
|
||||
<th class="min-w-[50px] text-center" data-datatable-column="actions">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</div>
|
||||
<div class="card-footer justify-center md:justify-between flex-col md:flex-row gap-3 text-gray-600 text-2sm font-medium">
|
||||
<div class="flex items-center gap-2">
|
||||
Show
|
||||
<select class="select select-sm w-16" data-datatable-size="true" name="perpage"> </select> per page
|
||||
</div>
|
||||
<div class="flex items-center gap-4">
|
||||
<span data-datatable-info="true"> </span>
|
||||
<div class="pagination" data-datatable-pagination="true">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('scripts')
|
||||
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||
<script type="text/javascript">
|
||||
function deleteData(data) {
|
||||
Swal.fire({
|
||||
title: 'Are you sure?',
|
||||
text: "You won't be able to revert this!" ,
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: '#3085d6',
|
||||
cancelButtonColor: '#d33',
|
||||
confirmButtonText: 'Yes, delete it!'
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
$.ajaxSetup({
|
||||
headers: {
|
||||
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
||||
}
|
||||
});
|
||||
|
||||
$.ajax(`positions/${data}`, {
|
||||
type: 'DELETE'
|
||||
}).then((response) => {
|
||||
swal.fire('Deleted!', 'Position has been deleted.','success').then(() => {
|
||||
window.location.reload();
|
||||
});
|
||||
}).catch((error) => {
|
||||
console.error('Error:', error);
|
||||
Swal.fire('Error!', 'An error occurred while deleting the position.', 'error');
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
</script>
|
||||
<script type="module">
|
||||
const element = document.querySelector('#positions-table');
|
||||
const searchInput = document.getElementById('search');
|
||||
|
||||
const apiUrl = element.getAttribute('data-api-url');
|
||||
const dataTableOptions = {
|
||||
apiEndpoint: apiUrl,
|
||||
pageSize: 5,
|
||||
columns: {
|
||||
select: {
|
||||
render: (item, data, context) => {
|
||||
const checkbox = document.createElement('input');
|
||||
checkbox.className = 'checkbox checkbox-sm';
|
||||
checkbox.type = 'checkbox';
|
||||
checkbox.value = data.id.toString();
|
||||
checkbox.setAttribute('data-datatable-row-check', 'true');
|
||||
return checkbox.outerHTML.trim();
|
||||
},
|
||||
},
|
||||
code: {
|
||||
title: 'Code',
|
||||
},
|
||||
name: {
|
||||
title: 'Name',
|
||||
},
|
||||
level: {
|
||||
title: 'Level',
|
||||
},
|
||||
actions: {
|
||||
title: 'Status',
|
||||
render: (item, data) => {
|
||||
return `<div class="flex flex-nowrap justify-center">
|
||||
<a class="btn btn-sm btn-icon btn-clear btn-info" href="positions/${data.id}/edit">
|
||||
<i class="ki-outline ki-notepad-edit"></i>
|
||||
</a>
|
||||
<a onclick="deleteData(${data.id})" class="delete btn btn-sm btn-icon btn-clear btn-danger">
|
||||
<i class="ki-outline ki-trash"></i>
|
||||
</a>
|
||||
</div>`;
|
||||
},
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
let dataTable = new KTDataTable(element, dataTableOptions);
|
||||
const exportBtn = document.getElementById('export-btn');
|
||||
const baseExportUrl = exportBtn.getAttribute('href');
|
||||
|
||||
// Custom search functionality
|
||||
searchInput.addEventListener('input', function () {
|
||||
const searchValue = this.value.trim();
|
||||
dataTable.search(searchValue, true);
|
||||
|
||||
// Update export URL with search parameter
|
||||
if (searchValue) {
|
||||
exportBtn.setAttribute('href', `${baseExportUrl}?search=${encodeURIComponent(searchValue)}`);
|
||||
} else {
|
||||
exportBtn.setAttribute('href', baseExportUrl);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
@@ -53,3 +53,18 @@
|
||||
$trail->parent('users.permissions');
|
||||
$trail->push('Edit Permission');
|
||||
});
|
||||
|
||||
Breadcrumbs::for('users.positions', function (BreadcrumbTrail $trail) {
|
||||
$trail->parent('users');
|
||||
$trail->push('Positions', route('users.positions.index'));
|
||||
});
|
||||
|
||||
Breadcrumbs::for('users.positions.create', function (BreadcrumbTrail $trail) {
|
||||
$trail->parent('users.positions');
|
||||
$trail->push('Add Position', route('users.positions.create'));
|
||||
});
|
||||
|
||||
Breadcrumbs::for('users.positions.edit', function (BreadcrumbTrail $trail) {
|
||||
$trail->parent('users.positions');
|
||||
$trail->push('Edit Position');
|
||||
});
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Modules\Usermanagement\Http\Controllers\PermissionsController;
|
||||
use Modules\Usermanagement\Http\Controllers\PositionsController;
|
||||
use Modules\Usermanagement\Http\Controllers\RolesController;
|
||||
use Modules\Usermanagement\Http\Controllers\UsersController;
|
||||
|
||||
@@ -43,6 +44,11 @@
|
||||
Route::get('export', [PermissionsController ::class, 'export'])->name('export');
|
||||
});
|
||||
Route::resource('permissions', PermissionsController::class);
|
||||
|
||||
Route::name('positions.')->prefix('positions')->group(function () {
|
||||
Route::get('datatables', [PositionsController::class, 'dataForDatatables'])->name('datatables');
|
||||
Route::get('export', [PositionsController::class, 'export'])->name('export');
|
||||
});
|
||||
Route::resource('positions', PositionsController::class);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user