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,18 @@ function escapeHtml(text) {
|
||||
return div.innerHTML;
|
||||
}
|
||||
|
||||
// Get ticket ID from URL (handles both /ticket/123 and ?id=123 formats)
|
||||
function getTicketIdFromUrl() {
|
||||
// Try new URL format first: /ticket/123456789
|
||||
const pathMatch = window.location.pathname.match(/\/ticket\/(\d+)/);
|
||||
if (pathMatch) {
|
||||
return pathMatch[1];
|
||||
}
|
||||
// Fall back to query param: ?id=123456789
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
return params.get('id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle visibility groups field based on visibility selection
|
||||
*/
|
||||
@@ -28,14 +40,7 @@ function saveTicket() {
|
||||
const editables = document.querySelectorAll('.editable');
|
||||
const data = {};
|
||||
|
||||
// Extract ticket ID from URL (works with both old and new URL formats)
|
||||
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();
|
||||
|
||||
if (!ticketId) {
|
||||
console.error('Could not determine ticket ID');
|
||||
@@ -157,14 +162,7 @@ function addComment() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Extract ticket ID from URL (works with both old and new URL formats)
|
||||
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();
|
||||
|
||||
if (!ticketId) {
|
||||
console.error('Could not determine ticket ID');
|
||||
@@ -346,8 +344,6 @@ function handleAssignmentChange() {
|
||||
if (!data.success) {
|
||||
toast.error('Error updating assignment');
|
||||
console.error(data.error);
|
||||
} else {
|
||||
console.log('Assignment updated successfully');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
@@ -386,8 +382,6 @@ function handleMetadataChanges() {
|
||||
toast.error(`Error updating ${fieldName}`);
|
||||
console.error(data.error);
|
||||
} else {
|
||||
console.log(`${fieldName} updated successfully to:`, newValue);
|
||||
|
||||
// Update window.ticketData
|
||||
window.ticketData[fieldName] = fieldName === 'priority' ? parseInt(newValue) : newValue;
|
||||
|
||||
@@ -470,17 +464,9 @@ function updateTicketStatus() {
|
||||
|
||||
// Extract status change logic into reusable function
|
||||
function performStatusChange(statusSelect, selectedOption, newStatus) {
|
||||
// Extract ticket ID
|
||||
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();
|
||||
|
||||
if (!ticketId) {
|
||||
console.error('Could not determine ticket ID');
|
||||
statusSelect.selectedIndex = 0;
|
||||
return;
|
||||
}
|
||||
@@ -531,8 +517,6 @@ function performStatusChange(statusSelect, selectedOption, newStatus) {
|
||||
statusSelect.insertBefore(selectedOption, statusSelect.firstChild);
|
||||
statusSelect.selectedIndex = 0;
|
||||
|
||||
console.log('Status updated successfully to:', newStatus);
|
||||
|
||||
// Reload page to refresh activity timeline
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
|
||||
Reference in New Issue
Block a user