v2
This commit is contained in:
@@ -94,6 +94,18 @@
|
||||
<i class="fas fa-tools"></i> Maintenance
|
||||
</button>
|
||||
</li>
|
||||
<li class="nav-item" role="presentation">
|
||||
<button class="nav-link" id="issues-tab" data-bs-toggle="tab" data-bs-target="#issues"
|
||||
type="button" role="tab">
|
||||
<i class="fas fa-bug"></i> Issue Tracking
|
||||
</button>
|
||||
</li>
|
||||
<li class="nav-item" role="presentation">
|
||||
<button class="nav-link" id="import-tab" data-bs-toggle="tab" data-bs-target="#import"
|
||||
type="button" role="tab">
|
||||
<i class="bi bi-upload"></i> Data Import
|
||||
</button>
|
||||
</li>
|
||||
<li class="nav-item" role="presentation">
|
||||
<button class="nav-link" id="backup-tab" data-bs-toggle="tab" data-bs-target="#backup"
|
||||
type="button" role="tab">
|
||||
@@ -373,6 +385,283 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Issues Tab -->
|
||||
<div class="tab-pane fade" id="issues" role="tabpanel">
|
||||
<div class="row mb-4">
|
||||
<!-- Issue Statistics Cards -->
|
||||
<div class="col-md-3">
|
||||
<div class="card border-danger">
|
||||
<div class="card-body text-center">
|
||||
<h2 class="text-danger" id="high-priority-count">0</h2>
|
||||
<h6>High Priority</h6>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="card border-warning">
|
||||
<div class="card-body text-center">
|
||||
<h2 class="text-warning" id="open-issues-count">0</h2>
|
||||
<h6>Open Issues</h6>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="card border-info">
|
||||
<div class="card-body text-center">
|
||||
<h2 class="text-info" id="in-progress-count">0</h2>
|
||||
<h6>In Progress</h6>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="card border-success">
|
||||
<div class="card-body text-center">
|
||||
<h2 class="text-success" id="resolved-count">0</h2>
|
||||
<h6>Resolved</h6>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Issue Management -->
|
||||
<div class="card">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<h5 class="mb-0"><i class="fas fa-bug"></i> Internal Issues & Bugs</h5>
|
||||
<div>
|
||||
<button type="button" class="btn btn-outline-primary btn-sm me-2" onclick="loadIssues()">
|
||||
<i class="fas fa-sync"></i> Refresh
|
||||
</button>
|
||||
<button type="button" class="btn btn-primary btn-sm" onclick="openSupportModal()">
|
||||
<i class="fas fa-plus"></i> New Issue
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<!-- Filters -->
|
||||
<div class="row mb-3">
|
||||
<div class="col-md-3">
|
||||
<select class="form-select form-select-sm" id="issueStatusFilter" onchange="filterIssues()">
|
||||
<option value="">All Statuses</option>
|
||||
<option value="open">Open</option>
|
||||
<option value="in_progress">In Progress</option>
|
||||
<option value="resolved">Resolved</option>
|
||||
<option value="closed">Closed</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<select class="form-select form-select-sm" id="issuePriorityFilter" onchange="filterIssues()">
|
||||
<option value="">All Priorities</option>
|
||||
<option value="urgent">Urgent</option>
|
||||
<option value="high">High</option>
|
||||
<option value="medium">Medium</option>
|
||||
<option value="low">Low</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<select class="form-select form-select-sm" id="issueCategoryFilter" onchange="filterIssues()">
|
||||
<option value="">All Categories</option>
|
||||
<option value="bug_report">Bug Reports</option>
|
||||
<option value="qa_issue">QA Issues</option>
|
||||
<option value="feature_request">Feature Requests</option>
|
||||
<option value="database_issue">Database Issues</option>
|
||||
<option value="system_error">System Errors</option>
|
||||
<option value="performance">Performance</option>
|
||||
<option value="user_access">User Access</option>
|
||||
<option value="configuration">Configuration</option>
|
||||
<option value="documentation">Documentation</option>
|
||||
<option value="testing">Testing</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="form-check form-check-inline">
|
||||
<input class="form-check-input" type="checkbox" id="assignedToMeFilter" onchange="filterIssues()">
|
||||
<label class="form-check-label" for="assignedToMeFilter">
|
||||
Assigned to me
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Issues Table -->
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-hover">
|
||||
<thead class="table-dark">
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Type</th>
|
||||
<th>Priority</th>
|
||||
<th>Subject</th>
|
||||
<th>Reporter</th>
|
||||
<th>Status</th>
|
||||
<th>Assigned</th>
|
||||
<th>Created</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="issues-table-body">
|
||||
<tr>
|
||||
<td colspan="9" class="text-center">Loading issues...</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Issue Detail Modal -->
|
||||
<div class="modal fade" id="issueDetailModal" tabindex="-1">
|
||||
<div class="modal-dialog modal-xl">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="issueDetailModalTitle">
|
||||
<i class="fas fa-bug me-2"></i>Issue Details
|
||||
</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="row">
|
||||
<!-- Left Column - Issue Details -->
|
||||
<div class="col-md-8">
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<div>
|
||||
<span class="badge bg-primary me-2" id="issueDetailNumber">ST-2025-XXXX</span>
|
||||
<span class="badge" id="issueDetailCategory">category</span>
|
||||
<span class="badge ms-2" id="issueDetailPriority">priority</span>
|
||||
</div>
|
||||
<span class="badge fs-6" id="issueDetailStatus">status</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<h5 id="issueDetailSubject">Issue subject</h5>
|
||||
<div class="mt-3">
|
||||
<h6>Description:</h6>
|
||||
<div id="issueDetailDescription" style="white-space: pre-wrap; background: #f8f9fa; padding: 1rem; border-radius: 0.375rem;"></div>
|
||||
</div>
|
||||
<div class="mt-3">
|
||||
<h6>Context Information:</h6>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<small><strong>Page:</strong> <span id="issueDetailPage">-</span></small>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<small><strong>Browser:</strong> <span id="issueDetailBrowser">-</span></small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Responses Section -->
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h6 class="mb-0">Comments & Updates</h6>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div id="issueResponses">
|
||||
<p class="text-muted">No comments yet.</p>
|
||||
</div>
|
||||
|
||||
<!-- Add Response Form -->
|
||||
<div class="mt-3 border-top pt-3">
|
||||
<textarea class="form-control mb-2" id="newResponseText" rows="3" placeholder="Add a comment..."></textarea>
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" id="internalResponseCheck">
|
||||
<label class="form-check-label" for="internalResponseCheck">
|
||||
Internal note (not visible to reporter)
|
||||
</label>
|
||||
</div>
|
||||
<button type="button" class="btn btn-primary btn-sm" onclick="addResponse()">
|
||||
<i class="fas fa-comment"></i> Add Comment
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Right Column - Issue Management -->
|
||||
<div class="col-md-4">
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">
|
||||
<h6 class="mb-0">Issue Management</h6>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form id="issueUpdateForm">
|
||||
<input type="hidden" id="currentIssueId">
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Status</label>
|
||||
<select class="form-select form-select-sm" id="updateStatus">
|
||||
<option value="open">Open</option>
|
||||
<option value="in_progress">In Progress</option>
|
||||
<option value="resolved">Resolved</option>
|
||||
<option value="closed">Closed</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Priority</label>
|
||||
<select class="form-select form-select-sm" id="updatePriority">
|
||||
<option value="low">Low</option>
|
||||
<option value="medium">Medium</option>
|
||||
<option value="high">High</option>
|
||||
<option value="urgent">Urgent</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Assign To</label>
|
||||
<select class="form-select form-select-sm" id="updateAssignee">
|
||||
<option value="">Unassigned</option>
|
||||
<!-- Will be populated with users -->
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<button type="button" class="btn btn-success btn-sm w-100" onclick="updateIssue()">
|
||||
<i class="fas fa-save"></i> Update Issue
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h6 class="mb-0">Issue Info</h6>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="mb-2">
|
||||
<small class="text-muted">Reporter:</small><br>
|
||||
<span id="issueDetailReporter">-</span>
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<small class="text-muted">Email:</small><br>
|
||||
<span id="issueDetailEmail">-</span>
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<small class="text-muted">Created:</small><br>
|
||||
<span id="issueDetailCreated">-</span>
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<small class="text-muted">Last Updated:</small><br>
|
||||
<span id="issueDetailUpdated">-</span>
|
||||
</div>
|
||||
<div class="mb-2" id="issueResolvedInfo" style="display: none;">
|
||||
<small class="text-muted">Resolved:</small><br>
|
||||
<span id="issueDetailResolved">-</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -515,6 +804,15 @@ let currentUsers = [];
|
||||
let currentSettings = [];
|
||||
let userPagination = { page: 1, limit: 10 };
|
||||
|
||||
// Helper function for authenticated API calls
|
||||
function getAuthHeaders() {
|
||||
const token = localStorage.getItem('auth_token');
|
||||
return {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'Content-Type': 'application/json'
|
||||
};
|
||||
}
|
||||
|
||||
// Initialize admin dashboard
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
loadSystemHealth();
|
||||
@@ -523,15 +821,25 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
loadSettings();
|
||||
loadLookupTables();
|
||||
loadBackups();
|
||||
loadIssues();
|
||||
loadIssueStats();
|
||||
|
||||
// Auto-refresh every 5 minutes
|
||||
setInterval(loadSystemHealth, 300000);
|
||||
|
||||
// Load issue stats when Issue Tracking tab is clicked
|
||||
document.getElementById('issues-tab').addEventListener('shown.bs.tab', function() {
|
||||
loadIssues();
|
||||
loadIssueStats();
|
||||
});
|
||||
});
|
||||
|
||||
// System Health Functions
|
||||
async function loadSystemHealth() {
|
||||
try {
|
||||
const response = await fetch('/api/admin/health');
|
||||
const response = await fetch('/api/admin/health', {
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
const data = await response.json();
|
||||
|
||||
// Update status indicator
|
||||
@@ -567,7 +875,9 @@ async function loadSystemHealth() {
|
||||
|
||||
async function loadSystemStats() {
|
||||
try {
|
||||
const response = await fetch('/api/admin/stats');
|
||||
const response = await fetch('/api/admin/stats', {
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
const data = await response.json();
|
||||
|
||||
// Update dashboard cards
|
||||
@@ -611,7 +921,9 @@ async function loadUsers() {
|
||||
if (search) url += 'search=' + encodeURIComponent(search) + '&';
|
||||
if (filter === 'active') url += 'active_only=true&';
|
||||
|
||||
const response = await fetch(url);
|
||||
const response = await fetch(url, {
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
const users = await response.json();
|
||||
currentUsers = users;
|
||||
|
||||
@@ -675,7 +987,9 @@ function showCreateUserModal() {
|
||||
|
||||
async function editUser(userId) {
|
||||
try {
|
||||
const response = await fetch('/api/admin/users/' + userId);
|
||||
const response = await fetch('/api/admin/users/' + userId, {
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
const user = await response.json();
|
||||
|
||||
document.getElementById('userModalTitle').textContent = 'Edit User';
|
||||
@@ -719,9 +1033,7 @@ async function saveUser() {
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: method,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
headers: getAuthHeaders(),
|
||||
body: JSON.stringify(userData)
|
||||
});
|
||||
|
||||
@@ -759,9 +1071,7 @@ async function resetPassword() {
|
||||
try {
|
||||
const response = await fetch('/api/admin/users/' + userId + '/reset-password', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
headers: getAuthHeaders(),
|
||||
body: JSON.stringify({
|
||||
new_password: newPassword,
|
||||
confirm_password: confirmPassword
|
||||
@@ -787,7 +1097,8 @@ async function deactivateUser(userId) {
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/admin/users/' + userId, {
|
||||
method: 'DELETE'
|
||||
method: 'DELETE',
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
@@ -807,7 +1118,9 @@ async function deactivateUser(userId) {
|
||||
// Settings Management Functions
|
||||
async function loadSettings() {
|
||||
try {
|
||||
const response = await fetch('/api/admin/settings');
|
||||
const response = await fetch('/api/admin/settings', {
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
const data = await response.json();
|
||||
currentSettings = data.settings;
|
||||
|
||||
@@ -856,7 +1169,9 @@ function showCreateSettingModal() {
|
||||
|
||||
async function editSetting(settingKey) {
|
||||
try {
|
||||
const response = await fetch('/api/admin/settings/' + encodeURIComponent(settingKey));
|
||||
const response = await fetch('/api/admin/settings/' + encodeURIComponent(settingKey), {
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
const setting = await response.json();
|
||||
|
||||
document.getElementById('settingModalTitle').textContent = 'Edit Setting';
|
||||
@@ -891,9 +1206,7 @@ async function saveSetting() {
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: method,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
headers: getAuthHeaders(),
|
||||
body: JSON.stringify(isEdit ? {
|
||||
setting_value: settingData.setting_value,
|
||||
description: settingData.description
|
||||
@@ -920,7 +1233,8 @@ async function deleteSetting(settingKey) {
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/admin/settings/' + encodeURIComponent(settingKey), {
|
||||
method: 'DELETE'
|
||||
method: 'DELETE',
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
@@ -940,7 +1254,9 @@ async function deleteSetting(settingKey) {
|
||||
// Maintenance Functions
|
||||
async function loadLookupTables() {
|
||||
try {
|
||||
const response = await fetch('/api/admin/lookups/tables');
|
||||
const response = await fetch('/api/admin/lookups/tables', {
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
const data = await response.json();
|
||||
|
||||
const element = document.getElementById('lookup-tables');
|
||||
@@ -964,7 +1280,10 @@ async function vacuumDatabase() {
|
||||
if (!confirm('This will optimize the database. Continue?')) return;
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/admin/maintenance/vacuum', { method: 'POST' });
|
||||
const response = await fetch('/api/admin/maintenance/vacuum', {
|
||||
method: 'POST',
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
const result = await response.json();
|
||||
|
||||
if (response.ok) {
|
||||
@@ -984,7 +1303,10 @@ async function analyzeDatabase() {
|
||||
if (!confirm('This will analyze database statistics. Continue?')) return;
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/admin/maintenance/analyze', { method: 'POST' });
|
||||
const response = await fetch('/api/admin/maintenance/analyze', {
|
||||
method: 'POST',
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
const result = await response.json();
|
||||
|
||||
if (response.ok) {
|
||||
@@ -1020,7 +1342,9 @@ function addMaintenanceLog(operation, message) {
|
||||
// Backup Functions
|
||||
async function loadBackups() {
|
||||
try {
|
||||
const response = await fetch('/api/admin/backup/list');
|
||||
const response = await fetch('/api/admin/backup/list', {
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
const data = await response.json();
|
||||
|
||||
const tbody = document.getElementById('backup-list');
|
||||
@@ -1059,7 +1383,10 @@ async function createBackup() {
|
||||
if (!confirm('Create a new database backup?')) return;
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/admin/backup/create', { method: 'POST' });
|
||||
const response = await fetch('/api/admin/backup/create', {
|
||||
method: 'POST',
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
const result = await response.json();
|
||||
|
||||
if (response.ok) {
|
||||
@@ -1087,9 +1414,360 @@ function refreshDashboard() {
|
||||
loadSettings();
|
||||
loadLookupTables();
|
||||
loadBackups();
|
||||
loadIssues();
|
||||
showAlert('Dashboard refreshed', 'info');
|
||||
}
|
||||
|
||||
// Issue Tracking Functions
|
||||
let currentIssues = [];
|
||||
let allUsers = [];
|
||||
|
||||
async function loadIssues() {
|
||||
try {
|
||||
const statusFilter = document.getElementById('issueStatusFilter').value;
|
||||
const priorityFilter = document.getElementById('issuePriorityFilter').value;
|
||||
const categoryFilter = document.getElementById('issueCategoryFilter').value;
|
||||
const assignedToMe = document.getElementById('assignedToMeFilter').checked;
|
||||
|
||||
let url = '/api/support/tickets?';
|
||||
if (statusFilter) url += 'status=' + encodeURIComponent(statusFilter) + '&';
|
||||
if (priorityFilter) url += 'priority=' + encodeURIComponent(priorityFilter) + '&';
|
||||
if (categoryFilter) url += 'category=' + encodeURIComponent(categoryFilter) + '&';
|
||||
if (assignedToMe) url += 'assigned_to_me=true&';
|
||||
|
||||
const response = await fetch(url, {
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to load issues');
|
||||
}
|
||||
|
||||
const issues = await response.json();
|
||||
currentIssues = issues;
|
||||
|
||||
renderIssuesTable(issues);
|
||||
|
||||
} catch (error) {
|
||||
console.error('Failed to load issues:', error);
|
||||
document.getElementById('issues-table-body').innerHTML = '<tr><td colspan="9" class="text-center text-danger">Failed to load issues</td></tr>';
|
||||
showAlert('Failed to load issues', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
async function loadIssueStats() {
|
||||
try {
|
||||
const response = await fetch('/api/support/stats', {
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to load issue stats');
|
||||
}
|
||||
|
||||
const stats = await response.json();
|
||||
|
||||
// Update dashboard cards
|
||||
document.getElementById('high-priority-count').textContent = stats.high_priority_tickets + stats.urgent_tickets;
|
||||
document.getElementById('open-count').textContent = stats.open_tickets;
|
||||
document.getElementById('in-progress-count').textContent = stats.in_progress_tickets;
|
||||
document.getElementById('resolved-count').textContent = stats.resolved_tickets;
|
||||
|
||||
} catch (error) {
|
||||
console.error('Failed to load issue stats:', error);
|
||||
showAlert('Failed to load issue statistics', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
function renderIssuesTable(issues) {
|
||||
const tbody = document.getElementById('issues-table-body');
|
||||
|
||||
if (issues.length === 0) {
|
||||
tbody.innerHTML = '<tr><td colspan="9" class="text-center">No issues found</td></tr>';
|
||||
return;
|
||||
}
|
||||
|
||||
tbody.innerHTML = issues.map(issue => {
|
||||
const priorityClass = {
|
||||
'urgent': 'bg-danger',
|
||||
'high': 'bg-warning',
|
||||
'medium': 'bg-info',
|
||||
'low': 'bg-secondary'
|
||||
}[issue.priority] || 'bg-secondary';
|
||||
|
||||
const statusClass = {
|
||||
'open': 'bg-danger',
|
||||
'in_progress': 'bg-warning',
|
||||
'resolved': 'bg-success',
|
||||
'closed': 'bg-secondary'
|
||||
}[issue.status] || 'bg-secondary';
|
||||
|
||||
const categoryDisplay = {
|
||||
'bug_report': 'Bug Report',
|
||||
'qa_issue': 'QA Issue',
|
||||
'feature_request': 'Feature Request',
|
||||
'database_issue': 'Database Issue',
|
||||
'system_error': 'System Error',
|
||||
'user_access': 'User Access',
|
||||
'performance': 'Performance',
|
||||
'documentation': 'Documentation',
|
||||
'configuration': 'Configuration',
|
||||
'testing': 'Testing'
|
||||
}[issue.category] || issue.category;
|
||||
|
||||
return `
|
||||
<tr>
|
||||
<td><strong>${issue.ticket_number}</strong></td>
|
||||
<td>
|
||||
<span class="badge bg-primary">${categoryDisplay}</span>
|
||||
</td>
|
||||
<td>
|
||||
<span class="badge ${priorityClass}">${issue.priority.toUpperCase()}</span>
|
||||
</td>
|
||||
<td>
|
||||
<div style="max-width: 200px; overflow: hidden; text-overflow: ellipsis;">
|
||||
${issue.subject}
|
||||
</div>
|
||||
</td>
|
||||
<td>${issue.contact_name}</td>
|
||||
<td>
|
||||
<span class="badge ${statusClass}">${issue.status.replace('_', ' ').toUpperCase()}</span>
|
||||
</td>
|
||||
<td>${issue.assigned_admin_name || 'Unassigned'}</td>
|
||||
<td>${new Date(issue.created_at).toLocaleDateString()}</td>
|
||||
<td>
|
||||
<button class="btn btn-outline-primary btn-sm" onclick="viewIssue(${issue.id})" title="View Details">
|
||||
<i class="fas fa-eye"></i>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
`;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
function filterIssues() {
|
||||
loadIssues();
|
||||
}
|
||||
|
||||
async function viewIssue(issueId) {
|
||||
try {
|
||||
const response = await fetch('/api/support/tickets/' + issueId, {
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to load issue details');
|
||||
}
|
||||
|
||||
const issue = await response.json();
|
||||
|
||||
// Populate issue detail modal
|
||||
document.getElementById('issueDetailNumber').textContent = issue.ticket_number;
|
||||
document.getElementById('issueDetailSubject').textContent = issue.subject;
|
||||
document.getElementById('issueDetailDescription').textContent = issue.description;
|
||||
|
||||
// Update badges
|
||||
const categoryDisplay = {
|
||||
'bug_report': 'Bug Report',
|
||||
'qa_issue': 'QA Issue',
|
||||
'feature_request': 'Feature Request',
|
||||
'database_issue': 'Database Issue',
|
||||
'system_error': 'System Error',
|
||||
'user_access': 'User Access',
|
||||
'performance': 'Performance',
|
||||
'documentation': 'Documentation',
|
||||
'configuration': 'Configuration',
|
||||
'testing': 'Testing'
|
||||
}[issue.category] || issue.category;
|
||||
|
||||
document.getElementById('issueDetailCategory').textContent = categoryDisplay;
|
||||
document.getElementById('issueDetailCategory').className = 'badge bg-primary';
|
||||
|
||||
document.getElementById('issueDetailPriority').textContent = issue.priority.toUpperCase();
|
||||
document.getElementById('issueDetailPriority').className = 'badge ms-2 ' + ({
|
||||
'urgent': 'bg-danger',
|
||||
'high': 'bg-warning',
|
||||
'medium': 'bg-info',
|
||||
'low': 'bg-secondary'
|
||||
}[issue.priority] || 'bg-secondary');
|
||||
|
||||
document.getElementById('issueDetailStatus').textContent = issue.status.replace('_', ' ').toUpperCase();
|
||||
document.getElementById('issueDetailStatus').className = 'badge fs-6 ' + ({
|
||||
'open': 'bg-danger',
|
||||
'in_progress': 'bg-warning',
|
||||
'resolved': 'bg-success',
|
||||
'closed': 'bg-secondary'
|
||||
}[issue.status] || 'bg-secondary');
|
||||
|
||||
// Update context info
|
||||
document.getElementById('issueCurrentPage').textContent = issue.current_page || 'Unknown';
|
||||
document.getElementById('issueBrowserInfo').textContent = issue.browser_info || 'Unknown';
|
||||
document.getElementById('issueIpAddress').textContent = issue.ip_address || 'Unknown';
|
||||
|
||||
// Update sidebar info
|
||||
document.getElementById('issueDetailReporter').textContent = issue.contact_name;
|
||||
document.getElementById('issueDetailEmail').textContent = issue.contact_email;
|
||||
document.getElementById('issueDetailCreated').textContent = new Date(issue.created_at).toLocaleString();
|
||||
document.getElementById('issueDetailUpdated').textContent = issue.updated_at ? new Date(issue.updated_at).toLocaleString() : 'Never';
|
||||
|
||||
if (issue.resolved_at) {
|
||||
document.getElementById('issueDetailResolved').textContent = new Date(issue.resolved_at).toLocaleString();
|
||||
document.getElementById('issueResolvedInfo').style.display = 'block';
|
||||
} else {
|
||||
document.getElementById('issueResolvedInfo').style.display = 'none';
|
||||
}
|
||||
|
||||
// Update form fields for editing
|
||||
document.getElementById('updateStatus').value = issue.status;
|
||||
document.getElementById('updatePriority').value = issue.priority;
|
||||
document.getElementById('updateAssignee').value = issue.assigned_to || '';
|
||||
|
||||
// Store current issue ID for updates
|
||||
window.currentIssueId = issue.id;
|
||||
|
||||
// Load users for assignment dropdown
|
||||
await loadUsersForAssignment();
|
||||
|
||||
// Load and display responses
|
||||
displayIssueResponses(issue.responses);
|
||||
|
||||
// Show modal
|
||||
new bootstrap.Modal(document.getElementById('issueDetailModal')).show();
|
||||
|
||||
} catch (error) {
|
||||
console.error('Failed to load issue details:', error);
|
||||
showAlert('Failed to load issue details', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
async function loadUsersForAssignment() {
|
||||
try {
|
||||
if (allUsers.length === 0) {
|
||||
const response = await fetch('/api/admin/users', {
|
||||
headers: getAuthHeaders()
|
||||
});
|
||||
allUsers = await response.json();
|
||||
}
|
||||
|
||||
const select = document.getElementById('updateAssignee');
|
||||
select.innerHTML = '<option value="">Unassigned</option>';
|
||||
|
||||
allUsers.filter(user => user.is_admin && user.is_active).forEach(user => {
|
||||
select.innerHTML += `<option value="${user.id}">${user.first_name} ${user.last_name} (${user.username})</option>`;
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('Failed to load users for assignment:', error);
|
||||
}
|
||||
}
|
||||
|
||||
function displayIssueResponses(responses) {
|
||||
const container = document.getElementById('issueResponsesList');
|
||||
|
||||
if (responses.length === 0) {
|
||||
container.innerHTML = '<p class="text-muted">No responses yet.</p>';
|
||||
return;
|
||||
}
|
||||
|
||||
container.innerHTML = responses.map(response => {
|
||||
const isInternal = response.is_internal;
|
||||
const badgeClass = isInternal ? 'bg-warning' : 'bg-primary';
|
||||
const badgeText = isInternal ? 'Internal' : 'Public';
|
||||
|
||||
return `
|
||||
<div class="border rounded p-3 mb-3">
|
||||
<div class="d-flex justify-content-between align-items-start mb-2">
|
||||
<div>
|
||||
<strong>${response.author_name}</strong>
|
||||
<span class="badge ${badgeClass} ms-2">${badgeText}</span>
|
||||
</div>
|
||||
<small class="text-muted">${new Date(response.created_at).toLocaleString()}</small>
|
||||
</div>
|
||||
<div style="white-space: pre-wrap;">${response.message}</div>
|
||||
</div>
|
||||
`;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
async function updateIssue() {
|
||||
if (!window.currentIssueId) {
|
||||
showAlert('No issue selected for update', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const updateData = {
|
||||
status: document.getElementById('updateStatus').value,
|
||||
priority: document.getElementById('updatePriority').value,
|
||||
assigned_to: document.getElementById('updateAssignee').value || null
|
||||
};
|
||||
|
||||
const response = await fetch('/api/support/tickets/' + window.currentIssueId, {
|
||||
method: 'PUT',
|
||||
headers: getAuthHeaders(),
|
||||
body: JSON.stringify(updateData)
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to update issue');
|
||||
}
|
||||
|
||||
showAlert('Issue updated successfully', 'success');
|
||||
|
||||
// Refresh the issue details and table
|
||||
await viewIssue(window.currentIssueId);
|
||||
await loadIssues();
|
||||
await loadIssueStats();
|
||||
|
||||
} catch (error) {
|
||||
console.error('Failed to update issue:', error);
|
||||
showAlert('Failed to update issue', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
async function addResponse() {
|
||||
const message = document.getElementById('newResponseMessage').value.trim();
|
||||
const isInternal = document.getElementById('newResponseInternal').checked;
|
||||
|
||||
if (!message) {
|
||||
showAlert('Please enter a response message', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!window.currentIssueId) {
|
||||
showAlert('No issue selected for response', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/support/tickets/' + window.currentIssueId + '/responses', {
|
||||
method: 'POST',
|
||||
headers: getAuthHeaders(),
|
||||
body: JSON.stringify({
|
||||
message: message,
|
||||
is_internal: isInternal
|
||||
})
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to add response');
|
||||
}
|
||||
|
||||
showAlert('Response added successfully', 'success');
|
||||
|
||||
// Clear form
|
||||
document.getElementById('newResponseMessage').value = '';
|
||||
document.getElementById('newResponseInternal').checked = false;
|
||||
|
||||
// Refresh the issue details
|
||||
await viewIssue(window.currentIssueId);
|
||||
|
||||
} catch (error) {
|
||||
console.error('Failed to add response:', error);
|
||||
showAlert('Failed to add response', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
function searchUsers() {
|
||||
const searchTerm = document.getElementById('user-search').value.toLowerCase();
|
||||
const filteredUsers = currentUsers.filter(user =>
|
||||
|
||||
Reference in New Issue
Block a user