Skip to content

Commit 64f636d

Browse files
committed
fitur pencarian di halaman admin
1 parent 440dfb4 commit 64f636d

File tree

3 files changed

+41
-29
lines changed

3 files changed

+41
-29
lines changed

application/controllers/admin/Post.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,16 @@ public function __construct()
1515
public function index()
1616
{
1717
$data['current_user'] = $this->auth_model->current_user();
18+
1819
$data['articles'] = $this->article_model->get();
19-
if(count($data['articles']) <= 0){
20+
21+
$data['keyword'] = $this->input->get('keyword');
22+
23+
if(!empty($this->input->get('keyword'))){
24+
$data['articles'] = $this->article_model->search($data['keyword']);
25+
}
26+
27+
if(count($data['articles']) <= 0 && !$this->input->get('keyword')){
2028
$this->load->view('admin/post_empty.php', $data);
2129
} else {
2230
$this->load->view('admin/post_list.php', $data);

application/views/admin/post_list.php

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414

1515
<div class="toolbar">
1616
<a href="<?= site_url('admin/post/new') ?>" class="button button-primary" role="button">+ Tulis Artikel</a>
17+
<div>
18+
<form action="" method="GET" style="flex-direction: row; width:360px">
19+
<input type="search" name="keyword" placeholder="Cari artikel" value="<?= html_escape($keyword) ?>">
20+
<input type="submit" value="Cari" class="button" style="width: 32%;">
21+
</form>
22+
</div>
1723
</div>
1824

1925
<table class="table">
@@ -25,32 +31,28 @@
2531
</tr>
2632
</thead>
2733
<tbody>
28-
29-
<?php foreach($articles as $article): ?>
30-
<tr>
31-
<td>
32-
<div><?= $article->title ?></div>
33-
<div class="text-gray"><small><?= $article->created_at ?><small></div>
34-
</td>
35-
<?php if($article->draft === 'true'): ?>
36-
<td class="text-center text-gray">Draft</td>
37-
<?php else: ?>
38-
<td class="text-center text-green">Published</td>
39-
<?php endif ?>
40-
<td>
41-
<div class="action">
42-
<a href="<?= site_url('article/'.$article->slug) ?>" class="button button-small" target="_blank" role="button">Preview</a>
43-
<a href="<?= site_url('admin/post/edit/'.$article->id) ?>" class="button button-small" role="button">Edit</a>
44-
<a href="#"
45-
data-delete-url="<?= site_url('admin/post/delete/'.$article->id) ?>"
46-
class="button button-small button-danger"
47-
role="button"
48-
onclick="deleteConfirm(this)">Delete</a>
49-
</div>
50-
</td>
51-
</tr>
34+
35+
<?php foreach ($articles as $article) : ?>
36+
<tr>
37+
<td>
38+
<div><?= $article->title ?></div>
39+
<div class="text-gray"><small><?= $article->created_at ?><small></div>
40+
</td>
41+
<?php if ($article->draft === 'true') : ?>
42+
<td class="text-center text-gray">Draft</td>
43+
<?php else : ?>
44+
<td class="text-center text-green">Published</td>
45+
<?php endif ?>
46+
<td>
47+
<div class="action">
48+
<a href="<?= site_url('article/' . $article->slug) ?>" class="button button-small" target="_blank" role="button">Preview</a>
49+
<a href="<?= site_url('admin/post/edit/' . $article->id) ?>" class="button button-small" role="button">Edit</a>
50+
<a href="#" data-delete-url="<?= site_url('admin/post/delete/' . $article->id) ?>" class="button button-small button-danger" role="button" onclick="deleteConfirm(this)">Delete</a>
51+
</div>
52+
</td>
53+
</tr>
5254
<?php endforeach ?>
53-
55+
5456
</tbody>
5557
</table>
5658

@@ -60,7 +62,7 @@ class="button button-small button-danger"
6062

6163
<script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script>
6264
<script>
63-
function deleteConfirm(event){
65+
function deleteConfirm(event) {
6466
Swal.fire({
6567
title: 'Delete Confirmation!',
6668
text: 'Are you sure to delete the item?',
@@ -70,14 +72,14 @@ function deleteConfirm(event){
7072
confirmButtonText: 'Yes Delete',
7173
confirmButtonColor: 'red'
7274
}).then(dialog => {
73-
if(dialog.isConfirmed){
75+
if (dialog.isConfirmed) {
7476
window.location.assign(event.dataset.deleteUrl);
7577
}
7678
});
7779
}
7880
</script>
7981

80-
<?php if($this->session->flashdata('message')): ?>
82+
<?php if ($this->session->flashdata('message')) : ?>
8183
<script>
8284
const Toast = Swal.mixin({
8385
toast: true,

public/assets/css/admin.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ body {
4545
.toolbar {
4646
display: flex;
4747
margin: 1rem 0;
48+
justify-content: space-between;
49+
align-items: center;
4850
}
4951

5052
.table {

0 commit comments

Comments
 (0)