mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 08:11:10 +00:00
Implements first stage library management system
This commit is contained in:
1 parent
5e0f94cd82
commit
36352ea9e8
291 files changed
+3733
-1384
No files matched your search
@@ -7,6 +7,8 @@ const modalBackgroundArticle = document.getElementById('modal-background-article
|
||||
const fileSystemBrowserDialog = document.getElementById('file-system-browser-dialog');
|
||||
const fileSystemBrowserTreeview = document.getElementById('file-system-browser-treeview');
|
||||
const pathSegmentsContainer = document.getElementById('navigator-path-segments');
|
||||
const article = document.querySelector('article');
|
||||
const menubar = document.getElementsByClassName('menubar')[0];
|
||||
|
||||
const fileSystemTreeViewContainer = document.getElementById('file-system-browser-file-system-treeview-container');
|
||||
const fileSystemExplorerContainer = document.getElementById('file-system-browser-file-system-explorer-container');
|
||||
@@ -47,6 +49,7 @@ const btnExtraLargeIconsView = document.getElementById('navigator-extra-large-ic
|
||||
const btnFileSystemBrowserEditPath = document.getElementById('navigator-edit-path-button');
|
||||
const btnFileSystemBrowserSubmitPath = document.getElementById('navigator-navigate-button');
|
||||
const btnFileSystemBrowserConfirm = document.getElementById('file-system-browser-confirm-button');
|
||||
const btnFileSystemBrowserCancel = document.getElementById('file-system-browser-cancel-button');
|
||||
|
||||
const selectedFileSystemElementsInput = document.getElementById('file-system-browser-selected-element');
|
||||
|
||||
@@ -178,15 +181,12 @@ async function initFileSystemBrowser(serverBasePathValue, clientBasePathValue, i
|
||||
addHorizontalScrolling(addressBar);
|
||||
//switchViewMode('list', null, true);
|
||||
switchViewMode(viewModeValue, viewModeValue === 'list' ? null : iconSizeValue, true);
|
||||
|
||||
// TODO: to be removed:
|
||||
//showFileSystemBrowserDialogAsync(initialPath, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the file system browser dialog.
|
||||
*/
|
||||
async function showFileSystemBrowserDialogAsync(path, showHiddenElementsValue, includeFilesValue) {
|
||||
async function showFileSystemBrowserDialogAsync(path, showHiddenElementsValue, includeFilesValue, onConfirmCallback) {
|
||||
if (path !== undefined && path !== null) {
|
||||
showHiddenElements = showHiddenElementsValue;
|
||||
includeFiles = includeFilesValue;
|
||||
@@ -200,6 +200,15 @@ async function showFileSystemBrowserDialogAsync(path, showHiddenElementsValue, i
|
||||
await toggleFileSystemTreeViewAsync(false);
|
||||
await toggleShowFileSystemElementsThumbnailsAsync(false);
|
||||
await navigateToPathAsync(path, false, false);
|
||||
// add click handler for confirm button
|
||||
btnFileSystemBrowserConfirm.onclick = function () {
|
||||
const selectedPaths = selectedFileSystemElementsInput.value;
|
||||
if (onConfirmCallback && typeof onConfirmCallback === 'function')
|
||||
onConfirmCallback(selectedPaths);
|
||||
// hide dialog
|
||||
hideFileSystemBrowserDialog();
|
||||
};
|
||||
btnFileSystemBrowserCancel.onclick = hideFileSystemBrowserDialog;
|
||||
} else
|
||||
notificationService.Show("Path cannot be null!", NotificationType.ERROR); // TODO: should ask error message from server when translation is implemented
|
||||
}
|
||||
@@ -208,9 +217,9 @@ async function showFileSystemBrowserDialogAsync(path, showHiddenElementsValue, i
|
||||
* Hides the file system browser dialog.
|
||||
*/
|
||||
function hideFileSystemBrowserDialog() {
|
||||
modalBackgroundMenu.style.display = 'block';
|
||||
modalBackgroundArticle.style.display = 'block';
|
||||
fileSystemBrowserDialog.style.display = 'block';
|
||||
modalBackgroundMenu.style.display = 'none';
|
||||
modalBackgroundArticle.style.display = 'none';
|
||||
fileSystemBrowserDialog.style.display = 'none';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -724,21 +733,15 @@ async function fetchFileSystemFilesAsync(path, callback) {
|
||||
* @param {string} itemType - Type of item being processed ('File' or 'Directory').
|
||||
*/
|
||||
async function fetchJsonDataAsync(url, callback, itemType) {
|
||||
// initiate the fetch request from the API
|
||||
const response = await fetch(url);
|
||||
// parse the JSON response
|
||||
const result = await response.json();
|
||||
|
||||
// verify the response was successful
|
||||
if (!result.success)
|
||||
throw new Error('Failed to fetch data from server');
|
||||
|
||||
// process each item in the response.data array
|
||||
for (let item of result.data) {
|
||||
// manually specify the type to the parsed object
|
||||
item.itemType = itemType;
|
||||
// call the provided callback function with the processed item
|
||||
callback(item);
|
||||
const response = await callApiGetAsync(url);
|
||||
if (response !== undefined) {
|
||||
// process each item in the response.data array
|
||||
for (let item of response) {
|
||||
// manually specify the type to the parsed object
|
||||
item.itemType = itemType;
|
||||
// call the provided callback function with the processed item
|
||||
callback(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1079,16 +1082,16 @@ function startSelection(e) {
|
||||
document.body.style.overflowY = 'hidden'; // needed in order to not put a vertical scrollbar on the document, while in vertical layout selection
|
||||
document.documentElement.style.overflowY = 'hidden';
|
||||
selectionStartPosition.x = e.pageX + fileSystemExplorer.scrollLeft;
|
||||
selectionStartPosition.y = e.pageY + fileSystemExplorerContainer.scrollTop; // not a mistake - in vertical mode, this is the overflow container!
|
||||
selectionStartPosition.y = (e.pageY - parseInt(window.getComputedStyle(menubar).height)) + fileSystemExplorerContainer.scrollTop; // not a mistake - in vertical mode, this is the overflow container!
|
||||
// place the selection rectangle at the clicked location (relative to the whole page, and taking into account scroll offset), with 0 size
|
||||
visibleSelectionRectangle.style.left = e.pageX + 'px';
|
||||
visibleSelectionRectangle.style.top = e.pageY + 'px';
|
||||
visibleSelectionRectangle.style.top = (e.pageY - parseInt(window.getComputedStyle(menubar).height)) + 'px';
|
||||
visibleSelectionRectangle.style.width = '0px';
|
||||
visibleSelectionRectangle.style.height = '0px';
|
||||
visibleSelectionRectangle.style.visibility = 'visible';
|
||||
|
||||
selectionRectangle.style.left = e.pageX + 'px';
|
||||
selectionRectangle.style.top = e.pageY + 'px';
|
||||
selectionRectangle.style.top = (e.pageY - parseInt(window.getComputedStyle(menubar).height)) + 'px';
|
||||
selectionRectangle.style.width = '0px';
|
||||
selectionRectangle.style.height = '0px';
|
||||
}
|
||||
@@ -1101,7 +1104,7 @@ function updateSelection(e) {
|
||||
if (!isSelecting)
|
||||
return;
|
||||
currentMousePosition.x = e.pageX;
|
||||
currentMousePosition.y = e.pageY;
|
||||
currentMousePosition.y = e.pageY - parseInt(window.getComputedStyle(menubar).height);
|
||||
handleSelection();
|
||||
}
|
||||
|
||||
@@ -1192,10 +1195,10 @@ function handleSelection() {
|
||||
if (right > containerRect.right)
|
||||
visibleSelectionRectangle.style.width = (containerRect.right - left) + 'px';
|
||||
|
||||
if (top < containerRect.top) {
|
||||
const difference = containerRect.top - top;
|
||||
if (top < containerRect.top - parseInt(window.getComputedStyle(menubar).height)) {
|
||||
const difference = containerRect.top - top - parseInt(window.getComputedStyle(menubar).height);
|
||||
visibleSelectionRectangle.style.height = (parseFloat(visibleSelectionRectangle.style.height) - difference) + 'px';
|
||||
visibleSelectionRectangle.style.top = containerRect.top + 'px';
|
||||
visibleSelectionRectangle.style.top = (containerRect.top - parseInt(window.getComputedStyle(menubar).height)) + 'px';
|
||||
}
|
||||
if (bottom > containerRect.bottom)
|
||||
visibleSelectionRectangle.style.height = (containerRect.bottom - top) + 'px';
|
||||
|
||||
@@ -62,8 +62,8 @@ class NotificationService {
|
||||
else
|
||||
console.log(message);
|
||||
|
||||
// set a timeout to remove the notification after 5 seconds
|
||||
setTimeout(() => this.removeNotification(notification.id), 5000);
|
||||
// set a timeout to remove the notification after 10 seconds (fading out effect is handled in notification.css)
|
||||
setTimeout(() => this.removeNotification(notification.id), 10000);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,9 +75,8 @@ class NotificationService {
|
||||
if (index !== -1) {
|
||||
this.notifications.splice(index, 1);
|
||||
const element = document.getElementById(`notification-${id}`);
|
||||
if (element) {
|
||||
if (element)
|
||||
element.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +92,7 @@ class NotificationService {
|
||||
notificationElement.id = `notification-${notification.id}`;
|
||||
notificationElement.className = `notification ${notification.type}`;
|
||||
notificationElement.innerHTML = `
|
||||
<div class="shine-effect"></div>
|
||||
<div class="notification-shine-effect"></div>
|
||||
<div class="notification-body">
|
||||
<span class="notification-message">${notification.message}</span>
|
||||
<button class="close-button" onclick="notificationService.removeNotification('${notification.id}')">×</button>
|
||||
|
||||
@@ -38,6 +38,55 @@ async function callApiGetAsync(url) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a POST request to the specified API endpoint.
|
||||
* @param {string} url - The API endpoint URL.
|
||||
* @param {Object} data - The data to send in the request body.
|
||||
* @param {Object} [options] - Additional options for the request.
|
||||
* @param {boolean} [options.useAntiForgery=true] - Whether to include anti-forgery token.
|
||||
* @param {Object} [options.headers] - Additional headers to include.
|
||||
* @returns {Promise<any>} The response data if successful, undefined otherwise.
|
||||
*/
|
||||
async function callApiPostAsync(url, data, options = {}) {
|
||||
const defaultOptions = {
|
||||
useAntiForgery: true,
|
||||
headers: {}
|
||||
};
|
||||
const finalOptions = { ...defaultOptions, ...options };
|
||||
try {
|
||||
// prepare headers
|
||||
const headers = {
|
||||
'Content-Type': 'application/json',
|
||||
...finalOptions.headers
|
||||
};
|
||||
// add anti-forgery token if enabled
|
||||
if (finalOptions.useAntiForgery) {
|
||||
const token = document.querySelector('input[name="__RequestVerificationToken"]')?.value;
|
||||
if (token)
|
||||
headers['X-CSRF-TOKEN'] = token;
|
||||
}
|
||||
// make the request
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: headers,
|
||||
body: JSON.stringify(data)
|
||||
});
|
||||
if (!response.ok)
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
const jsonResponse = await response.json();
|
||||
if (jsonResponse.success) {
|
||||
if (jsonResponse.message)
|
||||
notificationService.show(jsonResponse.message, NotificationType.SUCCESS);
|
||||
return jsonResponse.data;
|
||||
}
|
||||
else
|
||||
notificationService.show(jsonResponse.errorMessage, NotificationType.ERROR);
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
notificationService.show(error, NotificationType.ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
//+======================================================================================+
|
||||
//| Website navigation |
|
||||
//+======================================================================================+
|
||||
@@ -338,6 +387,12 @@ function getElementOffset(id) {
|
||||
};
|
||||
}
|
||||
|
||||
document.querySelectorAll('.remove-form-table-row-icon').forEach(icon => {
|
||||
icon.addEventListener('click', function () {
|
||||
this.parentElement.remove();
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Toggles the visibility of the audio player.
|
||||
*/
|
||||
@@ -361,4 +416,90 @@ function toggleAudioPlayerFullHeight() {
|
||||
audioPlayerFullHeightToggle.addEventListener('click', toggleAudioPlayerFullHeight);
|
||||
audioPlayerClose.addEventListener('click', toggleAudioPlayerVisibility);
|
||||
|
||||
|
||||
/**
|
||||
* Closes all comboboxes except for the one passed as an argument.
|
||||
* @param {HTMLElement} exceptionCheckbox - The checkbox of the combobox that should remain open.
|
||||
*/
|
||||
function closeAllComboboxesExcept(exceptionCheckbox) {
|
||||
const checkedCheckboxes = document.querySelectorAll('.enlightenment-toggle-checkbox:checked, .navigator-toggle-checkbox:checked');
|
||||
checkedCheckboxes.forEach(function (checkbox) {
|
||||
if (!exceptionCheckbox || checkbox.id !== exceptionCheckbox.id)
|
||||
checkbox.checked = false;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects changes on any combobox checkbox. If a combobox is opened, this will ensure all other comboboxes are closed.
|
||||
*/
|
||||
document.addEventListener('change', function (e) {
|
||||
if (e.target.matches('.enlightenment-toggle-checkbox, .navigator-toggle-checkbox'))
|
||||
if (e.target.checked)
|
||||
closeAllComboboxesExcept(e.target);
|
||||
});
|
||||
|
||||
/**
|
||||
* Event handler for when an option in the combobox is clicked.
|
||||
* This updates the displayed value of the combobox to the clicked option and closes the dropdown.
|
||||
*/
|
||||
document.addEventListener('click', function (e) {
|
||||
if (e.target.matches('.enlightenment-option')) {
|
||||
var text = e.target.textContent;
|
||||
var combobox = e.target.closest('.enlightenment-combobox');
|
||||
|
||||
var selectedText = combobox.querySelector('.enlightenment-selected-text');
|
||||
if (selectedText)
|
||||
selectedText.textContent = text;
|
||||
|
||||
var toggleCheckbox = combobox.querySelector('.enlightenment-toggle-checkbox');
|
||||
if (toggleCheckbox)
|
||||
toggleCheckbox.checked = false;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Global click event for the entire document. Closes all combobox dropdowns if the clicked target is outside any combobox.
|
||||
*/
|
||||
document.addEventListener('click', function (e) {
|
||||
// enlightenment combobox logic
|
||||
if (!e.target.closest('.enlightenment-combobox')) {
|
||||
const checkbox = document.querySelector('.enlightenment-toggle-checkbox:checked');
|
||||
if (checkbox)
|
||||
checkbox.checked = false;
|
||||
}
|
||||
// navigator combobox logic
|
||||
if (!e.target.closest('.navigator-combobox') && typeof addressBar !== 'undefined' && addressBar !== null) {
|
||||
const checkbox = document.querySelector('.navigator-toggle-checkbox:checked');
|
||||
if (checkbox)
|
||||
checkbox.checked = false;
|
||||
// when drop down closes, hide address bar overflow
|
||||
addressBar.style.overflowX = 'auto';
|
||||
addressBar.style.overflowY = 'hidden';
|
||||
reattachDropdown();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Event handler for navigation combobox drop down item clicks.
|
||||
*/
|
||||
document.addEventListener("click", function (e) {
|
||||
if (e.target.matches('.navigator-option')) {
|
||||
// the address bar drop downs may be destroyed when an option is clicked - they are regenerated each time anyway
|
||||
addressBar.removeEventListener('scroll', adjustDropdownPosition);
|
||||
|
||||
var parentElement = e.target.parentElement;
|
||||
if (parentElement)
|
||||
parentElement.remove();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Prevents the global document click event from propagating when clicking on a combobox.
|
||||
* This ensures the dropdown doesn't close unintentionally.
|
||||
*/
|
||||
document.addEventListener('click', function (e) {
|
||||
if (e.target.closest('.enlightenment-combobox, .navigator-combobox'))
|
||||
e.stopPropagation();
|
||||
});
|
||||
|
||||
document.addEventListener('DOMContentLoaded', initializeNavigation);
|
||||
Reference in new issue
Block a user