Browse Source

Loading theme automatically

main
Jesus 1 year ago
parent
commit
a3280ee7b5
6 changed files with 20 additions and 9 deletions
  1. +13
    -2
      src/main/java/com/jesuspinar/webserver/Manager.java
  2. +0
    -1
      src/main/resources/css/style.css
  3. +0
    -4
      src/main/resources/static/css/dark.css
  4. +4
    -0
      src/main/resources/static/css/light.css
  5. +1
    -1
      src/main/resources/templates/index.html
  6. +2
    -1
      src/main/resources/templates/time.html

+ 13
- 2
src/main/java/com/jesuspinar/webserver/Manager.java View File

@ -11,15 +11,26 @@ import java.time.format.DateTimeFormatter;
public class Manager {
@GetMapping({"/", "", "/index"})
public String welcome(Model model){
loadTheme(model);
model.addAttribute("mesage", "Hello");
return "index";
}
@GetMapping("/hour")
public String hour(Model model){
loadTheme(model);
return "time";
}
private void loadTheme(Model model) {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss");
model.addAttribute("dateTime", dtf.format(LocalDateTime.now()));
// model.addAttribute("bg", "dark");
return "time";
DateTimeFormatter hour = DateTimeFormatter.ofPattern("HH");
int h = Integer.parseInt(hour.format(LocalDateTime.now()));
String bg = "light";
if (h >= 20 || h <= 7){
bg = "dark";
}
model.addAttribute("background", bg);
}
}

+ 0
- 1
src/main/resources/css/style.css View File

@ -1 +0,0 @@
html{background: slategrey}

src/main/resources/static/css/style.css → src/main/resources/static/css/dark.css View File

@ -2,7 +2,3 @@ body{
background-color: slategrey;
color: white;
}
h1{
font-size: 4rem;
}

+ 4
- 0
src/main/resources/static/css/light.css View File

@ -0,0 +1,4 @@
body{
background-color: aliceblue;
color: dimgray;
}

+ 1
- 1
src/main/resources/templates/index.html View File

@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" media="all" href="/css/style.css">
<link rel="stylesheet" type="text/css" media="all" th:href="'/css/'+${background}+'.css'">
<title>Index</title>
</head>
<body>


+ 2
- 1
src/main/resources/templates/time.html View File

@ -4,7 +4,8 @@
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" media="all" href="/css/style.css">
<link rel="stylesheet" type="text/css" media="all" th:href="'/css/'+${background}+'.css'">
<title>Time</title>
</head>
<body>


Loading…
Cancel
Save