dev smartfarming #1

Merged
agrilink merged 53 commits from development into main 2024-12-30 05:53:19 +00:00
2 changed files with 35 additions and 1 deletions
Showing only changes of commit 141fc9bb54 - Show all commits

View File

@ -4,7 +4,7 @@
<h3 class="description">Welcome back to your management system</h3>
</div>
<div>
<h2 class="update">Latest Update: 06/09/2024 15:39:21</h2>
<h2 class="update">Latest Update: {{latestUpdate}}</h2>
</div>
<div>

View File

@ -6,6 +6,7 @@ import { GraphComponent } from './page/graph/graph.component';
import { CommonModule } from '@angular/common';
import { ApiService } from '../../cores/services/api.service';
import { SensorData } from '../../cores/interface/sensor-data';
import { interval } from 'rxjs';
@Component({
selector: 'app-dashboard',
@ -17,6 +18,8 @@ import { SensorData } from '../../cores/interface/sensor-data';
export class DashboardComponent implements OnInit {
isLoaded: boolean = false;
selectedButton: string = '';
latestUpdate: string = '';
intervalId: any;
sensorData: SensorData = {
dht: { lightIntensity: 0, temperature: 0, humidity: 0 },
npk1: { temperature: 0, moisture: 0, conductivity: 0, ph: 0, nitrogen: 0, phosphorus: 0, potassium: 0 },
@ -27,9 +30,38 @@ export class DashboardComponent implements OnInit {
ngOnInit(): void {
this.selectedButton = 'dht';
this.startClock();
this.loadData();
}
ngOnDestroy(): void {
if (this.intervalId) {
clearInterval(this.intervalId);
}
}
startClock(): void {
this.updateLatestTime();
this.intervalId = setInterval(() => {
this.updateLatestTime();
}, 1000);
}
updateLatestTime(): void {
const now = new Date();
const options: Intl.DateTimeFormatOptions = {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
};
this.latestUpdate = now.toLocaleString('en-GB', options); // Update waktu ke format yang sesuai
}
selectSensor(param: string): void {
this.selectedButton = param;
this.loadData();
@ -73,6 +105,7 @@ export class DashboardComponent implements OnInit {
};
}
this.updateLatestTime(); // Update waktu setelah data diambil
this.isLoaded = false;
},
(error) => {
@ -82,3 +115,4 @@ export class DashboardComponent implements OnInit {
);
}
}