Add renaming of profiles + use alphabetical sorting

This commit is contained in:
Cohee
2024-09-23 20:19:18 +03:00
parent 5b4d524bc0
commit 583cc4b097
2 changed files with 27 additions and 1 deletions

View File

@ -335,7 +335,7 @@ function renderConnectionProfiles(profiles) {
noneOption.selected = !extension_settings.connectionManager.selectedProfile;
profiles.appendChild(noneOption);
for (const profile of extension_settings.connectionManager.profiles) {
for (const profile of extension_settings.connectionManager.profiles.sort((a, b) => a.name.localeCompare(b.name))) {
const option = document.createElement('option');
option.value = profile.id;
option.textContent = profile.name;
@ -472,6 +472,31 @@ async function renderDetailsContent(detailsContent) {
await eventSource.emit(event_types.CONNECTION_PROFILE_LOADED, NONE);
});
const renameButton = document.getElementById('rename_connection_profile');
renameButton.addEventListener('click', async () => {
const selectedProfile = extension_settings.connectionManager.selectedProfile;
const profile = extension_settings.connectionManager.profiles.find(p => p.id === selectedProfile);
if (!profile) {
console.log('No profile selected');
return;
}
const newName = await Popup.show.input('Enter a new name', null, profile.name, { rows: 2 });
if (!newName) {
return;
}
if (extension_settings.connectionManager.profiles.some(p => p.name === newName)) {
toastr.error('A profile with the same name already exists.');
return;
}
profile.name = newName;
saveSettingsDebounced();
renderConnectionProfiles(profiles);
toastr.success('Connection profile renamed', '', { timeOut: 1500 });
});
/** @type {HTMLElement} */
const viewDetails = document.getElementById('view_connection_profile');
const detailsContent = document.getElementById('connection_profile_details_content');