mirror of
https://github.com/ckaczor/HomeMonitor.git
synced 2026-01-14 01:25:38 -05:00
Some rough work on date controls for chart
This commit is contained in:
8
Display/package-lock.json
generated
8
Display/package-lock.json
generated
@@ -1013,6 +1013,14 @@
|
|||||||
"tslib": "^1.7.1"
|
"tslib": "^1.7.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@angular/material-moment-adapter": {
|
||||||
|
"version": "8.2.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@angular/material-moment-adapter/-/material-moment-adapter-8.2.2.tgz",
|
||||||
|
"integrity": "sha512-HZYoVssNh+uon0SszUDtVTWmjah5vtEJOYVYl9BakE6dC+Z4910B+/hVQ1HfOdas5mHpjxVoYpbIoe4QG5sc5A==",
|
||||||
|
"requires": {
|
||||||
|
"tslib": "^1.7.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"@angular/platform-browser": {
|
"@angular/platform-browser": {
|
||||||
"version": "8.2.8",
|
"version": "8.2.8",
|
||||||
"resolved": "https://registry.npmjs.org/@angular/platform-browser/-/platform-browser-8.2.8.tgz",
|
"resolved": "https://registry.npmjs.org/@angular/platform-browser/-/platform-browser-8.2.8.tgz",
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
"@angular/core": "~8.2.4",
|
"@angular/core": "~8.2.4",
|
||||||
"@angular/forms": "~8.2.4",
|
"@angular/forms": "~8.2.4",
|
||||||
"@angular/material": "^8.2.1",
|
"@angular/material": "^8.2.1",
|
||||||
|
"@angular/material-moment-adapter": "^8.2.2",
|
||||||
"@angular/platform-browser": "~8.2.4",
|
"@angular/platform-browser": "~8.2.4",
|
||||||
"@angular/platform-browser-dynamic": "~8.2.4",
|
"@angular/platform-browser-dynamic": "~8.2.4",
|
||||||
"@angular/router": "~8.2.4",
|
"@angular/router": "~8.2.4",
|
||||||
|
|||||||
@@ -5,12 +5,13 @@ import { HttpClientModule } from '@angular/common/http';
|
|||||||
import { AppRoutingModule } from './app-routing.module';
|
import { AppRoutingModule } from './app-routing.module';
|
||||||
import { AppComponent } from './components/app/app.component';
|
import { AppComponent } from './components/app/app.component';
|
||||||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
|
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||||
import { MatToolbarModule, MatIconModule, MatMenuModule, MatButtonModule, MatExpansionModule } from '@angular/material';
|
import { MatToolbarModule, MatIconModule, MatMenuModule, MatButtonModule, MatExpansionModule, MatSelectModule, MatDatepickerModule, MatInputModule } from '@angular/material';
|
||||||
import { NavComponent } from './components/nav/nav.component';
|
import { NavComponent } from './components/nav/nav.component';
|
||||||
import { LayoutModule } from '@angular/cdk/layout';
|
import { LayoutModule } from '@angular/cdk/layout';
|
||||||
import { MatSidenavModule } from '@angular/material/sidenav';
|
import { MatSidenavModule } from '@angular/material/sidenav';
|
||||||
import { MatListModule } from '@angular/material/list';
|
import { MatListModule } from '@angular/material/list';
|
||||||
|
import { MatMomentDateModule } from '@angular/material-moment-adapter';
|
||||||
|
|
||||||
import { SocketIoModule, SocketIoConfig } from 'ngx-socket-io';
|
import { SocketIoModule, SocketIoConfig } from 'ngx-socket-io';
|
||||||
|
|
||||||
@@ -36,7 +37,7 @@ const config: SocketIoConfig = { url: 'http://home.kaczorzoo.net:9091', options:
|
|||||||
BrowserAnimationsModule,
|
BrowserAnimationsModule,
|
||||||
SocketIoModule.forRoot(config),
|
SocketIoModule.forRoot(config),
|
||||||
ChartModule,
|
ChartModule,
|
||||||
HttpClientModule,
|
HttpClientModule,
|
||||||
MatIconModule,
|
MatIconModule,
|
||||||
MatButtonModule,
|
MatButtonModule,
|
||||||
MatToolbarModule,
|
MatToolbarModule,
|
||||||
@@ -44,7 +45,13 @@ const config: SocketIoConfig = { url: 'http://home.kaczorzoo.net:9091', options:
|
|||||||
LayoutModule,
|
LayoutModule,
|
||||||
MatSidenavModule,
|
MatSidenavModule,
|
||||||
MatListModule,
|
MatListModule,
|
||||||
MatExpansionModule
|
MatExpansionModule,
|
||||||
|
MatSelectModule,
|
||||||
|
MatDatepickerModule,
|
||||||
|
MatInputModule,
|
||||||
|
FormsModule,
|
||||||
|
ReactiveFormsModule,
|
||||||
|
MatMomentDateModule
|
||||||
],
|
],
|
||||||
providers: [],
|
providers: [],
|
||||||
bootstrap: [AppComponent]
|
bootstrap: [AppComponent]
|
||||||
|
|||||||
@@ -2,27 +2,28 @@
|
|||||||
<span class="spinner"></span>
|
<span class="spinner"></span>
|
||||||
</div> -->
|
</div> -->
|
||||||
<div class="chart-content">
|
<div class="chart-content">
|
||||||
<!-- <header class="chart-header">
|
<header class="chart-header">
|
||||||
<clr-dropdown class="clr-dropdown">
|
<mat-form-field>
|
||||||
<button class="btn btn-outline-primary chart-button-spacer" clrDropdownTrigger>
|
<mat-select [(value)]="selectedTimeSpan">
|
||||||
{{ timeSpanItems[selectedTimeSpan] }}
|
<mat-option *ngFor="let item of timeSpanItems | keyvalue" [value]="+item.key">{{ item.value }}</mat-option>
|
||||||
<clr-icon shape="caret down"></clr-icon>
|
</mat-select>
|
||||||
</button>
|
</mat-form-field>
|
||||||
<clr-dropdown-menu clrPosition="bottom-left" *clrIfOpen>
|
<button mat-button *ngIf="selectedTimeSpan === timeSpans.Day" (click)="handleDateArrowClick(-1)">
|
||||||
<div *ngFor="let item of timeSpanItems | keyvalue" clrDropdownItem [class.active]="+item.key === selectedTimeSpan" (click)="selectedTimeSpan = +item.key">
|
<mat-icon>arrow_back</mat-icon>
|
||||||
{{ item.value }}
|
|
||||||
</div>
|
|
||||||
</clr-dropdown-menu>
|
|
||||||
</clr-dropdown>
|
|
||||||
<button class="btn btn-outline-primary" [hidden]="selectedTimeSpan !== timeSpans.Day" (click)="handleDateArrowClick(-1)">
|
|
||||||
<clr-icon shape="caret left"></clr-icon>
|
|
||||||
</button>
|
</button>
|
||||||
<button class="btn btn-outline-primary chart-button-spacer" [hidden]="selectedTimeSpan !== timeSpans.Day || isSelectedDateToday()" (click)="handleDateArrowClick(1)">
|
<mat-form-field *ngIf="selectedTimeSpan === timeSpans.Day">
|
||||||
<clr-icon shape="caret right"></clr-icon>
|
<input matInput [matDatepicker]="picker" [(formControl)]="selectedDate">
|
||||||
|
<mat-datepicker-toggle matSuffix [for]="picker">
|
||||||
|
<mat-icon matDatepickerToggleIcon>keyboard_arrow_down</mat-icon>
|
||||||
|
</mat-datepicker-toggle>
|
||||||
|
<mat-datepicker #picker disabled="false"></mat-datepicker>
|
||||||
|
</mat-form-field>
|
||||||
|
<button mat-button *ngIf="selectedTimeSpan === timeSpans.Day && !isSelectedDateToday()" (click)="handleDateArrowClick(1)">
|
||||||
|
<mat-icon>arrow_forward</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
<button class="btn btn-outline-primary" [hidden]="selectedTimeSpan !== timeSpans.Day || isSelectedDateToday()" (click)="resetToToday()">
|
<button mat-button *ngIf="selectedTimeSpan === timeSpans.Day && !isSelectedDateToday()" (click)="resetToToday()">
|
||||||
Today
|
Today
|
||||||
</button>
|
</button>
|
||||||
</header> -->
|
</header>
|
||||||
<div id="chart" [chart]="chart"></div>
|
<div id="chart" [chart]="chart"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import * as moment from 'moment';
|
|||||||
|
|
||||||
import * as Highcharts from 'highcharts';
|
import * as Highcharts from 'highcharts';
|
||||||
import HC_exporting from 'highcharts/modules/exporting';
|
import HC_exporting from 'highcharts/modules/exporting';
|
||||||
|
import { FormControl } from '@angular/forms';
|
||||||
HC_exporting(Highcharts);
|
HC_exporting(Highcharts);
|
||||||
|
|
||||||
enum TimeSpan {
|
enum TimeSpan {
|
||||||
@@ -29,7 +30,7 @@ export class WeatherChartsComponent implements OnInit {
|
|||||||
|
|
||||||
public timeSpanItems: { [value: number]: string } = {};
|
public timeSpanItems: { [value: number]: string } = {};
|
||||||
public selectedTimeSpan: TimeSpan = TimeSpan.Last24Hours;
|
public selectedTimeSpan: TimeSpan = TimeSpan.Last24Hours;
|
||||||
public selectedDate: Date = moment().startOf('day').toDate();
|
public selectedDate: FormControl = new FormControl({ value: moment().startOf('day').toDate(), disabled: true });
|
||||||
public timeSpans: typeof TimeSpan = TimeSpan;
|
public timeSpans: typeof TimeSpan = TimeSpan;
|
||||||
|
|
||||||
constructor(private route: ActivatedRoute, private httpClient: HttpClient) { }
|
constructor(private route: ActivatedRoute, private httpClient: HttpClient) { }
|
||||||
@@ -46,25 +47,25 @@ export class WeatherChartsComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public handleDateArrowClick(value: number) {
|
public handleDateArrowClick(value: number) {
|
||||||
this.selectedDate = moment(this.selectedDate).add(value, 'day').toDate();
|
this.selectedDate.setValue(moment(this.selectedDate.value).add(value, 'day').toDate());
|
||||||
|
|
||||||
this.loadChart();
|
this.loadChart();
|
||||||
}
|
}
|
||||||
|
|
||||||
public isSelectedDateToday(): boolean {
|
public isSelectedDateToday(): boolean {
|
||||||
const isToday = moment(this.selectedDate).startOf('day').isSame(moment().startOf('day'));
|
const isToday = moment(this.selectedDate.value).startOf('day').isSame(moment().startOf('day'));
|
||||||
|
|
||||||
return isToday;
|
return isToday;
|
||||||
}
|
}
|
||||||
|
|
||||||
public resetToToday() {
|
public resetToToday() {
|
||||||
this.selectedDate = moment().startOf('day').toDate();
|
this.selectedDate.setValue(moment().startOf('day').toDate());
|
||||||
|
|
||||||
this.loadChart();
|
this.loadChart();
|
||||||
}
|
}
|
||||||
|
|
||||||
public getSelectedDateDisplayString(): string {
|
public getSelectedDateDisplayString(): string {
|
||||||
return moment(this.selectedDate).format('LL');
|
return moment(this.selectedDate.value).format('LL');
|
||||||
}
|
}
|
||||||
|
|
||||||
private loadChart() {
|
private loadChart() {
|
||||||
@@ -80,8 +81,8 @@ export class WeatherChartsComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case TimeSpan.Day: {
|
case TimeSpan.Day: {
|
||||||
start = moment(this.selectedDate).startOf('d').toDate();
|
start = moment(this.selectedDate.value).startOf('d').toDate();
|
||||||
end = moment(this.selectedDate).endOf('d').toDate();
|
end = moment(this.selectedDate.value).endOf('d').toDate();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user