Add renaming of profiles + use alphabetical sorting
| @@ -335,7 +335,7 @@ function renderConnectionProfiles(profiles) { | |||
| 335 | noneOption.selected = !extension_settings.connectionManager.selectedProfile; | 335 | noneOption.selected = !extension_settings.connectionManager.selectedProfile; |
| 336 | profiles.appendChild(noneOption); | 336 | profiles.appendChild(noneOption); |
| 337 | 337 | ||
| 338 | for (const profile of extension_settings.connectionManager.profiles) { | 338 | for (const profile of extension_settings.connectionManager.profiles.sort((a, b) => a.name.localeCompare(b.name))) { |
| 339 | const option = document.createElement('option'); | 339 | const option = document.createElement('option'); |
| 340 | option.value = profile.id; | 340 | option.value = profile.id; |
| 341 | option.textContent = profile.name; | 341 | option.textContent = profile.name; |
| @@ -472,6 +472,31 @@ async function renderDetailsContent(detailsContent) { | |||
| 472 | await eventSource.emit(event_types.CONNECTION_PROFILE_LOADED, NONE); | 472 | await eventSource.emit(event_types.CONNECTION_PROFILE_LOADED, NONE); |
| 473 | }); | 473 | }); |
| 474 | 474 | ||
| 475 | const renameButton = document.getElementById('rename_connection_profile'); | ||
| 476 | renameButton.addEventListener('click', async () => { | ||
| 477 | const selectedProfile = extension_settings.connectionManager.selectedProfile; | ||
| 478 | const profile = extension_settings.connectionManager.profiles.find(p => p.id === selectedProfile); | ||
| 479 | if (!profile) { | ||
| 480 | console.log('No profile selected'); | ||
| 481 | return; | ||
| 482 | } | ||
| 483 | |||
| 484 | const newName = await Popup.show.input('Enter a new name', null, profile.name, { rows: 2 }); | ||
| 485 | if (!newName) { | ||
| 486 | return; | ||
| 487 | } | ||
| 488 | |||
| 489 | if (extension_settings.connectionManager.profiles.some(p => p.name === newName)) { | ||
| 490 | toastr.error('A profile with the same name already exists.'); | ||
| 491 | return; | ||
| 492 | } | ||
| 493 | |||
| 494 | profile.name = newName; | ||
| 495 | saveSettingsDebounced(); | ||
| 496 | renderConnectionProfiles(profiles); | ||
| 497 | toastr.success('Connection profile renamed', '', { timeOut: 1500 }); | ||
| 498 | }); | ||
| 499 | |||
| 475 | /** @type {HTMLElement} */ | 500 | /** @type {HTMLElement} */ |
| 476 | const viewDetails = document.getElementById('view_connection_profile'); | 501 | const viewDetails = document.getElementById('view_connection_profile'); |
| 477 | const detailsContent = document.getElementById('connection_profile_details_content'); | 502 | const detailsContent = document.getElementById('connection_profile_details_content'); |
| @@ -13,6 +13,7 @@ | |||
| 13 | <i id="view_connection_profile" class="menu_button fa-solid fa-info-circle" title="View connection profile details" data-i18n="[title]View connection profile details"></i> | 13 | <i id="view_connection_profile" class="menu_button fa-solid fa-info-circle" title="View connection profile details" data-i18n="[title]View connection profile details"></i> |
| 14 | <i id="create_connection_profile" class="menu_button fa-solid fa-file-circle-plus" title="Create a new connection profile" data-i18n="[title]Create a new connection profile"></i> | 14 | <i id="create_connection_profile" class="menu_button fa-solid fa-file-circle-plus" title="Create a new connection profile" data-i18n="[title]Create a new connection profile"></i> |
| 15 | <i id="update_connection_profile" class="menu_button fa-solid fa-save" title="Update a connection profile" data-i18n="[title]Update a connection profile"></i> | 15 | <i id="update_connection_profile" class="menu_button fa-solid fa-save" title="Update a connection profile" data-i18n="[title]Update a connection profile"></i> |
| 16 | <i id="rename_connection_profile" class="menu_button fa-solid fa-pencil" title="Rename a connection profile" data-i18n="[title]Rename a connection profile"></i> | ||
| 16 | <i id="reload_connection_profile" class="menu_button fa-solid fa-recycle" title="Reload a connection profile" data-i18n="[title]Reload a connection profile"></i> | 17 | <i id="reload_connection_profile" class="menu_button fa-solid fa-recycle" title="Reload a connection profile" data-i18n="[title]Reload a connection profile"></i> |
| 17 | <i id="delete_connection_profile" class="menu_button fa-solid fa-trash-can" title="Delete a connection profile" data-i18n="[title]Delete a connection profile"></i> | 18 | <i id="delete_connection_profile" class="menu_button fa-solid fa-trash-can" title="Delete a connection profile" data-i18n="[title]Delete a connection profile"></i> |
| 18 | </div> | 19 | </div> |