-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from ConnorMarcus/project-view-page-noah
Project view page noah
- Loading branch information
Showing
9 changed files
with
335 additions
and
23 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
src/main/java/sysc4806/project/controllers/CustomErrorController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package sysc4806.project.controllers; | ||
|
||
import org.springframework.boot.web.servlet.error.ErrorController; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
@Controller | ||
public class CustomErrorController implements ErrorController { | ||
|
||
@RequestMapping("/error") | ||
public String handleError() { | ||
return "error"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/sysc4806/project/services/ApplicationUserService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package sysc4806.project.services; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.stereotype.Service; | ||
import sysc4806.project.models.*; | ||
import sysc4806.project.repositories.ApplicationUserRepository; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import static sysc4806.project.util.AuthenticationHelper.PROFESSOR_ROLE; | ||
import static sysc4806.project.util.AuthenticationHelper.getUserRole; | ||
|
||
@Service | ||
public class ApplicationUserService { | ||
@Autowired | ||
ApplicationUserRepository applicationUserRepository; | ||
|
||
/** | ||
* Gets the current user | ||
* @return The current application user | ||
*/ | ||
public ApplicationUser getCurrentUser() { | ||
UserDetails user = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); | ||
return applicationUserRepository.findApplicationUserByEmail(user.getUsername()); | ||
} | ||
|
||
|
||
/** | ||
* Check if the current user is Professor | ||
* @return True if the current user is Professor | ||
*/ | ||
public boolean isCurrentUserProfessor() throws Exception { | ||
ApplicationUser currentUser = getCurrentUser(); | ||
return Objects.equals(getUserRole(currentUser), PROFESSOR_ROLE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
body { | ||
font-family: Arial, sans-serif; | ||
background-color: #f5f5f5; | ||
text-align: center; | ||
margin-top: 50px; | ||
color: #333; | ||
} | ||
|
||
h1 { | ||
margin-bottom: 30px; | ||
} | ||
|
||
table { | ||
margin-left: auto; | ||
margin-right: auto; | ||
border-collapse: collapse; | ||
color: #333; | ||
} | ||
|
||
th, td { | ||
border: 2px solid #dddddd; | ||
padding: 8px; | ||
background-color: #fff; | ||
} | ||
|
||
ul { | ||
list-style-type: none; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
li { | ||
margin: 5px 0; | ||
} | ||
|
||
button { | ||
color: #fff; | ||
padding: 10px 15px; | ||
border: none; | ||
border-radius: 3px; | ||
cursor: pointer; | ||
} | ||
|
||
.delete { | ||
background-color: #ff0000; | ||
} | ||
|
||
.join, .leave, .create { | ||
background-color: #0056b3; | ||
} | ||
|
||
.create { | ||
font-size: 15px; | ||
margin-top: 30px; | ||
} | ||
|
||
button:hover { | ||
opacity: 70%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
$(document).ready(function() { | ||
const baseUrl = window.location.origin; | ||
const patchMethod = "PATCH"; | ||
const token = $("meta[name='_csrf']").attr("content"); | ||
const header = $("meta[name='_csrf_header']").attr("content"); | ||
|
||
$(document).ajaxSend(function(e, xhr, options) { | ||
xhr.setRequestHeader(header, token); | ||
}); | ||
|
||
function makeAjaxCall(method, endpointUrl) { | ||
$.ajax({ | ||
type: method, | ||
url: baseUrl + endpointUrl | ||
}) | ||
.done(function () { | ||
window.location.reload(); | ||
}); | ||
} | ||
|
||
function getProjectID(elem) { | ||
return $(elem).parent().attr("project-id") | ||
} | ||
|
||
$('.delete').on("click", function() { | ||
const deleteEndpoint = "/deleteProject/" + getProjectID(this); | ||
makeAjaxCall("DELETE", deleteEndpoint); | ||
}); | ||
|
||
$('.join').on("click", function() { | ||
const joinEndpoint = "/project/" + getProjectID(this) + "/addStudent/" + $(this).attr("user-id"); | ||
makeAjaxCall(patchMethod, joinEndpoint); | ||
}); | ||
|
||
$('.leave').on("click", function() { | ||
const leaveEndpoint = "/project/" + getProjectID(this) + "/removeStudent/" + $(this).attr("user-id"); | ||
makeAjaxCall(patchMethod, leaveEndpoint); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Error</title> | ||
<style> | ||
body { | ||
margin-left: 15px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h1>Oops! An error occurred</h1> | ||
<p>We're sorry, but something went wrong.</p> | ||
<a href="/home">Go to homepage</a> | ||
</body> | ||
</html> |
Oops, something went wrong.