Skip to content

Commit

Permalink
DN-26: Moved configuration from Config to WelcomeWidgetFactory.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Marius Austerschulte committed Apr 24, 2024
1 parent c3fd1ee commit 41adf19
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 64 deletions.
2 changes: 1 addition & 1 deletion src/main/js/apps/sample/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"buttonText": "${welcome.buttonText}",
"buttonDependsOnCheckbox": false,
"showCheckbox": true,
"checkboxChecked": true,
"checkboxChecked": false,
"checkboxText": "${welcome.checkboxText}",
"showImage": true,
"imageHeight": "300px",
Expand Down
34 changes: 0 additions & 34 deletions src/main/js/bundles/dn_welcome/Config.ts

This file was deleted.

37 changes: 23 additions & 14 deletions src/main/js/bundles/dn_welcome/WelcomeWidgetFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,17 @@
import WelcomeWidget from "./WelcomeWidget.ts.vue";
import Vue from "apprt-vue/Vue";
import VueDijit from "apprt-vue/VueDijit";
import Config from "./Config";

export default class WelcomeWidgetFactory {
#config: Config;
#windowToggleTool: any;
#doNotShowStorageKey = "dn_welcome.doNotShow";
#widget: any;

constructor(config?: Config) {
this.#config = config || new Config();
constructor(props: Partial<Config>) {
this.#widget = this.#createWelcomeWidget(props);
}

activate(): void {
this.#initComponent();
this.#applySavedDoNotShowWindowState();
}

Expand All @@ -40,9 +37,8 @@ export default class WelcomeWidgetFactory {
}
}

#initComponent(): void {
const config = this.#config;
const vm = this.#widget = new Vue(WelcomeWidget);
#createWelcomeWidget(config: Partial<Config>): any {
const vm: any = new Vue(WelcomeWidget);
vm.heading = config.heading;
vm.infoText = config.infoText;
vm.infoTextUrl = config.infoTextUrl;
Expand All @@ -62,22 +58,35 @@ export default class WelcomeWidgetFactory {
} else {
localStorage.removeItem(this.#doNotShowStorageKey);
}
this.#windowToggleTool.set("active", false);
this.#windowToggleTool?.set("active", false);
});

return vm;
}

#applySavedDoNotShowWindowState(): void {
const doNotShowAgain = localStorage.getItem(this.#doNotShowStorageKey);
if (doNotShowAgain !== "1") {
this.#windowToggleTool.set("active", true);
this.#windowToggleTool?.set("active", true);
}
}

set config(config: Config) {
this.#config = config;
}

set windowToggleTool(tool: any) {
this.#windowToggleTool = tool;
}
}

interface Config {
heading: string;
infoText: string;
infoTextUrl: string;
showButton: boolean;
buttonText: string;
buttonDependsOnCheckbox: boolean;
showCheckbox: boolean;
checkboxText: string;
checkboxChecked: boolean;
showImage: boolean;
imageUrl: string;
imageHeight: string;
}
16 changes: 3 additions & 13 deletions src/main/js/bundles/dn_welcome/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@
"components": [
{
"name": "Config",
"provides": "dn_welcome.Config",
"provides": "dijit.Widget",
"instanceFactory": true,
"propertiesConstructor": true,
"properties": {
"widgetRole": "welcomeWidget",
"heading": "",
"infoText": "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.",
"infoTextUrl": "",
Expand All @@ -72,20 +74,8 @@
"showImage": true,
"imageHeight": "300px",
"imageUrl": ""
}
},
{
"name": "WelcomeWidgetFactory",
"provides": "dijit.Widget",
"instanceFactory": true,
"properties": {
"widgetRole": "welcomeWidget"
},
"references": [
{
"name": "config",
"providing": "dn_welcome.Config"
},
{
"name": "windowToggleTool",
"providing": "ct.tools.Tool",
Expand Down
3 changes: 1 addition & 2 deletions src/main/js/bundles/dn_welcome/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@
/// limitations under the License.
///

export {default as WelcomeWidgetFactory} from "./WelcomeWidgetFactory";
export {default as Config} from "./Config";
export {default as Config} from "./WelcomeWidgetFactory";

0 comments on commit 41adf19

Please sign in to comment.