@WidgetComponent
File
Metadata
selector |
nm-config |
styleUrls |
config.component.scss |
templateUrl |
./config.component.html |
Index
Widget inputs
|
|
|
Widget outputs
|
|
Properties
|
|
Methods
|
|
Constructor
constructor(localStorageService: LocalStorageService, overlayContainer: OverlayContainer, configService: ConfigService)
|
|
Parameters :
Name |
Type |
Optional |
localStorageService |
LocalStorageService
|
no
|
overlayContainer |
OverlayContainer
|
no
|
configService |
ConfigService
|
no
|
|
Methods
Public
change
|
change(withReload: )
|
|
Parameters :
Name |
Optional |
withReload |
no
|
|
Protected
configureWidget
|
configureWidget(configuration: WidgetConfig)
|
Decorators : WidgetConfigure
|
|
|
Public
_id
|
_id:
|
Decorators : WidgetId
|
|
Public
productNo
|
productNo:
|
Default value : new Subject<any>()
|
Decorators : WidgetInput
|
|
Private
themeEntry
|
themeEntry: LocalStorageEntry
|
Type : LocalStorageEntry
|
|
import { Component } from "@angular/core";
import { WidgetConfig } from "../../widget.configuration";
import {
WidgetComponent,
WidgetConfiguration,
WidgetConfigure,
WidgetId,
WidgetInput,
} from "../../widget.metadata";
import { Observable, Subject } from "rxjs";
import { WidgetframeService } from "../../widgetframe/widgetframe.service";
import {
LocalStorageEntry,
LocalStorageEntryConfig,
LocalStorageService,
} from "../../../components/local-storage/local-storage.service";
import {
DeletionMode,
Scope,
} from "../../../components/local-storage/local-storage-constants";
import { OverlayContainer } from "@angular/cdk/overlay";
import { ConfigService } from "./config.service";
declare var contextPath: string;
declare var $;
export const defaultTheme = "light-theme";
export const themeLocalStorageConfig: LocalStorageEntryConfig = {
deletionMode: DeletionMode.NEVER,
key: "nm-theme",
scope: Scope.UNSCOPED,
};
@WidgetComponent("nm-config")
@Component({
selector: "nm-config",
templateUrl: "./config.component.html",
styleUrls: ["./config.component.scss"],
})
export class ConfigWidgetComponent {
@WidgetInput()
public productNo = new Subject<any>();
@WidgetConfiguration()
public configuration: WidgetConfig;
@WidgetId()
public _id;
//Variable for the template
public themes;
currentTheme: string;
private themeEntry: LocalStorageEntry;
constructor(
private localStorageService: LocalStorageService,
private overlayContainer: OverlayContainer,
private configService: ConfigService
) {}
@WidgetConfigure()
protected configureWidget(configuration: WidgetConfig) {
this.themeEntry = this.localStorageService.getLocalStorageEntryByConfig(
themeLocalStorageConfig
);
this.configService.getThemes().subscribe((themes) => {
this.themes = themes;
if (
this.themeEntry.exists() &&
this.themes
.map((entry) => entry.identifier)
.includes(this.themeEntry.value)
) {
this.currentTheme = this.themeEntry.value;
} else {
this.currentTheme = this.themes.find(
(entry) => entry.default
).identifier;
}
this.change(false);
});
}
public change(withReload) {
this.themeEntry.value = this.currentTheme;
for (let entry of this.themes) {
<any>$("body").removeClass(entry.identifier);
}
<any>$("body ").addClass(this.currentTheme);
}
}
<nm-widgetframe
[configuration]="configuration"
[header]="configuration.configuration['header']"
widgetId="{{ _id }}"
style="max-width: 50%; min-width: 700px"
[infoText]="configuration.configuration.infoText"
infoTitle="nav.administration"
infoWidth="550px"
infoPlacement="bottom"
>
<div slot="title" class="nm-widgetframe__title">
{{ "nav.administration" | translate }}
</div>
<div slot="content" class="nm-widgetframe__content">
<label class="nm-label-font">
{{ "theme.label" | translate }}
</label>
<mat-form-field>
<mat-select
placeholder=""
[(ngModel)]="currentTheme"
[required]="false"
[disabled]="false"
#themeControl="ngModel"
(ngModelChange)="change(true)"
>
<mat-option *ngFor="let theme of themes" [value]="theme.identifier">
{{ theme.label | translate }}
</mat-option>
</mat-select>
</mat-form-field>
</div>
</nm-widgetframe>
Legend
Html element with directive