From fb28c63867fac4b0f32d06861377a6d411ef6a11 Mon Sep 17 00:00:00 2001 From: FyloZ Date: Thu, 1 Apr 2021 17:29:34 -0400 Subject: [PATCH] =?UTF-8?q?Correction=20de=20l'erreur=20de=20d=C3=A9tectio?= =?UTF-8?q?n=20des=20changements=20lors=20d'une=20recherche=20dans=20la=20?= =?UTF-8?q?liste=20des=20recettes.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../colors/pages/list/list.component.html | 17 ++++++-- .../colors/pages/list/list.component.ts | 39 ++++++++++++------- 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/app/modules/colors/pages/list/list.component.html b/src/app/modules/colors/pages/list/list.component.html index 6c00852..3d536af 100644 --- a/src/app/modules/colors/pages/list/list.component.html +++ b/src/app/modules/colors/pages/list/list.component.html @@ -1,8 +1,17 @@
Recherche - - @@ -13,7 +22,7 @@ @@ -84,6 +93,6 @@ - + diff --git a/src/app/modules/colors/pages/list/list.component.ts b/src/app/modules/colors/pages/list/list.component.ts index 68fd86e..5000b6a 100644 --- a/src/app/modules/colors/pages/list/list.component.ts +++ b/src/app/modules/colors/pages/list/list.component.ts @@ -1,4 +1,4 @@ -import {Component} from '@angular/core' +import {ChangeDetectorRef, Component} from '@angular/core' import {ErrorHandlingComponent} from '../../../shared/components/subscribing.component' import {RecipeService} from '../../services/recipe.service' import {EmployeePermission} from '../../../shared/model/employee' @@ -13,17 +13,18 @@ import {ErrorModel, ErrorService} from '../../../shared/service/error.service' styleUrls: ['./list.component.sass'] }) export class ListComponent extends ErrorHandlingComponent { - recipes$ = this.recipeService.allSortedByCompany + recipes: { company: string, recipes: Recipe[] }[] = [] tableCols = ['name', 'description', 'color', 'gloss', 'sample', 'iconNotApproved', 'buttonView', 'buttonEdit'] - searchQuery = "" + searchQuery = '' panelForcedExpanded = false - recipesHidden = [] + hiddenRecipes = [] handledErrorModels: ErrorModel[] constructor( private recipeService: RecipeService, private accountService: AccountService, + private cdRef: ChangeDetectorRef, errorService: ErrorService, router: Router, activatedRoute: ActivatedRoute @@ -32,22 +33,27 @@ export class ListComponent extends ErrorHandlingComponent { } ngOnInit() { - super.ngOnInit(); + super.ngOnInit() + + this.subscribe( + this.recipeService.allSortedByCompany, + recipes => this.recipes = recipes + ) } - searchRecipe(recipe: Recipe) { - if (this.searchQuery.length > 0) { + searchRecipes() { + if (this.searchQuery.length > 0 && !this.panelForcedExpanded) { this.panelForcedExpanded = true + this.cdRef.detectChanges() } - const positive = this.searchString(recipe.name) || - this.searchString(recipe.description) || - (recipe.sample && this.searchString(recipe.sample.toString())) - this.recipesHidden[recipe.id] = !positive - return positive + + this.recipes + .flatMap(r => r.recipes) + .forEach(r => this.recipeMatchesSearchQuery(r)) } isCompanyHidden(companyRecipes: Recipe[]): boolean { - return (this.searchQuery && this.searchQuery.length > 0) && companyRecipes.map(r => this.recipesHidden[r.id]).filter(r => !r).length <= 0 + return (this.searchQuery && this.searchQuery.length > 0) && companyRecipes.map(r => this.hiddenRecipes[r.id]).filter(r => !r).length <= 0 } isLightColor(recipe: Recipe): boolean { @@ -66,6 +72,13 @@ export class ListComponent extends ErrorHandlingComponent { return this.accountService.hasPermission(EmployeePermission.EDIT_RECIPE) } + private recipeMatchesSearchQuery(recipe: Recipe) { + const matches = this.searchString(recipe.name) || + this.searchString(recipe.description) || + (recipe.sample && this.searchString(recipe.sample.toString())) + this.hiddenRecipes[recipe.id] = !matches + } + private searchString(value: string): boolean { return value.toLowerCase().indexOf(this.searchQuery.toLowerCase()) >= 0 }