Skip to content

Commit

Permalink
rilis pantau v2309.0.0 (#205)
Browse files Browse the repository at this point in the history
Co-authored-by: ahmad afandi <ahmad.afandi85@gmail.com>
Co-authored-by: Andi Fahruddin Akas <andifahruddinakas@gmail.com>
Co-authored-by: pandigresik <pandigresik@users.noreply.github.com>
Co-authored-by: Agung Sugiarto <sugiartoagung92@gmail.com>
Co-authored-by: Andi Fahruddin Akas <57283157+andifahruddinakas@users.noreply.github.com>
Co-authored-by: Afila <apidongblog@gmail.com>
Co-authored-by: apidong <apidong@users.noreply.github.com>
Co-authored-by: Habibie <habibie.mahbub@gmail.com>
Co-authored-by: Abah Roland <59082428+vickyrolanda@users.noreply.github.com>
Co-authored-by: Abah Roland <v.rolanda92@gmail.com>
  • Loading branch information
11 people authored Sep 1, 2023
1 parent 9dbf8ee commit 9a46a83
Show file tree
Hide file tree
Showing 56 changed files with 3,480 additions and 150 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/public/storage
/storage/*.key
/vendor
/tools
.env
.env.backup
.php-cs-fixer.cache
Expand Down
100 changes: 100 additions & 0 deletions app/Helpers/helper.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
<?php

use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http;

if (! function_exists('pantau_versi')) {
/**
* OpenKab database gabungan versi.
*/
function pantau_versi()
{
return 'v2309.0.0';
}
}

if (! function_exists('kode_wilayah')) {
/**
* Kode wilayah dengan titik dari 5201142005 --> 52.01.14.2005
Expand Down Expand Up @@ -123,3 +134,92 @@ function lastrelease($url)
}
}
}

if (! function_exists('lastrelease_opensid')) {
/**
* Validasi domain.
*
* @param string $url
* @return object
*/
function lastrelease_opensid()
{
$version = Cache::get('opensid_premium_version', '2307.0.1');
$versi_opensid = lastrelease('https://api.github.com/repos/OpenSID/rilis-premium/releases/latest');

if ($versi_opensid !== false) {
$version = str_replace('v', '', $versi_opensid->tag_name);
Cache::forever('opensid_premium_version', $version);
}

return $version;
}
}

if (! function_exists('pantau_wilayah_khusus')) {
/**
* Validasi domain.
*
* @param string $url
* @return object
*/
function pantau_wilayah_khusus()
{
return Cache::get('pantau_wilayah_khusus', []);
}
}

if (! function_exists('abaikan_domain')) {
/**
* Validasi domain.
*
* @param string $url
* @return object
*/
function abaikan_domain($aplikasi)
{
switch($aplikasi) {
case 'opendk':
return Cache::get('abaikan_domain_opendk', '');
break;
default:
return Cache::get('abaikan_domain_opensid', '');
}
}
}

if (! function_exists('cleanVersi')) {
/**
* Convert versi agar sama
* 22.06 menjadi 2206, versi terbaru menggunakan YYmm bukan YY.mm
* @param string $url
* @return object
*/
function cleanVersi($version)
{
$version = preg_replace('/[^0-9]/', '', $version);

return substr($version, 0, 4);
}
}

if (! function_exists('lastrelease_opendk')) {
/**
* Validasi domain.
*
* @param string $url
* @return object
*/
function lastrelease_opendk()
{
$version = Cache::get('opendk_version', '2307.0.0');
$versi_opendk = lastrelease('https://api.github.com/repos/OpenSID/opendk/releases/latest');

if ($versi_opendk !== false) {
$version = str_replace('v', '', $versi_opendk->tag_name);
Cache::forever('opendk_version', $version);
}

return $version;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,63 @@
use App\Http\Requests\PengaturanAplikasiRequest;
use App\Models\PengaturanAplikasi;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;

class PengaturanAplikasiController extends Controller
{
public function index(Request $request)
{
$pengaturan = PengaturanAplikasi::where(['kategori' => 'setting'])->get();
$kategori = ['setting'];
$kategori = ['setting', 'wilayah_khusus'];

return view('admin.pengaturan.pengaturan_aplikasi.index', compact('pengaturan', 'kategori'));
}

public function store(PengaturanAplikasiRequest $request)
{
try {
foreach ($request->validated() as $key => $value) {
if (! $request->get('wilayah_khusus')) {
$request->merge(['wilayah_khusus' => '[]']);
}
if (! $request->get('abaikan_domain_opendk')) {
$request->merge(['abaikan_domain_opendk' => null]);
}
if (! $request->get('abaikan_domain_opensid')) {
$request->merge(['abaikan_domain_opensid' => null]);
}
foreach ($request->all() as $key => $value) {
if (is_array($value)) {
switch ($key) {
case 'abaikan_domain_opendk':
case 'abaikan_domain_opensid':
$value = $value ? implode('|', $value) : null;
break;
default:
$value = collect($value)->map(function ($item) {
return json_decode($item);
})->toJson();
}
}
PengaturanAplikasi::where(['key' => $key])->update(['value' => $value]);

switch($key) {
case 'abaikan_domain_opendk':
Cache::forever('abaikan_domain_opendk', $value);
break;
case 'abaikan_domain_opensid':
Cache::forever('abaikan_domain_opensid', $value);
break;
}
}
$wilayahKhusus = [];
$tmp = PengaturanAplikasi::where(['key' => 'wilayah_khusus', 'kategori' => 'setting'])->select(['value'])->first();
if (! empty($tmp->value)) {
foreach (json_decode($tmp->value) as $key => $val) {
$wilayahKhusus[$val->key] = $val->value;
}
}

Cache::forever('pantau_wilayah_khusus', $wilayahKhusus);
} catch (\Throwable $th) {
return back()->with('error', 'Data gagal diubah');
}
Expand Down
74 changes: 68 additions & 6 deletions app/Http/Controllers/Admin/Wilayah/KecamatanController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,87 @@
namespace App\Http\Controllers\Admin\Wilayah;

use App\Http\Controllers\Controller;
use App\Http\Requests\RegionKecamatanRequest;
use App\Models\Region;
use Illuminate\Http\Request;
use Yajra\DataTables\DataTables;

class KecamatanController extends Controller
{
public function index()
public function index(Request $request)
{
return view('admin.wilayah.kecamatan.index');
}
$r = Region::with(['child'])->find(67);

public function datatables(Request $request)
{
if ($request->ajax()) {
return DataTables::of(Region::kecamatan())
->addIndexColumn()
->addColumn('action', function ($data) {
$edit = '<a href="'.url('kecamatan/'.$data->id.'/edit').'" class="btn btn-sm btn-warning btn-sm"><i class="fas fa-pencil-alt"></i></a>';
$delete = '<button data-href="'.url('kecamatan/'.$data->id).'" class="btn btn-sm btn-danger" data-toggle="modal" data-target="#confirm-delete"><i class="fas fa-trash"></i></button>';

return '<div class="btn btn-group">'.$edit.$delete.'</div>';
})
->rawColumns(['action'])
->make(true);
}

abort(404);
return view('admin.wilayah.kecamatan.index');
}

public function create()
{
return view('admin.wilayah.kecamatan.create');
}

public function store(RegionKecamatanRequest $request)
{
$input = $request->all();

if (Region::create($input)) {
return redirect('kecamatan')->with('success', 'Data berhasil disimpan');
}

return back()->with('error', 'Data gagal disimpan');
}

public function edit($id)
{
return view('admin.wilayah.kecamatan.edit', [
'kecamatan' => Region::kecamatan()->findOrFail($id),
]);
}

public function update(RegionKecamatanRequest $request, $id)
{
$input = $request->all();
$kecamatan = Region::kecamatan()->find($id);

if ($kecamatan->nama_kecamatan != $input['region_name']) {
$input['new_region_name'] = $input['region_name'];

unset($input['region_name']);
}

if ($kecamatan->update($input)) {
return redirect('kecamatan')->with('success', 'Data berhasil diubah');
}

return back()->with('error', 'Data gagal diubah');
}

public function destroy($id)
{
// pastikan tidak ada region dengan parent_code kecamatan ini
$region = Region::with(['child'])->find($id);

if ($region->child->count()) {
return redirect('kecamatan')->with('error', 'Data gagal dihapus karena data ini menjadi induk dari desa '.$region->child->pluck('region_name')->join(', '));
}

if (Region::destroy($id)) {
return redirect('kecamatan')->with('success', 'Data berhasil dihapus');
}

return redirect('kecamatan')->with('error', 'Data gagal dihapus');
}
}
116 changes: 116 additions & 0 deletions app/Http/Controllers/MobileController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php

namespace App\Http\Controllers;

use App\Models\Desa;
use App\Models\TrackMobile;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Config;
use Yajra\DataTables\Facades\DataTables;

class MobileController extends Controller
{
private $mobile;

protected $baseRoute = 'mobile';

protected $baseView = 'mobile';

public function __construct()
{
$this->mobile = new TrackMobile();
Config::set('title', $this->baseView.'');
}

public function index()
{
$totalPengguna = $this->mobile->wilayahKhusus()->count();
$totalDesaPengguna = $this->mobile->wilayahKhusus()->desa()->count();
$totalDesaPenggunaAktif = $this->mobile->wilayahKhusus()->desa()->active()->count();
$totalPenggunaAktif = $this->mobile->wilayahKhusus()->count();

$desaWidgets = [
'semua' => ['urlWidget' => (Auth::check() ? url($this->baseRoute.'/pengguna') : ''), 'titleWidget' => 'Total Pengguna', 'classWidget' => 'col-lg-3', 'classBackgroundWidget' => 'bg-info', 'totalWidget' => $totalPengguna, 'iconWidget' => 'fa-user'],
'aktif' => ['urlWidget' => (Auth::check() ? url($this->baseRoute.'/pengguna?akses_mobile=1') : ''), 'titleWidget' => 'Pengguna Aktif', 'classWidget' => 'col-lg-3', 'classBackgroundWidget' => 'bg-success', 'totalWidget' => $totalPenggunaAktif, 'iconWidget' => 'fa-shopping-cart'],
'desa' => ['urlWidget' => url($this->baseRoute.'/desa'), 'titleWidget' => 'Total Desa', 'classWidget' => 'col-lg-3', 'classBackgroundWidget' => 'bg-primary', 'totalWidget' => $totalDesaPengguna, 'iconWidget' => 'fa-user'],
'desa_aktif' => ['urlWidget' => url($this->baseRoute.'/desa?akses_mobile=1'), 'titleWidget' => 'Desa pengguna Aktif', 'classWidget' => 'col-lg-3', 'classBackgroundWidget' => 'bg-warning', 'totalWidget' => $totalDesaPenggunaAktif, 'iconWidget' => 'fa-shopping-cart'],
];
$penggunaBaru = $this->mobile->wilayahKhusus()->selectRaw('kode_desa, count(kode_desa) as jumlah')->with(['desa'])
->groupBy('kode_desa')
->where('created_at', '>=', now()->subDay(7))->get();

return view($this->baseView.'.dashboard', [
'baseRoute' => $this->baseRoute,
'baseView' => $this->baseView,
'desaWidgets' => $desaWidgets,
'daftar_baru' => $penggunaBaru,
]);
}

public function pengguna(Request $request)
{
$fillters = [
'kode_provinsi' => $request->kode_provinsi,
'kode_kabupaten' => $request->kode_kabupaten,
'akses_mobile' => $request->akses_mobile,
];

if ($request->ajax()) {
return DataTables::of(TrackMobile::wilayahKhusus()->filter($request)->with(['desa']))
->addIndexColumn()
->make(true);
}

return view($this->baseView.'.pengguna', compact('fillters'));
}

public function desa(Request $request)
{
$fillters = [
'kode_provinsi' => $request->kode_provinsi,
'kode_kabupaten' => $request->kode_kabupaten,
'akses_mobile' => $request->akses_mobile,
];
if ($request->ajax()) {
return DataTables::of(Desa::whereHas('mobile', function (Builder $query) use ($request) {
$query->when($request['kode_provinsi'], function ($q) use ($request) {
$q->whereRaw('left(kode_desa, 2) = '.$request['kode_provinsi']);
});
$query->when($request['kode_kabupaten'], function ($q) use ($request) {
$q->whereRaw('left(kode_desa, 5) = '.$request['kode_kabupaten']);
});
$query->when($request['kode_kecamatan'], function ($q) use ($request) {
$q->whereRaw('left(kode_desa, 8) = '.$request['kode_kecamatan']);
});
$query->when(! empty($request['akses_mobile']), function ($query) use ($request) {
$interval = 'interval '.TrackMobile::ACTIVE_DAYS.' day';
$sign = '>=';
switch($request['akses_mobile']) {
case '1':
$interval = 'interval '.TrackMobile::ACTIVE_DAYS.' day';
break;
case '2':
$interval = 'interval 2 month';
break;
case '3':
$interval = 'interval 2 month';
$sign = '<=';
break;
}

return $query->whereRaw('tgl_akses '.$sign.' now() - '.$interval);
});
})->wilayahKhusus()->with(['mobile' => function ($r) {
$r->select('kode_desa');
}]))
->addColumn('jumlah', function ($data) {
return $data->mobile->count();
})
->make(true);
}

return view($this->baseView.'.desa', compact('fillters'));
}
}
Loading

0 comments on commit 9a46a83

Please sign in to comment.