Skip to content

Commit

Permalink
Add 'add idea' button to project page
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomigueltech committed Sep 3, 2020
1 parent 1e8610e commit 4e5a947
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 86 deletions.
70 changes: 0 additions & 70 deletions src/main/java/com/plainplanner/controller/IdeaController.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,76 +48,6 @@ public class IdeaController {
@Autowired
private IdeaService ideaService;

@RequestMapping("/addNewItem/{referrer}/{referrerId}")
public ModelAndView addNewItem(@PathVariable("referrer") String referrer, @PathVariable("referrerId") Long referrerId, @ModelAttribute("newItem") @Valid ItemDTO dto, Model model) {
ModelAndView resultingPage = new ModelAndView();

Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (!(auth instanceof AnonymousAuthenticationToken)) {
User currentUser = userService.getUserByUsername(auth.getName());
List<Idea> upcomingTasks = userService.getUpcomingTasks(currentUser);
resultingPage.addObject("upcoming", upcomingTasks);

if (dto.getTitle().isEmpty()) return resultingPage;

switch (dto.getItemType()) {
case "idea":
Idea newIdea = new Idea(dto.getTitle(), dto.getItemType());
if (dto.getContent() != null) {
newIdea.setDescription(dto.getContent());
}
if (dto.getBucketID() != null) {
Bucket bucket = bucketService.getBucket(dto.getBucketID());
bucketService.addIdea(bucket, newIdea);
} else {
bucketService.addIdea(currentUser.getDefaultBucket(), newIdea);
}
if (dto.getProjectID() != null) {
Project project = projectService.getProject(dto.getProjectID());
projectService.addIdea(project, newIdea);
}
break;
case "project":
Project newProject = new Project(dto.getTitle());
newProject.setDeadline(dto.getDate());
userService.addProject(currentUser, newProject);
break;
case "task":
Idea newTask = new Idea(dto.getTitle(), dto.getItemType());
if (dto.getContent() != null) {
newTask.setDescription(dto.getContent());
}
newTask.setDeadline(dto.getDate());
if (dto.getBucketID() != null) {
Bucket bucket = bucketService.getBucket(dto.getBucketID());
bucketService.addIdea(bucket, newTask);
} else {
bucketService.addIdea(currentUser.getDefaultBucket(), newTask);
}
if (dto.getProjectID() != null) {
Project project = projectService.getProject(dto.getProjectID());
projectService.addIdea(project, newTask);
}
break;
case "note":
TextNote newNote = new TextNote(dto.getTitle());
userService.addTextNote(currentUser, newNote);
break;
}
resultingPage.addObject("added", dto.getItemType());

if (referrer.equals("dashboard")) {
resultingPage.setViewName("redirect:/dashboard");
} else {
resultingPage.setViewName("redirect:/" + referrer + "/" + referrerId);
}
} else {
resultingPage.setViewName("redirect:/signin");
}

return resultingPage;
}

@RequestMapping("/updateIdea/{referrer}/{referrerId}/{ideaId}")
public String updateIdea(@PathVariable("referrer") String referrer, @PathVariable("referrerId") Long referrerId, @PathVariable("ideaId") Long ideaId, @ModelAttribute("item") @Valid ItemDTO dto, Model model) {
if (dto == null) return "/dashboard";
Expand Down
131 changes: 131 additions & 0 deletions src/main/webapp/WEB-INF/views/addIdea.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
<script src="https://kit.fontawesome.com/a4e465149a.js" crossorigin="anonymous"></script>
<link rel="stylesheet" type="text/css" href="/resources/css/bootstrap.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.min.css" integrity="sha512-mSYUmp1HYZDFaVKK//63EcZq4iFWFjxSL+Z3T/aCt4IO9Cejm03q3NKKYN6pFQzY0SBOr8h+eCIAZHPXcpZaNw==" crossorigin="anonymous" />
<link rel="stylesheet" type="text/css" href="/resources/css/style.css">
<title>PlainPlanner - Add Idea</title>
</head>
<body>
<div id="wrapper">
<nav class="navbar navbar-expand-md navbar-dark bg-primary p-0 m-0 position-relative">
<a href="/index" class="navbar-brand ml-5 p-0 text-dark" style="font-size: 2rem;">PlainPlanner</a>
<button class="navbar-toggler" data-toggle="collapse" data-target="#navbarCollapse">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="nav navbar-nav ml-auto ">
<li class="nav-item">
<a href="/dashboard" class="nav-link py-3 px-2">Dashboard</a>
</li>
<li class="nav-item">
<a href="/projects" class="nav-link py-3 px-2">Projects</a>
</li>
<li class="nav-item">
<a href="/buckets" class="nav-link py-3 px-2">Buckets</a>
</li>
<li class="nav-item">
<a href="/notes" class="nav-link py-3 px-2">Notes</a>
</li>
<li class="nav-item dropdown" style="min-width:185px;">
<a class="nav-link dropdown-toggle py-3 px-2" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" style="text-transform: capitalize;">
<i class="fas fa-user-circle mx-2 d-none d-md-inline"></i>
<security:authorize access="isAuthenticated()">
<security:authentication property="principal.username" />
</security:authorize>
</a>
<div class="dropdown-menu m-0 rounded-0 border-top-0" style="right:0%; left:auto; min-width:185px;">
<a class="dropdown-item" href="/statistics">Statistics</a>
<a class="dropdown-item" href="/settings">Settings</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="/about">About PlainPlanner</a>
<form action="/signout" method="post">
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
<button type="submit" class="btn btn-link dropdown-item py-0">Sign Out</button>
</form>
</div>
</li>
</ul>
</div>
</nav>

<section id="statistics-section" class="mb-5 mt-3">
<div class="container">
<div class="card">
<div class="card-header text-white text-center" style="background-color: #3A3535">
<h2>Create New Idea</h2>
</div>
<div class="card-body">
<form:form action="/addNewItem/${referrer}/${referrerId}" method="post" modelAttribute="item">
<form:hidden path="itemType" value="idea" />
<c:choose>
<c:when test="${referrer == 'bucket'}">
<form:hidden path="bucketID" value="${referrerId}" />
</c:when>
<c:otherwise>
<form:hidden path="projectID" value="${referrerId}" />
</c:otherwise>
</c:choose>
<div class="row my-2">
<div class="input-group justify-content-center">
<form:label class="col-4 col-md-2 col-form-label" path="title">Title</form:label>
<div class="col-8 col-md-4">
<form:input type="text" class="login-control form-control" placeholder="Enter your idea here" path="title"></form:input>
</div>
</div>
</div>
<div class="row my-2">
<div class="input-group justify-content-center">
<form:label class="col-4 col-md-2 col-form-label" path="content">Description</form:label>
<div class="col-8 col-md-4">
<form:input type="text" class="login-control form-control" placeholder="Enter a description for your idea" path="content"></form:input>
</div>
</div>
</div>
<div class="row mt-4 justify-content-center">
<div class="col-6 col-md-4 d-flex justify-content-center align-items-center">
<form:button type="submit" class="btn btn-primary mx-2">Add</form:button>
<a href="/${referralURL}" class="mx-2">Cancel</a>
</div>
</div>
</form:form>
</div>
</div>
</div>
</section>

<c:import url="/resources/footer.jsp" />
</div>

<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js" integrity="sha512-T/tUfKSV1bihCnd+MxKD0Hm1uBBroVYBOYSk1knyvQ9VyZJpc/ALb4P0r6ubwVPSGB2GvjeoMAJJImBG12TiaQ==" crossorigin="anonymous"></script>
<script>
$(document).ready(function(){
var date_input=$('input[name="date"]'); //our date input has the name "date"
var container=$('.bootstrap-iso form').length>0 ? $('.bootstrap-iso form').parent() : "body";
var options={
format: 'mm/dd/yyyy',
container: container,
todayHighlight: true,
autoclose: true,
};
date_input.datepicker(options);
date_input.datepicker('setDate', 'now');
})
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion src/main/webapp/WEB-INF/views/bucket.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
<c:when test="${not empty ideas}">
<c:forEach items="${ideas}" var="idea">
<li class="list-group-item">
<h4><a href="/bucketIdea/${bucket.id}/${idea.id}">${idea.title}</a></h4>
<h4><a href="/idea/bucket/${bucket.id}/${idea.id}">${idea.title}</a></h4>
<c:if test="${idea.isTask()}">
<h6 class="mb-0">Due: ${idea.deadline}</h6>
</c:if>
Expand Down
8 changes: 4 additions & 4 deletions src/main/webapp/WEB-INF/views/dashboard.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
</c:if>
<div class="card">
<div class="card-body pb-2 pt-3" style="border-bottom: 10px solid #3A3535;">
<form:form action="/addNewItem" method="post" modelAttribute="newItem">
<form:form action="/addNewItem/dashboard/1" method="post" modelAttribute="newItem">
<div class="input-group">
<form:input type="text" class="form-control" placeholder="Record a thought.." path="title"></form:input>
<form:input class="form-control text-center" id="date" path="date" placeholder="MM/DD/YYY" type="text" style="max-width: 125px;"></form:input>
Expand Down Expand Up @@ -106,19 +106,19 @@
<ul class="list-group list-group-flush">
<c:forEach items="${upcoming}" var="item">
<li class="list-group-item">
<h4><a href="/dashboardIdea/${item.id}">${item.title}</a></h4>
<h4><a href="/idea/dashboard/1/${item.id}">${item.title}</a></h4>
<h6>Due: ${item.deadline}</h6>
<c:if test="${item.isComplete()}">
<h6 class="text-alert">Completed</h6>
</c:if>
<h6 class="card-subtitle text-muted">${item.description }</h6>
<c:if test="${!item.isComplete()}">
<a class="btn btn-primary btn-sm mt-3 text-white" href="/complete/${item.id}">
<a class="btn btn-primary btn-sm mt-3 text-white" href="/complete/dashboard/dashboard/1/${item.id}">
Complete
</a>
</c:if>

<a class="btn btn-primary btn-sm mt-3 text-white" href="/deleteIdea/${item.id}">Delete</a>
<a class="btn btn-primary btn-sm mt-3 text-white" href="/deleteIdea/dashboard/1/${item.id}">Delete</a>
</li>
</c:forEach>
</ul>
Expand Down
16 changes: 8 additions & 8 deletions src/main/webapp/WEB-INF/views/idea.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
<script src="https://kit.fontawesome.com/a4e465149a.js" crossorigin="anonymous"></script>
<link rel="stylesheet" type="text/css" href="../resources/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="/resources/css/bootstrap.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.min.css" integrity="sha512-mSYUmp1HYZDFaVKK//63EcZq4iFWFjxSL+Z3T/aCt4IO9Cejm03q3NKKYN6pFQzY0SBOr8h+eCIAZHPXcpZaNw==" crossorigin="anonymous" />
<link rel="stylesheet" type="text/css" href="../resources/css/style.css">
<link rel="stylesheet" type="text/css" href="/resources/css/style.css">
<title>PlainPlanner - Edit Item</title>
</head>
<body>
Expand Down Expand Up @@ -68,7 +68,7 @@
<h2>Viewing "${idea.title}"</h2>
</div>
<div class="card-body">
<form:form action="/updateIdea" method="post" modelAttribute="item">
<form:form action="/updateIdea/${referralURL}/${idea.id}" method="post" modelAttribute="item">
<form:hidden path="id" value="${idea.id}" />
<div class="row my-2">
<div class="input-group justify-content-center">
Expand Down Expand Up @@ -143,22 +143,22 @@
<form:input class="form-control text-center" id="date" path="date" placeholder="MM/DD/YYY" type="text" style="max-width: 125px;"></form:input>
</c:when>
<c:otherwise>
<a href="/addIdeaDeadline/${idea.id}" class="btn btn-outline-primary">Add deadline</a>
<a href="/addIdeaDeadline/${referralURL}/${idea.id}" class="btn btn-outline-primary">Add deadline</a>
</c:otherwise>
</c:choose> </div>
</div>
</div>
<div class="row my-3 justify-content-center">
<div class="col-6 col-md-4">
<div class="input-group d-flex justify-content-center align-items-center">
<c:url value="/complete/{$idea.id}" var="completeUrl"/>
<c:url value="/complete/idea/${referralURL}/${idea.id}" var="completeUrl"/>
<c:if test="${idea.isComplete()}">
<a class="btn btn-warning disabled">
Item Completed
</a>
</c:if>
<c:if test="${!idea.isComplete()}">
<a class="btn btn-warning" href="/complete/${idea.id}">
<a class="btn btn-warning" href="/complete/idea/${referralURL}/${idea.id}">
Complete Item
</a>
</c:if>
Expand All @@ -168,8 +168,8 @@
<div class="row justify-content-center mt-4">
<div class="col-4 d-flex justify-content-center align-items-center">
<form:button type="submit" class="btn btn-primary mx-sm-2">Save</form:button>
<a class="btn btn-primary mx-sm-2" href="/deleteIdea/${idea.id}">Delete</a>
<a href="${redirectURL}" class="mx-sm-2">Cancel</a>
<a class="btn btn-primary mx-sm-2" href="/deleteIdea/${referralURL}/${idea.id}">Delete</a>
<a href="/${redirectURL}" class="mx-sm-2">Cancel</a>
</div>
</div>
</form:form>
Expand Down
8 changes: 5 additions & 3 deletions src/main/webapp/WEB-INF/views/project.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,24 @@
<div class="card-body">
<div class="row">
<div class="col">
<h4 class="card-title">Tasks & Ideas</h4>
<h4 class="card-title">Tasks & Ideas
<a class="btn btn-primary btn-sm mt-3" href="/addIdea/project/${project.id}">Add New Idea</a>
</h4>
<hr>
<ul class="list-group list-group-flush">
<c:choose>
<c:when test="${not empty ideas}">
<c:forEach items="${ideas}" var="idea">
<li class="list-group-item">
<h4><a href="/projectIdea/${project.id}/${idea.id}">${idea.title}</a></h4>
<h4><a href="/idea/project/${project.id}/${idea.id}">${idea.title}</a></h4>
<c:if test="${idea.isTask()}">
<h6 class="mb-0">Due: ${idea.deadline}</h6>
</c:if>
<c:if test="${idea.isComplete()}">
<h6 class="text-warning font-weight-bold">Completed</h6>
</c:if>
<h6 class="card-subtitle text-muted mt-2">${idea.description }</h6>
<a class="btn btn-primary btn-sm mt-3" href="/deleteIdea/${idea.id}">Delete</a>
<a class="btn btn-primary btn-sm mt-3" href="/deleteIdea/project/${project.id}/${idea.id}">Delete</a>
</li>
</c:forEach>
</c:when>
Expand Down

0 comments on commit 4e5a947

Please sign in to comment.