debug: add logging to diagnose admin pricing page issue

- Added immediate calls to checkDbStatus() and checkWritePermission() in base.html
- Calls happen right after function definitions, before DOMContentLoaded
- Added console.log statements to track function execution and API responses
- Removed duplicate calls from admin_pricing.html to avoid conflicts
- This will help diagnose why username and admin link disappear on admin pricing page

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Mikhail Chusavitin
2026-02-02 14:51:38 +03:00
parent 693c1d05d7
commit eda0e7cb47
2 changed files with 18 additions and 5 deletions

View File

@@ -891,9 +891,6 @@ document.addEventListener('DOMContentLoaded', () => {
const initialTab = urlParams.get('tab') || 'alerts';
loadTab(initialTab);
// Check write permission for admin pricing link
checkWritePermission();
// Add event listeners for preview updates
document.getElementById('modal-period').addEventListener('change', fetchPreview);
document.getElementById('modal-coefficient').addEventListener('input', debounceFetchPreview);

View File

@@ -159,17 +159,21 @@
}
async function checkDbStatus() {
console.log('[DEBUG] checkDbStatus called');
try {
const resp = await fetch('/api/db-status');
const data = await resp.json();
console.log('[DEBUG] checkDbStatus response:', data);
const statusEl = document.getElementById('db-status');
const countsEl = document.getElementById('db-counts');
const userEl = document.getElementById('db-user');
console.log('[DEBUG] userEl:', userEl);
if (data.connected) {
statusEl.innerHTML = '<span class="text-green-400">БД: подключено</span>';
if (data.db_user) {
userEl.innerHTML = '<span class="text-gray-500">@</span>' + data.db_user;
console.log('[DEBUG] username set to:', data.db_user);
}
} else {
statusEl.innerHTML = '<span class="text-red-400">БД: ошибка - ' + data.error + '</span>';
@@ -177,20 +181,27 @@
countsEl.textContent = 'lot: ' + data.lot_count + ' | lot_log: ' + data.lot_log_count + ' | metadata: ' + data.metadata_count;
} catch(e) {
console.error('[DEBUG] checkDbStatus error:', e);
document.getElementById('db-status').innerHTML = '<span class="text-red-400">БД: нет связи</span>';
}
}
async function checkWritePermission() {
console.log('[DEBUG] checkWritePermission called');
try {
const resp = await fetch('/api/pricelists/can-write');
const data = await resp.json();
console.log('[DEBUG] checkWritePermission response:', data);
if (data.can_write) {
const link = document.getElementById('admin-pricing-link');
if (link) link.classList.remove('hidden');
console.log('[DEBUG] admin-pricing-link element:', link);
if (link) {
link.classList.remove('hidden');
console.log('[DEBUG] admin-pricing-link shown');
}
}
} catch(e) {
console.error('Failed to check write permission:', e);
console.error('[DEBUG] checkWritePermission error:', e);
}
}
@@ -210,6 +221,11 @@
}
}
// Call functions immediately to ensure they run even before DOMContentLoaded
// This ensures username and admin link are visible ASAP
checkDbStatus();
checkWritePermission();
// Load last sync time when page loads
document.addEventListener('DOMContentLoaded', loadLastSyncTime);
</script>