mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 06:11:10 +00:00
Adds media libraries management view
This commit is contained in:
1 parent
b593cbce93
commit
d7c8478101
162 files changed
+3741
-171
No files matched your search
@@ -1 +1,75 @@
|
||||
@await Component.InvokeAsync("FileSystemBrowser")
|
||||
@*
|
||||
/
|
||||
*@
|
||||
|
||||
@using Lumina.Presentation.Web.Common.Models.Libraries
|
||||
@using Lumina.Presentation.Web.Common.Services
|
||||
@using Microsoft.AspNetCore.Mvc.Localization
|
||||
|
||||
@{
|
||||
// generate a unique id for the scripts section of this view, so it can be dynamically loaded/unloaded by the global AJAX navigator handler
|
||||
var scriptId = ScriptIdentifierHelper.GenerateScriptId();
|
||||
}
|
||||
|
||||
@inject IViewLocalizer _localizer
|
||||
@inject IUrlService _urlService
|
||||
|
||||
<div class="cotton-candy">
|
||||
<div style="display: grid; grid-template-rows: auto 1fr;">
|
||||
<!--container with two rows, one fixed, one filling remaining space-->
|
||||
<div style="min-height: 1rem;"></div><!--the first row is a dummy row for "margin", because setting a margin on the next row would offset the parent's position-->
|
||||
<div id="libraries-container" class="cards-container justify-start pl-10 pr-10 w-100 h-100">
|
||||
<p id="no-libraries" class="hidden">@_localizer["NoLibraries"]</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@section Scripts {
|
||||
<script type="text/javascript" data-form="@scriptId" defer>
|
||||
// create cleanup registry for this view
|
||||
const cleanupFunctions = [];
|
||||
|
||||
const librariesContainer = document.getElementById('libraries-container');
|
||||
const noLibrariesMessage = document.getElementById('no-libraries');
|
||||
|
||||
const documentLoaded = async function () {
|
||||
// get the media libraries
|
||||
// TODO: add setting check whether the user desires this feature or not
|
||||
const data = await callApiGetAsync('@_urlService.GetAbsoluteUrl("GetLibraries", "LibraryManagement")');
|
||||
if (data && data.length > 0) {
|
||||
noLibrariesMessage.classList.replace('block', 'hidden');
|
||||
librariesContainer.classList.replace('justify-center', 'justify-start');
|
||||
// populate media library items
|
||||
data.forEach((library) => {
|
||||
const libraryDiv = document.createElement('div');
|
||||
libraryDiv.className = 'media-panel';
|
||||
|
||||
libraryDiv.innerHTML = `
|
||||
<img src="${globalConfiguration.serverBasePath}/media/libraries/${library.id}/${library.coverImage}" />
|
||||
<span class="text-light-two"><strong>${library.title}</strong></span>
|
||||
`;
|
||||
|
||||
librariesContainer.appendChild(libraryDiv);
|
||||
});
|
||||
} else {
|
||||
noLibrariesMessage.classList.replace('hidden', 'block');
|
||||
librariesContainer.classList.replace('justify-start', 'justify-center');
|
||||
}
|
||||
};
|
||||
|
||||
// add listeners
|
||||
document.addEventListener('DOMContentLoaded', documentLoaded);
|
||||
|
||||
// register cleanup for these listeners
|
||||
cleanupFunctions.push(() => {
|
||||
document.removeEventListener('click', documentLoaded);
|
||||
});
|
||||
|
||||
// store all cleanups for this view on window object using the scriptId
|
||||
window.viewCleanups = window.viewCleanups || {};
|
||||
window.viewCleanups['@scriptId'] = () => {
|
||||
cleanupFunctions.forEach(cleanup => cleanup());
|
||||
console.log(`Unloaded @scriptId`);
|
||||
};
|
||||
console.log(`Loaded @scriptId`);
|
||||
</script>
|
||||
}
|
||||
@@ -1,4 +1,113 @@
|
||||
@*
|
||||
/library/manage
|
||||
*@
|
||||
<p>libraries</p>
|
||||
|
||||
@using Lumina.Presentation.Web.Common.Models.Libraries
|
||||
@using Lumina.Presentation.Web.Common.Services
|
||||
@using Microsoft.AspNetCore.Mvc.Localization
|
||||
|
||||
@{
|
||||
// generate a unique id for the scripts section of this view, so it can be dynamically loaded/unloaded by the global AJAX navigator handler
|
||||
var scriptId = ScriptIdentifierHelper.GenerateScriptId();
|
||||
}
|
||||
|
||||
@inject IUrlService _urlService
|
||||
@inject IViewLocalizer _localizer
|
||||
|
||||
<div style="display: grid; grid-template-rows: auto 1fr;"><!--container with two rows, one fixed, one filling remaining space-->
|
||||
<div style="min-height: 1rem;"></div><!--the first row is a dummy row for "margin", because setting a margin on the next row would offset the parent's position-->
|
||||
<div class="enlightenment-panel shadow-effect mx-auto panel w-75 mb-10" style="min-width: 320px;">
|
||||
<div class="shine-effect"></div>
|
||||
<div class="form-row">
|
||||
<h1 class="text-light-two w-100 text-center pt-0 pb-0 engraved-title">
|
||||
@(_localizer["Libraries"])
|
||||
</h1>
|
||||
</div>
|
||||
<div id="libraries-content">
|
||||
<div class="form-row">
|
||||
<div id="add-media-directory-form-table" class="form-table w-100">
|
||||
<!-- libraries will be populated here -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@section Scripts {
|
||||
<script type="text/javascript" data-form="@scriptId" defer>
|
||||
// create cleanup registry for this view
|
||||
const cleanupFunctions = [];
|
||||
let isInitialized = false;
|
||||
|
||||
// on view load
|
||||
const loadLibrariesAsync = async function() {
|
||||
const response = await callApiGetAsync('@_urlService.GetAbsoluteUrl("GetLibraries", "LibraryManagement")');
|
||||
const table = document.getElementById('add-media-directory-form-table');
|
||||
const container = document.getElementById('libraries-content');
|
||||
|
||||
if (response && response.length > 0) {
|
||||
table.innerHTML = response.map(library => {
|
||||
const editUrl = '@_urlService.GetAbsoluteUrl("EditLibrary", "LibraryManagement", new { id = default(Guid) })'
|
||||
.replace('/@(default(Guid))', `/${library.id}`);
|
||||
|
||||
return `
|
||||
<div class="form-table-row">
|
||||
<span title="${library.title}">${library.title}</span>
|
||||
<a href="${editUrl}">
|
||||
<img src="/images/ui/edit.svg" alt="@_localizer["Edit"]" title="@_localizer["Edit"]" class="remove-form-table-row-icon" />
|
||||
</a>
|
||||
<img src="/images/ui/delete.svg" alt="@_localizer["Remove"]" title="@_localizer["Remove"]" class="remove-form-table-row-icon" />
|
||||
</div>
|
||||
`;
|
||||
}).join('');
|
||||
} else {
|
||||
container.innerHTML = '<p class="text-center">@_localizer["NoLibraries"]</p>';
|
||||
}
|
||||
};
|
||||
|
||||
// on delete library icon click
|
||||
const handleDeleteLibraryClick = async function(e) {
|
||||
if (e.target.matches('img[src*="delete.svg"]')) {
|
||||
const row = e.target.closest('.form-table-row');
|
||||
const libraryTitle = row.querySelector('span').textContent;
|
||||
|
||||
if (await dialogService.show('@_localizer["DeleteLibraryConfirm"]'.replace('{0}', libraryTitle),
|
||||
jsLocalizedDialogs.confirmation, DialogButtons.YES_NO, DialogIcon.QUESTION) === DialogButton.YES) {
|
||||
const libraryId = row.querySelector('a').href.split('id=')[1];
|
||||
const url = '@_urlService.GetAbsoluteUrl("DeleteLibrary", "LibraryManagement", new { id = default(Guid) })';
|
||||
const success = await callApiDeleteAsync(url.replace('/@(default(Guid))', `/${libraryId}`));
|
||||
|
||||
if (success) {
|
||||
await loadLibrariesAsync(); // Reload the entire library list
|
||||
notificationService.show('@_localizer["LibraryDeleted"]', NotificationType.SUCCESS);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// add listeners
|
||||
document.addEventListener('click', handleDeleteLibraryClick);
|
||||
document.addEventListener('DOMContentLoaded', InitializeAsync);
|
||||
|
||||
// register cleanup for these listeners
|
||||
cleanupFunctions.push(() => {
|
||||
document.removeEventListener('click', handleDeleteLibraryClick);
|
||||
document.removeEventListener('DOMContentLoaded', InitializeAsync);
|
||||
});
|
||||
|
||||
// store all cleanups for this view on window object using the scriptId
|
||||
window.viewCleanups = window.viewCleanups || {};
|
||||
window.viewCleanups['@scriptId'] = () => {
|
||||
cleanupFunctions.forEach(cleanup => cleanup());
|
||||
console.log(`Unloaded @scriptId`);
|
||||
};
|
||||
|
||||
async function InitializeAsync() {
|
||||
if (isInitialized)
|
||||
return;
|
||||
isInitialized = true;
|
||||
await loadLibrariesAsync();
|
||||
}
|
||||
|
||||
console.log(`Loaded @scriptId`);
|
||||
</script>
|
||||
}
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
<div style="display: grid; grid-template-rows: auto 1fr;"><!--container with two rows, one fixed, one filling remaining space-->
|
||||
<div style="min-height: 1rem;"></div><!--the first row is a dummy row for "margin", because setting a margin on the next row would offset the parent's position-->
|
||||
<div class="enlightenment-panel shadow-effect p-2 mx-auto panel w-50 mb-10" style="min-width: 320px;">
|
||||
<div class="enlightenment-panel shadow-effect mx-auto panel w-50 mb-10" style="min-width: 320px;">
|
||||
<div class="shine-effect"></div>
|
||||
<form method="post" id="add-media-library-form" class="inline">
|
||||
@Html.AntiForgeryToken()
|
||||
@@ -231,7 +231,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// on Enter key pressed
|
||||
const handleEnterKey = async function(e) {
|
||||
if (e.key === 'Enter') {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
@using Lumina.Presentation.Web.Common.Models.Configuration
|
||||
@using Microsoft.AspNetCore.Mvc.Localization
|
||||
@using Microsoft.Extensions.Options
|
||||
|
||||
@inject IViewLocalizer _localizer
|
||||
@inject IOptions<ServerConfigurationModel> _serverConfigurationModel
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
@@ -50,6 +53,10 @@
|
||||
<div id="modal-background-menu"></div>
|
||||
|
||||
<script>
|
||||
var globalConfiguration = {
|
||||
serverBasePath: '@(_serverConfigurationModel.Value.BaseAddress):@(_serverConfigurationModel.Value.Port)',
|
||||
apiBasePath: '@(_serverConfigurationModel.Value.BaseAddress):@(_serverConfigurationModel.Value.Port)/api/v@(_serverConfigurationModel.Value.ApiVersion)',
|
||||
};
|
||||
var jsLocalizedMessages = {
|
||||
navigationFailed: '@_localizer["NavigationFailed"]',
|
||||
};
|
||||
|
||||
@@ -15,6 +15,12 @@
|
||||
<span></span>
|
||||
<nav id="mobile-menu">
|
||||
<div id="mobile-menu-content">
|
||||
<div class="mobile-menu-heading">
|
||||
Lumina
|
||||
</div>
|
||||
<ul>
|
||||
<li><a href="@_urlService.GetAbsoluteUrl("Index", "Home")"><span>@_localizer["Home"]</span></a></li>
|
||||
</ul>
|
||||
<div class="mobile-menu-heading">
|
||||
@_localizer["Account"]
|
||||
</div>
|
||||
@@ -52,7 +58,7 @@
|
||||
</div>
|
||||
<ul>
|
||||
<li><a href="@_urlService.GetAbsoluteUrl("Index", "LibraryManagement")" class="nav-link"><span>@_localizer["ManageLibraries"]</span></a></li>
|
||||
@if (await _auth.IsInRoleAsync("Admin", CancellationToken.None) || await _auth.HasPermissionAsync(AuthorizationPermission.canCreateLibraries, CancellationToken.None))
|
||||
@if (await _auth.IsInRoleAsync("Admin", CancellationToken.None) || await _auth.HasPermissionAsync(AuthorizationPermission.CanCreateLibraries, CancellationToken.None))
|
||||
{
|
||||
<li><a href="@_urlService.GetAbsoluteUrl("AddLibrary", "LibraryManagement")" class="nav-link"><span>@_localizer["AddNewLibrary"]</span></a></li>
|
||||
}
|
||||
@@ -114,6 +120,12 @@
|
||||
</label>
|
||||
<nav class="menubar">
|
||||
<ul>
|
||||
<li tabindex="0" class="top-level-menuitem">
|
||||
<label for="account-menu">Lumina</label>
|
||||
<ul>
|
||||
<li><a href="@_urlService.GetAbsoluteUrl("Index", "Home")">@_localizer["Home"]</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li tabindex="0" class="top-level-menuitem">
|
||||
<label for="account-menu">@_localizer["Account"]</label>
|
||||
<ul>
|
||||
@@ -150,7 +162,7 @@
|
||||
<label for="library-menu">@_localizer["Library"]</label>
|
||||
<ul>
|
||||
<li tabindex="0"><a href="@_urlService.GetAbsoluteUrl("Index", "LibraryManagement")" class="nav-link">@_localizer["ManageLibraries"]</a></li>
|
||||
@if (await _auth.IsInRoleAsync("Admin", CancellationToken.None) || await _auth.HasPermissionAsync(AuthorizationPermission.canCreateLibraries, CancellationToken.None))
|
||||
@if (await _auth.IsInRoleAsync("Admin", CancellationToken.None) || await _auth.HasPermissionAsync(AuthorizationPermission.CanCreateLibraries, CancellationToken.None))
|
||||
{
|
||||
<li tabindex="0"><a href="@_urlService.GetAbsoluteUrl("AddLibrary", "LibraryManagement")" class="nav-link">@_localizer["AddNewLibrary"]</a></li>
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user