mirror of https://github.com/bvn13/JIrcBot.git
implemented logs view as html
parent
19ff4520ef
commit
da1cacd209
|
@ -109,6 +109,10 @@
|
|||
<orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:1.3.9" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.http-client:google-http-client-jackson2:1.23.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.guava:guava-jdk5:17.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.modelmapper:modelmapper:1.1.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.webjars:jquery:3.2.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.webjars:bootstrap:3.3.7-1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.webjars:font-awesome:4.7.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.2.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.2.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
|
||||
|
|
|
@ -5,7 +5,7 @@ After=network.target
|
|||
[Service]
|
||||
User=bvn13
|
||||
WorkingDirectory=/srv/jircbot
|
||||
ExecStart=/usr/bin/java -jar /srv/jircbot/jircbot-1.1.4.jar
|
||||
ExecStart=/usr/bin/java -jar /srv/jircbot/jircbot-1.1.5.jar
|
||||
SuccessExitStatus=143
|
||||
|
||||
[Install]
|
||||
|
|
26
pom.xml
26
pom.xml
|
@ -6,7 +6,7 @@
|
|||
|
||||
<groupId>ru.bvn13</groupId>
|
||||
<artifactId>jircbot</artifactId>
|
||||
<version>1.1.5</version>
|
||||
<version>1.1.6</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
|
||||
|
@ -144,6 +144,30 @@
|
|||
<version>v1-rev57-1.23.0</version>
|
||||
</dependency>
|
||||
|
||||
<!--Mapper-->
|
||||
<dependency>
|
||||
<groupId>org.modelmapper</groupId>
|
||||
<artifactId>modelmapper</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
|
||||
<!--webjars-->
|
||||
<dependency>
|
||||
<groupId>org.webjars</groupId>
|
||||
<artifactId>jquery</artifactId>
|
||||
<version>3.2.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.webjars</groupId>
|
||||
<artifactId>bootstrap</artifactId>
|
||||
<version>3.3.7-1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.webjars</groupId>
|
||||
<artifactId>font-awesome</artifactId>
|
||||
<version>4.7.0</version>
|
||||
</dependency>
|
||||
|
||||
<!--logging-->
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package ru.bvn13.jircbot.database.entities.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Created by bvn13 on 10.03.2018.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public abstract class BaseDTO {
|
||||
|
||||
private final SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
|
||||
|
||||
private Long id;
|
||||
private Date dtCreated;
|
||||
private Date dtUpdated;
|
||||
|
||||
public String getDtCreatedStr() {
|
||||
return DATE_FORMATTER.format(dtCreated);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package ru.bvn13.jircbot.database.entities.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* Created by bvn13 on 10.03.2018.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class IrcMessageDTO extends BaseDTO {
|
||||
|
||||
private String serverHost;
|
||||
private String channelName;
|
||||
private String username;
|
||||
private String message;
|
||||
|
||||
public boolean isUserSet() {
|
||||
return username != null && !username.isEmpty();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package ru.bvn13.jircbot.utilities;
|
||||
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.modelmapper.convention.MatchingStrategies;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Raysmond<i@raysmond.com>
|
||||
*/
|
||||
public class DTOUtil {
|
||||
|
||||
private static ModelMapper MAPPER = null;
|
||||
|
||||
private static ModelMapper getMapper(){
|
||||
if(MAPPER == null){
|
||||
MAPPER = new ModelMapper();
|
||||
MAPPER.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
|
||||
}
|
||||
|
||||
return MAPPER;
|
||||
}
|
||||
|
||||
public static <S, T> T map(S source, Class<T> targetClass) {
|
||||
return getMapper().map(source, targetClass);
|
||||
}
|
||||
|
||||
public static <S, T> void mapTo(S source, T dist) {
|
||||
getMapper().map(source, dist);
|
||||
}
|
||||
|
||||
public static <S, T> List<T> mapList(List<S> source, Class<T> targetClass) {
|
||||
List<T> list = new ArrayList<>();
|
||||
for (S s : source) {
|
||||
list.add(getMapper().map(s, targetClass));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
|
@ -5,10 +5,16 @@ import org.springframework.stereotype.Controller;
|
|||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.bvn13.jircbot.database.entities.IrcMessage;
|
||||
import ru.bvn13.jircbot.database.entities.dto.IrcMessageDTO;
|
||||
import ru.bvn13.jircbot.database.services.IrcMessageService;
|
||||
import ru.bvn13.jircbot.utilities.DTOUtil;
|
||||
import ru.bvn13.jircbot.utilities.DateTimeUtility;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -28,15 +34,63 @@ public class IrcLogController {
|
|||
|
||||
|
||||
@RequestMapping(value = "/{serverHost:.+}/{day}", method = RequestMethod.GET)
|
||||
public String index(@PathVariable String serverHost, @RequestParam(name = "channel") String channelName, @PathVariable String day, Model model) {
|
||||
model.addAttribute("serverHost", serverHost);
|
||||
model.addAttribute("channelName", channelName);
|
||||
model.addAttribute("day", day);
|
||||
public String index(@PathVariable String serverHost, @RequestParam(name = "channel") String channelName, @PathVariable String day, Model model) throws Exception {
|
||||
prepareModel(model, serverHost, channelName, day);
|
||||
return "irclog";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{serverHost:.+}", method = RequestMethod.GET)
|
||||
public String index(@PathVariable String serverHost, @RequestParam(name = "channel") String channelName, Model model) throws Exception {
|
||||
prepareModel(model, serverHost, channelName, DATE_READER.format(new Date()));
|
||||
return "irclog";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/text/{serverHost:.+}/{day}", method = RequestMethod.GET, produces = "plain/text; charset=utf-8")
|
||||
public @ResponseBody String indexText(@PathVariable String serverHost, @RequestParam(name = "channel") String channelName, @PathVariable String day, Model model) throws Exception {
|
||||
return renderAsText(serverHost, channelName, day);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/text/{serverHost:.+}", method = RequestMethod.GET, produces = "plain/text; charset=utf-8")
|
||||
public @ResponseBody String indexText(@PathVariable String serverHost, @RequestParam(name = "channel") String channelName, Model model) throws Exception {
|
||||
return renderAsText(serverHost, channelName, DATE_READER.format(new Date()));
|
||||
}
|
||||
|
||||
|
||||
private void prepareModel(Model model, String serverHost, String channelName, String day) throws Exception {
|
||||
model.addAttribute("serverHost", serverHost);
|
||||
model.addAttribute("day", day);
|
||||
|
||||
Date date = null;
|
||||
try {
|
||||
date = DATE_READER.parse(day);
|
||||
} catch (ParseException e) {
|
||||
throw new Exception("unknown date");
|
||||
}
|
||||
|
||||
LocalDateTime paramDay = DateTimeUtility.dateToLocalDateTime(date);
|
||||
Date prevDay = DateTimeUtility.localDateTimeToDate(paramDay.minusDays(1));
|
||||
Date nextDay = DateTimeUtility.localDateTimeToDate(paramDay.plusDays(1));
|
||||
|
||||
model.addAttribute("prevDay", DATE_READER.format(prevDay));
|
||||
model.addAttribute("nextDay", DATE_READER.format(nextDay));
|
||||
|
||||
List<IrcMessage> messages = ircMessageService.getMessagesOfDay(serverHost, channelName, date);
|
||||
if (messages.size() == 0) {
|
||||
model.addAttribute("channelNameStr", channelName);
|
||||
} else {
|
||||
model.addAttribute("channelNameStr", messages.get(0).getChannelName());
|
||||
}
|
||||
model.addAttribute("channelName", channelName);
|
||||
|
||||
List<IrcMessageDTO> dtos = new ArrayList<>();
|
||||
messages.forEach(message -> {
|
||||
dtos.add(DTOUtil.map(message, IrcMessageDTO.class));
|
||||
});
|
||||
|
||||
model.addAttribute("messages", dtos);
|
||||
}
|
||||
|
||||
private String renderAsText(String serverHost, String channelName, String day) throws Exception {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
Date date = null;
|
||||
|
@ -49,7 +103,11 @@ public class IrcLogController {
|
|||
List<IrcMessage> messages = ircMessageService.getMessagesOfDay(serverHost, channelName, date);
|
||||
|
||||
sb.append("SERVER: "+serverHost+"\n");
|
||||
sb.append("CHANNEL: "+channelName+"\n");
|
||||
if (messages.size() == 0) {
|
||||
sb.append("CHANNEL: "+channelName+"\n");
|
||||
} else {
|
||||
sb.append("CHANNEL: "+messages.get(0).getChannelName()+"\n");
|
||||
}
|
||||
sb.append("DATE: "+day+"\n");
|
||||
|
||||
sb.append("\n");
|
||||
|
@ -65,7 +123,4 @@ public class IrcLogController {
|
|||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ name: jircbot
|
|||
config: config.json
|
||||
|
||||
server:
|
||||
port: 8001
|
||||
port: 8002
|
||||
|
||||
spring:
|
||||
# for PostgreSQL
|
||||
|
|
|
@ -3,11 +3,59 @@
|
|||
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<title>Hello</title>
|
||||
<title th:text="|${day} - ${channelName} on ${serverHost}|"></title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<link rel="stylesheet" type="text/css" th:href="@{/webjars/bootstrap/3.3.7-1/css/bootstrap.min.css}" href="webjars/bootstrap/3.3.7-1/css/bootstrap.min.css" />
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="container">
|
||||
|
||||
<h1 th:text="|Server: ${serverHost}|"></h1>
|
||||
<h3 th:text="|Channel: ${channelNameStr}|"></h3>
|
||||
<h3 th:text="|Date: ${day}|"></h3>
|
||||
|
||||
<p>
|
||||
<div class="btn-toolbar">
|
||||
<a class="btn btn-default" th:href="@{'/logs/'+${serverHost}+'/'+${prevDay}+'?channel='+${channelName}}" th:text="${prevDay}"></a>
|
||||
<a class="btn btn-default" th:href="@{'/logs/'+${serverHost}+'/'+${nextDay}+'?channel='+${channelName}}" th:text="${nextDay}"></a>
|
||||
</div>
|
||||
</p>
|
||||
|
||||
<div class="irc-messages">
|
||||
|
||||
<table class="table table-hover table-condensed">
|
||||
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Date</th>
|
||||
<th>Username</th>
|
||||
<th>Message</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="msg : ${messages}">
|
||||
|
||||
<div th:if="${msg.isUserSet()}">
|
||||
<td class="col-sm-2 col-md-2 col-lg-2" th:text="${msg.getDtCreatedStr()}"></td>
|
||||
<td class="col-sm-2 col-md-2 col-lg-2" th:text="${msg.username}"></td>
|
||||
<td class="col-sm-8 col-md-8 col-lg-8" th:text="${msg.message}"></td>
|
||||
</div>
|
||||
<div th:if="${!msg.isUserSet()}">
|
||||
<td class="col-sm-2 col-md-2 col-lg-2" th:text="${msg.getDtCreatedStr()}"></td>
|
||||
<td class="col-sm-10 col-md-10 col-lg-10" colspan="2"><i th:text="${msg.message}"></i></td>
|
||||
</div>
|
||||
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" th:src="@{/webjars/jquery/3.3.1-1/jquery.min.js}"></script>
|
||||
<script type="text/javascript" th:src="@{/webjars/bootstrap/3.3.7-1/js/bootstrap.min.js}"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -1,10 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<title>${day} - ${channelName} on ${serverHost}</title>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue