Skip to content
This repository was archived by the owner on Apr 21, 2026. It is now read-only.

Commit c446a93

Browse files
authored
Merge pull request #42 from paiindustries/blogs_fixes
blog approval fixes in admin panel
2 parents 3bc8bb9 + 7284bb5 commit c446a93

10 files changed

Lines changed: 355 additions & 110 deletions

File tree

app/config/routes.cfm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
.get(name = "admin-index", pattern = "admin", to = "web.AdminController##index")
3434
.get(name = "admin-blog", pattern = "admin/blog", to = "web.AdminController##blog")
3535
.get(name = "admin-show-blog", pattern = "admin/blog/[slug]", to = "web.AdminController##showBlog")
36-
.get(name = "BlogList", pattern = "admin/blog/list", to = "web.AdminController##BlogList")
36+
.get(name = "blog-List", pattern = "admin/blog/list", to = "web.AdminController##blogList")
3737
.post(name = "admin-approve", pattern = "admin/approve", to = "web.AdminController##approve")
3838
.post(name = "admin-reject", pattern = "admin/reject", to = "web.AdminController##reject")
3939

app/controllers/web/AdminController.cfc

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
component extends="app.Controllers.Controller" {
33

44
function config() {
5-
verifies(except="index,dashboard,checkAdminAccess,blog,BlogList,approve,reject,showBlog", params="key", paramsTypes="integer", handler="dashboard");
5+
verifies(except="index,dashboard,checkAdminAccess,blog,blogList,approve,reject,showBlog", params="key", paramsTypes="integer", handler="dashboard");
66

7-
usesLayout(template="/web/AdminController/layout", except="BlogList");
7+
usesLayout(template="/web/AdminController/layout");
88
filters(through="checkAdminAccess");
99
}
1010

@@ -13,30 +13,25 @@ component extends="app.Controllers.Controller" {
1313
}
1414

1515
function blog() {
16-
}
17-
18-
function BlogList() {
19-
// Fetch all blogs
2016
blogs = getAllBlogs();
21-
renderPartial(partial="partials/blogs");
2217
}
2318

2419
function approve() {
2520
try {
26-
var message = Approve(params.id);
27-
redirectTo(action="blog", success="#message#");
21+
var message = blogApproval(params.id);
22+
header name="HX-Redirect" value="#urlFor(route='admin-blog')#";
2823
} catch (any e) {
2924
// Handle error
30-
redirectTo(action="blog", errorMessage="Failed to delete user.");
25+
renderText("Failed to approve blog.");
3126
}
3227
}
3328
function reject() {
3429
try {
35-
var message = Reject(params.id);
36-
redirectTo(action="blog", success="#message#");
30+
var message = blogReject(params.id);
31+
header name="HX-Redirect" value="#urlFor(route='admin-blog')#";
3732
} catch (any e) {
3833
// Handle error
39-
redirectTo(action="blog", errorMessage="Failed to delete user.");
34+
renderText("Failed to reject blog.");
4035
}
4136
}
4237

@@ -224,8 +219,8 @@ component extends="app.Controllers.Controller" {
224219

225220
}
226221

227-
private function Approve(id){
228-
var blog = model("Blog").findByKey(arguments.id);
222+
private function blogApproval(id){
223+
var blog = model("Blog").findByKey(id);
229224

230225
if (!isNull(blog)) {
231226

@@ -250,8 +245,8 @@ component extends="app.Controllers.Controller" {
250245
};
251246
}
252247

253-
private function Reject(id){
254-
var blog = model("Blog").findByKey(arguments.id);
248+
private function blogReject(id){
249+
var blog = model("Blog").findByKey(id);
255250

256251
if (!isNull(blog)) {
257252

app/controllers/web/BlogController.cfc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ component extends="app.Controllers.Controller" {
134134
if(structKeyExists(form, "title")){
135135
var blogModel = model("Blog").findAll(where="title='#form.title#'");
136136
if(blogModel.recordCount != 0){
137-
renderText('<p class="text-danger">Blog title already exist!</p>');
137+
renderText('<span class="text-danger">A blog already exist with this title!</span><input type="hidden" id="titleExists" value="1">');
138138
}else{
139-
renderText("");
139+
renderText('<input type="hidden" id="titleExists" value="0">');
140140
}
141141
}
142142
}catch (any e) {
Lines changed: 78 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,82 @@
11
<main>
2-
<div class="container py-5">
3-
<div class="row justify-content-center justify-content-lg-between">
4-
<div class="bg-white rounded-5 shadow-sm mt-4 p-4">
5-
<h1 class="text-center fs-24 fw-bold">Blogs List</h1>
6-
<table class="table table-hover">
7-
<thead>
8-
<tr>
9-
<th>ID</th>
10-
<th>Title</th>
11-
<th>Slug</th>
12-
<th>Category</th>
13-
<th>Status</th>
14-
<th>Post Type</th>
15-
<th>Created By</th>
16-
<th>Content</th>
17-
<th>Status</th>
18-
<th>Actions</th>
19-
</tr>
20-
</thead>
21-
<tbody id="blogs-container" hx-get="/admin/blog/list" hx-trigger="load" hx-target="#blogs-container" hx-swap="innerHTML">
22-
<!--- Load Blog List thorugh partial view --->
23-
</tbody>
24-
</table>
2+
<cfoutput>
3+
<div class="container py-5">
4+
<div class="row justify-content-center justify-content-lg-between">
5+
<div class="bg-white rounded-5 shadow-sm mt-4 p-4 overflow-x-auto">
6+
<h1 class="text-center fs-24 mb-5 fw-bold">Blogs</h1>
7+
<table id="blogTable" class="table table-hover">
8+
<thead>
9+
<tr>
10+
<th>ID</th>
11+
<th>Title</th>
12+
<th>Status</th>
13+
<th>Post Type</th>
14+
<th>Created By</th>
15+
<th>Approval Status</th>
16+
<th></th>
17+
</tr>
18+
</thead>
19+
<tbody>
20+
<cfloop from="1" to="#blogs.recordCount#" index="i">
21+
<cfset blogId = blogs.id[i]>
22+
<cfset truncatedContent = left(blogs.content[i], 100) & "...">
23+
24+
<tr id="blog-#blogId#">
25+
<td>#i#</td>
26+
<td><a href="blog/#blogs.slug[i]#" class="cursor-pointer text-primary">#blogs.title[i]#</a></td>
27+
<td>#blogs.NAME[i]#</td>
28+
<td>#blogs.POSTTYPENAME[i]#</td>
29+
<td>#blogs.fullName[i]#</td>
30+
<td>
31+
<cfif blogs.status[i] eq 'Approved'>
32+
<span class="badge bg-success">Approved</span>
33+
<cfelseif blogs.status[i] eq 'Rejected'>
34+
<span class="badge bg-danger">Rejected</span>
35+
<cfelse>
36+
<span class="badge bg-warning text-dark">Pending</span>
37+
</cfif>
38+
</td>
39+
<td>
40+
<div class="dropdown">
41+
<div class="fw-bold cursor-pointer" data-bs-toggle="dropdown" aria-expanded="false">
42+
...
43+
</div>
44+
<ul class="dropdown-menu">
45+
<li>
46+
<button
47+
class="dropdown-item text-success"
48+
hx-post="approve"
49+
hx-vals='{"id": "#blogId#"}'
50+
hx-confirm="Are you sure you want to approve this blog?"
51+
>Approve</button>
52+
</li>
53+
<li>
54+
<button
55+
class="dropdown-item text-danger"
56+
hx-post="reject"
57+
hx-vals='{"id": "#blogId#"}'
58+
hx-confirm="Are you sure you want to reject this blog?"
59+
>Reject</button>
60+
</li>
61+
</ul>
62+
</div>
63+
</td>
64+
</tr>
65+
</cfloop>
66+
</tbody>
67+
</table>
68+
</div>
2569
</div>
2670
</div>
27-
</div>
71+
</cfoutput>
72+
<script>
73+
let table = new DataTable('#blogTable', {
74+
columnDefs: [
75+
{
76+
targets: [5,6], // Adjust these indexes based on your actual table structure
77+
orderable: false
78+
}
79+
]
80+
});
81+
</script>
2882
</main>

0 commit comments

Comments
 (0)