feat: filter data
feat: export data
This commit is contained in:
parent
2ee3c08670
commit
a9278afa77
@ -110,7 +110,7 @@ public function headings(): array
|
||||
|
||||
public function styles(Worksheet $sheet)
|
||||
{
|
||||
$sheet->mergeCells('A1:I1'); // A1 sampai D1 digabung
|
||||
$sheet->mergeCells('A1:I1'); // A1 sampai I1 digabung
|
||||
|
||||
// Set alignment untuk pusat horizontal dan vertikal
|
||||
$sheet->getStyle('A1:I1')->getAlignment()->setHorizontal('center');
|
||||
|
||||
115
app/Exports/ContentRecapExport.php
Normal file
115
app/Exports/ContentRecapExport.php
Normal file
@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use App\Models\ContentRecap;
|
||||
use Carbon\Carbon;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Maatwebsite\Excel\Concerns\WithStyles;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
|
||||
|
||||
class ContentRecapExport implements FromCollection, WithHeadings, WithStyles, WithMapping
|
||||
{
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
protected $no = 1;
|
||||
protected $classification;
|
||||
protected $channel;
|
||||
protected $social_media;
|
||||
protected $posted_year;
|
||||
protected $posted_month;
|
||||
protected $posted_date;
|
||||
|
||||
public function __construct($classification, $channel, $social_media, $posted_year, $posted_month, $posted_date)
|
||||
{
|
||||
$this->classification = $classification;
|
||||
$this->channel = $channel;
|
||||
$this->social_media = $social_media;
|
||||
$this->posted_year = $posted_year;
|
||||
$this->posted_month = $posted_month;
|
||||
$this->posted_date = $posted_date;
|
||||
}
|
||||
|
||||
public function collection()
|
||||
{
|
||||
$query = ContentRecap::with(['enhancer', 'classification']);
|
||||
|
||||
if($this->classification && $this->classification !== 'all'){
|
||||
$query->where('classification_id', decrypt_id($this->classification));
|
||||
}
|
||||
|
||||
if($this->channel && $this->channel !== 'all'){
|
||||
$query->where('channel', $this->channel);
|
||||
}
|
||||
|
||||
if($this->social_media && $this->social_media !== 'all'){
|
||||
$query->where('social_media', $this->social_media);
|
||||
}
|
||||
|
||||
if ($this->posted_year) {
|
||||
$query->whereYear('posted_date', $this->posted_year);
|
||||
}
|
||||
|
||||
if ($this->posted_month) {
|
||||
$monthYear = Carbon::parse($this->posted_month);
|
||||
$query->whereYear('posted_date', $monthYear->year)
|
||||
->whereMonth('posted_date', $monthYear->month);
|
||||
}
|
||||
|
||||
if ($this->posted_date) {
|
||||
$query->whereDate('posted_date', $this->posted_date);
|
||||
}
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
public function map($contentRecap): array
|
||||
{
|
||||
return [
|
||||
$this->no++,
|
||||
$contentRecap->content_theme,
|
||||
$contentRecap->link,
|
||||
$contentRecap->classification->name,
|
||||
$contentRecap->social_media,
|
||||
Carbon::parse($contentRecap->posted_date)->locale('id')->translatedFormat('l, d F Y'),
|
||||
$contentRecap->channel,
|
||||
filled($contentRecap->description) ? strip_tags($contentRecap->description) : 'Tidak ada',
|
||||
Carbon::parse($contentRecap->created_at)->locale('id')->translatedFormat('l, d F Y'),
|
||||
];
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
['Data Rekap Konten', '', '', '', '', '', '', '', ''],
|
||||
['NO', 'Tema Konten', 'Link', 'Klasifikasi', 'Media Sosial', 'Tanggal Posting', 'Channel', 'Deskripsi', 'Dibuat Pada']
|
||||
];
|
||||
}
|
||||
|
||||
public function styles(Worksheet $sheet)
|
||||
{
|
||||
$sheet->mergeCells('A1:I1'); // A1 sampai D1 digabung
|
||||
|
||||
// Set alignment untuk pusat horizontal dan vertikal
|
||||
$sheet->getStyle('A1:I1')->getAlignment()->setHorizontal('center');
|
||||
$sheet->getStyle('A1:I1')->getAlignment()->setVertical('center');
|
||||
|
||||
$sheet->getColumnDimension('A')->setWidth(7); // Set column A width
|
||||
$sheet->getColumnDimension('B')->setAutoSize(true);
|
||||
$sheet->getColumnDimension('C')->setAutoSize(true);
|
||||
$sheet->getColumnDimension('D')->setAutoSize(true);
|
||||
$sheet->getColumnDimension('E')->setAutoSize(true);
|
||||
$sheet->getColumnDimension('F')->setAutoSize(true);
|
||||
$sheet->getColumnDimension('G')->setAutoSize(true);
|
||||
$sheet->getColumnDimension('H')->setAutoSize(true);
|
||||
$sheet->getColumnDimension('I')->setAutoSize(true);
|
||||
|
||||
// Menambahkan gaya lain jika diperlukan
|
||||
$sheet->getStyle('A1:I1')->getFont()->setBold(true);
|
||||
$sheet->getStyle('A1:I1')->getFont()->setSize(14);
|
||||
}
|
||||
}
|
||||
@ -2,12 +2,15 @@
|
||||
|
||||
namespace App\Http\Controllers\Dashboard;
|
||||
|
||||
use App\Exports\ContentRecapExport;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\ContentRecapRequest;
|
||||
use App\Models\ContentRecap;
|
||||
use App\Models\ContentRecapClassification;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
class ContentRecapController extends Controller
|
||||
{
|
||||
@ -15,8 +18,8 @@ public function index(Request $request){
|
||||
return view('dashboard.content-recaps.index', [
|
||||
'title' => 'Rekap Konten',
|
||||
'classifications' => ContentRecapClassification::all(),
|
||||
'classification' => $request->input('classification', null),
|
||||
'channel' => $request->input('channel', null),
|
||||
'classification' => $request->input('classification', null),
|
||||
'social_media' => $request->input('social_media', null),
|
||||
'posted_year' => $request->input('posted_year', null),
|
||||
'posted_month' => $request->input('posted_month', null),
|
||||
@ -111,4 +114,29 @@ public function checkLink(Request $request)
|
||||
'exists' => $linkExists
|
||||
]);
|
||||
}
|
||||
|
||||
public function filter(Request $request){
|
||||
|
||||
$filteredRequest = $request->except('_token');
|
||||
|
||||
$filterField = array_filter($filteredRequest, function ($value) {
|
||||
return filled($value);
|
||||
});
|
||||
|
||||
return redirect()->route('dashboard.content.recaps.index', $filterField);
|
||||
}
|
||||
|
||||
public function export(Request $request)
|
||||
{
|
||||
$classification = $request->input('classification', 'all');
|
||||
$channel = $request->input('channel', 'all');
|
||||
$social_media = $request->input('social_media', 'all');
|
||||
$posted_year = $request->input('posted_year', null);
|
||||
$posted_month = $request->input('posted_month', null);
|
||||
$posted_date = $request->input('posted_date', null);
|
||||
|
||||
$formattedNow = Carbon::parse(now())->locale('id')->translatedFormat('d-m-Y');
|
||||
|
||||
return Excel::download(new ContentRecapExport($classification, $channel, $social_media, $posted_year, $posted_month, $posted_date), 'content-recaps-'.$formattedNow.'.xlsx');
|
||||
}
|
||||
}
|
||||
|
||||
@ -2095,14 +2095,49 @@ class="text-dark"
|
||||
public function contentRecap(Request $request){
|
||||
if ($request->ajax()) {
|
||||
|
||||
$classificationParam = $request->input('classification', null);
|
||||
$classification = $request->input('classification', null);
|
||||
$channel = $request->input('channel', null);
|
||||
$social_media = $request->input('social_media', null);
|
||||
$posted_year = $request->input('posted_year', null);
|
||||
$posted_month = $request->input('posted_month', null);
|
||||
$posted_date = $request->input('posted_date', null);
|
||||
|
||||
if(filled($classificationParam)){
|
||||
$data = ContentRecap::where('classification_id', decrypt_id($classificationParam))->get();
|
||||
}else{
|
||||
$data = ContentRecap::all();
|
||||
$query = ContentRecap::query();
|
||||
|
||||
if($classification && $classification !== 'all'){
|
||||
$query->where('classification_id', decrypt_id($classification));
|
||||
}
|
||||
|
||||
if($channel && $channel !== 'all'){
|
||||
$query->where('channel', $channel);
|
||||
}
|
||||
|
||||
if($social_media && $social_media !== 'all'){
|
||||
$query->where('social_media', $social_media);
|
||||
}
|
||||
|
||||
if ($posted_year) {
|
||||
$query->whereYear('posted_date', $posted_year);
|
||||
}
|
||||
|
||||
if ($posted_month) {
|
||||
$monthYear = Carbon::parse($posted_month);
|
||||
$query->whereYear('posted_date', $monthYear->year)
|
||||
->whereMonth('posted_date', $monthYear->month);
|
||||
}
|
||||
|
||||
if ($posted_date) {
|
||||
$query->whereDate('posted_date', $posted_date);
|
||||
}
|
||||
|
||||
$data = $query->get();
|
||||
|
||||
// if(filled($classification)){
|
||||
// $data = ContentRecap::where('classification_id', decrypt_id($classification))->get();
|
||||
// }else{
|
||||
// $data = ContentRecap::all();
|
||||
// }
|
||||
|
||||
|
||||
return DataTables::of($data)
|
||||
->addIndexColumn()
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
<form action="{{route('dashboard.content.recaps.store')}}" method="post" enctype="multipart/form-data" id="myForm">
|
||||
@csrf
|
||||
<div class="row g-4">
|
||||
<div class="col-lg-6">
|
||||
<div class="col-lg-12">
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="content_theme">Tema Konten<span class="required-input">*</span></label>
|
||||
<div class="form-control-wrap">
|
||||
@ -106,7 +106,7 @@
|
||||
</div>
|
||||
<div class="col-lg-6">
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="image">Gambar</label>
|
||||
<label class="form-label" for="image">Gambar<span class="required-input">*</span></label>
|
||||
<div class="form-control-wrap">
|
||||
<div class="form-file">
|
||||
<input type="file" accept="image/*" class="form-file-input" id="image" name="image">
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
@csrf
|
||||
@method('put')
|
||||
<div class="row g-4">
|
||||
<div class="col-lg-6">
|
||||
<div class="col-lg-12">
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="content_theme">Tema Konten<span class="required-input">*</span></label>
|
||||
<div class="form-control-wrap">
|
||||
@ -150,7 +150,7 @@
|
||||
</a>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<img src="{{asset(display_image($contentRecap->image, 'news'))}}" alt="">
|
||||
<img src="{{asset(display_image($contentRecap->image, 'content-recaps'))}}" alt="">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -17,9 +17,9 @@
|
||||
<div class="toggle-expand-content" data-content="pageMenu">
|
||||
<ul class="nk-block-tools g-3">
|
||||
<li>
|
||||
@if (filled(value: $channel) || filled(value: $social_media) || filled($posted_year) || filled($posted_month) || filled($posted_date))
|
||||
@if (filled(value: $channel) || filled($classification) || filled(value: $social_media) || filled($posted_year) || filled($posted_month) || filled($posted_date))
|
||||
<span class="mx-1">
|
||||
<a href="{{route('dashboard.news.index')}}" class="text-secondary">
|
||||
<a href="{{route('dashboard.content.recaps.index')}}" class="text-secondary">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor" class="icon icon-tabler icons-tabler-filled icon-tabler-xbox-x"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M12 2c5.523 0 10 4.477 10 10s-4.477 10 -10 10s-10 -4.477 -10 -10s4.477 -10 10 -10m3.6 5.2a1 1 0 0 0 -1.4 .2l-2.2 2.933l-2.2 -2.933a1 1 0 1 0 -1.6 1.2l2.55 3.4l-2.55 3.4a1 1 0 1 0 1.6 1.2l2.2 -2.933l2.2 2.933a1 1 0 0 0 1.6 -1.2l-2.55 -3.4l2.55 -3.4a1 1 0 0 0 -.2 -1.4" /></svg>
|
||||
</a>
|
||||
</span>
|
||||
@ -71,13 +71,13 @@
|
||||
<em class="icon ni ni-cross"></em>
|
||||
</a>
|
||||
</div>
|
||||
<form action="{{route('dashboard.news.export')}}" class="form-validate is-alter" method="post">
|
||||
<form action="{{route('dashboard.content.recaps.export')}}" class="form-validate is-alter" method="post">
|
||||
@csrf
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Kanal</label>
|
||||
<div class="form-control-wrap">
|
||||
<select class="form-select js-select2" name="channel" data-search="on">
|
||||
<select class="form-select js-select2" name="channel">
|
||||
<option value="all">Semua</option>
|
||||
<option value="website">Website</option>
|
||||
<option value="tiktok">Tiktok</option>
|
||||
@ -92,10 +92,10 @@
|
||||
<div class="form-group">
|
||||
<label class="form-label">Klasifikasi</label>
|
||||
<div class="form-control-wrap">
|
||||
<select class="form-select js-select2" name="category">
|
||||
<select class="form-select js-select2" name="classification">
|
||||
<option value="all">Semua</option>
|
||||
@foreach ($classifications as $item)
|
||||
<option value="encrypt_id({{$item->id}})">{{$item->name}}</option>
|
||||
<option value="{{encrypt_id($item->id)}}">{{$item->name}}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
@ -112,21 +112,21 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="year">Tahun</label>
|
||||
<label class="form-label" for="posted_year">Tahun Posting</label>
|
||||
<div class="form-control-wrap">
|
||||
<input type="number" class="form-control" id="year" placeholder="Data berita pada tahun" name="year">
|
||||
<input type="number" class="form-control" id="posted_year" placeholder="Data berita pada tahun" name="posted_year">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="month">Bulan</label>
|
||||
<label class="form-label" for="posted_month">Bulan Posting</label>
|
||||
<div class="form-control-wrap">
|
||||
<input type="month" class="form-control" id="month" placeholder="Data berita pada bulan dan tahun" name="month">
|
||||
<input type="month" class="form-control" id="posted_month" placeholder="Data berita pada bulan dan tahun" name="posted_month">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="date">Tanggal</label>
|
||||
<label class="form-label" for="posted_date">Tanggal Posting</label>
|
||||
<div class="form-control-wrap">
|
||||
<input type="date" class="form-control" id="date" placeholder="Data berita pada bulan dan tahun" name="date">
|
||||
<input type="date" class="form-control" id="posted_date" placeholder="Data berita pada bulan dan tahun" name="posted_date">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -148,13 +148,13 @@
|
||||
<em class="icon ni ni-cross"></em>
|
||||
</a>
|
||||
</div>
|
||||
<form action="{{route('dashboard.news.filter')}}" class="form-validate is-alter" method="post">
|
||||
<form action="{{route('dashboard.content.recaps.filter')}}" class="form-validate is-alter" method="post">
|
||||
@csrf
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Kanal</label>
|
||||
<div class="form-control-wrap">
|
||||
<select class="form-select js-select2" name="channel" data-search="on">
|
||||
<select class="form-select js-select2" name="channel">
|
||||
<option value="all" {{$channel == 'all' ? 'selected' : ''}}>Semua</option>
|
||||
<option value="website" {{$channel == 'website' ? 'selected' : ''}}>Website</option>
|
||||
<option value="tiktok" {{$channel == 'tiktok' ? 'selected' : ''}}>Tiktok</option>
|
||||
@ -169,10 +169,10 @@
|
||||
<div class="form-group">
|
||||
<label class="form-label">Klasifikasi</label>
|
||||
<div class="form-control-wrap">
|
||||
<select class="form-select js-select2" name="category">
|
||||
<select class="form-select js-select2" name="classification">
|
||||
<option value="all">Semua</option>
|
||||
@foreach ($classifications as $item)
|
||||
<option value="encrypt_id({{$item->id}})">{{$item->name}}</option>
|
||||
<option value="{{encrypt_id($item->id)}}">{{$item->name}}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
@ -189,21 +189,21 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="year">Tahun</label>
|
||||
<label class="form-label" for="posted_year">Tahun Posting</label>
|
||||
<div class="form-control-wrap">
|
||||
<input type="number" class="form-control" id="year" placeholder="Data berita pada tahun" name="year" value="{{ old('year', $year ?? '') }}">
|
||||
<input type="number" class="form-control" id="posted_year" placeholder="Data berita pada tahun" name="posted_year" value="{{ old('posted_year', $posted_year ?? '') }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="month">Bulan</label>
|
||||
<label class="form-label" for="posted_month">Bulan Posting</label>
|
||||
<div class="form-control-wrap">
|
||||
<input type="month" class="form-control" id="month" placeholder="Data berita pada bulan dan tahun" name="month" value="{{ old('month', $month ?? '') }}">
|
||||
<input type="month" class="form-control" id="posted_month" placeholder="Data berita pada bulan dan tahun" name="posted_month" value="{{ old('posted_month', $posted_month ?? '') }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="date">Tanggal</label>
|
||||
<label class="form-label" for="posted_date">Tanggal Posting</label>
|
||||
<div class="form-control-wrap">
|
||||
<input type="date" class="form-control" id="date" placeholder="Data berita pada bulan dan tahun" name="date" value="{{ old('date', $date ?? '') }}">
|
||||
<input type="date" class="form-control" id="posted_date" placeholder="Data berita pada bulan dan tahun" name="posted_date" value="{{ old('posted_date', $posted_date ?? '') }}">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -104,13 +104,13 @@
|
||||
</div><!-- .nk-block-head --> --}}
|
||||
<div id="accordion" class="accordion">
|
||||
<div class="accordion-item" style="background-color: #F5F6FA;">
|
||||
<a href="#" class="accordion-head collapsed" data-bs-toggle="collapse" data-bs-target="#news">
|
||||
<a href="#" class="accordion-head collapsed" data-bs-toggle="collapse" data-bs-target="#contentRecap">
|
||||
<h6 class="title"><svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-photo" style="margin-bottom: 0.2rem"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M15 8h.01" /><path d="M3 6a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v12a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3v-12z" /><path d="M3 16l5 -5c.928 -.893 2.072 -.893 3 0l5 5" /><path d="M14 14l1 -1c.928 -.893 2.072 -.893 3 0l3 3" /></svg> Gambar</h6>
|
||||
<span class="accordion-icon"></span>
|
||||
</a>
|
||||
<div class="accordion-body collapse" id="news" data-bs-parent="#accordion">
|
||||
<div class="accordion-body collapse" id="contentRecap" data-bs-parent="#accordion">
|
||||
<div class="accordion-inner">
|
||||
{!! display_file('news', $contentRecap->image) !!}
|
||||
{!! display_file('content-recaps', $contentRecap->image) !!}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -984,6 +984,11 @@
|
||||
type: 'GET',
|
||||
data: function(d) {
|
||||
d.classification = '{{ $classification }}';
|
||||
d.channel = '{{ $channel }}';
|
||||
d.social_media = '{{ $social_media }}';
|
||||
d.posted_year = '{{ $posted_year }}';
|
||||
d.posted_month = '{{ $posted_month }}';
|
||||
d.posted_date = '{{ $posted_date }}';
|
||||
}
|
||||
},
|
||||
columns: [
|
||||
|
||||
@ -496,6 +496,9 @@
|
||||
Route::get('/{id}/edit', 'edit')->name('edit');
|
||||
Route::put('/{id}', 'update')->name('update');
|
||||
Route::delete('/{id}', 'destroy')->name('destroy');
|
||||
|
||||
Route::post('/export', 'export')->name('export');
|
||||
Route::post('/filter', 'filter')->name('filter');
|
||||
});
|
||||
|
||||
Route::get('/data', [DatatableController::class, 'contentRecap'])->name('data');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user