Skip to content
Permalink
Browse files Browse the repository at this point in the history
H5 sync2 (#595)
* style: 目录样式gh

* style: J_new

* feat: advListFilterTabs

* feat: nav-copyto

* enh: 助记码全拼

* enh: 地图搜索选点

* enh: topnav

* list pn

* .form-line.v33

* open TAG

* KVS addShutdownHook

* fix: #594

---------

Co-authored-by: devezhao <zhaofang123@gmail.com>
  • Loading branch information
getrebuild and devezhao committed Mar 18, 2023
1 parent 9057a41 commit c9474f8
Show file tree
Hide file tree
Showing 38 changed files with 359 additions and 141 deletions.
2 changes: 1 addition & 1 deletion @rbv
Submodule @rbv updated from e7a767 to daad0b
Expand Up @@ -488,7 +488,7 @@ static String renderTopNav2(HttpServletRequest request) {
String name = StringUtils.defaultIfBlank((String) d[4], Language.L("未命名"));

topNavHtml.append(
String.format("<li class=\"nav-item\" data-id=\"%s\"><a class=\"nav-link\" href=\"%s\">%s</a></li>", useNav, url, name));
String.format("<li class=\"nav-item\" data-id=\"%s\"><a class=\"nav-link text-ellipsis\" href=\"%s\">%s</a></li>", useNav, url, name));
break;
}
}
Expand Down
Expand Up @@ -50,4 +50,8 @@ public class EasyEntityConfigProps {
* 列表查询面板
*/
public static final String ADV_LIST_FILTERPANE = "advListFilterPane";
/**
* 列表查询页签
*/
public static final String ADV_LIST_FILTERTABS = "advListFilterTabs";
}
Expand Up @@ -15,7 +15,7 @@
import com.rebuild.core.configuration.general.ClassificationService;
import com.rebuild.core.metadata.EntityHelper;
import com.rebuild.core.support.task.HeavyTask;
import org.apache.commons.lang.StringEscapeUtils;
import com.rebuild.utils.CommonsUtils;
import org.apache.commons.lang.StringUtils;

/**
Expand Down Expand Up @@ -81,9 +81,9 @@ protected ID findOrCreate(String name, String code, ID parent, int level) {
String sql = "select itemId from ClassificationData where dataId = ? and ";
if (StringUtils.isNotBlank(code)) {
sql += String.format("(code = '%s' or name = '%s')",
StringEscapeUtils.escapeSql(code), StringEscapeUtils.escapeSql(name));
CommonsUtils.escapeSql(code), CommonsUtils.escapeSql(name));
} else {
sql += String.format("name = '%s'", StringEscapeUtils.escapeSql(name));
sql += String.format("name = '%s'", CommonsUtils.escapeSql(name));
}

if (parent != null) {
Expand Down
Expand Up @@ -36,8 +36,8 @@
import com.rebuild.core.service.query.QueryHelper;
import com.rebuild.core.support.i18n.Language;
import com.rebuild.core.support.state.StateManager;
import com.rebuild.utils.CommonsUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;

import java.text.MessageFormat;
Expand Down Expand Up @@ -231,7 +231,7 @@ protected ID checkoutReferenceValue(Field field, Cell cell) {
if (refEntity.getEntityCode() == EntityHelper.User) {
String sql = MessageFormat.format(
"select userId from User where loginName = ''{0}'' or email = ''{0}'' or fullName = ''{0}''",
StringEscapeUtils.escapeSql(val2Text.toString()));
CommonsUtils.escapeSql(val2Text.toString()));
query = Application.createQueryNoFilter(sql);
} else {
// 查找引用实体的名称字段和自动编号字段
Expand All @@ -248,7 +248,7 @@ protected ID checkoutReferenceValue(Field field, Cell cell) {
String.format("select %s from %s where ", refEntity.getPrimaryField().getName(), refEntity.getName()));
for (String qf : queryFields) {
sql.append(
String.format("%s = '%s' or ", qf, StringEscapeUtils.escapeSql(val2Text.toString())));
String.format("%s = '%s' or ", qf, CommonsUtils.escapeSql(val2Text.toString())));
}
sql = new StringBuilder(sql.substring(0, sql.length() - 4));

Expand Down
Expand Up @@ -17,7 +17,11 @@
import com.rebuild.core.configuration.general.ClassificationManager;
import com.rebuild.core.configuration.general.PickListManager;
import com.rebuild.core.metadata.EntityHelper;
import com.rebuild.core.metadata.easymeta.*;
import com.rebuild.core.metadata.easymeta.DisplayType;
import com.rebuild.core.metadata.easymeta.EasyEmail;
import com.rebuild.core.metadata.easymeta.EasyMetaFactory;
import com.rebuild.core.metadata.easymeta.EasyPhone;
import com.rebuild.core.metadata.easymeta.EasyUrl;
import com.rebuild.core.privileges.UserService;
import com.rebuild.core.support.i18n.Language;
import com.rebuild.core.support.state.StateManager;
Expand Down Expand Up @@ -103,6 +107,8 @@ protected Integer exec() {
// --

/**
* 生成助记码
*
* @param record
* @return
*/
Expand All @@ -111,7 +117,7 @@ public static String generateQuickCode(Record record) {
if (!entity.containsField(EntityHelper.QuickCode)) return null;

Field nameField = entity.getNameField();
if (!record.hasValue(nameField.getName(), false)) return null;
if (!record.hasValue(nameField.getName(), Boolean.FALSE)) return null;

Object nameValue = record.getObjectValue(nameField.getName());
DisplayType dt = EasyMetaFactory.getDisplayType(nameField);
Expand Down Expand Up @@ -139,10 +145,7 @@ public static String generateQuickCode(Record record) {
}

/**
* 你好世界 - NHSJ
* HelloWorld - HW
* hello world - HW
* 43284327432 - ""
* 生成助记码
*
* @param nameVal
* @return
Expand All @@ -159,34 +162,22 @@ public static String generateQuickCode(String nameVal) {
// 忽略数字或小字母
if (nameVal.matches("[a-z0-9]+")) return StringUtils.EMPTY;

String quickCode = StringUtils.EMPTY;
String quickCode = nameVal;

// 仅包含字母数字或空格
if (nameVal.matches("[a-zA-Z0-9\\s]+")) {
// 提取英文单词的首字母
String[] asplit = nameVal.split("(?=[A-Z\\s])");
if (asplit.length == 1) {
quickCode = nameVal;
} else {
StringBuilder sb = new StringBuilder();
for (String a : asplit) {
if (a.trim().length() > 0) {
sb.append(a.trim(), 0, 1);
}
}
quickCode = sb.toString();
}

// 仅包含字母数字或空格
} else {
// 拼音首字母
nameVal = nameVal.replaceAll(" ", "");
// v3.3 拼音全拼
try {
quickCode = HanLP.convertToPinyinFirstCharString(nameVal, "", false);
quickCode = HanLP.convertToPinyinString(nameVal, "", Boolean.FALSE);
} catch (Exception e) {
log.error("QuickCode shorting error : " + nameVal, e);
quickCode = StringUtils.EMPTY;
}
}

// 去除空格
quickCode = quickCode.replaceAll(" ", "");
return CommonsUtils.maxstr(quickCode, 50).toUpperCase();
}
}
Expand Up @@ -29,9 +29,9 @@
import com.rebuild.core.privileges.bizz.Department;
import com.rebuild.core.support.SetUser;
import com.rebuild.core.support.i18n.Language;
import com.rebuild.utils.CommonsUtils;
import com.rebuild.utils.JSONUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.springframework.util.Assert;
Expand Down Expand Up @@ -587,7 +587,7 @@ private String quoteValue(String val, Type type) {
if (NumberUtils.isNumber(val) && isNumberType(type)) {
return val;
} else if (StringUtils.isNotBlank(val)) {
return String.format("'%s'", StringEscapeUtils.escapeSql(val));
return String.format("'%s'", CommonsUtils.escapeSql(val));
}
return "''";
}
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/com/rebuild/core/support/KVStorage.java
Expand Up @@ -165,7 +165,7 @@ protected static String getValue(final String key, boolean noCache, Object defau
private static final Timer THROTTLED_TIMER = new Timer("KVStorage-Timer");

static {
THROTTLED_TIMER.scheduleAtFixedRate(new TimerTask() {
final TimerTask localTimerTask = new TimerTask() {
@Override
public void run() {
try {
Expand All @@ -184,6 +184,13 @@ public void run() {
log.error(null, ex);
}
}
}, 1000, 1000);
};

THROTTLED_TIMER.scheduleAtFixedRate(localTimerTask, 2000, 2000);

Runtime.getRuntime().addShutdownHook(new Thread(() -> {
log.info("The KVStorage shutdown hook is enabled");
localTimerTask.run();
}));
}
}
Expand Up @@ -26,9 +26,9 @@
import com.rebuild.core.service.dashboard.ChartManager;
import com.rebuild.core.service.query.AdvFilterParser;
import com.rebuild.core.service.query.ParseHelper;
import com.rebuild.utils.CommonsUtils;
import com.rebuild.utils.JSONUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.Assert;

Expand Down Expand Up @@ -199,7 +199,7 @@ protected String parseCategory(String entity, String value) {
if (categoryField == null || StringUtils.isBlank(value)) return "(9=9)";

DisplayType dt = EasyMetaFactory.getDisplayType(categoryField);
value = StringEscapeUtils.escapeSql(value);
value = CommonsUtils.escapeSql(value);

if (dt == DisplayType.MULTISELECT) {
return String.format("%s && %d", categoryField.getName(), ObjectUtils.toInt(value));
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/com/rebuild/utils/CommonsUtils.java
Expand Up @@ -13,6 +13,7 @@
import com.rebuild.core.RebuildException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.core.io.ClassPathResource;

Expand Down Expand Up @@ -85,7 +86,7 @@ public static String maxstr(String text, int maxLength) {
/**
* @param text
* @return
* @see org.apache.commons.lang.StringEscapeUtils#escapeHtml(String)
* @see StringEscapeUtils#escapeHtml(String)
*/
public static String escapeHtml(Object text) {
if (text == null || StringUtils.isBlank(text.toString())) {
Expand All @@ -101,6 +102,17 @@ public static String escapeHtml(Object text) {
.replace("<", "&lt;");
}

/**
* @param text
* @return
* @see StringEscapeUtils#escapeSql(String)
*/
public static String escapeSql(String text) {
// https://github.com/getrebuild/rebuild/issues/594
text = text.replace("\\'", "'");
return StringEscapeUtils.escapeSql(text);
}

/**
* 获取 classpath 下的配置文件流
*
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/rebuild/web/admin/ConfigCommons.java
Expand Up @@ -11,7 +11,7 @@
import com.rebuild.core.metadata.MetadataHelper;
import com.rebuild.core.metadata.easymeta.EasyMetaFactory;
import com.rebuild.core.support.i18n.I18nUtils;
import org.apache.commons.lang.StringEscapeUtils;
import com.rebuild.utils.CommonsUtils;
import org.apache.commons.lang.StringUtils;

import java.util.Date;
Expand All @@ -31,10 +31,10 @@ public class ConfigCommons {
*/
public static Object[][] queryListOfConfig(String sql, String belongEntity, String q) {
if (StringUtils.isNotBlank(belongEntity) && !"$ALL$".equalsIgnoreCase(belongEntity)) {
sql = sql.replace("(1=1)", "belongEntity = '" + StringEscapeUtils.escapeSql(belongEntity) + "'");
sql = sql.replace("(1=1)", "belongEntity = '" + CommonsUtils.escapeSql(belongEntity) + "'");
}
if (StringUtils.isNotBlank(q)) {
sql = sql.replace("(2=2)", "name like '%" + StringEscapeUtils.escapeSql(q) + "%'");
sql = sql.replace("(2=2)", "name like '%" + CommonsUtils.escapeSql(q) + "%'");
}

Object[][] array = Application.createQuery(sql).setLimit(500).array();
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/com/rebuild/web/configuration/NavSettings.java
Expand Up @@ -11,6 +11,7 @@
import cn.devezhao.persist4j.Record;
import cn.devezhao.persist4j.engine.ID;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.rebuild.api.RespBody;
import com.rebuild.core.Application;
import com.rebuild.core.configuration.NavManager;
Expand All @@ -27,6 +28,7 @@
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

Expand Down Expand Up @@ -119,8 +121,30 @@ public RespBody getsTopNav() {

@PostMapping("nav-settings/topnav")
public RespBody setsTopNav(HttpServletRequest request) {
if (!UserHelper.isAdmin(getRequestUser(request))) return RespBody.error();

String s = ServletUtils.getRequestString(request);
KVStorage.setCustomValue("TopNav32", s);
return RespBody.ok();
}

@PostMapping("nav-settings/nav-copyto")
public RespBody navCopyTo(@RequestBody JSONObject post, HttpServletRequest request) {
final ID user = getRequestUser(request);
if (!UserHelper.isAdmin(user)) return RespBody.error();

final ID from = ID.valueOf(post.getString("from"));
final JSON config = NavManager.instance.getLayoutById(from).getJSON("config");

for (Object s : post.getJSONArray("copyTo")) {
ID to = ID.isId(s) ? ID.valueOf(s.toString()) : null;
if (to == null || from.equals(to)) continue;

Record record = EntityHelper.forUpdate(to, user);
record.setString("config", config.toJSONString());
Application.getBean(LayoutConfigService.class).createOrUpdate(record);
}

return RespBody.ok();
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/rebuild/web/files/FileListController.java
Expand Up @@ -25,10 +25,10 @@
import com.rebuild.core.service.project.ProjectManager;
import com.rebuild.core.support.i18n.I18nUtils;
import com.rebuild.core.support.i18n.Language;
import com.rebuild.utils.CommonsUtils;
import com.rebuild.utils.JSONUtils;
import com.rebuild.web.BaseController;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down Expand Up @@ -103,7 +103,7 @@ public JSON listFile(HttpServletRequest request) {

List<String> sqlWhere = new ArrayList<>();
if (StringUtils.isNotBlank(q)) {
sqlWhere.add(String.format("filePath like '%%%s%%'", StringEscapeUtils.escapeSql(q)));
sqlWhere.add(String.format("filePath like '%%%s%%'", CommonsUtils.escapeSql(q)));
}

// 附件
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/com/rebuild/web/general/GeneralListController.java
Expand Up @@ -81,7 +81,8 @@ public ModelAndView pageList(@PathVariable String entity,
if (listMode == 1) {
listConfig = DataListManager.instance.getListFields(entity, user);

// 扩展配置
// 侧栏

String advListHideFilters = easyEntity.getExtraAttr(EasyEntityConfigProps.ADV_LIST_HIDE_FILTERS);
String advListHideCharts = easyEntity.getExtraAttr(EasyEntityConfigProps.ADV_LIST_HIDE_CHARTS);
String advListShowCategory = easyEntity.getExtraAttr(EasyEntityConfigProps.ADV_LIST_SHOWCATEGORY);
Expand All @@ -94,10 +95,10 @@ public ModelAndView pageList(@PathVariable String entity,

// 查询面板

String advListFilterpane = easyEntity.getExtraAttr(EasyEntityConfigProps.ADV_LIST_FILTERPANE);
mv.getModel().put(EasyEntityConfigProps.ADV_LIST_FILTERPANE, advListFilterpane);
String advListFilterPane = easyEntity.getExtraAttr(EasyEntityConfigProps.ADV_LIST_FILTERPANE);
mv.getModel().put(EasyEntityConfigProps.ADV_LIST_FILTERPANE, advListFilterPane);

if (BooleanUtils.toBoolean(advListFilterpane)) {
if (BooleanUtils.toBoolean(advListFilterPane)) {
JSONArray paneFields = new JSONArray();
for (String field : DataListManager.instance.getListFilterPaneFields(user, entity)) {
if (AdvFilterParser.VF_ACU.equals(field)) {
Expand All @@ -112,6 +113,11 @@ public ModelAndView pageList(@PathVariable String entity,
mv.getModel().put("paneFields", paneFields);
}

// 查询页签 v3.3

String advListFilterTabs = easyEntity.getExtraAttr(EasyEntityConfigProps.ADV_LIST_FILTERTABS);
mv.getModel().put(EasyEntityConfigProps.ADV_LIST_FILTERTABS, advListFilterTabs);

} else if (listMode == 2) {
listConfig = DataListManager.instance.getFieldsLayoutMode2(listEntity);

Expand Down

0 comments on commit c9474f8

Please sign in to comment.