dev smartfarming #1
|
|
@ -4,7 +4,7 @@
|
||||||
<h3 class="description">Welcome back to your management system</h3>
|
<h3 class="description">Welcome back to your management system</h3>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<h2 class="update">Latest Update: 06/09/2024 15:39:21</h2>
|
<h2 class="update">Latest Update: {{latestUpdate}}</h2>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import { GraphComponent } from './page/graph/graph.component';
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import { ApiService } from '../../cores/services/api.service';
|
import { ApiService } from '../../cores/services/api.service';
|
||||||
import { SensorData } from '../../cores/interface/sensor-data';
|
import { SensorData } from '../../cores/interface/sensor-data';
|
||||||
|
import { interval } from 'rxjs';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-dashboard',
|
selector: 'app-dashboard',
|
||||||
|
|
@ -17,6 +18,8 @@ import { SensorData } from '../../cores/interface/sensor-data';
|
||||||
export class DashboardComponent implements OnInit {
|
export class DashboardComponent implements OnInit {
|
||||||
isLoaded: boolean = false;
|
isLoaded: boolean = false;
|
||||||
selectedButton: string = '';
|
selectedButton: string = '';
|
||||||
|
latestUpdate: string = '';
|
||||||
|
intervalId: any;
|
||||||
sensorData: SensorData = {
|
sensorData: SensorData = {
|
||||||
dht: { lightIntensity: 0, temperature: 0, humidity: 0 },
|
dht: { lightIntensity: 0, temperature: 0, humidity: 0 },
|
||||||
npk1: { temperature: 0, moisture: 0, conductivity: 0, ph: 0, nitrogen: 0, phosphorus: 0, potassium: 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 {
|
ngOnInit(): void {
|
||||||
this.selectedButton = 'dht';
|
this.selectedButton = 'dht';
|
||||||
|
this.startClock();
|
||||||
this.loadData();
|
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 {
|
selectSensor(param: string): void {
|
||||||
this.selectedButton = param;
|
this.selectedButton = param;
|
||||||
this.loadData();
|
this.loadData();
|
||||||
|
|
@ -73,6 +105,7 @@ export class DashboardComponent implements OnInit {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.updateLatestTime(); // Update waktu setelah data diambil
|
||||||
this.isLoaded = false;
|
this.isLoaded = false;
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
|
|
@ -82,3 +115,4 @@ export class DashboardComponent implements OnInit {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user