Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Simple form using a modal to create and update regulation type data #1047

Merged
merged 4 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 33 additions & 39 deletions app/Http/Controllers/Setting/TipeRegulasiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@

namespace App\Http\Controllers\Setting;

use App\Http\Controllers\Controller;
use App\Models\TipeRegulasi;
use Illuminate\Http\Request;
use Yajra\DataTables\DataTables;
use App\Http\Controllers\Controller;
use App\Http\Requests\TipeRegulasiRequest;

class TipeRegulasiController extends Controller
{
Expand All @@ -51,68 +51,62 @@ public function getData()
{
return DataTables::of(TipeRegulasi::all())
->addColumn('aksi', function ($row) {
$data['edit_url'] = route('setting.tipe-regulasi.edit', $row->id);
$data['modal_form'] = $row->id;
$data['delete_url'] = route('setting.tipe-regulasi.destroy', $row->id);

return view('forms.aksi', $data);
})
->make();
}

// Create Action
public function create()
{
$page_title = 'Tipe Regulasi';
$page_description = 'Tambah Tipe Regulasi';

return view('setting.tipe_regulasi.create', compact('page_title', 'page_description'));
}

// Store Data
public function store(Request $request)
/**
* Store a newly created resource in storage.
*
* @param TipeRegulasiRequest $request
*
* @return Response
*/
public function store(TipeRegulasiRequest $request)
{
request()->validate([
'nama' => 'required',
]);

try {
$tipe = new TipeRegulasi($request->all());
$tipe->save();
TipeRegulasi::create($request->validated());
return response()->json(['success' => 'Tipe Regulasi berhasil ditambahkan!']);
} catch (\Exception $e) {
report($e);

return back()->withInput()->with('error', 'Tipe Regulasi gagal dikirim!');
return response()->json(['error' => 'Tipe Regulasi gagal ditambahkan!']);
}

return redirect()->route('setting.tipe-regulasi.index')->with('success', 'Tipe Regulasi berhasil dikirim!');
}

/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function edit($id)
{
$tipe = TipeRegulasi::findOrFail($id);
$page_title = 'Tipe Regulasi';
$page_description = 'Ubah Tipe Regulasi : '.$tipe->nama;

return view('setting.tipe_regulasi.edit', compact('page_title', 'page_description', 'tipe'));
return response()->json($tipe);
}

public function update(Request $request, $id)
/**
* Update the specified resource in storage.
*
* @param int $id
* @param TipeRegulasiRequest $request
*
* @return Response
*/
public function update(TipeRegulasiRequest $request, $id)
{
request()->validate([
'nama' => 'required',
]);

try {
$tipe = TipeRegulasi::findOrFail($id);
$tipe->fill($request->all());
$tipe->save();
TipeRegulasi::findOrFail($id)->update($request->validated());
return response()->json(['success' => 'Tipe Regulasi berhasil diupdate!']);
} catch (\Exception $e) {
report($e);

return back()->withInput()->with('error', 'Tipe Regulasi gagal diupdate!');
return response()->json(['error' => 'Tipe Regulasi gagal diupdate!']);
}

return redirect()->route('setting.tipe-regulasi.index')->with('success', 'Tipe Regulasi berhasil diupdate!');
}

public function destroy($id)
Expand Down
59 changes: 59 additions & 0 deletions app/Http/Requests/TipeRegulasiRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/*
* File ini bagian dari:
*
* OpenDK
*
* Aplikasi dan source code ini dirilis berdasarkan lisensi GPL V3
*
* Hak Cipta 2017 - 2024 Perkumpulan Desa Digital Terbuka (https://opendesa.id)
*
* Dengan ini diberikan izin, secara gratis, kepada siapa pun yang mendapatkan salinan
* dari perangkat lunak ini dan file dokumentasi terkait ("Aplikasi Ini"), untuk diperlakukan
* tanpa batasan, termasuk hak untuk menggunakan, menyalin, mengubah dan/atau mendistribusikan,
* asal tunduk pada syarat berikut:
*
* Pemberitahuan hak cipta di atas dan pemberitahuan izin ini harus disertakan dalam
* setiap salinan atau bagian penting Aplikasi Ini. Barang siapa yang menghapus atau menghilangkan
* pemberitahuan ini melanggar ketentuan lisensi Aplikasi Ini.
*
* PERANGKAT LUNAK INI DISEDIAKAN "SEBAGAIMANA ADANYA", TANPA JAMINAN APA PUN, BAIK TERSURAT MAUPUN
* TERSIRAT. PENULIS ATAU PEMEGANG HAK CIPTA SAMA SEKALI TIDAK BERTANGGUNG JAWAB ATAS KLAIM, KERUSAKAN ATAU
* KEWAJIBAN APAPUN ATAS PENGGUNAAN ATAU LAINNYA TERKAIT APLIKASI INI.
*
* @package OpenDK
* @author Tim Pengembang OpenDesa
* @copyright Hak Cipta 2017 - 2024 Perkumpulan Desa Digital Terbuka (https://opendesa.id)
* @license http://www.gnu.org/licenses/gpl.html GPL V3
* @link https://github.com/OpenSID/opendk
*/

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class TipeRegulasiRequest 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()
{
return [
'nama' => 'required|string|max:100',
];
}
}
3 changes: 2 additions & 1 deletion catatan_rilis.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ Terima kasih pada @uddinmtm telah ikut berkontribusi.
7. [#1054](https://github.com/OpenSID/OpenDK/issues/1054) Change color navigation active.
8. [#1055](https://github.com/OpenSID/OpenDK/issues/1055) Simple form using a modal to create and update potential category data.
9. [#1056](https://github.com/OpenSID/OpenDK/issues/1056) Simple form using a modal to create and update complaint category data.
10.[#1057](https://github.com/OpenSID/OpenDK/issues/1057) Simple form using a modal to create and update disease type data.
10. [#1057](https://github.com/OpenSID/OpenDK/issues/1057) Simple form using a modal to create and update disease type data.
11. [#1058](https://github.com/OpenSID/OpenDK/issues/1058) Simple form using a modal to create and update regulation type data.
47 changes: 0 additions & 47 deletions resources/views/setting/tipe_regulasi/create.blade.php

This file was deleted.

47 changes: 0 additions & 47 deletions resources/views/setting/tipe_regulasi/edit.blade.php

This file was deleted.

8 changes: 0 additions & 8 deletions resources/views/setting/tipe_regulasi/form.blade.php

This file was deleted.

7 changes: 4 additions & 3 deletions resources/views/setting/tipe_regulasi/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

<div class="box box-primary">
<div class="box-header with-border">
@include('forms.btn-social', ['create_url' => route('setting.tipe-regulasi.create')])
@include('forms.btn-social', ['modal_url' => '#modal-form'])
</div>
<div class="box-body">
<div class="table-responsive">
<table class="table table-striped table-bordered" id="data-komplain-kategori">
<table class="table table-striped table-bordered" id="data-tipe-regulasi">
<thead>
<tr>
<th style="max-width: 100px;">Aksi</th>
Expand All @@ -33,6 +33,7 @@
</div>
</div>
</div>
@include('setting.tipe_regulasi.modal-form')
</section>
@endsection

Expand All @@ -41,7 +42,7 @@
@push('scripts')
<script type="text/javascript">
$(document).ready(function() {
var data = $('#data-komplain-kategori').DataTable({
var data = $('#data-tipe-regulasi').DataTable({
processing: true,
serverSide: true,
ajax: "{!! route('setting.tipe-regulasi.getdata') !!}",
Expand Down
Loading