Commit b4e02b97 authored by Mattias J Duffy's avatar Mattias J Duffy
Browse files

sidebar and facility card hours can now handle when there are two schedules for the same day

parent 7a4660d2
Pipeline #1875 passed with stage
in 1 minute and 47 seconds
import React from 'react' import React from 'react'
import Grid from 'material-ui/Grid'; import Grid from 'material-ui/Grid';
import FacilityUtils from '../utils/facilityUtils'; import facilityUtils from '../utils/facilityUtils';
const WeekHours = ({facility}) => { const WeekHours = ({facility}) => {
const weekDays = [ const weekDays = [
...@@ -14,15 +14,19 @@ const WeekHours = ({facility}) => { ...@@ -14,15 +14,19 @@ const WeekHours = ({facility}) => {
]; ];
let output = []; let output = [];
try { try {
let index = 0;
for (let dayOfWeek = 0; dayOfWeek < 7; dayOfWeek++) { for (let dayOfWeek = 0; dayOfWeek < 7; dayOfWeek++) {
output[dayOfWeek] = ( const todaysHours = facilityUtils.getHoursByDay(facility,dayOfWeek)
<Grid container key={facility.slug + dayOfWeek} className='week-hours-row'> for(let i = 0; i < todaysHours.length; i++){
<Grid item xs={2} className='week-hours-day'>{weekDays[dayOfWeek]}</Grid> output[index] = (
<Grid item className='week-hours-times'>{FacilityUtils.getHoursByDay(facility, dayOfWeek)}</Grid> <Grid container spacing={0} key={facility.slug + index} className='week-hours-row'>
</Grid> <Grid item xs={2} className='week-hours-day'>{weekDays[dayOfWeek]}</Grid>
) <Grid item className='week-hours-times'>{todaysHours[i].text}</Grid>
</Grid>
)
index++;
}
} }
} catch (e) { } catch (e) {
} }
......
...@@ -40,6 +40,7 @@ class FacilityCard extends React.Component { ...@@ -40,6 +40,7 @@ class FacilityCard extends React.Component {
isHovered:false isHovered:false
}) })
}; };
render() { render() {
const {facility, facilities, favorites, selectedFacility, addFavoriteFacility, removeFavoriteFacility} = this.props; const {facility, facilities, favorites, selectedFacility, addFavoriteFacility, removeFavoriteFacility} = this.props;
...@@ -47,6 +48,20 @@ class FacilityCard extends React.Component { ...@@ -47,6 +48,20 @@ class FacilityCard extends React.Component {
const isSelected = selectedFacility.slug === facility.slug; const isSelected = selectedFacility.slug === facility.slug;
const dayOfWeek = [6, 0, 1, 2, 3, 4, 5][new Date().getDay()]; const dayOfWeek = [6, 0, 1, 2, 3, 4, 5][new Date().getDay()];
const getDisplayHours = () => {
let currentHour = new Date().getHours();
const todaysHours = FacilityUtils.getHoursByDay(facility, dayOfWeek)
if(todaysHours.length > 1){
for(let i = 0; i < todaysHours.length; i++){
const hour = todaysHours[i]
if(currentHour <= parseInt(hour.end) && currentHour >= parseInt(hour.start)){
return hour.text;
}
}
}
return todaysHours[0].text
}
return ( return (
<Card onClick={this.handleCardClick} className={classnames('fc-root', isSelected && 'fc-selected')} <Card onClick={this.handleCardClick} className={classnames('fc-root', isSelected && 'fc-selected')}
...@@ -75,7 +90,7 @@ class FacilityCard extends React.Component { ...@@ -75,7 +90,7 @@ class FacilityCard extends React.Component {
</Grid> </Grid>
<Grid item className={'fc-small-grid-item-spacing'}> <Grid item className={'fc-small-grid-item-spacing'}>
<Typography type={'body1'}> <Typography type={'body1'}>
{"Today: " + FacilityUtils.getHoursByDay(facility, dayOfWeek)} {"Today: " + getDisplayHours()}
</Typography> </Typography>
</Grid> </Grid>
</Grid> </Grid>
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
} }
.sidebar-open { .sidebar-open {
flex: 1 0 100px; flex: 1 0 400px;
} }
.sidebar-closed { .sidebar-closed {
......
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
} }
.layout-card-container { .layout-card-container {
height: calc(100% - 86px); height: calc(100% - 70px);
overflow-y: auto; overflow-y: auto;
overflow-x: hidden; overflow-x: hidden;
} }
......
...@@ -167,12 +167,12 @@ const getActiveEntry = schedule => { ...@@ -167,12 +167,12 @@ const getActiveEntry = schedule => {
ex. start day is Sunday (6), end day is Monday (0) ex. start day is Sunday (6), end day is Monday (0)
*/ */
if ((scheduleEntry.start_day <= scheduleEntry.end_day && if ((scheduleEntry.start_day <= scheduleEntry.end_day &&
dayOfWeek >= scheduleEntry.start_day && (dayOfWeek >= scheduleEntry.start_day &&
dayOfWeek <= scheduleEntry.end_day) || dayOfWeek <= scheduleEntry.end_day)) ||
(scheduleEntry.start_day > scheduleEntry.end_day && (scheduleEntry.start_day > scheduleEntry.end_day &&
dayOfWeek >= scheduleEntry.start_day || (dayOfWeek >= scheduleEntry.start_day ||
dayOfWeek <= scheduleEntry.end_day) dayOfWeek <= scheduleEntry.end_day))
) { ) {
if (scheduleEntry.start_day === scheduleEntry.end_day) { if (scheduleEntry.start_day === scheduleEntry.end_day) {
...@@ -219,12 +219,12 @@ const getEntryByDay = (schedule, dayOfWeek) => { ...@@ -219,12 +219,12 @@ const getEntryByDay = (schedule, dayOfWeek) => {
const endDay = entry.end_day; const endDay = entry.end_day;
if ((startDay <= endDay && if ((startDay <= endDay &&
dayOfWeek >= startDay && (dayOfWeek >= startDay &&
dayOfWeek <= endDay) || dayOfWeek <= endDay)) ||
(startDay > endDay && (startDay > endDay &&
dayOfWeek >= startDay || (dayOfWeek >= startDay ||
dayOfWeek <= endDay) dayOfWeek <= endDay))
) { ) {
return entry; return entry;
} }
...@@ -233,21 +233,73 @@ const getEntryByDay = (schedule, dayOfWeek) => { ...@@ -233,21 +233,73 @@ const getEntryByDay = (schedule, dayOfWeek) => {
return null; return null;
}; };
/**
* Determines an array of entires based on the day of the week.
*
* @param schedule A schedule.
* @param dayOfWeek The day of the week
* @returns {*} an array of entries that are active on the given day of the week
*/
const getEntriesByDay = (schedule, dayOfWeek) => {
const openTimes = schedule.open_times;
let entries = []
for (let i = 0; i < openTimes.length; i++) {
const entry = openTimes[i];
const startDay = entry.start_day;
const endDay = entry.end_day;
if ((startDay <= endDay &&
(dayOfWeek >= startDay &&
dayOfWeek <= endDay)) ||
(startDay > endDay &&
(dayOfWeek >= startDay ||
dayOfWeek <= endDay))
) {
// console.log(entry)
entries.push(entry)
}
}
// if(entries.length === 0){
// return null;
// }
return entries;
};
const getHoursByDay = (facility, dayOfWeek) => { const getHoursByDay = (facility, dayOfWeek) => {
const schedule = getFacilityActiveSchedule(facility); const schedule = getFacilityActiveSchedule(facility);
if (schedule.twenty_four_hours) { if (schedule.twenty_four_hours) {
return 'All Day'; return [{text:'All Day',
start:0,
end:0,
allDayOrClosed:true}]
} }
const entry = getEntryByDay(schedule, dayOfWeek); const entries = getEntriesByDay(schedule, dayOfWeek);
if (entry === null) { if (entries.length === 0) {
return 'Closed'; return [{text:'Closed',
start:0,
end:0,
allDayOrClosed:true}];
} }
let hours = [];
return convertToMeridiemTime(entry.start_time) + ' - ' + convertToMeridiemTime(entry.end_time);
for(let i = 0; i < entries.length; i++){
hours.push({
text:convertToMeridienTime(entries[i].start_time) + ' - ' + convertToMeridienTime(entries[i].end_time),
start:entries[i].start_time,
end:entries[i].end_time,
allDayOrClosed:false
})
}
return hours.sort((a,b) => {
return parseInt(a.start) - parseInt(b.start)
})
}; };
...@@ -258,7 +310,7 @@ const getHoursByDay = (facility, dayOfWeek) => { ...@@ -258,7 +310,7 @@ const getHoursByDay = (facility, dayOfWeek) => {
* @param time The time as military time * @param time The time as military time
* @returns {string} The time as 12-hour time. * @returns {string} The time as 12-hour time.
*/ */
const convertToMeridiemTime = (time) => { const convertToMeridienTime = (time) => {
const timeArr = time const timeArr = time
.split(":") .split(":")
.map((item) => { .map((item) => {
...@@ -301,6 +353,7 @@ const daysTill = (dayFrom, dayTo) => { ...@@ -301,6 +353,7 @@ const daysTill = (dayFrom, dayTo) => {
export default { export default {
getFacilityActiveSchedule: getFacilityActiveSchedule, getFacilityActiveSchedule: getFacilityActiveSchedule,
isFacilityOpen: isFacilityOpen, isFacilityOpen: isFacilityOpen,
getEntriesByDay:getEntriesByDay,
getHoursByDay: getHoursByDay, getHoursByDay: getHoursByDay,
calcTimeTillOpen: calcTimeTillOpen, calcTimeTillOpen: calcTimeTillOpen,
calcTimeTillClose: calcTimeTillClose calcTimeTillClose: calcTimeTillClose
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment