1
+ import { HttpClient } from '@angular/common/http' ;
1
2
import { Injectable } from '@angular/core' ;
2
- import { Subject } from 'rxjs' ;
3
+ import { firstValueFrom , Observable , Subject } from 'rxjs' ;
3
4
import { DeviceConfiguration } from '../model/device-configuration' ;
4
5
5
6
@Injectable ( {
@@ -13,40 +14,28 @@ export class DeviceConfigurationService {
13
14
14
15
localDeviceConfigurations : DeviceConfiguration [ ] ;
15
16
16
- deviceConfigurations : DeviceConfiguration [ ] = [ {
17
- id : "epulse-feather" ,
18
- name : "ePulse Feather" ,
19
- imageSource : "assets/feather/epulsefeather.jpg" ,
20
- partitions : [ {
21
- name : 'Firmware' ,
22
- data : new Uint8Array ,
23
- offset : 0x00 ,
24
- url : './assets/feather/app-firmware.bin'
25
- } ]
26
- } ,
27
- {
28
- id : "espgateway" ,
29
- name : "ESPGateway" ,
30
- imageSource : "assets/espgateway/espgateway.jpg" ,
31
- partitions : [ {
32
- name : 'Firmware' ,
33
- data : new Uint8Array ,
34
- offset : 0x00 ,
35
- url : './assets/espgateway/app-firmware.bin'
36
- } ]
37
- } ] ;
17
+ deviceConfigurations : DeviceConfiguration [ ] = [ ] ;
38
18
39
19
40
- constructor ( ) { }
20
+ constructor ( public httpClient : HttpClient ) {
41
21
42
- getDeviceConfigurations ( ) : DeviceConfiguration [ ] {
22
+ }
23
+
24
+
25
+ loadDefaultDeviceConfiguration ( ) : Observable < DeviceConfiguration [ ] > {
26
+ return this . httpClient . get < DeviceConfiguration [ ] > ( "/assets/defaultDeviceConfiguration.json" ) ;
27
+ }
28
+
29
+ async getDeviceConfigurations ( ) : Promise < DeviceConfiguration [ ] > {
30
+ this . deviceConfigurations = await firstValueFrom ( this . loadDefaultDeviceConfiguration ( ) ) ;
43
31
this . loadLocalDeviceConfigurations ( ) ;
44
32
var combinedDeviceConfigurations = this . deviceConfigurations . concat ( this . localDeviceConfigurations ) ;
45
33
return combinedDeviceConfigurations ;
46
34
}
47
35
48
- getDeviceConfigurationById ( id : string ) {
49
- return this . getDeviceConfigurations ( ) . find ( x => x . id == id ) ;
36
+ async getDeviceConfigurationById ( id : string ) {
37
+ const combinedConfiguration = await this . getDeviceConfigurations ( ) ;
38
+ return combinedConfiguration . find ( x => x . id == id ) ;
50
39
}
51
40
52
41
addOrUpdateLocalStorageConfiguration ( deviceConfiguration : DeviceConfiguration ) {
0 commit comments