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
40 changes: 37 additions & 3 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 @@ -103,7 +103,8 @@ <h2 class="mdl-card__title-text">Registration form</h2>
</button>
</div>
</form>
{% if guest.id %}

{% 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">
Expand All @@ -118,6 +119,39 @@ <h2 class="mdl-card__title-text">Registration form</h2>
</div>
</form>
{% endif %}
</div>
</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>
</div>
{% endif %}

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