refactor filter input field into standalone component
parent
0255e63c3a
commit
f4a9ef7a9d
|
@ -5,7 +5,8 @@
|
||||||
</mat-button-toggle>
|
</mat-button-toggle>
|
||||||
</mat-button-toggle-group>
|
</mat-button-toggle-group>
|
||||||
<button mat-icon-button class="add-btn">
|
<button mat-icon-button class="add-btn">
|
||||||
<mat-icon svgIcon="{{addButton.svgIcon}}" title="addButton.tooltip"
|
<mat-icon svgIcon="{{addButton.svgIcon}}"
|
||||||
|
title="{{addButton.tooltip}}"
|
||||||
(click)="add()"></mat-icon>
|
(click)="add()"></mat-icon>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
.list-header {
|
||||||
|
width: 100%;
|
||||||
|
padding-bottom: 20px;
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
<div class="input-group list-header">
|
||||||
|
<input id="search-field"
|
||||||
|
type="text" #query class="form-control"
|
||||||
|
(keyup.enter)="emitSearch()"
|
||||||
|
[formControl]="searchTerm">
|
||||||
|
<span class="input-group-btn">
|
||||||
|
<button class="btn btn-default" type="button"
|
||||||
|
(click)="emitSearch()">
|
||||||
|
Suchen
|
||||||
|
</button>
|
||||||
|
</span>
|
||||||
|
</div>
|
|
@ -0,0 +1,43 @@
|
||||||
|
import {Component, EventEmitter, Input, Output} from '@angular/core';
|
||||||
|
import {Location} from '@angular/common';
|
||||||
|
import {ActivatedRoute} from '@angular/router';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'cc-list-search',
|
||||||
|
templateUrl: './search-field.component.html',
|
||||||
|
styleUrls: ['./search-field.component.css']
|
||||||
|
})
|
||||||
|
export class SearchFieldComponent {
|
||||||
|
|
||||||
|
@Input() searchTerm;
|
||||||
|
|
||||||
|
@Output() executeSearch = new EventEmitter();
|
||||||
|
|
||||||
|
@Output() searchTermStream = new EventEmitter();
|
||||||
|
|
||||||
|
constructor(private route:ActivatedRoute,
|
||||||
|
private location: Location) {
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
const paramsObservable = this.route.queryParams
|
||||||
|
.map(params => decodeURI(params['query'] || ''))
|
||||||
|
.do(query => this.searchTerm.setValue(query));
|
||||||
|
|
||||||
|
const searchTermObservable = this.searchTerm.valueChanges
|
||||||
|
.debounceTime(400)
|
||||||
|
.do(query => this.adjustBrowserUrl(query));
|
||||||
|
this.searchTermStream.emit({params: paramsObservable, searchTerm: searchTermObservable});
|
||||||
|
}
|
||||||
|
|
||||||
|
emitSearch() {
|
||||||
|
this.executeSearch.emit();
|
||||||
|
}
|
||||||
|
|
||||||
|
adjustBrowserUrl(queryString = '') {
|
||||||
|
const absoluteUrl = this.location.path().split('?')[0];
|
||||||
|
const queryPart = queryString !== '' ? `query=${queryString}` : '';
|
||||||
|
|
||||||
|
this.location.replaceState(absoluteUrl, queryPart);
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,26 +8,15 @@
|
||||||
(openAddFrom)="openNewDecorationForm()">
|
(openAddFrom)="openNewDecorationForm()">
|
||||||
</cc-list-filter>
|
</cc-list-filter>
|
||||||
|
|
||||||
<div class="input-group list-header">
|
<cc-list-search [searchTerm]="searchTerm"
|
||||||
<input id="search-tasks"
|
(searchTermStream)="initObservable($event)"
|
||||||
type="text" #query class="form-control"
|
(executeSearch)="filterDecorations()">
|
||||||
(keyup.enter)="filterDecorations()"
|
</cc-list-search>
|
||||||
[formControl]="searchTerm">
|
|
||||||
<span class="input-group-btn">
|
|
||||||
<button class="btn btn-default" type="button"
|
|
||||||
(click)="filterDecorations()">
|
|
||||||
Suchen
|
|
||||||
</button>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<decoration-item *ngFor="let decoration of decorations$ | async"
|
|
||||||
[decoration]="decoration"
|
|
||||||
(decorationDelete)="deleteDecoration(decoration)"
|
|
||||||
(decorationSelected)="selectDecoration($event)"
|
|
||||||
[selected]="decoration._id == selectedDecorationId">
|
|
||||||
</decoration-item>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
<decoration-item *ngFor="let decoration of decorations$ | async"
|
||||||
|
[decoration]="decoration"
|
||||||
|
(decorationDelete)="deleteDecoration(decoration)"
|
||||||
|
(decorationSelected)="selectDecoration($event)"
|
||||||
|
[selected]="decoration._id == selectedDecorationId">
|
||||||
|
</decoration-item>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import {Component, OnInit} from '@angular/core';
|
import {Component, OnInit} from '@angular/core';
|
||||||
import {Location} from '@angular/common';
|
|
||||||
|
|
||||||
import {FormControl} from '@angular/forms';
|
import {FormControl} from '@angular/forms';
|
||||||
import {ActivatedRoute, Router} from '@angular/router';
|
import {ActivatedRoute, Router} from '@angular/router';
|
||||||
|
@ -29,22 +28,15 @@ export class DecorationListComponent implements OnInit {
|
||||||
|
|
||||||
constructor(private decorationService: DecorationService,
|
constructor(private decorationService: DecorationService,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute) {
|
||||||
private location: Location) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.decorations$ = this.decorationService.decorations$;
|
this.decorations$ = this.decorationService.decorations$;
|
||||||
|
}
|
||||||
|
|
||||||
const paramsStream = this.route.queryParams
|
initObservable(observables: any) {
|
||||||
.map(params => decodeURI(params['query'] || ''))
|
Observable.merge(observables.params as Observable<string>, observables.searchTerm)
|
||||||
.do(query => this.searchTerm.setValue(query));
|
|
||||||
|
|
||||||
const searchTermStream = this.searchTerm.valueChanges
|
|
||||||
.debounceTime(400)
|
|
||||||
.do(query => this.adjustBrowserUrl(query));
|
|
||||||
|
|
||||||
Observable.merge(paramsStream, searchTermStream)
|
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.switchMap(query => this.decorationService.findDecorations(query, this.radioModel))
|
.switchMap(query => this.decorationService.findDecorations(query, this.radioModel))
|
||||||
.subscribe();
|
.subscribe();
|
||||||
|
@ -79,12 +71,4 @@ export class DecorationListComponent implements OnInit {
|
||||||
this.radioModel = UIHelpers.toggleReleaseButton(this.radioModel, group);
|
this.radioModel = UIHelpers.toggleReleaseButton(this.radioModel, group);
|
||||||
this.decorations$ = this.decorationService.findDecorations(this.searchTerm.value, this.radioModel);
|
this.decorations$ = this.decorationService.findDecorations(this.searchTerm.value, this.radioModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
adjustBrowserUrl(queryString = '') {
|
|
||||||
const absoluteUrl = this.location.path().split('?')[0];
|
|
||||||
const queryPart = queryString !== '' ? `query=${queryString}` : '';
|
|
||||||
|
|
||||||
this.location.replaceState(absoluteUrl, queryPart);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import {EditDecorationComponent} from './edit-decoration/edit-decoration.compone
|
||||||
import {ModuleWithProviders} from '@angular/core';
|
import {ModuleWithProviders} from '@angular/core';
|
||||||
import {DecorationItemComponent} from './decoration-list/decoration-item.component';
|
import {DecorationItemComponent} from './decoration-list/decoration-item.component';
|
||||||
import {ListFilterComponent} from '../common/user-interface/list-filter/list-filter.component';
|
import {ListFilterComponent} from '../common/user-interface/list-filter/list-filter.component';
|
||||||
|
import {SearchFieldComponent} from '../common/user-interface/search-field/search-field.component';
|
||||||
|
|
||||||
export const decorationsRoutes: Routes = [{
|
export const decorationsRoutes: Routes = [{
|
||||||
path: '', component: DecorationComponent,
|
path: '', component: DecorationComponent,
|
||||||
|
@ -29,5 +30,5 @@ export const decorationsRoutes: Routes = [{
|
||||||
export const decorationRoutesModule: ModuleWithProviders = RouterModule.forChild(decorationsRoutes);
|
export const decorationRoutesModule: ModuleWithProviders = RouterModule.forChild(decorationsRoutes);
|
||||||
|
|
||||||
export const decorationsRoutingComponents = [DecorationItemComponent, DecorationComponent, DecorationListComponent,
|
export const decorationsRoutingComponents = [DecorationItemComponent, DecorationComponent, DecorationListComponent,
|
||||||
EditDecorationComponent, ListFilterComponent];
|
EditDecorationComponent, ListFilterComponent, SearchFieldComponent];
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,3 @@
|
||||||
.select-list {
|
.select-list {
|
||||||
padding: 20px 2% 0 5%;
|
padding: 20px 2% 0 5%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.list-header {
|
|
||||||
width: 100%;
|
|
||||||
padding-bottom: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.add-btn {
|
|
||||||
margin-right: 16px;
|
|
||||||
margin-top: -3px;
|
|
||||||
float: right;
|
|
||||||
}
|
|
||||||
|
|
||||||
:host/deep/.mat-icon {
|
|
||||||
height: 32px;
|
|
||||||
width: 32px;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue