Skip to content

Commit c9c4a51

Browse files
authored
Merge pull request #128 from Riyad-Murad/provider_dashboard_page_dev
Provider dashboard page dev
2 parents ed6f017 + f801b0d commit c9c4a51

File tree

13 files changed

+911
-25
lines changed

13 files changed

+911
-25
lines changed

amp-client/src/Pages/ProviderPages/ProviderDashboard/ProviderDashboard.jsx

Lines changed: 485 additions & 6 deletions
Large diffs are not rendered by default.

amp-client/src/Pages/ProviderPages/ProviderDashboard/styles.css

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,182 @@
22
.provider-dashboard-container {
33
display: flex;
44
flex-direction: row;
5+
flex-wrap: wrap;
6+
margin-right: 15px;
7+
}
8+
9+
.spinner-container {
10+
display: flex;
11+
flex-direction: column;
12+
align-items: center;
13+
justify-content: center;
14+
height: 150px;
15+
color: #555;
16+
width: 100%;
17+
}
18+
19+
.spinner {
20+
width: 40px;
21+
height: 40px;
22+
border: 4px solid rgba(0, 0, 0, 0.1);
23+
border-left-color: #f9a43a;
24+
border-radius: 50%;
25+
animation: spin 1s linear infinite;
26+
margin-bottom: 10px;
27+
}
28+
29+
@keyframes spin {
30+
to {
31+
transform: rotate(360deg);
32+
}
33+
}
34+
35+
.error-message {
36+
color: #dc3545;
37+
padding: 15px;
38+
background-color: #f8d7da;
39+
border: 1px solid #f5c6cb;
40+
border-radius: 5px;
41+
margin-top: 20px;
42+
width: 100%;
43+
}
44+
45+
.charts-row {
46+
display: flex;
47+
flex-wrap: wrap;
48+
gap: 20px;
49+
margin-bottom: 20px;
50+
width: 100%;
51+
}
52+
53+
.chart-widget {
54+
flex: 1;
55+
min-width: 250px;
56+
max-width: 500px;
57+
max-height: 450px;
58+
background-color: #fff;
59+
padding: 15px;
60+
border-radius: 8px;
61+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
62+
border: 1px solid #eee;
63+
display: flex;
64+
flex-direction: column;
65+
align-items: center;
66+
}
67+
68+
.chart-widget h3 {
69+
margin-top: 0px;
70+
font-size: 1em;
71+
color: #333;
72+
text-align: center;
73+
margin-bottom: 10px;
74+
}
75+
76+
.voltage-distribution-widget {
77+
height: 350px;
78+
max-height: 400px;
79+
}
80+
81+
.metric-card {
82+
flex: 1;
83+
min-width: 150px;
84+
max-width: 200px;
85+
background-color: #fff;
86+
padding: 15px;
87+
border-radius: 8px;
88+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
89+
border: 1px solid #eee;
90+
display: flex;
91+
flex-direction: column;
92+
align-items: center;
93+
justify-content: center;
94+
text-align: center;
95+
}
96+
97+
.metric-card h3 {
98+
margin-top: 0;
99+
font-size: 1em;
100+
color: #333;
101+
margin-bottom: 5px;
102+
}
103+
104+
.metric-value {
105+
font-size: 1.3em;
106+
font-weight: bold;
107+
color: #198754;
108+
}
109+
110+
.all-metrics-widget {
111+
flex: 1 1 100%;
112+
overflow-x: auto;
113+
max-height: 500px;
114+
}
115+
116+
.all-metrics-widget h3 {
117+
margin-top: 0;
118+
font-size: 1.1em;
119+
color: #333;
120+
text-align: center;
121+
margin-bottom: 10px;
122+
}
123+
124+
.all-metrics-widget table {
125+
width: 100%;
126+
border-collapse: collapse;
127+
margin-bottom: 15px;
128+
}
129+
130+
.all-metrics-widget th,
131+
.all-metrics-widget td {
132+
border: 1px solid #ddd;
133+
padding: 8px;
134+
text-align: left;
135+
}
136+
137+
.all-metrics-widget th {
138+
background-color: #f2f2f2;
139+
font-weight: bold;
140+
}
141+
142+
/* Media query for smaller screens (e.g., tablets) */
143+
@media (max-width: 768px) {
144+
.provider-dashboard-container {
145+
flex-direction: column;
146+
}
147+
148+
.main-content {
149+
margin-left: 300px !important;
150+
margin-top: 20px;
151+
}
152+
153+
.charts-row {
154+
flex-direction: column;
155+
}
156+
157+
.chart-widget,
158+
.metric-card {
159+
min-width: auto;
160+
width: 100%;
161+
max-width: none;
162+
margin-bottom: 15px;
163+
}
164+
165+
.all-metrics-widget {
166+
max-height: none;
167+
}
168+
}
169+
170+
/* Media query for even smaller screens (e.g., mobile phones) */
171+
@media (max-width: 480px) {
172+
.chart-widget h3,
173+
.metric-card h3,
174+
.all-metrics-widget h3 {
175+
font-size: 1em;
176+
}
177+
178+
.all-metrics-widget th,
179+
.all-metrics-widget td {
180+
padding: 6px;
181+
font-size: 0.9em;
182+
}
5183
}

amp-laravel/app/Http/Controllers/Provider/ProviderFunctionsController.php

Lines changed: 75 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@
33
namespace App\Http\Controllers\Provider;
44

55
use App\Http\Controllers\Controller;
6-
use App\Services\Provider\GeneratingReportService;
6+
use App\Services\Provider\GetAllLinesService;
77
use App\Http\Requests\Provider\EditUserRequest;
8-
use App\Http\Requests\Provider\EditProfileRequest;
98
use App\Services\Provider\EditClientUserService;
10-
use App\Services\Provider\GetAllLinesService;
9+
use App\Services\Provider\GetOverviewDataService;
10+
use App\Services\Provider\GetMetricSummaryService;
11+
use App\Services\Provider\GeneratingReportService;
12+
use App\Http\Requests\Provider\EditProfileRequest;
1113
use App\Services\Provider\GetAllClientUsersService;
14+
use App\Services\Provider\GetAverageVoltageService;
15+
use App\Services\Provider\GetTotalPowerUsageService;
1216
use App\Services\Provider\ProviderEditProfileService;
1317
use App\Services\Provider\GetAllClientMetricsService;
18+
use App\Services\Provider\GetPowerUsageByClientService;
19+
use App\Services\Provider\GetVoltageDistributionService;
1420

1521
class ProviderFunctionsController extends Controller
1622
{
@@ -46,36 +52,96 @@ public function editUser(EditUserRequest $request, $id)
4652
}
4753
}
4854

49-
public function getUsers()
55+
public function getUsers($id)
5056
{
5157
try {
52-
$users = GetAllClientUsersService::getAll();
58+
$users = GetAllClientUsersService::getAll($id);
5359

5460
return $this->messageResponse(true, "Messages retrieved successfully", 200, $users);
5561
} catch (\Exception $e) {
5662
return $this->errorMessageResponse(false, $e->getMessage(), "Failed to retrieve messages", 500);
5763
}
5864
}
5965

60-
public function getMetrics()
66+
public function getMetrics($id)
6167
{
6268
try {
63-
$metrics = GetAllClientMetricsService::getAll();
69+
$metrics = GetAllClientMetricsService::getAll($id);
6470

6571
return $this->messageResponse(true, "Messages retrieved successfully", 200, $metrics);
6672
} catch (\Exception $e) {
6773
return $this->errorMessageResponse(false, $e->getMessage(), "Failed to retrieve messages", 500);
6874
}
6975
}
7076

71-
public function getLines()
77+
public function getLines($id)
7278
{
7379
try {
74-
$lines = GetAllLinesService::getAll();
80+
$lines = GetAllLinesService::getAll($id);
7581

7682
return $this->messageResponse(true, "Messages retrieved successfully", 200, $lines);
7783
} catch (\Exception $e) {
7884
return $this->errorMessageResponse(false, $e->getMessage(), "Failed to retrieve messages", 500);
7985
}
8086
}
87+
88+
public function getOverviewData($id)
89+
{
90+
try {
91+
$overviewData = GetOverviewDataService::getOverviewData($id);
92+
return $this->messageResponse(true, "Overview data retrieved successfully", 200, $overviewData);
93+
} catch (\Exception $e) {
94+
return $this->errorMessageResponse(false, $e->getMessage(), "Failed to retrieve overview data", 500);
95+
}
96+
}
97+
98+
public function getTotalPowerUsage($id)
99+
{
100+
try {
101+
$totalPower = GetTotalPowerUsageService::getTotalPowerUsage($id);
102+
return $this->messageResponse(true, "Total power usage retrieved successfully", 200, $totalPower);
103+
} catch (\Exception $e) {
104+
return $this->errorMessageResponse(false, $e->getMessage(), "Failed to retrieve total power usage", 500);
105+
}
106+
}
107+
108+
public function getAverageVoltage($id)
109+
{
110+
try {
111+
$averageVoltage = GetAverageVoltageService::getAverageVoltage($id);
112+
return $this->messageResponse(true, "Average voltage retrieved successfully", 200, $averageVoltage);
113+
} catch (\Exception $e) {
114+
return $this->errorMessageResponse(false, $e->getMessage(), "Failed to retrieve average voltage", 500);
115+
}
116+
}
117+
118+
public function getPowerUsageByClient($id)
119+
{
120+
try {
121+
$powerUsageByClient = GetPowerUsageByClientService::getPowerUsageByClient($id);
122+
return $this->messageResponse(true, "Power usage by client retrieved successfully", 200, $powerUsageByClient);
123+
} catch (\Exception $e) {
124+
return $this->errorMessageResponse(false, $e->getMessage(), "Failed to retrieve power usage by client", 500);
125+
}
126+
}
127+
128+
public function getVoltageDistribution($id)
129+
{
130+
try {
131+
$voltageDistribution = GetVoltageDistributionService::getVoltageDistribution($id);
132+
return $this->messageResponse(true, "Voltage distribution retrieved successfully", 200, $voltageDistribution);
133+
} catch (\Exception $e) {
134+
return $this->errorMessageResponse(false, $e->getMessage(), "Failed to retrieve voltage distribution", 500);
135+
}
136+
}
137+
138+
public function getMetricsSummary($id)
139+
{
140+
try {
141+
$metricsSummary = GetMetricSummaryService::getMetricSummary($id);
142+
return $this->messageResponse(true, "Metrics summary retrieved successfully", 200, $metricsSummary);
143+
} catch (\Exception $e) {
144+
return $this->errorMessageResponse(false, $e->getMessage(), "Failed to retrieve metrics summary", 500);
145+
}
146+
}
81147
}

amp-laravel/app/Services/Provider/GetAllClientMetricsService.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
namespace App\Services\Provider;
44

5+
use App\Models\Master;
56
use App\Models\Metric;
67

78
class GetAllClientMetricsService
89
{
9-
public static function getAll()
10+
public static function getAll(int $providerId)
1011
{
11-
return Metric::all();
12+
$masterIds = Master::where('user_id', $providerId)->pluck('id');
13+
return Metric::whereIn('master_id', $masterIds)->get();
1214
}
1315
}

amp-laravel/app/Services/Provider/GetAllClientUsersService.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
namespace App\Services\Provider;
44

55
use App\Models\User;
6+
use App\Models\Master;
7+
use App\Models\Metric;
68

79
class GetAllClientUsersService
810
{
9-
public static function getAll()
11+
public static function getAll(int $providerId)
1012
{
11-
return User::where('user_type', 'Client')->get();
13+
$masterIds = Master::where('user_id', $providerId)->pluck('id');
14+
$clientSlaveIds = Metric::whereIn('master_id', $masterIds)->distinct()->pluck('slave_id');
15+
return User::whereIn('slave_id', $clientSlaveIds)->where('user_type', 'Client')->get();
1216
}
1317
}

amp-laravel/app/Services/Provider/GetAllLinesService.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
namespace App\Services\Provider;
44

55
use App\Models\Line;
6+
use App\Models\Master;
67

78
class GetAllLinesService
89
{
9-
public static function getAll()
10+
public static function getAll(int $providerId)
1011
{
11-
return Line::all();
12+
$masterIds = Master::where('user_id', $providerId)->pluck('id');
13+
return Line::whereIn('master_id', $masterIds)->get();
1214
}
1315
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace App\Services\Provider;
4+
5+
use App\Models\Master;
6+
use App\Models\Metric;
7+
use App\Models\User;
8+
9+
class GetAverageVoltageService
10+
{
11+
public static function getAverageVoltage(int $providerId): float
12+
{
13+
$masterIds = Master::where('user_id', $providerId)->pluck('id');
14+
return round(Metric::whereIn('master_id', $masterIds)->avg('voltage'), 2);
15+
}
16+
}

0 commit comments

Comments
 (0)