version v3
This commit is contained in:
@@ -706,12 +706,20 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
const headerButtons = document.querySelector('.header-buttons');
|
||||
if (headerButtons) {
|
||||
const refreshButton = document.createElement('button');
|
||||
refreshButton.className = 'btn btn-outline-primary';
|
||||
refreshButton.innerHTML = '<i class="fas fa-sync-alt"></i> Refresh';
|
||||
refreshButton.className = 'btn btn-outline-primary me-2';
|
||||
refreshButton.innerHTML = '<i class="fas fa-sync-alt"></i> Refresh All';
|
||||
refreshButton.onclick = function() {
|
||||
fetchCompanyNames();
|
||||
};
|
||||
headerButtons.appendChild(refreshButton);
|
||||
|
||||
const versionRefreshButton = document.createElement('button');
|
||||
versionRefreshButton.className = 'btn btn-outline-info';
|
||||
versionRefreshButton.innerHTML = '<i class="fas fa-code-branch"></i> Refresh Versions';
|
||||
versionRefreshButton.onclick = function() {
|
||||
refreshAllVersionInfo();
|
||||
};
|
||||
headerButtons.appendChild(versionRefreshButton);
|
||||
}
|
||||
|
||||
// Wait a short moment to ensure the table is rendered
|
||||
@@ -768,12 +776,25 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
updateColorPreview();
|
||||
});
|
||||
|
||||
// Function to check status of all instances
|
||||
// Function to check all instance statuses
|
||||
async function checkAllInstanceStatuses() {
|
||||
const statusBadges = document.querySelectorAll('[data-instance-id]');
|
||||
for (const badge of statusBadges) {
|
||||
console.log('Checking all instance statuses...');
|
||||
const instances = document.querySelectorAll('[data-instance-id]');
|
||||
|
||||
for (const badge of instances) {
|
||||
const instanceId = badge.dataset.instanceId;
|
||||
await checkInstanceStatus(instanceId);
|
||||
|
||||
// Also refresh version info when checking status
|
||||
const instanceUrl = badge.closest('tr').querySelector('td:nth-child(7) a')?.href;
|
||||
const apiKey = badge.dataset.token;
|
||||
|
||||
if (instanceUrl && apiKey) {
|
||||
// Fetch version info in the background (don't await to avoid blocking status checks)
|
||||
fetchVersionInfo(instanceUrl, instanceId).catch(error => {
|
||||
console.error(`Error fetching version info for instance ${instanceId}:`, error);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -890,6 +911,115 @@ async function fetchInstanceStats(instanceUrl, instanceId, jwtToken) {
|
||||
}
|
||||
}
|
||||
|
||||
// Function to fetch version information for an instance
|
||||
async function fetchVersionInfo(instanceUrl, instanceId) {
|
||||
const row = document.querySelector(`[data-instance-id="${instanceId}"]`).closest('tr');
|
||||
const versionCell = row.querySelector('td:nth-child(9)'); // Version column
|
||||
const branchCell = row.querySelector('td:nth-child(10)'); // Branch column
|
||||
|
||||
// Show loading state
|
||||
if (versionCell) {
|
||||
versionCell.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Loading...';
|
||||
}
|
||||
if (branchCell) {
|
||||
branchCell.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Loading...';
|
||||
}
|
||||
|
||||
try {
|
||||
const apiKey = document.querySelector(`[data-instance-id="${instanceId}"]`).dataset.token;
|
||||
if (!apiKey) {
|
||||
throw new Error('No API key available');
|
||||
}
|
||||
|
||||
console.log(`Getting JWT token for instance ${instanceId} for version info`);
|
||||
const jwtToken = await getJWTToken(instanceUrl, apiKey);
|
||||
console.log('Got JWT token for version info');
|
||||
|
||||
// Fetch version information
|
||||
console.log(`Fetching version info for instance ${instanceId} from ${instanceUrl}/api/admin/version-info`);
|
||||
const response = await fetch(`${instanceUrl}/api/admin/version-info`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Authorization': `Bearer ${jwtToken}`
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
console.error(`HTTP error ${response.status}:`, errorText);
|
||||
throw new Error(`Server returned ${response.status}: ${errorText}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
console.log('Received version data:', data);
|
||||
|
||||
// Update version cell
|
||||
if (versionCell) {
|
||||
const appVersion = data.app_version || 'unknown';
|
||||
const gitCommit = data.git_commit || 'unknown';
|
||||
const deployedAt = data.deployed_at || 'unknown';
|
||||
|
||||
if (appVersion !== 'unknown') {
|
||||
versionCell.innerHTML = `
|
||||
<span class="badge bg-info version-badge" data-bs-toggle="tooltip"
|
||||
title="App Version: ${appVersion}<br>Git Commit: ${gitCommit}<br>Deployed: ${deployedAt}">
|
||||
${appVersion.length > 8 ? appVersion.substring(0, 8) : appVersion}
|
||||
</span>`;
|
||||
} else {
|
||||
versionCell.innerHTML = '<span class="badge bg-secondary version-badge">unknown</span>';
|
||||
}
|
||||
}
|
||||
|
||||
// Update branch cell
|
||||
if (branchCell) {
|
||||
const gitBranch = data.git_branch || 'unknown';
|
||||
|
||||
if (gitBranch !== 'unknown') {
|
||||
branchCell.innerHTML = `
|
||||
<span class="badge bg-light text-dark branch-badge" data-bs-toggle="tooltip"
|
||||
title="Deployed branch: ${gitBranch}">
|
||||
${gitBranch}
|
||||
</span>`;
|
||||
} else {
|
||||
branchCell.innerHTML = '<span class="badge bg-secondary branch-badge">unknown</span>';
|
||||
}
|
||||
}
|
||||
|
||||
// Update tooltips
|
||||
const versionBadge = versionCell?.querySelector('[data-bs-toggle="tooltip"]');
|
||||
const branchBadge = branchCell?.querySelector('[data-bs-toggle="tooltip"]');
|
||||
|
||||
if (versionBadge) {
|
||||
new bootstrap.Tooltip(versionBadge);
|
||||
}
|
||||
if (branchBadge) {
|
||||
new bootstrap.Tooltip(branchBadge);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error(`Error fetching version info for instance ${instanceId}:`, error);
|
||||
|
||||
// Show error state
|
||||
if (versionCell) {
|
||||
versionCell.innerHTML = `
|
||||
<span class="text-warning" data-bs-toggle="tooltip" title="Error: ${error.message}">
|
||||
<i class="fas fa-exclamation-triangle"></i> Error
|
||||
</span>`;
|
||||
}
|
||||
if (branchCell) {
|
||||
branchCell.innerHTML = `
|
||||
<span class="text-warning" data-bs-toggle="tooltip" title="Error: ${error.message}">
|
||||
<i class="fas fa-exclamation-triangle"></i> Error
|
||||
</span>`;
|
||||
}
|
||||
|
||||
// Add tooltips for error states
|
||||
const errorBadges = [versionCell, branchCell].map(cell => cell?.querySelector('[data-bs-toggle="tooltip"]')).filter(Boolean);
|
||||
errorBadges.forEach(badge => new bootstrap.Tooltip(badge));
|
||||
}
|
||||
}
|
||||
|
||||
// Function to fetch company name from instance settings
|
||||
async function fetchCompanyName(instanceUrl, instanceId) {
|
||||
const row = document.querySelector(`[data-instance-id="${instanceId}"]`).closest('tr');
|
||||
@@ -977,53 +1107,31 @@ async function fetchCompanyName(instanceUrl, instanceId) {
|
||||
|
||||
// Function to fetch company names for all instances
|
||||
async function fetchCompanyNames() {
|
||||
console.log('Starting fetchCompanyNames...');
|
||||
|
||||
const instances = document.querySelectorAll('[data-instance-id]');
|
||||
const loadingPromises = [];
|
||||
|
||||
console.log('Starting to fetch company names and stats for all instances');
|
||||
|
||||
for (const instance of instances) {
|
||||
const instanceId = instance.dataset.instanceId;
|
||||
const row = instance.closest('tr');
|
||||
for (const badge of instances) {
|
||||
const instanceId = badge.dataset.instanceId;
|
||||
const instanceUrl = badge.closest('tr').querySelector('td:nth-child(7) a')?.href;
|
||||
const apiKey = badge.dataset.token;
|
||||
|
||||
// Debug: Log all cells in the row
|
||||
console.log(`Row for instance ${instanceId}:`, {
|
||||
cells: Array.from(row.querySelectorAll('td')).map(td => ({
|
||||
text: td.textContent.trim(),
|
||||
html: td.innerHTML.trim()
|
||||
}))
|
||||
});
|
||||
|
||||
// Main URL is now the 9th column (after adding Version and Branch columns)
|
||||
const urlCell = row.querySelector('td:nth-child(9)');
|
||||
|
||||
if (!urlCell) {
|
||||
console.error(`Could not find URL cell for instance ${instanceId}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const urlLink = urlCell.querySelector('a');
|
||||
if (!urlLink) {
|
||||
console.error(`Could not find URL link for instance ${instanceId}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const instanceUrl = urlLink.getAttribute('href');
|
||||
const token = instance.dataset.token;
|
||||
|
||||
console.log(`Instance ${instanceId}:`, {
|
||||
url: instanceUrl,
|
||||
hasToken: !!token
|
||||
});
|
||||
|
||||
if (instanceUrl && token) {
|
||||
loadingPromises.push(fetchCompanyName(instanceUrl, instanceId));
|
||||
if (instanceUrl && apiKey) {
|
||||
console.log(`Fetching data for instance ${instanceId}`);
|
||||
loadingPromises.push(
|
||||
fetchCompanyName(instanceUrl, instanceId),
|
||||
fetchVersionInfo(instanceUrl, instanceId) // Add version info fetching
|
||||
);
|
||||
} else {
|
||||
const row = badge.closest('tr');
|
||||
const cells = [
|
||||
row.querySelector('td:nth-child(2)'), // Company
|
||||
row.querySelector('td:nth-child(3)'), // Rooms
|
||||
row.querySelector('td:nth-child(4)'), // Conversations
|
||||
row.querySelector('td:nth-child(5)') // Data
|
||||
row.querySelector('td:nth-child(5)'), // Data
|
||||
row.querySelector('td:nth-child(9)'), // Version
|
||||
row.querySelector('td:nth-child(10)') // Branch
|
||||
];
|
||||
|
||||
cells.forEach(cell => {
|
||||
@@ -1043,7 +1151,7 @@ async function fetchCompanyNames() {
|
||||
|
||||
try {
|
||||
await Promise.all(loadingPromises);
|
||||
console.log('Finished fetching all company names and stats');
|
||||
console.log('Finished fetching all company names, stats, and version info');
|
||||
} catch (error) {
|
||||
console.error('Error in fetchCompanyNames:', error);
|
||||
}
|
||||
@@ -1886,5 +1994,30 @@ function launchInstance() {
|
||||
// Redirect to the launch progress page
|
||||
window.location.href = '/instances/launch-progress';
|
||||
}
|
||||
|
||||
// Function to refresh all version information
|
||||
async function refreshAllVersionInfo() {
|
||||
console.log('Refreshing all version information...');
|
||||
const instances = document.querySelectorAll('[data-instance-id]');
|
||||
const loadingPromises = [];
|
||||
|
||||
for (const badge of instances) {
|
||||
const instanceId = badge.dataset.instanceId;
|
||||
const instanceUrl = badge.closest('tr').querySelector('td:nth-child(7) a')?.href;
|
||||
const apiKey = badge.dataset.token;
|
||||
|
||||
if (instanceUrl && apiKey) {
|
||||
console.log(`Refreshing version info for instance ${instanceId}`);
|
||||
loadingPromises.push(fetchVersionInfo(instanceUrl, instanceId));
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
await Promise.all(loadingPromises);
|
||||
console.log('Finished refreshing all version information');
|
||||
} catch (error) {
|
||||
console.error('Error refreshing version information:', error);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user