add English for viewer

This commit is contained in:
huoyo 2022-06-07 15:54:41 +08:00
parent cd5c061cd5
commit bbf76eb44b
9 changed files with 592 additions and 4 deletions

View File

@ -6,7 +6,7 @@
<groupId>cn.langpy</groupId>
<artifactId>ko-time</artifactId>
<version>2.2.1</version>
<version>2.2.2</version>
<name>KoTime</name>
<description>A springboot tool for tracking the paths of the methods,which can help you to find methods's performances easily.</description>
<licenses>

View File

@ -12,6 +12,8 @@ import org.springframework.stereotype.Component;
@ConfigurationProperties(prefix = "ko-time")
public class DefaultConfig {
private Boolean enable;
private String language;
@Deprecated
private String logLanguage;
private Boolean logEnable;
private Double threshold;
@ -26,6 +28,14 @@ public class DefaultConfig {
private String userName;
private String password;
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public String getDataSource() {
return dataSource;
}

View File

@ -69,6 +69,7 @@ public class LoadConfig {
config.setSaver(defaultConfig.getSaver() == null ? saveSaver : defaultConfig.getSaver());
config.setEnable(defaultConfig.getEnable() == null ? kotimeEnable : defaultConfig.getEnable());
config.setContextPath(defaultConfig.getContextPath());
config.setLanguage(defaultConfig.getLanguage() == null ? "chinese" : defaultConfig.getLanguage());
config.setThreadNum(defaultConfig.getThreadNum() == null ? 2 : defaultConfig.getThreadNum());
config.setAuthEnable(defaultConfig.getAuthEnable() == null ? false : defaultConfig.getAuthEnable());
config.setParamAnalyse(defaultConfig.getParamAnalyse() == null ? true : defaultConfig.getParamAnalyse());

View File

@ -1,5 +1,7 @@
package cn.langpy.kotime.constant;
import cn.langpy.kotime.util.Context;
public class KoConstant {
public final static String comMethodRange = "@annotation(cn.langpy.kotime.annotation.ComputeTime)";
public final static String authRange = "@annotation(cn.langpy.kotime.annotation.Auth)";
@ -9,5 +11,15 @@ public class KoConstant {
public final static String globalIsLogin = "globalIsLoginValue";
public final static String contextPath = "contextPath";
public final static String kotimeViewer = "kotime.html";
public final static String kotimeViewerEn = "kotime-en.html";
public final static String loginName = "kotimeUserName";
public static String getViewName() {
if ("chinese".equals(Context.getConfig().getLanguage())) {
return kotimeViewer;
}else {
return kotimeViewerEn;
}
}
}

View File

@ -73,7 +73,7 @@ public class KoTimeController {
return;
}
response.setContentType("text/html;charset=utf-8");
ClassPathResource classPathResource = new ClassPathResource(KoConstant.kotimeViewer);
ClassPathResource classPathResource = new ClassPathResource(KoConstant.getViewName());
try (
InputStream inputStream = classPathResource.getInputStream();
InputStreamReader streamReader = new InputStreamReader(inputStream, "utf-8");
@ -208,6 +208,9 @@ public class KoTimeController {
if (config.getThreshold() != null) {
koTimeConfig.setThreshold(config.getThreshold());
}
if (config.getLanguage() != null) {
koTimeConfig.setLanguage(config.getLanguage());
}
return true;
}
}

View File

@ -133,7 +133,7 @@ public class Common {
}
public static void showLog(String method, double value) {
if ("chinese".equals(Context.getConfig().getLogLanguage())) {
if ("chinese".equals(Context.getConfig().getLanguage())) {
log.info("调用方法=" + method + "(),耗时=" + value + "毫秒");
} else if ( "english".equals(Context.getConfig().getLogLanguage())) {
log.info("method=" + method + "()runTime=" + value + "ms");

View File

@ -35,11 +35,18 @@
"description": "to print log in console",
"sourceType": "cn.langpy.kotime.config.DefaultConfig"
},
{
"name": "ko-time.language",
"defaultValue": "chinese",
"type": "java.lang.String",
"description": "to select language for viewer",
"sourceType": "cn.langpy.kotime.config.DefaultConfig"
},
{
"name": "ko-time.log-language",
"defaultValue": "chinese",
"type": "java.lang.String",
"description": "to select language for log printed",
"description": "(Deprecated)to select language for log printed",
"sourceType": "cn.langpy.kotime.config.DefaultConfig"
},
{

File diff suppressed because one or more lines are too long

View File

@ -57,6 +57,9 @@
let logEnable = data['logEnable'];
let logEnableDom = document.getElementById('logEnable');
logEnableDom.checked = logEnable;
let language = data['language'];
$("#languageSwitch").val(language)
});
document.getElementById('kotimeEnable').onclick = function(){
@ -72,6 +75,10 @@
$.ajax({type:'POST',url:'contextPath/koTime/updateConfig?token='+globalToken,data:JSON.stringify({logEnable:document.getElementById('logEnable').checked}),dataType:'json', headers: {'Content-Type': 'application/json' }});
};
document.getElementById('languageSwitch').onchange = function(){
let selectedObj = document.getElementById('languageSwitch');
$.ajax({type:'POST',url:'contextPath/koTime/updateConfig?token='+globalToken,data:JSON.stringify({language:selectedObj.options[selectedObj.selectedIndex].value}),dataType:'json', headers: {'Content-Type': 'application/json' }});
};
document.getElementById("timeThresholdYes").onclick = function(){
$.ajax({type:'POST',url:'contextPath/koTime/updateConfig?token='+globalToken,data:JSON.stringify({threshold:document.getElementById('timeThreshold').value}),dataType:'json', headers: {'Content-Type': 'application/json' }});
@ -415,6 +422,12 @@
<br>
<label >开启控制台日志:</label> <input id='logEnable' type="checkbox">
<br>
<label>语言选择:</label>
<select id="languageSwitch" >
<option value="chinese">中文</option>
<option value="english">英文</option>
</select>
<br>
<label >方法运行时间阈值:</label> <input id='timeThreshold' type="input"><button id="timeThresholdYes">确认</button>
<br>
<br>