From 0994e1717ad823029fff35012e15afe2bd274d85 Mon Sep 17 00:00:00 2001 From: myuqinurrohman Date: Thu, 17 Apr 2025 14:43:27 +0700 Subject: [PATCH] chore: change show content recap UI chore: change show content recap classification UI feat: add grouping by classification --- .../Dashboard/ContentRecapController.php | 31 +-- .../Dashboard/DatatableController.php | 13 +- app/Http/Requests/ContentRecapRequest.php | 25 ++- app/Models/ContentRecap.php | 3 +- app/Models/ContentRecapClassification.php | 4 + ..._15_102641_create_content_recaps_table.php | 2 +- database/seeders/ContentRecapSeeder.php | 2 +- public/assets/dashboard/css/custom.css | 4 + .../classifications/create.blade.php | 12 +- .../classifications/edit.blade.php | 12 +- .../classifications/show.blade.php | 40 +++- .../dashboard/content-recaps/create.blade.php | 42 +++- .../dashboard/content-recaps/edit.blade.php | 60 +++++- .../dashboard/content-recaps/index.blade.php | 2 +- .../dashboard/content-recaps/show.blade.php | 185 ++++++++++++------ .../views/partials/app/datatable.blade.php | 27 ++- 16 files changed, 341 insertions(+), 123 deletions(-) diff --git a/app/Http/Controllers/Dashboard/ContentRecapController.php b/app/Http/Controllers/Dashboard/ContentRecapController.php index f5fff70..ba2aeab 100644 --- a/app/Http/Controllers/Dashboard/ContentRecapController.php +++ b/app/Http/Controllers/Dashboard/ContentRecapController.php @@ -11,9 +11,10 @@ class ContentRecapController extends Controller { - public function index(){ + public function index(Request $request){ return view('dashboard.content-recaps.index', [ - 'title' => 'Rekap Konten' + 'title' => 'Rekap Konten', + 'classification' => $request->input('classification', null) ]); } @@ -28,15 +29,19 @@ public function store(ContentRecapRequest $request){ $validatedData = $request->validated(); $validatedData['enhancer_id'] = Auth::id(); - if($request->has('image')){ + if($request->has('image') && filled($validatedData['image'])){ $validatedData['image'] = store_file($validatedData['image'], '/uploads/content-recaps', 'public')['randomFileName']; + }else{ + $validatedData['image'] = null; } - $createdContentRecap = ContentRecap::create($validatedData); - if($createdContentRecap){ - return redirect()->back()->with('success-status', 'Berhasil menambahkan rekap konten.'); - }else{ + try{ + $createdContentRecap = ContentRecap::create($validatedData); + + return redirect()->route('dashboard.content.recaps.index')->with('success-status', 'Berhasil menambahkan rekap konten.') + ->with('new_data', encrypt_id($createdContentRecap->id)); + }catch(\Exception $e){ return redirect()->back()->with('failed-status', 'Gagal menambahkan rekap konten.'); } } @@ -56,18 +61,17 @@ public function update(ContentRecapRequest $request, $id){ $validatedData['enhancer_id'] = Auth::id(); $contentRecap = ContentRecap::findOrFail(decrypt_id($id)); - if($request->has('image')){ + if($request->has('image') && filled($validatedData['image'])){ delete_file('app/public/uploads/content-recaps/'.$contentRecap->image); $validatedData['image'] = store_file($validatedData['image'], '/uploads/content-recaps', 'public')['randomFileName']; }else{ $validatedData['image'] = $contentRecap->image; } - $updatedContentRecap = $contentRecap->update($validatedData); - - if($updatedContentRecap){ - return redirect()->back()->with('success-status', 'Berhasil mengubah rekap konten.'); - }else{ + try{ + $contentRecap->update($validatedData); + return redirect()->route('dashboard.content.recaps.show', ['id' => encrypt_id($contentRecap->id)])->with('success-status', 'Berhasil mengubah rekap konten.'); + }catch(\Exception $e){ return redirect()->back()->with('failed-status', 'Gagal mengubah rekap konten.'); } @@ -85,7 +89,6 @@ public function show($id){ public function destroy($id){ try { $contentRecap = ContentRecap::findOrFail(decrypt_id($id)); - $contentRecap->delete(); return response()->json(['message' => 'Berhasil menghapus rekap konten.']); diff --git a/app/Http/Controllers/Dashboard/DatatableController.php b/app/Http/Controllers/Dashboard/DatatableController.php index daad262..ddaa22d 100644 --- a/app/Http/Controllers/Dashboard/DatatableController.php +++ b/app/Http/Controllers/Dashboard/DatatableController.php @@ -516,8 +516,6 @@ public function airingProofTheme(Request $request){ public function contentRecapClassification(Request $request){ if ($request->ajax()) { - - $data = ContentRecapClassification::all(); return DataTables::of($data) @@ -563,7 +561,7 @@ public function contentRecapClassification(Request $request){ return $dropdown; }) - ->rawColumns(['action']) + ->rawColumns(['content_recaps', 'action']) ->make(true); } @@ -2097,7 +2095,14 @@ class="text-dark" public function contentRecap(Request $request){ if ($request->ajax()) { - $data = ContentRecap::all(); + $classificationParam = $request->input('classification', null); + + if(filled($classificationParam)){ + $data = ContentRecap::where('classification_id', decrypt_id($classificationParam))->get(); + }else{ + $data = ContentRecap::all(); + } + return DataTables::of($data) ->addIndexColumn() diff --git a/app/Http/Requests/ContentRecapRequest.php b/app/Http/Requests/ContentRecapRequest.php index 1b47057..ee32c2e 100644 --- a/app/Http/Requests/ContentRecapRequest.php +++ b/app/Http/Requests/ContentRecapRequest.php @@ -23,12 +23,13 @@ public function authorize(): bool public function rules(): array { $rules = [ - 'title' => ['required'], + 'content_theme' => ['required'], 'posted_date' => ['required', 'date'], - 'channel'=> ['required', 'in:website,tiktok,youtube,instagram,facebook,twitter,cetak'], + 'channel'=> ['required', 'in:website,tiktok,youtube,instagram,facebook,twitter,cetak', 'not_in:placeholder'], 'link' => ['required', 'url'], - 'classification_id' => ['required', 'exists:content_recap_classifications,id'], - 'social_media' => ['required'], + 'classification_id' => ['required', 'exists:content_recap_classifications,id', 'not_in:placeholder'], + 'social_media' => ['required', 'not_in:placeholder'], + 'description' => ['nullable'], ]; if($this->isMethod('post')){ @@ -40,14 +41,23 @@ public function rules(): array return $rules; } + protected function prepareForValidation() + { + $this->merge([ + 'image' => filled($this->image) ? $this->image : null, + 'description' => filled($this->description) ? $this->description : null, + ]); + } + public function messages() { return [ - 'title.required' => 'Judul wajib diisi.', + 'content_theme.required' => 'Tema konten wajib diisi.', + 'content_theme.max' => 'Tema konten tidak boleh lebih dari 200 karakter.', 'posted_date.required' => 'Tanggal posting wajib diisi.', 'posted_date.date' => 'Tanggal posting harus berupa format tanggal yang valid.', - 'channel.required' => 'Channel wajib dipilih.', - 'channel.in' => 'Channel harus salah satu dari: website, tiktok, youtube, instagram, facebook, twitter, atau cetak.', + 'channel.required' => 'Kanal wajib dipilih.', + 'channel.in' => 'Kanal harus salah satu dari: website, tiktok, youtube, instagram, facebook, twitter, atau cetak.', 'link.required' => 'Link wajib diisi.', 'link.url' => 'Link harus berupa URL yang valid.', 'classification_id.required' => 'Klasifikasi wajib dipilih.', @@ -57,6 +67,7 @@ public function messages() 'image.image' => 'File yang diunggah harus berupa gambar.', 'image.mimes' => 'Format gambar harus PNG, JPG, atau JPEG.', 'image.max' => 'Ukuran gambar maksimal 2MB.', + 'description.nullable' => 'Deskripsi bersifat opsional.', ]; } diff --git a/app/Models/ContentRecap.php b/app/Models/ContentRecap.php index 8a55ba0..dd1590e 100644 --- a/app/Models/ContentRecap.php +++ b/app/Models/ContentRecap.php @@ -11,13 +11,14 @@ class ContentRecap extends Model protected $table = 'content_recaps'; protected $fillable = [ - 'title', + 'content_theme', 'posted_date', 'channel', 'link', 'classification_id', 'social_media', 'image', + 'description', 'enhancer_id', ]; diff --git a/app/Models/ContentRecapClassification.php b/app/Models/ContentRecapClassification.php index 2e375ae..1b6db1b 100644 --- a/app/Models/ContentRecapClassification.php +++ b/app/Models/ContentRecapClassification.php @@ -21,4 +21,8 @@ class ContentRecapClassification extends Model public function contentRecaps(){ return $this->hasMany(ContentRecap::class, 'classification_id', 'id'); } + + public function enhancer(){ + return $this->belongsTo(User::class, 'enhancer_id', 'id'); + } } diff --git a/database/migrations/2025_04_15_102641_create_content_recaps_table.php b/database/migrations/2025_04_15_102641_create_content_recaps_table.php index 82e49a9..4de2f8f 100644 --- a/database/migrations/2025_04_15_102641_create_content_recaps_table.php +++ b/database/migrations/2025_04_15_102641_create_content_recaps_table.php @@ -13,7 +13,7 @@ public function up(): void { Schema::create('content_recaps', function (Blueprint $table) { $table->id(); - $table->text('title'); + $table->text('content_theme'); $table->date('posted_date'); $table->enum('channel', ['website', 'tiktok', 'youtube', 'instagram', 'facebook', 'twitter', 'cetak']); $table->string('link'); diff --git a/database/seeders/ContentRecapSeeder.php b/database/seeders/ContentRecapSeeder.php index 4408f42..a764bf6 100644 --- a/database/seeders/ContentRecapSeeder.php +++ b/database/seeders/ContentRecapSeeder.php @@ -19,7 +19,7 @@ public function run(): void foreach($legacyContentRecaps as $legacyContentRecap){ ContentRecap::create([ 'id' => $legacyContentRecap->id, - 'title' => $legacyContentRecap->title, + 'content_theme' => $legacyContentRecap->title, 'posted_date' => $legacyContentRecap->posting_date == '0000-00-00' ? now() : $legacyContentRecap->posting_date, 'channel' => $legacyContentRecap->channel, 'link' => $legacyContentRecap->link, diff --git a/public/assets/dashboard/css/custom.css b/public/assets/dashboard/css/custom.css index cb21b1c..1784adf 100644 --- a/public/assets/dashboard/css/custom.css +++ b/public/assets/dashboard/css/custom.css @@ -167,3 +167,7 @@ .file-not-filled{ border: 1px solid red !important; background-color: red !important; } + +.link-show{ + width: 68% !important; +} diff --git a/resources/views/dashboard/content-recaps/classifications/create.blade.php b/resources/views/dashboard/content-recaps/classifications/create.blade.php index 455df00..32e3c4a 100644 --- a/resources/views/dashboard/content-recaps/classifications/create.blade.php +++ b/resources/views/dashboard/content-recaps/classifications/create.blade.php @@ -21,7 +21,10 @@
-
{{$title}}
+
+
Buat Klasifikasi Rekap Konten Baru
+

Masukkan informasi yang diperlukan untuk membuat klasifikasi rekap konten.

+
@csrf @@ -30,7 +33,7 @@
- +
@error('name') {{$message}} @@ -41,7 +44,7 @@
- +
@error('year') {{$message}} @@ -55,6 +58,9 @@
+ @error('description') + {{$message}} + @enderror

diff --git a/resources/views/dashboard/content-recaps/classifications/edit.blade.php b/resources/views/dashboard/content-recaps/classifications/edit.blade.php index 287a0c5..a4eed5a 100644 --- a/resources/views/dashboard/content-recaps/classifications/edit.blade.php +++ b/resources/views/dashboard/content-recaps/classifications/edit.blade.php @@ -10,7 +10,10 @@
-
{{$title}}
+
+
Ubah Klasifikasi Rekap Konten
+

Perbarui informasi klasifikasi rekap konten ini.

+
@csrf @@ -20,7 +23,7 @@
- +
@error('name') {{$message}} @@ -31,7 +34,7 @@
- +
@error('year') {{$message}} @@ -45,6 +48,9 @@
+ @error('description') + {{$message}} + @enderror

diff --git a/resources/views/dashboard/content-recaps/classifications/show.blade.php b/resources/views/dashboard/content-recaps/classifications/show.blade.php index f396490..d79109d 100644 --- a/resources/views/dashboard/content-recaps/classifications/show.blade.php +++ b/resources/views/dashboard/content-recaps/classifications/show.blade.php @@ -6,13 +6,32 @@
+
+
+
+

Detail Klasifikasi Rekap Konten

+
+
    +
  • Detail klasifikasi rekap konten dapat dilihat di sini.
  • +
+
+
+
+ + Kembali +
+
+
@@ -28,6 +47,12 @@ {{$contentRecapClassification->name}}
+
+
+ Tahun + {{$contentRecapClassification->year}} +
+
Rekap Konten @@ -46,6 +71,12 @@ {{idn_date($contentRecapClassification->created_at, 'l, d F Y')}}
+
+
+ Dibuat Oleh + {{$contentRecapClassification->enhancer->name}} +
+
{{--
--}} @@ -56,16 +87,11 @@
- {!! filled($contentRecapClassification->description) ? $contentRecapClassification->description : '-' !!} + {!!$contentRecapClassification->description ?? '-' !!}
-
-
- Kembali - Ubah -
diff --git a/resources/views/dashboard/content-recaps/create.blade.php b/resources/views/dashboard/content-recaps/create.blade.php index bbae5e6..73af02f 100644 --- a/resources/views/dashboard/content-recaps/create.blade.php +++ b/resources/views/dashboard/content-recaps/create.blade.php @@ -10,18 +10,21 @@
-
{{$title}}
+
+
Buat Rekap Konten Baru
+

Masukkan informasi yang diperlukan untuk membuat rekap konten.

+
@csrf
- +
- +
- @error('title') + @error('content_theme') {{$message}} @enderror
@@ -30,7 +33,7 @@
- +
@error('link') @@ -43,11 +46,15 @@
+ @error('classification_id') + {{$message}} + @enderror
@@ -55,18 +62,22 @@
+ @error('social_media') + {{$message}} + @enderror
- +
@error('posted_date') {{$message}} @@ -78,6 +89,7 @@
+ @error('channel') + {{$message}} + @enderror
- +
- +
@error('image') @@ -103,6 +118,17 @@ @enderror
+
+
+ + @error('description') + {{$message}} + @enderror +
+ +
+
+

diff --git a/resources/views/dashboard/content-recaps/edit.blade.php b/resources/views/dashboard/content-recaps/edit.blade.php index 08e6cbd..ab9da00 100644 --- a/resources/views/dashboard/content-recaps/edit.blade.php +++ b/resources/views/dashboard/content-recaps/edit.blade.php @@ -10,22 +10,22 @@
-
{{$title}}
+
+
Ubah Rekap Konten
+

Perbarui informasi rekap konten ini.

+
- @foreach ($errors->all() as $item) - {{$item}} - @endforeach @csrf @method('put')
- +
- +
- @error('title') + @error('content_theme') {{$message}} @enderror
@@ -34,7 +34,7 @@
- +
@error('link') {{$message}} @@ -94,11 +94,21 @@
- +
- +
@error('image') @@ -106,15 +116,45 @@ @enderror
+
+
+ + @error('description') + {{$message}} + @enderror +
+ +
+
+

+ @if (request()->query('show')) + Kembali + @else Kembali + @endif
+
diff --git a/resources/views/dashboard/content-recaps/index.blade.php b/resources/views/dashboard/content-recaps/index.blade.php index 8f33453..f63973d 100644 --- a/resources/views/dashboard/content-recaps/index.blade.php +++ b/resources/views/dashboard/content-recaps/index.blade.php @@ -43,7 +43,7 @@ No - Judul + Tema Konten Kanal Social Media Tanggal Posting diff --git a/resources/views/dashboard/content-recaps/show.blade.php b/resources/views/dashboard/content-recaps/show.blade.php index 95cc6b3..eee52cd 100644 --- a/resources/views/dashboard/content-recaps/show.blade.php +++ b/resources/views/dashboard/content-recaps/show.blade.php @@ -6,68 +6,131 @@
-
-
-
-
-
{{$title}}
+
+
+
+

Detail Rekap Konten

+
+
    +
  • Detail rekap konten dapat dilihat di sini.
  • +
- @foreach ($errors->all() as $item) - {{$item}} - @endforeach -
- @csrf -
-
-
- -
- -
-
-
-
-
- -
- -
-
-
-
-
- -
- -
-
-
-
-
- -
- -
-
-
-
-
- -
- -
-
-
-
-
-
- Kembali - Ubah -
-
-
-
+
+ Kembali + +
+
+
+
+
+
+
+ +
+
+ {{--
+
Personal Information
+

Basic info, like your name and address, that you use on Nio Platform.

+
--}} +
+
+
+ Tema Konten + {{$contentRecap->content_theme}} +
+
+
+
+ Kanal + {{ucfirst($contentRecap->channel)}} +
+
+
+
+ Media Sosial + {{ucfirst($contentRecap->social_media)}} +
+
+
+
+ Tanggal Posting + {{idn_date($contentRecap->posted_date, 'l, d F Y')}} +
+
+
+
+ Klasifikasi + {{$contentRecap->classification->name}} +
+
+
+
+ Link + + @if (filled($contentRecap->link)) + {{$contentRecap->link}} + @else + {{'-'}} + @endif + +
+
+
+
+ Dibuat Pada + {{idn_date($contentRecap->created_at, 'l, d F Y')}} +
+
+
+
+ Oleh + {{$contentRecap->enhancer->name}} +
+
+
+
+ {{--
--}} +
+ {{--
+
Admin Note
+
--}} +
+
+ +
+
+ {!! display_file('news', $contentRecap->image) !!} +
+
+
+
+
+
+
+ Deskripsi +
+
+
+
+ {!! $contentRecap->description ?? 'Tidak ada' !!} +
+
+
+
+
+
+
@@ -75,4 +138,4 @@
-@include('partials.dashboard.footer', ['rich_editor' => true]) +@include('partials.dashboard.footer', ['rich_editor' => false]) diff --git a/resources/views/partials/app/datatable.blade.php b/resources/views/partials/app/datatable.blade.php index 2429237..8a228e1 100644 --- a/resources/views/partials/app/datatable.blade.php +++ b/resources/views/partials/app/datatable.blade.php @@ -339,6 +339,23 @@ { data: 'created_at', name: 'created_at', visible: false }, { data: 'id', name: 'id', orderable: true, searchable: false, visible: false }, ], + columnDefs: [ + { targets: 0, width: '2%' }, // Index + { targets: 1, width: '20%' }, // Name + { targets: 2, width: '5%' }, // Content Recaps + { targets: 3, width: '7%' }, // Created Date + { targets: 4, width: '2%', className: 'text-center' }, // Action button + + { + targets: [1, 2], // Title & Link + createdCell: function(td) { + $(td).css({ + 'white-space': 'normal', + 'word-break': 'break-word', + }); + } + } + ], language: datatableLanguage, // responsive: true, autoWidth: false, @@ -962,10 +979,16 @@ $('#contentRecapsTable').DataTable({ processing: true, serverSide: true, - ajax: '{{ route('dashboard.content.recaps.data') }}', + ajax: { + url: '{{ route('dashboard.content.recaps.data') }}', + type: 'GET', + data: function(d) { + d.classification = '{{ $classification }}'; + } + }, columns: [ { data: 'DT_RowIndex', name: 'DT_RowIndex', orderable: false, searchable: false }, - { data: 'title', name: 'title' }, + { data: 'content_theme', name: 'content_theme' }, { data: 'channel', name: 'channel' }, { data: 'social_media', name: 'social_media' }, { data: 'posted_date', name: 'posted_date' },