nm-search-favorites
src/app/shared/widgets/search/favorites/search-favorites.component.ts
providers |
EditAttributeService
|
selector | nm-search-favorites |
styleUrls | search-favorites.component.scss |
templateUrl | ./search-favorites.component.html |
Widget inputs |
Widget outputs |
Properties |
|
Methods |
|
Inputs |
Outputs |
constructor(dialogService: DialogService, widgetframeService: WidgetframeService)
|
|||||||||
Parameters :
|
currentLocale
|
|
data
|
Type:
Default value: |
enableRoleBasedSearchTemplates
|
Type:
Default value: |
listsearch
|
Type:
Default value: |
placeholder
|
Default value: |
reset
|
Type:
Default value: |
searchTemplatesUri
|
|
reloadLookups
|
$event type: EventEmitter
|
template
|
$event type: EventEmitter
|
edit |
edit()
|
Returns :
void
|
Private filterTemplates |
filterTemplates()
|
Returns :
void
|
Private loadSearchFavorites |
loadSearchFavorites()
|
Returns :
void
|
ngOnDestroy |
ngOnDestroy()
|
Returns :
void
|
ngOnInit |
ngOnInit()
|
Returns :
void
|
onInputEvent | ||||||
onInputEvent($event: FormEventPayload)
|
||||||
Parameters :
Returns :
void
|
Public resetSelect |
resetSelect()
|
Returns :
void
|
valueChanged |
valueChanged()
|
Returns :
void
|
Public filterCtrl |
filterCtrl:
|
Type : FormControl
|
Default value : new FormControl()
|
Public filteredTemplates |
filteredTemplates:
|
Public form |
form:
|
Private formData |
formData:
|
Type : any
|
Default value : {}
|
Private resentChanged |
resentChanged:
|
Type : boolean
|
Public templates |
templates:
|
Type : Template[]
|
Private unsubscribe |
unsubscribe:
|
Default value : NgUnsubscribe.create()
|
Public value |
value:
|
import { EditAttributeService } from "../../../components/edit-attribute/edit-attribute.service";
import {
Component,
EventEmitter,
Input,
OnInit,
OnDestroy,
Output,
} from "@angular/core";
import { FormEventPayload } from "../advanced/search-advanced.component";
import { FormControl, FormGroup } from "@angular/forms";
import { filter, take, takeUntil } from "rxjs/operators";
import { NgUnsubscribe } from "../../../ng-unsubscribe";
import { ReplaySubject, Subject } from "rxjs";
import { MatDialog, MatDialogRef } from "@angular/material/dialog";
import { SearchFavoritesDialogComponent } from "./dialog/search-favorites-dialog.component";
import { WidgetframeService } from "../../widgetframe/widgetframe.service";
import { DialogService } from "../../../../shared/components/dialog/dialog.service";
export interface Template {
identifier: string;
text: string;
}
@Component({
selector: "nm-search-favorites",
templateUrl: "./search-favorites.component.html",
styleUrls: ["./search-favorites.component.scss"],
providers: [EditAttributeService],
})
export class SearchFavoritesComponent implements OnInit, OnDestroy {
@Input() public reset = new Subject();
@Input() public currentLocale;
@Input() public searchTemplatesUri;
@Input() public placeholder = "table.head.searchfavorite";
@Input() public data: any = new Subject();
@Output() public template = new EventEmitter<any>();
@Output() public reloadLookups = new EventEmitter<any>();
@Input() public listsearch: boolean = false;
@Input() public enableRoleBasedSearchTemplates: boolean = false;
public form;
public filteredTemplates;
public templates: Template[];
public value;
private resentChanged: boolean;
private formData: any = {};
private unsubscribe = NgUnsubscribe.create();
public filterCtrl: FormControl = new FormControl();
constructor(
private dialogService: DialogService,
private widgetframeService: WidgetframeService
) {}
private loadSearchFavorites() {
this.widgetframeService
.getData(this.searchTemplatesUri)
.subscribe((value) => {
this.templates = value._embedded.templates;
this.filterTemplates();
});
}
ngOnInit(): void {
this.reloadLookups
.pipe(takeUntil(this.unsubscribe))
.subscribe(() => this.loadSearchFavorites());
this.data.pipe(takeUntil(this.unsubscribe)).subscribe((data) => {
this.formData = data;
});
this.filterCtrl.valueChanges
.pipe(takeUntil(this.unsubscribe))
.subscribe(() => this.filterTemplates());
this.loadSearchFavorites();
this.form = new FormGroup({
searchfavorites: new FormControl(""),
});
this.form.valueChanges
.asObservable()
.pipe(takeUntil(this.unsubscribe))
.subscribe(() => {
this.resentChanged = true;
});
this.reset
.pipe(takeUntil(this.unsubscribe))
.subscribe(() => this.resetSelect());
}
private filterTemplates() {
if (!this.filterCtrl.value) {
this.filteredTemplates = this.templates;
return;
}
this.filteredTemplates = this.templates.filter(
(entry) =>
entry.text
.toLowerCase()
.indexOf(this.filterCtrl.value.toLowerCase()) !== -1
);
}
onInputEvent($event: FormEventPayload) {}
edit() {
let dialogRef = this.dialogService.open(SearchFavoritesDialogComponent, {
autoFocus: true,
minWidth: "800px",
height: "760px",
});
dialogRef.componentInstance.searchTemplatesUri = this.searchTemplatesUri;
dialogRef.componentInstance.formData = this.formData;
dialogRef.componentInstance.isListSearch = this.listsearch;
dialogRef.componentInstance.hasCreateRoleBasedTemplate = this.enableRoleBasedSearchTemplates;
dialogRef.componentInstance.dialogService = this.dialogService;
// dialogRef.componentInstance['selectedFavorite'] = selectedFavorite
// dialogRef.componentInstance.infoText = "infoText.search.favorites";
dialogRef.componentInstance.onFavoriteChange.subscribe((data) => {
this.reloadLookups.emit(["searchfavorites"]);
});
}
ngOnDestroy(): void {
this.unsubscribe.destroy();
}
public resetSelect() {
if (!this.resentChanged) {
this.value = null;
this.form.patchValue({ searchfavorites: null });
}
}
valueChanged() {
if (this.value) {
this.widgetframeService
.getData(this.searchTemplatesUri + "/" + this.value)
.subscribe((template) => {
this.template.emit(template);
this.resentChanged = false;
});
}
}
}
<form [formGroup]="form" class="favorite-input" autocomplete="off">
<div class="form-input" style="width: 68%; margin-top: 10px">
<mat-form-field>
<mat-select
[placeholder]="placeholder | translate"
[(value)]="value"
(valueChange)="valueChanged()"
>
<mat-option>
<ngx-mat-select-search
[formControl]="filterCtrl"
placeholderLabel="{{ 'placeholder.search' | translate }}"
noEntriesFoundLabel="{{ 'select.no.options' | translate }}"
(keydown.escape)="selectSearch.matSelect.focus()"
#selectSearch
></ngx-mat-select-search>
</mat-option>
<mat-option></mat-option>
<mat-option
*ngFor="let value of filteredTemplates"
[value]="value.identifier"
>{{ value.text }}</mat-option
>
</mat-select>
</mat-form-field>
</div>
</form>
<button class="nm-edit-favorites-button" mat-stroked-button (click)="edit()">
{{ "label.edit" | translate }}
</button>
<div style="clear: both"></div>