package cfvbaibai.cardfantasy.web.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cfvbaibai.cardfantasy.web.Utils;
import cfvbaibai.cardfantasy.web.beans.UserAction;
import cfvbaibai.cardfantasy.web.beans.UserActionRecorder;

@Controller
public class SiteMonitorController {

    public SiteMonitorController() {
        // TODO Auto-generated constructor stub
    }

    @Autowired
    private UserActionRecorder userActionRecorder;
    
    @RequestMapping(value = "/monitor")
    public void monitor(HttpServletRequest request, HttpServletResponse response) {
        try {
            PrintWriter writer = response.getWriter();
            writer.println("<!DOCTYPE html>");
            writer.println("<html>");
            writer.println("<head>");
            writer.println("<style>td { font-size: 7pt; font-family: 微软雅黑, Calibri, Consolas, Tahoma, Arial; }</style>");
            writer.println("<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>");
            writer.println("<meta name='viewport' content='width=device-width, initial-scale=1'>");
            writer.println("</head>");
            writer.println("<body>");
            writer.println("<table width='100%' border='0' cellspacing='1' bgcolor='#AAAAFF'>");
            writer.println("<tr bgcolor='blue' style='color: white; font-weight: bold; text-align: center'>");
            writer.println("<td>TimeStamp</td><td>User</td><td>Action</td><td>Content</td></tr>");
            
            for (UserAction action : userActionRecorder.getAllActions()) {
                String line = String.format("<tr bgcolor='white'><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>",
                        Utils.toString(action.getTimeStamp()), action.getUserId(), action.getActionType(), action.getActionContent());
                writer.print(line);
            }
            writer.println("</table>");
            writer.println("</body></html>");
        } catch (IOException e) {
            System.err.println("Cannot get writer...");
            e.printStackTrace();
        }
    }
}

@@ -1085,131 +1085,8 @@
 );%0D%0A
-            writer.println(%22%3Cstyle%3Etd %7B font-size: 7pt; font-family: %E5%BE%AE%E8%BD%AF%E9%9B%85%E9%BB%91, Calibri, Consolas, Tahoma, Arial; %7D%3C/style%3E%22);%0D%0A
     
@@ -1315,261 +1315,506 @@
 n(%22%3C
-/head%3E%22);%0D%0A            writer.println(%22%3Cbody%3E%22);%0D%0A            writer.println(%22%3Ctable width='100%25' border='0' cellspacing='1' bgcolor='#AAAAFF'%3E%22);%0D%0A            writer.println(%22%3Ctr bgcolor='blue' style='color: white; font-weight: bold; text-align: center
+style%3Ebody %7B font-size: 9px; font-family: %5C%22Helvetica Neue%5C%22,Helvetica,%5C%22Hiragino Sans GB%5C%22,%5C%22Microsoft YaHei%5C%22,Arial,sans-serif; %7D%22);%0D%0A            writer.println(%22table %7B border-collapse: collapse; %7D table td %7B border: solid 1px #006699; padding: 2px; %7D%3C/style%3E%22);%0D%0A            writer.println(%22%3C/head%3E%22);%0D%0A            writer.println(%22%3Cbody%3E%22);%0D%0A            writer.println(%22%3Ctable width='100%25'%3E%22);%0D%0A            writer.println(%22%3Ctr style='color: #cccccc; background-color: #003366; font-weight: bold
 '%3E%22)
@@ -2058,24 +2058,8 @@
 %22%3Ctr
- bgcolor='white'
 %3E%3Ctd

Improve monitor table style