diff --git a/src/app/configs/configs.component.html b/src/app/configs/configs.component.html
index 782977c..6ee3cef 100644
--- a/src/app/configs/configs.component.html
+++ b/src/app/configs/configs.component.html
@@ -8,14 +8,14 @@
{{option}}
-
+
+
Device {{i + 1}}
-
-
+
-
+
+
+
+
diff --git a/src/app/configs/configs.component.ts b/src/app/configs/configs.component.ts
index 9c75aa8..9385fb0 100644
--- a/src/app/configs/configs.component.ts
+++ b/src/app/configs/configs.component.ts
@@ -25,18 +25,37 @@ export class ConfigsComponent implements OnInit {
devices: new FormArray([])
});
// Setup an API call to get the list of certificate IDs from DDB to store in options
- options: string[] = ['1217f08d31bbc1e9f70aabb700fb33878ccc1ec6caa38c5efb8c9f2709c7a444',
- '1370cf88050a5d9bc5aeef22f2b9756224c080c89f703eefeee8c9081dc6424e', '1e1f59fb7ac397487ceddbd65ff3ecb39e021997c1926317d076b2fe1f8a9614'];
+ options: string[];
+
+
+
filteredOptions: Observable;
ngOnInit() {
- this.filteredOptions = this.certificateIDInput.valueChanges.pipe(
- startWith(''),
- map(value => this._filter(value))
- );
+ this.getCertList();
}
+ getCertList() {
+ const httpOptions = {
+ headers: new HttpHeaders({
+ 'Content-Type': 'application/json'
+ })
+ };
+ const certList = this.http.get('https://4ax24ru9ra.execute-api.us-east-1.amazonaws.com/Gamma/HPIoTgetCertList/', httpOptions);
- plcArray(i) { return this.configForm.get('devices.' + i + '.plcdata') as FormArray; }
+ certList.subscribe(
+ data => {
+ this.options = data as string[];
+ console.log(data);
+ this.filteredOptions = this.certificateIDInput.valueChanges.pipe(
+ startWith(''),
+ map(value => this._filter(value))
+ );
+ },
+ (err) => console.log(err)
+ );
+
+ }
+ plcArray(i) { return this.configForm.get('devices.' + i + '.PLCData') as FormArray; }
private _filter(value: string): string[] {
const filterValue = value.toLowerCase();
return this.options.filter(option => option.toLowerCase().includes(filterValue));
@@ -54,26 +73,26 @@ export class ConfigsComponent implements OnInit {
this.devicesArray.clear();
for (let i = this.devicesArray.length; i < numberOfDevices; i++) {
this.devicesArray.push(this.builder.group({
- appname: this.configDownloaded['device' + (i + 1).toString()].appname,
- certificateID: this.configDownloaded['device' + (i + 1).toString()].certificateID,
- company: this.configDownloaded['device' + (i + 1).toString()].company,
- location: this.configDownloaded['device' + (i + 1).toString()].locationID,
- field: this.configDownloaded['device' + (i + 1).toString()].field,
- devicetype: this.configDownloaded['device' + (i + 1).toString()].deviceType,
- plcdata: new FormArray([]),
- modbusdata: new FormArray([]),
- currentdata: new FormArray([]),
- voltagedata: new FormArray([])
+ appname: this.configDownloaded['device' + (i + 1).toString()].appname,
+ certificateID: this.configDownloaded['device' + (i + 1).toString()].certificateID,
+ company: this.configDownloaded['device' + (i + 1).toString()].company,
+ location: this.configDownloaded['device' + (i + 1).toString()].locationID,
+ field: this.configDownloaded['device' + (i + 1).toString()].field,
+ devicetype: this.configDownloaded['device' + (i + 1).toString()].deviceType,
+ PLCData: new FormArray([]),
+ modbusdata: new FormArray([]),
+ currentdata: new FormArray([]),
+ voltagedata: new FormArray([])
}));
if (this.configDownloaded['device' + (i + 1).toString()].PLCData !== 'empty') {
for (let j = 1; j - 1 < Object.keys(this.configDownloaded['device' + (i + 1).toString()].PLCData).length; j++ ) {
this.plcArray(i).push(this.builder.group({
- plcip: this.configDownloaded['device' + (i + 1).toString()].PLCData['tag' + j.toString()].plcIP,
- plctag: this.configDownloaded['device' + (i + 1).toString()].PLCData['tag' + j.toString()].tag,
- plcname: this.configDownloaded['device' + (i + 1).toString()].PLCData['tag' + j.toString()].name,
- plcchangethres: this.configDownloaded['device' + (i + 1).toString()].PLCData['tag' + j.toString()].changeThreshold,
- plcguaranteed: this.configDownloaded['device' + (i + 1).toString()].PLCData['tag' + j.toString()].guaranteed,
- plctype: this.configDownloaded['device' + (i + 1).toString()].PLCData['tag' + j.toString()].plcType,
+ plcIP: this.configDownloaded['device' + (i + 1).toString()].PLCData['tag' + j.toString()].plcIP,
+ tag: this.configDownloaded['device' + (i + 1).toString()].PLCData['tag' + j.toString()].tag,
+ name: this.configDownloaded['device' + (i + 1).toString()].PLCData['tag' + j.toString()].name,
+ changeThreshold: this.configDownloaded['device' + (i + 1).toString()].PLCData['tag' + j.toString()].changeThreshold,
+ guaranteed: this.configDownloaded['device' + (i + 1).toString()].PLCData['tag' + j.toString()].guaranteed,
+ plcType: this.configDownloaded['device' + (i + 1).toString()].PLCData['tag' + j.toString()].plcType,
}));
}
}
@@ -93,4 +112,63 @@ export class ConfigsComponent implements OnInit {
(err) => console.log(err)
);
}
+
+ addDataPoint(e) {
+ this.plcArray(e).push(this.builder.group({
+ plcIP: '',
+ tag: '',
+ name: '',
+ changeThreshold: '',
+ guaranteed: '',
+ plcType: ''
+ }));
+ }
+
+ removeDataPoint(i, j) {
+ this.plcArray(i).removeAt(j);
+ }
+
+ addDevice() {
+ this.devicesArray.push(this.builder.group({
+ appname: '',
+ certificateID: '',
+ company: '',
+ location: '',
+ field: '',
+ devicetype: '',
+ PLCData: new FormArray([]),
+ modbusdata: new FormArray([]),
+ currentdata: new FormArray([]),
+ voltagedata: new FormArray([])
+ }));
+ }
+
+ removeDevice(e) {
+ this.devicesArray.removeAt(e);
+ }
+
+ saveConfig() {
+ const formObj = this.configForm.getRawValue();
+ const devices = formObj.devices;
+ let j = 1;
+ devices.forEach(device => {
+ let i = 1;
+ const plcdata = {};
+ device.PLCData.forEach(element => {
+ plcdata['tag' + i] = element;
+ i++;
+ });
+ device.PLCData = plcdata;
+ formObj['device' + j.toString()] = device;
+ j++;
+ });
+ delete formObj.devices;
+ formObj.version = this.configDownloaded.version + 1;
+ const serialized = JSON.stringify(formObj);
+ this.http.post('https://4ax24ru9ra.execute-api.us-east-1.amazonaws.com/Gamma/postConfig/', serialized)
+ .subscribe(
+ data => console.log('success!', data),
+ error => console.error('couldn\'t post because', error)
+ );
+ }
}