Skip to content

Commit d6d9e64

Browse files
authored
Merge pull request #182 from CodeForPhilly/issue-166-360Page
Adoption and ContactInfo updates
2 parents b73a1c6 + cb6171d commit d6d9e64

File tree

4 files changed

+60
-21
lines changed

4 files changed

+60
-21
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ class DataView360 extends Component {
124124
<TableBody>
125125
{
126126
_.map(participantListGrouped, (row_group, index) => {
127-
return _.map(row_group, row => {
128-
return <TableRow key={row.source_id}
127+
return _.map(row_group, (row, idx) => {
128+
return <TableRow key={`${row.source_id}${idx}`}
129129
className={tableRowColors[index % _.size(tableRowColors)]}
130130
onClick={() => this.handleGetParticipant(row.matching_id)}>
131131
<TableCell align="left">{row.matching_id}</TableCell>
@@ -185,19 +185,19 @@ class DataView360 extends Component {
185185
this.state.showParticipant === true) && (
186186
<Paper className={styles.main} elevation={1} style={{"padding": "1em"}}>
187187
<ContactInfo participant={_.get(this.state, 'participantData.contact_details')}/>
188-
<Container>
189-
<Grid container direction="row" justify="center" alignItems="center" style={{"margin-top": "1em"}}>
190-
<Button variant="contained" color="primary"
191-
onClick={() => {
192-
this.setState({showParticipant: false, showTable: true, showSearchBar: true })
193-
}}>Back to Results
194-
</Button>
188+
<Grid container direction="row" justify="center">
189+
<Grid item style={{"marginTop": "1em", "position": "fixed"}}>
190+
<Button variant="contained" color="primary"
191+
onClick={() => {
192+
this.setState({showParticipant: false, showTable: true, showSearchBar: true })
193+
}}>Back to Results
194+
</Button>
195+
</Grid>
195196
</Grid>
196-
</Container>
197197
<Donations donations={_.get(this.state, 'participantData.donations')}/>
198198
<Adoptions adoptions={_.get(this.state, 'participantData.adoptions')}/>
199199
<Volunteer volunteer={_.get(this.state, 'participantData.shifts')}
200-
volunteerShifts={_.get(this.state, 'participantData.volgistics_shifts_results')}/>
200+
volunteerShifts={_.get(this.state, 'participantData.shifts')}/>
201201

202202
</Paper>)}
203203
{this.state.isDataBusy === true && (

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,36 @@ class Adoptions extends Component {
4141
render() {
4242
// todo: update when we add pet info
4343
// todo: clean array of animal_id
44+
const numAdoptions = _.size(this.props.adoptions);
4445
return (<Container className={styles.adoptions} style={{"marginTop":"1em"}}>
45-
<Typography className={styles.adoptions_title} variant='h4'>Adoption/Foster Records (Top 3)</Typography>
46+
<Typography className={styles.adoptions_title} variant='h4'>Adoption/Foster Records {(numAdoptions > 3) && "(Showing latest 3 out of " + numAdoptions + ")"}</Typography>
4647
<TableContainer className="main_table_container" style={{"marginTop":"1em"}} component={Paper} variant='outlined'>
4748
<Table className="main_table">
4849
<TableHead>
4950
<TableRow>
50-
<StyledTableCell align="center">Number of Adoptions</StyledTableCell>
51+
<StyledTableCell align="center">Name</StyledTableCell>
52+
<StyledTableCell align="center">Adoption Type</StyledTableCell>
53+
<StyledTableCell align="center">Adoption Subtype</StyledTableCell>
54+
<StyledTableCell align="center">Animal Type</StyledTableCell>
55+
<StyledTableCell align="center">Breed</StyledTableCell>
56+
<StyledTableCell align="center">Age</StyledTableCell>
57+
<StyledTableCell align="center">Photo</StyledTableCell>
5158
</TableRow>
5259
</TableHead>
5360
<TableBody>
54-
<StyledTableRow>
55-
<TableCell align="center"> {_.size(this.getAnimalIds())}</TableCell>
61+
{_.map(this.props.adoptions, (adoptionInfo, index) => {
62+
const photoLink = adoptionInfo["animal_details"]["Photos"][0]
63+
const photo = <img src={photoLink} style={{"maxWidth": "100px"}}/>;
64+
return <StyledTableRow key={adoptionInfo["Time"] + index}>
65+
<TableCell align="center">{adoptionInfo["animal_details"]["Name"]}</TableCell>
66+
<TableCell align="center">{adoptionInfo["Type"]}</TableCell>
67+
<TableCell align="center">{adoptionInfo["Subtype"]}</TableCell>
68+
<TableCell align="center">{adoptionInfo["animal_details"]["Type"]}</TableCell>
69+
<TableCell align="center">{adoptionInfo["animal_details"]["Breed"]}</TableCell>
70+
<TableCell align="center">{(parseInt(adoptionInfo["animal_details"]["Age"])/12).toFixed(2)}</TableCell>
71+
<TableCell align="center">{photo}</TableCell>
5672
</StyledTableRow>
73+
})}
5774
</TableBody>
5875
</Table>
5976
</TableContainer>

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,19 @@ const StyledContact = withStyles((theme)=>({
1616

1717
class ContactInfo extends Component {
1818
render() {
19-
const participantArray = _.get(this.props, "participant")
20-
const participant = participantArray[0]
19+
// TODO: move to the backend
20+
let participantArray = _.get(this.props, "participant");
21+
let participant = {};
22+
if (participantArray.length === 1) {
23+
participant = participantArray[0];
24+
} else {
25+
participantArray = _.filter(participantArray, function(p) {
26+
if (p["source_type"] === "salesforcecontacts") {
27+
return p;
28+
}
29+
});
30+
participant = participantArray[0];
31+
}
2132
const phoneStr = participant.mobile;
2233
let phone = _.isEmpty(phoneStr) ? '-' : phoneStr.split(" ").join("");
2334
return (<Container className={styles.contact_info}>

src/server/api/common_api.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from sqlalchemy.sql import text
55
import requests
66
import json
7+
import dateutil.parser
78
from secrets import SHELTERLUV_SECRET_TOKEN
89

910

@@ -14,9 +15,9 @@ def get_contacts(search_text):
1415

1516
names = search_text.split(" ")
1617
if len(names) == 2:
17-
query = text("select * from pdp_contacts where archived_date is null AND\
18-
lower(first_name) like lower(:name1) and lower(last_name) like lower(:name2) \
19-
OR lower(first_name) like lower(:name2) and lower(last_name) like lower(:name1)")
18+
query = text("select * from pdp_contacts where archived_date is null AND ( \
19+
(lower(first_name) like lower(:name1) and lower(last_name) like lower(:name2)) \
20+
OR (lower(first_name) like lower(:name2) and lower(last_name) like lower(:name1)) )")
2021
query_result = connection.execute(query, name1='{}%'.format(names[0]), name2='{}%'.format(names[1]))
2122
elif len(names) == 1:
2223
query = text("select * from pdp_contacts \
@@ -52,7 +53,17 @@ def get_360(matching_id):
5253
if row["source_type"] == "volgistics":
5354
shifts_query = text("select * from volgisticsshifts where number = :volgistics_id")
5455
volgistics_shifts_query_result = connection.execute(shifts_query, volgistics_id=row["source_id"])
55-
volgisticsshifts_results = [dict(row) for row in volgistics_shifts_query_result]
56+
volgisticsshifts_results = []
57+
58+
# todo: temporary fix until formatted in the pipeline
59+
for r in volgistics_shifts_query_result:
60+
shifts = dict(r)
61+
# normalize date string
62+
parsed_date_from = dateutil.parser.parse(shifts["from"], ignoretz=True)
63+
normalized_date_from = parsed_date_from.strftime("%Y-%m-%d")
64+
shifts["from"] = normalized_date_from
65+
volgisticsshifts_results.append(shifts)
66+
5667
result['shifts'] = volgisticsshifts_results
5768

5869
if row["source_type"] == "shelterluvpeople":

0 commit comments

Comments
 (0)