refactor: Code cleanup and documentation updates
Bug fixes: - Fix ticket ID extraction using URLSearchParams instead of split() - Add error handling for query result in get_users.php - Make Discord webhook URLs dynamic (use HTTP_HOST) Code cleanup: - Remove debug console.log statements from dashboard.js and ticket.js - Add getTicketIdFromUrl() helper function to both JS files Documentation: - Update Claude.md: fix web server (nginx not Apache), add new notes - Update README.md: add keyboard shortcuts, update setup instructions Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,14 @@ function escapeHtml(text) {
|
||||
return div.innerHTML;
|
||||
}
|
||||
|
||||
// Get ticket ID from URL (handles both /ticket/123 and ?id=123 formats)
|
||||
function getTicketIdFromUrl() {
|
||||
const pathMatch = window.location.pathname.match(/\/ticket\/(\d+)/);
|
||||
if (pathMatch) return pathMatch[1];
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
return params.get('id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle sidebar visibility on desktop
|
||||
*/
|
||||
@@ -32,19 +40,13 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
|
||||
// Main initialization
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
console.log('DOM loaded, initializing dashboard...');
|
||||
|
||||
// Check if we're on the dashboard page
|
||||
const hasTable = document.querySelector('table');
|
||||
const isTicketPage = window.location.pathname.includes('/ticket/') ||
|
||||
const isTicketPage = window.location.pathname.includes('/ticket/') ||
|
||||
window.location.href.includes('ticket.php') ||
|
||||
document.querySelector('.ticket-details') !== null;
|
||||
const isDashboard = hasTable && !isTicketPage;
|
||||
|
||||
console.log('Has table:', hasTable);
|
||||
console.log('Is ticket page:', isTicketPage);
|
||||
console.log('Is dashboard:', isDashboard);
|
||||
|
||||
if (isDashboard) {
|
||||
// Dashboard-specific initialization
|
||||
initStatusFilter();
|
||||
@@ -324,8 +326,6 @@ function quickSave() {
|
||||
priority: parseInt(prioritySelect.value)
|
||||
};
|
||||
|
||||
console.log('Saving ticket data:', data);
|
||||
|
||||
fetch('/api/update_ticket.php', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -335,9 +335,7 @@ function quickSave() {
|
||||
body: JSON.stringify(data)
|
||||
})
|
||||
.then(response => {
|
||||
console.log('Response status:', response.status);
|
||||
return response.text().then(text => {
|
||||
console.log('Raw response:', text);
|
||||
try {
|
||||
return JSON.parse(text);
|
||||
} catch (e) {
|
||||
@@ -346,7 +344,6 @@ function quickSave() {
|
||||
});
|
||||
})
|
||||
.then(result => {
|
||||
console.log('Update result:', result);
|
||||
if (result.success) {
|
||||
// Update the hamburger menu display
|
||||
const hamburgerStatus = document.getElementById('hamburger-status');
|
||||
@@ -365,9 +362,7 @@ function quickSave() {
|
||||
statusDisplay.className = `status-${statusSelect.value}`;
|
||||
statusDisplay.textContent = statusSelect.value;
|
||||
}
|
||||
|
||||
console.log('Ticket updated successfully');
|
||||
|
||||
|
||||
// Close hamburger menu after successful save
|
||||
const hamburgerContent = document.querySelector('.hamburger-content');
|
||||
if (hamburgerContent) {
|
||||
@@ -391,15 +386,8 @@ function quickSave() {
|
||||
function saveTicket() {
|
||||
const editables = document.querySelectorAll('.editable');
|
||||
const data = {};
|
||||
|
||||
let ticketId;
|
||||
if (window.location.href.includes('?id=')) {
|
||||
ticketId = window.location.href.split('id=')[1];
|
||||
} else {
|
||||
const matches = window.location.pathname.match(/\/ticket\/(\d+)/);
|
||||
ticketId = matches ? matches[1] : null;
|
||||
}
|
||||
|
||||
const ticketId = getTicketIdFromUrl();
|
||||
|
||||
editables.forEach(field => {
|
||||
if (field.dataset.field) {
|
||||
data[field.dataset.field] = field.value;
|
||||
@@ -477,8 +465,6 @@ function loadTemplate() {
|
||||
if (template.default_priority) {
|
||||
document.getElementById('priority').value = template.default_priority;
|
||||
}
|
||||
|
||||
console.log('Template loaded:', template.template_name);
|
||||
} else {
|
||||
console.error('Failed to load template:', data.error);
|
||||
toast.error('Failed to load template: ' + (data.error || 'Unknown error'), 4000);
|
||||
|
||||
Reference in New Issue
Block a user