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: Event Datatables #974

Merged
merged 6 commits into from
Jun 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
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,59 @@
* @link https://github.com/OpenSID/opendk
*/

namespace App\Http\Controllers\Informasi;
namespace App\Http\Controllers\BackEnd;

use App\Http\Controllers\Controller;
use App\Http\Requests\EventRequest;
use App\Models\Event;
use Illuminate\Support\Carbon;
use App\Http\Requests\EventRequest;
use Illuminate\Support\Facades\File;
use Yajra\DataTables\Facades\DataTables;
use App\Http\Controllers\BackEndController;

class EventController extends Controller
class EventController extends BackEndController
{
public function index()
{
$page_title = 'Event';
$page_description = 'Daftar Event';
$events = Event::getOpenEvents();

return view('informasi.event.index', compact('page_title', 'page_description', 'events'));
return view('backend.event.index', compact('page_title', 'page_description'));
}

public function datatables()
{
return DataTables::of(Event::query())
->editColumn('start', function ($row) {
return Carbon::parse($row->start)->format('d-m-Y H:i');
})
->editColumn('end', function ($row) {
return Carbon::parse($row->end)->format('d-m-Y H:i');
})
->addColumn('aksi', function ($row) {
if ($row->status == 'OPEN') {
$data['show_url'] = route('event.detail', $row->slug);

if (! auth()->guest()) {
$data['edit_url'] = route('informasi.event.edit', $row->id);
$data['delete_url'] = route('informasi.event.destroy', $row->id);
}
}

if ($row->status == 'CLOSED' && $row->attachment != null) {
$data['download_url'] = route('informasi.event.download', $row->id);
}

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

public function create()
{
$page_title = 'Event';
$page_description = 'Tambah Event';

return view('informasi.event.create', compact('page_title', 'page_description'));
return view('backend.event.create', compact('page_title', 'page_description'));
}

public function store(EventRequest $request)
Expand All @@ -64,6 +93,7 @@ public function store(EventRequest $request)
$input['start'] = date('Y-m-d H:i', strtotime($waktu[0]));
$input['end'] = date('Y-m-d H:i', strtotime($waktu[1]));
$input['status'] = 'OPEN';

Event::create($input);
} catch (\Exception $e) {
report($e);
Expand All @@ -76,11 +106,14 @@ public function store(EventRequest $request)

public function edit(Event $event)
{
if ($event->status == 'CLOSED') {
return redirect()->route('informasi.event.index')->with('error', 'Event sudah ditutup! Tidak bisa diubah!');
}

$page_title = 'Event';
$page_description = 'Ubah Event';
$event->waktu = $event->start.' - '.$event->end;

return view('informasi.event.edit', compact('page_title', 'page_description', 'event'));
return view('backend.event.edit', compact('page_title', 'page_description', 'event'));
}

public function update(EventRequest $request, Event $event)
Expand All @@ -104,26 +137,35 @@ public function update(EventRequest $request, Event $event)
} catch (\Exception $e) {
report($e);

return back()->withInput()->with('error', 'Ubah Event gagal!');
return back()->with('error', 'Data Event gagal disimpan!');
}

return redirect()->route('informasi.event.index')->with('success', 'Ubah Event sukses!');
return redirect()->route('informasi.event.index')->with('success', 'Data Event berhasil disimpan!');
}

public function destroy(Event $event)
{
if ($event->status == 'CLOSED') {
return redirect()->route('informasi.event.index')->with('error', 'Event sudah ditutup! Tidak bisa dihapus!');
}

try {
if ($event->delete()) {
if ($event->file_dokumen != null && File::exists(base_path('public/'.$event->file_dokumen))) {
unlink(base_path('public/'.$event->file_dokumen));
if ($event->attachment != null && File::exists(base_path('public/'.$event->attachment))) {
unlink(base_path('public/'.$event->attachment));
}
}
} catch (\Exception $e) {
report($e);

return redirect()->route('informasi.event.index')->with('error', 'Event gagal dihapus!');
return redirect()->route('informasi.event.index')->with('error', 'Event Gagal dihapus!');
}

return redirect()->route('informasi.event.index')->with('success', 'Event berhasil dihapus!');
return redirect()->route('informasi.event.index')->with('success', 'Event Berhasil dihapus!');
}

public function download(Event $event)
{
return response()->download(base_path('public/'.$event->attachment));
}
}
3 changes: 2 additions & 1 deletion catatan_rilis.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ Di rilis versi v2406.1.0 di versi ini terdapat [untuk diisi] dan perbaikan lain
3. [#968](https://github.com/OpenSID/OpenDK/issues/968) Penyesuaian modul regulasi menggunakan datatable.
4. [#969](https://github.com/OpenSID/OpenDK/issues/969) Penyesuaian modul potensi menggunakan datatable.
5. [#965](https://github.com/OpenSID/OpenDK/issues/965) Penyesuaian seeders dan factories.
6. [#964](https://github.com/OpenSID/OpenDK/issues/964) Penyesuaian Lang (bahasa) yang tidak digunakan.
6. [#964](https://github.com/OpenSID/OpenDK/issues/964) Penyesuaian Lang (bahasa) yang tidak digunakan.
7. [#970](https://github.com/OpenSID/OpenDK/issues/970) Penyesuaian modul event menggunakan datatable.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<div class="box-body">

@include('flash::message')
@include('informasi.event.form_create')
@include('backend.event.form_create')

</div>
<div class="box-footer">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
<div class="box box-primary">

<!-- form start -->
{!! Form::model($event, ['route' => ['informasi.event.update', $event->id], 'method' => 'post', 'id' => 'form-event', 'class' => 'form-horizontal form-label-left', 'files' => true]) !!}
{!! Form::model($event, ['route' => ['informasi.event.update', $event->id], 'method' => 'PUT', 'id' => 'form-event', 'class' => 'form-horizontal form-label-left', 'files' => true]) !!}
@include('layouts.fragments.error_message')

<div class="box-body">
@include('flash::message')
@include('informasi.event.form_edit')
@include('backend.event.form_edit')
</div>
<!-- /.box-body -->
<div class="box-footer">
Expand Down
90 changes: 90 additions & 0 deletions resources/views/backend/event/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
@extends('layouts.dashboard_template')

@section('content')
<section class="content-header">
<h1>
{{ $page_title ?? 'Page Title' }}
<small>{{ $page_description ?? '' }}</small>
</h1>
<ol class="breadcrumb">
<li><a href="{{ route('dashboard') }}"><i class="fa fa-dashboard"></i> Dashboard</a></li>
<li class="active">{!! $page_title !!}</li>
</ol>
</section>

<section class="content container-fluid">
@include('partials.flash_message')

<div class="box box-primary">
<div class="box-header with-border">
<a href="{{ route('informasi.event.create') }}"
class="btn btn-success btn-sm btn-social {{ auth()->guest() ? 'hidden' : '' }}" title="Tambah Data"><i
class="fa fa-plus"></i>&nbsp;Tambah</a>
</div>
<!-- /.box-header -->
<div class="box-body">
<div class="table-responsive">
<table class="table table-striped table-bordered" id="event-table">
<thead>
<tr>
<th class="text-center" style="max-width: 150px;">Aksi</th>
<th>Kegiatan</th>
<th>Tanggal Mulai</th>
<th>Tanggal Selesai</th>
<th>Dihadiri Oleh</th>
<th>Status</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
</section>
@endsection

@include('partials.asset_datatables')

@push('scripts')
<script type="text/javascript">
$(document).ready(function() {
var data = $('#event-table').DataTable({
processing: true,
serverSide: false,
ajax: "{!! route('informasi.event.getdata') !!}",
columns: [{
data: 'aksi',
name: 'aksi',
class: 'text-nowrap',
searchable: false,
orderable: false
},
{
data: 'event_name',
name: 'event_name'
},
{
data: 'start',
name: 'start'
},
{
data: 'end',
name: 'end'
},
{
data: 'attendants',
name: 'attendants'
},
{
data: 'status',
name: 'status'
},
],
order: [
[2, 'asc']
]
});
});
</script>
@include('forms.datatable-vertical')
@include('forms.delete-modal')
@endpush
131 changes: 0 additions & 131 deletions resources/views/informasi/event/index.blade.php

This file was deleted.

Loading