From 6bc240f301cb9b20819117a484b702cb8614e111 Mon Sep 17 00:00:00 2001 From: Henriette Dinger Date: Mon, 5 Aug 2019 09:40:16 +0200 Subject: [PATCH] Fix: Listen for changes in highlighting to display them instantly in the WP card view --- .../components/wp-grid/wp-grid.component.ts | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/frontend/src/app/components/wp-grid/wp-grid.component.ts b/frontend/src/app/components/wp-grid/wp-grid.component.ts index 5314174912..3428369e8f 100644 --- a/frontend/src/app/components/wp-grid/wp-grid.component.ts +++ b/frontend/src/app/components/wp-grid/wp-grid.component.ts @@ -26,10 +26,13 @@ // See doc/COPYRIGHT.rdoc for more details. // ++ -import {ChangeDetectionStrategy, Component} from "@angular/core"; +import {ChangeDetectionStrategy, ChangeDetectorRef, Component} from "@angular/core"; import {WorkPackageTableHighlightingService} from "core-components/wp-fast-table/state/wp-table-highlighting.service"; import {CardViewOrientation} from "core-components/wp-card-view/wp-card-view.component"; import {WorkPackageTableSortByService} from "core-components/wp-fast-table/state/wp-table-sort-by.service"; +import {distinctUntilChanged, takeUntil} from "rxjs/operators"; +import {HighlightingMode} from "core-components/wp-fast-table/builders/highlighting/highlighting-mode.const"; +import {IsolatedQuerySpace} from "core-app/modules/work_packages/query-space/isolated-query-space"; @Component({ selector: 'wp-grid', @@ -37,7 +40,7 @@ import {WorkPackageTableSortByService} from "core-components/wp-fast-table/state @@ -48,16 +51,33 @@ import {WorkPackageTableSortByService} from "core-components/wp-fast-table/state export class WorkPackagesGridComponent { public canDragOutOf = () => { return true; }; public gridOrientation:CardViewOrientation = 'horizontal'; + public highlightingMode:HighlightingMode = 'none'; constructor(readonly wpTableHighlight:WorkPackageTableHighlightingService, - readonly wpTableSortBy:WorkPackageTableSortByService) { + readonly wpTableSortBy:WorkPackageTableSortByService, + readonly querySpace:IsolatedQuerySpace, + readonly cdRef:ChangeDetectorRef) { } - public switchToManualSorting() { - this.wpTableSortBy.switchToManualSorting(); + ngOnInit() { + this.wpTableHighlight + .updates$() + .pipe( + takeUntil(this.querySpace.stopAllSubscriptions), + distinctUntilChanged() + ) + .subscribe(() => { + this.highlightingMode = this.wpTableHighlight.current.mode; + this.cdRef.detectChanges(); + }); + } - public highlightingMode() { - return this.wpTableHighlight.current.mode; + ngOnDestroy():void { + // Nothing to do + } + + public switchToManualSorting() { + this.wpTableSortBy.switchToManualSorting(); } }