Skip to content
Snippets Groups Projects
Verified Commit 3dc39edc authored by Jan Loewe's avatar Jan Loewe :speech_balloon:
Browse files

feat(preview): improve settings handling for strategies

old changes I found on my pc
parent bb32ce07
No related branches found
No related tags found
1 merge request!115Draft: Allow for multiple preview strategies
Pipeline #53342 failed
Showing
with 52 additions and 11 deletions
......@@ -32,11 +32,12 @@ export default {
option.value = await file.text();
},
async createStrategy() {
const strategy = await this.factory.createPreviewStrategy(
const strategy = await this.factory.createInstance(
this.$tool,
this.options
);
this.$tool.previewStrategies.push(strategy);
await this.$tool.persistStrategies();
},
},
};
......
......@@ -11,6 +11,8 @@ import { XSLPreviewStrategyFactory } from "~/core/strategies/preview/browser/XSL
export class GemimegTool implements IApplication {
$global: Vue;
STORAGE_KEY = "gemimeg.tool.strategies";
selectedPreviewStrategy?: IPreviewStrategy;
previewStrategies: IPreviewStrategy[] = [];
previewStrategyFactories: IPreviewStrategyFactory<any>[] = [];
......@@ -32,6 +34,17 @@ export class GemimegTool implements IApplication {
this.previewStrategyFactories.push(new SaxonJSPreviewStrategyFactory());
}
async persistStrategies() {
localStorage.setItem(
`${this.STORAGE_KEY}.preview`,
JSON.stringify(
await Promise.all(
this.previewStrategies.map(async (x) => await x.serializeOptions())
)
)
);
}
on(name: string, callback: Function): void {
this.$global.$on(name, callback);
}
......
......@@ -29,6 +29,11 @@ export interface IApplication {
*/
emit(event: string, ...args: any[]): void;
/**
* Persists all registered strategies
*/
persistStrategies(): Promise<void>;
/**
* Registers one or more credits
* @param credits credits to register
......
......@@ -3,4 +3,5 @@ import { DCCDocument } from "@d-ptb/dcc-js";
export interface IPreviewStrategy {
name: string;
renderPreview(item: DCCDocument): Promise<string>;
serializeOptions(): Promise<Object>;
}
......@@ -18,5 +18,5 @@ export interface IPreviewStrategyFactory<T> {
* @param options the options to use
* @returns the preview strategy
*/
createPreviewStrategy($tool: IApplication, options: T): IPreviewStrategy;
createInstance($tool: IApplication, options: T): IPreviewStrategy;
}
......@@ -48,4 +48,13 @@ export class XSLPreviewStrategy implements IPreviewStrategy {
return Promise.resolve(resultDocument.documentElement.outerHTML);
}
serializeOptions(): Promise<Object> {
return Promise.resolve({
name: this.name,
xslt: this._xslt,
xsltPath: this._xsltPath,
base: this.base,
});
}
}
......@@ -8,8 +8,8 @@ import {
import { IApplication } from "~/core/interfaces/IApplication";
export interface Options {
name: ConfigurableOption<String>;
xslt: ConfigurableOption<String>;
name: ConfigurableOption<string>;
xslt: ConfigurableOption<string>;
}
export class XSLPreviewStrategyFactory
......@@ -33,7 +33,7 @@ export class XSLPreviewStrategyFactory
});
}
createPreviewStrategy(_: IApplication, options): IPreviewStrategy {
createInstance(_: IApplication, options: Options): IPreviewStrategy {
return new XSLPreviewStrategy({
name: options.name.value,
xslt: options.xslt.value,
......
......@@ -130,4 +130,13 @@ export class SaxonJSPreviewStrategy implements IPreviewStrategy {
return resultStringXML.principalResult;
}
serializeOptions(): Promise<Object> {
return Promise.resolve({
name: this.name,
xslt: this._xslt,
xsltPath: this._xsltPath,
base: this.base,
});
}
}
......@@ -8,8 +8,8 @@ import {
import { IApplication } from "~/core/interfaces/IApplication";
export interface Options {
name: ConfigurableOption<String>;
xslt: ConfigurableOption<String>;
name: ConfigurableOption<string>;
xslt: ConfigurableOption<string>;
}
export class SaxonJSPreviewStrategyFactory
......@@ -33,7 +33,7 @@ export class SaxonJSPreviewStrategyFactory
});
}
createPreviewStrategy($tool: IApplication, options): IPreviewStrategy {
createInstance($tool: IApplication, options: Options): IPreviewStrategy {
return new SaxonJSPreviewStrategy($tool, {
name: options.name.value,
xslt: options.xslt.value,
......
......@@ -21,7 +21,10 @@ async function verifyPermissionOrThrow(fileHandle) {
throw new Error("The permission for the file system was not granted.");
}
const customStore = createStore("gemimeg-tool-files", "files");
const customStore = createStore(
"gemimeg.tool.strategies.storage.fileSystemAPI",
"files"
);
class FSFile implements IDCCFile {
autoSave: boolean;
......
......@@ -14,7 +14,7 @@
<xsl:template match="dcc:digitalCalibrationCertificate">
<html>
<body>
<h1>Custom 2</h1>
<h1>Custom 1</h1>
<p>XSLT Version = <xsl:copy-of select="system-property('xsl:version')"/></p>
<p>XSLT Vendor = <xsl:copy-of select="system-property('xsl:vendor')"/></p>
<p>XSLT Vendor URL = <xsl:copy-of select="system-property('xsl:vendor-url')"/></p>
......
......@@ -14,7 +14,7 @@
<xsl:template match="dcc:digitalCalibrationCertificate">
<html>
<body>
<h1>Custom 1</h1>
<h1>Custom 2</h1>
<p>XSLT Version = <xsl:copy-of select="system-property('xsl:version')"/></p>
<p>XSLT Vendor = <xsl:copy-of select="system-property('xsl:vendor')"/></p>
<p>XSLT Vendor URL = <xsl:copy-of select="system-property('xsl:vendor-url')"/></p>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment