Skip to content

Commit

Permalink
misc: add remove mapping button to settings
Browse files Browse the repository at this point in the history
- Added a button to remove the mapping for a media folder if it's unmapped, so it's easier to attempt to remap it without resorting to manual edits of the settings file or fiddling with the browser dev. tools.
  • Loading branch information
revam committed Jun 17, 2024
1 parent e82e623 commit c76413a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Shokofin/Configuration/configController.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ async function loadMediaFolderConfig(form, mediaFolderId, config) {
form.querySelector("#MediaFolderDefaultSettingsContainer").setAttribute("hidden", "");
form.querySelector("#MediaFolderPerFolderSettingsContainer").removeAttribute("hidden");

if (mediaFolderConfig.IsMapped) {
form.querySelector("#MediaFolderDeleteContainer").setAttribute("hidden", "");
}
else {
form.querySelector("#MediaFolderDeleteContainer").removeAttribute("hidden");
}

Dashboard.hideLoadingMsg();
}

Expand Down Expand Up @@ -562,6 +569,23 @@ async function unlinkUser(form) {
return config;
}

async function removeMediaFolder(form) {
const config = await ApiClient.getPluginConfiguration(PluginConfig.pluginId);
const mediaFolderId = form.querySelector("#MediaFolderSelector").value;
if (!mediaFolderId) return;

const index = config.MediaFolders.findIndex((m) => m.MediaFolderId === mediaFolderId);
if (index !== -1) {
config.MediaFolders.splice(index, 1);
}

const result = await ApiClient.updatePluginConfiguration(PluginConfig.pluginId, config)
form.querySelector("#MediaFolderSelector").value = "";

Dashboard.processPluginConfigurationUpdateResult(result);
return config;
}

async function syncMediaFolderSettings(form) {
const config = await ApiClient.getPluginConfiguration(PluginConfig.pluginId);
const mediaFolderId = form.querySelector("#MediaFolderSelector").value;
Expand Down Expand Up @@ -1044,6 +1068,9 @@ export default function (page) {
.then(refreshSignalr)
.catch(onError);
break;
case "remove-media-folder":
removeMediaFolder(form).then(refreshSettings).catch(onError);
break;
case "unlink-user":
unlinkUser(form).then(refreshSettings).catch(onError);
break;
Expand Down
6 changes: 6 additions & 0 deletions Shokofin/Configuration/configPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -1333,6 +1333,12 @@ <h3>Media Folder Settings</h3>
</div>
</div>
</div>
<div id="MediaFolderDeleteContainer" class="inputContainer inputContainer-withDescription" hidden>
<button is="emby-button" type="submit" name="remove-media-folder" class="raised button-delete block emby-button">
<span>Delete</span>
</button>
<div class="fieldDescription">This will delete the saved settings and reset the mapping for the media folder.</div>
</div>
<button is="emby-button" type="submit" name="media-folder-settings" class="raised button-submit block emby-button">
<span>Save</span>
</button>
Expand Down

0 comments on commit c76413a

Please sign in to comment.