#14 Dark mode stays on the same page
This commit is contained in:
@@ -16,6 +16,7 @@ import de.financer.util.ControllerUtils;
|
||||
import de.financer.util.TransactionUtils;
|
||||
import org.apache.commons.collections4.IterableUtils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
@@ -24,6 +25,10 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -201,10 +206,23 @@ public class AccountController {
|
||||
}
|
||||
|
||||
@GetMapping("/toggleDarkMode")
|
||||
public String toggleDarkMode(Model model) {
|
||||
public String toggleDarkMode(Model model, HttpServletRequest httpServletRequest) {
|
||||
String navigateTo = "/accountOverview";
|
||||
|
||||
try {
|
||||
final String fullPath = new URL(httpServletRequest.getHeader("referer")).toURI().getPath();
|
||||
|
||||
// FIXME - will break if the app is deployed on http://host/a/b/financer instead of http://host/financer
|
||||
final String tmpPath = StringUtils.removeStart(fullPath, "/");
|
||||
navigateTo = tmpPath.substring(tmpPath.indexOf("/"));
|
||||
}catch(MalformedURLException | URISyntaxException e) {
|
||||
// TODO
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
this.financerConfig.setDarkMode(!this.financerConfig.isDarkMode());
|
||||
|
||||
return "redirect:/accountOverview";
|
||||
return "redirect:" + navigateTo;
|
||||
}
|
||||
|
||||
// ---------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user