From 3d25ad7de4fdbb3eba2cde2a62422e6be5d79a0a Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Tue, 25 Aug 2026 22:57:22 +0000
Subject: [PATCH] =It's been a minute. I went through the Routes and associated Managers and ensured they played together well. Reworked the Cache.php, and I think I caught all the references. Moving away from JVBase() root class, to individuall classes that are Instanced. Double checked for the ABSPATH check in every file, and added index.php to every directory that didn't already have it. Also still working on the MenuBlock to work with WooCommerce for now for Northeh
---
assets/js/concise/Queue.js | 90 +++++++++++++++++++++++++++++++++------------
1 files changed, 66 insertions(+), 24 deletions(-)
diff --git a/assets/js/concise/Queue.js b/assets/js/concise/Queue.js
index 13d8f83..e1f1a04 100644
--- a/assets/js/concise/Queue.js
+++ b/assets/js/concise/Queue.js
@@ -5,6 +5,10 @@
this.user = window.auth.getUser();
+ if (!this.user) {
+ return;
+ }
+
this.canUpdateUI = true;
this.isProcessing = false;
@@ -12,12 +16,12 @@
this.queue = new Map();
this.items = new Map();
this.subscribers = new Set();
+ this.loadFromStorage = false;
+ this.failedFetches = 0;
this.api = jvbSettings.api;
this.endpoint = 'queue';
- this.queueItems = new Map();
-
this.init();
}
init() {
@@ -27,6 +31,7 @@
this.initElements();
this.initListeners();
this.initStore();
+
if (this.canUpdateUI && this.ui.panel) {
this.popup = window.jvbPopup.registerPopup({
popup: this.ui.panel,
@@ -57,8 +62,8 @@
count: '.qtoggle .count'
},
refresh: {
- button: '#queue .refresh .refreshNow',
- countdown: '#queue .refresh .countdown'
+ button: '#queue .m-actions .refresh',
+ countdown: '#queue .m-actions .refresh .countdown'
},
popup: {
popup: '#queue .popup',
@@ -167,7 +172,7 @@
window.addEventListener('online', this.onlineHandler);
window.addEventListener('offline', this.offlineHandler);
- window.addEventListener('beforeunload', this.unloadHandler);
+ // window.addEventListener('beforeunload', this.unloadHandler);
document.addEventListener('visibilitychange', this.visibilityHandler);
}
@@ -301,6 +306,7 @@
keyPath: 'id',
endpoint: this.endpoint,
TTL: Infinity,
+ isAuth: true,
indexes: [
{name: 'status', keyPath: 'status'},
{name: 'type', keyPath: 'type'},
@@ -403,6 +409,7 @@
OPERATIONS
****************************************************************************/
addToQueue(operation) {
+ console.log(operation, 'Adding to queue:');
const item = {
id: `u${this.user}_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`,
endpoint: null,
@@ -487,7 +494,7 @@
}
try {
- const response = await fetch(
+ const response = await window.auth.fetch(
`${this.api}${this.endpoint}`,
{
method: 'POST',
@@ -585,21 +592,25 @@
this.updateOperationStatus(operation.id, 'uploading');
let requestBody;
+ let req;
if (operation.data instanceof FormData) {
operation.data.append('id', operation.id);
operation.data.append('user', window.auth.getUser());
requestBody = operation.data;
+ req = operation.data;
} else {
- requestBody = JSON.stringify({
+ req = {
...operation.data,
id: operation.id,
user: window.auth.getUser()
- });
+ };
+ requestBody = JSON.stringify(req);
operation.headers['Content-Type'] = 'application/json';
}
- if (requestBody === undefined || requestBody === null) return;
+ if (operation.endpoint === 'unknown' || requestBody === undefined || requestBody === null) return;
- const response = await fetch(
+
+ const response = await window.auth.fetch(
`${this.api}${operation.endpoint}`,
{
method: operation.method,
@@ -607,11 +618,14 @@
body: requestBody
}
);
+ // console.log('Sending request with data: ', req);
const result = await response.json();
if (skip) {
operation.data = {};
}
+ // console.log('Result: ', result);
if (response.ok && result.success) {
+ this.notify('sent-to-server', req);
if (result.id && operation.id !== result.id) {
operation = await this.handleServerMerge(operation, result);
} else {
@@ -695,10 +709,24 @@
}
getAllQueue() {
- let ops = [... new Set([
- ...Array.from(this.store.data.values()),
+ let index = new Set();
+
+ let ops = [
... Array.from(this.queue.values())
- ])];
+ ];
+ if (!this.loadFromStorage) {
+ this.loadFromStorage = true;
+ ops = [
+ ... ops,
+ ...Array.from(this.store.data.values())
+ ];
+
+ ops = ops.filter(el => {
+ const isAdded = index.has(el.id);
+ index.add(el.id);
+ return !isAdded;
+ });
+ }
//Sort operations by operation updated_at
return this.sortOperations(ops);
}
@@ -708,17 +736,19 @@
status = [status];
}
- let ops = [...new Set([
- ...Array.from(this.store.filterByIndex({status: status})),
- ...Array.from(this.queue.values()).filter(op => status.includes(op.status))
- ])];
- return this.sortOperations(ops);
+ let ops = this.getAllQueue();
+ return ops.filter(op => status.includes(op.status));
}
updateOperationStatus(itemID, status) {
let item = this.getQueue(itemID);
- if (!item || !this.statuses.includes(status)) return;
+ if (!item) return;
+ if (!this.statuses.includes(status)) {
+ console.log('Invalid status: ', status);
+ return;
+ }
+
item.status = status;
this.notify('operation-status', item);
this.setQueue(item);
@@ -759,7 +789,15 @@
try {
this.ui.refresh.button.classList.add('fetching');
this.store.clearCache();
- await this.store.fetch();
+ let response = await this.store.fetch();
+
+ if (Object.hasOwn(response, 'status') && response.status === 429) {
+ console.log('Too many requests. Waiting 30 seconds');
+ this.stopPolling();
+ this.startCountdown(30, () => this.runPollCycle());
+ return;
+ }
+
this.ui.refresh.button.classList.remove('fetching');
if (!this.maybeStartPolling()) {
this.stopPolling();
@@ -767,6 +805,8 @@
return;
}
} catch (error) {
+ this.stopPolling();
+ this.updatePanel('synced');
console.error('Polling error:', error);
}
@@ -827,9 +867,10 @@
this.ui.actions.retry.disabled = operations.filter(op => op.status === 'failed').length === 0;
this.ui.actions.clear.disabled = operations.filter(op => op.status === 'completed').length ===0;
- const activeCount = operations.filter(op =>
+ let activeCount = operations.filter(op =>
[...this.pendingStatuses, ...this.workingStatuses].includes(op.status)
- ).length;
+ );
+ activeCount = activeCount.length;
this.ui.toggle.count.hidden = activeCount === 0;
this.ui.toggle.count.textContent = activeCount;
@@ -907,7 +948,8 @@
let op = this.getQueue(opId);
let element = item.element;
- element.classList.remove(this.statuses);
+
+ element.classList.remove(... this.statuses);
element.classList.add(op.status);
let progress = this.getProgress(op);
@@ -1099,7 +1141,7 @@
// Auto-dismiss merged operation after brief display
// The target operation already has all the merged data from server
setTimeout(() => {
- this.store.delete(operation.id);
+ this.clearQueue(operation.id);
this.removeOperationFromUI(operation.id);
}, 3000);
}
--
Gitblit v1.10.0