dev smartfarming #1

Merged
agrilink merged 53 commits from development into main 2024-12-30 05:53:19 +00:00
Showing only changes of commit e0b74fd135 - Show all commits

View File

@ -149,7 +149,7 @@ export class DashboardComponent implements OnInit {
this.apiService.getRelayStatus().subscribe(
(response) => {
if (Array.isArray(response.data)) {
if (Array.isArray(response.data) && response.data.length > 0) {
this.relayStatus = response.data.map((relay) => ({
id: relay.id,
number: relay.number,
@ -159,16 +159,22 @@ export class DashboardComponent implements OnInit {
current_status: relay.current_status
}));
this.relayStatus.sort((a, b) => a.number - b.number);
this.noData = false; // Data available
} else {
// Throw an error if relay data is empty
this.handleError({ message: 'No available relay data.' });
this.noData = true;
}
this.isLoaded = false;
},
(error) => {
this.toast.error('Failed to get relay status, please try again');
this.hasError = true;
this.isLoaded = false;
this.handleError(error);
this.hasError = true;
}
);
}
}
handleError(error: any): void {
if (this.selectedButton === 'dht') {
@ -177,6 +183,8 @@ export class DashboardComponent implements OnInit {
this.toast.error('Error fetching NPK1 sensor data. Please try again.', 'Error', { timeOut: 3000 });
} else if (this.selectedButton === 'npk2') {
this.toast.error('Error fetching NPK2 sensor data. Please try again.', 'Error', { timeOut: 3000 });
} else if (this.selectedButton === 'relay') {
this.toast.error('Error fetching relay status. Please try again.', 'Error', { timeOut: 3000 });
}
this.hasError = true;
}