From ccf66298ab7677a49818e178a8c4d76969f6ebc0 Mon Sep 17 00:00:00 2001 From: rahmagustin Date: Mon, 9 Feb 2026 14:43:26 +0700 Subject: [PATCH] pembaruan sig tps --- app/Http/Controllers/Admin/TpsController.php | 318 ++++++++----------- app/Http/Requests/Auth/LoginRequest.php | 57 ++-- public/assets/user/css/main.css | 41 +++ resources/views/admin/tps/index.blade.php | 144 ++++----- resources/views/coba.blade.php | 67 ++++ resources/views/user/sig-tps.blade.php | 264 ++++++++------- 6 files changed, 457 insertions(+), 434 deletions(-) create mode 100644 resources/views/coba.blade.php diff --git a/app/Http/Controllers/Admin/TpsController.php b/app/Http/Controllers/Admin/TpsController.php index aabdaa6..8d9cd86 100644 --- a/app/Http/Controllers/Admin/TpsController.php +++ b/app/Http/Controllers/Admin/TpsController.php @@ -10,186 +10,140 @@ class TpsController extends Controller { - public function index() - { - $title = 'Data TPS'; - - // Ambil TPS + kategori + jumlah aduan - $tps = LokasiTps::with('kategori') - ->withCount('aduan') - ->get(); - - return view('admin.tps.index', compact('title', 'tps')); - } - - public function create() - { - $title = 'Tambah TPS'; - $kategori = KategoriTps::all(); - - return view('admin.tps.create', compact('title', 'kategori')); - } - - private function convertToDecimal($coordinate) - { - // decimal langsung - if (is_numeric($coordinate)) { - return (float) $coordinate; - } - - $coordinate = html_entity_decode($coordinate); - $coordinate = strtoupper(trim($coordinate)); - - // ganti simbol jadi seragam - $coordinate = str_replace( - ['°', "'", '"'], - [' ', ' ', ' '], - $coordinate - ); - - // ambil arah - preg_match('/([NSEW])/', $coordinate, $dirMatch); - if (!$dirMatch) return null; - - $direction = $dirMatch[1]; - - // ambil angka - preg_match_all('/\d+(\.\d+)?/', $coordinate, $numbers); - if (count($numbers[0]) < 3) return null; - - [$deg, $min, $sec] = array_map('floatval', $numbers[0]); - - $decimal = $deg + ($min / 60) + ($sec / 3600); - - if (in_array($direction, ['S', 'W'])) { - $decimal *= -1; - } - - return $decimal; - } - - public function store(Request $request) - { - $request->validate([ - 'kategori_tps_id' => 'required|exists:kategori_tps,id_kategori_tps', - 'nama_tps' => 'required|string|max:255', - 'alamat_tps' => 'required|string|max:255', - 'status_tps' => 'required', - 'tahun_pembuatan' => 'required|numeric', - 'kapasitas_tps' => 'required', - 'latitude' => 'required', - 'longitude' => 'required', - 'foto_tps' => 'nullable|image|mimes:jpg,jpeg,png|max:2048', - ]); - - // 🔥 KONVERSI KOORDINAT - $latitude = $this->convertToDecimal($request->latitude); - $longitude = $this->convertToDecimal($request->longitude); - - if ($latitude === null || $longitude === null) { - return back()->withErrors(['Koordinat tidak valid'])->withInput(); - } - - // Upload foto - $foto = $request->hasFile('foto_tps') - ? $request->file('foto_tps')->store('foto-tps', 'public') - : null; - - LokasiTps::create([ - 'kategori_tps_id' => $request->kategori_tps_id, - 'nama_tps' => $request->nama_tps, - 'alamat_tps' => $request->alamat_tps, - 'status_tps' => $request->status_tps, - 'tahun_pembuatan' => $request->tahun_pembuatan, - 'kapasitas_tps' => $request->kapasitas_tps, - 'latitude' => $latitude, - 'longitude' => $longitude, - 'foto_tps' => $foto, - ]); - - return redirect()->route('admin.tps.index') - ->with('success', 'Data TPS berhasil ditambahkan'); - } - - - public function edit($id) - { - $title = 'Edit TPS'; - $tps = LokasiTps::findOrFail($id); - $kategori = KategoriTps::all(); - - return view('admin.tps.edit', compact('title', 'tps', 'kategori')); - } - - public function update(Request $request, $id) - { - $tps = LokasiTps::findOrFail($id); - - // VALIDASI - $request->validate([ - 'kategori_tps_id' => 'required|exists:kategori_tps,id_kategori_tps', - 'nama_tps' => 'required|string|max:255', - 'alamat_tps' => 'required|string|max:255', - 'status_tps' => 'required', - 'tahun_pembuatan' => 'required|numeric', - 'kapasitas_tps' => 'required', - 'latitude' => 'required', - 'longitude' => 'required', - 'foto_tps' => 'nullable|image|mimes:jpg,jpeg,png|max:4096', - ]); - - // 🔥 KONVERSI KOORDINAT (DMS / DECIMAL) - $latitude = $this->convertToDecimal($request->latitude); - $longitude = $this->convertToDecimal($request->longitude); - - // Jika koordinat tidak valid - if ($latitude === null || $longitude === null) { - return back() - ->withErrors(['Koordinat tidak valid. Gunakan format Decimal atau DMS.']) - ->withInput(); - } - - // 📸 UPLOAD FOTO JIKA ADA - if ($request->hasFile('foto_tps')) { - - // Hapus foto lama - if ($tps->foto_tps) { - Storage::disk('public')->delete($tps->foto_tps); - } - - $foto = $request->file('foto_tps')->store('foto-tps', 'public'); - } else { - $foto = $tps->foto_tps; - } - - // 💾 UPDATE DATA - $tps->update([ - 'kategori_tps_id' => $request->kategori_tps_id, - 'nama_tps' => $request->nama_tps, - 'alamat_tps' => $request->alamat_tps, - 'status_tps' => $request->status_tps, - 'tahun_pembuatan' => $request->tahun_pembuatan, - 'kapasitas_tps' => $request->kapasitas_tps, - 'latitude' => $latitude, - 'longitude' => $longitude, - 'foto_tps' => $foto, - ]); - - return redirect()->route('admin.tps.index') - ->with('success', 'Data TPS berhasil diperbarui'); - } - - public function destroy($id) - { - $tps = LokasiTps::findOrFail($id); - - if ($tps->foto_tps) { - Storage::disk('public')->delete($tps->foto_tps); - } - - $tps->delete(); - - return redirect()->route('admin.tps.index') - ->with('success', 'Data TPS berhasil dihapus'); - } +public function index() +{ + $title = 'Data TPS'; + $tps = LokasiTps::with('kategori') + ->withCount('aduan') + ->get(); + return view('admin.tps.index', compact('title', 'tps')); +} + +public function create() +{ + $title = 'Tambah TPS'; + $kategori = KategoriTps::all(); + return view('admin.tps.create', compact('title', 'kategori')); +} +private function convertToDecimal($coordinate) +{ + if (is_numeric($coordinate)) { + return (float) $coordinate; + } + $coordinate = html_entity_decode($coordinate); + $coordinate = strtoupper(trim($coordinate)); + $coordinate = str_replace( + ['°', "'", '"'], + [' ', ' ', ' '], + $coordinate + ); + preg_match('/([NSEW])/', $coordinate, $dirMatch); + if (!$dirMatch) return null; + $direction = $dirMatch[1]; + preg_match_all('/\d+(\.\d+)?/', $coordinate, $numbers); + if (count($numbers[0]) < 3) return null; + [$deg, $min, $sec] = array_map('floatval', $numbers[0]); + $decimal = $deg + ($min / 60) + ($sec / 3600); + if (in_array($direction, ['S', 'W'])) { + $decimal *= -1; + } + return $decimal; +} +public function store(Request $request) +{ + $request->validate([ + 'kategori_tps_id' => 'required|exists:kategori_tps,id_kategori_tps', + 'nama_tps' => 'required|string|max:255', + 'alamat_tps' => 'required|string|max:255', + 'status_tps' => 'required', + 'tahun_pembuatan' => 'required|numeric', + 'kapasitas_tps' => 'required', + 'latitude' => 'required', + 'longitude' => 'required', + 'foto_tps' => 'nullable|image|mimes:jpg,jpeg,png|max:2048', + ]); + $latitude = $this->convertToDecimal($request->latitude); + $longitude = $this->convertToDecimal($request->longitude); + if ($latitude === null || $longitude === null) { + return back()->withErrors(['Koordinat tidak valid'])->withInput(); + } + $foto = $request->hasFile('foto_tps') + ? $request->file('foto_tps')->store('foto-tps', 'public') + : null; + LokasiTps::create([ + 'kategori_tps_id' => $request->kategori_tps_id, + 'nama_tps' => $request->nama_tps, + 'alamat_tps' => $request->alamat_tps, + 'status_tps' => $request->status_tps, + 'tahun_pembuatan' => $request->tahun_pembuatan, + 'kapasitas_tps' => $request->kapasitas_tps, + 'latitude' => $latitude, + 'longitude' => $longitude, + 'foto_tps' => $foto, + ]); + return redirect()->route('admin.tps.index') + ->with('success', 'Data TPS berhasil ditambahkan'); +} + +public function edit($id) +{ + $title = 'Edit TPS'; + $tps = LokasiTps::findOrFail($id); + $kategori = KategoriTps::all(); + return view('admin.tps.edit', compact('title', 'tps', 'kategori')); +} +public function update(Request $request, $id) +{ + $tps = LokasiTps::findOrFail($id); + $request->validate([ + 'kategori_tps_id' => 'required|exists:kategori_tps,id_kategori_tps', + 'nama_tps' => 'required|string|max:255', + 'alamat_tps' => 'required|string|max:255', + 'status_tps' => 'required', + 'tahun_pembuatan' => 'required|numeric', + 'kapasitas_tps' => 'required', + 'latitude' => 'required', + 'longitude' => 'required', + 'foto_tps' => 'nullable|image|mimes:jpg,jpeg,png|max:4096', + ]); + $latitude = $this->convertToDecimal($request->latitude); + $longitude = $this->convertToDecimal($request->longitude); + if ($latitude === null || $longitude === null) { + return back() + ->withErrors(['Koordinat tidak valid. Gunakan format Decimal atau DMS.']) + ->withInput(); + } + if ($request->hasFile('foto_tps')) { + if ($tps->foto_tps) { + Storage::disk('public')->delete($tps->foto_tps); + } + $foto = $request->file('foto_tps')->store('foto-tps', 'public'); + } else { + $foto = $tps->foto_tps; + } + $tps->update([ + 'kategori_tps_id' => $request->kategori_tps_id, + 'nama_tps' => $request->nama_tps, + 'alamat_tps' => $request->alamat_tps, + 'status_tps' => $request->status_tps, + 'tahun_pembuatan' => $request->tahun_pembuatan, + 'kapasitas_tps' => $request->kapasitas_tps, + 'latitude' => $latitude, + 'longitude' => $longitude, + 'foto_tps' => $foto, + ]); + return redirect()->route('admin.tps.index') + ->with('success', 'Data TPS berhasil diperbarui'); +} + +public function destroy($id) +{ + $tps = LokasiTps::findOrFail($id); + if ($tps->foto_tps) { + Storage::disk('public')->delete($tps->foto_tps); + } + $tps->delete(); + return redirect()->route('admin.tps.index') + ->with('success', 'Data TPS berhasil dihapus'); +} } diff --git a/app/Http/Requests/Auth/LoginRequest.php b/app/Http/Requests/Auth/LoginRequest.php index 0e51199..9bee446 100644 --- a/app/Http/Requests/Auth/LoginRequest.php +++ b/app/Http/Requests/Auth/LoginRequest.php @@ -8,22 +8,15 @@ use Illuminate\Support\Facades\RateLimiter; use Illuminate\Support\Str; use Illuminate\Validation\ValidationException; +use App\Models\User; class LoginRequest extends FormRequest { - /** - * Determine if the user is authorized to make this request. - */ public function authorize(): bool { return true; } - /** - * Get the validation rules that apply to the request. - * - * @return array|string> - */ public function rules(): array { return [ @@ -32,31 +25,25 @@ public function rules(): array ]; } - /** - * Attempt to authenticate the request's credentials. - * - * @throws \Illuminate\Validation\ValidationException - */ - public function authenticate(): void - { - $this->ensureIsNotRateLimited(); - - if (! Auth::attempt($this->only('username', 'password'), $this->boolean('remember'))) { - RateLimiter::hit($this->throttleKey()); - - throw ValidationException::withMessages([ - 'email' => trans('auth.failed'), - ]); - } - - RateLimiter::clear($this->throttleKey()); +public function authenticate(): void +{ + $user = User::where('username', $this->username)->first(); + if (!$user) { + throw ValidationException::withMessages([ + 'username' => 'Username tidak terdaftar.', + ]); } + if (!Auth::attempt([ + 'username' => $this->username, + 'password' => $this->password, + ])) { + throw ValidationException::withMessages([ + 'password' => 'Password yang dimasukkan salah.', + ]); + } +} + - /** - * Ensure the login request is not rate limited. - * - * @throws \Illuminate\Validation\ValidationException - */ public function ensureIsNotRateLimited(): void { if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) { @@ -68,18 +55,16 @@ public function ensureIsNotRateLimited(): void $seconds = RateLimiter::availableIn($this->throttleKey()); throw ValidationException::withMessages([ - 'email' => trans('auth.throttle', [ + 'username' => trans('auth.throttle', [ 'seconds' => $seconds, 'minutes' => ceil($seconds / 60), ]), ]); } - /** - * Get the rate limiting throttle key for the request. - */ + public function throttleKey(): string { - return Str::transliterate(Str::lower($this->string('email')).'|'.$this->ip()); + return Str::transliterate(Str::lower($this->string('username')) . '|' . $this->ip()); } } diff --git a/public/assets/user/css/main.css b/public/assets/user/css/main.css index 2b076df..905a4b1 100644 --- a/public/assets/user/css/main.css +++ b/public/assets/user/css/main.css @@ -3027,3 +3027,44 @@ .btn-aduan-tps:hover { background: #bb2d3b; /* merah lebih gelap */ color: #fff; } + +.map-wrapper { + position: relative; +} + +.map-action { + position: absolute; + top: 16px; + right: 16px; + z-index: 1000; + background: #fff; + padding: 12px 14px; + border-radius: 12px; + box-shadow: 0 6px 20px rgba(0,0,0,.15); + max-width: 260px; +} + +.map-action-text { + font-size: 14px; + color: #333; + margin-bottom: 8px; + line-height: 1.4; +} + +.btn-lokasi { + width: 100%; + border: none; + background: #00A86B; + color: #fff; + padding: 8px 12px; + border-radius: 8px; + font-size: 14px; + font-weight: 500; + cursor: pointer; +} + +.btn-lokasi:hover, +.btn-lokasi:focus:hover { + color: var(--contrast-color); + background: color-mix(in srgb, var(--accent-color), transparent 15%); +} diff --git a/resources/views/admin/tps/index.blade.php b/resources/views/admin/tps/index.blade.php index 05b9555..95c0258 100644 --- a/resources/views/admin/tps/index.blade.php +++ b/resources/views/admin/tps/index.blade.php @@ -7,10 +7,10 @@
-
+
-

Data TPS

-

+

Data TPS

+

Daftar Tempat Pembuangan Sampah (TPS)

@@ -20,82 +20,68 @@
- - - - - - - - - - - - - @forelse ($tps as $item) - - - - - - - - - - - - - - - - - - @empty - - - - @endforelse - - -
Nama TPSKategoriFotoStatusAksi
{{ $item->nama_tps }} - {{ $item->kategori->nama_kategori ?? '-' }} - - @if ($item->foto_tps) - Foto TPS - @else - - - @endif - - @if ($item->status_tps == 'Aktif') - - @elseif ($item->status_tps == 'Tidak Aktif') - - @else - - @endif - - - - - -
- @csrf - @method('DELETE') - -
- -
- Data TPS belum tersedia -
+ + + + + + + + + + + + @forelse ($tps as $item) + + + + + + + + @empty + + + + @endforelse + +
Nama TPSKategoriFotoStatusAksi
{{ $item->nama_tps }} + {{ $item->kategori->nama_kategori ?? '-' }} + + @if ($item->foto_tps) + Foto TPS + @else + - + @endif + + @if ($item->status_tps == 'Aktif') + + @elseif ($item->status_tps == 'Tidak Aktif') + + @else + + @endif + + + + +
+ @csrf + @method('DELETE') + +
+
+ Data TPS belum tersedia +
diff --git a/resources/views/coba.blade.php b/resources/views/coba.blade.php new file mode 100644 index 0000000..d3c6de4 --- /dev/null +++ b/resources/views/coba.blade.php @@ -0,0 +1,67 @@ +validate([ + 'tahun' => 'required|numeric', + 'total_sampah' => 'required|numeric', + 'total_kelola' => 'required|numeric', + 'total_daur_ulang' => 'required|numeric', + ]); + $sisa_sampah = $request->total_sampah + - ($request->total_kelola + $request->total_daur_ulang); + Sampah::create([ + 'user_id' => Auth::id(), + 'tahun' => $request->tahun, + 'total_sampah' => $request->total_sampah, + 'total_kelola' => $request->total_kelola, + 'total_daur_ulang' => $request->total_daur_ulang, + 'sisa_sampah' => $sisa_sampah, + ]); + return redirect()->route('admin.sampah.index') + ->with('success', 'Data sampah berhasil ditambahkan'); +} + +public function edit($id) +{ + $title = 'Edit Data Sampah'; + $sampah = Sampah::findOrFail($id); + $users = User::all(); + return view('admin.sampah.edit', compact('title', 'sampah', 'users')); +} +public function update(Request $request, $id) +{ + $sampah = Sampah::findOrFail($id); + $request->validate([ + 'user_id' => 'required|exists:users,id', + 'tahun' => 'required|numeric', + 'total_sampah' => 'required|numeric', + 'total_kelola' => 'required|numeric', + 'total_daur_ulang' => 'required|numeric', + ]); + $sisa_sampah = $request->total_sampah + - ($request->total_kelola + $request->total_daur_ulang); + $sampah->update([ + 'user_id' => $request->user_id, + 'tahun' => $request->tahun, + 'total_sampah' => $request->total_sampah, + 'total_kelola' => $request->total_kelola, + 'total_daur_ulang' => $request->total_daur_ulang, + 'sisa_sampah' => $sisa_sampah, + ]); + return redirect()->route('admin.sampah.index') + ->with('success', 'Data sampah berhasil diperbarui'); +} + +public function destroy($id) +{ + $sampah = Sampah::findOrFail($id); + $sampah->delete(); + return redirect()->route('admin.sampah.index') + ->with('success', 'Data sampah berhasil dihapus'); +} diff --git a/resources/views/user/sig-tps.blade.php b/resources/views/user/sig-tps.blade.php index 9032e28..3401cb2 100644 --- a/resources/views/user/sig-tps.blade.php +++ b/resources/views/user/sig-tps.blade.php @@ -5,7 +5,9 @@
@@ -69,156 +63,152 @@
- - -
-
- Klik tombol di samping untuk menemukan TPS terdekat dari lokasi Anda saat ini. +
+
+
+ Temukan TPS terdekat dari lokasi Anda saat ini +
+
- +
- -
@endsection