nm-list-cell-chip-select
src/app/shared/widgets/data-list/list-cell-chip-select/list-cell-chip-select-widget.component.ts
CellWidget
OnDestroy
OnChanges
selector | nm-list-cell-chip-select |
templateUrl | ./list-cell-chip-select-widget.component.html |
Widget inputs |
Widget outputs |
Properties |
|
Methods |
|
constructor(cdr: ChangeDetectorRef)
|
||||||
Parameters :
|
Protected configureWidget | ||||||
configureWidget(configuration: WidgetConfig)
|
||||||
Decorators : WidgetConfigure
|
||||||
Parameters :
Returns :
void
|
ngOnChanges | ||||||
ngOnChanges(changes: SimpleChanges)
|
||||||
Parameters :
Returns :
void
|
ngOnDestroy |
ngOnDestroy()
|
Returns :
void
|
onValueChange | ||||
onValueChange(event: )
|
||||
Parameters :
Returns :
void
|
Private setOptionValueAndDescription | ||||
setOptionValueAndDescription(selectedOption: )
|
||||
Parameters :
Returns :
void
|
Private updateColor |
updateColor()
|
Returns :
void
|
Public _id |
_id:
|
Decorators : WidgetId
|
Public cellComponent |
cellComponent:
|
Type : IgxGridCell
|
Public chipColors |
chipColors:
|
Type : any
|
Public color |
color:
|
Type : string
|
Public columnDefinition |
columnDefinition:
|
Type : Column
|
Public configuration |
configuration:
|
Type : WidgetConfig
|
Decorators : WidgetConfiguration
|
Public description |
description:
|
Type : string
|
Public identifier |
identifier:
|
Type : string
|
Public isEditing |
isEditing:
|
Type : boolean
|
Public lookupValues |
lookupValues:
|
Type : any
|
Default value : new BehaviorSubject<any>([])
|
Decorators : WidgetInput
|
Public row |
row:
|
Type : any
|
Private unsubscribe |
unsubscribe:
|
Default value : NgUnsubscribe.create()
|
Public value |
value:
|
Type : any
|
import {
ChangeDetectorRef,
Component,
OnChanges,
OnDestroy,
SimpleChanges,
} from "@angular/core";
import { ReplaySubject, BehaviorSubject } from "rxjs";
import { IgxGridCell } from "@infragistics/igniteui-angular";
import { takeUntil } from "rxjs/operators";
import { NgUnsubscribe } from "../../../ng-unsubscribe";
import {
WidgetComponent,
WidgetConfiguration,
WidgetConfigure,
WidgetId,
WidgetInput,
} from "../../widget.metadata";
import { CellWidget } from "../../../components/list-cell";
import { WidgetConfig } from "../../widget.configuration";
import { Column } from "../../interfaces/list.interfaces";
@WidgetComponent("nm-list-cell-chip-select")
@Component({
selector: "nm-list-cell-chip-select",
templateUrl: "./list-cell-chip-select-widget.component.html",
})
export class ListCellChipSelect implements CellWidget, OnDestroy, OnChanges {
@WidgetId()
public _id;
@WidgetConfiguration()
public configuration: WidgetConfig;
public value: any;
public row: any;
public isEditing: boolean;
public cellComponent: IgxGridCell;
public columnDefinition: Column;
public chipColors: any;
public identifier: string;
public description: string;
public color: string;
private unsubscribe = NgUnsubscribe.create();
constructor(private cdr: ChangeDetectorRef) {}
ngOnChanges(changes: SimpleChanges) {
if (changes.value) {
let value = this.value || this.cellComponent.value;
this.identifier = value.source[0].value;
this.description = value.source[0].description;
this.updateColor();
}
}
private updateColor() {
if (this.chipColors && this.identifier) {
this.color = this.chipColors[this.identifier];
} else {
this.color = null;
}
this.cdr.markForCheck();
}
@WidgetInput()
public lookupValues: any = new BehaviorSubject<any>([]);
@WidgetConfigure()
protected configureWidget(configuration: WidgetConfig) {
this.chipColors = configuration.configuration.chipColors;
this.lookupValues.pipe(takeUntil(this.unsubscribe)).subscribe((data) => {
this.setOptionValueAndDescription(
this.value ? this.value.source[0].value : this.value
);
});
}
onValueChange(event) {
this.setOptionValueAndDescription(event.value);
}
private setOptionValueAndDescription(selectedOption) {
this.lookupValues.value.forEach((option) => {
if (
option.identifier !== selectedOption &&
option.description !== selectedOption
) {
return;
}
this.identifier = option.identifier;
this.description = option.description;
this.updateColor();
this.value = {
identifier: this.columnDefinition.field,
description: this.description,
value: this.description,
tooltip: this.description,
type: "LOOKUP",
source: [{ value: this.identifier, description: this.description }],
};
this.cellComponent.editValue = this.value;
});
}
ngOnDestroy() {
if (this.unsubscribe) {
this.unsubscribe.destroy();
}
}
}
<div *ngIf="!isEditing">
<nm-chip [content]="description" [modifier]="color" [toUpperCase]="false">
</nm-chip>
</div>
<div *ngIf="isEditing">
<mat-form-field>
<mat-select
style="width: 100%"
(selectionChange)="onValueChange($event)"
[(ngModel)]="identifier"
>
<mat-select-trigger>
<nm-chip
[content]="description"
[modifier]="color"
[toUpperCase]="false"
>
</nm-chip>
</mat-select-trigger>
<mat-option
*ngFor="let option of lookupValues | async"
[value]="option.identifier"
>{{ option.description | translate }}</mat-option
>
</mat-select>
</mat-form-field>
</div>