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

pass error (while fetching appointments), to frontend #12

Merged
merged 1 commit into from
Jul 17, 2018
Merged
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
78 changes: 40 additions & 38 deletions config/ews/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,54 +59,56 @@ module.exports = function (callback) {
return promise;
};

var fillRoomData = function (context, room, appointments = [], option = {}) {
room.Appointments = [];
appointments.forEach(function(appt, index) {
// get start time from appointment
var start = processTime(appt.Start.momentDate),
end = processTime(appt.End.momentDate),
now = Date.now();

room.Busy = index === 0
? start < now && now < end
: room.Busy;

room.Appointments.push({
"Subject" : appt.Subject,
"Organizer" : appt.Organizer.Name,
"Start" : start,
"End" : end
});
});

if (option.errorMessage) {
room.ErrorMessage = option.errorMessage;
}

context.itemsProcessed++;

if (context.itemsProcessed === context.roomAddresses.length) {
context.roomAddresses.sort(sortByRoomName);
context.callback(context.roomAddresses);
}
};

// promise: get current or upcoming appointments for each room
var getAppointmentsForRooms = function (roomAddresses) {
var promise = new Promise(function (resolve, reject) {
var itemsProcessed = 0;
var context = {
callback: resolve,
itemsProcessed: 0,
roomAddresses
};

roomAddresses.forEach(function(room, index, array){
var calendarFolderId = new ews.FolderId(ews.WellKnownFolderName.Calendar, new ews.Mailbox(room.Email));
var view = new ews.CalendarView(ews.DateTime.Now, new ews.DateTime(ews.DateTime.Now.TotalMilliSeconds + ews.TimeSpan.FromHours(240).asMilliseconds()), 6);
exch.FindAppointments(calendarFolderId, view).then((response) => {

var appointments = response.Items;
var appointment = appointments[0];

if (appointments) {
room.Appointments = [];
appointments.forEach(function(appt, index, array) {
// get start time from appointment
var start = processTime(appt.Start.momentDate);
var end = processTime(appt.End.momentDate);
var now = Date.now();

if(index === 0) {
if (start < now && now < end) {
room.Busy = true;
}
else {
room.Busy = false;
}
}

room.Appointments.push({
"Subject" : appt.Subject,
"Organizer" : appt.Organizer.Name,
"Start" : start,
"End" : end
});
});
}

itemsProcessed++;

if (itemsProcessed === array.length) {
roomAddresses.sort(sortByRoomName);
resolve(roomAddresses);
}
fillRoomData(context, room, response.Items);
}, (error) => {
// handle the error here
callback(error, null);
// callback(error, null);
fillRoomData(context, room, undefined, { errorMessage: error.response.errorMessage });
});
});
});
Expand Down
9 changes: 9 additions & 0 deletions scss/_globals.scss
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ body {
color: $yellow;
}

.meeting-error {
font-size: 24px;
color: $orange;
}

.meeting-room__name {
font-size: 30px;
color: $grayLightest;
Expand Down Expand Up @@ -207,6 +212,10 @@ body {
border-left: 8px solid $red !important;
}

.meeting-room-error {
border-left: 8px solid $orange !important;
}

#single-room__wrap {
height: 100vh;
width: 100%;
Expand Down
1 change: 1 addition & 0 deletions scss/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ $grayDark: #333;
$grayLightest: #eceef1;
$grayLight: #d4d6d8;
$red: #f04124;
$orange: #f3840e;

// font colors -----------------------------------------------------------------
$primaryFont: #ffffff;
Expand Down
6 changes: 6 additions & 0 deletions static/css/styles.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion static/css/styles.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 17 additions & 10 deletions ui-react/src/components/flightboard/board/Flightboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,30 @@ class Flightboard extends Component {
}
// if the room needs to be skipped, return null
if (!skippedRoom) {
let meetingRoomClass = `${ room } meeting-room ${ item.Busy ? 'meeting-room-busy' : '' }`;
meetingRoomClass += item.Busy ? ' meeting-room-busy' : '';
meetingRoomClass += item.ErrorMessage ? ' meeting-room-error' : '';
const meetingClass = item.ErrorMessage
? 'meeting-error'
: item.Busy
? 'meeting-busy'
: 'meeting-open';
let statusText = item.ErrorMessage
? fbConfig.board.text.statusError
: item.Busy
? fbConfig.board.text.statusBusy
: fbConfig.board.text.statusAvailable;
return (

<div className={'row-padder ' + roomlist} style={this.props.filter === roomlist || this.props.filter === 'roomlist-all' || this.props.filter === '' ? styles.show : styles.hide}>
<div className="row">
<div className="medium-12 columns">
<div className={item.Busy ? room + ' meeting-room meeting-room-busy' : room + ' meeting-room'}>
<div className={meetingRoomClass}>
<div className="row valign-middle">
<div className={room + '-status meeting-room__status medium-2 columns'}>
{item.Busy ?
<div className="meeting-busy">
{fbConfig.board.text.statusBusy}
</div>
:
<div className="meeting-open">
{fbConfig.board.text.statusAvailable}
</div>
}
<div className={meetingClass} title={item.ErrorMessage || ''}>
{statusText}
</div>
</div>
<div className="medium-3 columns">
<div className={room + '-name meeting-room__name'}>
Expand Down
1 change: 1 addition & 0 deletions ui-react/src/config/flightboard.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {
'nextUp' : 'Next Up',
'statusAvailable' : 'Open',
'statusBusy' : 'Busy',
'statusError' : 'Error'
}
},

Expand Down