Skip to content

Commit 2fa511d

Browse files
committed
added auto-updating
had to disable ssr for it to work
1 parent d82693e commit 2fa511d

File tree

4 files changed

+42
-34
lines changed

4 files changed

+42
-34
lines changed

angular.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@
5757
"development": {
5858
"optimization": false,
5959
"extractLicenses": false,
60-
"sourceMap": true
60+
"sourceMap": true,
61+
"ssr": false,
62+
"prerender": false
6163
}
6264
},
6365
"defaultConfiguration": "production"

src/app/components/home/home.component.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { HttpClient, HttpClientModule } from '@angular/common/http';
22
import { Component, OnInit } from '@angular/core';
33
import { DataService } from '../../services/data.service';
44
import { KeyValuePipe } from '@angular/common';
5+
import { Subscription, interval, switchMap } from 'rxjs';
56

67
@Component({
78
selector: 'app-home',
@@ -12,6 +13,7 @@ import { KeyValuePipe } from '@angular/common';
1213
styleUrl: './home.component.css'
1314
})
1415
export class HomeComponent implements OnInit {
16+
private intervalSub!: Subscription;
1517

1618
showData: any
1719
devices: any
@@ -27,20 +29,19 @@ export class HomeComponent implements OnInit {
2729

2830
}
2931
ngOnInit(): void {
30-
this.getCurrent()
31-
32+
this.intervalSub = interval(1000).pipe(
33+
switchMap(() => this.dataService.getCurrentData())
34+
).subscribe(res => {
35+
if (res) this.applyData(res);
36+
});
3237
}
3338

34-
getCurrent() {
35-
this.dataService.getCurrentData().subscribe((res: any) => {
36-
this.showData = res.MTConnectStreams
37-
this.devices = this.showData.Streams
38-
console.log(this.devices)
39-
40-
}, (error) => {
41-
console.log(error)
42-
})
39+
applyData(res: any) {
40+
this.showData = res.MTConnectStreams
41+
this.devices = this.showData.Streams
42+
console.log(this.devices)
4343
}
44+
4445
openDeviceComponent(item: any, x: any) {
4546
console.log('x', x)
4647
this.selectedComponentEventsIterate = [];

src/app/components/sample/sample.component.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { HttpClient, HttpClientModule } from '@angular/common/http';
22
import { Component, OnInit } from '@angular/core';
33
import { DataService } from '../../services/data.service';
44
import { KeyValuePipe } from '@angular/common';
5+
import { Subscription, interval, switchMap } from 'rxjs';
56

67
@Component({
78
selector: 'app-sample',
@@ -12,6 +13,8 @@ import { KeyValuePipe } from '@angular/common';
1213
styleUrl: './sample.component.css'
1314
})
1415
export class SampleComponent implements OnInit {
16+
private intervalSub!: Subscription;
17+
1518
showData: any
1619
devices: any
1720
selectedComponentName: any
@@ -26,20 +29,19 @@ export class SampleComponent implements OnInit {
2629

2730
}
2831
ngOnInit(): void {
29-
this.getCurrent()
30-
32+
this.intervalSub = interval(1000).pipe(
33+
switchMap(() => this.dataService.getCurrentData())
34+
).subscribe(res => {
35+
if (res) this.applyData(res);
36+
});
3137
}
3238

33-
getCurrent() {
34-
this.dataService.getSampleData().subscribe((res: any) => {
35-
this.showData = res.MTConnectStreams
36-
this.devices = this.showData.Streams
37-
console.log(this.devices)
38-
39-
}, (error) => {
40-
console.log(error)
41-
})
39+
applyData(res: any) {
40+
this.showData = res.MTConnectStreams
41+
this.devices = this.showData.Streams
42+
console.log(this.devices)
4243
}
44+
4345
openDeviceComponent(item: any, x: any) {
4446
console.log('x', x)
4547
this.selectedComponentEventsIterate = [];

src/app/components/setting/setting.component.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { HttpClient, HttpClientModule } from '@angular/common/http';
22
import { Component, OnInit } from '@angular/core';
33
import { DataService } from '../../services/data.service';
44
import { KeyValuePipe } from '@angular/common';
5+
import { Subscription, interval, switchMap } from 'rxjs';
6+
57
@Component({
68
selector: 'app-setting',
79
standalone: true,
@@ -11,6 +13,8 @@ import { KeyValuePipe } from '@angular/common';
1113
styleUrl: './setting.component.css'
1214
})
1315
export class SettingComponent implements OnInit {
16+
private intervalSub!: Subscription;
17+
1418
showData: any
1519
devices: any
1620
selectedComponentName: any
@@ -25,20 +29,19 @@ export class SettingComponent implements OnInit {
2529

2630
}
2731
ngOnInit(): void {
28-
this.getCurrent()
29-
32+
this.intervalSub = interval(1000).pipe(
33+
switchMap(() => this.dataService.getCurrentData())
34+
).subscribe(res => {
35+
if (res) this.applyData(res);
36+
});
3037
}
3138

32-
getCurrent() {
33-
this.dataService.getCountData().subscribe((res: any) => {
34-
this.showData = res.MTConnectStreams
35-
this.devices = this.showData.Streams
36-
console.log(this.devices)
37-
38-
}, (error) => {
39-
console.log(error)
40-
})
39+
applyData(res: any) {
40+
this.showData = res.MTConnectStreams
41+
this.devices = this.showData.Streams
42+
console.log(this.devices)
4143
}
44+
4245
openDeviceComponent(item: any, x: any) {
4346
console.log('x', x)
4447
this.selectedComponentEventsIterate = [];

0 commit comments

Comments
 (0)