diff --git a/webapp/src/ts/modules/tasks/tasks.component.ts b/webapp/src/ts/modules/tasks/tasks.component.ts
index a68c342b8d..0e9524a849 100644
--- a/webapp/src/ts/modules/tasks/tasks.component.ts
+++ b/webapp/src/ts/modules/tasks/tasks.component.ts
@@ -1,4 +1,4 @@
-import { Component, OnDestroy, OnInit } from '@angular/core';
+import { Component, OnDestroy, OnInit, AfterViewInit, ViewChild } from '@angular/core';
import { Store } from '@ngrx/store';
import { combineLatest, Subscription } from 'rxjs';
import { debounce as _debounce } from 'lodash-es';
@@ -13,11 +13,14 @@ import { GlobalActions } from '@mm-actions/global';
import { LineageModelGeneratorService } from '@mm-services/lineage-model-generator.service';
import { PerformanceService } from '@mm-services/performance.service';
import { ExtractLineageService } from '@mm-services/extract-lineage.service';
+import { TasksSidebarFilterComponent } from '@mm-modules/tasks/tasks-sidebar-filter.component';
@Component({
templateUrl: './tasks.component.html',
})
-export class TasksComponent implements OnInit, OnDestroy {
+export class TasksComponent implements OnInit, AfterViewInit, OnDestroy {
+ @ViewChild(TasksSidebarFilterComponent) tasksSidebarFilter: TasksSidebarFilterComponent;
+
constructor(
private store: Store,
private changesService: ChangesService,
@@ -39,11 +42,17 @@ export class TasksComponent implements OnInit, OnDestroy {
tasksList;
selectedTask;
+ selectedTasks;
errorStack;
hasTasks;
loading;
tasksDisabled;
userLineageLevel;
+ filters: any = {};
+ selectMode = false;
+ selectModeAvailable = false;
+ useSidebarFilter = true;
+ isSidebarFilterOpen = false;
private tasksLoaded;
private debouncedReload;
@@ -57,11 +66,15 @@ export class TasksComponent implements OnInit, OnDestroy {
const taskList$ = combineLatest([
this.store.select(Selectors.getTasksList),
this.store.select(Selectors.getSelectedTask),
+ this.store.select(Selectors.getFilters),
]).subscribe(([
tasksList = [],
selectedTask,
+ filters,
]) => {
this.selectedTask = selectedTask;
+ this.filters = filters;
+
// Make new reference because the one from store is read-only. Fixes: ExpressionChangedAfterItHasBeenCheckedError
this.tasksList = tasksList.map(task => ({ ...task, selected: task._id === this.selectedTask?._id }));
});
@@ -106,6 +119,10 @@ export class TasksComponent implements OnInit, OnDestroy {
this.refreshTasks();
}
+ async ngAfterViewInit() {
+ this.subscribeSidebarFilter();
+ }
+
ngOnDestroy() {
this.subscription.unsubscribe();
this.tasksActions.setTasksList([]);
@@ -119,6 +136,17 @@ export class TasksComponent implements OnInit, OnDestroy {
window.location.reload();
}
+ private subscribeSidebarFilter() {
+ if (!this.useSidebarFilter) {
+ return;
+ }
+
+ const subscription = this.store
+ .select(Selectors.getSidebarFilter)
+ .subscribe(({ isOpen }) => this.isSidebarFilterOpen = !!isOpen);
+ this.subscription.add(subscription);
+ }
+
private hydrateEmissions(taskDocs) {
return taskDocs.map(taskDoc => {
const emission = { ...taskDoc.emission };
@@ -141,7 +169,7 @@ export class TasksComponent implements OnInit, OnDestroy {
const taskDocs = isEnabled ? await this.rulesEngineService.fetchTaskDocsForAllContacts() : [];
this.hasTasks = taskDocs.length > 0;
- const hydratedTasks = await this.hydrateEmissions(taskDocs) || [];
+ let hydratedTasks = await this.hydrateEmissions(taskDocs) || [];
const subjects = await this.getLineagesFromTaskDocs(hydratedTasks);
if (subjects?.size) {
const userLineageLevel = await this.userLineageLevel;
@@ -150,6 +178,19 @@ export class TasksComponent implements OnInit, OnDestroy {
});
}
+ if (subjects?.size) {
+ const userLineageLevel = await this.currentLevel;
+ hydratedTasks.forEach(task => {
+ task.lineageId = this.getTaskLineageById(subjects, task, userLineageLevel);
+ });
+ }
+
+ if(this.filters?.facilities) {
+ hydratedTasks = hydratedTasks.filter(task =>
+ task.lineageId.some(value => this.filters.facilities.selected.includes(value))
+ );
+ }
+
this.tasksActions.setTasksList(hydratedTasks);
} catch (exception) {
@@ -185,6 +226,18 @@ export class TasksComponent implements OnInit, OnDestroy {
return task?._id;
}
+ toggleFilter() {
+ this.tasksSidebarFilter?.toggleSidebarFilter();
+ }
+
+ resetFilter() {
+ this.tasksSidebarFilter?.resetFilters();
+ }
+
+ search() {
+ this.refreshTasks();
+ }
+
private getLineagesFromTaskDocs(taskDocs) {
const ids = [ ...new Set(taskDocs.map(task => task.owner)) ];
return this.lineageModelGeneratorService
@@ -198,4 +251,11 @@ export class TasksComponent implements OnInit, OnDestroy {
?.map(lineage => lineage?.name);
return this.extractLineageService.removeUserFacility(lineage, userLineageLevel);
}
+
+ private getTaskLineageById(subjects, task, userLineageLevel) {
+ const lineage = subjects
+ .get(task.owner)
+ ?.map(lineage => lineage?._id);
+ return this.extractLineageService.removeUserFacility(lineage, userLineageLevel);
+ }
}