Skip to content

Commit

Permalink
Toasts for LRS settings events (Closes #39)
Browse files Browse the repository at this point in the history
  • Loading branch information
Galaxy102 committed Feb 16, 2022
1 parent 3c19c6d commit 0555a23
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import org.springframework.web.servlet.view.RedirectView;

import java.util.Optional;
import java.util.UUID;
Expand Down Expand Up @@ -76,9 +78,10 @@ public ModelAndView showLrsConnections(@RequestParam(name = "active_only") Optio
* @param lrsUuid UUID of the Connection to deactivate
*/
@PostMapping(LrsMavController.BASE_URL + "/deactivate")
public ModelAndView deleteLrsConnection(@RequestParam(name = "lrs_uuid") UUID lrsUuid) {
public RedirectView deleteLrsConnection(@RequestParam(name = "lrs_uuid") UUID lrsUuid, RedirectAttributes attributes) {
this.lrsService.deactivateConnection(lrsUuid);
return new ModelAndView("redirect:/ui/manage/lrs/");
attributes.addAttribute("deactivate", this.lrsService.getConnection(lrsUuid).getFriendlyName());
return new RedirectView(".");
}

/**
Expand All @@ -87,9 +90,10 @@ public ModelAndView deleteLrsConnection(@RequestParam(name = "lrs_uuid") UUID lr
* @param lrsUuid UUID of the Connection to reactivate
*/
@PostMapping(LrsMavController.BASE_URL + "/reactivate")
public ModelAndView reactivateLrsConnection(@RequestParam(name = "lrs_uuid") UUID lrsUuid) {
public RedirectView reactivateLrsConnection(@RequestParam(name = "lrs_uuid") UUID lrsUuid, RedirectAttributes attributes) {
this.lrsService.activateConnection(lrsUuid);
return new ModelAndView("redirect:/ui/manage/lrs/");
attributes.addAttribute("reactivate", this.lrsService.getConnection(lrsUuid).getFriendlyName());
return new RedirectView(".");
}

/**
Expand All @@ -112,9 +116,10 @@ public ModelAndView showEditLrsConnection(@RequestParam(name = "lrs_uuid") UUID
* @param data Transfer object containing the new details of the LRS Connection
*/
@PostMapping(LrsMavController.BASE_URL + "/edit")
public ModelAndView editLrsConnection(@Validated LrsConnectionTO data) {
public RedirectView editLrsConnection(@Validated LrsConnectionTO data, RedirectAttributes attributes) {
this.lrsService.updateConnection(data);
return new ModelAndView("redirect:/ui/manage/lrs/");
attributes.addAttribute("edit", data.getName());
return new RedirectView(".");
}

/**
Expand All @@ -133,8 +138,9 @@ public ModelAndView showAddLrsConnection() {
* @param data Transfer object containing the new details of the LRS Connection
*/
@PostMapping(LrsMavController.BASE_URL + "/add")
public ModelAndView addLrsConnection(@Validated LrsConnectionTO data) {
public RedirectView addLrsConnection(@Validated LrsConnectionTO data, RedirectAttributes attributes) {
this.lrsService.createConnection(data);
return new ModelAndView("redirect:/ui/manage/lrs/");
attributes.addAttribute("create", data.getName());
return new RedirectView(".");
}
}
52 changes: 52 additions & 0 deletions src/main/resources/templates/bootstrap/lrs/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,58 @@ <h3 th:text="${connection.getName()}"></h3>
</div>
</div>
</div>
<!-- Create Toast -->
<div class="position-absolute top-0 start-0 w-100" th:if="${param.get('create')}">
<div aria-live="polite" aria-atomic="true" class="d-flex justify-content-center align-items-center">
<div class="toast-container w-50 d-flex mt-3">
<div class="toast bg-success flex-fill" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-body fs-4 text-white text-center">
Activated&nbsp;<span th:text="${param.get('create')}"></span>.<br />
Refresh the application for status indicators to update.
</div>
</div>
</div>
</div>
</div>
<!-- Edit Toast -->
<div class="position-absolute top-0 start-0 w-100" th:if="${param.get('edit')}">
<div aria-live="polite" aria-atomic="true" class="d-flex justify-content-center align-items-center">
<div class="toast-container w-50 d-flex mt-3">
<div class="toast bg-success flex-fill" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-body fs-4 text-white text-center">
Edited&nbsp;<span th:text="${param.get('edit')}"></span>.<br />
Refresh the application for status indicators to update.
</div>
</div>
</div>
</div>
</div>
<!-- Reactivate Toast -->
<div class="position-absolute top-0 start-0 w-100" th:if="${param.get('reactivate')}">
<div aria-live="polite" aria-atomic="true" class="d-flex justify-content-center align-items-center">
<div class="toast-container w-50 d-flex mt-3">
<div class="toast bg-success flex-fill" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-body fs-4 text-white text-center">
Reactivated&nbsp;<span th:text="${param.get('reactivate')}"></span>.<br />
Refresh the application for status indicators to update.
</div>
</div>
</div>
</div>
</div>
<!-- Deactivate Toast -->
<div class="position-absolute top-0 start-0 w-100" th:if="${param.get('deactivate')}">
<div aria-live="polite" aria-atomic="true" class="d-flex justify-content-center align-items-center">
<div class="toast-container w-50 d-flex mt-3">
<div class="toast bg-danger flex-fill" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-body fs-4 text-white text-center">
Deactivated&nbsp;<span th:text="${param.get('deactivate')}"></span>.<br />
Refresh the application for status indicators to update.
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

0 comments on commit 0555a23

Please sign in to comment.