-
- TODO: dashboard component.
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/app/home/dashboard/dashboard.component.scss b/src/app/home/dashboard/dashboard.component.scss
index e69de29bb..25b6bc5a9 100644
--- a/src/app/home/dashboard/dashboard.component.scss
+++ b/src/app/home/dashboard/dashboard.component.scss
@@ -0,0 +1,10 @@
+.card {
+ padding: 2%;
+ .recent-activities, .frequent-activities {
+ width: 20rem;
+ padding: 0;
+ .list {
+ padding-top: 0px;
+ }
+ }
+}
diff --git a/src/app/home/dashboard/dashboard.component.ts b/src/app/home/dashboard/dashboard.component.ts
index cf7487d81..d7ba1de2d 100644
--- a/src/app/home/dashboard/dashboard.component.ts
+++ b/src/app/home/dashboard/dashboard.component.ts
@@ -11,10 +11,60 @@ import { Component, OnInit } from '@angular/core';
})
export class DashboardComponent implements OnInit {
- constructor() { }
+ /** Array of all user activities */
+ userActivity: string[];
+ /** Array of most recent user activities */
+ recentActivities: string[];
+ /** Array of most frequent user activities */
+ frequentActivities: string[];
+
+ /**
+ * Gets user activities from local storage.
+ */
+ constructor() {
+ this.userActivity = JSON.parse(localStorage.getItem('mifosXLocation'));
+ }
ngOnInit() {
+ this.recentActivities = this.getRecentActivities();
+ this.frequentActivities = this.getFrequentActivities();
+ }
+
+ /**
+ * Returns top eight recent activities.
+ */
+ getRecentActivities() {
+ const reverseActivities = this.userActivity.reverse();
+ const uniqueActivities: string[] = [];
+ reverseActivities.forEach((activity: string) => {
+ if (!uniqueActivities.includes(activity)) {
+ uniqueActivities.push(activity);
+ }
+ });
+ const topEightRecentActivities =
+ uniqueActivities
+ .filter((activity: string) => !['/', '/login', '/home', '/dashboard'].includes(activity))
+ .slice(0, 8);
+ return topEightRecentActivities;
+ }
+
+ /**
+ * Returns top eight frequent activities.
+ */
+ getFrequentActivities() {
+ const frequencyCounts: any = {};
+ let index = this.userActivity.length;
+ while (index) {
+ frequencyCounts[this.userActivity[--index]] = (frequencyCounts[this.userActivity[index]] || 0) + 1;
+ }
+ const frequencyCountsArray = Object.entries(frequencyCounts);
+ const topEigthFrequentActivities =
+ frequencyCountsArray
+ .sort((a: any, b: any) => b[1] - a[1])
+ .map((entry: any[]) => entry[0])
+ .filter((activity: string) => !['/', '/login', '/home', '/dashboard'].includes(activity))
+ .slice(0, 8);
+ return topEigthFrequentActivities;
}
}
-
diff --git a/src/app/home/home-routing.module.ts b/src/app/home/home-routing.module.ts
index 885586b61..0d6670fda 100644
--- a/src/app/home/home-routing.module.ts
+++ b/src/app/home/home-routing.module.ts
@@ -12,6 +12,9 @@ import { extract } from '../core/i18n/i18n.service';
import { HomeComponent } from './home.component';
import { DashboardComponent } from './dashboard/dashboard.component';
+/** Custom Resolvers */
+import { OfficesResolver } from '../accounting/common-resolvers/offices.resolver';
+
/** Home and Dashboard Routes */
const routes: Routes = [
Route.withShell([
@@ -28,7 +31,10 @@ const routes: Routes = [
{
path: 'dashboard',
component: DashboardComponent,
- data: { title: extract('Dashboard'), breadcrumb: 'Dashboard' }
+ data: { title: extract('Dashboard'), breadcrumb: 'Dashboard' },
+ resolve: {
+ offices: OfficesResolver
+ }
}
])
];
@@ -41,6 +47,6 @@ const routes: Routes = [
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
- providers: []
+ providers: [OfficesResolver]
})
export class HomeRoutingModule { }
diff --git a/src/app/home/home.module.ts b/src/app/home/home.module.ts
index 407d447c7..b1b010153 100644
--- a/src/app/home/home.module.ts
+++ b/src/app/home/home.module.ts
@@ -1,13 +1,18 @@
/** Angular Imports */
import { NgModule } from '@angular/core';
+import { DatePipe } from '@angular/common';
/** Custom Modules */
import { SharedModule } from '../shared/shared.module';
import { HomeRoutingModule } from './home-routing.module';
+import { PipesModule } from '../pipes/pipes.module';
/** Custom Components */
import { HomeComponent } from './home.component';
import { DashboardComponent } from './dashboard/dashboard.component';
+import { AmountCollectedPieComponent } from './dashboard/amount-collected-pie/amount-collected-pie.component';
+import { AmountDisbursedPieComponent } from './dashboard/amount-disbursed-pie/amount-disbursed-pie.component';
+import { ClientTrendsBarComponent } from './dashboard/client-trends-bar/client-trends-bar.component';
/**
* Home Component
@@ -17,11 +22,18 @@ import { DashboardComponent } from './dashboard/dashboard.component';
@NgModule({
imports: [
SharedModule,
+ PipesModule,
HomeRoutingModule
],
declarations: [
HomeComponent,
- DashboardComponent
+ DashboardComponent,
+ AmountCollectedPieComponent,
+ AmountDisbursedPieComponent,
+ ClientTrendsBarComponent
+ ],
+ providers: [
+ DatePipe
]
})
export class HomeModule { }
diff --git a/src/app/home/home.service.spec.ts b/src/app/home/home.service.spec.ts
new file mode 100644
index 000000000..2d073b453
--- /dev/null
+++ b/src/app/home/home.service.spec.ts
@@ -0,0 +1,12 @@
+import { TestBed } from '@angular/core/testing';
+
+import { HomeService } from './home.service';
+
+describe('HomeService', () => {
+ beforeEach(() => TestBed.configureTestingModule({}));
+
+ it('should be created', () => {
+ const service: HomeService = TestBed.get(HomeService);
+ expect(service).toBeTruthy();
+ });
+});
diff --git a/src/app/home/home.service.ts b/src/app/home/home.service.ts
new file mode 100644
index 000000000..ee098ae5a
--- /dev/null
+++ b/src/app/home/home.service.ts
@@ -0,0 +1,109 @@
+/** Angular Imports */
+import { Injectable } from '@angular/core';
+import { HttpClient, HttpParams } from '@angular/common/http';
+
+/** rxjs Imports */
+import { Observable } from 'rxjs';
+
+/**
+ * Home Service
+ */
+@Injectable({
+ providedIn: 'root'
+})
+export class HomeService {
+
+ /**
+ * @param {HttpClient} http Http Client to send requests.
+ */
+ constructor(private http: HttpClient) { }
+
+ /**
+ * @param {number} officeId Office Id.
+ * @returns {Observable