Create libraries based on external unmanaged directories (#147)

* Library management is now complete

* Library functions complete

* Added default platform support
This commit is contained in:
Michael Green
2023-10-08 18:19:59 -07:00
committed by GitHub
parent fc09db60ab
commit 1934558595
19 changed files with 709 additions and 158 deletions

View File

@@ -0,0 +1,27 @@
<p>Are you sure you want to delete this library?</p>
<p><strong>Warning:</strong> This cannot be undone!</p>
<div style="width: 100%; text-align: center;">
<div style="display: inline-block; margin-right: 20px;">
<button class="redbutton" value="Delete" onclick="deleteLibrary();">Delete</button>
</div>
<div style="display: inline-block; margin-left: 20px;">
<button value="Cancel" onclick="closeSubDialog();">Cancel</button>
</div>
</div>
<script type="text/javascript">
function deleteLibrary() {
ajaxCall(
'/api/v1/Library/' + subModalVariables,
'DELETE',
function (result) {
drawLibrary();
closeSubDialog();
},
function (error) {
drawLibrary();
closeSubDialog();
}
);
}
</script>

View File

@@ -0,0 +1,91 @@
<div style="padding-top: 5px;">
<strong>New Library</strong>
</div>
<div style="width: 300px;">
<table style="width: 98%; margin-top: 15px; margin-bottom: 15px;">
<tr>
<th>Name</th>
<td><input type="text" id="newlibrary_name" style="width: 95%;" /></td>
</tr>
<tr>
<th>Default Platform</th>
<td><select id="newlibrary_defaultplatform" style="width: 100%;"></select></td>
</tr>
<tr>
<th>Path</th>
<td><input type="text" id="newlibrary_path" style="width: 95%;" /></td>
</tr>
</table>
<div style="width: 100%; text-align: right;">
<div style="display: inline-block; margin-right: 20px;">
<button value="OK" onclick="newLibrary();">OK</button>
</div>
<div style="display: inline-block;">
<button value="Cancel" onclick="closeSubDialog();">Cancel</button>
</div>
</div>
</div>
<script type="text/javascript">
$('#newlibrary_defaultplatform').select2({
minimumInputLength: 3,
ajax: {
url: '/api/v1/Search/Platform',
data: function (params) {
var query = {
SearchString: params.term
}
// Query parameters will be ?SearchString=[term]
return query;
},
processResults: function (data) {
var arr = [];
arr.push({
id: 0,
text: 'Any'
});
for (var i = 0; i < data.length; i++) {
arr.push({
id: data[i].id,
text: data[i].name
});
}
return {
results: arr
};
}
}
});
document.getElementById('newlibrary_defaultplatform').innerHTML = "<option value='" + 0 + "' selected='selected'>Any</option>";
function newLibrary() {
var libName = document.getElementById('newlibrary_name').value;
var libPlatform = $('#newlibrary_defaultplatform').select2('data');
var libPath = document.getElementById('newlibrary_path').value;
if (libName.length == 0) {
alert("A library name must be provided.")
} else if (libPath.length == 0) {
alert("A path must be provided.");
} else {
ajaxCall(
'/api/v1/Library?Name=' + encodeURIComponent(libName) + '&DefaultPlatformId=' + libPlatform[0].id + '&Path=' + encodeURIComponent(libPath),
'POST',
function(result) {
drawLibrary();
closeSubDialog();
},
function(error) {
alert('An error occurred while creating the library:\n\n' + JSON.stringify(error.responseText));
}
);
}
}
</script>

View File

@@ -7,6 +7,10 @@
<div id="properties_bodypanel">
<div id="properties_bodypanel_general" name="properties_tab" style="display: none;">
<table cellspacing="0" style="width: 100%;">
<tr>
<th>Library</th>
<td id="rominfo_library"></td>
</tr>
<tr>
<th>Platform</th>
<td id="rominfo_platform"></td>
@@ -117,6 +121,7 @@
ajaxCall('/api/v1/Games/' + gameId + '/roms/' + modalVariables, 'GET', function (result) {
romData = result;
document.getElementById('modal-heading').innerHTML = result.name;
document.getElementById('rominfo_library').innerHTML = result.library.name;
document.getElementById('rominfo_platform').innerHTML = result.platform.name;
document.getElementById('rominfo_size').innerHTML = formatBytes(result.size, 2);
document.getElementById('rominfo_type').innerHTML = getRomType(result.romType);
@@ -130,6 +135,10 @@
document.getElementById('properties_fixplatform').innerHTML = "<option value='" + result.platform.id + "' selected='selected'>" + result.platform.name + "</option>";
document.getElementById('properties_fixgame').innerHTML = "<option value='" + gameData.id + "' selected='selected'>" + gameData.name + "</option>";
if (result.library.isDefaultLibrary == false) {
document.getElementById('romDelete').style.display = 'none';
}
if (result.attributes.length > 0) {
document.getElementById('properties_bodypanel_attributes').appendChild(BuildAttributesTable(result.attributes, result.source));
} else {