forked from faucetsdn/udmi
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display points #53
Merged
Merged
Display points #53
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yes, missed that from the copy-paste...i will re-work it regardless with ur new api to get points