Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
Support for Assest and Child Devices
Browse files Browse the repository at this point in the history
  • Loading branch information
SabreenIrfana committed Mar 10, 2022
1 parent 4c5d011 commit 6abf080
Show file tree
Hide file tree
Showing 9 changed files with 24,634 additions and 85 deletions.
24,600 changes: 24,558 additions & 42 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gp-processing-widget",
"version": "2.0.0",
"version": "2.0.1",
"description": "This is an Angular 11 widget, which is designed to display the current process state based on the latest event. ",
"author": "Khushi Khanna - Software AG, Global Presales",
"license": "Apache 2.0",
Expand Down Expand Up @@ -33,8 +33,10 @@
"@c8y/ng1-modules": "^1011.0.12",
"@c8y/ngx-components": "^1011.0.12",
"@c8y/style": "1011.0.12",
"moment": "^2.26.0",
"@ng-select/ng-select": "^6.1.0",
"font-awesome": "^4.7.0"

},
"devDependencies": {
"@angular-devkit/build-angular": "~0.1101.2",
Expand Down
2 changes: 1 addition & 1 deletion projects/gp-processing/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gp-processing",
"version": "2.0.0",
"version": "2.0.1",
"description": "This is an Angular 11 widget, which is designed to display the current process state based on the latest event. ",
"author": "Khushi Khanna - Software AG, Global Presales",
"license": "Apache 2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,10 @@


</div>
<div class="form-group">
<label class="c8y-switch">
<input type="checkbox" checked="config.innerChild" [(ngModel)]="config.innerChild" />
<span></span> Include child devices
</label>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ export class GpLibProcessingConfig implements OnInit {
constructor() {
}
ngOnInit() {
if (this.config.innerChild === undefined) {

this.config.innerChild = false;

}
if (this.config.dataSource === undefined) {
this.config.dataSource = [{displayStatus: '', fieldValue: '', matIcon: 'bathtub'}];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class GpLibProcessingWidgetComponent implements OnInit {
displayStatus = [];
fieldValue = [];
deviceId: any;
innerChild: any;
statusValue = '';
realTimeEventSubs = [];
index = -1;
Expand All @@ -50,60 +51,79 @@ export class GpLibProcessingWidgetComponent implements OnInit {
this.deviceId = this.config.device.id;
this.fieldName = this.config.fieldName;
} else {
this.deviceId = '2422320',
this.displayStatus = [ 'Truck Depot', 'In Route', 'Pick Up Point'];
this.fieldValue = ['truckdepoleft', 'inroute', 'pickuppoint'];
this.matImages = ['truck', 'list', 'map-marker'];
this.indoorEventType = 'c8y_LocationUpdate';
this.fieldName = 'process';
// this.deviceId = '12179',
// this.displayStatus = ['Cleaning', 'Re packaging', 'Quality Check', 'Dispatch', 'In Service'];
// this.fieldValue = ['2138-1', '2138-2', '2138-3', '2138-4', '2138-5'];
// this.matImages = ['map-marker', 'map-marker', 'map-marker', 'map-marker','map-marker'];
// this.indoorEventType = 'c8y_LocationUpdate';
// this.fieldName = 's7y_BeaconId';
// // this.deviceId = '15085135',
// this.innerChild = true ;
// this.displayStatus = ['Buffering', 'AutoTuning', 'Learning', 'Monitoring'];
// this.fieldValue = ['Buffering', 'AutoTuning', 'Learning', 'Monitoring'];
// this.matImages = ['map-marker', 'map-marker', 'map-marker', 'map-marker','map-marker'];
// this.indoorEventType = 'c8y_nano_state';
// this.fieldName = 'state_flow';
}
this.arrivalTime = new Date();
this.fetchEvents();
}
async getDeviceList() {
let response: any = null;
let assetresponse: any = null;
const filter: object = {
pageSize: 2000,
pageSize: 20000,
withTotalPages: true,
};
response = (await this.inventory.childDevicesList(this.deviceId, filter)).data;
// Check that whether the device has child devices or not
if (response.length === 0) {
this.fetchCurrentState(this.deviceId);
} else {
response.forEach(device => {
const deviceresp =(await this.inventory.detail(this.deviceId,filter)).data;
if(deviceresp.hasOwnProperty('c8y_IsDevice'))
{
if(this.innerChild)
{
response = (await this.inventory.childDevicesList(this.deviceId, filter)).data;
// Check that whether the device has child devices or not
if (response.length === 0) {
this.fetchCurrentState(this.deviceId);
} else {
this.fetchCurrentState(this.deviceId);
response.forEach(device => {
this.fetchCurrentState(device.id);
});
}
}
else
{
this.fetchCurrentState(this.deviceId);
}
}
else if(deviceresp.hasOwnProperty('c8y_IsAsset') || deviceresp.hasOwnProperty('c8y_IsDeviceGroup'))
{
assetresponse = (await this.inventory.childAssetsList(this.deviceId, filter)).data;
if(assetresponse.length != 0){
assetresponse.forEach(async device => {
this.fetchCurrentState(device.id);
if(this.innerChild){
response = (await this.inventory.childDevicesList(device.id, filter)).data;
if(response.length != 0)
{
response.forEach(childdevice => {
this.fetchCurrentState(childdevice.id);
});
}

}

});
}
}
else {
alert ("Please select asset or a device");
}
}
// Fetches the current state for a particular device Id
async fetchCurrentState(deviceId) {
const moment = moment_;
const now = moment();
// const filter = { pageSize: 3,
// source: deviceId,
// type: this.config.indoorEventType,
// dateTo: now.add(1, 'days').format('YYYY-MM-DD'),
// dateFrom: '1970-01-01',
// revert: false
// };
// const { data, res, paging } = await this.events.list(filter);
// console.log(data);
// console.log(res);
// const lastEvent = data[0];
// if (lastEvent.type === this.config.indoorEventType) {
// if (lastEvent.hasOwnProperty(this.config.fieldName)) {
// this.arrivalTime = lastEvent.creationTime;
// this.statusValue = lastEvent[this.config.fieldName];
// this.fieldValue.map((singleValue, index) => {
// if (this.statusValue.includes(singleValue)) {
// this.index = index;
// }
// });
// } else if (this.arrivalTime !== undefined && Date.parse(this.arrivalTime) < Date.parse(lastEvent.creationTime)) {
// this.index = this.displayStatus.length - 1;
// }
// }

// fetches the events for each device based of date

Expand All @@ -117,7 +137,7 @@ export class GpLibProcessingWidgetComponent implements OnInit {
}
this.events.list(filter)
.then( res => {
const lastEvent = res[0];
const lastEvent = res.data[0];
if (lastEvent && lastEvent.type === this.indoorEventType) {
if (lastEvent.hasOwnProperty(this.fieldName)) {
this.arrivalTime = lastEvent.creationTime;
Expand Down
2 changes: 1 addition & 1 deletion runtime/cumulocity.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"manifest": {
"noAppSwitcher": true,
"requiredPlatformVersion": ">=1011.0.0",
"version":"2.0.0",
"version":"2.0.1",
"author":"Software AG, Global Presales",
"description":"This is an Angular 8 widget, which is designed to display the current process state based on the latest event.",
"license": "Apache 2.0"
Expand Down
2 changes: 1 addition & 1 deletion runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"dist\\bundle-src\\custom-widget.js": "processing-runtime-widget-CustomWidget",
"dist/bundle-src/custom-widget.js": "processing-runtime-widget-CustomWidget"
},
"version": "2.0.0",
"version": "2.0.1",
"description": "Runtime package.json for library widget (written by Software AG Global Presales)",
"author": "Darpankumar Lalani - Software AG, Global Presales",
"license": "Apache 2.0"
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import {
} from '@c8y/client';

const auth = new BasicAuth({
user: '###',
user: '####',
password: '###',
tenant: '###'
});
Expand Down

0 comments on commit 6abf080

Please sign in to comment.