|
| 1 | +package org.woehlke.java.simpleworklist.domain.meso; |
| 2 | + |
| 3 | +import lombok.extern.slf4j.Slf4j; |
| 4 | +import org.springframework.beans.factory.annotation.Autowired; |
| 5 | +import org.springframework.stereotype.Controller; |
| 6 | +import org.springframework.ui.Model; |
| 7 | +import org.springframework.web.bind.annotation.ModelAttribute; |
| 8 | +import org.springframework.web.bind.annotation.PathVariable; |
| 9 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 10 | +import org.springframework.web.bind.annotation.RequestMethod; |
| 11 | +import org.woehlke.java.simpleworklist.domain.AbstractController; |
| 12 | +import org.woehlke.java.simpleworklist.domain.db.data.Context; |
| 13 | +import org.woehlke.java.simpleworklist.domain.db.data.Project; |
| 14 | +import org.woehlke.java.simpleworklist.domain.db.data.Task; |
| 15 | +import org.woehlke.java.simpleworklist.domain.meso.session.UserSessionBean; |
| 16 | +import org.woehlke.java.simpleworklist.domain.meso.taskworkflow.MoveTaskService; |
| 17 | + |
| 18 | +import javax.validation.constraints.NotNull; |
| 19 | + |
| 20 | +@Slf4j |
| 21 | +@Controller |
| 22 | +@RequestMapping(path = "/taskstate/task") |
| 23 | +public class TaskMoveController extends AbstractController { |
| 24 | + |
| 25 | + private final MoveTaskService moveTaskService; |
| 26 | + |
| 27 | + @Autowired |
| 28 | + public TaskMoveController(MoveTaskService moveTaskService) { |
| 29 | + this.moveTaskService = moveTaskService; |
| 30 | + } |
| 31 | + |
| 32 | + @RequestMapping(path = "/{taskId}/move/to/project/{projectId}", method = RequestMethod.GET) |
| 33 | + public final String moveTaskToAnotherProject( |
| 34 | + @NotNull @PathVariable("taskId") Task task, |
| 35 | + @NotNull @PathVariable("projectId") Project project, |
| 36 | + @NotNull @ModelAttribute("userSession") UserSessionBean userSession, |
| 37 | + Model model |
| 38 | + ) { |
| 39 | + task = moveTaskService.moveTaskToAnotherProject(task,project); |
| 40 | + userSession.setLastProjectId(project.getId()); |
| 41 | + model.addAttribute("userSession",userSession); |
| 42 | + model.addAttribute("dataPage", true); |
| 43 | + return task.getTaskState().getUrl(); |
| 44 | + } |
| 45 | + |
| 46 | + @RequestMapping(path = "/{taskId}/move/to/project/root", method = RequestMethod.GET) |
| 47 | + public final String moveTaskToRootProject( |
| 48 | + @NotNull @PathVariable("taskId") Task task, |
| 49 | + @NotNull @ModelAttribute("userSession") UserSessionBean userSession, |
| 50 | + Model model |
| 51 | + ) { |
| 52 | + task = moveTaskService.moveTaskToRootProject(task); |
| 53 | + userSession.setLastProjectId(0L); |
| 54 | + model.addAttribute("userSession",userSession); |
| 55 | + model.addAttribute("dataPage", true); |
| 56 | + return task.getTaskState().getUrl(); |
| 57 | + } |
| 58 | + |
| 59 | + @RequestMapping(path = "/{taskId}/move/to/taskstate/inbox", method = RequestMethod.GET) |
| 60 | + public final String moveTaskToInbox( |
| 61 | + @NotNull @PathVariable("taskId") Task task, |
| 62 | + @NotNull @ModelAttribute("userSession") UserSessionBean userSession, |
| 63 | + Model model |
| 64 | + ) { |
| 65 | + log.info("dragged and dropped "+task.getId()+" to inbox"); |
| 66 | + task = moveTaskService.moveTaskToInbox(task); |
| 67 | + model.addAttribute("userSession", userSession); |
| 68 | + model.addAttribute("dataPage", true); |
| 69 | + return task.getTaskState().getUrl(); |
| 70 | + } |
| 71 | + |
| 72 | + @RequestMapping(path = "/{taskId}/move/to/taskstate/today", method = RequestMethod.GET) |
| 73 | + public final String moveTaskToToday( |
| 74 | + @NotNull @PathVariable("taskId") Task task, |
| 75 | + @NotNull @ModelAttribute("userSession") UserSessionBean userSession, |
| 76 | + Model model |
| 77 | + ) { |
| 78 | + log.info("dragged and dropped "+task.getId()+" to today"); |
| 79 | + task = moveTaskService.moveTaskToToday(task); |
| 80 | + model.addAttribute("userSession", userSession); |
| 81 | + model.addAttribute("dataPage", true); |
| 82 | + return task.getTaskState().getUrl(); |
| 83 | + } |
| 84 | + |
| 85 | + @RequestMapping(path = "/{taskId}/move/to/taskstate/next", method = RequestMethod.GET) |
| 86 | + public final String moveTaskToNext( |
| 87 | + @NotNull @PathVariable("taskId") Task task, |
| 88 | + @NotNull @ModelAttribute("userSession") UserSessionBean userSession, |
| 89 | + Model model |
| 90 | + ) { |
| 91 | + log.info("dragged and dropped "+task.getId()+" to next"); |
| 92 | + task = moveTaskService.moveTaskToNext(task); |
| 93 | + model.addAttribute("userSession", userSession); |
| 94 | + model.addAttribute("dataPage", true); |
| 95 | + return task.getTaskState().getUrl(); |
| 96 | + } |
| 97 | + |
| 98 | + @RequestMapping(path = "/{taskId}/move/to/taskstate/waiting", method = RequestMethod.GET) |
| 99 | + public final String moveTaskToWaiting( |
| 100 | + @NotNull @PathVariable("taskId") Task task, |
| 101 | + @NotNull @ModelAttribute("userSession") UserSessionBean userSession, |
| 102 | + Model model |
| 103 | + ) { |
| 104 | + log.info("dragged and dropped "+task.getId()+" to waiting"); |
| 105 | + task = moveTaskService.moveTaskToWaiting(task); |
| 106 | + model.addAttribute("userSession", userSession); |
| 107 | + model.addAttribute("dataPage", true); |
| 108 | + return task.getTaskState().getUrl(); |
| 109 | + } |
| 110 | + |
| 111 | + @RequestMapping(path = "/{taskId}/move/to/taskstate/someday", method = RequestMethod.GET) |
| 112 | + public final String moveTaskToSomeday( |
| 113 | + @NotNull @PathVariable("taskId") Task task, |
| 114 | + @NotNull @ModelAttribute("userSession") UserSessionBean userSession, |
| 115 | + Model model |
| 116 | + ) { |
| 117 | + log.info("dragged and dropped "+task.getId()+" to someday"); |
| 118 | + task = moveTaskService.moveTaskToSomeday(task); |
| 119 | + model.addAttribute("userSession", userSession); |
| 120 | + model.addAttribute("dataPage", true); |
| 121 | + return task.getTaskState().getUrl(); |
| 122 | + } |
| 123 | + |
| 124 | + @RequestMapping(path = "/{taskId}/move/to/taskstate/focus", method = RequestMethod.GET) |
| 125 | + public final String moveTaskToFocus( |
| 126 | + @NotNull @PathVariable("taskId") Task task, |
| 127 | + @NotNull @ModelAttribute("userSession") UserSessionBean userSession, |
| 128 | + Model model |
| 129 | + ) { |
| 130 | + log.info("dragged and dropped "+task.getId()+" to focus"); |
| 131 | + task = moveTaskService.moveTaskToFocus(task); |
| 132 | + model.addAttribute("userSession", userSession); |
| 133 | + model.addAttribute("dataPage", true); |
| 134 | + return task.getTaskState().getUrl(); |
| 135 | + } |
| 136 | + |
| 137 | + @RequestMapping(path = "/{taskId}/move/to/taskstate/completed", method = RequestMethod.GET) |
| 138 | + public final String moveTaskToCompleted( |
| 139 | + @NotNull @PathVariable("taskId") Task task, |
| 140 | + @NotNull @ModelAttribute("userSession") UserSessionBean userSession, |
| 141 | + Model model |
| 142 | + ) { |
| 143 | + log.info("dragged and dropped "+task.getId()+" to completed"); |
| 144 | + task = moveTaskService.moveTaskToCompleted(task); |
| 145 | + model.addAttribute("userSession", userSession); |
| 146 | + model.addAttribute("dataPage", true); |
| 147 | + return task.getTaskState().getUrl(); |
| 148 | + } |
| 149 | + |
| 150 | + @RequestMapping(path = "/{taskId}/move/to/taskstate/trash", method = RequestMethod.GET) |
| 151 | + public final String moveTaskToTrash( |
| 152 | + @NotNull @PathVariable("taskId") Task task, |
| 153 | + @NotNull @ModelAttribute("userSession") UserSessionBean userSession, |
| 154 | + Model model |
| 155 | + ) { |
| 156 | + log.info("dragged and dropped "+task.getId()+" to trash"); |
| 157 | + task = moveTaskService.moveTaskToTrash(task); |
| 158 | + model.addAttribute("userSession", userSession); |
| 159 | + model.addAttribute("dataPage", true); |
| 160 | + return task.getTaskState().getUrl(); |
| 161 | + } |
| 162 | + |
| 163 | + @RequestMapping(path = "/completed/move/to/trash", method = RequestMethod.GET) |
| 164 | + public final String moveAllCompletedToTrash( |
| 165 | + @ModelAttribute("userSession") UserSessionBean userSession, |
| 166 | + Model model |
| 167 | + ) { |
| 168 | + Context context = super.getContext(userSession); |
| 169 | + moveTaskService.moveAllCompletedToTrash(context); |
| 170 | + model.addAttribute("userSession", userSession); |
| 171 | + model.addAttribute("dataPage", true); |
| 172 | + return "redirect:/taskstate/trash"; |
| 173 | + } |
| 174 | + |
| 175 | + @RequestMapping(path = "/trash/empty", method = RequestMethod.GET) |
| 176 | + public final String emptyTrash( |
| 177 | + @ModelAttribute("userSession") UserSessionBean userSession, |
| 178 | + Model model |
| 179 | + ) { |
| 180 | + Context context = super.getContext(userSession); |
| 181 | + moveTaskService.emptyTrash(context); |
| 182 | + model.addAttribute("userSession", userSession); |
| 183 | + model.addAttribute("dataPage", true); |
| 184 | + return "redirect:/taskstate/trash"; |
| 185 | + } |
| 186 | + |
| 187 | +} |
0 commit comments