@WidgetComponent
File
Implements
Metadata
| selector |
nm-price-app-add-price |
| styleUrls |
price-app-add-price.component.scss |
| templateUrl |
./price-app-add-price.component.html |
Index
Widget inputs
|
|
|
Widget outputs
|
|
|
Properties
|
|
|
Methods
|
|
|
Methods
|
onAttributesEdit
|
onAttributesEdit()
|
|
|
|
|
|
onRowsEdit
|
onRowsEdit(event: )
|
|
|
|
|
|
setIsValid
|
setIsValid(event: )
|
|
|
|
|
|
Public
articles
|
articles: any[]
|
Type : any[]
|
|
|
|
Public
clearCellSelection
|
clearCellSelection:
|
Default value : new Subject<void>()
|
|
|
|
Public
disableCellEditMode
|
disableCellEditMode:
|
Default value : new Subject<void>()
|
|
|
|
Private
editData
|
editData:
|
|
|
|
Private
emptyPrice
|
emptyPrice:
|
|
|
|
Public
emptyPriceLink
|
emptyPriceLink:
|
|
|
|
Public
endGridEditMode
|
endGridEditMode:
|
Default value : new Subject<void>()
|
|
|
|
Public
isPriceValid
|
isPriceValid: boolean
|
Type : boolean
|
Default value : false
|
|
|
|
Public
maintenanceLevel
|
maintenanceLevel: number
|
Type : number
|
|
|
|
Public
prices
|
prices: []
|
Type : []
|
Default value : []
|
|
|
|
Public
selectedLocale
|
selectedLocale: null
|
Type : null
|
Default value : null
|
|
|
import { Component, HostListener, OnInit } from "@angular/core";
import { MatDialogRef } from "@angular/material/dialog";
import { DataListConfiguration } from "../../interfaces/list.interfaces";
import { deepCopy } from "../../../components/util/util.service";
import { WidgetframeService } from "../../widgetframe/widgetframe.service";
import { Subject } from "rxjs";
import { ValidationService } from "../../../components/validation/validation.service";
import * as uriTemplates_ from "uri-templates";
import { Attributes } from "../../../components/edit-attribute";
const uriTemplates = uriTemplates_;
@Component({
selector: "nm-price-app-add-price",
templateUrl: "./price-app-add-price.component.html",
styleUrls: ["./price-app-add-price.component.scss"],
})
export class PriceAppAddPriceComponent implements OnInit {
public tableConfiguration: DataListConfiguration;
public selectedLocale = null;
public priceTableConfiguration: DataListConfiguration;
public articles: any[];
public emptyPriceLink;
public prices = [];
private editData;
private emptyPrice;
public isPriceValid: boolean = false;
public maintenanceLevel: number;
public disableCellEditMode = new Subject<void>();
public clearCellSelection = new Subject<void>();
public endGridEditMode = new Subject<void>();
constructor(
public dialogRef: MatDialogRef<PriceAppAddPriceComponent>,
private widgetframeService: WidgetframeService,
private validationService: ValidationService
) {}
ngOnInit(): void {
const priceIsland = this.priceTableConfiguration.islands[0];
const columns = deepCopy(
priceIsland.columns.filter(
(column) =>
column.type !== "hal-actions" && column.type !== "interactions"
)
);
columns.forEach((column) => {
column.filter = false;
column.sortable = false;
});
this.tableConfiguration = {
columns: columns,
attributeUrl: priceIsland.attributeUrl,
columnTemplates: priceIsland.columnTemplates,
shownAttributesSelection: true,
attributeSelectionEnabled: false,
rowSelectable: false,
rowEditable: false,
ignoreSeconds: true,
tableHeight: 400,
primaryKey: priceIsland.primaryKey,
localStorageShownAttributes: "price-app-add-price",
};
this.widgetframeService
.getData(
uriTemplates(this.emptyPriceLink).fill({
"maintenance-level-id": this.maintenanceLevel,
})
)
.subscribe((data) => {
this.emptyPrice = Attributes.mapRowAttributes(
data,
Attributes.createRowPrototype()
);
this.addRow();
});
}
save() {
this.endGridEditMode.next();
this.dialogRef.close(this.editData);
}
onRowsEdit(event) {
this.editData = event;
}
addRow() {
const price = deepCopy(this.emptyPrice);
price.pimRef = this.prices.length;
this.endGridEditMode.next();
this.clearCellSelection.next();
this.prices = [price].concat(this.prices);
}
setIsValid(event) {
this.isPriceValid = event;
}
onAttributesEdit() {
const prices = this.prices;
this.prices = [];
this.prices.push(...prices);
}
}
<nm-dialog [dialogRef]="dialogRef" class="nm-dialog" (keydown.enter)="save()">
<ng-container slot="title">
{{ "add-prices" | translate }}
</ng-container>
<ng-container slot="content">
<button
mat-mini-fab
color="primary"
class="nm-show-fields-button"
(click)="addRow()"
(keydown.enter)="$event.stopPropagation()"
>
<mat-icon>add</mat-icon>
</button>
<div style="width: 1000px">
<nm-data-list-component
[configuration]="tableConfiguration"
(editedRows)="onRowsEdit($event)"
[disableCellEditMode]="disableCellEditMode"
[clearCellSelection]="clearCellSelection"
[endGridEditMode]="endGridEditMode"
[locale]="selectedLocale"
[data]="prices"
(shownAttributes)="onAttributesEdit()"
(isValid)="setIsValid($event)"
>
</nm-data-list-component>
</div>
</ng-container>
<ng-container slot="actions">
<button mat-button type="button" (click)="dialogRef.close()">
{{ "button.cancel" | translate }}
</button>
<button
mat-raised-button
type="button"
color="primary"
(click)="save()"
[disabled]="!isPriceValid"
>
{{ "button.save" | translate }}
</button>
</ng-container>
</nm-dialog>
Legend
Html element with directive