chore: change show UI

This commit is contained in:
myuqinurrohman 2025-04-16 09:00:51 +07:00
parent 48560b9b3f
commit 3d4afa7e11
12 changed files with 179 additions and 72 deletions

View File

@ -17,6 +17,7 @@ class NewsExport implements FromCollection, WithHeadings, WithStyles, WithMappin
* @return \Illuminate\Support\Collection
*/
protected $no = 1;
protected $category;
protected $year;
protected $month;
@ -31,7 +32,7 @@ public function __construct($category, $year, $month, $date)
}
public function collection()
{
$query = News::query()->select(['id', 'title', 'category', 'created_at']);
$query = News::query();
if($this->category !== 'all'){
if($this->category === 'news'){
@ -61,18 +62,22 @@ public function collection()
public function map($news): array
{
return [
$news->id,
$this->no++,
$news->title,
$news->link ?? 'Tidak ada',
$news->tag ?? 'Tidak ada',
$news->category === '0' ? 'Berita' : 'Pengumuman',
Carbon::parse($news->created_at)->locale('id')->translatedFormat('l, d F Y')
$news->views == '0'? '0' : $news->views,
Carbon::parse($news->created_at)->locale('id')->translatedFormat('l, d F Y'),
$news->author->name,
];
}
public function headings(): array
{
return [
['Data Berita', '', '', ''],
['NO', 'Judul', 'Kategori', 'Dibuat Pada']
['Data Berita', '', '', '', '', '', '', ''],
['NO', 'Judul', 'Link', 'Tag', 'Kategori', 'Dilihat', 'Dibuat Pada', 'Dibuat Oleh']
];
}
@ -81,16 +86,20 @@ public function styles(Worksheet $sheet)
$sheet->mergeCells('A1:D1'); // A1 sampai D1 digabung
// Set alignment untuk pusat horizontal dan vertikal
$sheet->getStyle('A1:D1')->getAlignment()->setHorizontal('center');
$sheet->getStyle('A1:D1')->getAlignment()->setVertical('center');
$sheet->getStyle('A1:H1')->getAlignment()->setHorizontal('center');
$sheet->getStyle('A1:H1')->getAlignment()->setVertical('center');
$sheet->getColumnDimension('A')->setWidth(7); // Set column A width
$sheet->getColumnDimension('A')->setAutoSize(true);
$sheet->getColumnDimension('B')->setAutoSize(true);
$sheet->getColumnDimension('C')->setWidth(15); // Set column C width
$sheet->getColumnDimension('D')->setWidth(25); // Set column D width
$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);
// Menambahkan gaya lain jika diperlukan
$sheet->getStyle('A1:D1')->getFont()->setBold(true);
$sheet->getStyle('A1:D1')->getFont()->setSize(14);
$sheet->getStyle('A1:H1')->getFont()->setBold(true);
$sheet->getStyle('A1:H1')->getFont()->setSize(14);
}
}

View File

@ -574,6 +574,9 @@ public function news(Request $request){
return '<span class="badge bg-info" style="display:inline-block;font-size:0.8rem;">Pengumuman</span>';
}
})
->addColumn('posted_at', function ($data) {
return idn_date($data->created_at, 'd F Y');
})
->addColumn('action', function ($data) {
$showUrl = route('dashboard.news.show', ['id' => encrypt_id($data->id)]);

View File

@ -16,7 +16,7 @@ class NewsController extends Controller
{
public function index(Request $request){
return view('dashboard.news.index', [
'title' => 'Berita',
'title' => 'Data Berita',
'category' => $request->input('category', null),
'year' => $request->input('year', null),
'month' => $request->input('month', null),
@ -27,7 +27,7 @@ public function index(Request $request){
public function create(){
return view('dashboard.news.create', [
'title' => 'Tambah Berita'
'title' => 'Buat Berita Baru'
]);
}
@ -36,6 +36,12 @@ public function store(NewsRequest $request){
$validatedData['slug'] = Str::slug($validatedData['title']);
$validatedData['author_id'] = Auth::id();
$isNewsExists = News::where('slug', $validatedData['slug'])->first();
if($isNewsExists){
return redirect()->back()->with('failed-status', 'Maaf, berita dengan judul tersebut sudah pernah ditambahkan.');
}
if($request->has('image')){
$validatedData['image'] = store_file($validatedData['image'], '/uploads/news', 'public')['randomFileName'];
}
@ -74,6 +80,12 @@ public function update(NewsRequest $request, $id){
$validatedData['slug'] = Str::slug($validatedData['title']);
$validatedData['author_id'] = Auth::id();
$isNewsExists = News::where('slug', $validatedData['slug'])->first();
if($isNewsExists && $isNewsExists->id !== $news->id){
return redirect()->back()->with('failed-status', 'Maaf, berita dengan judul tersebut sudah pernah ditambahkan.');
}
$news = News::findOrFail(decrypt_id($id));
$updatedNews = $news->update($validatedData);
@ -96,7 +108,9 @@ public function show($id){
public function destroy($id){
try {
$news = News::findOrFail(decrypt_id($id));
delete_file('app/public/uploads/news/'.$news->image);
$news->update([
'slug' => $news->slug.'-deleted-'. now()->timestamp
]);
$news->delete();
@ -136,4 +150,13 @@ public function printData($slug){
return $pdf->stream('berita-'.$news->slug.'.pdf');
}
public function checkLink(Request $request)
{
$linkExists = News::where('link', $request->link)->exists();
return response()->json([
'exists' => $linkExists
]);
}
}

View File

@ -80,6 +80,7 @@ $(document).ready(function () {
}
// Panggil fungsi untuk masing-masing input
setupLinkChecker('#newsLink', '#newsLinkFeedback', '/dashboard/news/check-link');
setupLinkChecker('#mediaMonitoringLink', '#mediaMonitoringLinkFeedback', '/dashboard/media-monitorings/check-link');
setupLinkChecker('#reportLink', '#reportLinkFeedback', '/dashboard/reports/check-link');
setupLinkChecker('#contentRecapLink', '#contentRecapLinkFeedback', '/dashboard/content-recaps/check-link');

View File

@ -91,14 +91,14 @@
</div>
<div class="col-lg-6">
<div class="form-group">
<label class="form-label" for="posted_date">Gambar<span class="required-input">*</span></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">
<label class="form-file-label" for="image">Gambar berupa screenshoot</label>
</div>
</div>
@error('posted_date')
@error('image')
<span class="validation-error">{{$message}}</span>
@enderror
</div>

View File

@ -94,14 +94,14 @@
</div>
<div class="col-lg-6">
<div class="form-group">
<label class="form-label" for="posted_date">Gambar<span class="required-input">*</span></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">
<label class="form-file-label" for="image">Gambar berupa screenshoot</label>
</div>
</div>
@error('posted_date')
@error('image')
<span class="validation-error">{{$message}}</span>
@enderror
</div>

View File

@ -10,7 +10,10 @@
<div class="card card-bordered card-preview">
<div class="card-inner">
<div class="card-head">
<h5 class="card-title">{{$title}}</h5>
<div class="nk-block-head">
<h5 class="title">Buat Berita Baru</h5>
<p>Masukkan informasi untuk membuat berita/pengumuman baru.</p>
</div>
</div>
<form action="{{route('dashboard.news.store')}}" method="post" enctype="multipart/form-data" id="myForm">
@csrf
@ -30,7 +33,8 @@
<div class="form-group">
<label class="form-label" for="link">Link</label>
<div class="form-control-wrap">
<input type="text" class="form-control @error('link') border-danger @enderror" id="link" name="link" placeholder="Masukan link" value="{{old('link')}}">
<input type="text" class="form-control @error('link') border-danger @enderror" id="newsLink" name="link" placeholder="Masukan link" value="{{old('link')}}">
<small id="newsLinkFeedback" class="d-none"></small>
</div>
@error('link')
<span class="validation-error">{{$message}}</span>
@ -46,6 +50,9 @@
<option value="1" {{old('category') == '1' ? 'selected' : ''}}>Pengumuman</option>
</select>
</div>
@error('category')
<span class="validation-error">{{$message}}</span>
@enderror
</div>
</div>
<div class="col-lg-6">
@ -63,7 +70,10 @@
<div class="form-group">
<label class="form-label" for="image">Gambar</label>
<div class="form-control-wrap">
<input type="file" class="form-control @error('image') border-danger @enderror" id="image" name="image" accept="image/*">
<div class="form-file">
<input type="file" accept="image/*" class="form-file-input" id="image" name="image">
<label class="form-file-label" for="image">Sampul berita/pengumuman</label>
</div>
</div>
@error('image')
<span class="validation-error">{{$message}}</span>
@ -73,6 +83,9 @@
<div class="col-lg-12">
<div class="form-group">
<label class="form-label" for="phone-no-1">Konten<span class="required-input">*</span></label>
@error('content')
<span class="validation-error">{{$message}}</span>
@enderror
<div class="form-control-wrap">
<textarea class="tinymce-basic form-control" name="content">{!!old('content')!!}</textarea>
</div>

View File

@ -10,7 +10,10 @@
<div class="card card-bordered card-preview">
<div class="card-inner">
<div class="card-head">
<h5 class="card-title">{{$title}}</h5>
<div class="nk-block-head">
<h5 class="title">Ubah Berita</h5>
<p>Perbarui informasi berita atau pengumuman yang telah dipublikasikan.</p>
</div>
</div>
<form action="{{route('dashboard.news.update', ['id' => encrypt_id($news->id)])}}" method="post" enctype="multipart/form-data" id="myForm">
@csrf
@ -47,6 +50,9 @@
<option value="1" {{$news->category == '1' ? 'selected' : ''}}>Pengumuman</option>
</select>
</div>
@error('category')
<span class="validation-error">{{$message}}</span>
@enderror
</div>
</div>
<div class="col-lg-6">
@ -62,9 +68,22 @@
</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 @if (filled($news->image))
<span>
<a href="javascript:void(0);" data-bs-toggle="modal" data-bs-target="#modalDefault">
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" 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-eye">
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
<path d="M10 12a2 2 0 1 0 4 0a2 2 0 0 0 -4 0" />
<path d="M21 12c-2.4 4 -5.4 6 -9 6c-3.6 0 -6.6 -2 -9 -6c2.4 -4 5.4 -6 9 -6c3.6 0 6.6 2 9 6" />
</svg>
</a>
</span>
@endif</label>
<div class="form-control-wrap">
<input type="file" class="form-control @error('image') border-danger @enderror" id="image" name="image" accept="image/*">
<div class="form-file">
<input type="file" accept="image/*" class="form-file-input" id="image" name="image">
<label class="form-file-label" for="image">{{!filled($news->image) ? 'Tidak ada sampul' : $news->image}}</label>
</div>
</div>
@error('image')
<span class="validation-error">{{$message}}</span>
@ -74,6 +93,9 @@
<div class="col-lg-12">
<div class="form-group">
<label class="form-label" for="phone-no-1">Konten<span class="required-input">*</span></label>
@error('content')
<span class="validation-error">{{$message}}</span>
@enderror
<div class="form-control-wrap">
<textarea class="tinymce-basic form-control" name="content">{!!$news->content!!}</textarea>
</div>
@ -92,6 +114,21 @@
</div>
</div>
</form>
<div class="modal fade" tabindex="-1" id="modalDefault">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Preview Sampul</h5>
<a href="#" class="close" data-bs-dismiss="modal" aria-label="Close">
<em class="icon ni ni-cross"></em>
</a>
</div>
<div class="modal-body">
<img src="{{asset(display_image($news->image, 'news'))}}" alt="">
</div>
</div>
</div>
</div>
</div>
</div>
</div>

View File

@ -17,12 +17,19 @@
<div class="toggle-expand-content" data-content="pageMenu">
<ul class="nk-block-tools g-3">
<li>
<div class="drodown">
@if (filled(value: $category) ||filled($year) || filled($month) || filled($date))
<span class="mx-1">
<a href="{{route('dashboard.news.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>
@endif
<div>
<a href="javascript: void(0);" class="btn btn-white btn-dim btn-outline-light" data-bs-toggle="modal" data-bs-target="#modalFilter"><em class="d-none d-sm-inline icon ni ni-filter"></em><span><span class="d-none d-md-inline">Filter</a>
</div>
</li>
<li>
<div class="drodown">
<div>
<a href="javascript: void(0);" class="btn btn-info" data-bs-toggle="modal" data-bs-target="#modalExport"><em class="d-none d-sm-inline icon ni ni-upload"></em><span><span class="d-none d-md-inline">Export</a>
</div>
</li>
@ -45,6 +52,7 @@
<th>Link</th>
<th>Kategori</th>
<th>Tag</th>
<th>Dibuat</th>
<th></th>
</tr>
</thead>

View File

@ -6,13 +6,29 @@
<div class="container-fluid">
<div class="nk-content-inner">
<div class="nk-content-body">
<div class="nk-block-head nk-block-head-sm">
<div class="nk-block-between g-3">
<div class="nk-block-head-content">
<h3 class="nk-block-title page-title">Detail Berita</h3>
<div class="nk-block-des text-soft">
<ul class="list-inline">
<li>Detail berita dapat dilihat di sini.</li>
</ul>
</div>
</div>
<div class="nk-block-head-content">
<a href="{{route('dashboard.news.index')}}" class="btn btn-outline-light bg-white d-none d-sm-inline-flex"><em class="icon ni ni-arrow-left"></em><span>Kembali</span></a>
<a href="{{route('dashboard.news.index')}}" class="btn btn-icon btn-outline-light bg-white d-inline-flex d-sm-none"><em class="icon ni ni-arrow-left"></em></a>
</div>
</div>
</div><!-- .nk-block-head -->
<div class="nk-block nk-block-lg">
<div class="card">
<div class="card-aside-wrap">
<div class="card-content">
<ul class="nav nav-tabs nav-tabs-mb-icon nav-tabs-card">
<li class="nav-item">
<a class="nav-link text-primary" href="#"><em class="icon ni ni-info"></em><span>Detail Berita</span></a>
<a class="nav-link text-primary" href="javascript:void(0);"><em class="icon ni ni-info"></em><span>Detail Informasi</span></a>
</li>
</ul><!-- .nav-tabs -->
<div class="card-inner">
@ -54,21 +70,15 @@
</div>
<div class="profile-ud-item">
<div class="profile-ud wider">
<span class="profile-ud-label">Gambar</span>
<span class="profile-ud-value">
@if (filled($news->image))
<a href="javascript:void(0);" data-bs-toggle="modal" data-bs-target="#modalDefault" class="btn btn-sm btn-info">Lihat gambar</a>
@else
Tidak ada gambar
@endif
</span>
<span class="profile-ud-label">Tag</span>
<span class="profile-ud-value">{{$news->tag}}</span>
</div>
</div>
<div class="profile-ud-item">
<div class="profile-ud wider">
<span class="profile-ud-label">Dilihat</span>
<span class="profile-ud-value">
{{$news->viewers ?? '-'}}
{{$news->views}}
</span>
</div>
</div>
@ -78,9 +88,33 @@
<span class="profile-ud-value">{{idn_date($news->created_at, 'l, d F Y')}}</span>
</div>
</div>
<div class="profile-ud-item">
<div class="profile-ud wider">
<span class="profile-ud-label">Dibuat Oleh</span>
<span class="profile-ud-value">{{$news->author->name}}</span>
</div>
</div>
</div><!-- .profile-ud-list -->
</div><!-- .nk-block -->
{{-- <div class="nk-divider divider md"></div> --}}
<div class="nk-block">
{{-- <div class="nk-block-head nk-block-head-sm nk-block-between">
<h5 class="title">Admin Note</h5>
</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">
<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> Sampul</h6>
<span class="accordion-icon"></span>
</a>
<div class="accordion-body collapse" id="news" data-bs-parent="#accordion">
<div class="accordion-inner">
{!! display_file('news', $news->image) !!}
</div>
</div>
</div>
</div>
</div><!-- .nk-block -->
<div class="nk-block">
<div class="nk-block-head nk-block-head-sm nk-block-between">
<span class="profile-ud-label">Konten</span>
@ -93,35 +127,10 @@
</div><!-- .bq-note-item -->
</div><!-- .bq-note -->
</div><!-- .nk-block -->
<hr>
<div class="nk-block d-flex justify-content-end">
<a href="{{route('dashboard.news.index')}}" class="btn btn-white btn-dim btn-outline-light mx-2"><span>Kembali</span></a>
@if (!filled($news->deleted_at))
<a href="{{route('dashboard.news.edit', ['id' => encrypt_id($news->id), 'show' => true])}}" class="btn btn-warning"><span>Ubah</span></a>
@endif
</div><!-- .nk-block -->
</div><!-- .card-inner -->
</div><!-- .card-content -->
</div><!-- .card-aside-wrap -->
</div>
<div class="modal fade" tabindex="-1" id="modalDefault">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Preview</h5>
<a href="#" class="close" data-bs-dismiss="modal" aria-label="Close">
<em class="icon ni ni-cross"></em>
</a>
</div>
<div class="modal-body">
<img src="{{asset('storage/uploads/news/'. $news->image)}}" alt="preview">
</div>
{{-- <div class="modal-footer bg-light">
<span class="sub-text">Modal Footer Text</span>
</div> --}}
</div>
</div>
</div>
</div>
</div>
</div>

View File

@ -332,23 +332,26 @@
{ data: 'link', name: 'link' },
{ data: 'category', name: 'category' },
{ data: 'tag', name: 'tag' },
{ data: 'posted_at', name: 'posted_at' },
{ data: 'action', name: 'action', orderable: false, searchable: false },
{ data: 'created_at', name: 'created_at', visible: false },
{ data: 'id', name: 'id', orderable: true, searchable: false, visible: false },
],
columnDefs: [
{ targets: 0, width: 'auto' },
// { targets: 2, width: '10%' },
{ targets: 3, width: '10%' },
{ targets: 4, width: '12%' },
{ targets: 5, width: '7%' },
{ targets: 0, width: '5%' }, // Index
{ targets: 1, width: '25%' }, // Title
{ targets: 2, width: '15%' }, // Link
{ targets: 3, width: '7%' }, // Category
{ targets: 4, width: '10%' }, // Tag
{ targets: 5, width: '7%' }, // Dibuat
{ targets: 6, width: '2%', className: 'text-center' }, // Action button
{
targets: [1,2],
createdCell: function(td, cellData, rowData, row, col) {
targets: [1, 2], // Title & Link
createdCell: function(td) {
$(td).css({
'word-wrap': 'break-word',
'white-space': 'normal',
'overflow-wrap': 'break-word'
'word-break': 'break-word',
});
}
}
@ -356,7 +359,7 @@
language: datatableLanguage,
// responsive: true,
autoWidth: false,
order: [[6, 'desc']],
order: [[7, 'desc']],
pagingType: "simple",
lengthMenu: [[10, 25, 50, 100, -1], ['Tampilkan 10 data', 'Tampilkan 25 data', 'Tampilkan 50 data', 'Tampilkan 100 data', 'Tampilkan semua']],
scrollX: true

View File

@ -176,6 +176,7 @@
Route::get('/', 'index')->name('index');
Route::get('/{id}/show', 'show')->name('show');
Route::get('/create', 'create')->name('create');
Route::post('/check-link', 'checkLink')->name('check.link');
Route::post('/', 'store')->name('store');
Route::get('/{id}/edit', 'edit')->name('edit');
Route::put('/{id}', 'update')->name('update');