Skip to content

Commit

Permalink
Merge pull request #26 from danxfisher/room-blacklist
Browse files Browse the repository at this point in the history
Room blacklist
  • Loading branch information
danxfisher authored Jul 19, 2018
2 parents 94fc6d0 + 373e106 commit 26f7d12
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 111 deletions.
26 changes: 21 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ In the event of wanting to commercially distribute a closed source modification

## Updates

* v0.3.1
* Removed skipped rooms/room blacklist filtering from front end to back end.
* v0.3
* Cleaned up unnecessarily nested component folder structure
* [#8](https://github.com/danxfisher/MeetEasier/pull/8) - add script-shortcuts to `package.json` in root
Expand Down Expand Up @@ -163,13 +165,27 @@ There are three main directories in the `ui-react/src/` folder:
```javascript
module.exports = {
'board' : {
'text' : {
'nextUp' : 'Next Up',
'statusAvailable' : 'Open',
'statusBusy' : 'Busy',
'statusError' : 'Error'
}
},
'navbar' : {
'title' : 'Conference Room Availability',
},
'roomFilter' : {
'filterTitle' : 'Locations',
'filterAllTitle' : 'All Conference Rooms',
'roomsToSkip' : [
'[email protected]'
],
'socketEndpoint' : 'http://localhost:8080'
},
'socket' : {
'endpoint' : 'http://localhost:8080',
}
};
```
Expand All @@ -181,7 +197,7 @@ There are three main directories in the `ui-react/src/` folder:
* To change the interval in which the web socket emits, edit the interval time in `config/controller.js`. By default, it is set to 1 minute.
* To update styles, make sure you install grunt first with `npm install -g grunt-cli`. Then run `grunt` in the root directory to watch for SCSS changes. Use the `.scss` files located in the `/scss` folder.
* All React components can be locally styled by adding a new `.css` file and importing it into the component itself if you'd prefer to do it that way.
* In `config/ews/rooms.js`, there is a block of code on lines 37-39 that may not be necessary but were added as a convenience. Feel free to use it, comment it out, or remove it completely. It was designed for a use case where the email addresses (ex: [email protected]) do not match the corporate domain (ex: jsmith-enterprise).
* In `config/ews/rooms.js`, there is a block of code that may not be necessary but were added as a convenience. Feel free to use it, comment it out, or remove it completely. It was designed for a use case where the email addresses (ex: [email protected]) do not match the corporate domain (ex: jsmith-enterprise).
```javascript
// if the email domain != your corporate domain,
// replace email domain with domain from auth config
Expand Down
2 changes: 1 addition & 1 deletion config/ews/roomlists.js → app/ews/roomlists.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = function (callback) {

// modules -------------------------------------------------------------------
var ews = require("ews-javascript-api");
var auth = require("../auth.js");
var auth = require("../../config/auth.js");

// ews -----------------------------------------------------------------------
var exch = new ews.ExchangeService(ews.ExchangeVersion.Exchange2016);
Expand Down
52 changes: 31 additions & 21 deletions config/ews/rooms.js → app/ews/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ module.exports = function (callback) {

// modules -------------------------------------------------------------------
var ews = require("ews-javascript-api");
var auth = require("../auth.js");
var auth = require("../../config/auth.js");
var blacklist = require("../../config/room-blacklist.js");

// ews -----------------------------------------------------------------------
var exch = new ews.ExchangeService(ews.ExchangeVersion.Exchange2016);
Expand Down Expand Up @@ -30,22 +31,27 @@ module.exports = function (callback) {
roomLists.forEach(function (item, i, array) {
exch.GetRooms(new ews.Mailbox(item.Address)).then((rooms) => {
rooms.forEach(function (roomItem, roomIndex, roomsArray) {
var room = {};

// if the email addresses != your corporate domain,
// replace email domain with domain
var email = roomItem.Address;
email = email.substring(0, email.indexOf('@'));
email = email + '@' + auth.domain;

var roomAlias = roomItem.Name.toLowerCase().replace(/\s+/g, "-");

room.Roomlist = item.Name;
room.Name = roomItem.Name;
room.RoomAlias = roomAlias;
room.Email = email;
roomAddresses.push(room);

// use either email var or roomItem.Address - depending on your use case
let inBlacklist = isRoomInBlacklist(roomItem.Address);

// if not in blacklist, proceed as normal; otherwise, skip
if (!inBlacklist) {
let room = {};

// if the email addresses != your corporate domain,
// replace email domain with domain
let email = roomItem.Address;
email = email.substring(0, email.indexOf('@'));
email = email + '@' + auth.domain;

let roomAlias = roomItem.Name.toLowerCase().replace(/\s+/g, "-");

room.Roomlist = item.Name;
room.Name = roomItem.Name;
room.RoomAlias = roomAlias;
room.Email = email;
roomAddresses.push(room);
}
});
counter++;

Expand Down Expand Up @@ -107,14 +113,19 @@ module.exports = function (callback) {
fillRoomData(context, room, response.Items);
}, (error) => {
// handle the error here
// callback(error, null);
// callback(error, null);
fillRoomData(context, room, undefined, { errorMessage: error.response.errorMessage });
});
});
});
return promise;
};

// check if room is in blacklist
function isRoomInBlacklist(email) {
return blacklist.roomEmails.includes(email);
}

// do all of the process for the appointment times
function processTime(appointmentTime) {
var time = JSON.stringify(appointmentTime);
Expand All @@ -136,13 +147,12 @@ module.exports = function (callback) {
return 0; //default return value (no sorting)
}


// perform promise chain to get rooms
getListOfRooms()
.then(getRoomsInLists)
.then(getAppointmentsForRooms)
.then(function(rooms){
callback(null, rooms);
});



};
4 changes: 2 additions & 2 deletions app/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = function(app) {
// returns an array of room objects
app.get('/api/rooms', function(req, res) {

var ews = require('../config/ews/rooms.js');
var ews = require('./ews/rooms.js');

ews(function(err, rooms) {
res.json(rooms);
Expand All @@ -15,7 +15,7 @@ module.exports = function(app) {
// returns an array of roomlist objects
app.get('/api/roomlists', function(req, res) {

var ews = require('../config/ews/roomlists.js');
var ews = require('./ews/roomlists.js');

ews(function(err, roomlists) {
res.json(roomlists);
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions config/room-blacklist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
'roomEmails' : [
'[email protected]'
]
};
4 changes: 2 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ var theserver = app.listen(port, function(){
var io = require('socket.io').listen(theserver);

// controller if using room lists
var controller = require('./config/controller.js')(io);
var controller = require('./app/socket-controller.js')(io);

// log something so we know the server is working correctly
console.log('now we are cooking.');
console.log(`now we're cooking.`);
});
138 changes: 61 additions & 77 deletions ui-react/src/components/flightboard/FlightboardRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ class FlightboardRow extends Component {
super(props);
this.state = {
nextUp: '',
timesPresent: false,
skippedRoom: false
timesPresent: false
}
}

Expand All @@ -32,25 +31,12 @@ class FlightboardRow extends Component {
}
}

isRoomSkipped = () => {
const { item } = this.props;

fbConfig.board.roomsToSkip.forEach(function(configItem, configKey) {
if(configItem === item.Email) {
this.setState({
skippedRoom: true
});
}
});
}

componentDidMount = () => {
this.isRoomSkipped();
this.getAppointmentTime();
}

render() {
const { nextUp, skippedRoom, timesPresent } = this.state;
const { nextUp, timesPresent } = this.state;
const { item, now } = this.props;

const styles = {
Expand All @@ -62,79 +48,77 @@ class FlightboardRow extends Component {
const room = item.Name.toLowerCase().replace(/\s+/g, "-");
const roomlist = 'roomlist-' + item.Roomlist.toLowerCase().replace(/\s+/g, "-");

// 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;
// set row class based on meet room status
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={meetingRoomClass}>
<div className="row valign-middle">
<div className={room + '-status meeting-room__status medium-2 columns'}>
<div className={meetingClass} title={item.ErrorMessage || ''}>
{statusText}
</div>
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={meetingRoomClass}>
<div className="row valign-middle">
<div className={room + '-status meeting-room__status medium-2 columns'}>
<div className={meetingClass} title={item.ErrorMessage || ''}>
{statusText}
</div>
<div className="medium-3 columns">
<div className={room + '-name meeting-room__name'}>
{item.Name}
</div>
</div>
<div className="medium-3 columns">
<div className={room + '-name meeting-room__name'}>
{item.Name}
</div>
</div>
<div className="medium-6 columns">
<div className={room + '-meeting-information'}>
{timesPresent && item.Appointments[0].End >= now &&
<div>
<span className={room + '-meeting-upcoming meeting-upcoming'}>
{nextUp}
</span>
<span className={room + '-subject meeting-subject'}>
{item.Appointments[0].Subject}
</span>
</div>
}
</div>
<div className="medium-6 columns">
<div className={room + '-meeting-information'}>
{timesPresent && item.Appointments[0].End >= now &&
<div>
<span className={room + '-meeting-upcoming meeting-upcoming'}>
{nextUp}
</span>
<span className={room + '-subject meeting-subject'}>
{item.Appointments[0].Subject}
</span>
</div>
}
</div>
<div className={room + '-time meeting-time'}>
{timesPresent ?
new Date(parseInt(item.Appointments[0].Start, 10)).toLocaleTimeString([], {hour: '2-digit', minute: '2-digit'}) + ' - ' + new Date(parseInt(item.Appointments[0].End, 10)).toLocaleTimeString([], {hour: '2-digit', minute: '2-digit'})
: ''
}
</div>
<div className={room + '-organizer meeting-organizer'}>
{timesPresent && item.Appointments[0].End >= now &&
item.Appointments[0].Organizer
}
</div>
<div className={room + '-time meeting-time'}>
{timesPresent ?
new Date(parseInt(item.Appointments[0].Start, 10)).toLocaleTimeString([], {hour: '2-digit', minute: '2-digit'}) + ' - ' + new Date(parseInt(item.Appointments[0].End, 10)).toLocaleTimeString([], {hour: '2-digit', minute: '2-digit'})
: ''
}
</div>
<div className="medium-1 columns">
<div className="meeting-fullscreen">
<div className={room + '-organizer meeting-organizer'}>
{timesPresent && item.Appointments[0].End >= now &&
item.Appointments[0].Organizer
}
</div>
</div>
<div className="medium-1 columns">
<div className="meeting-fullscreen">

<Link to={'/single-room/' + room} target="_blank">
<i className="fi-monitor"></i>
</Link>
<Link to={'/single-room/' + room} target="_blank">
<i className="fi-monitor"></i>
</Link>

</div>
</div>
</div>
</div>
</div>
</div>
</div>
)
}
</div>
)
}
}

Expand Down
3 changes: 0 additions & 3 deletions ui-react/src/config/flightboard.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
module.exports = {
'board' : {
'roomsToSkip' : [
'[email protected]'
],
'text' : {
'nextUp' : 'Next Up',
'statusAvailable' : 'Open',
Expand Down

0 comments on commit 26f7d12

Please sign in to comment.