Skip to content

Commit

Permalink
Get schedule working.
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyGee committed Nov 8, 2016
1 parent bcf13e8 commit a7b7e4d
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 75 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ git.update.fork.bat
nb-configuration.xml
ui.bat
.distribution
.microprofile
7 changes: 6 additions & 1 deletion microservice-vote/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@
<version>1.0.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.microprofile.showcase</groupId>
<artifactId>demo-bootstrap</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -226,7 +231,7 @@
</plugin>
</plugins>
</pluginManagement>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,22 @@
*/
package io.microprofile.showcase.vote.persistence;

import io.microprofile.showcase.bootstrap.BootstrapData;
import io.microprofile.showcase.vote.model.SessionRating;

import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;

import javax.enterprise.context.ApplicationScoped;

import io.microprofile.showcase.vote.model.SessionRating;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;

@ApplicationScoped
@NonPersistent
Expand All @@ -36,6 +42,23 @@ public class HashMapSessionRatingDAO implements SessionRatingDAO {

private Map<String, Collection<String>> ratingIdsByAttendee = new HashMap<String, Collection<String>>();

@Inject
BootstrapData bootstrapData;

private List<SessionRating> fakeData;

@PostConstruct
public void init() {
System.out.println("Loaded "+bootstrapData.getSessions().size()+ " sessions");

fakeData = bootstrapData.getSessions().stream()
.map(bootstrap -> {
int rating = ThreadLocalRandom.current().nextInt(1, 10);
return new SessionRating(bootstrap.getId(), "12345", rating);
})
.collect(Collectors.toList());
}

@Override
public SessionRating rateSession(SessionRating sessionRating) {

Expand Down Expand Up @@ -137,8 +160,8 @@ public Collection<SessionRating> getRatingsByAttendee(String attendeeId) {

@Override
public Collection<SessionRating> getAllRatings() {

return allRatings.values();
return fakeData;
//return allRatings.values();
}

@Override
Expand All @@ -151,7 +174,16 @@ public void clearAllRatings() {

@Override
public SessionRating getRating(String id) {
return allRatings.get(id);

Optional<SessionRating> match = fakeData.stream()
.filter(r -> r.getSession().equals(id))
.findFirst();

if(!match.isPresent())
throw new RuntimeException("No session with id "+id);

return match.get();
//return allRatings.get(id);
}

}
33 changes: 21 additions & 12 deletions web-application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,8 @@
<workingDirectory>src/main/static</workingDirectory>
</configuration>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<filesets>
<fileset>
<directory>src/main/static/node_modules</directory>
</fileset>
</filesets>
</configuration>
</plugin>
</plugins>

</build>

<profiles>
Expand Down Expand Up @@ -314,6 +303,26 @@
</plugins>
</build>
</profile>

<profile>
<id>clean</id>
<build>
<plugins>

<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<filesets>
<fileset>
<directory>src/main/static/node_modules</directory>
</fileset>
</filesets>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
speaker=microservice-speaker-web/speaker
session=microservice-session/sessions
schedule=microservice-schedule/schedule
vote=vote-service-application
vote=microservice-vote/
4 changes: 4 additions & 0 deletions web-application/src/main/static/app/schedule/schedule.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
//This is the same model our service emits
import {Timestamp} from "rxjs";
export class Schedule {
id: string;
date: Date;
startTime: string;
venue: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ <h3>{{title}}</h3>
</div>
</div>
<div class="row">
<p-schedule #schedule [events]="events" [header]="header" [defaultDate]="defaultDate"
[defaultView]="defaultView" [allDaySlot]="allDaySlot" [minTime]="minTime" [maxTime]="maxTime"></p-schedule>
<p-schedule #schedule [events]="events" [header]="header"></p-schedule>
</div>
</div>
80 changes: 31 additions & 49 deletions web-application/src/main/static/app/schedule/schedules.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import {Component, enableProdMode, OnInit, ViewChild} from "@angular/core";
import {Router} from "@angular/router";
import {Schedule} from "./schedule";
import {ScheduleService} from "./schedule.service";
import {ScheduleModule} from 'primeng/primeng';
import {ScheduleModule} from "primeng/primeng";
import moment = require('moment');

enableProdMode();

@Component({
selector: 'schedules',
templateUrl: 'app/schedule/schedules.component.html',
directives: [ScheduleModule]
templateUrl: 'app/schedule/schedules.component.html'
})

export class SchedulesComponent implements OnInit {
Expand All @@ -19,13 +19,9 @@ export class SchedulesComponent implements OnInit {
selectedSchedule: Schedule;
events: any[];
header: any;
defaultView: string = "agendaWeek";
allDaySlot: boolean = false;
minTime: any = moment.duration(8, "hours");
maxTime: any = moment.duration(20, "hours");

@ViewChild('schedule')
private pSchedule : ScheduleModule;
private pSchedule: ScheduleModule;

constructor(private router: Router, private scheduleService: ScheduleService) {
}
Expand All @@ -37,75 +33,61 @@ export class SchedulesComponent implements OnInit {
});

//No header
this.header = {left: '',
center: '',
right: 'agendaWeek, agendaDay, prev, next '
};
this.header = false;

var today = moment().startOf('day');
var thisWeek = moment().startOf('week').subtract(7, "days");
var d = new Date();
var year = d.getFullYear();
var month = d.getMonth();
var day = d.getDay();

this.events = [
{
"title": "All Day Event",
"start": moment().startOf('week').add(9, "hours"),
"end": moment().startOf('week').add(18, "hours")
"start": new Date(year, month, day).toISOString().substring(0, 10)
},
{
"title": "Long Event",
"allDay": true,
"start": "2016-01-07",
"end": moment().startOf('day').add(1, "days")
"end": new Date(year, month, day++).toISOString().substring(0, 10)
},
{
"title": "Repeating Event",
"id": "repeating"
"start": moment().startOf('week').add(12, "hours"),
"start": moment().startOf('week').add(13, "hours")
"start": new Date(year, month, day++).toISOString().substring(0, 10) + "2016-11-03T16:00:00"
},
{
"title": "Repeating Event",
"id": "repeating"
"start": moment().startOf('week').add(12, "hours").add(1, "days"),
"start": moment().startOf('week').add(13, "hours").add(1, "days")
},
{
"title": "Repeating Event",
"id": "repeating"
"start": moment().startOf('week').add(12, "hours").add(2, "days"),
"start": moment().startOf('week').add(13, "hours").add(2, "days")
"start": new Date(year, month, day++).toISOString().substring(0, 10) + "2016-11-14T16:00:00"
},
{
"title": "Conference",
"allDay": true,
"start": moment().startOf('week'),
"end": moment().startOf('week').add(3, "days")
"start": new Date(year, month, day++).toISOString().substring(0, 10),
"end": new Date(year, month, day++).toISOString().substring(0, 10)
}
];
}

getSchedules(): void {
this.scheduleService.getSchedules().then(schedules => {
this.schedules = schedules;
this.events = this.updateEventsFromSchedules(this.schedules);
if (this.events.length > 0) {
this.defaultDate = this.events[0].start;
this.pSchedule.gotoDate(this.defaultDate);
}
this.setSchedules(schedules);
}).catch(SchedulesComponent.handleError);
}

updateEventsFromSchedules(schedules: Schedule[]) : any[] {
setSchedules(schedules: Schedule[]): void {
this.schedules = schedules;
this.updateEventsFromSchedules(this.schedules)
}

updateEventsFromSchedules(schedules: Schedule[]): any[] {
var events = [];
for (let s of schedules) {
var startTime = moment(s.date + "T" + s.startTime + ":00");
var endTime = moment(startTime).add(1, "hour");
events.push({
"title" : s.venue,
"start" : startTime,
"end" : endTime
});
}
// for (let s of schedules) {
// var startTime = moment(s.date + "T" + s.startTime + ":00");
// var endTime = moment(startTime).add(1, "hour");
// events.push({
// "title": s.venue,
// "start": startTime,
// "end": endTime
// });
// }
return events;
}

Expand Down
3 changes: 2 additions & 1 deletion web-application/src/main/static/app/vote/vote.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class VoteService {
return Promise.resolve(this.votes);
}

console.info('Loading votes...');
return this.http.get(this.endPoint.url + '/rate')
.toPromise()
.then(response => this.setVotes(response.json()))
Expand All @@ -48,4 +49,4 @@ export class VoteService {
console.error('An error occurred', error); // TODO - Display safe error
return Promise.reject(error.message || error);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ <h3>{{title}}</h3>
*ngFor="let vote of votes"
[class.selected]="vote === selectedVote"
(click)="onSelect(vote)">
<span class="badge">Session: {{vote.sessionId}}</span>, Venue: {{vote.venue}}, Date: {{vote.date}}, StartTime: {{vote.startTime}}
<span class="badge">Session: {{vote.session}}</span>, Rating: {{vote.rating}}
</a>
</div>
<vote [vote]="selectedVote"></vote>
2 changes: 1 addition & 1 deletion web-application/src/main/static/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ gulp.task('js-third-party', function () {

try {
fs.accessSync(file, fs.F_OK);
console.log("Synchronized: " + src + " to " + dest);
//console.log("Synchronized: " + src + " to " + dest);
} catch (e) {
tasks.push(buildTask(src, dest));
}
Expand Down
1 change: 1 addition & 0 deletions web-application/src/main/static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"zone.js": "^0.6.26"
},
"devDependencies": {
"@types/chai": "^3.4.34",
"babel-preset-es2015": "^6.16.0",
"concurrently": "^3.1.0",
"del": "^2.2.2",
Expand Down

0 comments on commit a7b7e4d

Please sign in to comment.