Skip to content

Commit a0dc503

Browse files
committed
Show zip code status for every shelter
1 parent 7499862 commit a0dc503

File tree

9 files changed

+56
-15
lines changed

9 files changed

+56
-15
lines changed

client/src/app/_services/shelters.service.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,10 @@ export class SheltersService {
8080
}
8181
);
8282
}
83+
84+
public getZipcodeStatus(): Observable<any> {
85+
return this.http.get(
86+
`${this.apiBaseUrl}/zipcode/status`
87+
);
88+
}
8389
}

client/src/app/shelters/add-shelter/add-shelter.component.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ export class AddShelterComponent implements AfterViewInit {
3333
return;
3434
}
3535

36-
console.log(this.shelter);
37-
3836
this.shelterService.addShelter(this.shelter)
3937
.subscribe(
4038
(res) => this.alertService.success('Shelter successfully added'),

client/src/app/shelters/shelter-card/shelter-card.component.css

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
.shelter-danger {
2-
background: #FF416C; /* fallback for old browsers */
3-
background: -webkit-linear-gradient(to right, #FF4B2B, #FF416C); /* Chrome 10-25, Safari 5.1-6 */
4-
background: linear-gradient(to right, #FF4B2B, #FF416C); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
5-
}
6-
71
.shelter-safe {
82
background: #11998e; /* fallback for old browsers */
93
background: -webkit-linear-gradient(to right, #38ef7d, #11998e); /* Chrome 10-25, Safari 5.1-6 */
104
background: linear-gradient(to right, #38ef7d, #11998e); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
115
}
126

7+
.shelter-danger {
8+
background: #FF416C; /* fallback for old browsers */
9+
background: -webkit-linear-gradient(to right, #FF4B2B, #FF416C); /* Chrome 10-25, Safari 5.1-6 */
10+
background: linear-gradient(to right, #FF4B2B, #FF416C); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
11+
}
12+
1313
.shelter-warning {
1414
background: #fceabb; /* fallback for old browsers */
1515
background: -webkit-linear-gradient(to right, #f8b500, #fceabb); /* Chrome 10-25, Safari 5.1-6 */

client/src/app/shelters/shelter-card/shelter-card.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div class="columns">
22
<div class="column is-1">
3-
<div class="shelter-danger is-pulled-right shelter-status-info"></div>
3+
<div class="is-pulled-right shelter-status-info" [ngClass]="{'shelter-danger': shelterStatus === 0, 'shelter-warning': shelterStatus === 1, 'shelter-safe': shelterStatus === 2}"></div>
44
</div>
55
<div class="column">
66
<div class="card">

client/src/app/shelters/shelter-card/shelter-card.component.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
22
import { Shelter } from '../shelter';
33
import { SheltersService } from 'src/app/_services/shelters.service';
44
import { AlertService } from 'src/app/_services/alert.service';
5+
import * as $ from 'jquery';
56

67
@Component({
78
selector: 'app-shelter-card',
@@ -11,8 +12,10 @@ import { AlertService } from 'src/app/_services/alert.service';
1112
export class ShelterCardComponent implements OnInit {
1213
@Input() shelter: Shelter;
1314
@Input() user: any;
15+
@Input() zipcodeStatus: any;
1416
@Output() updateUserDetails = new EventEmitter<any>();
1517
bingMapUrl = '';
18+
shelterStatus = 2;
1619

1720
joinShelter() {
1821
this.shelterService.joinShelter(this.shelter['_id'])
@@ -35,16 +38,19 @@ export class ShelterCardComponent implements OnInit {
3538
(err) => this.alertService.error(err)
3639
);
3740
}
41+
3842
constructor(
3943
private shelterService: SheltersService,
4044
private alertService: AlertService
4145
) { }
4246

43-
ngOnInit() {
44-
// this.shelterService.getHospitalDetails(this.shelter.lngLat, 10)
45-
// .subscribe(
46-
// (res) => console.log(res)
47-
// )
47+
ngOnInit() {
48+
if ($.inArray(+this.shelter.zipcode, this.zipcodeStatus.dangerous) !== -1) {
49+
this.shelterStatus = 0;
50+
} else if ($.inArray(+this.shelter.zipcode, this.zipcodeStatus.warning) !== -1) {
51+
this.shelterStatus = 1;
52+
}
53+
4854
this.bingMapUrl = `http://bing.com/maps/default.aspx?cp=${this.shelter.lngLat.split(',').reverse().join('~')}&sp=point.${this.shelter.lngLat.split(',').reverse().join('_')}_${this.shelter.name}_Shelter&lvl=15`
4955
}
5056

client/src/app/shelters/shelters.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ <h1 class="has-text-grey-lighter">No shelters available</h1>
1919
</div>
2020
<div class="columns" *ngFor="let shelter of shelters">
2121
<div class="column">
22-
<app-shelter-card [shelter]="shelter" [user]="user" (updateUserDetails)="updateUserDetails($event)"></app-shelter-card>
22+
<app-shelter-card [shelter]="shelter" [user]="user" [zipcodeStatus]="zipcodeStatus" (updateUserDetails)="updateUserDetails($event)"></app-shelter-card>
2323
</div>
2424
</div>
2525
</div>

client/src/app/shelters/shelters.component.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export class SheltersComponent implements OnInit {
1212
tab = 0;
1313
shelters = [];
1414
user: any;
15+
zipcodeStatus = {};
1516

1617
constructor(
1718
private alertService: AlertService,
@@ -31,6 +32,12 @@ export class SheltersComponent implements OnInit {
3132
(res) => this.shelters = res,
3233
(err) => this.alertService.error(err)
3334
);
35+
36+
this.shelterService.getZipcodeStatus()
37+
.subscribe(
38+
(res) => this.zipcodeStatus = res[0],
39+
this.alertService.error
40+
);
3441
}
3542

3643
updateUserDetails(user) {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const mongoose = require('mongoose')
2+
const Schema = mongoose.Schema;
3+
4+
const ZipcodeStatusModel = new Schema({
5+
dangerous: [{ type: Number }],
6+
warning: [{ type: Number }],
7+
safe: [{ type: Number }]
8+
})
9+
10+
module.exports = mongoose.model('Zipcodestatus', ZipcodeStatusModel)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const ZipcodeStatus = require('../model/ZipcodeStatus')
2+
3+
module.exports = {
4+
method: 'GET',
5+
path: '/api/zipcode/status',
6+
options: {
7+
handler: async (request, h) => {
8+
const zipCodeStatus = await ZipcodeStatus.find({})
9+
10+
return zipCodeStatus;
11+
},
12+
description: 'Returns zip code status'
13+
}
14+
}

0 commit comments

Comments
 (0)