Fix seconds handling in sidebar

This commit is contained in:
Joshua Boniface 2025-03-02 11:01:24 -05:00
parent 94d0ed544f
commit ef3e013f2d
4 changed files with 47 additions and 13 deletions

View File

@ -27,7 +27,7 @@
<!-- Refresh interval display with tooltip --> <!-- Refresh interval display with tooltip -->
<div class="refresh-display text-white-50 mb-3 text-center" data-title="Refresh Time"> <div class="refresh-display text-white-50 mb-3 text-center" data-title="Refresh Time">
<i class="fas fa-sync-alt"></i> <i class="fas fa-sync-alt"></i>
<span class="refresh-text ms-2">{{ api.config.updateInterval / 1000 }}s</span> <span class="refresh-text ms-2">{{ api.config.updateInterval }}s</span>
</div> </div>
<!-- Collapse/Expand button with tooltip --> <!-- Collapse/Expand button with tooltip -->
@ -218,10 +218,22 @@ const updateDashboard = async () => {
} }
try { try {
console.log(`${new Date().toISOString()} Starting API calls`);
// Ensure all endpoints are called together in a single Promise.all
const [status, nodes, vms] = await Promise.all([ const [status, nodes, vms] = await Promise.all([
api.fetchStatus(), api.fetchStatus().then(res => {
api.fetchNodes(), console.log(`${new Date().toISOString()} Status API call complete`);
api.fetchVMs() return res;
}),
api.fetchNodes().then(res => {
console.log(`${new Date().toISOString()} Nodes API call complete`);
return res;
}),
api.fetchVMs().then(res => {
console.log(`${new Date().toISOString()} VMs API call complete`);
return res;
})
]); ]);
console.log('[API] Status Response:', status); console.log('[API] Status Response:', status);
@ -250,7 +262,8 @@ const restartDashboard = () => {
clearInterval(updateTimer); clearInterval(updateTimer);
} }
updateDashboard(); updateDashboard();
updateTimer = setInterval(updateDashboard, api.config.updateInterval); const intervalMs = api.config.updateInterval * 1000;
updateTimer = setInterval(updateDashboard, intervalMs);
}; };
onMounted(() => { onMounted(() => {

View File

@ -42,9 +42,13 @@
class="form-control" class="form-control"
id="updateInterval" id="updateInterval"
v-model.number="formData.updateInterval" v-model.number="formData.updateInterval"
min="1" min="5"
max="3600" max="300"
required
> >
<div class="form-text">
Enter value in seconds (5-300, default: 15)
</div>
</div> </div>
<div class="d-grid gap-2"> <div class="d-grid gap-2">
@ -73,14 +77,20 @@ const props = defineProps({
const emit = defineEmits(['update:modelValue', 'save']); const emit = defineEmits(['update:modelValue', 'save']);
// Initialize form data with raw values from config
const formData = ref({ const formData = ref({
apiUri: props.config.apiUri || '', apiUri: props.config.apiUri || '',
apiKey: props.config.apiKey || '', apiKey: props.config.apiKey || '',
updateInterval: props.config.updateInterval / 1000 updateInterval: props.config.updateInterval || 15 // Default to 15 seconds
}); });
const saveConfig = () => { const saveConfig = () => {
emit('save', { ...formData.value }); // Pass the raw values to parent
emit('save', {
apiUri: formData.value.apiUri,
apiKey: formData.value.apiKey,
updateInterval: formData.value.updateInterval // Pass seconds directly
});
}; };
const closePanel = () => { const closePanel = () => {

View File

@ -6,7 +6,7 @@ export const useApiStore = defineStore('api', () => {
const config = ref({ const config = ref({
apiUri: localStorage.getItem('pvc_api_uri') || '', apiUri: localStorage.getItem('pvc_api_uri') || '',
apiKey: localStorage.getItem('pvc_api_key') || '', apiKey: localStorage.getItem('pvc_api_key') || '',
updateInterval: parseInt(localStorage.getItem('pvc_update_interval')) || 5000 updateInterval: parseInt(localStorage.getItem('pvc_update_interval')) || 15 // Default to 15s
}); });
// Computed // Computed
@ -16,12 +16,18 @@ export const useApiStore = defineStore('api', () => {
// Actions // Actions
const updateConfig = (newConfig) => { const updateConfig = (newConfig) => {
config.value = { ...newConfig }; // Ensure interval is between 5 and 300 seconds
const interval = Math.min(300, Math.max(5, parseInt(newConfig.updateInterval) || 15));
config.value = {
...newConfig,
updateInterval: interval
};
// Save to localStorage // Save to localStorage
localStorage.setItem('pvc_api_uri', newConfig.apiUri); localStorage.setItem('pvc_api_uri', newConfig.apiUri);
localStorage.setItem('pvc_api_key', newConfig.apiKey); localStorage.setItem('pvc_api_key', newConfig.apiKey);
localStorage.setItem('pvc_update_interval', newConfig.updateInterval.toString()); localStorage.setItem('pvc_update_interval', interval.toString());
}; };
const fetchStatus = async () => { const fetchStatus = async () => {

View File

@ -1,6 +1,11 @@
import { defineConfig } from 'vite'; import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue'; import vue from '@vitejs/plugin-vue';
function getTimestamp() {
const now = new Date();
return now.toISOString().replace('T', ' ').replace('Z', '');
}
export default defineConfig({ export default defineConfig({
plugins: [vue()], plugins: [vue()],
server: { server: {
@ -21,7 +26,7 @@ export default defineConfig({
const requestPath = req.url.replace('/api', ''); const requestPath = req.url.replace('/api', '');
proxyReq.path = `${apiPath}${requestPath}`; proxyReq.path = `${apiPath}${requestPath}`;
console.log(`Proxying to: ${options.target}${proxyReq.path}`); console.log(`${getTimestamp()} Proxying to: ${options.target}${proxyReq.path}`);
} }
if (req.headers['x-api-key']) { if (req.headers['x-api-key']) {