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

Commit

Permalink
- last event check added
Browse files Browse the repository at this point in the history
  • Loading branch information
khushikhanna299 committed Sep 15, 2020
1 parent a90f49a commit d433570
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gp-processing-widget",
"version": "0.0.0",
"version": "1.0.0",
"description": "This is an Angular 8 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 @@ -54,9 +54,8 @@ export class GpLibProcessingWidgetComponent implements OnInit {
withTotalPages: true,
};
response = (await this.inventory.childDevicesList(this.deviceId, filter)).data;

// Check that the response is a Group and not a device
if (response.hasOwnProperty('c8y_IsDevice')) {
// Check that whether the device has child devices or not
if (response.length === 0) {
this.fetchCurrentState(this.deviceId);
} else {
response.forEach(device => {
Expand All @@ -68,6 +67,7 @@ export class GpLibProcessingWidgetComponent implements OnInit {
fetchCurrentState(deviceId) {
const moment = moment_;
const now = moment();

// fetches the events for each device based of date
this.events.listBySource$(deviceId, { pageSize: 3,
type: this.config.indoorEventType,
Expand All @@ -81,15 +81,15 @@ export class GpLibProcessingWidgetComponent implements OnInit {
const lastEvent = res[0];
if (lastEvent.type === this.config.indoorEventType) {
if (lastEvent.hasOwnProperty(this.config.fieldName)) {
this.arrivalTime = lastEvent.time;
this.arrivalTime = lastEvent.creationTime;
this.statusValue = lastEvent[this.config.fieldName];
this.fieldValue.map((singleValue, index) => {
if (this.statusValue.includes(singleValue)) {
this.index = index;
}
});
} else {
this.index = this.displayStatus.length;
} else if (this.arrivalTime !== undefined && Date.parse(this.arrivalTime) < Date.parse(lastEvent.creationTime)) {
this.index = this.displayStatus.length - 1;
}
}
});
Expand All @@ -104,15 +104,15 @@ export class GpLibProcessingWidgetComponent implements OnInit {
const lastEvent = eventData.data;
if (lastEvent.type === this.config.indoorEventType) {
if (lastEvent.hasOwnProperty(this.config.fieldName)) {
this.arrivalTime = lastEvent.time;
this.arrivalTime = lastEvent.creationTime;
this.statusValue = lastEvent[this.config.fieldName];
this.fieldValue.map((singleValue, index) => {
if (this.statusValue.includes(singleValue)) {
this.index = index;
}
});
} else {
this.index = this.displayStatus.length;
this.index = this.displayStatus.length - 1;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {MatButtonModule,
MatFormFieldModule,
MatInputModule} from '@angular/material';
import { IconSelectorModule } from './icon-selector/icon-selector.module';

import * as preview from './preview-image';
@NgModule({
declarations: [GpLibProcessingWidgetComponent, GpLibProcessingConfig],
imports: [
Expand All @@ -51,6 +51,7 @@ import { IconSelectorModule } from './icon-selector/icon-selector.module';
id: 'trolley-processing.widget',
label: 'Processing Widget',
description: 'Processing Widget',
previewImage: preview.previewImage,
component: GpLibProcessingWidgetComponent,
configComponent: GpLibProcessingConfig,
data : {
Expand Down
21 changes: 21 additions & 0 deletions projects/gp-lib-processing-widget/src/lib/preview-image.ts

Large diffs are not rendered by default.

0 comments on commit d433570

Please sign in to comment.