Detail Berita
+-
+
- Detail berita dapat dilihat di sini. +
diff --git a/app/Exports/NewsExport.php b/app/Exports/NewsExport.php index 99b9cb7..1c24cd7 100644 --- a/app/Exports/NewsExport.php +++ b/app/Exports/NewsExport.php @@ -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); } } diff --git a/app/Http/Controllers/Dashboard/DatatableController.php b/app/Http/Controllers/Dashboard/DatatableController.php index caacbe8..ab4f79f 100644 --- a/app/Http/Controllers/Dashboard/DatatableController.php +++ b/app/Http/Controllers/Dashboard/DatatableController.php @@ -574,6 +574,9 @@ public function news(Request $request){ return 'Pengumuman'; } }) + ->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)]); diff --git a/app/Http/Controllers/Dashboard/NewsController.php b/app/Http/Controllers/Dashboard/NewsController.php index edcbaa0..7e2482a 100644 --- a/app/Http/Controllers/Dashboard/NewsController.php +++ b/app/Http/Controllers/Dashboard/NewsController.php @@ -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 + ]); + } } diff --git a/public/assets/dashboard/js/custom.js b/public/assets/dashboard/js/custom.js index 4fada11..431cb0e 100644 --- a/public/assets/dashboard/js/custom.js +++ b/public/assets/dashboard/js/custom.js @@ -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'); diff --git a/resources/views/dashboard/content-recaps/create.blade.php b/resources/views/dashboard/content-recaps/create.blade.php index 13952b1..bbae5e6 100644 --- a/resources/views/dashboard/content-recaps/create.blade.php +++ b/resources/views/dashboard/content-recaps/create.blade.php @@ -91,14 +91,14 @@
Masukkan informasi untuk membuat berita/pengumuman baru.
+Perbarui informasi berita atau pengumuman yang telah dipublikasikan.
+