Added Tabs to edit page

This commit is contained in:
2025-11-16 21:57:10 -08:00
parent bba62180fe
commit a14df54cd9
29 changed files with 771 additions and 130 deletions

View File

@@ -1,5 +1,7 @@
<?php
// Create an admin user (POST)
use Nickyeoman\Validation;
$validate = new Validation\Validate();

View File

@@ -2,7 +2,8 @@
$data = array_merge($data, [
'title' => 'Novaconium Edit Page',
'pageclass' => 'novaconium'
'pageclass' => 'novaconium',
'editor' => 'ace'
]);
// Check if logged in
@@ -18,25 +19,35 @@ $pageid = $router->parameters['id'] ?? null;
if (!empty($pageid)) {
// Existing page: fetch from database
$query = <<<EOSQL
SELECT
id,
title,
heading,
description,
keywords,
author,
slug,
path,
intro,
body,
notes,
draft,
changefreq,
priority,
created,
updated
FROM pages
WHERE id = ?
WITH all_tags AS (
SELECT GROUP_CONCAT(DISTINCT name ORDER BY name SEPARATOR ',') AS tags_list
FROM tags
)
SELECT
p.id,
p.title,
p.heading,
p.description,
p.keywords,
p.author,
p.slug,
p.path,
p.intro,
p.body,
p.notes,
p.draft,
p.changefreq,
p.priority,
p.created,
p.updated,
COALESCE(GROUP_CONCAT(DISTINCT t.name ORDER BY t.name SEPARATOR ','), '') AS page_tags,
at.tags_list AS existing_tags
FROM pages p
LEFT JOIN page_tags pt ON p.id = pt.page_id
LEFT JOIN tags t ON pt.tag_id = t.id
CROSS JOIN all_tags at -- Zero-cost join for scalar
WHERE p.id = ?
GROUP BY p.id;
EOSQL;
$data['rows'] = $db->getRow($query, [$pageid]);
@@ -70,4 +81,4 @@ if (empty($pageid)) {
}
// Render the edit page view
view('@novacore/editpage', $data);
view('@novacore/editpage/index', $data);

View File

@@ -151,4 +151,51 @@ if ($row['total'] < 1) {
makeitso();
}
// Check Tags Table
$query = <<<EOSQL
SELECT TABLE_NAME
FROM information_schema.tables
WHERE table_schema = DATABASE()
AND TABLE_NAME = 'tags';
EOSQL;
$result = $db->query($query);
if ($result->num_rows === 0) {
$query = <<<EOSQL
CREATE TABLE IF NOT EXISTS `tags` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL UNIQUE,
`created` datetime NOT NULL,
`updated` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
EOSQL;
$db->query($query);
$log->info('Tags Table Created');
}
// Check Page Tags Junction Table (after tags table)
$query = <<<EOSQL
SELECT TABLE_NAME
FROM information_schema.tables
WHERE table_schema = DATABASE()
AND TABLE_NAME = 'page_tags';
EOSQL;
$result = $db->query($query);
if ($result->num_rows === 0) {
$query = <<<EOSQL
CREATE TABLE IF NOT EXISTS `page_tags` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`page_id` int(11) NOT NULL,
`tag_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `page_id` (`page_id`),
KEY `tag_id` (`tag_id`),
FOREIGN KEY (`page_id`) REFERENCES `pages` (`id`) ON DELETE CASCADE,
FOREIGN KEY (`tag_id`) REFERENCES `tags` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
EOSQL;
$db->query($query);
$log->info('Page Tags Junction Table Created');
}
view('@novacore/init', $data);

View File

@@ -2,6 +2,7 @@
use Nickyeoman\Validation;
$v = new Nickyeoman\Validation\Validate();
use Novaconium\Services\TagManager; // Autoloads automatically
$url_error = '/novaconium/page/edit/' . $post->get('id'); // fallback for errors
@@ -34,6 +35,7 @@ $notes = $_POST['notes'] ?? '';
$draft = !empty($post->get('draft')) ? 1 : 0;
$changefreq = $_POST['changefreq'] ?? 'monthly';
$priority = $_POST['priority'] ?? 0.0;
$tags_json = $_POST['tags_json'] ?? '[]';
// Validate required fields
if (empty($title) || empty($slug) || empty($body)) {
@@ -64,6 +66,19 @@ try {
}
if (!empty($id) && !$newpage) {
/** Work in Progress
// Delete old tag links for this page (cleanup)
$deleteQuery = <<<EOSQL
DELETE FROM page_tags WHERE page_id = ?
EOSQL;
$db->query($deleteQuery, [$id]);
$tagManager = new TagManager();
dd($tags_json);
**/
// Update existing page
$query = "UPDATE `pages` SET
`title` = ?, `heading` = ?, `description` = ?, `keywords` = ?, `author` = ?,