diff --git a/Design/adminPage_ideas.md b/Design/adminPage_ideas.md index 1ed1df10..38b56a62 100644 --- a/Design/adminPage_ideas.md +++ b/Design/adminPage_ideas.md @@ -14,7 +14,6 @@ Tags Tạo và quản lý các Thẻ (nhãn từ khóa tìm kiếm nhanh). Add New Tải tệp tin mới lên máy chủ. (Done) 4. Pages (Trang) All Pages Quản lý các trang tĩnh (ví dụ: Trang chủ, Trang liên hệ, Giới thiệu bệnh viện, Giờ làm việc...). Add New Tạo trang tĩnh mới. -5. Comments (Bình luận) (Không có) Quản lý bình luận của người đọc (Phê duyệt, Trả lời, Đánh dấu Spam, Xóa tạm/Xóa vĩnh viễn). 6. Appearance (Giao diện) Themes Cài đặt, kích hoạt hoặc xóa các giao diện hiển thị của website. Customize Chỉnh sửa giao diện trực quan theo thời gian thực (Header, Footer, Colors, Font, v.v.). Widgets Quản lý các khối nội dung ở Sidebar hoặc Footer. @@ -30,7 +29,7 @@ Profile Chỉnh sửa thông tin cá nhân của tài khoản đang đăng nhậ Import / Export Nhập/Xuất toàn bộ bài viết, trang, media sang file .xml để sao lưu hoặc chuyển host. Site Health Kiểm tra sức khỏe hệ thống (phiên bản PHP, MySQL, các lỗi bảo mật). Export / Erase Personal Data Xuất hoặc xóa dữ liệu cá nhân của người dùng để tuân thủ luật bảo mật (GDPR). -10. Settings (Cài đặt) General Thiết lập tên website, câu khẩu hiệu, địa chỉ email admin, múi giờ, định dạng ngày tháng. +(done) 10. Settings (Cài đặt) General Thiết lập tên website, câu khẩu hiệu, địa chỉ email admin, múi giờ, định dạng ngày tháng. Writing Cấu hình mặc định khi soạn thảo văn bản và gửi bài viết qua email. Reading Thiết lập trang chủ hiển thị, số lượng bài viết tối đa trên một trang blog, chặn công cụ tìm kiếm. Discussion Cấu hình bình luận (yêu cầu phê duyệt, chặn từ ngữ nhạy cảm). diff --git a/sisvietnamvn_main/src/main/java/com/sisvietnamvn/web/controller/manage/ManageDashboardController.java b/sisvietnamvn_main/src/main/java/com/sisvietnamvn/web/controller/manage/ManageDashboardController.java index c617ae8a..f1b4d04f 100644 --- a/sisvietnamvn_main/src/main/java/com/sisvietnamvn/web/controller/manage/ManageDashboardController.java +++ b/sisvietnamvn_main/src/main/java/com/sisvietnamvn/web/controller/manage/ManageDashboardController.java @@ -1,11 +1,25 @@ package com.sisvietnamvn.web.controller.manage; +import com.sisvietnamvn.web.domain.Post; +import com.sisvietnamvn.web.domain.PageStatus; +import com.sisvietnamvn.web.repository.PostRepository; +import com.sisvietnamvn.web.repository.PageRepository; +import com.sisvietnamvn.web.service.PostService; import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.security.access.prepost.PreAuthorize; import com.sisvietnamvn.web.security.AuthoritiesConstants; +import java.io.File; +import java.lang.management.ManagementFactory; +import com.sun.management.OperatingSystemMXBean; +import java.util.List; +import java.util.stream.Collectors; + /** * Controller for the admin dashboard index page. * Serves the main "/manage" landing page. @@ -15,8 +29,69 @@ import com.sisvietnamvn.web.security.AuthoritiesConstants; @PreAuthorize("hasAnyAuthority(\"" + AuthoritiesConstants.ADMIN + "\", \"" + AuthoritiesConstants.EDITOR + "\", \"" + AuthoritiesConstants.AUTHOR + "\", \"" + AuthoritiesConstants.CONTRIBUTOR + "\", \"" + AuthoritiesConstants.SUBSCRIBER + "\", \"" + AuthoritiesConstants.USER + "\")") public class ManageDashboardController { + private final PostRepository postRepository; + private final PageRepository pageRepository; + private final PostService postService; + + public ManageDashboardController(PostRepository postRepository, PageRepository pageRepository, PostService postService) { + this.postRepository = postRepository; + this.pageRepository = pageRepository; + this.postService = postService; + } + @GetMapping({"", "/"}) - public String index() { + public String index(Model model) { + // At a Glance stats + long postCount = postRepository.count(); + long pageCount = pageRepository.count(); + model.addAttribute("postCount", postCount); + model.addAttribute("pageCount", pageCount); + + // Recent Activity (Top 5 posts) + List recentPosts = postRepository.findAllByOrderByCreatedDateDesc().stream() + .limit(5) + .collect(Collectors.toList()); + model.addAttribute("recentPosts", recentPosts); + + // Telemetry Stats + Runtime runtime = Runtime.getRuntime(); + long totalRam = runtime.totalMemory(); + long freeRam = runtime.freeMemory(); + long usedRam = totalRam - freeRam; + int ramPercentage = totalRam > 0 ? (int) ((usedRam * 100.0f) / totalRam) : 0; + model.addAttribute("ramPercentage", ramPercentage); + model.addAttribute("usedRamMb", usedRam / (1024 * 1024)); + model.addAttribute("totalRamMb", totalRam / (1024 * 1024)); + + File root = new File("/"); + long totalSpace = root.getTotalSpace(); + long freeSpace = root.getUsableSpace(); + long usedSpace = totalSpace - freeSpace; + int ioPercentage = totalSpace > 0 ? (int) ((usedSpace * 100.0f) / totalSpace) : 0; + model.addAttribute("ioPercentage", ioPercentage); + model.addAttribute("usedSpaceGb", usedSpace / (1024 * 1024 * 1024)); + model.addAttribute("totalSpaceGb", totalSpace / (1024 * 1024 * 1024)); + + try { + OperatingSystemMXBean osBean = ManagementFactory.getPlatformMXBean(OperatingSystemMXBean.class); + double cpuLoad = osBean.getCpuLoad(); // returns 0.0 to 1.0. Returns < 0 if not available. + int cpuPercentage = cpuLoad >= 0 ? (int) (cpuLoad * 100) : 0; + model.addAttribute("cpuPercentage", cpuPercentage); + } catch (Exception e) { + model.addAttribute("cpuPercentage", 0); + } + return "manage/index"; } + + @PostMapping("/quick-draft") + public String quickDraft(@RequestParam("title") String title, @RequestParam("content") String content) { + Post post = new Post(); + post.setTitle(title); + post.setContent(content); + post.setStatus(PageStatus.DRAFT); + + postService.save(post); + return "redirect:/manage"; + } } diff --git a/sisvietnamvn_main/src/main/java/com/sisvietnamvn/web/controller/manage/ManageUpdatesController.java b/sisvietnamvn_main/src/main/java/com/sisvietnamvn/web/controller/manage/ManageUpdatesController.java new file mode 100644 index 00000000..fb017692 --- /dev/null +++ b/sisvietnamvn_main/src/main/java/com/sisvietnamvn/web/controller/manage/ManageUpdatesController.java @@ -0,0 +1,62 @@ +package com.sisvietnamvn.web.controller.manage; + +import com.sisvietnamvn.web.service.SettingService; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.servlet.mvc.support.RedirectAttributes; +import com.sisvietnamvn.web.security.AuthoritiesConstants; + +import java.util.Map; + +/** + * Controller for the admin Updates page. + */ +@Controller +@RequestMapping("/manage/updates") +@PreAuthorize("hasAnyAuthority(\"" + AuthoritiesConstants.ADMIN + "\", \"" + AuthoritiesConstants.EDITOR + "\")") +public class ManageUpdatesController { + + private final SettingService settingService; + private static final String LATEST_VERSION = "4.0.7"; + + public ManageUpdatesController(SettingService settingService) { + this.settingService = settingService; + } + + @GetMapping + public String updates(Model model) { + Map settings = settingService.getAllAsMap(); + String currentVersion = settings.getOrDefault("core_version", "4.0.6"); + + boolean updateAvailable = !LATEST_VERSION.equals(currentVersion); + + model.addAttribute("coreVersionCurrent", currentVersion); + model.addAttribute("coreVersionLatest", LATEST_VERSION); + model.addAttribute("coreUpdateAvailable", updateAvailable); + + // Plugin mock logic + String pluginSeoVersion = settings.getOrDefault("plugin_seo_version", "1.0.0"); + model.addAttribute("pluginSeoVersion", pluginSeoVersion); + model.addAttribute("pluginSeoUpdateAvailable", !"1.1.2".equals(pluginSeoVersion)); + + return "manage/updates"; + } + + @PostMapping("/core") + public String updateCore(RedirectAttributes redirectAttributes) { + settingService.setValue("core_version", LATEST_VERSION); + redirectAttributes.addFlashAttribute("successMessage", "System successfully updated to version " + LATEST_VERSION); + return "redirect:/manage/updates"; + } + + @PostMapping("/plugins") + public String updatePlugins(RedirectAttributes redirectAttributes) { + settingService.setValue("plugin_seo_version", "1.1.2"); + redirectAttributes.addFlashAttribute("successMessage", "Selected plugins successfully updated."); + return "redirect:/manage/updates"; + } +} diff --git a/sisvietnamvn_main/src/main/resources/templates/fragments/manage-layout.html b/sisvietnamvn_main/src/main/resources/templates/fragments/manage-layout.html index 36919757..61a5c0a1 100644 --- a/sisvietnamvn_main/src/main/resources/templates/fragments/manage-layout.html +++ b/sisvietnamvn_main/src/main/resources/templates/fragments/manage-layout.html @@ -40,11 +40,19 @@ - + diff --git a/sisvietnamvn_main/src/main/resources/templates/manage/index.html b/sisvietnamvn_main/src/main/resources/templates/manage/index.html index 80f2b52c..3856162a 100644 --- a/sisvietnamvn_main/src/main/resources/templates/manage/index.html +++ b/sisvietnamvn_main/src/main/resources/templates/manage/index.html @@ -11,145 +11,110 @@

Dashboard

- Generate Report
-
- - -
-
-
-
-
-
- Earnings (Monthly)
-
$40,000
-
-
- -
-
-
-
-
- - -
-
-
-
-
-
- Earnings (Annual)
-
$215,000
-
-
- -
-
-
-
-
- - -
-
-
-
-
-
Tasks -
-
-
-
50%
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
- - -
-
-
-
-
-
- Pending Requests
-
18
-
-
- -
-
-
-
-
-
- - -
- - -
- - + +
-
Projects
+
Site Health & Telemetry
-

Server Migration 20%

+

CPU Load 0%

-
+
-

Sales Tracking 40%

+ +

Memory (RAM) 0 MB / 0 MB

-
+
-

Customer Database 60%

+ +

Disk Space (I/O) 0 GB / 0 GB

-
-
-

Payout Details 80%

-
-
-
-

Account Setup Complete!

-
-
+
+ +
+
+
Quick Draft
+
+
+
+ +
+ +
+
+ +
+ +
+
+
+
+ +
+ +
+
+
At a Glance
+
+
+
+
+ +

0 Posts

+
+
+ +

0 Pages

+
+
+

Running Spring Boot 4.0.6 (Java 21)

+
+
+ + +
+
+
Recent Activity
+
+
+
    +
  • +
    + Date + Post Title +
    + DRAFT +
  • +
  • + No recent activity +
  • +
+
+
+
+ diff --git a/sisvietnamvn_main/src/main/resources/templates/manage/updates.html b/sisvietnamvn_main/src/main/resources/templates/manage/updates.html new file mode 100644 index 00000000..0c445594 --- /dev/null +++ b/sisvietnamvn_main/src/main/resources/templates/manage/updates.html @@ -0,0 +1,109 @@ + + + + + System Updates + + + + +
+ +
+

System Updates

+
+ + + + +
+ +
+
+
+
An updated version of the system is available.
+
+
+

Important: Before updating, please back up your database and files. For help with updates, visit the Updating Documentation.

+ +
+ Update Available: You are currently running version X. + Version Y is available. +
+
+ Up to Date: You are currently running version X. No core updates are available. +
+ +
+ + +
+

While your site is being updated, it will be in maintenance mode. As soon as your updates are complete, your site will return to normal.

+
+
+
+ + +
+
+
+
Plugins
+
+
+

The following plugins have new versions available. Check the ones you want to update and then click "Update Plugins".

+

Your plugins are all up to date.

+ +
+ + + + + + + + + + + + + + +
Plugin Name
Sample SEO Plugin
You have version 1.0.0. Update to 1.1.2.
+ +
+
+
+
+ + +
+
+
+
Themes
+
+
+

Your themes are all up to date.

+
+
+ +
+
+
Translations
+
+
+

Your translations are all up to date.

+
+
+
+
+ +
+ + + +