fix: clean code

This commit is contained in:
Desy Ayurianti 2024-11-06 09:28:54 +07:00
parent cff1e79837
commit 50c3ce7497
4 changed files with 5 additions and 12 deletions

View File

@ -20,7 +20,7 @@
<div class="sensor-wrapper"> <div class="sensor-wrapper">
<div class="title-with-dropdown"> <div class="title-with-dropdown">
<div class="title">Sensor NPK 1</div> <div class="title">Sensor NPK 1</div>
<select class="form-select" style="margin-top: 10px" [(ngModel)]="selectedNPK1" (change)="updateCharts(); onResize()"> <select class="form-select" style="margin-top: 10px" [(ngModel)]="selectedNPK1" (change)="onResize()">
<option value="npk">NPK</option> <option value="npk">NPK</option>
<option value="others">Lainnya</option> <option value="others">Lainnya</option>
</select> </select>
@ -39,7 +39,7 @@
<div class="sensor-wrapper"> <div class="sensor-wrapper">
<div class="title-with-dropdown"> <div class="title-with-dropdown">
<div class="title">Sensor NPK 2</div> <div class="title">Sensor NPK 2</div>
<select class="form-select" style="margin-top: 10px" [(ngModel)]="selectedNPK2" (change)="updateCharts(); onResize()"> <select class="form-select" style="margin-top: 10px" [(ngModel)]="selectedNPK2" (change)=" onResize()">
<option value="npk">NPK</option> <option value="npk">NPK</option>
<option value="others">Lainnya</option> <option value="others">Lainnya</option>
</select> </select>

View File

@ -82,15 +82,12 @@ export class GraphComponent implements OnInit, AfterViewInit, OnDestroy, OnChang
this.updateCharts(); this.updateCharts();
} }
ngOnChanges(changes: SimpleChanges): void { ngOnChanges(changes: SimpleChanges): void {
if (changes['interval'] && !changes['interval'].firstChange) { if (changes['interval'] && changes['interval'].previousValue !== changes['interval'].currentValue) {
this.selectedInterval = changes['interval'].currentValue; this.selectedInterval = changes['interval'].currentValue;
this.updateCharts();
} }
} }
ngAfterViewInit(): void { ngAfterViewInit(): void {
this.onResize(); this.onResize();
} }
@ -157,7 +154,6 @@ export class GraphComponent implements OnInit, AfterViewInit, OnDestroy, OnChang
fetchNPK2Data(savedTimeRange: string): void { fetchNPK2Data(savedTimeRange: string): void {
const startEnd = this.getDate(); const startEnd = this.getDate();
const timeRange = this.interval;
this.sensorService.getSensorData('npk2', this.selectedNPK2, startEnd, savedTimeRange).subscribe({ this.sensorService.getSensorData('npk2', this.selectedNPK2, startEnd, savedTimeRange).subscribe({
next: (response) => { next: (response) => {
console.log(savedTimeRange); console.log(savedTimeRange);
@ -177,7 +173,7 @@ export class GraphComponent implements OnInit, AfterViewInit, OnDestroy, OnChang
} }
updateCharts(): void { updateCharts(): void {
const interval = this.selectedInterval; const interval = this.selectedInterval;
Object.keys(this.charts).forEach(key => { Object.keys(this.charts).forEach(key => {
if (this.charts[key]) { if (this.charts[key]) {
@ -191,7 +187,6 @@ export class GraphComponent implements OnInit, AfterViewInit, OnDestroy, OnChang
this.fetchNPK2Data(interval); this.fetchNPK2Data(interval);
} }
createChart(canvas: HTMLCanvasElement, response: ApiResponse, sensor: string, selectedOption: string): void { createChart(canvas: HTMLCanvasElement, response: ApiResponse, sensor: string, selectedOption: string): void {
const ctx = canvas.getContext('2d'); const ctx = canvas.getContext('2d');

View File

@ -11,7 +11,6 @@
<button (click)="updateInterval('HOURLY')" [class.active-button]="selectedButton === 'hourly'">Hourly</button> <button (click)="updateInterval('HOURLY')" [class.active-button]="selectedButton === 'hourly'">Hourly</button>
<button (click)="updateInterval('DAILY')" [class.active-button]="selectedButton === 'daily'">Daily</button> <button (click)="updateInterval('DAILY')" [class.active-button]="selectedButton === 'daily'">Daily</button>
</div> </div>
<div class="graph"> <div class="graph">
<app-graph [interval]="selectedInterval"></app-graph> <app-graph [interval]="selectedInterval"></app-graph>

View File

@ -42,7 +42,6 @@ export class HistorygraphComponent implements OnInit, OnDestroy {
} }
}, 300); }, 300);
} }
ngOnDestroy(): void { ngOnDestroy(): void {
if (this.intervalId) { if (this.intervalId) {