Merge pull request #15 from Quantum-P3/feature/US-18

Feature/us 18
This commit is contained in:
Eduardo Quiros 2021-07-11 02:37:14 +00:00 committed by GitHub
commit a298acc976
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 2 deletions

View File

@ -29,6 +29,12 @@
</div> </div>
<div class="table-responsive" id="entities" *ngIf="categorias && categorias.length > 0"> <div class="table-responsive" id="entities" *ngIf="categorias && categorias.length > 0">
<form class="ds-form">
<div class="input-group">
<div class="input-group-addon"><i class="glyphicon glyphicon-search"></i></div>
<input type="text" class="form-control" name="searchString" placeholder="Type to search..." [(ngModel)]="searchString" />
</div>
</form>
<table class="table table-striped" aria-describedby="page-heading"> <table class="table table-striped" aria-describedby="page-heading">
<thead> <thead>
<tr> <tr>
@ -39,7 +45,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr *ngFor="let categoria of categorias; trackBy: trackId" data-cy="entityTable"> <tr *ngFor="let categoria of categorias | filter: 'nombre':searchString; trackBy: trackId" data-cy="entityTable">
<td> <td>
<a [routerLink]="['/categoria', categoria.id, 'view']">{{ categoria.id }}</a> <a [routerLink]="['/categoria', categoria.id, 'view']">{{ categoria.id }}</a>
</td> </td>

View File

@ -13,8 +13,11 @@ import { CategoriaDeleteDialogComponent } from '../delete/categoria-delete-dialo
export class CategoriaComponent implements OnInit { export class CategoriaComponent implements OnInit {
categorias?: ICategoria[]; categorias?: ICategoria[];
isLoading = false; isLoading = false;
public searchString: string;
constructor(protected categoriaService: CategoriaService, protected modalService: NgbModal) {} constructor(protected categoriaService: CategoriaService, protected modalService: NgbModal) {
this.searchString = '';
}
loadAll(): void { loadAll(): void {
this.isLoading = true; this.isLoading = true;
@ -31,6 +34,7 @@ export class CategoriaComponent implements OnInit {
} }
ngOnInit(): void { ngOnInit(): void {
this.searchString = '';
this.loadAll(); this.loadAll();
} }

View File

@ -0,0 +1,18 @@
import { Pipe, PipeTransform, Injectable } from '@angular/core';
@Pipe({
name: 'filter',
})
@Injectable()
export class FilterPipe implements PipeTransform {
transform(items: any[], field: string, value: string): any[] {
if (!items) {
return [];
}
if (!field || !value) {
return items;
}
return items.filter(singleItem => singleItem[field].toLowerCase().includes(value.toLowerCase()));
}
}

View File

@ -12,6 +12,7 @@ import { FormatMediumDatePipe } from './date/format-medium-date.pipe';
import { SortByDirective } from './sort/sort-by.directive'; import { SortByDirective } from './sort/sort-by.directive';
import { SortDirective } from './sort/sort.directive'; import { SortDirective } from './sort/sort.directive';
import { ItemCountComponent } from './pagination/item-count.component'; import { ItemCountComponent } from './pagination/item-count.component';
import { FilterPipe } from './pipes/filter';
@NgModule({ @NgModule({
imports: [SharedLibsModule], imports: [SharedLibsModule],
@ -27,6 +28,7 @@ import { ItemCountComponent } from './pagination/item-count.component';
SortByDirective, SortByDirective,
SortDirective, SortDirective,
ItemCountComponent, ItemCountComponent,
FilterPipe,
], ],
exports: [ exports: [
SharedLibsModule, SharedLibsModule,
@ -41,6 +43,7 @@ import { ItemCountComponent } from './pagination/item-count.component';
SortByDirective, SortByDirective,
SortDirective, SortDirective,
ItemCountComponent, ItemCountComponent,
FilterPipe,
], ],
}) })
export class SharedModule {} export class SharedModule {}