移除已發布狀態,簡化為草稿和已發送兩種狀態
Browse files- app/api/post_routes.py +8 -6
- frontend/js/pages/posts.js +3 -13
app/api/post_routes.py
CHANGED
|
@@ -106,8 +106,12 @@ async def get_posts(
|
|
| 106 |
if product_type and product_type in ['revit', 'autocad', 'announcement']:
|
| 107 |
query = query.eq('product_type', product_type)
|
| 108 |
|
| 109 |
-
if status and status in ['draft', '
|
| 110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
result = query.order('created_at', desc=True).limit(limit).execute()
|
| 113 |
|
|
@@ -456,9 +460,8 @@ async def get_post_stats(current_user = Depends(verify_admin)):
|
|
| 456 |
result = client.table('posts').select('*').eq('is_deleted', False).execute()
|
| 457 |
posts = result.data
|
| 458 |
|
| 459 |
-
# 統計各狀態數量
|
| 460 |
-
draft_count = len([p for p in posts if p['status']
|
| 461 |
-
published_count = len([p for p in posts if p['status'] == 'published'])
|
| 462 |
sent_count = len([p for p in posts if p['status'] == 'sent'])
|
| 463 |
|
| 464 |
# 統計各產品類型
|
|
@@ -472,7 +475,6 @@ async def get_post_stats(current_user = Depends(verify_admin)):
|
|
| 472 |
"total_posts": len(posts),
|
| 473 |
"by_status": {
|
| 474 |
"draft": draft_count,
|
| 475 |
-
"published": published_count,
|
| 476 |
"sent": sent_count
|
| 477 |
},
|
| 478 |
"by_product": {
|
|
|
|
| 106 |
if product_type and product_type in ['revit', 'autocad', 'announcement']:
|
| 107 |
query = query.eq('product_type', product_type)
|
| 108 |
|
| 109 |
+
if status and status in ['draft', 'sent']:
|
| 110 |
+
if status == 'draft':
|
| 111 |
+
# 草稿包含 draft 和舊的 published 狀態
|
| 112 |
+
query = query.in_('status', ['draft', 'published'])
|
| 113 |
+
else:
|
| 114 |
+
query = query.eq('status', status)
|
| 115 |
|
| 116 |
result = query.order('created_at', desc=True).limit(limit).execute()
|
| 117 |
|
|
|
|
| 460 |
result = client.table('posts').select('*').eq('is_deleted', False).execute()
|
| 461 |
posts = result.data
|
| 462 |
|
| 463 |
+
# 統計各狀態數量(published 視為 draft)
|
| 464 |
+
draft_count = len([p for p in posts if p['status'] in ['draft', 'published']])
|
|
|
|
| 465 |
sent_count = len([p for p in posts if p['status'] == 'sent'])
|
| 466 |
|
| 467 |
# 統計各產品類型
|
|
|
|
| 475 |
"total_posts": len(posts),
|
| 476 |
"by_status": {
|
| 477 |
"draft": draft_count,
|
|
|
|
| 478 |
"sent": sent_count
|
| 479 |
},
|
| 480 |
"by_product": {
|
frontend/js/pages/posts.js
CHANGED
|
@@ -54,7 +54,6 @@ class PostsPage {
|
|
| 54 |
<div class="filter-buttons" id="statusFilter">
|
| 55 |
<button type="button" class="filter-btn active" data-value="all">全部</button>
|
| 56 |
<button type="button" class="filter-btn" data-value="draft">草稿</button>
|
| 57 |
-
<button type="button" class="filter-btn" data-value="published">已發布</button>
|
| 58 |
<button type="button" class="filter-btn" data-value="sent">已發送</button>
|
| 59 |
</div>
|
| 60 |
</div>
|
|
@@ -78,18 +77,11 @@ class PostsPage {
|
|
| 78 |
<span class="stat-label">草稿</span>
|
| 79 |
</div>
|
| 80 |
</div>
|
| 81 |
-
<div class="stat-card">
|
| 82 |
-
<div class="stat-icon published"><i class="fas fa-check"></i></div>
|
| 83 |
-
<div class="stat-info">
|
| 84 |
-
<span class="stat-value" id="statPublished">-</span>
|
| 85 |
-
<span class="stat-label">已發布</span>
|
| 86 |
-
</div>
|
| 87 |
-
</div>
|
| 88 |
<div class="stat-card">
|
| 89 |
<div class="stat-icon sent"><i class="fas fa-envelope"></i></div>
|
| 90 |
<div class="stat-info">
|
| 91 |
<span class="stat-value" id="statSent">-</span>
|
| 92 |
-
<span class="stat-label">已發送
|
| 93 |
</div>
|
| 94 |
</div>
|
| 95 |
</div>
|
|
@@ -258,13 +250,11 @@ class PostsPage {
|
|
| 258 |
|
| 259 |
updateStats() {
|
| 260 |
const total = this.posts.length;
|
| 261 |
-
const draft = this.posts.filter(p => p.status === 'draft').length;
|
| 262 |
-
const published = this.posts.filter(p => p.status === 'published').length;
|
| 263 |
const sent = this.posts.filter(p => p.status === 'sent').length;
|
| 264 |
|
| 265 |
document.getElementById('statTotal').textContent = total;
|
| 266 |
document.getElementById('statDraft').textContent = draft;
|
| 267 |
-
document.getElementById('statPublished').textContent = published;
|
| 268 |
document.getElementById('statSent').textContent = sent;
|
| 269 |
}
|
| 270 |
|
|
@@ -393,7 +383,7 @@ class PostsPage {
|
|
| 393 |
getStatusBadge(status) {
|
| 394 |
const badges = {
|
| 395 |
draft: '<span class="status-badge draft"><i class="fas fa-edit"></i> 草稿</span>',
|
| 396 |
-
published: '<span class="status-badge
|
| 397 |
sent: '<span class="status-badge sent"><i class="fas fa-envelope"></i> 已發送</span>'
|
| 398 |
};
|
| 399 |
return badges[status] || '';
|
|
|
|
| 54 |
<div class="filter-buttons" id="statusFilter">
|
| 55 |
<button type="button" class="filter-btn active" data-value="all">全部</button>
|
| 56 |
<button type="button" class="filter-btn" data-value="draft">草稿</button>
|
|
|
|
| 57 |
<button type="button" class="filter-btn" data-value="sent">已發送</button>
|
| 58 |
</div>
|
| 59 |
</div>
|
|
|
|
| 77 |
<span class="stat-label">草稿</span>
|
| 78 |
</div>
|
| 79 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
<div class="stat-card">
|
| 81 |
<div class="stat-icon sent"><i class="fas fa-envelope"></i></div>
|
| 82 |
<div class="stat-info">
|
| 83 |
<span class="stat-value" id="statSent">-</span>
|
| 84 |
+
<span class="stat-label">已發送</span>
|
| 85 |
</div>
|
| 86 |
</div>
|
| 87 |
</div>
|
|
|
|
| 250 |
|
| 251 |
updateStats() {
|
| 252 |
const total = this.posts.length;
|
| 253 |
+
const draft = this.posts.filter(p => p.status === 'draft' || p.status === 'published').length;
|
|
|
|
| 254 |
const sent = this.posts.filter(p => p.status === 'sent').length;
|
| 255 |
|
| 256 |
document.getElementById('statTotal').textContent = total;
|
| 257 |
document.getElementById('statDraft').textContent = draft;
|
|
|
|
| 258 |
document.getElementById('statSent').textContent = sent;
|
| 259 |
}
|
| 260 |
|
|
|
|
| 383 |
getStatusBadge(status) {
|
| 384 |
const badges = {
|
| 385 |
draft: '<span class="status-badge draft"><i class="fas fa-edit"></i> 草稿</span>',
|
| 386 |
+
published: '<span class="status-badge draft"><i class="fas fa-edit"></i> 草稿</span>',
|
| 387 |
sent: '<span class="status-badge sent"><i class="fas fa-envelope"></i> 已發送</span>'
|
| 388 |
};
|
| 389 |
return badges[status] || '';
|