From 081aee4c7c23ee83ea51efcd63d9c64e0a2898a0 Mon Sep 17 00:00:00 2001 From: Firliani Fauziah Date: Mon, 28 Oct 2024 10:47:25 +0700 Subject: [PATCH 1/5] pengaturan menu presisi --- app/Helpers/general.php | 108 ++++++++++++++++++ app/Http/Controllers/CMS/MenuController.php | 17 ++- app/Http/Repository/CMS/MenuRepository.php | 39 +++++-- app/Models/CMS/Menu.php | 1 + ...10_26_040605_add_menu_type_table_menus.php | 33 ++++++ ...8_013521_add-default-menu-presisi-data.php | 43 +++++++ resources/views/menus/fields.blade.php | 10 ++ resources/views/menus/index.blade.php | 8 ++ .../views/presisi/partials/footer.blade.php | 1 - .../views/presisi/partials/head.blade.php | 31 ++--- resources/views/web/partials/nav.blade.php | 2 +- 11 files changed, 264 insertions(+), 29 deletions(-) create mode 100644 database/migrations/2024_10_26_040605_add_menu_type_table_menus.php create mode 100644 database/migrations/2024_10_28_013521_add-default-menu-presisi-data.php diff --git a/app/Helpers/general.php b/app/Helpers/general.php index c3c8056f..77dd3bdf 100644 --- a/app/Helpers/general.php +++ b/app/Helpers/general.php @@ -2,6 +2,8 @@ use App\Models\Config; use App\Models\SettingAplikasi; +use App\Models\Bantuan; +use App\Models\Enums\SasaranEnum; use Carbon\Carbon; use Illuminate\Support\Str; use Intervention\Image\Facades\Image; @@ -269,6 +271,35 @@ function generateMenu($tree, $parentId = null) } } +if (! function_exists('generateMenuPresisi')) { + function generateMenuPresisi($tree, $parentId = null) + { + $result = ''; + foreach ($tree as $item) { + if ($item->children->count() > 0) { + $result .= "'; + } else { + if ($parentId) { + $result .= "{$item->text}"; + } else { + $result .= "{$item->text}"; + } + } + } + + return $result; + } +} + + if (! function_exists('angka_lokal')) { /** * Menampilkan nilai persentase. @@ -724,3 +755,80 @@ function persen3($number, $total, $precision = 2) return round(($number / $total) * 100, $precision).'%'; } + +if (! function_exists('getStatistikLabel')) { + /** + * Mendapatkan label statistik berdasarkan kode laporan. + * + * @param mixed $lap + * @param mixed $stat + * @param mixed $namaDesa + * + * @return array + */ + function getStatistikLabel($lap, $stat, $namaDesa) + { + $akhiran = ' di ' . ucwords(setting('sebutan_desa') . ' ' . $namaDesa) . ', ' . date('Y'); + $kategori = 'Penduduk'; + $label = 'Jumlah dan Persentase Penduduk Berdasarkan ' . $stat . $akhiran; + + if ((int) $lap > 50) { + // Untuk program bantuan, $lap berbentuk '50' + $program_id = substr($lap, 2); + $program = Bantuan::select(['nama', 'sasaran'])->find($program_id)->toArray(); + $program['judul_sasaran'] = SasaranEnum::valueOf($program['sasaran']); + $kategori = 'Bantuan'; + $label = 'Jumlah dan Persentase Peserta ' . $program['nama'] . $akhiran; + } elseif ((int) $lap > 20 || $lap === 'kelas_sosial') { + $kategori = 'Keluarga'; + $label = 'Jumlah dan Persentase Keluarga Berdasarkan ' . $stat . $akhiran; + } else { + switch ($lap) { + case 'bantuan_keluarga': + $kategori = 'Bantuan'; + $label = 'Jumlah dan Persentase ' . $stat . $akhiran; + break; + + case 'bdt': + $kategori = 'RTM'; + $label = 'Jumlah dan Persentase Rumah Tangga Berdasarkan ' . $stat . $akhiran; + break; + + case '1': + $label = 'Jumlah dan Persentase Penduduk Berdasarkan Aktivitas atau Jenis Pekerjaannya ' . $akhiran; + break; + + case '0': + case '14': + $label = 'Jumlah dan Persentase Penduduk Berdasarkan ' . $stat . ' yang Dicatat dalam Kartu Keluarga ' . $akhiran; + break; + + case '13': + case '15': + $label = 'Jumlah dan Persentase Penduduk Menurut Kelompok ' . $stat . $akhiran; + break; + + case '16': + $label = 'Jumlah dan Persentase Penduduk Menurut Penggunaan Alat Keluarga Berencana dan Jenis Kelamin ' . $akhiran; + break; + + case '13': + $label = 'Jumlah Keluarga dan Penduduk Berdasarkan Wilayah RT ' . $akhiran; + break; + + case '4': + $label = 'Jumlah Penduduk yang Memiliki Hak Suara ' . $stat . $akhiran; + break; + + case 'hamil': + $label = 'Jumlah dan Persentase Penduduk Perempuan Berdasarkan ' . $stat . $akhiran; + break; + } + } + + return [ + 'kategori' => $kategori, + 'label' => $label, + ]; + } +} diff --git a/app/Http/Controllers/CMS/MenuController.php b/app/Http/Controllers/CMS/MenuController.php index b11f5777..c023bbed 100644 --- a/app/Http/Controllers/CMS/MenuController.php +++ b/app/Http/Controllers/CMS/MenuController.php @@ -26,6 +26,10 @@ public function __construct(MenuRepository $menuRepo) */ public function index() { + $type = 1; + if (request('type') != null){ + $type = request('type'); + } $sourceItem = [ 'Halaman' => Page::activePublished()->get()->pluck('title', 'link')->toArray(), 'Kategori' => Category::all()->pluck('name', 'link')->toArray(), @@ -47,11 +51,20 @@ public function store(UpdateMenuRequest $request) { $input = $request->all(); + $menu_type = $input["menu_type"] == null ? 1 : $input["menu_type"]; + $menu = $this->menuRepository->create($input); Session::flash('success', 'Menu berhasil disimpan.'); - - return redirect(route('menus.index')); + if ($menu_type == 1){ + return redirect(route('menus.index')); + } + else if ($menu_type == 2){ + return redirect(route('menus.index') . "?type=" .$menu_type); + } + else{ + return redirect(route('menus.index')); + } } protected function getOptionItems($id = null) diff --git a/app/Http/Repository/CMS/MenuRepository.php b/app/Http/Repository/CMS/MenuRepository.php index 55a5fd68..b26dba47 100644 --- a/app/Http/Repository/CMS/MenuRepository.php +++ b/app/Http/Repository/CMS/MenuRepository.php @@ -10,6 +10,7 @@ class MenuRepository extends BaseRepository { protected $fieldSearchable = [ + 'menu_type', 'name', 'url', 'sequence', @@ -29,22 +30,35 @@ public function model(): string public function treeJson(): string { - $menus = $this->tree()->toArray(); + $type = 1; + if (request('type') != null){ + $type = request('type'); + } + $menus = $this->tree($type)->toArray(); $this->removeEmptyChildren($menus); return json_encode($menus); } - public function tree(): Collection|null + public function tree($menu_type): Collection|null { - return $this->model->selectRaw("id, parent_id , name as text, url as href, 'fas fa-list' as icon") - ->whereNull('parent_id') + if($menu_type == null){ + $menu_type = request('type'); + } + $menus = $this->model->selectRaw("id, parent_id , name as text, url as href, 'fas fa-list' as icon"); + if($menu_type != null){ + $menus = $menus->where('menu_type', $menu_type); + } + else{ + $menus = $menus->where('menu_type', 1); + } + $menus = $menus->whereNull('parent_id') ->with(['children' => function ($q) { $q->selectRaw("id, parent_id , name as text, url as href, 'fas fa-list' as icon"); }]) - ->orderBy('sequence') - ->get(); + ->orderBy('sequence'); + return $menus->get(); } private function removeEmptyChildren(&$array) @@ -63,22 +77,25 @@ private function removeEmptyChildren(&$array) */ public function create(array $input): Model { - $this->model->whereNotNull('id')->delete(); + $menu_type = $input['menu_type'] != null ? $input['menu_type'] : 1; + + $this->model->where('menu_type', $menu_type)->whereNotNull('id')->delete(); + try { // hapus data lama lalu buat lagi $json = json_decode($input['json_menu'], 1); - - return $this->loopTree($json); + return $this->loopTree($json, $menu_type); } catch (\Throwable $th) { throw $th; } } - private function loopTree(array $elements, $parentId = null) + private function loopTree(array $elements, $menu_type, $parentId = null) { $sequence = 1; foreach ($elements as $element) { $input = [ + 'menu_type' => $menu_type, 'name' => $element['text'], 'url' => $element['href'], 'sequence' => $sequence, @@ -86,7 +103,7 @@ private function loopTree(array $elements, $parentId = null) ]; $model = parent::create($input); if (isset($element['children'])) { - $this->loopTree($element['children'], $model->id); + $this->loopTree($element['children'], $menu_type, $model->id); } $sequence++; } diff --git a/app/Models/CMS/Menu.php b/app/Models/CMS/Menu.php index 982d5076..99ff7e65 100644 --- a/app/Models/CMS/Menu.php +++ b/app/Models/CMS/Menu.php @@ -10,6 +10,7 @@ class Menu extends Model public $table = 'menus'; public $fillable = [ + 'menu_type', 'name', 'url', 'sequence', diff --git a/database/migrations/2024_10_26_040605_add_menu_type_table_menus.php b/database/migrations/2024_10_26_040605_add_menu_type_table_menus.php new file mode 100644 index 00000000..9da29756 --- /dev/null +++ b/database/migrations/2024_10_26_040605_add_menu_type_table_menus.php @@ -0,0 +1,33 @@ +integer('menu_type')->default(1)->change(); + $table->string('menu_type')->default(1)->after('id'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('menus', function($table) { + $table->dropColumn('menu_type'); + }); + } +}; diff --git a/database/migrations/2024_10_28_013521_add-default-menu-presisi-data.php b/database/migrations/2024_10_28_013521_add-default-menu-presisi-data.php new file mode 100644 index 00000000..d67963ae --- /dev/null +++ b/database/migrations/2024_10_28_013521_add-default-menu-presisi-data.php @@ -0,0 +1,43 @@ +insert([ + ["id" => "191", "menu_type" => "2", "name" => " Terkini", "url" => "#", "sequence" => "1", "position" => "top", "parent_id" => NULL, "created_at" => "2023-09-27 17:39:33"], + ["id" => "192","menu_type" => "2", "name" => " Demografi", "url" => "/presisi", "sequence" => "2", "position" => "top", "parent_id" => NULL, "created_at" => "2023-09-27 17:39:33"], + ["id" => "193","menu_type" => "2", "name" => " Sosial", "url" => "/presisi/bantuan", "sequence" => "3", "position" => "top", "parent_id" => NULL, "created_at" => "2023-09-27 17:39:33"], + ["id" => "194","menu_type" => "2", "name" => "Data Kemiskinan", "url" => "/presisi/sosial", "sequence" => "1", "position" => "top", "parent_id" => "193", "created_at" => "2023-09-27 17:39:33"], + ["id" => "195","menu_type" => "2", "name" => "Program Bantuan", "url" => "/presisi/bantuan", "sequence" => "2", "position" => "top", "parent_id" => "193", "created_at" => "2023-09-27 17:39:33"], + ["id" => "196","menu_type" => "2", "name" => " Kependudukan", "url" => "/presisi/kependudukan", "sequence" => "4", "position" => "top", "parent_id" => NULL, "created_at" => "2023-09-27 17:39:33"], + ["id" => "197","menu_type" => "2", "name" => "Statistik Penduduk", "url" => "/presisi/kependudukan", "sequence" => "1", "position" => "top", "parent_id" => "196", "created_at" => "2023-09-27 17:39:33"], + ["id" => "198","menu_type" => "2", "name" => "Statistik Keluarga", "url" => "#", "sequence" => "2", "position" => "top", "parent_id" => "196", "created_at" => "2023-09-27 17:39:33"], + ["id" => "199","menu_type" => "2", "name" => "Statistik RTM", "url" => "#", "sequence" => "3", "position" => "top", "parent_id" => "196", "created_at" => "2023-09-27 17:39:33"], + ["id" => "200","menu_type" => "2", "name" => " Ekonomi", "url" => "/presisi/ekonomi", "sequence" => "5", "position" => "top", "parent_id" => NULL, "created_at" => "2023-09-27 17:39:33"], + ["id" => "201","menu_type" => "2", "name" => " E-Stunting", "url" => "/presisi/kesehatan", "sequence" => "6", "position" => "top", "parent_id" => NULL, "created_at" => "2023-09-27 17:39:33"], + ["id" => "202","menu_type" => "2", "name" => " Geo Spasial", "url" => "#", "sequence" => "7", "position" => "top", "parent_id" => NULL, "created_at" => "2023-09-27 17:39:33"], + ]); + } + + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +}; diff --git a/resources/views/menus/fields.blade.php b/resources/views/menus/fields.blade.php index 0c00af3d..28acf114 100644 --- a/resources/views/menus/fields.blade.php +++ b/resources/views/menus/fields.blade.php @@ -1,6 +1,7 @@
+ {!! Form::select('menu_type', array('1' => 'Default', '2' => 'Presisi'), '1',['class' => 'form-control']) !!}
{!! Form::text('text', null, ['class' => 'form-control item-menu', 'maxlength' => 255, 'placeholder' => 'Nama Menu']) !!} {!! Form::hidden('icon', 'fas fa-list', ['class' => 'item-menu']) !!}
@@ -59,6 +60,15 @@ $('select[name=sourcelist]').on('change', function(){ $('input[name=href]').val($(this).val()) }) + + $('select[name=menu_type]').on('change', function(){ + window.location.href = "{{ url('cms/menus') }}?type=" + this.value; + }) + + const queryString = window.location.search; + const urlParams = new URLSearchParams(queryString); + const menutype = urlParams.get('type') + $('select[name=menu_type]').val((menutype == null ? 1 : menutype)); }) @endpush diff --git a/resources/views/menus/index.blade.php b/resources/views/menus/index.blade.php index 7dac5ca1..0d9e9265 100644 --- a/resources/views/menus/index.blade.php +++ b/resources/views/menus/index.blade.php @@ -89,10 +89,18 @@ $("#btnUpdate").click(function () { editor.update(); + const queryString = window.location.search; + const urlParams = new URLSearchParams(queryString); + const menutype = urlParams.get('type') + $('select[name=menu_type]').val((menutype == null ? 1 : menutype)); }); $('#btnAdd').click(function () { editor.add(); + const queryString = window.location.search; + const urlParams = new URLSearchParams(queryString); + const menutype = urlParams.get('type') + $('select[name=menu_type]').val((menutype == null ? 1 : menutype)); }); $('#frmEdit').bind('reset', function(e){ diff --git a/resources/views/presisi/partials/footer.blade.php b/resources/views/presisi/partials/footer.blade.php index 6961b41d..9457d58e 100644 --- a/resources/views/presisi/partials/footer.blade.php +++ b/resources/views/presisi/partials/footer.blade.php @@ -12,5 +12,4 @@
- diff --git a/resources/views/presisi/partials/head.blade.php b/resources/views/presisi/partials/head.blade.php index d00bc466..cf98441c 100644 --- a/resources/views/presisi/partials/head.blade.php +++ b/resources/views/presisi/partials/head.blade.php @@ -1,34 +1,35 @@
-

- {{ $identitasAplikasi['nama_aplikasi'] }}

+

{{ $identitasAplikasi['nama_aplikasi'] }}

- -
- - + {{-- + Demografi @@ -47,20 +48,22 @@ Ekonomi - + E-Stunting + --}} + + {!! generateMenuPresisi((new \App\Http\Repository\CMS\MenuRepository)->tree(2)) !!}
+
{!! Form::select('penduduk', $sourceItem['penduduk'], null, ['class' => 'form-control', 'style' => 'display:none;']) !!} @@ -43,7 +62,7 @@ @push('js')