Added courses and course entity pages.

This commit is contained in:
Andrew Lalis 2019-03-03 17:46:07 +01:00 committed by andrewlalis
parent 16bf623a06
commit d49419146a
13 changed files with 196 additions and 22 deletions

View File

@ -0,0 +1,23 @@
package nl.andrewlalis.teaching_assistant_assistant.controllers;
import nl.andrewlalis.teaching_assistant_assistant.model.repositories.CourseRepository;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class Courses {
private CourseRepository courseRepository;
protected Courses(CourseRepository courseRepository) {
this.courseRepository = courseRepository;
}
@GetMapping("/courses")
public String get(Model model) {
model.addAttribute("courses", courseRepository.findAll());
return "courses";
}
}

View File

@ -3,7 +3,6 @@ package nl.andrewlalis.teaching_assistant_assistant.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class RootController {

View File

@ -0,0 +1,29 @@
package nl.andrewlalis.teaching_assistant_assistant.controllers.courses;
import nl.andrewlalis.teaching_assistant_assistant.model.Course;
import nl.andrewlalis.teaching_assistant_assistant.model.repositories.CourseRepository;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import java.util.Optional;
@Controller
public class Entity {
private CourseRepository courseRepository;
protected Entity(CourseRepository courseRepository) {
this.courseRepository = courseRepository;
}
@GetMapping("/courses/{id}")
public String get(@PathVariable Long id, Model model) {
Optional<Course> courseOptional = this.courseRepository.findById(id);
courseOptional.ifPresent(course -> model.addAttribute("course", course));
return "courses/entity";
}
}

View File

@ -76,4 +76,27 @@ public class Course extends BasicEntity {
this.code = code;
}
/*
Getters and Setters
*/
public String getName() {
return name;
}
public String getCode() {
return code;
}
public List<TeachingAssistant> getTeachingAssistants() {
return teachingAssistants;
}
public List<Student> getStudents() {
return students;
}
public List<Assignment> getAssignments() {
return assignments;
}
}

View File

@ -28,7 +28,7 @@ public class AssignmentGrade extends BasicEntity {
fetch = FetchType.EAGER,
orphanRemoval = true
)
@JoinColumn(name = "assignmentGrade_id")
@JoinColumn(name = "assignment_grade_id")
private List<SectionGrade> sectionGrades;
}

View File

@ -11,7 +11,7 @@ import javax.persistence.*;
@Inheritance(
strategy = InheritanceType.JOINED
)
public abstract class Feedback extends BasicEntity {
public class Feedback extends BasicEntity {
/**
* The graded section to which this feedback belongs.
@ -22,6 +22,7 @@ public abstract class Feedback extends BasicEntity {
)
private SectionGrade assignmentSection;
@Column
private String text;
}

View File

@ -17,7 +17,7 @@ public class TeachingAssistant extends Person {
* The list of all feedback given by a teaching assistant.
*/
@OneToMany
@JoinColumn(name = "teachingAssistant_id")
@JoinColumn(name = "teaching_assistant_id")
private List<SectionGrade> sectionGrades;
}

View File

@ -0,0 +1,44 @@
body {
padding: 0;
margin: 0;
background-color: whitesmoke;
}
.header_bar {
background-color: green;
width: 100%;
color: whitesmoke;
padding-bottom: 20px;
padding-top: 20px;
}
.header_title {
margin-top: auto;
margin-bottom: auto;
padding: 10px;
width: 25%;
display: inline;
}
.header_link_list {
list-style-type: none;
margin: 0;
padding: 0;
width: 75%;
display: inline;
}
.header_link_list li {
display: inline-block;
}
.header_link_list a {
text-decoration: none;
color: inherit;
background-color: darkgreen;
padding: 10px;
}
.header_link_list a:hover {
background-color: darkgray;
}

View File

@ -0,0 +1,24 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" th:replace="~{layouts/basic_page :: layout (~{::title}, ~{::section})}">
<head>
<title>Courses</title>
</head>
<body>
<section>
<table>
<tr>
<th>Name</th>
<th>Code</th>
</tr>
<tr th:each="course: ${courses}">
<td>
<a th:href="@{/courses/{id}(id=${course.getId()})}" th:text="${course.getName()}"></a>
</td>
<td th:text="${course.getCode()}"></td>
</tr>
</table>
</section>
</body>
</html>

View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" th:replace="~{layouts/basic_page :: layout (~{::title}, ~{::section})}">
<head>
<meta charset="UTF-8">
<title th:text="${course.getName()}"></title>
</head>
<body>
<section>
<h1 th:text="${course.getName()}"></h1>
<h3 th:text="${course.getCode()}"></h3>
<h3>Created on: <span th:text="${course.getCreatedOn()}"></span></h3>
<h3>Id: <span th:text="${course.getId()}"></span></h3>
</section>
</body>
</html>

View File

@ -2,21 +2,18 @@
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
<title>Teaching Assistant Assistant</title>
</head>
<body>
<nav th:fragment="header">
<ul>
<li>
<a href="#" th:href="@{/}">Home</a>
</li>
<li>
<a href="#" th:href="@{/courses}">Courses</a>
</li>
<li>
<a href="#" th:href="@{/students}">Students</a>
</li>
<nav th:fragment="header" class="header_bar">
<link rel="stylesheet" href="../../../resources/static/css/header.css" th:href="@{/css/header.css}"/>
<h1 class="header_title">Teaching Assistant Assistant</h1>
<ul class="header_link_list">
<li><a href="/" th:href="@{/}">Home</a>
<li><a href="/courses" th:href="@{/courses}">Courses</a>
<li><a href="/students" th:href="@{/students}">Students</a>
</ul>
</nav>

View File

@ -1,18 +1,17 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<html xmlns:th="http://www.thymeleaf.org" th:replace="~{layouts/basic_page :: layout (~{::title}, ~{::section})}">
<head>
<meta charset="UTF-8">
<title>Title</title>
<title>Homepage</title>
</head>
<body>
<div th:replace="~{fragments/header :: header}">&nbsp;</div>
<div>
<section>
<p>
Welcome to the home page.
</p>
</div>
</section>
</body>
</html>

View File

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en" th:fragment="layout (title, content)" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title th:replace="${title}">basic_page</title>
</head>
<body>
<div th:replace="~{fragments/header :: header}">&nbsp;</div>
<div th:replace="${content}">
<p>
Basic page content block.
</p>
</div>
</body>
</html>