diff --git a/app/Http/Controllers/Api/GoogleSheetController.php b/app/Http/Controllers/Api/GoogleSheetController.php index 7cad121..baac2ec 100644 --- a/app/Http/Controllers/Api/GoogleSheetController.php +++ b/app/Http/Controllers/Api/GoogleSheetController.php @@ -3,33 +3,15 @@ namespace App\Http\Controllers\Api; use App\Http\Controllers\Controller; -use App\Services\GoogleSheetService; use Illuminate\Http\Request; class GoogleSheetController extends Controller { - protected $googleSheetService; - public function __construct(GoogleSheetService $googleSheetService){ - $this->googleSheetService = $googleSheetService; - } - /** - * Display a listing of the resource. - */ - public function index() + public function index(Request $request) { - $dataCollection = $this->googleSheetService->getSheetDataCollection(); - $result = [ - "last_row" => $this->googleSheetService->getLastRowByColumn("C"), - "last_column" => $this->googleSheetService->getLastColumn(), - "header" => $this->googleSheetService->getHeader(), - "data_collection" => $dataCollection - ]; - return response()->json($result); + } - /** - * Store a newly created resource in storage. - */ public function store(Request $request) { // diff --git a/app/Http/Controllers/Api/PbgTaskGoogleSheetsController.php b/app/Http/Controllers/Api/PbgTaskGoogleSheetsController.php new file mode 100644 index 0000000..b7a8c49 --- /dev/null +++ b/app/Http/Controllers/Api/PbgTaskGoogleSheetsController.php @@ -0,0 +1,55 @@ +orderBy('id', 'desc'); + if ($request->filled('search')) { + $query->where('no_registrasi', 'like', "%{$request->get('search')}%"); + } + return PbgTaskGoogleSheetResource::collection($query->paginate(config('app.paginate_per_page', 50))); + } + + /** + * Store a newly created resource in storage. + */ + public function store(Request $request) + { + // + } + + /** + * Display the specified resource. + */ + public function show(string $id) + { + // + } + + /** + * Update the specified resource in storage. + */ + public function update(Request $request, string $id) + { + // + } + + /** + * Remove the specified resource from storage. + */ + public function destroy(string $id) + { + // + } +} diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 8677cd5..f1aab11 100755 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -2,7 +2,54 @@ namespace App\Http\Controllers; +use Illuminate\Support\Facades\Auth; + abstract class Controller { - // + protected array $permissions = []; + + public function __construct() + { + if (!Auth::check()) { + return; + } + $this->setUserPermissions(); + } + + protected function setUserPermissions() + { + $user = Auth::user(); + + if (!$user) { + return; + } + + $menus = $user->roles() + ->with(['menus' => function ($query) { + $query->select('menus.id', 'menus.name') + ->withPivot(['allow_show' ,'allow_create', 'allow_update', 'allow_destroy']); + }]) + ->get() + ->pluck('menus') + ->flatten() + ->unique('id'); + + // Store permissions in an associative array + foreach ($menus as $menu) { + $this->permissions[$menu->id] = [ + 'allow_show' => $menu->pivot->allow_show ?? 0, + 'allow_create' => $menu->pivot->allow_create ?? 0, + 'allow_update' => $menu->pivot->allow_update ?? 0, + 'allow_destroy' => $menu->pivot->allow_destroy ?? 0, + ]; + } + + // Share permissions globally in views + view()->share('permissions', $this->permissions); + } + + public function getPermissions() + { + return $this->permissions; + } } diff --git a/app/Http/Controllers/Data/GoogleSheetsController.php b/app/Http/Controllers/Data/GoogleSheetsController.php new file mode 100644 index 0000000..50eb186 --- /dev/null +++ b/app/Http/Controllers/Data/GoogleSheetsController.php @@ -0,0 +1,34 @@ +query('menu_id'); + $user_menu_permission = $this->permissions[$menu_id]; + return view('data.google-sheet.index', compact('user_menu_permission')); + } + + public function create() + { + return view('data.google-sheet.create'); + } + + public function show(string $id) + { + return view('data.google-sheet.show'); + } + + public function edit(string $id) + { + return view('data.google-sheet.edit'); + } +} diff --git a/app/Http/Resources/PbgTaskGoogleSheetResource.php b/app/Http/Resources/PbgTaskGoogleSheetResource.php new file mode 100644 index 0000000..ce53cc8 --- /dev/null +++ b/app/Http/Resources/PbgTaskGoogleSheetResource.php @@ -0,0 +1,19 @@ + + */ + public function toArray(Request $request): array + { + return parent::toArray($request); + } +} diff --git a/app/Models/RoleMenu.php b/app/Models/RoleMenu.php index 4208269..16e10ea 100644 --- a/app/Models/RoleMenu.php +++ b/app/Models/RoleMenu.php @@ -18,6 +18,13 @@ class RoleMenu extends Model 'allow_destroy', ]; + protected $casts = [ + 'allow_show' => 'boolean', + 'allow_create' => 'boolean', + 'allow_update' => 'boolean', + 'allow_destroy' => 'boolean', + ]; + public $timestamps = true; public function role(){ diff --git a/database/seeders/UsersRoleMenuSeeder.php b/database/seeders/UsersRoleMenuSeeder.php index 22a6be3..97b39cd 100644 --- a/database/seeders/UsersRoleMenuSeeder.php +++ b/database/seeders/UsersRoleMenuSeeder.php @@ -215,6 +215,13 @@ class UsersRoleMenuSeeder extends Seeder "parent_id" => $data->id, "sort_order" => 7, ], + [ + "name" => "Google Sheets", + "url" => "google-sheets", + "icon" => null, + "parent_id" => $data->id, + "sort_order" => 8, + ], [ "name" => "Lap Pariwisata", "url" => "tourisms-report.index", @@ -277,6 +284,7 @@ class UsersRoleMenuSeeder extends Seeder $chatbot = Menu::where('name', 'Chat')->first(); $dalam_sistem = Menu::where('name', 'Dalam Sistem')->first(); $luar_sistem = Menu::where('name', 'Luar Sistem')->first(); + $google_sheets = Menu::where('name', 'Google Sheets')->first(); // Superadmin gets all menus $superadmin->menus()->sync([ @@ -310,6 +318,7 @@ class UsersRoleMenuSeeder extends Seeder $luar_sistem->id => ["allow_show" => true, "allow_create" => true, "allow_update" => true, "allow_destroy" => true], $bigdata_resume->id => ["allow_show" => true, "allow_create" => true, "allow_update" => true, "allow_destroy" => true], $chatbot->id => ["allow_show" => true, "allow_create" => true, "allow_update" => true, "allow_destroy" => true], + $google_sheets->id => ["allow_show" => true, "allow_create" => true, "allow_update" => true, "allow_destroy" => true], ]); // Admin gets limited menus diff --git a/resources/js/data/google-sheet/create.js b/resources/js/data/google-sheet/create.js new file mode 100644 index 0000000..e69de29 diff --git a/resources/js/data/google-sheet/edit.js b/resources/js/data/google-sheet/edit.js new file mode 100644 index 0000000..e69de29 diff --git a/resources/js/data/google-sheet/index.js b/resources/js/data/google-sheet/index.js new file mode 100644 index 0000000..3d301b6 --- /dev/null +++ b/resources/js/data/google-sheet/index.js @@ -0,0 +1,211 @@ +import { Grid } from "gridjs/dist/gridjs.umd.js"; +import gridjs from "gridjs/dist/gridjs.umd.js"; +import "gridjs/dist/gridjs.umd.js"; +import GlobalConfig from "../../global-config.js"; + +class GoogleSheets { + constructor() { + this.toastMessage = document.getElementById("toast-message"); + this.toastElement = document.getElementById("toastNotification"); + this.toast = new bootstrap.Toast(this.toastElement); + this.table = null; + + // Initialize functions + this.initTableGoogleSheets(); + this.initEvents(); + } + + initEvents() { + document.body.addEventListener("click", async (event) => { + const deleteButton = event.target.closest( + ".btn-delete-google-sheet" + ); + if (deleteButton) { + event.preventDefault(); + await this.handleDelete(deleteButton); + } + }); + } + + initTableGoogleSheets() { + let tableContainer = document.getElementById( + "table-data-google-sheets" + ); + + if (!tableContainer) { + console.error("Table container not found!"); + return; + } + + // Clear previous table content + tableContainer.innerHTML = ""; + + // Get user permissions from data attributes + let canUpdate = tableContainer.getAttribute("data-updater") === "1"; + let canDelete = tableContainer.getAttribute("data-destroyer") === "1"; + + this.table = new Grid({ + columns: [ + "ID", + "No Registratsi", + "No KRK", + "Format STS", + "Fungsi BG", + "Selesai Terbit", + "Selesai Verifikasi", + "Tanggal Permohonan", + { + name: "Action", + formatter: (cell) => { + let buttons = ""; + + buttons += ` + + + + `; + + if (canUpdate) { + buttons += ` + + + + `; + } + + if (canDelete) { + buttons += ` + + `; + } + + if (!canUpdate && !canDelete) { + buttons = `No Privilege`; + } + + return gridjs.html( + `