Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Queue
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
EIP
Labrador
Queue
Merge requests
!147
Update active course filter for dashboard
Code
Review changes
Check out branch
Open in Workspace
Download
Patches
Plain diff
Expand sidebar
Merged
Update active course filter for dashboard
207-ghost-courses-for-teachers
into
development
Overview
0
Commits
1
Pipelines
0
Changes
2
Merged
Update active course filter for dashboard
Chris Lemaire
requested to merge
207-ghost-courses-for-teachers
into
development
Aug 27, 2019
Overview
0
Commits
1
Pipelines
0
Changes
2
Closes
#207 (closed)
0
0
Merge request reports
Compare
development
version 1
37c4d6a1
Aug 27, 2019
development (base)
and
latest version
latest version
b1a5978e
1 commit,
Aug 28, 2019
version 1
37c4d6a1
1 commit,
Aug 27, 2019
2 files
+
49
−
21
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
src/main/java/nl/tudelft/ewi/queue/controller/HomeController.java
+
36
−
15
View file @ b1a5978e
Edit in single-file editor
Open in Web IDE
Show full file
/*
/*
*
* Queue - A Queueing system that can be used to handle labs in higher education Copyright (C) 2016-2019 Delft
* University of Technology
*
@@ -19,7 +19,10 @@ import java.util.List;
import
java.util.stream.Collectors
;
import
nl.tudelft.ewi.queue.annotation.AuthenticatedUser
;
import
nl.tudelft.ewi.queue.model.*
;
import
nl.tudelft.ewi.queue.model.Course
;
import
nl.tudelft.ewi.queue.model.Role
;
import
nl.tudelft.ewi.queue.model.User
;
import
nl.tudelft.ewi.queue.model.UserPrincipal
;
import
nl.tudelft.ewi.queue.repository.CourseRepository
;
import
nl.tudelft.ewi.queue.repository.UserRepository
;
@@ -46,41 +49,59 @@ public class HomeController {
return
"main"
;
}
/**
* Maps the index/root url to a page. When the user is logged in correctly with an
* AnonymousAuthenticationToken, the user is directed to a dashboard view of the Queue. When the user is
* not correctly logged in, they are redirected to the introductory page of the Queue.
*
* @param model The model to be filled out when the user has courses and/or labs to show on their
* dashboard.
* @return The path to the corresponding Thymeleaf template.
*/
@RequestMapping
(
"/"
)
public
String
index
(
Model
model
)
{
if
(
SecurityContextHolder
.
getContext
().
getAuthentication
()
!=
null
)
{
if
(
SecurityContextHolder
.
getContext
().
getAuthentication
().
isAuthenticated
()
)
{
if
(
!(
SecurityContextHolder
.
getContext
()
if
(
SecurityContextHolder
.
getContext
().
getAuthentication
()
!=
null
&&
SecurityContextHolder
.
getContext
().
getAuthentication
().
isAuthenticated
()
&&
!(
SecurityContextHolder
.
getContext
()
.
getAuthentication
()
instanceof
AnonymousAuthenticationToken
))
{
Authentication
authentication
=
SecurityContextHolder
.
getContext
().
getAuthentication
();
UserPrincipal
userPrincipal
=
(
UserPrincipal
)
authentication
.
getPrincipal
();
Authentication
authentication
=
SecurityContextHolder
.
getContext
().
getAuthentication
();
UserPrincipal
userPrincipal
=
(
UserPrincipal
)
authentication
.
getPrincipal
();
return
dashboard
(
userRepository
.
findByUsername
(
userPrincipal
.
getUsername
()),
model
);
}
}
return
dashboard
(
userRepository
.
findByUsername
(
userPrincipal
.
getUsername
()),
model
);
}
return
"home/index"
;
}
/**
* Maps the user to the dashboard page and inserts the courses and user attributes corresponding to the
* given user.
*
* @param user The user to fill the dashboard model for.
* @param model The model to fill.
* @return The path to the dashboard Thymeleaf template.
*/
private
String
dashboard
(
@AuthenticatedUser
User
user
,
Model
model
)
{
model
.
addAttribute
(
"user"
,
user
);
List
<
Role
>
availableCourses
=
user
.
getRoles
().
stream
()
.
filter
(
role
->
!
role
.
getCourse
().
getIsArchived
()
||
role
.
getUser
().
isTeacher
())
.
filter
(
role
->
!
role
.
getCourse
().
isDeleted
()
&&
(!
role
.
getCourse
().
getIsArchived
()
||
role
.
getUser
().
isTeacher
()))
.
collect
(
Collectors
.
toList
());
// System.out.println(availableCourses);
model
.
addAttribute
(
"availableCourses"
,
availableCourses
);
// TODO this is probably not efficient
if
(
user
.
isAdmin
())
{
List
<
Course
>
runningCourses
=
courseRepository
.
findAll
().
stream
()
.
filter
(
course
->
!
course
.
getTodaysLabs
().
isEmpty
())
.
collect
(
Collectors
.
toList
());
model
.
addAttribute
(
"runningCourses"
,
runningCourses
);
}
model
.
addAttribute
(
"user"
,
user
);
model
.
addAttribute
(
"availableCourses"
,
availableCourses
);
return
"home/dashboard"
;
}
}
Loading