Skip to content

Commit 1d33335

Browse files
authored
Merge pull request #140 from CodeForPhilly/petpoint->shelterluv
shelterluv -> petpoint
2 parents ac2bfe2 + ab14287 commit 1d33335

18 files changed

+201
-232
lines changed

src/client/src/pages/Admin.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { Component } from 'react';
2-
import {Tabs, Tab, Container, Paper } from "@material-ui/core";
2+
import {Tabs, Tab, Paper } from "@material-ui/core";
33
import TabPanel from '../components/TabPanel';
44
import Grid from '@material-ui/core/Grid';
55
import Table from '@material-ui/core/Table';
@@ -9,7 +9,6 @@ import TableContainer from '@material-ui/core/TableContainer';
99
import TableHead from '@material-ui/core/TableHead';
1010
import TableRow from '@material-ui/core/TableRow';
1111
import { withStyles } from '@material-ui/core/styles';
12-
import Divider from '@material-ui/core/Divider';
1312
import LinearProgress from '@material-ui/core/LinearProgress';
1413
import CircularProgress from '@material-ui/core/CircularProgress';
1514
import { UploadForm, DownloadForm, ExecuteForm } from '../components/Forms';
@@ -47,11 +46,15 @@ class Admin extends Component {
4746
this.handleGetStatistics = this.handleGetStatistics.bind(this);
4847
}
4948

50-
componentDidMount(){
49+
refreshPage() {
5150
this.handleGetFileList();
5251
this.handleGetStatistics();
5352
}
5453

54+
componentDidMount(){
55+
this.refreshPage();
56+
}
57+
5558
handleIndexChange(event, newIndex){
5659
this.setState({activeIndex: newIndex});
5760
};
@@ -85,6 +88,8 @@ class Admin extends Component {
8588

8689
this.setState({loading: false});
8790

91+
this.refreshPage();
92+
8893
return result
8994
}
9095

src/client/src/pages/DataView360/DataView360.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ class DataView360 extends Component {
5757
render(){
5858
const { classes } = this.props;
5959

60-
//temporary taking the first pet row in petpoint - todo: change to list
6160
return(
6261
<Container>
6362
<SearchBar participant={this.state.participant}
@@ -67,7 +66,7 @@ class DataView360 extends Component {
6766
<Paper elevation={1} style={{"padding":"1em"}}>
6867
<ContactInfo participant={_.get(this.state, "participantData.salesforcecontacts")} />
6968
<Donations donations={_.get(this.state, 'participantData.salesforcedonations')} />
70-
<Adoptions adoptions={_.get(this.state, 'participantData.petpoint')} />
69+
<Adoptions adoptions={_.get(this.state, 'participantData.shelterluvpeople')} />
7170
<Volunteer volunteer={_.get(this.state, 'participantData.volgistics.json')}
7271
volunteerShifts={_.get(this.state, 'participantData.volgistics_shifts_results')}/>
7372

src/client/src/pages/DataView360/components/Adoptions.js

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ import { Paper, Typography, Table, TableContainer, TableHead, TableBody, TableRo
33
import { withStyles } from '@material-ui/core/styles';
44
import "./styles/Adoptions.css";
55
import _ from 'lodash';
6-
import moment from 'moment';
7-
8-
const ROWS_TO_SHOW = 3
96

107
const StyledTableCell = withStyles((theme)=>({
118
head:{
@@ -22,52 +19,39 @@ const StyledTableRow = withStyles((theme)=>({
2219
}
2320
}))(TableRow);
2421

25-
class Adoptions extends Component {
26-
constructor(props) {
27-
super(props);
2822

29-
this.createRows = this.createRows.bind(this);
30-
}
3123

32-
createRows(adoptions){
33-
adoptions = _.map(adoptions, pet => {
34-
return pet.json;
35-
});
36-
const adoptionsSorted = _.sortBy(adoptions, 'outcome_date');
37-
const latestAdoptions = adoptionsSorted.slice(0,ROWS_TO_SHOW);
24+
class Adoptions extends Component {
3825

39-
const result = _.map(latestAdoptions, pet => {
40-
return(<StyledTableRow>
41-
<TableCell align="center">{moment(pet.outcome_date).format("YYYY-MM-DD")}</TableCell>
42-
<TableCell align="center">{pet.animal_name}</TableCell>
43-
<TableCell align="center">{pet.animal_type}</TableCell>
44-
<TableCell align="center">{pet.primary_breed}</TableCell>
45-
<TableCell align="center">{pet.animal_num}</TableCell>
46-
<TableCell align="center">{pet.age_group}</TableCell>
47-
</StyledTableRow>);
26+
getAnimalIds() {
27+
let result = [];
4828

49-
});
29+
let animal_ids = _.get(this.props, 'adoptions[0].animal_ids');
30+
if(animal_ids) {
31+
result = _.filter(animal_ids.split("'"), item => {
32+
return _.isNaN(_.parseInt(item)) !== true;
33+
})
34+
}
5035

5136
return result;
5237
}
5338

5439
render() {
40+
// todo: update when we add pet info
41+
// todo: clean array of animal_id
5542
return (<Container style={{"marginTop":"1em"}}>
56-
<Typography align='center' gutterBottom='true' variant='h4'>Adoption/Foster Records(Top 3)</Typography>
43+
<Typography align='center' variant='h4'>Adoption/Foster Records(Top 3)</Typography>
5744
<TableContainer style={{"marginTop":"1em"}} component={Paper} variant='outlined'>
5845
<Table>
5946
<TableHead>
6047
<TableRow>
61-
<StyledTableCell align="center">Date of Adoption</StyledTableCell>
62-
<StyledTableCell align="center">Name</StyledTableCell>
63-
<StyledTableCell align="center">Type/Species</StyledTableCell>
64-
<StyledTableCell align="center">Primary Breed</StyledTableCell>
65-
<StyledTableCell align="center">Animal-Number</StyledTableCell>
66-
<StyledTableCell align="center">Current Age</StyledTableCell>
48+
<StyledTableCell align="center">Number of Adoptions</StyledTableCell>
6749
</TableRow>
6850
</TableHead>
6951
<TableBody>
70-
{ this.props.adoptions && this.createRows(this.props.adoptions) }
52+
<StyledTableRow>
53+
<TableCell align="center"> {_.size(this.getAnimalIds())}</TableCell>
54+
</StyledTableRow>
7155
</TableBody>
7256
</Table>
7357
</TableContainer>

src/client/src/pages/DataView360/components/ContactInfo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ class ContactInfo extends Component {
1919
const phoneStr = _.get(this.props, "participant.phone");
2020
let phone = _.isEmpty(phoneStr) ? '-' : phoneStr.split(" ").join("");
2121

22-
return (<Container class="contactInfo">
23-
<Typography align='center' gutterBottom='true' variant='h4'>Contact Info</Typography>
22+
return (<Container className="contactInfo">
23+
<Typography align='center' variant='h4'>Contact Info</Typography>
2424
<Paper variant='outlined' style={{padding:'1em'}}>
2525
<div style={{"display":"flex", "justifyContent":"space-between"}}>
2626
<Typography>

src/client/src/pages/DataView360/components/Donations.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class Donations extends Component {
3838
donationsSorted = donationsSorted.reverse();
3939
const latestDonations = donationsSorted.slice(0,ROWS_TO_SHOW);
4040

41-
const result = _.map(latestDonations, donation => {
42-
return( <StyledTableRow>
41+
const result = _.map(latestDonations, (donation, index) => {
42+
return( <StyledTableRow key={index}>
4343
<TableCell align="center">{donation.close_date}</TableCell>
4444
<TableCell align="center">${donation.amount}</TableCell>
4545
<TableCell align="center">{donation.type}</TableCell>
@@ -52,7 +52,7 @@ class Donations extends Component {
5252
render() {
5353
return (
5454
<Container style={{"marginTop":"1em"}}>
55-
<Typography align='center' gutterBottom='true' variant='h4'>Financial Support Activity(Top 3)</Typography>
55+
<Typography align='center' variant='h4'>Financial Support Activity(Top 3)</Typography>
5656
<TableContainer style={{"marginTop":"1em"}} component={Paper} variant='outlined'>
5757
<Table>
5858
<TableHead>

src/client/src/pages/DataView360/components/SearchBar.js

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
import React, { Component } from 'react';
22
import {Button, Paper, Select, InputLabel, MenuItem, FormControl, TextField, IconButton} from '@material-ui/core';
33
import SearchIcon from '@material-ui/icons/Search';
4-
import { withStyles } from '@material-ui/core/styles';
54
import "./styles/SearchBar.css";
65
import CircularProgress from '@material-ui/core/CircularProgress';
76

87
import _ from 'lodash';
98

109
const LIST_LIMIT = 200;
1110

12-
const styles = theme => ({
13-
spinner: {
14-
display: 'flex',
15-
marginLeft: theme.spacing(2)
16-
}
17-
});
18-
1911
class SearchBar extends Component {
2012
constructor(props) {
2113
super(props);
@@ -55,7 +47,7 @@ class SearchBar extends Component {
5547
searchParticipant(event) {
5648
return (
5749
<form onSubmit={this.handleParticipantSearch} style={{"display":"flex"}}>
58-
<TextField style={{"min-width":"300px"}}
50+
<TextField style={{minWidth:300}}
5951
error={this.state.alertMinChars}
6052
helperText={this.state.alertMinChars ? "Requires 3 search characters for first and last name" : ""}
6153
id="participant-search"
@@ -91,7 +83,7 @@ class SearchBar extends Component {
9183
}
9284

9385
return (
94-
<FormControl style={{"minWidth":"20em"}}>
86+
<FormControl style={{minWidth:"20em"}}>
9587
<InputLabel id="paws-participant-label">Select Participant - Top 200 Results</InputLabel>
9688
<Select
9789
labelId="paws-participant-label"
@@ -124,8 +116,6 @@ class SearchBar extends Component {
124116
};
125117

126118
render() {
127-
const { classes } = this.props;
128-
129119
return (
130120
<Paper elevation={1} style={{
131121
"display":"flex",
@@ -135,15 +125,11 @@ class SearchBar extends Component {
135125
"justifyContent":"space-around"
136126
}}>
137127
{this.searchParticipant()}
138-
139-
140128
{this.state.isSearchBusy === true ?
141-
(<div className={classes.spinner}>
142-
<CircularProgress />
143-
</div>) : this.selectParticipant()}
129+
<CircularProgress /> : this.selectParticipant()}
144130
</Paper>
145131
)
146132
}
147133
}
148134

149-
export default withStyles(styles)(SearchBar);
135+
export default SearchBar;

src/client/src/pages/DataView360/components/Volunteer.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ const StyledTableRow = withStyles((theme)=>({
2424
const SHIFTS_TO_SHOW = 3;
2525

2626
class Volunteer extends Component {
27-
constructor(props) {
28-
super(props);
29-
}
3027

3128
createShiftRows(shifts) {
3229
const shiftsSorted = _.sortBy(shifts, shift => {
@@ -35,8 +32,8 @@ class Volunteer extends Component {
3532

3633
const lastShifts = shiftsSorted.slice(shiftsSorted.length - SHIFTS_TO_SHOW, shiftsSorted.length)
3734

38-
const result = _.map(lastShifts, shift => {
39-
return(<StyledTableRow>
35+
const result = _.map(lastShifts, (shift, index) => {
36+
return(<StyledTableRow key={index}>
4037
<TableCell align="center">{moment(shift.from).format("YYYY-MM-DD")}</TableCell>
4138
<TableCell align="center">{shift.assignment}</TableCell>
4239
</StyledTableRow>);
@@ -51,7 +48,7 @@ class Volunteer extends Component {
5148
return (
5249
<div>
5350
<Container style={{"marginTop":"1em"}}>
54-
<Typography align='center' gutterBottom='true' variant='h4'>Volunteer Activity</Typography>
51+
<Typography align='center' variant='h4'>Volunteer Activity</Typography>
5552
<TableContainer style={{"marginTop":"1em"}} component={Paper} variant='outlined'>
5653
<Table>
5754
<TableHead>
@@ -75,7 +72,7 @@ class Volunteer extends Component {
7572
</Container>
7673

7774
<Container style={{"marginTop":"1em"}}>
78-
<Typography align='center' gutterBottom='true' variant='h4'>Volunteer History(Top 3)</Typography>
75+
<Typography align='center' variant='h4'>Volunteer History(Top 3)</Typography>
7976
<TableContainer style={{"marginTop":"1em"}} component={Paper} variant='outlined'>
8077
<Table>
8178
<TableHead>

src/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ services:
1919
depends_on:
2020
- db
2121
volumes:
22-
- src_archive:/app/static/uploads
22+
- src_archive:/app/static/raw_data
2323
environment:
2424
FLASK_ENV: development
2525

src/server/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ RUN pip install --no-cache-dir -r /requirements.txt
1515
COPY . .
1616

1717
RUN mkdir /app/static \
18-
/app/static/uploads \
19-
/app/static/uploads/current \
18+
/app/static/raw_data \
19+
/app/static/raw_data/current \
2020
/app/static/output \
2121
/app/static/output/reports \
2222
/app/static/logs \

src/server/api/admin_api.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from sqlalchemy.sql import text
77
from pipeline import flow_script
88
from config import engine
9-
from flask import send_file, request, redirect, jsonify, current_app
9+
from flask import send_file, request, redirect, jsonify, current_app, abort
1010
from api.file_uploader import validate_and_arrange_upload
1111
from config import RAW_DATA_PATH, OUTPUT_PATH, CURRENT_SOURCE_FILES_PATH, ZIPPED_FILES, LOGS_PATH
1212

@@ -102,26 +102,29 @@ def checkStatus():
102102
'''
103103

104104

105-
106105
@admin_api.route('/api/statistics', methods=['GET'])
107106
def listStatistics():
108-
last_execution_file = open(LOGS_PATH + 'last_execution.json', 'r')
109-
last_execution_details = json.loads(last_execution_file.read())
110-
last_execution_file.close()
107+
try:
108+
last_execution_file = open(LOGS_PATH + 'last_execution.json', 'r')
109+
last_execution_details = json.loads(last_execution_file.read())
110+
last_execution_file.close()
111+
112+
except Exception as e:
113+
return abort(404)
111114

112115
return jsonify(last_execution_details)
113116

114117

115118
def getStatistics():
116119
with engine.connect() as connection:
117120
query = text("SELECT \
118-
SUM(CASE WHEN salesforcecontacts_id is not null and volgistics_id is null and petpoint_id is null THEN 1 ELSE 0 END) AS \"Only SalesForce Contacts\", \
119-
SUM(CASE WHEN volgistics_id is not null and petpoint_id is null and salesforcecontacts_id is null THEN 1 ELSE 0 END) AS \"Only Volgistics Contacts\", \
120-
SUM(CASE WHEN petpoint_id is not null and volgistics_id is null and salesforcecontacts_id is null THEN 1 ELSE 0 END) AS \"Only Petpoint Contacts\", \
121-
SUM(CASE WHEN salesforcecontacts_id is not null and petpoint_id is not null and volgistics_id is null THEN 1 ELSE 0 END) AS \"Salesforcec & Petpoint\", \
122-
SUM(CASE WHEN salesforcecontacts_id is not null and volgistics_id is not null and petpoint_id is null THEN 1 ELSE 0 END) AS \"Salesforce & Volgistics\", \
123-
SUM(CASE WHEN volgistics_id is not null and petpoint_id is not null and salesforcecontacts_id is null THEN 1 ELSE 0 END) AS \"Petpoint & Volgistics\", \
124-
SUM(CASE WHEN salesforcecontacts_id is not null and volgistics_id is not null and petpoint_id is not null THEN 1 ELSE 0 END) AS \"Salesforcec & Petpoint & Volgistics\" \
121+
SUM(CASE WHEN salesforcecontacts_id is not null and volgistics_id is null and shelterluvpeople_id is null THEN 1 ELSE 0 END) AS \"Only SalesForce Contacts\", \
122+
SUM(CASE WHEN volgistics_id is not null and shelterluvpeople_id is null and salesforcecontacts_id is null THEN 1 ELSE 0 END) AS \"Only Volgistics Contacts\", \
123+
SUM(CASE WHEN shelterluvpeople_id is not null and volgistics_id is null and salesforcecontacts_id is null THEN 1 ELSE 0 END) AS \"Only Shelterluv Contacts\", \
124+
SUM(CASE WHEN salesforcecontacts_id is not null and shelterluvpeople_id is not null and volgistics_id is null THEN 1 ELSE 0 END) AS \"Only Salesforcec & Shelterluv\", \
125+
SUM(CASE WHEN salesforcecontacts_id is not null and volgistics_id is not null and shelterluvpeople_id is null THEN 1 ELSE 0 END) AS \"Only Salesforce & Volgistics\", \
126+
SUM(CASE WHEN volgistics_id is not null and shelterluvpeople_id is not null and salesforcecontacts_id is null THEN 1 ELSE 0 END) AS \"Only Shelterluv & Volgistics\", \
127+
SUM(CASE WHEN salesforcecontacts_id is not null and volgistics_id is not null and shelterluvpeople_id is not null THEN 1 ELSE 0 END) AS \"Salesforcec & Shelterluv & Volgistics\" \
125128
FROM master")
126129
query_result = connection.execute(query)
127130

0 commit comments

Comments
 (0)