Permalink
Browse files

Implement SignUp/Cancel buttons on shuttlecards

  • Loading branch information...
dawneraq committed Apr 28, 2017
1 parent 6ccad1e commit 38231bc05ce8ad4a36bdb27dbeafb35fcf5343bc
@@ -30,6 +30,7 @@ export class DashboardComponent implements OnInit {
this.user = new User();
this.shuttles = [];
this.shuttleGroups = [];
+ this.usershuttles = [];
//async load current user from /current-user
this.getuser();
@@ -97,6 +98,7 @@ export class DashboardComponent implements OnInit {
});
}
signup(shuttle: Shuttle) {
+ console.log('TODO signup shuttle:', shuttle);
this.dashboardService.signup(this.user, shuttle).then(data => {
this.usershuttles.push(shuttle);
var index: number = this.shuttles.indexOf(shuttle, 0);
@@ -105,6 +107,7 @@ export class DashboardComponent implements OnInit {
}
this.getShuttles();
// TODO show a candybar or something
+ console.log('successfully signed up for shuttle:', shuttle);
}
)
}
@@ -160,4 +163,9 @@ export class DashboardComponent implements OnInit {
getShuttleById(shuttleId: string) {
return this.shuttles.find(shuttle => shuttle._id == shuttleId);
}
+ isSignedUp(shuttleId: string) {
+ // TypeScript doesn't support Array.includes()
+ return this.usershuttles.map(userShuttle => { return userShuttle._id }).indexOf(shuttleId) != -1;
+ // return this.getShuttleById(shuttleId).riders.map(rider => { return rider.username }).indexOf(this.user.username) != -1;
+ }
}
@@ -48,8 +48,8 @@ export class DashboardService {
console.log(user);
var data = {
"id":shuttle._id,
- "numGuests":user.numGuests,
- "guestsOnly":user.guestsOnly
+ "numGuests":user.numGuests || 0,
+ "guestsOnly":user.guestsOnly || false
}
console.log(data);
let headers = new Headers({ 'Content-Type': 'application/json' });
@@ -63,8 +63,8 @@ export class DashboardService {
console.log(user);
var data = {
"id":shuttle._id,
- "numGuests":user.numGuests,
- "guestsOnly":user.guestsOnly
+ "numGuests":user.numGuests || 0,
+ "guestsOnly":user.guestsOnly || false
}
console.log(data);
let headers = new Headers({ 'Content-Type': 'application/json' });
@@ -30,7 +30,6 @@
}
.demo-card-event.mdl-card {
- width: 256px;
height: 256px;
background: #3E4EB8;
}
@@ -97,12 +96,21 @@ <h2 class="mdl-card__title-text">{{shuttleGroup.origin[0].name}}
Departs {{ getShuttleById(shuttleId)?.departureDateTime | date: 'h:mm a' }}<br/>
{{ getShuttleById(shuttleId)?.departureDateTime | date: 'MMMM d, y' }}
</p>
+ <!-- <div class="mdl-textfield mdl-js-textfield">
+ <label for="num-guests-{{ shuttleId }}" class="mdl-textfield__label">Number of guests</label>
+ <input type="number" id="num-guests-{{ shuttleId }}" class="mdl-textfield__input">
+ </div> -->
</div>
<div class="mdl-card__actions mdl-card--border">
<!-- TODO disable if user is already signed up -->
- <a class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect">
+ <!-- <a (click)="signup(getShuttleById(shuttleId))" class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect"> -->
+ <a (click)="signup(getShuttleById(shuttleId))" [hidden]="isSignedUp(shuttleId)" class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect">
Sign Up
</a>
+ <!-- <a (click)="unsignup(getShuttleById(shuttleId))" class="mdl-button mdl-button--accent mdl-js-button mdl-js-ripple-effect"> -->
+ <a (click)="unsignup(getShuttleById(shuttleId))" [hidden]="!isSignedUp(shuttleId)" class="mdl-button mdl-button--accent mdl-js-button mdl-js-ripple-effect">
+ Cancel Signup
+ </a>
<a class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect" *ngIf="godmode" (click)="cancelShuttle(shuttleId)">
<i class="material-icons">clear</i>
Cancel

0 comments on commit 38231bc

Please sign in to comment.