class Timetable extends React.Component { constructor(props) { super(props); this.state = {}; } selectTime(sessionInfo) { this.props.selectTime(sessionInfo); } selectExistingBooking(transferData){ this.props.selectExistingBooking(transferData); } cellMouseOver(e){ } cellMouseOut(e){ } resizeTable() { var container = $("#bookingTimetable"); var widthChangeObjects = container.find(".timetable .col-header-container, .timetable .table-data-container"); var heightChangeObjects = container.find(".timetable .row-header-container, .timetable .table-data-container"); var colHeaderSpans = container.find(".timetable .col-header span"); var colHeaderChangeObjects = container.find(".timetable .col-header, .timetable .table-data"); var allSpans = container.find(".row-data-cell, .col-header span"); var tableDataContainer = container.find(".table-data-container"); widthChangeObjects.width($(window).width() - 60); heightChangeObjects.height($(window).height() - 150); var spanWidth = (tableDataContainer.width() / colHeaderSpans.length) - 16; if(spanWidth < 120){ spanWidth = 120; } allSpans.width(spanWidth); colHeaderChangeObjects.width((spanWidth +16) * colHeaderSpans.length); container.find(".group-info").each(function(){ $(this).css({left: ($(this).attr("dataspaceindex") * (spanWidth + 12)) + 3, top: ($(this).attr("datagroupstartindex") * 25) + 3, width: spanWidth + 2, height: (25 * $(this).attr("datagroupsessioncount")) - 8}); }) } componentDidUpdate(){ var _this = this; this.resizeTable(); $(window).resize(function(){ _this.resizeTable(); }); } componentDidMount() { var container = $("#bookingTimetable"); container.find(".timetable .table-data-container").scroll(function(){ container.find(".timetable .col-header").css({ 'marginLeft' : ( - $(this).scrollLeft())}); container.find(".timetable .row-header").css({ 'marginTop' : ( - $(this).scrollTop())}); }) } render() { var groupSessions = []; var spaceSessions = []; var _this = this; $.each(this.props.spaces,function(spaceIndex, space){ var singleSpaceSessions = []; var group = ''; var groupStartIndex; var groupSessionCount = 0; $.each(_this.props.timespans, function(timespanIndex, timespan){ $.each(_this.props.minutesPerSession, function(sessionIndex, minutes){ var bookingSessionData = _this.props.bookingData[space]; var time = timespan.split(':')[0] + ':' + minutes; var untilTime = ''; if(sessionIndex + 1 < _this.props.minutesPerSession.length){ untilTime = timespan.split(':')[0] + ':' + _this.props.minutesPerSession[sessionIndex + 1]; }else{ if(timespanIndex + 1 < _this.props.timespans.length){ untilTime = _this.props.timespans[timespanIndex + 1]; }else{ untilTime = _this.props.timespans[0]; } } $.each(bookingSessionData, function(i, d){ if(d.time == time){ if(_this.props.forbidSessions != null) { for(var j = 0; j < _this.props.forbidSessions[space].length; j++) { if(timespanIndex * _this.props.minutesPerSession.length + sessionIndex >= _this.props.forbidSessions[space][j].session_from && timespanIndex * _this.props.minutesPerSession.length + sessionIndex <= _this.props.forbidSessions[space][j].session_to){ d.available = false; break; } } } if(d.available){ if(_this.props.selectedSpace == space && _this.props.selectedFromTime != ''){ if(_this.props.selectedToTime != ''){ if(time >= _this.props.selectedFromTime && time <= _this.props.selectedToTime){ singleSpaceSessions.push(
_this.selectTime(time + ',' + untilTime + ',' +space)}>
); }else{ singleSpaceSessions.push(
_this.cellMouseOver(e)} onMouseOut={(e) => _this.cellMouseOut(e)} onClick={(e1, e2) => _this.selectTime(time + ',' + untilTime + ',' +space)}>
); } }else{ if(time == _this.props.selectedFromTime){ singleSpaceSessions.push(
_this.selectTime(time + ',' + untilTime + ',' +space)}>
); }else{ singleSpaceSessions.push(
_this.cellMouseOver(e)} onMouseOut={(e) => _this.cellMouseOut(e)} onClick={(e1, e2) => _this.selectTime(time + ',' + untilTime + ',' +space)}>
); } } }else{ singleSpaceSessions.push(
_this.cellMouseOver(e)} onMouseOut={(e) => _this.cellMouseOut(e)} onClick={(e1, e2) => _this.selectTime(time + ',' + untilTime + ',' +space)}>
); } }else{ var transferData = { 'time': group, 'space': space, 'toTime': time, 'toTimeDisplay': untilTime, 'notes': d.notes, 'booking_id': d.booking_id}; singleSpaceSessions.push(
); if(group==''){ //start group session groupSessionCount = 1; group = d.groupByTime; groupStartIndex = i; }else{ var notes = d.notes.split('\n').map((n) => (
{n}
)); if(i + 1 < bookingSessionData.length){ if(bookingSessionData[i + 1].groupByTime==group){ groupSessionCount++; }else{ //end group session groupSessionCount++; if(d.owned){ groupSessions.push(
_this.selectExistingBooking(transferData)} style={{left: (spaceIndex * 120) + 3, top: (groupStartIndex * 25) + 3, width: 114, height: (25 * groupSessionCount) - 6}}>
{d.user}
{notes}
); }else{ groupSessions.push(
{d.user}
{notes}
); } group = ''; groupSessionCount = 0; } }else{ //end group session groupSessionCount++; if(d.owned){ groupSessions.push(
_this.selectExistingBooking(transferData)} style={{left: (spaceIndex * 120) + 3, top: (groupStartIndex * 25) + 3, width: 114, height: (25 * groupSessionCount) - 6}}>
{d.user}
{notes}
); }else{ groupSessions.push(
{d.user}
{notes}
); } group = ''; groupSessionCount = 0; } } } } }) }) }) spaceSessions.push(
{singleSpaceSessions}
); }) const colHeaders = this.props.spaces.map((space) => ( {space} )); const rowHeaders = this.props.timespans.map((timespan) => (
{timespan}
)); return (
{colHeaders}
{rowHeaders}
{groupSessions} {spaceSessions}
); } }