From 0113d2e9c9ff34a6ffb10707cc76d34b67a0c367 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Mon, 19 Jan 2026 16:29:41 +0000
Subject: [PATCH] =Refactored window.getTemplate into a full templating class window.jvbTemplates. Refactored CRUD.js, UploadManager.js, FormController.js, PopulateForm.js with that in mind
---
inc/managers/AdminPages.php | 101 +++++++++++++++++++++++++++++---------------------
1 files changed, 58 insertions(+), 43 deletions(-)
diff --git a/inc/managers/AdminPages.php b/inc/managers/AdminPages.php
index 0ae75d4..a2147a0 100644
--- a/inc/managers/AdminPages.php
+++ b/inc/managers/AdminPages.php
@@ -134,14 +134,15 @@
public function handleIconAction(\WP_REST_Request $request): \WP_REST_Response
{
$action = sanitize_text_field($request->get_param('action'));
- $icons = \JVBase\managers\IconsManager::getInstance();
+ $source = sanitize_text_field($request->get_param('source') ?? 'icons'); // Add source param
+ $icons = \JVBase\managers\IconsManager::for($source);
switch ($action) {
case 'refresh-icons':
$icons->forceRefresh();
return new \WP_REST_Response([
'success' => true,
- 'message' => 'Icon CSS regenerated successfully'
+ 'message' => "Icon CSS regenerated successfully for '{$source}'"
]);
case 'restore-icon-version':
@@ -582,9 +583,9 @@
if (current_user_can($action['capability'])) {
?>
<a data-action="<?=$action['slug']?>" class="jvb-action">
- <?= jvbIcon($action['icon']); ?>
+ <?= jvbDashIcon($action['icon']); ?>
<span class="jvb-link-title"><?= esc_html($action['label'])?></span>
- <span class="loader"><?=jvbIcon('arrows-clockwise')?><?=jvbIcon('check')?></span>
+ <span class="loader"><?=jvbDashIcon('arrows-clockwise')?><?=jvbDashIcon('check')?></span>
</a>
<?php
}
@@ -639,7 +640,7 @@
*/
protected function getIcon(string $icon = 'logo', bool $css = false): string
{
- $svg = jvbIcon($icon, ['wrap' => false]);
+ $svg = jvbDashIcon($icon, ['wrap' => false]);
if ($css) {
// For CSS, replace currentColor with brand color
$svg = str_replace('currentColor', '#FF0080', $svg);
@@ -681,7 +682,7 @@
<div class="jvb-cache-actions">
<button type="button" class="button button-primary" data-action="flush-all">
- <?= jvbIcon('arrows-clockwise'); ?>
+ <?= jvbDashIcon('arrows-clockwise'); ?>
Flush All Caches
</button>
</div>
@@ -706,7 +707,7 @@
<td><?= $this->formatConnections($configs); ?></td>
<td>
<button type="button" class="button" data-action="flush-cache" data-group="<?= esc_attr($group); ?>">
- <?= jvbIcon('trash'); ?> Flush
+ <?= jvbDashIcon('trash'); ?> Flush
</button>
</td>
</tr>
@@ -733,7 +734,7 @@
<td><?= $this->formatConnections($configs); ?></td>
<td>
<button type="button" class="button" data-action="flush-cache" data-group="<?= esc_attr($group); ?>">
- <?= jvbIcon('trash'); ?> Flush
+ <?= jvbDashIcon('trash'); ?> Flush
</button>
</td>
</tr>
@@ -928,7 +929,14 @@
public function renderIconsPage():void
{
- $icons = \JVBase\managers\IconsManager::getInstance();
+ // Get current source from query param or default to 'icons'
+ $current_source = $_GET['icon_source'] ?? 'icons';
+ $current_source = sanitize_text_field($current_source);
+
+ // Get all registered icon sources
+ $all_sources = ['icons', 'forms', 'dash']; // You could get this dynamically if needed
+
+ $icons = \JVBase\managers\IconsManager::for($current_source);
$versions = $icons->getVersionHistory();
$nonce = wp_create_nonce('wp_rest');
@@ -936,18 +944,30 @@
<div class="wrap jvb-admin-wrap">
<h1>Icon Management</h1>
+ <!-- Source Selector -->
+ <div class="jvb-icon-source-selector">
+ <label for="icon-source-select">Icon Source:</label>
+ <select id="icon-source-select" onchange="window.location.href='<?= admin_url('admin.php?page=' . BASE . 'icons&icon_source='); ?>' + this.value">
+ <?php foreach ($all_sources as $source): ?>
+ <option value="<?= esc_attr($source); ?>" <?= selected($current_source, $source, false); ?>>
+ <?= esc_html(ucfirst($source)); ?>
+ </option>
+ <?php endforeach; ?>
+ </select>
+ </div>
+
<div class="jvb-icon-actions">
- <button type="button" class="button button-primary" data-action="refresh-icons">
- <?= jvbIcon('arrows-clockwise'); ?>
+ <button type="button" class="button button-primary" data-action="refresh-icons" data-source="<?= esc_attr($current_source); ?>">
+ <?= jvbDashIcon('arrows-clockwise'); ?>
Force Refresh CSS
</button>
- <button type="button" class="button" data-action="merge-icon-versions" id="merge-versions-btn" disabled>
- <?= jvbIcon('git-merge'); ?>
+ <button type="button" class="button" data-action="merge-icon-versions" data-source="<?= esc_attr($current_source); ?>" id="merge-versions-btn" disabled>
+ <?= jvbDashIcon('git-merge'); ?>
Merge Selected Versions
</button>
</div>
- <h2>Version History</h2>
+ <h2>Version History for <?= esc_html(ucfirst($current_source)); ?></h2>
<table class="wp-list-table widefat fixed striped">
<thead>
<tr>
@@ -977,18 +997,18 @@
<td>
<?= esc_html($version['icon_count']); ?> icons
<button type="button"
- class="button-link"
- data-action="view-icon-list"
+ class="button-link view-icon-list-btn"
data-timestamp="<?= esc_attr($version['timestamp']); ?>">
(view)
</button>
</td>
<td><?= esc_html($version['size_formatted']); ?></td>
<td>
- <button type="button" class="button"
+ <button type="button" class="button restore-version-btn"
data-action="restore-icon-version"
+ data-source="<?= esc_attr($current_source); ?>"
data-timestamp="<?= esc_attr($version['timestamp']); ?>">
- <?= jvbIcon('arrow-counter-clockwise'); ?> Restore
+ <?= jvbDashIcon('arrow-counter-clockwise'); ?> Restore
</button>
</td>
</tr>
@@ -1012,10 +1032,11 @@
(function() {
const apiUrl = '<?= esc_js(rest_url('jvb/v1/admin-icons')); ?>';
const nonce = '<?= esc_js($nonce); ?>';
+ const currentSource = '<?= esc_js($current_source); ?>';
// Helper function for API calls
function callIconAction(action, data = {}) {
- const body = { action, ...data };
+ const body = { action, source: currentSource, ...data };
return fetch(apiUrl, {
method: 'POST',
@@ -1072,34 +1093,28 @@
});
// Force refresh button
- const refreshBtn = document.getElementById('refresh-icons-btn');
- if (refreshBtn) {
- refreshBtn.addEventListener('click', function() {
- if (confirm('Force regenerate icon CSS? This will reload the page.')) {
- this.disabled = true;
- callIconAction('refresh-icons');
- }
- });
- }
+ document.querySelector('[data-action="refresh-icons"]')?.addEventListener('click', function() {
+ if (confirm('Force regenerate icon CSS? This will reload the page.')) {
+ this.disabled = true;
+ callIconAction('refresh-icons');
+ }
+ });
// Merge versions button
- const mergeBtn = document.getElementById('merge-versions-btn');
- if (mergeBtn) {
- mergeBtn.addEventListener('click', function() {
- const checkboxes = document.querySelectorAll('.version-checkbox:checked');
- const timestamps = Array.from(checkboxes).map(cb => parseInt(cb.value));
+ document.getElementById('merge-versions-btn')?.addEventListener('click', function() {
+ const checkboxes = document.querySelectorAll('.version-checkbox:checked');
+ const timestamps = Array.from(checkboxes).map(cb => parseInt(cb.value));
- if (timestamps.length < 2) {
- alert('Please select at least 2 versions to merge');
- return;
- }
+ if (timestamps.length < 2) {
+ alert('Please select at least 2 versions to merge');
+ return;
+ }
- if (confirm(`Merge ${timestamps.length} versions? This will create a new CSS file with all unique icons.`)) {
- this.disabled = true;
- callIconAction('merge-icon-versions', { timestamps: timestamps });
- }
- });
- }
+ if (confirm(`Merge ${timestamps.length} versions? This will create a new CSS file with all unique icons.`)) {
+ this.disabled = true;
+ callIconAction('merge-icon-versions', { timestamps: timestamps });
+ }
+ });
// Restore version buttons
document.querySelectorAll('.restore-version-btn').forEach(btn => {
--
Gitblit v1.10.0