mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 14:11:10 +00:00
Stops the browser from requesting the file browser theme sub templates as resources
This commit is contained in:
1 parent
f694882b46
commit
30437030f9
5 files changed
+17
-11
No files matched your search
@@ -247,21 +247,23 @@ The shell template receives a model with the following fields:
|
|||||||
| `assetBase` | The base URL of the theme assets. |
|
| `assetBase` | The base URL of the theme assets. |
|
||||||
| `iconBaseUrl` | The base URL of the file type icons of the theme, derived from `assetBase`. |
|
| `iconBaseUrl` | The base URL of the file type icons of the theme, derived from `assetBase`. |
|
||||||
| `fileIconsUrl` | The URL of the file icons mapping of the theme, derived from `assetBase`. |
|
| `fileIconsUrl` | The URL of the file icons mapping of the theme, derived from `assetBase`. |
|
||||||
| `treeNodeTemplate` | The raw source of the `shared/file-system-browser/tree-node` template, inlined by the application into a `<template>` element. |
|
| `treeNodeTemplate` | The raw source of the `shared/file-system-browser/tree-node` template, inlined by the application into a plain text script element. |
|
||||||
| `explorerItemTemplate` | The raw source of the `shared/file-system-browser/explorer-item` template, inlined by the application into a `<template>` element. |
|
| `explorerItemTemplate` | The raw source of the `shared/file-system-browser/explorer-item` template, inlined by the application into a plain text script element. |
|
||||||
| `pathSegmentTemplate` | The raw source of the `shared/file-system-browser/path-segment` template, inlined by the application into a `<template>` element. |
|
| `pathSegmentTemplate` | The raw source of the `shared/file-system-browser/path-segment` template, inlined by the application into a plain text script element. |
|
||||||
| `strings` | The localized strings of the component, keyed by their resource names. |
|
| `strings` | The localized strings of the component, keyed by their resource names. |
|
||||||
|
|
||||||
The shell template owns the whole dialog markup: the header with the view mode, navigation and address bar controls, the tree view and explorer panes and the action bar. It must keep the DOM contract the application script binds to (the element ids such as `file-system-browser-dialog`, `navigator-*`, `file-system-browser-treeview`, `file-system-browser-file-system-explorer` and the two selection rectangles), and it must include the application component scripts with their `data-component-script` attributes:
|
The shell template owns the whole dialog markup: the header with the view mode, navigation and address bar controls, the tree view and explorer panes and the action bar. It must keep the DOM contract the application script binds to (the element ids such as `file-system-browser-dialog`, `navigator-*`, `file-system-browser-treeview`, `file-system-browser-file-system-explorer` and the two selection rectangles), and it must include the application component scripts with their `data-component-script` attributes:
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<template id="fsb-template-tree-node">{{{treeNodeTemplate}}}</template>
|
<script type="text/plain" id="fsb-template-tree-node">{{{treeNodeTemplate}}}</script>
|
||||||
<template id="fsb-template-explorer-item">{{{explorerItemTemplate}}}</template>
|
<script type="text/plain" id="fsb-template-explorer-item">{{{explorerItemTemplate}}}</script>
|
||||||
<template id="fsb-template-path-segment">{{{pathSegmentTemplate}}}</template>
|
<script type="text/plain" id="fsb-template-path-segment">{{{pathSegmentTemplate}}}</script>
|
||||||
<script defer src="{{appBase}}js/theme-client-template-engine.js" data-component-script="file-system-browser"></script>
|
<script defer src="{{appBase}}js/theme-client-template-engine.js" data-component-script="file-system-browser"></script>
|
||||||
<script defer src="{{appBase}}js/file-system-browser-dialog.js" data-component-script="file-system-browser"></script>
|
<script defer src="{{appBase}}js/file-system-browser-dialog.js" data-component-script="file-system-browser"></script>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The sub template sources are inlined into plain text script elements, whose content the browser never parses into elements, so the theme markup cannot be loaded or requested before the application script renders it. The application script reads the raw source from the script element text and renders it for each dynamic entry.
|
||||||
|
|
||||||
The application appends the initialization script of the component after the rendered shell, so the theme does not author it.
|
The application appends the initialization script of the component after the rendered shell, so the theme does not author it.
|
||||||
|
|
||||||
The sub templates are rendered client side by the application script for each dynamic entry, using the same Mustache syntax as the server side engine. They receive the following fields:
|
The sub templates are rendered client side by the application script for each dynamic entry, using the same Mustache syntax as the server side engine. They receive the following fields:
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -75,6 +75,7 @@
|
|||||||
let explorerItemTemplate = null;
|
let explorerItemTemplate = null;
|
||||||
let pathSegmentTemplate = null;
|
let pathSegmentTemplate = null;
|
||||||
|
|
||||||
|
let serverBasePath;
|
||||||
let clientBasePath;
|
let clientBasePath;
|
||||||
let _path;
|
let _path;
|
||||||
let pathSeparator = '/';
|
let pathSeparator = '/';
|
||||||
@@ -109,9 +110,10 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the values needed by the file sytem browser.
|
* Initializes the values needed by the file sytem browser.
|
||||||
* @param {any} config The configuration of the file system browser, with the server and client base paths, the initial path, the initial view mode and icon size, and the optional theme asset URLs.
|
* @param {any} config The configuration of the file system browser.
|
||||||
*/
|
*/
|
||||||
async function initFileSystemBrowser(config) {
|
async function initFileSystemBrowser(config) {
|
||||||
|
serverBasePath = config.serverBasePath;
|
||||||
clientBasePath = config.clientBasePath;
|
clientBasePath = config.clientBasePath;
|
||||||
iconBaseUrl = config.iconBaseUrl || '';
|
iconBaseUrl = config.iconBaseUrl || '';
|
||||||
fileIconsUrl = config.fileIconsUrl || '';
|
fileIconsUrl = config.fileIconsUrl || '';
|
||||||
@@ -142,6 +144,8 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the raw source of a theme sub template element, or null when the theme does not provide one.
|
* Gets the raw source of a theme sub template element, or null when the theme does not provide one.
|
||||||
|
* The theme inlines the sub template sources into plain text script elements, so that the browser never parses the theme markup into live elements,
|
||||||
|
* which could otherwise make it request their resources, and the raw source is recovered by reading the element text.
|
||||||
* @param {string} id - The id of the template element.
|
* @param {string} id - The id of the template element.
|
||||||
* @returns {string|null} The raw template source, or null when the element is missing.
|
* @returns {string|null} The raw template source, or null when the element is missing.
|
||||||
*/
|
*/
|
||||||
@@ -153,7 +157,7 @@
|
|||||||
if (typeof renderThemeTemplate !== 'function')
|
if (typeof renderThemeTemplate !== 'function')
|
||||||
return null;
|
return null;
|
||||||
// an empty template element means the theme does not provide the template, in which case the built-in markup is used
|
// an empty template element means the theme does not provide the template, in which case the built-in markup is used
|
||||||
return templateElement.innerHTML || null;
|
return templateElement.textContent || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1466,8 +1470,8 @@
|
|||||||
* @throws {Error} - Throws an error if the API call fails.
|
* @throws {Error} - Throws an error if the API call fails.
|
||||||
*/
|
*/
|
||||||
async function getThumbnailApiCall(path, quality) {
|
async function getThumbnailApiCall(path, quality) {
|
||||||
// fetch the thumbnail for the given item from the server, through the Web application, which proxies the request with the authentication of the current user
|
// fetch the thumbnail for the given item from the server
|
||||||
const response = await fetch(`${clientBasePath}thumbnails/api-get-thumbnail?path=` + encodeURIComponent(path) + '&quality=' + quality, {
|
const response = await fetch(`${serverBasePath}thumbnails/get-thumbnail?path=` + encodeURIComponent(path) + '&quality=' + quality, {
|
||||||
signal: abortController.signal // use the abort signal
|
signal: abortController.signal // use the abort signal
|
||||||
});
|
});
|
||||||
if (!response.ok)
|
if (!response.ok)
|
||||||
|
|||||||
+1
-1
@@ -66,7 +66,7 @@ public class EditLibraryViewEndpointTests : IClassFixture<LuminaWebFactory>
|
|||||||
_apiFactory.ApiClientStub.RegisterGetResponse($"libraries/{libraryId}", expectedLibrary);
|
_apiFactory.ApiClientStub.RegisterGetResponse($"libraries/{libraryId}", expectedLibrary);
|
||||||
ThemeResponseDto theme = _themeResponseDtoFixture.Create(themeId: "lumina-default");
|
ThemeResponseDto theme = _themeResponseDtoFixture.Create(themeId: "lumina-default");
|
||||||
_apiFactory.ApiClientStub.RegisterGetResponse(ApiRoutes.Themes.GET_CURRENT_THEME, theme);
|
_apiFactory.ApiClientStub.RegisterGetResponse(ApiRoutes.Themes.GET_CURRENT_THEME, theme);
|
||||||
RegisterThemeTemplate(theme, "shared/file-system-browser", "<template id=\"fsb-template-tree-node\">{{{treeNodeTemplate}}}</template><div id=\"file-system-browser-dialog\">themed</div>");
|
RegisterThemeTemplate(theme, "shared/file-system-browser", "<script type=\"text/plain\" id=\"fsb-template-tree-node\">{{{treeNodeTemplate}}}</script><div id=\"file-system-browser-dialog\">themed</div>");
|
||||||
RegisterThemeTemplate(theme, "shared/file-system-browser/tree-node", "<div class=\"tree-node\">{{name}}</div>");
|
RegisterThemeTemplate(theme, "shared/file-system-browser/tree-node", "<div class=\"tree-node\">{{name}}</div>");
|
||||||
RegisterThemeTemplate(theme, "shared/file-system-browser/explorer-item", "<div class=\"e\">{{name}}</div>");
|
RegisterThemeTemplate(theme, "shared/file-system-browser/explorer-item", "<div class=\"e\">{{name}}</div>");
|
||||||
RegisterThemeTemplate(theme, "shared/file-system-browser/path-segment", "<li>{{path}}</li>");
|
RegisterThemeTemplate(theme, "shared/file-system-browser/path-segment", "<li>{{path}}</li>");
|
||||||
|
|||||||
Reference in new issue
Block a user