Added a shit ton of stuff to make it easier to navigate through data.

This commit is contained in:
Andrew Lalis 2019-04-20 13:19:11 +02:00 committed by andrewlalis
parent d9d9a51707
commit 10403b4be5
22 changed files with 467 additions and 94 deletions

View File

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

View File

@ -0,0 +1,70 @@
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 for the course entity, that is, one individual course.
*/
@Controller
public class CourseEntity {
private CourseRepository courseRepository;
protected CourseEntity(CourseRepository courseRepository) {
this.courseRepository = courseRepository;
}
/**
* Handles get requests to a course with a given code.
* @param code The unique course code used to identify a course entity.
* @param model The view model that will be populated with data.
* @return The template which will be used in conjunction with the model to build a view.
*/
@GetMapping("/courses/{code}")
public String get(@PathVariable String code, Model model) {
this.addCourseToModelIfExists(code, model);
return "courses/entity";
}
/**
* Gets the student teams for a particular course.
* @param code The course code.
* @param model The view model.
* @return The template for viewing the list of student teams.
*/
@GetMapping("/courses/{code}/student_teams")
public String getStudentTeams(@PathVariable String code, Model model) {
this.addCourseToModelIfExists(code, model);
return "courses/entity/student_teams";
}
/**
* Gets the students for a particular course.
* @param code The course code.
* @param model The view model.
* @return The template for viewing the list of students.
*/
@GetMapping("/courses/{code}/students")
public String getStudents(@PathVariable String code, Model model) {
this.addCourseToModelIfExists(code, model);
return "courses/entity/students";
}
/**
* Adds the course found by a certain code to the list of model attributes.
* @param courseCode The unique code used to identify this course.
* @param model The view model to add the course data to.
*/
private void addCourseToModelIfExists(String courseCode, Model model) {
Optional<Course> courseOptional = this.courseRepository.findByCode(courseCode);
courseOptional.ifPresent(course -> model.addAttribute("course", course));
}
}

View File

@ -1,42 +0,0 @@
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 for the course entity, that is, one individual course.
*/
@Controller
public class Entity {
private CourseRepository courseRepository;
protected Entity(CourseRepository courseRepository) {
this.courseRepository = courseRepository;
}
/**
* Handles get requests to a course with a given code.
* @param code The unique course code used to identify a course entity.
* @param model The view model that will be populated with data.
* @return The template which will be used in conjunction with the model to build a view.
*/
@GetMapping("/courses/{code}")
public String get(@PathVariable String code, Model model) {
Optional<Course> courseOptional = this.courseRepository.findByCode(code);
if (courseOptional.isPresent()) {
Course course = courseOptional.get();
model.addAttribute("course", course);
}
return "courses/entity";
}
}

View File

@ -1,4 +1,4 @@
package nl.andrewlalis.teaching_assistant_assistant.controllers.courses; package nl.andrewlalis.teaching_assistant_assistant.controllers.courses.entity;
import nl.andrewlalis.teaching_assistant_assistant.model.Course; import nl.andrewlalis.teaching_assistant_assistant.model.Course;
import nl.andrewlalis.teaching_assistant_assistant.model.people.teams.StudentTeam; import nl.andrewlalis.teaching_assistant_assistant.model.people.teams.StudentTeam;
@ -40,7 +40,7 @@ public class ImportStudents {
public String get(@PathVariable String code, Model model) { public String get(@PathVariable String code, Model model) {
Optional<Course> optionalCourse = this.courseRepository.findByCode(code); Optional<Course> optionalCourse = this.courseRepository.findByCode(code);
optionalCourse.ifPresent(course -> model.addAttribute("course", course)); optionalCourse.ifPresent(course -> model.addAttribute("course", course));
return "courses/import_students"; return "courses/entity/import_students";
} }
@PostMapping( @PostMapping(
@ -74,10 +74,10 @@ public class ImportStudents {
team.setCourse(course); team.setCourse(course);
course.addStudentTeam(team); course.addStudentTeam(team);
//this.studentRepository.saveAll((team.getMembers())); this.studentRepository.saveAll(team.getStudents());
}); });
//this.studentTeamRepository.saveAll(studentTeams); this.studentTeamRepository.saveAll(studentTeams);
this.courseRepository.save(course); this.courseRepository.save(course);

View File

@ -0,0 +1,39 @@
package nl.andrewlalis.teaching_assistant_assistant.controllers.courses.entity.student_teams;
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 org.springframework.web.bind.annotation.PostMapping;
import java.util.Optional;
@Controller
public class GenerateRepositories {
private CourseRepository courseRepository;
protected GenerateRepositories(CourseRepository courseRepository) {
this.courseRepository = courseRepository;
}
@GetMapping("/courses/{courseCode}/student_teams/generate_repositories")
public String get(@PathVariable String courseCode, Model model) {
Optional<Course> optionalCourse = this.courseRepository.findByCode(courseCode);
optionalCourse.ifPresent(course -> model.addAttribute("course", course));
return "courses/entity/student_teams/generate_repositories";
}
@PostMapping(
value = "/courses/{courseCode}/student_teams/generate_repositories",
consumes = "application/x-www-form-urlencoded"
)
public String post(@PathVariable String courseCode) {
System.out.println("Post received for " + courseCode);
return "redirect:/courses/{courseCode}";
}
}

View File

@ -0,0 +1,35 @@
package nl.andrewlalis.teaching_assistant_assistant.controllers.courses.entity.student_teams;
import nl.andrewlalis.teaching_assistant_assistant.model.people.teams.StudentTeam;
import nl.andrewlalis.teaching_assistant_assistant.model.repositories.StudentTeamRepository;
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 StudentTeamEntity {
private StudentTeamRepository studentTeamRepository;
protected StudentTeamEntity(StudentTeamRepository studentTeamRepository) {
this.studentTeamRepository = studentTeamRepository;
}
/**
* Gets data for a specific student team.
* @param courseCode The course code for the course in which the team resides.
* @param teamId The id of the team.
* @param model The view model.
* @return The name of the template which will be used to view the student team.
*/
@GetMapping("/courses/{courseCode}/student_teams/{teamId}")
public String get(@PathVariable String courseCode, @PathVariable int teamId, Model model) {
Optional<StudentTeam> optionalStudentTeam = this.studentTeamRepository.findByCourseCodeAndId(courseCode, teamId);
optionalStudentTeam.ifPresent(team -> model.addAttribute("student_team", team));
return "courses/entity/student_teams/entity";
}
}

View File

@ -0,0 +1,27 @@
package nl.andrewlalis.teaching_assistant_assistant.controllers.students;
import nl.andrewlalis.teaching_assistant_assistant.model.people.Student;
import nl.andrewlalis.teaching_assistant_assistant.model.repositories.StudentRepository;
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 StudentEntity {
private StudentRepository studentRepository;
protected StudentEntity(StudentRepository studentRepository) {
this.studentRepository = studentRepository;
}
@GetMapping("/students/{id}")
public String get(@PathVariable long id, Model model) {
Optional<Student> optionalStudent = this.studentRepository.findById(id);
optionalStudent.ifPresent(student -> model.addAttribute("student", student));
return "students/entity";
}
}

View File

@ -31,6 +31,12 @@ public class Course extends BasicEntity {
@Column(unique = true, nullable = false) @Column(unique = true, nullable = false)
private String code; private String code;
/**
* The github organization name for this course, if any.
*/
@Column
private String githubOrganizationName;
/** /**
* The list of assignments this course contains. * The list of assignments this course contains.
*/ */
@ -119,6 +125,14 @@ public class Course extends BasicEntity {
return code; return code;
} }
public String getGithubOrganizationName() {
return this.githubOrganizationName;
}
public void setGithubOrganizationName(String name) {
this.githubOrganizationName = name;
}
public List<Assignment> getAssignments() { public List<Assignment> getAssignments() {
return assignments; return assignments;
} }

View File

@ -4,6 +4,7 @@ import nl.andrewlalis.teaching_assistant_assistant.model.assignments.grades.Assi
import nl.andrewlalis.teaching_assistant_assistant.model.people.Person; import nl.andrewlalis.teaching_assistant_assistant.model.people.Person;
import nl.andrewlalis.teaching_assistant_assistant.model.people.Student; import nl.andrewlalis.teaching_assistant_assistant.model.people.Student;
import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.FetchType; import javax.persistence.FetchType;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
@ -16,6 +17,12 @@ import java.util.List;
@Entity @Entity
public class StudentTeam extends Team { public class StudentTeam extends Team {
/**
* The name of the github repository that belongs to this team.
*/
@Column
private String githubRepositoryName;
/** /**
* The list of assignment grades which this student group has received. * The list of assignment grades which this student group has received.
*/ */
@ -38,4 +45,12 @@ public class StudentTeam extends Team {
return students; return students;
} }
public String getGithubRepositoryName() {
return this.githubRepositoryName;
}
public void setGithubRepositoryName(String name) {
this.githubRepositoryName = name;
}
} }

View File

@ -3,5 +3,8 @@ package nl.andrewlalis.teaching_assistant_assistant.model.repositories;
import nl.andrewlalis.teaching_assistant_assistant.model.people.teams.StudentTeam; import nl.andrewlalis.teaching_assistant_assistant.model.people.teams.StudentTeam;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
import java.util.Optional;
public interface StudentTeamRepository extends CrudRepository<StudentTeam, Long> { public interface StudentTeamRepository extends CrudRepository<StudentTeam, Long> {
Optional<StudentTeam> findByCourseCodeAndId(String courseCode, long id);
} }

View File

@ -1,4 +1,4 @@
spring.jpa.hibernate.ddl-auto=create-drop spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL57Dialect spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL57Dialect
spring.datasource.username=root spring.datasource.username=root
spring.datasource.password=root spring.datasource.password=root
@ -11,3 +11,5 @@ spring.datasource.url=jdbc:mysql://localhost:3306/teaching_assistant_assistant?s
spring.security.user.name=tester spring.security.user.name=tester
spring.security.user.password=tester spring.security.user.password=tester
spring.data.rest.e

View File

@ -14,6 +14,8 @@
<input id="course_name_input" type="text" th:field="*{name}"/> <input id="course_name_input" type="text" th:field="*{name}"/>
<label for="course_code_input">Code:</label> <label for="course_code_input">Code:</label>
<input id="course_code_input" type="text" th:field="*{code}"/> <input id="course_code_input" type="text" th:field="*{code}"/>
<label for="course_github_organization_name_input">Github Organization:</label>
<input id="course_github_organization_name_input" type="text" th:field="*{githubOrganizationName}"/>
<button type="submit">Submit</button> <button type="submit">Submit</button>
</form> </form>
</div> </div>

View File

@ -10,53 +10,20 @@
<h1><span th:text="${course.getName()}"></span> (Code: <span th:text="${course.getCode()}"></span>)</h1> <h1><span th:text="${course.getName()}"></span> (Code: <span th:text="${course.getCode()}"></span>)</h1>
<hr> <hr>
<h3>Teaching Assistant Groups (<span th:text="${course.getTeachingAssistantTeams().size()}"></span>):</h3> <ul>
<table> <li>
<tr th:each="teachingAssistantTeam: ${course.getTeachingAssistantTeams()}"> <a th:href="@{${'https://www.github.com/' + course.getGithubOrganizationName()}}">Github Organization</a>
<td> </li>
<a <li>
th:href="@{/courses/{code}/ta_teams/{team_id} <a th:href="@{/courses/{code}/teaching_assistant_teams(code=${course.getCode()})}">Teaching Assistant Teams</a>
(code=${course.getCode()}, team_id=${teachingAssistantTeam.getId()})}"> </li>
TA Team <span th:text="${teachingAssistantTeam.getId()}"></span> <li>
</a> <a th:href="@{/courses/{code}/student_teams(code=${course.getCode()})}">Student Teams</a>
</td> </li>
<td th:each="teachingAssistant: ${teachingAssistantTeam.getMembers()}"> <li>
<span th:text="${teachingAssistant.getFullName()}"></span> <a th:href="@{/courses/{code}/students(code=${course.getCode()})}">All Students</a>
</td> </li>
</tr> </ul>
</table>
<h3>Student Groups (<span th:text="${course.getStudentTeams().size()}"></span>):</h3>
<table>
<tr th:each="studentTeam: ${course.getStudentTeams()}">
<td>
<a
th:href="@{/courses/{code}/student_teams/{team_id}
(code=${course.getCode()}, team_id=${studentTeam.getId()})}">
Student Team <span th:text="${studentTeam.getId()}"></span>
</a>
</td>
<td th:each="student: ${studentTeam.getMembers()}">
<span th:text="${student.getFullName()}"></span>
</td>
</tr>
</table>
<h3>All Students (<span th:text="${course.getStudents().size()}"></span>):</h3>
<table>
<tr th:each="student: ${course.getStudents()}">
<td>
<a
th:href="@{/students/{student_id}
(student_id=${student.getId()})}">
Student <span th:text="${student.getId()}"></span>
</a>
</td>
<td th:text="${student.getFullName()}"></td>
<td th:text="${student.getStudentNumber()}"></td>
<td th:text="${student.getEmailAddress()}"></td>
</tr>
</table>
</div> </div>
<div id="sidebar"> <div id="sidebar">

View File

@ -0,0 +1,39 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" th:replace="~{layouts/basic_page :: layout (~{::title}, ~{::#content}, ~{::#sidebar})}">
<head>
<meta charset="UTF-8">
<title>Student Teams</title>
</head>
<body>
<div id="content">
<h1>Student Teams for <span th:text="${course.getName()}"></span></h1>
<div th:if="${course.getStudentTeams().isEmpty()}">
<p>No student teams.</p>
</div>
<table>
<tr th:each="studentTeam: ${course.getStudentTeams()}">
<td>
<a
th:href="@{/courses/{code}/student_teams/{team_id}
(code=${course.getCode()}, team_id=${studentTeam.getId()})}">
Student Team <span th:text="${studentTeam.getId()}"></span>
</a>
</td>
<td th:each="student: ${studentTeam.getStudents()}">
<span th:text="${student.getFullName()}"></span>
</td>
<td th:text="${studentTeam.getGithubRepositoryName()}"></td>
</tr>
</table>
</div>
<div id="sidebar">
<div class="sidebar_block">
<a th:href="@{/courses/{code}/student_teams/generate_repositories(code=${course.getCode()})}">Generate Repositories</a>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,38 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" th:replace="~{layouts/basic_page :: layout (~{::title}, ~{::#content}, ~{::#sidebar})}">
<head>
<meta charset="UTF-8">
<title>Student Team</title>
</head>
<body>
<div id="content">
<h1>Student Team <span th:text="${student_team.getId()}"></span></h1>
<ul>
<li>
Github Repository:
<a th:href="@{${'https://www.github.com/' + student_team.getCourse().getGithubOrganizationName() + '/' + student_team.getGithubRepositoryName()}}">
<span th:text="${student_team.getGithubRepositoryName()}"></span>
</a>
</li>
<li>
Members:
<ul>
<li th:each="student: ${student_team.getStudents()}">
<a th:href="@{/students/{id}(id=${student.getId()})}">
<span th:text="${student.getFullName()}"></span>
</a>
</li>
</ul>
</li>
</ul>
</div>
<div id="sidebar">
</div>
</body>
</html>

View File

@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" th:replace="~{layouts/basic_page :: layout (~{::title}, ~{::#content}, ~{::#sidebar})}">
<head>
<meta charset="UTF-8">
<title>Generate Repositories</title>
</head>
<body>
<div id="content">
<h1>Generate Repositories for all Student Teams in <span th:text="${course.getName()}"></span></h1>
<form
method="post"
action="#"
enctype="application/x-www-form-urlencoded"
th:action="@{/courses/{code}/student_teams/generate_repositories(code=${course.getCode()})}"
>
<button type="submit">Submit</button>
</form>
</div>
<div id="sidebar">
</div>
</body>
</html>

View File

@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" th:replace="~{layouts/basic_page :: layout (~{::title}, ~{::#content}, ~{::#sidebar})}">
<head>
<meta charset="UTF-8">
<title>Students</title>
</head>
<body>
<div id="content">
<h1>Students in <span th:text="${course.getName()}"></span></h1>
<table>
<tr th:each="student: ${course.getStudents()}">
<td>
<a th:href="@{/students/{id}(id=${student.getId()})}"><span th:text="${student.getFullName()}"></span></a>
</td>
<td th:text="${student.getStudentNumber()}"></td>
<td th:text="${student.getEmailAddress()}"></td>
</tr>
</table>
</div>
<div id="sidebar">
</div>
</body>
</html>

View File

@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" th:replace="~{layouts/basic_page :: layout (~{::title}, ~{::#content}, ~{::#sidebar})}">
<head>
<meta charset="UTF-8">
<title>Teaching Assistant Teams</title>
</head>
<body>
<div id="content">
<h1>Teaching Assistant Teams for <span th:text="${course.getName()}"></span></h1>
<table>
</table>
</div>
<div id="sidebar">
</div>
</body>
</html>

View File

@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" th:replace="~{layouts/basic_page :: layout (~{::title}, ~{::#content}, ~{::#sidebar})}">
<head>
<meta charset="UTF-8">
<title>Students</title>
</head>
<body>
<div id="content">
<h1>All Students</h1>
<table>
<tr th:each="student: ${students}">
<td>
<a th:href="@{/students/{id}(id=${student.getId()})}"><span th:text="${student.getFullName()}"></span></a>
</td>
<td th:text="${student.getStudentNumber()}"></td>
<td th:text="${student.getEmailAddress()}"></td>
</tr>
</table>
</div>
<div id="sidebar">
</div>
</body>
</html>

View File

@ -0,0 +1,37 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" th:replace="~{layouts/basic_page :: layout (~{::title}, ~{::#content}, ~{::#sidebar})}">
<head>
<title>Student</title>
</head>
<body>
<div id="content">
<h1>Student: <span th:text="${student.getFullName()}"></span></h1>
<ul>
<li>
Student Number: <code th:text="${student.getStudentNumber()}"></code>
</li>
<li>
Email: <code th:text="${student.getEmailAddress()}"></code>
</li>
<li>
Github Username: <code th:text="${student.getGithubUsername()}"></code>
</li>
<li>
Courses:
<ul>
<li th:each="course: ${student.getCourses()}">
<a th:href="@{/courses/{code}(code=${course.getCode()})}"><span th:text="${course.getName()}"></span></a>
</li>
</ul>
</li>
</ul>
</div>
<div id="sidebar">
</div>
</body>
</html>