@WidgetComponent
File
Description
This class represents ModuleListComponent.
Implements
Metadata
selector |
nm-modules |
styleUrls |
modules.component.scss |
templateUrl |
./modules.component.html |
Index
Widget inputs
|
|
|
Widget outputs
|
|
Properties
|
|
Methods
|
|
Constructor
constructor(moduleService: ModuleService, currentLocaleService: CurrentLocaleService, halService: HalService, _notificationService: CustomNotificationService, translateService: TranslateService, dialog: MatDialog, dragulaService: DragulaService)
|
|
Parameters :
Name |
Type |
Optional |
moduleService |
ModuleService
|
no
|
currentLocaleService |
CurrentLocaleService
|
no
|
halService |
HalService
|
no
|
_notificationService |
CustomNotificationService
|
no
|
translateService |
TranslateService
|
no
|
dialog |
MatDialog
|
no
|
dragulaService |
DragulaService
|
no
|
|
Methods
Protected
configureWidget
|
configureWidget(configuration: WidgetConfig)
|
Decorators : WidgetConfigure
|
|
|
deleteCustomTile
|
deleteCustomTile(module: )
|
|
|
editCustomTile
|
editCustomTile(module: )
|
|
|
openTilePopup
|
openTilePopup(module: )
|
|
|
storeLocalTiles
|
storeLocalTiles(toSave: )
|
|
|
Public
_id
|
_id:
|
Decorators : WidgetId
|
|
Public
dialog
|
dialog: MatDialog
|
Type : MatDialog
|
|
Public
disableAddModule
|
disableAddModule: string
|
Type : string
|
|
Public
formData
|
formData: any
|
Type : any
|
|
Public
formData_rootconfig
|
formData_rootconfig: any
|
Type : any
|
|
Public
productNo
|
productNo:
|
Default value : new Subject<any>()
|
Decorators : WidgetInput
|
|
import { tap, map, mergeMap } from "rxjs/operators";
import { Component, OnInit } from "@angular/core";
import { ModuleService } from "./module.service";
import { Subject } from "rxjs";
import { WidgetConfig } from "../../widget.configuration";
import {
WidgetComponent,
WidgetConfiguration,
WidgetConfigure,
WidgetId,
WidgetInput,
} from "../../widget.metadata";
import { CurrentLocaleService } from "../../../components/i18n/currentLocale.service";
import { MatDialog } from "@angular/material/dialog";
import { AddModuleDialogComponent } from "./addModuleDialog.component";
import { HalService } from "../../../components/hal/hal.service";
import { CustomNotificationService } from "../../../components/notification/customnotification.service";
import { Module } from "./module";
import { TranslateService } from "@ngx-translate/core";
import { ConfirmationDialogComponent } from "../../../components/dialog/confirmationDialog.component";
import { DragulaService } from "ng2-dragula";
import { deepCopy } from "../../../components/util";
import { BaseConfiguration } from "../../widgetframe/widgetframe.component";
declare var contextPath: string;
export interface ModulesConfiguration extends BaseConfiguration {
formData: any;
formData_rootconfig: any;
disableAddModule: boolean;
}
/**
* This class represents ModuleListComponent.
*/
@WidgetComponent("nm-modules")
@Component({
selector: "nm-modules",
templateUrl: "./modules.component.html",
styleUrls: ["./modules.component.scss"],
})
export class ModulesComponentWidget implements OnInit {
@WidgetInput()
public productNo = new Subject<any>();
@WidgetConfiguration()
public configuration: WidgetConfig<ModulesConfiguration>;
@WidgetId()
public _id;
public modules: Module[];
public tempModule: Module;
public formData: any;
public formData_rootconfig: any;
public currentlocale: string;
public title: string;
public infoText: string;
public wikiLink: string;
public disableAddModule: string;
constructor(
private moduleService: ModuleService,
private currentLocaleService: CurrentLocaleService,
private halService: HalService,
private _notificationService: CustomNotificationService,
private translateService: TranslateService,
public dialog: MatDialog,
private dragulaService: DragulaService
) {}
@WidgetConfigure()
protected configureWidget(configuration: WidgetConfig<ModulesConfiguration>) {
this.title = configuration.configuration.title;
this.formData = configuration.configuration.formData;
this.formData_rootconfig = configuration.configuration.formData_rootconfig;
this.infoText = configuration.configuration.infoText;
this.wikiLink = this.configuration.configuration.wikiLink;
if (configuration.configuration.disableAddModule) {
this.disableAddModule = "--disable";
}
}
ngOnInit() {
const bag: any = this.dragulaService.find("bag");
if (bag !== undefined) this.dragulaService.destroy("bag");
this.dragulaService.createGroup("bag", {
accepts: (el, target, source, sibling) => {
// From the doc "The sibling can be null, which would mean that the element would be placed as the last element in the container."
// This means that if the sibling is null the user is trying to place the element last => after the add, which we want to prevent
if (sibling == null) {
return false;
}
return true;
},
moves: (el, source, handle, sibling) => {
// Dont allow moving the nm-add-new-app
if (el.classList.contains("nm-add-new-app")) {
return false;
}
return true;
},
});
this.dragulaService.dropModel().subscribe((event: any) => {
const ids = event?.targetModel?.map((module) => module.id);
this.moduleService.updateModuleOrder(ids).subscribe();
});
this.currentLocaleService
.getCurrentLocale()
.pipe(
tap((locale) => {
this.currentlocale = locale;
}),
mergeMap((locale) => this.moduleService.getModules())
)
.subscribe(
(data) => {
let links = data._links;
for (let module in data._embedded.modules) {
if (data._embedded.modules[module].image !== undefined) {
if (data._embedded.modules[module].image.startsWith("data")) {
data._embedded.modules[module].image =
data._embedded.modules[module].image;
} else {
data._embedded.modules[module].image =
contextPath + data._embedded.modules[module].image;
}
}
}
this.modules = data._embedded.modules;
},
(err) => console.error(err)
);
}
storeLocalTiles(toSave) {
if (toSave && toSave["_actions"] != undefined) {
this.halService
.execute("edit", toSave["_actions"]["edit"])
.pipe(map((response) => <any>response))
.subscribe((response) => {
this._notificationService.fromJson(response.response);
this.currentLocaleService.setLocale(this.currentlocale);
});
} else {
this.moduleService
.postModule("/api/portal/modules", JSON.stringify(toSave))
.subscribe((response) => {
this._notificationService.fromJson(response);
this.currentLocaleService.setLocale(this.currentlocale);
});
}
}
editCustomTile(module) {
this.openTilePopup(module);
}
deleteCustomTile(module) {
let dialogRef = this.dialog.open(ConfirmationDialogComponent);
dialogRef.componentInstance["title"] =
this.translateService.instant("hl.confirmation");
dialogRef.componentInstance["message"] = this.translateService.instant(
"message.confirmation.delete"
);
dialogRef.componentInstance["buttonAcceptTitle"] =
this.translateService.instant("button.accept");
dialogRef.componentInstance["buttonCancelTitle"] =
this.translateService.instant("button.cancel");
dialogRef.afterClosed().subscribe((confirmed) => {
if (confirmed) {
this.halService
.execute("delete", module._actions.delete)
.subscribe((response) => {
this._notificationService.fromJson(response.response);
if (response.response.body.level === "SUCCESS") {
this.modules.splice(
this.modules.findIndex((mod) => mod === module),
1
);
}
});
}
});
}
openTilePopup(module) {
let dialogRef = this.dialog.open(AddModuleDialogComponent, {
minWidth: "550px",
height: "800px",
});
dialogRef.componentInstance["title"] =
module !== null
? this.translateService.instant("module.edit")
: this.translateService.instant("module.create");
dialogRef.componentInstance["module"] =
module !== undefined ? module : <Module>{};
dialogRef.componentInstance["form"] = this.formData;
dialogRef.componentInstance["rootconfig"] = this.formData_rootconfig;
dialogRef.afterClosed().subscribe((module) => {
if (module) {
this.storeLocalTiles(module);
}
});
}
}
<nm-widgetframe
[header]="configuration.configuration['header']"
widgetId="{{ _id }}"
[configuration]="configuration"
[infoTitle]="title"
[infoText]="infoText"
[infoPlacement]="'bottom'"
[wikiLink]="wikiLink"
>
<div slot="title" class="nm-widgetframe__title">
{{ configuration.configuration["title"] | translate }}
</div>
<div slot="content" class="nm-widgetframe__content">
<div
class="nm-module__container"
[dragula]="'bag'"
[(dragulaModel)]="modules"
>
<mat-card
*ngFor="let module of modules"
layout=""
class="nm-module__element mat-elevation-z0"
[ngClass]="{ disabled: module.active === false }"
>
<mat-card-content>
<img
*ngIf="module.image"
src="{{ module.image }}"
mat-card-image
alt="{{ module.title }}"
/>
<div
*ngIf="!module.image && module.linkType === 'app' && module.icon"
class="nm-app-icon-container"
>
<i class="material-icons nm-app-icon"> {{ module.icon }}</i>
</div>
<mat-card-title>{{ module.title }}</mat-card-title>
<p>{{ module.description }}</p>
</mat-card-content>
<mat-card-actions
*ngIf="
module._actions && module._actions.links;
then actionLinksTemplate;
else moduleLinksTemplate
"
>
</mat-card-actions>
<ng-template #actionLinksTemplate>
<ng-container
*ngIf="
!module.linkType || module.linkType !== 'app';
else appLinkTemplate
"
>
<mat-card-actions align="end">
<button
color="primary"
class="nm-module__actionLink nm-noUppercase"
mat-button
*ngFor="let link of module._actions.links"
[nm-action]="link"
action-name="links"
layout-align="end-right"
>
<mat-icon color="accent">input</mat-icon>
{{ link.title }}
</button>
</mat-card-actions>
</ng-container>
</ng-template>
<ng-template #moduleLinksTemplate>
<ng-container
*ngIf="
!module.linkType || module.linkType !== 'app';
else appLinkTemplate
"
>
<mat-card-actions align="end">
<button
color="primary"
class="nm-noUppercase"
mat-button
*ngFor="let link of module.links"
[nm-action]="link"
action-name="links"
>
<mat-icon>input</mat-icon>
{{ link.title }}
</button>
</mat-card-actions>
</ng-container>
</ng-template>
<ng-template #appLinkTemplate>
<mat-card-actions align="end">
<a
mat-button
[routerLink]="module.links[0].href"
color="primary"
class="nm-floating-links nm-noUppercase"
layout-align="end-right"
>
<mat-icon color="accent">input</mat-icon>
<span class="nm-floating-links-text">
{{ module.links[0].title }}
</span>
</a>
</mat-card-actions>
</ng-template>
<div class="nm-gidlist-actionBox" *ngIf="module._actions?.edit != null">
<a (click)="editCustomTile(module)">
<span class="material-icons">
<mat-icon role="img" class="material-icons mat-icon">
settings</mat-icon
>
</span>
</a>
</div>
<div
class="nm-gidlist-actionBox nm-gidlist-actionBox-2"
*ngIf="module._actions?.delete != null"
>
<a (click)="deleteCustomTile(module)">
<span class="material-icons">
<mat-icon role="img" class="material-icons mat-icon"
>close</mat-icon
>
</span>
</a>
</div>
</mat-card>
<div
(click)="openTilePopup(null)"
class="nm-add-new-app {{ disableAddModule }}"
>
<i class="material-icons">add</i>
</div>
</div>
</div>
</nm-widgetframe>
Legend
Html element with directive