From 44aa8cdc776b0ba29b9094e113a4dbdd2db6f33e Mon Sep 17 00:00:00 2001 From: Omar-Nabil Date: Sun, 21 Jul 2024 16:26:41 +0300 Subject: [PATCH] add Search Activity to our dashboard and fix html & css of the dashboard --- .../client-trends-bar.component.scss | 3 +- .../home/dashboard/dashboard.component.html | 62 +++++++------------ .../home/dashboard/dashboard.component.scss | 62 ++++++++++--------- src/app/home/dashboard/dashboard.component.ts | 32 +++++++++- 4 files changed, 88 insertions(+), 71 deletions(-) diff --git a/src/app/home/dashboard/client-trends-bar/client-trends-bar.component.scss b/src/app/home/dashboard/client-trends-bar/client-trends-bar.component.scss index bb685d866..446cb59f4 100644 --- a/src/app/home/dashboard/client-trends-bar/client-trends-bar.component.scss +++ b/src/app/home/dashboard/client-trends-bar/client-trends-bar.component.scss @@ -7,7 +7,8 @@ } } #timescale { - margin: 2% 35%; + margin: 2% 50%; + transform: translateX(-50%); } .fallback { overflow-x: auto; diff --git a/src/app/home/dashboard/dashboard.component.html b/src/app/home/dashboard/dashboard.component.html index e40922355..9e5e4d461 100644 --- a/src/app/home/dashboard/dashboard.component.html +++ b/src/app/home/dashboard/dashboard.component.html @@ -2,55 +2,39 @@ + +
+ +
- - - -

-    {{"labels.heading.Recent Activities" | translate}}

-
- - - - - - - -
- - - - -

-    {{"labels.heading.Frequent Activities" | translate}}

-
- - - - - - - -
+
-
- -
- - -
- +
diff --git a/src/app/home/dashboard/dashboard.component.scss b/src/app/home/dashboard/dashboard.component.scss index c71eab6cf..dd7504546 100644 --- a/src/app/home/dashboard/dashboard.component.scss +++ b/src/app/home/dashboard/dashboard.component.scss @@ -3,54 +3,56 @@ padding: 2%; display: flex; flex-direction: column; + overflow-x: hidden; + + .search { + width: 100%; + padding: 12px; + mat-card-content { + width: 100%; + } + + mat-form-field { + width: 100%; + } + } .top-card { - display: flex; - flex-wrap: wrap; - flex-direction: row; - gap: 2px; + flex: 1 0 100%; - .recent-activities, - .frequent-activities{ - min-width: 18.5rem; - } - .recent-activities, - .frequent-activities, - .amount-disbursed { - flex: 1 0 calc(26.33% - 10px); - padding: 0; - margin: 10px; - - .list { - padding-top: 0; - } + .trends-bar { + width: 100%; + flex: 1 0 100%; } } - .bottom-card{ + .bottom-card { display: flex; flex-wrap: wrap; flex-direction: row; gap: 2px; - .trends-bar, - .amount-collected { + .amount-collected, + .amount-disbursed { flex: 1 0 calc(40% - 10px); padding: 0; margin: 10px; } } - - @media screen and (max-width: 768px) { - .recent-activities, - .frequent-activities, - .amount-disbursed, +} + +@media screen and (max-width: 768px) { + + .top-card, + .bottom-card { + flex-direction: column; + .trends-bar, - .amount-collected { - box-sizing: border-box; + .amount-collected, + .amount-disbursed { + flex: 1 0 100%; width: 100%; - flex: 1 0 calc(80% - 10px); - margin-bottom: 20px; + margin: 10px 0; } } } diff --git a/src/app/home/dashboard/dashboard.component.ts b/src/app/home/dashboard/dashboard.component.ts index 6fbec00c8..869ef401e 100644 --- a/src/app/home/dashboard/dashboard.component.ts +++ b/src/app/home/dashboard/dashboard.component.ts @@ -1,7 +1,10 @@ /** Angular Imports */ import { Component, OnInit } from '@angular/core'; +import { UntypedFormControl } from '@angular/forms'; import { Router } from '@angular/router'; - +import { Observable } from 'rxjs'; +import { map } from 'rxjs/operators'; +import { activities } from '../activities'; /** * Dashboard component. */ @@ -18,6 +21,12 @@ export class DashboardComponent implements OnInit { recentActivities: string[]; /** Array of most frequent user activities */ frequentActivities: string[]; + /** Search Text. */ + searchText: UntypedFormControl = new UntypedFormControl(); + /** Filtered Activities. */ + filteredActivities: Observable; + /** All User Activities. */ + allActivities: any[] = activities; /** * Gets user activities from local storage. @@ -29,6 +38,7 @@ export class DashboardComponent implements OnInit { ngOnInit() { this.recentActivities = this.getRecentActivities(); this.frequentActivities = this.getFrequentActivities(); + this.setFilteredActivities(); } /** @@ -75,5 +85,25 @@ export class DashboardComponent implements OnInit { this.router.navigateByUrl(activity); } + /** + * Sets filtered activities for autocomplete. + */ + setFilteredActivities() { + this.filteredActivities = this.searchText.valueChanges + .pipe( + map((activity: any) => typeof activity === 'string' ? activity : activity.activity), + map((activityName: string) => activityName ? this.filterActivity(activityName) : this.allActivities)); + } + + /** + * Filters activities. + * @param activityName Activity name to filter activity by. + * @returns {any} Filtered activities. + */ + private filterActivity(activityName: string): any { + const filterValue = activityName.toLowerCase(); + return this.allActivities.filter(activity => activity.activity.toLowerCase().indexOf(filterValue) === 0); + } + }