Skip to content

Commit ed8f8d1

Browse files
authored
Merge pull request #120 from marc101101/feature/course-detail-view
Feature/course detail view
2 parents 093e447 + 46ec4d0 commit ed8f8d1

11 files changed

Lines changed: 240 additions & 167 deletions

File tree

client/app/components/home/courses/courses.component.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Renderer2, ViewChild, ElementRef, AfterViewInit, OnInit } from '@angular/core';
1+
import { Component, Renderer2, ViewChild, ElementRef, OnInit } from '@angular/core';
22
import { CategoryService } from '../../../services/category.service';
33
import { ActivatedRoute, Params } from '@angular/router';
44
import { CommunicationService } from '../shared/communication.service';
@@ -16,25 +16,24 @@ export class CoursesComponent implements OnInit {
1616
@ViewChild('backgroundElement') backgroundElement: ElementRef;
1717

1818
public dataIsAvailable: boolean = false;
19-
public courses: Array<any>;
19+
public courses: Array<any> = [];
2020
public headerText: string = "";
2121
public category: string = "";
2222

2323
constructor(
24-
public categoryService: CategoryService,
25-
public userService: UserService,
26-
private activatedRoute: ActivatedRoute,
27-
public comService: CommunicationService,
28-
public coursesService: CoursesService,
29-
public renderer: Renderer2) {}
30-
31-
ngOnInit() {
32-
this.comService.getInfo().subscribe(response => {
33-
this.category = response.category;
34-
this.renderer.addClass(this.backgroundElement.nativeElement, response.color);
35-
});
24+
public coursesService: CoursesService,
25+
public categoryService: CategoryService,
26+
public userService: UserService,
27+
private activatedRoute: ActivatedRoute,
28+
public comService: CommunicationService,
29+
public renderer: Renderer2) {
30+
this.comService.getInfo().subscribe(color => {
31+
//this.renderer.addClass(this.backgroundElement.nativeElement, color);
32+
});
33+
}
3634

37-
this.activatedRoute.params.subscribe((params: Params) => {
35+
ngOnInit(){
36+
this.activatedRoute.params.subscribe((params: Params) => {
3837
if(params.id == "me"){
3938
this.requestCoursesByUser();
4039
}
@@ -46,24 +45,25 @@ export class CoursesComponent implements OnInit {
4645

4746
requestCoursesByUser():void{
4847
this.headerText = "Meine";
49-
this.userService.getCoursesByUser().subscribe(response =>{
50-
response.forEach(element => {
51-
this.courses = [];
52-
this.coursesService.getCoursesByCourseId(element.ANM_KURS_ID).subscribe(response => {
53-
response.ANM_DATUM = element.ANM_DATUM;
54-
this.courses.push(response);
48+
this.courses = [];
49+
this.userService.getCoursesByUser().subscribe(responseUser =>{
50+
responseUser.forEach(element => {
51+
this.coursesService.getCoursesByCourseId(element.KURS_ID).subscribe(responseCourse => {
52+
responseCourse.ANM_DATUM = element.ANM_DATUM;
53+
this.courses.push(responseCourse);
5554
});
5655
});
57-
if(response.name != "HttpResponseError"){
56+
if(responseUser.name != "HttpResponseError"){
5857
this.dataIsAvailable = true;
5958
}
6059
});
6160
}
6261

6362
requestCoursesByCategory(courseId: string):void{
6463
this.headerText = this.category;
65-
this.categoryService.getCoursesByCategoryId(courseId).subscribe(response =>{
66-
this.courses = response;
64+
this.courses = [];
65+
this.categoryService.getCoursesByCategoryId(courseId).subscribe(response =>{
66+
this.courses.push(response);
6767
if(response.name != "HttpResponseError"){
6868
this.dataIsAvailable = true;
6969
this.courses = response;

client/app/components/home/singlecourse/singlecourse.component.html

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
</div>
1919
<div>
2020
<i class="fa fa-map-marker info-icon"></i>
21-
<p style="color:white">Ort: {{singleCourse.KURS_ORT_ID}}</p>
21+
<p style="color:white">Ort: {{singleCourse.location.ORT_STRASSE}}, {{singleCourse.location.ORT_PLZ}} {{singleCourse.location.ORT_ORTSNAME}}</p>
2222
</div>
2323
<div>
2424
<i class="fa fa-user info-icon"></i>
25-
<p style="color:white">Veranstalter: {{singleCourse.KURS_VERANSTALTUNG}}</p>
25+
<p style="color:white">Veranstalter: {{singleCourse.KURS_REFERENT_ID}}</p>
2626
</div>
2727
</div>
2828

@@ -36,16 +36,37 @@
3636
</div>
3737

3838

39-
<!--section style="padding: 1rem; margin-top: -2rem;" *ngIf="dataIsAvailable">
40-
<div class="card" style="padding:1rem; height: 4rem">
39+
<section style="padding: 1rem; margin-top: -2rem;" *ngIf="dataIsAvailable && moreInfo">
40+
<div class="card" style="padding:1rem;" (click)="moreInfo = false">
41+
<div style="font-size: 1.2rem; float: left;">
42+
Weniger Informationen
43+
</div>
44+
<div style="padding: 0.5rem;">
45+
<i class="fa fa-chevron-up " style="float: right;" aria-hidden="true"></i>
46+
</div>
47+
<div class="column is-12" style="padding-left: 0rem; padding-top: 1rem;">
48+
<div>
49+
<p>Teilnehmer: max. {{singleCourse.KURS_TEIL_MAX}} / min. {{singleCourse.KURS_TEIL_MIN}}</p>
50+
<p>Termine: {{singleCourse.KURS_ANZAHLTERMINE}}</p>
51+
<p>Mitzubringen: {{singleCourse.KURS_MITZUBRINGEN}}</p>
52+
<p>Kursgebühr: {{singleCourse.KURS_PREIS}}</p>
53+
<p>Anmeldefrist: {{singleCourse.KURS_ANMFRIST}}</p>
54+
<p>Ende: {{singleCourse.KURS_ENDE_UHRZEIT}}</p>
55+
</div>
56+
</div>
57+
</div>
58+
</section>
59+
60+
<section style="padding: 1rem; margin-top: -2rem;" *ngIf="dataIsAvailable && !moreInfo">
61+
<div class="card" style="padding:1rem; height: 4rem" (click)="moreInfo = true">
4162
<div style="font-size: 1.2rem; float: left;">
4263
Mehr Informationen
4364
</div>
4465
<div style="padding: 0.5rem;">
4566
<i class="fa fa-chevron-down " style="float: right;" aria-hidden="true"></i>
4667
</div>
4768
</div>
48-
</section-->
69+
</section>
4970

5071
<section *ngIf="dataIsAvailable" style=" margin-bottom: 2rem">
5172
<div class="card" style="padding:1rem">

client/app/components/home/singlecourse/singlecourse.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export class SingleCourseComponent implements OnInit {
1818
public button_text: string = "Anmelden";
1919
public showButton: boolean = false;
2020
public alreadyApplied: boolean = false;
21+
public moreInfo: boolean = false;
2122

2223
@ViewChild('button') elButton: ElementRef;
2324

server/service/CoursesService.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,12 @@ exports.coursesCourse_idGET = function (course_id) {
128128
Courses.where({
129129
kurs_id: course_id
130130
})
131-
.fetch()
131+
.fetch({withRelated: ["location"]})
132132
.then((course) => {
133133
if (!course) {
134134
reject(Errors.notFound("GET ID " + course_id, "COURSE"));
135135
}
136-
resolve(course);
136+
resolve(course.toJSON());
137137
})
138138
.catch((error) => {
139139
reject(error);
@@ -183,9 +183,9 @@ exports.coursesCourse_idSignoffPOST = function (course_id, req) {
183183
exports.coursesGET = function () {
184184
return new Promise(function (resolve, reject) {
185185
Courses
186-
.fetchAll()
186+
.fetchAll({withRelated: ["location"]})
187187
.then((course) => {
188-
resolve(course.map(item => item.attributes));
188+
resolve(course.toJSON());
189189
})
190190
.catch((error) => {
191191
reject(error);
@@ -204,9 +204,9 @@ exports.coursesHighlightsGET = function () {
204204
return new Promise(function (resolve, reject) {
205205
Courses
206206
.where({kurs_highlight: 1})
207-
.fetchAll()
207+
.fetchAll({withRelated: ["location"]})
208208
.then((courses) => {
209-
resolve(courses.map(item => item.attributes));
209+
resolve(courses.toJSON());
210210
})
211211
.catch((error) => {
212212
reject(error);
@@ -221,12 +221,12 @@ exports.coursesLastminuteGET = function() {
221221
.query(function(qb) {
222222
qb.whereBetween('KURS_ANMFRIST', [moment().format('YYYY-MM-DD'), moment().add(6, 'weeks').format('YYYY-MM-DD')]);
223223
})
224-
.fetchAll({withRelated: ["applications"]})
224+
.fetchAll({withRelated: ["applications", "location"]})
225225
.then((courses) => {
226226
resolve(courses
227227
.filter(item => item.related('applications').toJSON().length < item.attributes.KURS_TEIL_MAX)
228228
.filter(item => item.attributes.KURS_KURSSTAT_ID === 3)
229-
.map(item => item.attributes)
229+
.map(item => item.toJSON())
230230
)
231231
})
232232
.catch((error) => {

server/service/UserService.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ exports.userMeGET = function (id) {
2525
if (!user) {
2626
reject(Errors.notFound("GET ID " + id, "USER"))
2727
}
28-
/*let trimmedUser = {
29-
"firstname": user.attributes.TEIL_VORNAME,
30-
"address": user.attributes.TEIL_ORT,
31-
"id": user.attributes.TEIL_ID,
32-
"email": user.attributes.TEIL_EMAIL,
33-
"lastname": user.attributes.TEIL_NACHNAME
34-
};*/
3528
resolve(user);
3629
})
3730
.catch((error) => {
@@ -48,12 +41,10 @@ exports.userMeCoursesGET = function (user_id) {
4841
ANM_STAT_ID: 1 || 2
4942
})
5043
.fetchAll({
51-
withRelated: ["course"]
44+
withRelated: ["course.location"]
5245
})
5346
.then((applications) => {
54-
let courses = applications.models.map(item => {
55-
return item.related("course").toJSON();
56-
})
47+
let courses = applications.map(item => item.related('course').toJSON());
5748
resolve(courses);
5849
})
5950
.catch((error) => {

server/test/categories.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ describe('Categories', () => {
2727
chai.request(server)
2828
.get('/v1/categories/42/courses')
2929
.end((err, res) => {
30-
console.log(err)
3130
res.should.have.status(404);
3231
done();
3332
})
@@ -68,6 +67,9 @@ describe('Categories', () => {
6867
.end((err, res) => {
6968
res.should.have.status(200);
7069
res.body.length.should.equal(3);
70+
res.body[0].DATENHISTORY.should.equal("COURSE_IDENTIFIER");
71+
res.body[1].DATENHISTORY.should.equal("COURSE_IDENTIFIER");
72+
res.body[2].DATENHISTORY.should.equal("COURSE_IDENTIFIER");
7173
done();
7274
})
7375
})

server/test/courses.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ describe("Courses Last Minute", () => {
172172
res.should.have.status(200);
173173
res.body.should.be.a('array');
174174
res.body.length.should.equal(1);
175+
res.body[0].DATENHISTORY.should.equal("COURSE_IDENTIFIER");
175176
done();
176177
})
177178
})

server/test/helpers/dbhelpers.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ var Courses = require('../../utils/database').Course;
66
var Applications = require('../../utils/database').Application;
77
var CourseFeedback = require('../../utils/database').CourseFeedback;
88
var User = require('../../utils/database').User;
9-
var Applications = require('../../utils/database').Application
9+
var Applications = require('../../utils/database').Application;
10+
var Location = require('../../utils/database').Location;
1011

1112
var generateApplicationFor = require('../../service/CoursesService').generateApplicationFor;
1213

@@ -100,6 +101,19 @@ const CoursesHelper = {
100101
},
101102

102103
setupDataBase: () => {
104+
Location
105+
.fetchAll()
106+
.then(locations => {
107+
if (locations.length == 0) {
108+
console.log("No Locations found. Adding a sample Location");
109+
let sampleLocation = require('./sampleData').location();
110+
new Location(sampleLocation)
111+
.save()
112+
.then(() => {
113+
console.log("Location added!");
114+
});
115+
}
116+
})
103117
console.log("Setting up Content in Table vhslq_kurse")
104118
return new Promise((resolve, reject) => {
105119
let sample = require('./sampleData').courses();

0 commit comments

Comments
 (0)