From 4089ba01e0881c89a72332e13bc3a80b6bddec2a Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Mon, 29 Jun 2026 22:15:55 +0000
Subject: [PATCH] =DashboardManager overhaul. A bit easier to modify the output of pages. Still have to get the account pages to work as expected, as well as verify the integrations and others are working - but registrar/content pages work as expected. Also fixed up the table generation in CRUD.js and CRUDSkeleton.php

---
 inc/managers/Dashboard/DashboardPage.php |   67 ++++++++++++++++++++++++---------
 1 files changed, 48 insertions(+), 19 deletions(-)

diff --git a/inc/managers/Dashboard/DashboardPage.php b/inc/managers/Dashboard/DashboardPage.php
index 653c86d..c8c7964 100644
--- a/inc/managers/Dashboard/DashboardPage.php
+++ b/inc/managers/Dashboard/DashboardPage.php
@@ -2,6 +2,7 @@
 namespace JVBase\managers\Dashboard;
 
 use JVBase\managers\Cache;
+use JVBase\registrar\Registrar;
 use WP_Query;
 
 if (!defined('ABSPATH')) {
@@ -11,8 +12,10 @@
 class DashboardPage {
 	protected string $title;
 	protected string $slug;
+	protected string $ogSlug;
 	protected string $icon;
 	protected string $URL;
+	protected int $parent = 0;
 	protected int $ID;
 	protected ?string $permission = null;
 	protected ?string $section = null;
@@ -22,24 +25,29 @@
 
 	public function __construct(string $title, string $slug = '', string $icon ='', int $parent = 0) {
 		$this->cache = Cache::for('dashboard');
-		$this->title = $title;
-		if (empty($slug)) {
-			$this->setSlug($title);
-		}else {
-			$this->setSlug($slug);
+		if (JVB_TESTING) {
+			$this->cache->flush();
 		}
+		$this->title = $title;
+		$this->setSlug(empty($slug) ? $title : $slug);
 		$this->icon = $icon;
+		$this->parent = $parent;
 		$this->setID($parent);
 		$this->setURL();
 	}
 
 	public function setID(int $parentID):void
 	{
+		if ($this->slug === 'dash') {
+			//We do not need to create the page for the main dash
+			$this->ID = 0;
+			return;
+		}
 		$this->ID = $this->cache->remember(
 			$this->slug.'_ID',
 			function() use ($parentID) {
 				$existing = new WP_Query([
-					'post_type'	=> BASE.'dash',
+					'post_type'	=> DashboardManager::$based,
 					'name'		=> $this->slug,
 					'fields'	=> 'ids',
 					'posts_per_page'=> 1,
@@ -51,7 +59,7 @@
 				$args = [
 					'post_title'	=> $this->title,
 					'post_name'		=> $this->slug,
-					'post_type'		=> BASE.'dash',
+					'post_type'		=> DashboardManager::$based,
 					'post_status'	=> 'publish'
 				];
 				if ($parentID > 0) {
@@ -66,14 +74,19 @@
 		return $this->ID;
 	}
 
+	public function getParent():int
+	{
+		return $this->parent;
+	}
+
 	public function setURL():void
 	{
-		$this->URL = $this->cache->remember(
-			$this->slug.'_url',
-			function () {
-				return get_permalink($this->ID);
-			}
-		);
+
+		if ($this->slug === 'dash') {
+			$this->URL = get_post_type_archive_link(DashboardManager::$based);
+			return;
+		}
+		$this->URL = get_the_permalink($this->ID);
 	}
 
 	public function getURL():string
@@ -93,6 +106,7 @@
 
 	public function setSlug(string $slug):void
 	{
+		$this->ogSlug = $slug;
 		$this->slug = self::sanitizeString($slug);
 	}
 	public function getSlug():string
@@ -142,12 +156,18 @@
 	}
 	public function render():string
 	{
-		return $this->cache->remember(
-			$this->ID,
-			function () {
-				return apply_filters(BASE.'render_'.$this->slug, '<h2>'.$this->title.' is not configured yet.</h2><p>Add a filter to '.BASE.'render_'.$this->slug.'</p>');
-			}
-		);
+		$check = str_replace('-','_',$this->slug);
+		ob_start();
+		do_action(BASE.'dashboard_page_'.$check, $this->slug, $this->ogSlug);
+		$out = ob_get_clean();
+
+		if (empty($out)) {
+			$out = sprintf(
+				'<h1>%s</h1><p>It doesn\'t look like this page is configured yet.</p>',
+				$this->title,
+			);
+		}
+		return $out;
 	}
 	/*********************************************************
 	 * UTILITY
@@ -156,4 +176,13 @@
 	{
 		return str_replace('_', '-', strtolower(sanitize_title($string)));
 	}
+
+	public function setScripts(array $scripts):void
+	{
+		$this->scripts = $scripts;
+	}
+	public function getScripts():array
+	{
+		return $this->scripts;
+	}
 }

--
Gitblit v1.10.0