forked from faucetsdn/udmi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from Buildings-IOT/DisplayPoints
Display points
- Loading branch information
Showing
12 changed files
with
225 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<p>points works!</p> | ||
<p>{{ points }}</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,24 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { ActivatedRoute } from '@angular/router'; | ||
import { Point } from './points'; | ||
import { PointsService } from './points.service'; | ||
|
||
@Component({ | ||
templateUrl: './points.component.html', | ||
styleUrls: ['./points.component.scss'], | ||
}) | ||
export class PointsComponent implements OnInit { | ||
constructor() {} | ||
points: Point[] = []; | ||
loading: boolean = true; | ||
|
||
ngOnInit(): void {} | ||
constructor(private route: ActivatedRoute, private pointsService: PointsService) {} | ||
|
||
ngOnInit(): void { | ||
const deviceId: string = this.route.parent?.snapshot.parent?.params['id']; | ||
|
||
this.pointsService.getPoints(deviceId).subscribe(({ data, loading }) => { | ||
this.loading = loading; | ||
this.points = data.device?.points ?? []; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export interface PointModel { | ||
id: string; | ||
name: string; | ||
value: string; | ||
units: string; | ||
state: string; | ||
} | ||
|
||
export type Point = Partial<PointModel> | null; | ||
|
||
export type PointsResponse = { | ||
device: { | ||
id: string; | ||
points: Point[]; | ||
} | null; | ||
}; | ||
|
||
export type PointsQueryResponse = PointsResponse; | ||
|
||
export type PointsQueryVariables = { | ||
id: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { gql } from 'apollo-angular'; | ||
|
||
export const fragments = { | ||
point: gql` | ||
fragment Point on Point { | ||
id | ||
name | ||
value | ||
units | ||
state | ||
} | ||
`, | ||
}; | ||
|
||
export const GET_POINTS = gql` | ||
query GetDevicePoints($id: ID!) { | ||
device(id: $id) { | ||
id | ||
points { | ||
...Point | ||
} | ||
} | ||
} | ||
${fragments.point} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { ApolloTestingController, ApolloTestingModule } from 'apollo-angular/testing'; | ||
import { GraphQLModule } from '../graphql/graphql.module'; | ||
import { GET_POINTS } from './points.gql'; | ||
import { PointsQueryResponse } from './points'; | ||
import { PointsService } from './points.service'; | ||
|
||
describe('PointsService', () => { | ||
let service: PointsService; | ||
let controller: ApolloTestingController; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ApolloTestingModule, GraphQLModule], | ||
}); | ||
service = TestBed.inject(PointsService); | ||
controller = TestBed.inject(ApolloTestingController); | ||
}); | ||
|
||
afterEach(() => { | ||
controller.verify(); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
|
||
xit('should return the points', (done) => { | ||
const mockDeviceResponse: PointsQueryResponse = { | ||
device: { | ||
id: '123', | ||
points: [], | ||
}, | ||
}; | ||
|
||
// Make some assertion about the result for once it's fulfilled. | ||
service.getPoints('123').subscribe(({ data }) => { | ||
expect(data).toEqual(mockDeviceResponse); | ||
done(); | ||
}); | ||
|
||
// The following `expectOne()` will match the operation's document. | ||
// If no requests or multiple requests matched that document | ||
// `expectOne()` would throw. | ||
const op = controller.expectOne(GET_POINTS); | ||
|
||
// Assert the correct search options were sent. | ||
expect(op.operation.variables).toEqual({ | ||
id: '123', | ||
}); | ||
|
||
// Respond with mock data, causing Observable to resolve. | ||
op.flush({ | ||
data: mockDeviceResponse, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Apollo } from 'apollo-angular'; | ||
import { GET_POINTS } from './points.gql'; | ||
import { QueryRef } from 'apollo-angular'; | ||
import { Observable } from 'rxjs'; | ||
import { ApolloQueryResult } from '@apollo/client/core'; | ||
import { PointsQueryResponse, PointsQueryVariables } from './points'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class PointsService { | ||
devicesQuery!: QueryRef<PointsQueryResponse, PointsQueryVariables>; | ||
|
||
constructor(private apollo: Apollo) {} | ||
|
||
getPoints(deviceId: string): Observable<ApolloQueryResult<PointsQueryResponse>> { | ||
this.devicesQuery = this.apollo.watchQuery<PointsQueryResponse, PointsQueryVariables>({ | ||
query: GET_POINTS, | ||
variables: { | ||
id: deviceId, | ||
}, | ||
}); | ||
|
||
return this.devicesQuery.valueChanges; | ||
} | ||
} |