Skip to content
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

Auto-fills new department from Firecares ID #497

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion client/app/admin/admin-home/admin-home.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export default class AdminHomeController {
resource2: type
};


this.FireDepartmentService.fixtures(params, {}).$promise
.then(() => {
this.ModalService.alert({
Expand Down
20 changes: 19 additions & 1 deletion client/app/admin/fire-department/fire-department.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export default class FireDepartmentController {
submitted = false;

/*@ngInject*/
constructor(FireDepartment, Modal, currentFireDepartment, $state, Upload) {
constructor(FireDepartment, Modal, currentFireDepartment, $state, Upload, $http) {
this.$http = $http;
this.FireDepartmentService = FireDepartment;
this.ModalService = Modal;
this.file = null;
Expand Down Expand Up @@ -106,4 +107,21 @@ export default class FireDepartmentController {
});
});
}

async onFirecaresIdUpdate(event) {
const value = event && event.target && event.target.value;
if (value) {
const firecares_id = parseInt(value);
const url = `/api/third-party/firecares/department/${firecares_id}`;
const response = await this.$http.get(url);
if (response && response.data) {
const [latitude, longitude] = response.data.geom.coordinates;
this.fireDepartment.fd_id = response.data.fdid;
this.fireDepartment.name = response.data.name;
this.fireDepartment.state = response.data.state;
this.fireDepartment.latitude = latitude;
this.fireDepartment.longitude = longitude;
}
}
}
}
4 changes: 2 additions & 2 deletions client/app/admin/fire-department/fire-department.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ <h2 class="subheader">Edit Fire Department</h2>

<div class="form-group " ng-class="{ 'has-success': fdForm.firecares_id.$valid && vm.submitted,'has-error': fdForm.firecares_id.$invalid && vm.submitted }">
<label>Firecares ID</label>
<input type="text" name="firecares_id" class="form-control input-md" ng-model="vm.fireDepartment.firecares_id" required="required"/>
<input type="text" name="firecares_id" class="form-control input-md" ng-model="vm.fireDepartment.firecares_id" required="required" ng-blur="vm.onFirecaresIdUpdate($event)"/>
<p class="help-block" ng-show="fdForm.firecares_id.$error.required && vm.submitted">
Firecares ID is required
</p>
</div>

<div class="form-group " ng-class="{ 'has-success': fdForm.fd_id.$valid && vm.submitted,'has-error': fdForm.fd_id.$invalid && vm.submitted }">
<div class="form-group" ng-class="{ 'has-success': fdForm.fd_id.$valid && vm.submitted,'has-error': fdForm.fd_id.$invalid && vm.submitted }">
<label>FD ID</label>
<input type="text" name="fd_id" class="form-control input-md" ng-model="vm.fireDepartment.fd_id" required="required"/>
<p class="help-block" ng-show="fdForm.fd_id.$error.required && vm.submitted">
Expand Down
16 changes: 16 additions & 0 deletions server/api/third-party/firecares/firecares.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import axios from 'axios';

export async function getDepartment(req, res) {
const firecares_id = req.params.firecares_id;
if (firecares_id) {
try {
const url = `https://firecares.org/api/v1/firestations/${firecares_id}`;
const response = await axios.get(url);
return res.json(response.data);
} catch (err) {
return res.send(500);
}
} else {
return res.send(404);
}
}
17 changes: 17 additions & 0 deletions server/api/third-party/firecares/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

import { Router } from 'express';

import * as controller from './firecares.controller';
import * as auth from '../../../auth/auth.service';

const router = new Router();

router.get(
'/department/:firecares_id',
auth.isApiAuthenticated,
auth.hasRole('department_admin'),
controller.getDepartment
);

module.exports = router;
1 change: 1 addition & 0 deletions server/api/third-party/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import { Router } from 'express';
const router = new Router();

router.use('/first-arriving', require('./first-arriving'));
router.use('/firecares', require('./firecares'));

module.exports = router;