Skip to content
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
4 changes: 3 additions & 1 deletion app/Http/Controllers/Master/ArtikelKabupatenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ public function index(Request $request): View
*/
public function create(): View
{
return view('master.artikel.create');
$listPermission = $this->generateListPermission();

return view('master.artikel.create')->with($listPermission);
}

/**
Expand Down
1 change: 1 addition & 0 deletions catatan_rilis.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Di rilis ini, versi 2604.0.1 berisi penambahan dan perbaikan yang diminta penggu

#### Perbaikan BUG
1. [#1023](https://github.com/OpenSID/OpenKab/issues/1023) Percobaan login gagal terkadang error 500
2. [#1025](https://github.com/OpenSID/OpenKab/issues/1025) Arahkan/Infokan pembuatan kategori artikel ketika kategori kosong saat membuat artikel opensid

#### Perubahan Teknis

Expand Down
71 changes: 67 additions & 4 deletions resources/views/master/artikel/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ class="btn col-12 btn-primary m-0 rounded-pill">
<select class="form-control select2" id="id_kategori" name="id_kategori" required>
<option value="">-- Pilih Kategori --</option>
</select>
<small id="empty-kategori-hint" class="form-text text-danger d-none">
Kategori artikel belum tersedia.
@if (($canwrite ?? 0) == 1)
<a href="{{ url('master/kategori/tambah/0') }}">Buat kategori artikel sekarang</a>.
@else
Silakan hubungi admin untuk menambahkan kategori.
@endif
</small>
</div>

<!-- Tanggal Upload -->
Expand Down Expand Up @@ -119,6 +127,8 @@ class="btn col-12 btn-primary m-0 rounded-pill">
@include('partials.asset_tinymce')
<script nonce="{{ csp_nonce() }}">
const header = @include('layouts.components.header_bearer_api_gabungan');
const canCreateKategori = {{ (($canwrite ?? 0) == 1) ? 'true' : 'false' }};
const kategoriCreateUrl = "{{ url('master/kategori/tambah/0') }}";

function artikel() {
return {
Expand All @@ -135,6 +145,8 @@ function artikel() {
fileData: {
gambar: null
},
hasKategori: true,
hasShownKategoriKosongPopup: false,

init() {
this.loadKategori();
Expand Down Expand Up @@ -162,7 +174,7 @@ function artikel() {
formData.append('file', file);

try {
const response = await fetch('{{ route('artikel.upload_gambar') }}', {
const response = await fetch("{{ route('artikel.upload_gambar') }}", {
method: 'POST',
headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}'
Expand Down Expand Up @@ -202,15 +214,29 @@ function artikel() {
},
success: function(response) {
const select = $('#id_kategori');
const hint = $('#empty-kategori-hint');
select.empty();
select.append('<option value="">-- Pilih Kategori --</option>');

if (response.data) {
response.data.forEach(function(item) {
const kategoriItems = Array.isArray(response.data) ? response.data : [];

if (kategoriItems.length > 0) {
self.hasKategori = true;
self.hasShownKategoriKosongPopup = false;
hint.addClass('d-none');
select.prop('disabled', false);

kategoriItems.forEach(function(item) {
select.append(
`<option value="${item.id}">${item.attributes.kategori}</option>`
);
});
} else {
self.hasKategori = false;
self.dataArtikel.id_kategori = '';
hint.removeClass('d-none');
select.prop('disabled', true);
self.showKategoriKosongInfo();
}

select.select2({
Expand All @@ -230,6 +256,37 @@ function artikel() {
});
},

showKategoriKosongInfo() {
if (this.hasShownKategoriKosongPopup) {
return;
}

this.hasShownKategoriKosongPopup = true;

if (canCreateKategori) {
Swal.fire({
icon: 'info',
title: 'Kategori Belum Tersedia',
text: 'Kategori artikel wajib diisi. Buat kategori artikel terlebih dahulu sebelum menambahkan artikel.',
showCancelButton: true,
confirmButtonText: 'Buat Kategori',
cancelButtonText: 'Nanti Saja'
}).then((result) => {
if (result.isConfirmed) {
window.location.href = kategoriCreateUrl;
}
});

return;
}

Swal.fire({
icon: 'info',
title: 'Kategori Belum Tersedia',
text: 'Kategori artikel wajib diisi. Silakan hubungi admin untuk menambahkan kategori artikel terlebih dahulu.'
});
},

async simpan() {
// Get content from TinyMCE
let isi = '';
Expand All @@ -253,6 +310,12 @@ function artikel() {
return;
}
if (!this.dataArtikel.id_kategori) {
if (!this.hasKategori) {
Swal.fire('Info', 'Kategori artikel belum tersedia. Buat kategori terlebih dahulu sebelum menyimpan artikel.',
'info');
return;
}

Swal.fire('Error!', 'Kategori harus dipilih', 'error');
return;
}
Expand Down Expand Up @@ -302,7 +365,7 @@ function artikel() {
});
setTimeout(() => {
window.location.href =
'{{ route('master-data-artikel.index') }}?clear_all_cache=1';
"{{ route('master-data-artikel.index') }}?clear_all_cache=1";
}, 1500);
} else {
Swal.fire({
Expand Down
12 changes: 12 additions & 0 deletions tests/Feature/ArtikelControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,24 @@ public function it_can_access_artikel_create()
$response = $this->get(route('master-data-artikel.create'));
$response->assertStatus(200);
$response->assertViewIs('master.artikel.create');
$response->assertViewHas(['canwrite', 'canedit', 'candelete']);
$response->assertSee('Tambah Artikel');
$response->assertSee('Judul Artikel');
$response->assertSee('Isi Artikel');
$response->assertSee('Kategori');
}

/** @test */
public function artikel_create_has_empty_kategori_popup_guard()
{
$response = $this->get(route('master-data-artikel.create'));
$response->assertStatus(200);

$response->assertSee('hasShownKategoriKosongPopup: false', false);
$response->assertSee('if (this.hasShownKategoriKosongPopup)', false);
$response->assertSee('this.hasShownKategoriKosongPopup = true', false);
}

/** @test */
public function it_can_access_artikel_edit()
{
Expand Down