Add profile deletion feature
- Added DELETE endpoint /api/profiles/<profile_name> to delete profiles - Prevent deletion of the only remaining profile - Clear current profile state if the active profile is deleted - Added Delete button next to each profile in the Profiles modal - Added confirmation dialog before deleting profiles - Automatically refresh profile list after deletion
This commit is contained in:
@@ -668,14 +668,25 @@ class LightingController {
|
||||
profileLabel.style.fontWeight = 'bold';
|
||||
profileLabel.style.color = '#FFD700';
|
||||
}
|
||||
|
||||
const actionsContainer = document.createElement('div');
|
||||
actionsContainer.style.cssText = 'display: flex; gap: 0.5rem;';
|
||||
|
||||
const loadButton = document.createElement('button');
|
||||
loadButton.className = 'btn btn-small';
|
||||
loadButton.textContent = 'Load';
|
||||
loadButton.addEventListener('click', () => this.loadProfile(profileName));
|
||||
|
||||
const deleteButton = document.createElement('button');
|
||||
deleteButton.className = 'btn btn-small btn-danger';
|
||||
deleteButton.textContent = 'Delete';
|
||||
deleteButton.addEventListener('click', () => this.deleteProfile(profileName));
|
||||
|
||||
actionsContainer.appendChild(loadButton);
|
||||
actionsContainer.appendChild(deleteButton);
|
||||
|
||||
profileItem.appendChild(profileLabel);
|
||||
profileItem.appendChild(loadButton);
|
||||
profileItem.appendChild(actionsContainer);
|
||||
profilesList.appendChild(profileItem);
|
||||
});
|
||||
}
|
||||
@@ -685,6 +696,37 @@ class LightingController {
|
||||
}
|
||||
}
|
||||
|
||||
async deleteProfile(profileName) {
|
||||
if (!confirm(`Delete profile '${profileName}'? This cannot be undone.`)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/profiles/${profileName}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
await this.loadProfiles();
|
||||
// If the current profile was deleted, clear current state tabs
|
||||
if (this.state.current_profile === profileName) {
|
||||
this.state.current_profile = '';
|
||||
this.state.lights = {};
|
||||
this.state.tab_order = [];
|
||||
this.renderTabs();
|
||||
document.getElementById('tab-content').innerHTML = '<p>No tabs available. Create a new tab to get started.</p>';
|
||||
this.updateCurrentProfileDisplay();
|
||||
}
|
||||
} else {
|
||||
const error = await response.json();
|
||||
alert(error.error || 'Failed to delete profile');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to delete profile:', error);
|
||||
alert('Failed to delete profile');
|
||||
}
|
||||
}
|
||||
|
||||
async loadProfile(profileName) {
|
||||
try {
|
||||
const response = await fetch(`/api/profiles/${profileName}`, {
|
||||
|
||||
Reference in New Issue
Block a user