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

Add 'Past visit' table #12

Merged
merged 4 commits into from
Mar 27, 2017
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
12 changes: 10 additions & 2 deletions server/controllers/guests-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,18 @@ exports.get = function(req, res, next) {
'?scope=' + encodeURIComponent(sessions.CAL_SCOPE));
}
getAsanaProjects().then(function(projects) {
const now = new Date().getTime();
const upcomingGuests = req.user.guests.filter(g => g.dateStart.getTime() > now);
const pastGuests = req.user.guests.filter(g => g.dateStart.getTime() <= now);
const guestById = req.params.guest_id && req.user.guests.id(req.params.guest_id);
if (guestById) {
guestById.upcoming = guestById.dateStart.getTime() > now;
}
res.render(req.render, {
user: req.user,
guests: req.user.guests,
guest: req.params.guest_id && req.user.guests.id(req.params.guest_id),
upcomingGuests: upcomingGuests,
pastGuests: pastGuests,
guest: guestById,
projects: projects,
exampleDate: new Date('2017-12-09T15:00:00+0900')
});
Expand Down
2 changes: 2 additions & 0 deletions server/middleware/google-passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ module.exports = function(passport) {
}
const oauth2Info = {
accessToken: accessToken,
// TODO(ryok): Currently refreshToken is undefined. We need to set
// Offline mode to retrieve refreshToken.
refreshToken: refreshToken,
scopes: req.session.scopes
};
Expand Down
164 changes: 99 additions & 65 deletions server/views/guests.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% block title %}Guests{% endblock %}

{% block content %}
{% if guests.length %}
{% if upcomingGuests.length %}
<div class="wide-card no-padding mdl-card mdl-shadow--2dp">
<div class="mdl-card__title">
<h2 class="mdl-card__title-text">Upcoming visits</h2>
Expand All @@ -18,7 +18,7 @@ <h2 class="mdl-card__title-text">Upcoming visits</h2>
</tr>
</thead>
<tbody>
{% for guest in guests %}
{% for guest in upcomingGuests %}
<tr>
<td class="mdl-data-table__cell--non-numeric">{{guest.name}}</td>
<td class="mdl-data-table__cell--non-numeric">{{moment(guest.dateStart).format('YYYY/MM/DD HH:mm')}}</td>
Expand Down Expand Up @@ -50,74 +50,108 @@ <h2 class="mdl-card__title-text">Guest policy</h2>
<h2 class="mdl-card__title-text">Registration form</h2>
</div>
<div class="mdl-card__supporting-text">
{% if guest.id %}
<form action="{{base_url}}/guests/edit/{{guest.id}}" method="post">
{% else %}
<form action="{{base_url}}/guests/create" method="post">
{% endif %}
<div class="mdl-grid">
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label mdl-cell mdl-cell--12-col">
<input class="mdl-textfield__input" type="text" value="{{guest.name}}" id="name" name="name" data-required>
<label class="mdl-textfield__label" for="name">Guest name</label>
</div>
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label mdl-cell mdl-cell--12-col">
<input class="mdl-textfield__input" type="text" value="{{guest.email}}" id="email" name="email" data-required>
<label class="mdl-textfield__label" for="email">Guest email</label>
</div>
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label mdl-cell mdl-cell--4-col">
<input class="mdl-textfield__input" type="text" {% if guest.dateStart %}value="{{moment(guest.dateStart).format('YYYY/MM/DD')}}"{% endif %} id="date" name="date" pattern="20[0-9]{2}/[0-1]?[0-9]/[0-3]?[0-9]" data-required>
<label class="mdl-textfield__label" for="date">Date</label>
<span class="mdl-textfield__error">Example: {{moment(exampleDate).format('YYYY/MM/DD')}}</span>
</div>
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label mdl-cell mdl-cell--4-col">
<input class="mdl-textfield__input" type="text" {% if guest.dateStart %}value="{{moment(guest.dateStart).format('HH:mm')}}"{% endif %} id="timeStart" name="timeStart" pattern="[0-2]?[0-9]:[0-5]?[0-9]" data-required>
<label class="mdl-textfield__label" for="timeStart">Start time</label>
<span class="mdl-textfield__error">Example: {{moment(exampleDate).format('HH:mm')}}</span>
</div>
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label mdl-cell mdl-cell--4-col">
<input class="mdl-textfield__input" type="text" {% if guest.dateEnd %}value="{{moment(guest.dateEnd).format('HH:mm')}}"{% endif %} id="timeEnd" name="timeEnd" pattern="[0-2]?[0-9]:[0-5]?[0-9]" data-required>
<label class="mdl-textfield__label" for="timeEnd">End time</label>
<span class="mdl-textfield__error">Example: {{moment(exampleDate).format('HH:mm')}}</span>
</div>
<div class="mdl-cell mdl-cell--12-col">
<div class="mdl-selectfield mdl-js-selectfield full-width">
<select class="mdl-selectfield__select" id="project" name="project">
{% for project in projects %}
<option value="{{project}}">{{project}}</option>
{% endfor %}
<option value="Not Listed">Not Listed</option>
</select>
<label class="mdl-selectfield__label" for="project">Project</label>
{% if guest.id %}
<form action="{{base_url}}/guests/edit/{{guest.id}}" method="post">
{% else %}
<form action="{{base_url}}/guests/create" method="post">
{% endif %}
<div class="mdl-grid">
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label mdl-cell mdl-cell--12-col">
<input class="mdl-textfield__input" type="text" value="{{guest.name}}" id="name" name="name" data-required>
<label class="mdl-textfield__label" for="name">Guest name</label>
</div>
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label mdl-cell mdl-cell--12-col">
<input class="mdl-textfield__input" type="text" value="{{guest.email}}" id="email" name="email" data-required>
<label class="mdl-textfield__label" for="email">Guest email</label>
</div>
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label mdl-cell mdl-cell--4-col">
<input class="mdl-textfield__input" type="text" {% if guest.dateStart %}value="{{moment(guest.dateStart).format('YYYY/MM/DD')}}"{% endif %} id="date" name="date" pattern="20[0-9]{2}/[0-1]?[0-9]/[0-3]?[0-9]" data-required>
<label class="mdl-textfield__label" for="date">Date</label>
<span class="mdl-textfield__error">Example: {{moment(exampleDate).format('YYYY/MM/DD')}}</span>
</div>
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label mdl-cell mdl-cell--4-col">
<input class="mdl-textfield__input" type="text" {% if guest.dateStart %}value="{{moment(guest.dateStart).format('HH:mm')}}"{% endif %} id="timeStart" name="timeStart" pattern="[0-2]?[0-9]:[0-5]?[0-9]" data-required>
<label class="mdl-textfield__label" for="timeStart">Start time</label>
<span class="mdl-textfield__error">Example: {{moment(exampleDate).format('HH:mm')}}</span>
</div>
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label mdl-cell mdl-cell--4-col">
<input class="mdl-textfield__input" type="text" {% if guest.dateEnd %}value="{{moment(guest.dateEnd).format('HH:mm')}}"{% endif %} id="timeEnd" name="timeEnd" pattern="[0-2]?[0-9]:[0-5]?[0-9]" data-required>
<label class="mdl-textfield__label" for="timeEnd">End time</label>
<span class="mdl-textfield__error">Example: {{moment(exampleDate).format('HH:mm')}}</span>
</div>
<div class="mdl-cell mdl-cell--12-col">
<div class="mdl-selectfield mdl-js-selectfield full-width">
<select class="mdl-selectfield__select" id="project" name="project">
{% for project in projects %}
<option value="{{project}}">{{project}}</option>
{% endfor %}
<option value="Not Listed">Not Listed</option>
</select>
<label class="mdl-selectfield__label" for="project">Project</label>
</div>
<div class="caption">Select the project you plan to work on with your guest. New projects can be added via Asana in the 'Projects / Incubation' team. If selecting 'Not Listed', please add additional commentary in the Notes.</div>
</div>
<div class="mdl-cell mdl-cell--12-col">
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label full-width">
<textarea class="mdl-textfield__input" type="text" id="notes" name="notes" rows="5">{{guest.notes}}</textarea>
<label class="mdl-textfield__label" for="notes">Notes</label>
</div>
<div class="caption">Please describe a few details about your guest and the purpose/context of the visit. Bonus points for linking to a personal or company website.</div>
</div>
<button type="submit" class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--colored mdl-cell mdl-cell--12-col">
{% if guest.id %}Update{% else %}Register{% endif %}
</button>
</div>
<div class="caption">Select the project you plan to work on with your guest. New projects can be added via Asana in the 'Projects / Incubation' team. If selecting 'Not Listed', please add additional commentary in the Notes.</div>
</div>
<div class="mdl-cell mdl-cell--12-col">
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label full-width">
<textarea class="mdl-textfield__input" type="text" id="notes" name="notes" rows="5">{{guest.notes}}</textarea>
<label class="mdl-textfield__label" for="notes">Notes</label>
</form>

{% if guest.id && guest.upcoming %}
<form role="form" action="{{base_url}}/guests/delete/{{guest.id}}" method="post" class="confirmation">
<div class="mdl-grid">
<div class="short-card mdl-card mdl-shadow--2dp hidden mdl-cell mdl-cell--12-col">
<div class="mdl-card__supporting-text" style="color: red">
Please confirm that you are canceling this visit. This will
remove corresponding calender entries and send notifications to the guest and other attendees.
</div>
</div>
<button type="submit" class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--colored mdl-cell mdl-cell--12-col">
Cancel visit
</button>
</div>
<div class="caption">Please describe a few details about your guest and the purpose/context of the visit. Bonus points for linking to a personal or company website.</div>
</div>
<button type="submit" class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--colored mdl-cell mdl-cell--12-col">
{% if guest.id %}Update{% else %}Register{% endif %}
</button>
</form>
{% endif %}
</div>
</form>
{% if guest.id %}
<form role="form" action="{{base_url}}/guests/delete/{{guest.id}}" method="post" class="confirmation">
<div class="mdl-grid">
<div class="short-card mdl-card mdl-shadow--2dp hidden mdl-cell mdl-cell--12-col">
<div class="mdl-card__supporting-text" style="color: red">
Please confirm that you are canceling this visit. This will
remove corresponding calender entries and send notifications to the guest and other attendees.
</div>
</div>
<button type="submit" class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--colored mdl-cell mdl-cell--12-col">
Cancel visit
</button>
</div>

{% if pastGuests.length %}
<div class="wide-card no-padding mdl-card mdl-shadow--2dp">
<div class="mdl-card__title">
<h2 class="mdl-card__title-text">Past visits</h2>
</div>
<div class="mdl-card__supporting-text">
<table class="mdl-data-table mdl-js-data-table mdl-shadow--2dp">
<thead>
<tr>
<th class="mdl-data-table__cell--non-numeric">Guest name</th>
<th class="mdl-data-table__cell--non-numeric">Date</th>
<th class="mdl-data-table__cell--non-numeric">Actions</th>
</tr>
</thead>
<tbody>
{% for guest in pastGuests %}
<tr>
<td class="mdl-data-table__cell--non-numeric">{{guest.name}}</td>
<td class="mdl-data-table__cell--non-numeric">{{moment(guest.dateStart).format('YYYY/MM/DD HH:mm')}}</td>
<td class="mdl-data-table__cell--non-numeric">
<a href="{{base_url}}/guests/{{guest.id}}#form">Edit</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</form>
</div>
{% endif %}

<script>
// TODO(ryok): Reuse code from subscription.html
jQuery(function($) {
Expand Down