first refactoring step
This commit is contained in:
@ -3,6 +3,8 @@
|
||||
* Handles VNA data acquisition control via REST API
|
||||
*/
|
||||
|
||||
import { setButtonLoading } from './utils.js';
|
||||
|
||||
export class AcquisitionManager {
|
||||
constructor(notifications) {
|
||||
this.notifications = notifications;
|
||||
@ -51,7 +53,7 @@ export class AcquisitionManager {
|
||||
|
||||
async handleStartClick() {
|
||||
try {
|
||||
this.setButtonLoading(this.elements.startBtn, true);
|
||||
const originalState = setButtonLoading(this.elements.startBtn, true);
|
||||
|
||||
const response = await fetch('/api/v1/acquisition/start', {
|
||||
method: 'POST',
|
||||
@ -70,13 +72,13 @@ export class AcquisitionManager {
|
||||
console.error('Error starting acquisition:', error);
|
||||
this.notifications.show({type: 'error', message: 'Failed to start acquisition'});
|
||||
} finally {
|
||||
this.setButtonLoading(this.elements.startBtn, false);
|
||||
setButtonLoading(this.elements.startBtn, false, originalState);
|
||||
}
|
||||
}
|
||||
|
||||
async handleStopClick() {
|
||||
try {
|
||||
this.setButtonLoading(this.elements.stopBtn, true);
|
||||
const originalState = setButtonLoading(this.elements.stopBtn, true);
|
||||
|
||||
const response = await fetch('/api/v1/acquisition/stop', {
|
||||
method: 'POST',
|
||||
@ -95,13 +97,13 @@ export class AcquisitionManager {
|
||||
console.error('Error stopping acquisition:', error);
|
||||
this.notifications.show({type: 'error', message: 'Failed to stop acquisition'});
|
||||
} finally {
|
||||
this.setButtonLoading(this.elements.stopBtn, false);
|
||||
setButtonLoading(this.elements.stopBtn, false, originalState);
|
||||
}
|
||||
}
|
||||
|
||||
async handleSingleSweepClick() {
|
||||
try {
|
||||
this.setButtonLoading(this.elements.singleSweepBtn, true);
|
||||
const originalState = setButtonLoading(this.elements.singleSweepBtn, true);
|
||||
|
||||
const response = await fetch('/api/v1/acquisition/single-sweep', {
|
||||
method: 'POST',
|
||||
@ -120,7 +122,7 @@ export class AcquisitionManager {
|
||||
console.error('Error triggering single sweep:', error);
|
||||
this.notifications.show({type: 'error', message: 'Failed to trigger single sweep'});
|
||||
} finally {
|
||||
this.setButtonLoading(this.elements.singleSweepBtn, false);
|
||||
setButtonLoading(this.elements.singleSweepBtn, false, originalState);
|
||||
}
|
||||
}
|
||||
|
||||
@ -190,45 +192,6 @@ export class AcquisitionManager {
|
||||
}
|
||||
}
|
||||
|
||||
setButtonLoading(button, loading) {
|
||||
if (!button) return;
|
||||
|
||||
if (loading) {
|
||||
button.disabled = true;
|
||||
button.classList.add('loading');
|
||||
const icon = button.querySelector('i');
|
||||
if (icon) {
|
||||
icon.setAttribute('data-lucide', 'loader-2');
|
||||
icon.style.animation = 'spin 1s linear infinite';
|
||||
// Re-initialize lucide for the changed icon
|
||||
if (window.lucide) {
|
||||
window.lucide.createIcons();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
button.disabled = false;
|
||||
button.classList.remove('loading');
|
||||
const icon = button.querySelector('i');
|
||||
if (icon) {
|
||||
icon.style.animation = '';
|
||||
// Restore original icon
|
||||
const buttonId = button.id;
|
||||
const originalIcons = {
|
||||
'startBtn': 'play',
|
||||
'stopBtn': 'square',
|
||||
'singleSweepBtn': 'zap'
|
||||
};
|
||||
const originalIcon = originalIcons[buttonId];
|
||||
if (originalIcon) {
|
||||
icon.setAttribute('data-lucide', originalIcon);
|
||||
if (window.lucide) {
|
||||
window.lucide.createIcons();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Public method to trigger single sweep programmatically
|
||||
async triggerSingleSweep() {
|
||||
return await this.handleSingleSweepClick();
|
||||
|
||||
Reference in New Issue
Block a user