Skip to content

Commit e8fe049

Browse files
committed
Work in progress (Not working yet): Display the threats grouped by city.
1 parent 9accb86 commit e8fe049

File tree

4 files changed

+46
-9
lines changed

4 files changed

+46
-9
lines changed

src/app/components/threat/threat.component.html

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@
66
<!-- Loading icon -->
77
<spinner [visible]="isLoading"></spinner>
88

9+
<!-- TODO: Organize threats by location...-->
10+
<!--<ul class="nav nav-pills nav-justified">-->
11+
<!--<li *ngFor="let location of locationThreats" role="presentation" class="active">{{ location.city}}</li>-->
12+
<!--</ul>-->
13+
914
<!-- Number of threats -->
1015
<div class="alert alert-danger" role="alert" *ngIf="!isLoading">
11-
{{ (threats) ? threats.length : 0 }} threats.
16+
{{ (threats) ? threats.length : 0 }} threats in {{ (locationThreats) ? locationThreats.length : 0 }} locations
1217
</div>
1318

1419
<ul class="list-group posts" *ngIf="!isLoading">
@@ -18,6 +23,7 @@
1823
{{i+1}} - {{ threat.organization}}, {{ threat.assetType }}, {{ threat.threatType }}, {{ threat.threatSeverity }}, {{ threat.threatDateBegin}}
1924
</li>
2025
</ul>
26+
2127
</div>
2228

2329
<!-- Second 6 columns-wide panel: Selected Threat detail -->
@@ -33,18 +39,34 @@ <h3 class="panel-title">Organization: {{ selectedThreat.organization }}, Asset:
3339
<li class="list-group-item"><span class="badge">{{ selectedThreat.temperatureAlert }}</span>Temperature Alert:</li>
3440
<li class="list-group-item"><span class="badge">{{ selectedThreat.threatDateBegin }}</span>Threat Begin Date:</li>
3541
</ul>
42+
43+
<!-- Google maps for Angular: See docs at https://angular-maps.com -->
3644
<sebm-google-map [latitude]="selectedThreat.assetAddress.latitude"
37-
[longitude]="selectedThreat.assetAddress.longitude">
45+
[longitude]="selectedThreat.assetAddress.longitude"
46+
[zoom]="10"
47+
>
48+
<!-- Put a marker to display the temperature -->
3849
<sebm-google-map-marker
3950
[label]="''+selectedThreat.temperatureAlert"
4051
[latitude]="selectedThreat.assetAddress.latitude"
4152
[longitude]="selectedThreat.assetAddress.longitude"
53+
[opacity]="0.8"
4254
(markerClick)="clickedMarker()"
4355
>
4456
<sebm-google-map-info-window>
4557
<strong>{{selectedThreat.assetType}}, {{selectedThreat.threatType}}, {{ selectedThreat.temperatureAlert}}</strong>
4658
</sebm-google-map-info-window>
4759
</sebm-google-map-marker>
60+
61+
<!-- Draw a circle, just to show that we can! -->
62+
<sebm-google-map-circle
63+
[latitude]="selectedThreat.assetAddress.latitude"
64+
[longitude]="selectedThreat.assetAddress.longitude"
65+
[radius]="10000"
66+
[fillOpacity]="0.2"
67+
[fillColor]="red"
68+
>
69+
</sebm-google-map-circle>
4870
</sebm-google-map>
4971
</div>
5072
</div>

src/app/components/threat/threat.component.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {Component, OnInit} from "@angular/core";
22
import {ThreatService} from "../../services/threat.service";
33
import {Threat} from "../../domain/threat/threat";
4+
import {LocationThreat} from "../../domain/threat/locationthreat";
45

56
@Component({
67
selector: 'app-threat',
@@ -11,6 +12,7 @@ export class ThreatComponent implements OnInit {
1112

1213
isLoading: Boolean = true;
1314
threats: Threat[] = []
15+
locationThreats: LocationThreat[] = []
1416
selectedThreat: Threat = null
1517

1618
constructor(private threatService: ThreatService) {
@@ -23,15 +25,17 @@ export class ThreatComponent implements OnInit {
2325
this.threatService.getThreats()
2426
.subscribe(
2527
result => {
26-
//console.log(result);
27-
this.threats = result;
28+
console.log(result);
29+
this.threats = result.threats;
30+
this.locationThreats = result.locations
2831
},
2932
error => {
3033
console.log(error);
3134
this.isLoading = false;
3235
},
3336
() => {
34-
console.log((this.threats) ? this.threats.length : 0 + ' threats loaded.');
37+
console.log((this.threats) ? this.threats.length : 0 + ' total threats.');
38+
console.log((this.locationThreats) ? this.locationThreats.length : 0 + ' locations.');
3539
this.isLoading = false;
3640
}
3741
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {Threat} from "./threat";
2+
export class LocationThreat {
3+
constructor(public city: string,
4+
public threats: Threat[]) {
5+
}
6+
}

src/app/services/threat.service.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Injectable} from "@angular/core";
2-
import {Http, Headers} from "@angular/http";
2+
import {Http, Headers, URLSearchParams} from "@angular/http";
33
import {Observable} from "rxjs";
44
import {SecurityService} from "./security.service";
55
import {Threat} from "../domain/threat/threat";
@@ -20,15 +20,20 @@ export class ThreatService {
2020
/**
2121
* Retrieve the active threats.
2222
*/
23-
getThreats(): Observable<Threat[]> {
23+
getThreats(): Observable<any> {
2424
// console.log(this.securityService);
2525
let securityToken = this.securityService.securityContext ? this.securityService.securityContext.access_token : '';
2626
// console.log('Using security token ' + securityToken);
2727
let headers = new Headers();
2828
headers.append('Authorization', 'Bearer ' + securityToken);
2929
// console.log(headers);
30+
31+
// Query parameters
32+
let params = new URLSearchParams();
33+
params.set('forecast', '10'); // In number of days
34+
3035
console.log('Calling ' + this.threatsUrl);
31-
return this.http.get(this.threatsUrl, {headers: headers})
32-
.map(response => response.json().threats);
36+
return this.http.get(this.threatsUrl, {search: params, headers: headers})
37+
.map(response => response.json());
3338
}
3439
}

0 commit comments

Comments
 (0)