mirror of
https://github.com/getrebuild/rebuild.git
synced 2024-09-20 15:35:55 +08:00
layout config
This commit is contained in:
parent
f51735dd64
commit
061369747d
|
@ -62,7 +62,7 @@ public class RoleService extends GeneralEntityService {
|
|||
* @param roleId
|
||||
* @param definition
|
||||
*/
|
||||
public void batchUpdatePrivileges(ID roleId, JSONObject definition) {
|
||||
public void bulkUpdatePrivileges(ID roleId, JSONObject definition) {
|
||||
Object[][] array = Application.createQuery(
|
||||
"select privilegesId,definition,entity,zeroKey from RolePrivileges where roleId = ?")
|
||||
.setParameter(1, roleId)
|
||||
|
|
|
@ -42,7 +42,7 @@ public class User extends cn.devezhao.bizz.security.member.User {
|
|||
super(userId, loginName, disabled);
|
||||
this.email = email;
|
||||
this.fullName = fullName;
|
||||
this.avatarUrl = "/assets/img/afo.png";
|
||||
this.avatarUrl = avatarUrl;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
|
|
|
@ -161,7 +161,7 @@ public class EasyMeta implements BaseMeta {
|
|||
}
|
||||
|
||||
/**
|
||||
* 对用户来说是否可见
|
||||
* 系统内建字段,一般系统用
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
|
|
|
@ -19,12 +19,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
package com.rebuild.server.helper.manager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
|
@ -32,9 +30,11 @@ import com.alibaba.fastjson.JSONObject;
|
|||
import com.rebuild.server.entityhub.EasyMeta;
|
||||
import com.rebuild.server.metadata.EntityHelper;
|
||||
import com.rebuild.server.metadata.MetadataHelper;
|
||||
import com.rebuild.utils.JSONUtils;
|
||||
|
||||
import cn.devezhao.persist4j.Entity;
|
||||
import cn.devezhao.persist4j.Field;
|
||||
import cn.devezhao.persist4j.engine.ID;
|
||||
|
||||
/**
|
||||
* 数据列表
|
||||
|
@ -43,67 +43,65 @@ import cn.devezhao.persist4j.Field;
|
|||
* @since 08/30/2018
|
||||
*/
|
||||
public class DataListManager extends LayoutManager {
|
||||
|
||||
private static final Log LOG = LogFactory.getLog(DataListManager.class);
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
public static JSON getColumnLayout(String entity) {
|
||||
Object[] raw = getLayoutConfigRaw(entity, TYPE_DATALIST);
|
||||
public static JSON getColumnLayout(String entity, ID user) {
|
||||
Object[] cfgs = getLayoutConfigRaw(entity, TYPE_DATALIST, user);
|
||||
|
||||
List<Map<String, Object>> columnList = new ArrayList<>();
|
||||
Entity entityMeta = MetadataHelper.getEntity(entity);
|
||||
|
||||
Field nameField = entityMeta.getNameField();
|
||||
nameField = nameField == null ? entityMeta.getPrimaryField() : nameField;
|
||||
Field namedField = entityMeta.getNameField();
|
||||
namedField = namedField == null ? entityMeta.getPrimaryField() : namedField;
|
||||
|
||||
// 默认配置
|
||||
if (raw == null) {
|
||||
columnList.add(warpColumn(nameField));
|
||||
if (cfgs == null) {
|
||||
columnList.add(formattedColumn(namedField));
|
||||
|
||||
if (entityMeta.containsField(EntityHelper.createdBy)) {
|
||||
columnList.add(warpColumn(entityMeta.getField(EntityHelper.createdBy)));
|
||||
String namedFieldName = namedField.getName();
|
||||
if (!StringUtils.equalsIgnoreCase(namedFieldName, EntityHelper.createdBy)
|
||||
&& entityMeta.containsField(EntityHelper.createdBy)) {
|
||||
columnList.add(formattedColumn(entityMeta.getField(EntityHelper.createdBy)));
|
||||
}
|
||||
if (!nameField.getName().equals(EntityHelper.createdOn) && entityMeta.containsField(EntityHelper.createdOn)) {
|
||||
columnList.add(warpColumn(entityMeta.getField(EntityHelper.createdOn)));
|
||||
if (!StringUtils.equalsIgnoreCase(namedFieldName, EntityHelper.createdOn)
|
||||
&& entityMeta.containsField(EntityHelper.createdOn)) {
|
||||
columnList.add(formattedColumn(entityMeta.getField(EntityHelper.createdOn)));
|
||||
}
|
||||
} else {
|
||||
JSONArray config = (JSONArray) raw[1];
|
||||
JSONArray config = (JSONArray) cfgs[1];
|
||||
for (Object o : config) {
|
||||
JSONObject jo = (JSONObject) o;
|
||||
String field = jo.getString("field");
|
||||
JSONObject col = (JSONObject) o;
|
||||
String field = col.getString("field");
|
||||
if (entityMeta.containsField(field)) {
|
||||
Map<String, Object> map = warpColumn(entityMeta.getField(field));
|
||||
Integer width = jo.getInteger("width");
|
||||
Map<String, Object> map = formattedColumn(entityMeta.getField(field));
|
||||
Integer width = col.getInteger("width");
|
||||
if (width != null) {
|
||||
map.put("width", width);
|
||||
}
|
||||
columnList.add(map);
|
||||
} else {
|
||||
LOG.warn("Invalid field : " + field);
|
||||
LOG.warn("Unknow field '" + field + "' in '" + entity + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, Object> ret = new HashMap<>();
|
||||
ret.put("entity", entity);
|
||||
ret.put("nameField", nameField.getName());
|
||||
ret.put("fields", columnList);
|
||||
return (JSON) JSON.parse(JSON.toJSONString(ret));
|
||||
return JSONUtils.toJSONObject(
|
||||
new String[] { "entity", "nameField", "fields" },
|
||||
new Object[] { entity, namedField.getName(), columnList });
|
||||
}
|
||||
|
||||
/**
|
||||
* @param field
|
||||
* @return
|
||||
*/
|
||||
public static Map<String, Object> warpColumn(Field field) {
|
||||
public static Map<String, Object> formattedColumn(Field field) {
|
||||
EasyMeta easyMeta = new EasyMeta(field);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("field", easyMeta.getName());
|
||||
map.put("label", easyMeta.getLabel());
|
||||
map.put("type", easyMeta.getDisplayType(false));
|
||||
return map;
|
||||
return JSONUtils.toJSONObject(
|
||||
new String[] { "field", "label", "type" },
|
||||
new Object[] { easyMeta.getName(), easyMeta.getLabel(), easyMeta.getDisplayType(false) });
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ package com.rebuild.server.helper.manager;
|
|||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.util.Assert;
|
||||
|
@ -54,27 +55,28 @@ public class FormManager extends LayoutManager {
|
|||
|
||||
/**
|
||||
* @param entity
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
public static JSON getFormLayout(String entity) {
|
||||
Assert.notNull(entity, "[entity] not be null");
|
||||
public static JSON getFormLayout(String entity, ID user) {
|
||||
JSONObject cfgsJson = new JSONObject();
|
||||
cfgsJson.put("entity", entity);
|
||||
|
||||
Object[] raw = getLayoutConfigRaw(entity, TYPE_FORM);
|
||||
JSONObject config = new JSONObject();
|
||||
config.put("entity", entity);
|
||||
if (raw != null) {
|
||||
config.put("id", raw[0].toString());
|
||||
config.put("elements", raw[1]);
|
||||
return config;
|
||||
Object[] cfgs = getLayoutConfigRaw(entity, TYPE_FORM, user);
|
||||
if (cfgs != null) {
|
||||
cfgsJson.put("id", cfgs[0].toString());
|
||||
cfgsJson.put("elements", cfgs[1]);
|
||||
} else {
|
||||
cfgsJson.put("elements", ArrayUtils.EMPTY_STRING_ARRAY);
|
||||
}
|
||||
config.put("elements", new String[0]);
|
||||
return config;
|
||||
return cfgsJson;
|
||||
}
|
||||
|
||||
/**
|
||||
* 表单-新建
|
||||
*
|
||||
* @param entity
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
public static JSON getFormModel(String entity, ID user) {
|
||||
|
@ -86,11 +88,11 @@ public class FormManager extends LayoutManager {
|
|||
*
|
||||
* @param entity
|
||||
* @param user
|
||||
* @param recordId
|
||||
* @param record
|
||||
* @return
|
||||
*/
|
||||
public static JSON getFormModel(String entity, ID user, ID recordId) {
|
||||
return getModel(entity, user, recordId, false);
|
||||
public static JSON getFormModel(String entity, ID user, ID record) {
|
||||
return getModel(entity, user, record, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -98,41 +100,45 @@ public class FormManager extends LayoutManager {
|
|||
*
|
||||
* @param entity
|
||||
* @param user
|
||||
* @param recordId
|
||||
* @param record
|
||||
* @return
|
||||
*/
|
||||
public static JSON getViewModel(String entity, ID user, ID recordId) {
|
||||
Assert.notNull(recordId, "[recordId] not be null");
|
||||
return getModel(entity, user, recordId, true);
|
||||
public static JSON getViewModel(String entity, ID user, ID record) {
|
||||
Assert.notNull(record, "[record] not be null");
|
||||
return getModel(entity, user, record, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
* @param user
|
||||
* @param recordId
|
||||
* @param onView
|
||||
* @param record
|
||||
* @param onView 视图模式?
|
||||
* @return
|
||||
*/
|
||||
protected static JSON getModel(String entity, ID user, ID recordId, boolean onView) {
|
||||
protected static JSON getModel(String entity, ID user, ID record, boolean onView) {
|
||||
Assert.notNull(entity, "[entity] not be null");
|
||||
Assert.notNull(user, "[user] not be null");
|
||||
|
||||
// TODO 判断表单权限
|
||||
|
||||
final Entity entityMeta = MetadataHelper.getEntity(entity);
|
||||
final User currentUser = Application.getUserStore().getUser(user);
|
||||
final Date now = CalendarUtils.now();
|
||||
|
||||
JSONObject config = (JSONObject) getFormLayout(entity);
|
||||
JSONObject config = (JSONObject) getFormLayout(entity, user);
|
||||
JSONArray elements = config.getJSONArray("elements");
|
||||
|
||||
Record record = null;
|
||||
if (!elements.isEmpty() && recordId != null) {
|
||||
record = queryRecord(recordId, elements);
|
||||
Record data = null;
|
||||
if (!elements.isEmpty() && record != null) {
|
||||
data = queryRecord(record, elements);
|
||||
}
|
||||
|
||||
for (Object element : elements) {
|
||||
JSONObject el = (JSONObject) element;
|
||||
String fieldName = el.getString("field");
|
||||
if (fieldName.equals("$LINE$") || fieldName.equals("$DIVIDER$")) {
|
||||
|
||||
// 分割线
|
||||
if (fieldName.equals("$DIVIDER$")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -143,14 +149,16 @@ public class FormManager extends LayoutManager {
|
|||
el.put("type", dt.name());
|
||||
el.put("nullable", fieldMeta.isNullable());
|
||||
el.put("readonly", false);
|
||||
if (record != null && !fieldMeta.isUpdatable()) {
|
||||
|
||||
// 不可更新字段
|
||||
if (data != null && !fieldMeta.isUpdatable()) {
|
||||
el.put("readonly", true);
|
||||
}
|
||||
|
||||
// 针对字段的配置
|
||||
|
||||
JSONObject ext = easyField.getFieldExtConfig();
|
||||
for (Map.Entry<String, Object> e : ext.entrySet()) {
|
||||
JSONObject fieldExt = easyField.getFieldExtConfig();
|
||||
for (Map.Entry<String, Object> e : fieldExt.entrySet()) {
|
||||
el.put(e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
|
@ -162,24 +170,24 @@ public class FormManager extends LayoutManager {
|
|||
}
|
||||
else if (dt == DisplayType.DATETIME) {
|
||||
if (!el.containsKey("datetimeFormat")) {
|
||||
el.put("datetimeFormat", "yyyy-MM-dd HH:mm:ss");
|
||||
el.put("datetimeFormat", DisplayType.DATETIME.getDefaultFormat());
|
||||
}
|
||||
}
|
||||
else if (dt == DisplayType.DATE) {
|
||||
if (!el.containsKey("dateFormat")) {
|
||||
el.put("dateFormat", "yyyy-MM-dd");
|
||||
el.put("dateFormat", DisplayType.DATE.getDefaultFormat());
|
||||
}
|
||||
}
|
||||
|
||||
// 编辑/视图
|
||||
if (record != null) {
|
||||
Object value = wrapFieldValue(record, easyField, onView);
|
||||
if (data != null) {
|
||||
Object value = wrapFieldValue(data, easyField, onView);
|
||||
if (value != null) {
|
||||
if (dt == DisplayType.BOOL && !onView) {
|
||||
value = value.toString().equals("是") ? "T" : "F";
|
||||
} else {
|
||||
el.put("value", value);
|
||||
value = "是".equals(value) ? "T" : "F";
|
||||
}
|
||||
|
||||
el.put("value", value);
|
||||
}
|
||||
}
|
||||
// 新建记录
|
||||
|
@ -195,8 +203,6 @@ public class FormManager extends LayoutManager {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO 默认值
|
||||
|
||||
if (dt == DisplayType.PICKLIST) {
|
||||
JSONArray options = el.getJSONArray("options");
|
||||
for (Object o : options) {
|
||||
|
@ -208,6 +214,8 @@ public class FormManager extends LayoutManager {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO 字段的默认值
|
||||
|
||||
}
|
||||
}
|
||||
return config;
|
||||
|
@ -254,15 +262,15 @@ public class FormManager extends LayoutManager {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param record
|
||||
* @param data
|
||||
* @param field
|
||||
* @param onView
|
||||
* @return
|
||||
*/
|
||||
protected static Object wrapFieldValue(Record record, EasyMeta field, boolean onView) {
|
||||
protected static Object wrapFieldValue(Record data, EasyMeta field, boolean onView) {
|
||||
String fieldName = field.getName();
|
||||
if (record.hasValue(fieldName)) {
|
||||
Object value = record.getObjectValue(fieldName);
|
||||
if (data.hasValue(fieldName)) {
|
||||
Object value = data.getObjectValue(fieldName);
|
||||
if (field.getDisplayType() == DisplayType.PICKLIST) {
|
||||
ID pickValue = (ID) value;
|
||||
return onView ? pickValue.getLabel() : pickValue.toLiteral();
|
||||
|
|
|
@ -18,9 +18,18 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
|
||||
package com.rebuild.server.helper.manager;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.rebuild.server.Application;
|
||||
|
||||
import cn.devezhao.commons.CalendarUtils;
|
||||
import cn.devezhao.persist4j.engine.ID;
|
||||
|
||||
/**
|
||||
* 布局管理
|
||||
*
|
||||
|
@ -29,28 +38,93 @@ import com.rebuild.server.Application;
|
|||
*/
|
||||
public class LayoutManager {
|
||||
|
||||
protected static final Log LOG = LogFactory.getLog(LayoutManager.class);
|
||||
|
||||
// 表单
|
||||
public static final String TYPE_FORM = "FORM";
|
||||
// 数据列表
|
||||
public static final String TYPE_DATALIST = "DATALIST";
|
||||
// 导航
|
||||
public static final String TYPE_NAVI = "NAVI";
|
||||
|
||||
// 私有配置
|
||||
public static final String APPLY_SELF = "SELF";
|
||||
// 全局配置
|
||||
public static final String APPLY_ALL = "ALL";
|
||||
|
||||
/**
|
||||
* 获取配置
|
||||
*
|
||||
* @param entity
|
||||
* @param type
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
public static Object[] getLayoutConfigRaw(String entity, String type) {
|
||||
Object[] config = Application.createNoFilterQuery(
|
||||
"select layoutId,config from LayoutConfig where type = ? and belongEntity = ?")
|
||||
.setParameter(1, type)
|
||||
.setParameter(2, entity)
|
||||
public static Object[] getLayoutConfigRaw(String entity, String type, ID user) {
|
||||
Assert.notNull(entity, "[entity] not be null");
|
||||
Assert.notNull(type, "[type] not be null");
|
||||
Assert.notNull(user, "[user] not be null");
|
||||
|
||||
String sql = "select layoutId,config,modifiedOn from LayoutConfig where belongEntity = '%s' and type = '%s' and applyTo = ?";
|
||||
sql = String.format(sql, entity, type);
|
||||
|
||||
Object[] myself = Application.createNoFilterQuery(sql + " and createdBy = ?")
|
||||
.setParameter(1, APPLY_SELF)
|
||||
.setParameter(2, user)
|
||||
.unique();
|
||||
if (config == null) {
|
||||
Object[] global = Application.createNoFilterQuery(sql).setParameter(1, APPLY_ALL).unique();
|
||||
|
||||
Object[] cfgs = global;
|
||||
|
||||
// 使用最近更新的
|
||||
if (myself != null && global != null) {
|
||||
cfgs = ((Date) myself[2]).getTime() > ((Date) global[2]).getTime() ? myself : global;
|
||||
} else if (myself != null) {
|
||||
cfgs = myself;
|
||||
}
|
||||
|
||||
if (cfgs == null) {
|
||||
return null;
|
||||
}
|
||||
config[1] = JSON.parse(config[1].toString());
|
||||
return config;
|
||||
cfgs[1] = JSON.parse((String) cfgs[1]);
|
||||
cfgs[2] = CalendarUtils.getUTCDateTimeFormat().format(cfgs[2]);
|
||||
return cfgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找配置ID
|
||||
*
|
||||
* @param cfgid
|
||||
* @param toAll
|
||||
* @param entity
|
||||
* @param type
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
public static ID detectConfigId(ID cfgid, boolean toAll, String entity, String type, ID user) {
|
||||
String sql = "select layoutId from LayoutConfig where belongEntity = '%s' and type = '%s'";
|
||||
sql = String.format(sql, entity, type);
|
||||
|
||||
boolean isAdmin = Application.getUserStore().getUser(user).isAdmin();
|
||||
// 管理员有两种配置,一个全局一个自己
|
||||
if (isAdmin) {
|
||||
sql += " and applyTo = '%s'";
|
||||
sql = String.format(sql, toAll ? APPLY_ALL : APPLY_SELF);
|
||||
} else {
|
||||
sql += " and applyTo = '%s' and createdBy = '%s'";
|
||||
sql = String.format(sql, APPLY_SELF, user.toLiteral());
|
||||
}
|
||||
|
||||
Object[] detect = Application.createNoFilterQuery(sql).unique();
|
||||
return detect == null ? null : (ID) detect[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 清理配置缓存
|
||||
*
|
||||
* @param entity
|
||||
* @param type
|
||||
*/
|
||||
public static void cleanLayoutConfig(String entity, String type, ID user) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,13 +18,18 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
|
||||
package com.rebuild.server.helper.manager;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.rebuild.utils.AppUtils;
|
||||
import com.rebuild.utils.JSONUtils;
|
||||
|
||||
import cn.devezhao.persist4j.engine.ID;
|
||||
|
||||
/**
|
||||
* 导航菜单
|
||||
*
|
||||
* @author zhaofang123@gmail.com
|
||||
* @since 09/20/2018
|
||||
|
@ -36,22 +41,33 @@ public class NavManager extends LayoutManager {
|
|||
* @return
|
||||
*/
|
||||
public static JSON getNav(ID user) {
|
||||
Object[] sets = getLayoutConfigRaw("", TYPE_NAVI);
|
||||
if (sets == null) {
|
||||
Object[] cfgs = getLayoutConfigRaw("N", TYPE_NAVI, user);
|
||||
if (cfgs == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("id", sets[0]);
|
||||
json.put("config", sets[1]);
|
||||
return json;
|
||||
JSONObject cfgsJson = JSONUtils.toJSONObject(new String[] { "id", "config" }, cfgs);
|
||||
return cfgsJson;
|
||||
}
|
||||
|
||||
/**
|
||||
* 页面用
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
public static JSONArray getNavForPortal() {
|
||||
Object[] sets = getLayoutConfigRaw("", TYPE_NAVI);
|
||||
return sets == null ? JSON.parseArray("[]") : (JSONArray) sets[1];
|
||||
public static JSONArray getNavForPortal(HttpServletRequest request) {
|
||||
ID user = AppUtils.getRequestUser(request);
|
||||
Object[] cfgs = getLayoutConfigRaw("N", TYPE_NAVI, user);
|
||||
return cfgs == null ? JSON.parseArray("[]") : (JSONArray) cfgs[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cfgid
|
||||
* @param toAll
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
public static ID detectConfigId(ID cfgid, boolean toAll, ID user) {
|
||||
return LayoutManager.detectConfigId(cfgid, toAll, "N", TYPE_NAVI, user);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,19 +18,25 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
|
||||
package com.rebuild.server.query;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.rebuild.server.Application;
|
||||
import com.rebuild.server.entityhub.DisplayType;
|
||||
import com.rebuild.server.entityhub.EasyMeta;
|
||||
import com.rebuild.server.helper.manager.LayoutManager;
|
||||
import com.rebuild.server.metadata.MetadataHelper;
|
||||
|
||||
import cn.devezhao.persist4j.Entity;
|
||||
import cn.devezhao.persist4j.Field;
|
||||
import cn.devezhao.persist4j.engine.ID;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -42,26 +48,51 @@ public class AdvFilterManager {
|
|||
private static final Log LOG = LogFactory.getLog(AdvFilterManager.class);
|
||||
|
||||
/**
|
||||
* 基本查询过滤条件特别名称
|
||||
* 快速查询过滤条件特别名称
|
||||
*/
|
||||
public static final String FN_SIMPLE = "$SIMPLE$";
|
||||
public static final String FILTER_QUICK = "$QUICK$";
|
||||
|
||||
/**
|
||||
* @param entity
|
||||
* @param user
|
||||
* @return
|
||||
* @see LayoutManager#getLayoutConfigRaw(String, String, ID)
|
||||
*/
|
||||
public static Object[] getSimpleFilterRaw(String entity) {
|
||||
Object[] raw = Application.createNoFilterQuery(
|
||||
"select filterId,config from FilterConfig where filterName = ? and belongEntity = ?")
|
||||
.setParameter(1, FN_SIMPLE)
|
||||
.setParameter(2, entity)
|
||||
public static Object[] getQuickFilterRaw(String entity, ID user) {
|
||||
Assert.notNull(entity, "[entity] not be null");
|
||||
Assert.notNull(user, "[user] not be null");
|
||||
|
||||
String sql = "select filterId,config,modifiedOn from FilterConfig where belongEntity = '%s' and filterName = '%s' and applyTo = ?";
|
||||
sql = String.format(sql, entity, FILTER_QUICK);
|
||||
|
||||
Object[] myself = Application.createNoFilterQuery(sql + " and createdBy = ?")
|
||||
.setParameter(1, LayoutManager.APPLY_SELF)
|
||||
.setParameter(2, user)
|
||||
.unique();
|
||||
if (raw == null) {
|
||||
return null;
|
||||
Object[] global = Application.createNoFilterQuery(sql).setParameter(1, LayoutManager.APPLY_ALL).unique();
|
||||
|
||||
Object[] cfgs = global;
|
||||
|
||||
// 使用最近更新的
|
||||
if (myself != null && global != null) {
|
||||
cfgs = ((Date) myself[2]).getTime() > ((Date) global[2]).getTime() ? myself : global;
|
||||
} else if (myself != null) {
|
||||
cfgs = myself;
|
||||
}
|
||||
|
||||
if (cfgs == null) {
|
||||
Entity entityMeta = MetadataHelper.getEntity(entity);
|
||||
Field namedField = entityMeta.getNameField();
|
||||
if (allowQuickFilter(namedField)) {
|
||||
cfgs = new Object[] { null, null };
|
||||
cfgs[1] = String.format("{items:[{ op:'lk', field:'%s', value:'{1}' }]}", namedField.getName());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Entity metaEntity = MetadataHelper.getEntity(entity);
|
||||
JSONObject config = (JSONObject) JSON.parse((String) raw[1]);
|
||||
JSONObject config = (JSONObject) JSON.parse((String) cfgs[1]);
|
||||
JSONArray items = config.getJSONArray("items");
|
||||
for (Iterator<Object> iter = items.iterator(); iter.hasNext(); ) {
|
||||
JSONObject item = (JSONObject) iter.next();
|
||||
|
@ -74,7 +105,47 @@ public class AdvFilterManager {
|
|||
String label = EasyMeta.getLabel(metaEntity.getField(field));
|
||||
item.put("label", label);
|
||||
}
|
||||
raw[1] = config;
|
||||
return raw;
|
||||
cfgs[1] = config;
|
||||
return cfgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找配置ID
|
||||
*
|
||||
* @param cfgid
|
||||
* @param toAll
|
||||
* @param entity
|
||||
* @param user
|
||||
* @return
|
||||
* @see LayoutManager#detectConfigId(ID, boolean, String, String, ID)
|
||||
*/
|
||||
public static ID detectQuickConfigId(ID cfgid, boolean toAll, String entity, ID user) {
|
||||
String sql = "select filterId from FilterConfig where belongEntity = '%s' and filterName = '%s'";
|
||||
sql = String.format(sql, entity, FILTER_QUICK);
|
||||
|
||||
boolean isAdmin = Application.getUserStore().getUser(user).isAdmin();
|
||||
// 管理员有两种配置,一个全局一个自己
|
||||
if (isAdmin) {
|
||||
sql += " and applyTo = '%s'";
|
||||
sql = String.format(sql, toAll ? LayoutManager.APPLY_ALL : LayoutManager.APPLY_SELF);
|
||||
} else {
|
||||
sql += " and applyTo = '%s' and createdBy = '%s'";
|
||||
sql = String.format(sql, LayoutManager.APPLY_SELF, user.toLiteral());
|
||||
}
|
||||
|
||||
Object[] detect = Application.createNoFilterQuery(sql).unique();
|
||||
return detect == null ? null : (ID) detect[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param field
|
||||
* @return
|
||||
*/
|
||||
public static boolean allowQuickFilter(Field field) {
|
||||
if (field == null) {
|
||||
return false;
|
||||
}
|
||||
DisplayType dt = EasyMeta.getDisplayType(field);
|
||||
return (dt == DisplayType.TEXT || dt == DisplayType.URL || dt == DisplayType.EMAIL || dt == DisplayType.PHONE || dt == DisplayType.PICKLIST);
|
||||
}
|
||||
}
|
|
@ -27,6 +27,8 @@ import java.util.Map;
|
|||
import org.springframework.util.Assert;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import cn.devezhao.commons.CalendarUtils;
|
||||
import cn.devezhao.persist4j.engine.ID;
|
||||
|
@ -44,7 +46,7 @@ public class JSONUtils {
|
|||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public static JSON toJSONObject(String key, Object value) {
|
||||
public static JSONObject toJSONObject(String key, Object value) {
|
||||
return toJSONObject(new String[] { key }, new Object[] { value });
|
||||
}
|
||||
|
||||
|
@ -53,13 +55,13 @@ public class JSONUtils {
|
|||
* @param values
|
||||
* @return
|
||||
*/
|
||||
public static JSON toJSONObject(String keys[], Object values[]) {
|
||||
Assert.isTrue(keys.length == values.length, "K/V 长度不匹配");
|
||||
public static JSONObject toJSONObject(String keys[], Object values[]) {
|
||||
Assert.isTrue(keys.length <= values.length, "K/V 长度不匹配");
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
map.put(keys[i], values[i]);
|
||||
}
|
||||
return (JSON) JSON.toJSON(map);
|
||||
return (JSONObject) JSON.toJSON(map);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -67,7 +69,7 @@ public class JSONUtils {
|
|||
* @param valuesArray
|
||||
* @return
|
||||
*/
|
||||
public static JSON toJSONArray(String keys[], Object valuesArray[][]) {
|
||||
public static JSONArray toJSONArray(String keys[], Object valuesArray[][]) {
|
||||
List<Map<String, Object>> array = new ArrayList<>();
|
||||
for (Object[] o : valuesArray) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
|
@ -76,7 +78,7 @@ public class JSONUtils {
|
|||
}
|
||||
array.add(map);
|
||||
}
|
||||
return (JSON) JSON.toJSON(array);
|
||||
return (JSONArray) JSON.toJSON(array);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
42
src/main/java/com/rebuild/web/LayoutConfig.java
Normal file
42
src/main/java/com/rebuild/web/LayoutConfig.java
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
rebuild - Building your system freely.
|
||||
Copyright (C) 2018 devezhao <zhaofang123@gmail.com>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.rebuild.web;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
/**
|
||||
* 布局配置标记接口
|
||||
*
|
||||
* @author devezhao
|
||||
* @since 10/14/2018
|
||||
*/
|
||||
public interface LayoutConfig {
|
||||
|
||||
void sets(@PathVariable String entity,
|
||||
HttpServletRequest request, HttpServletResponse response) throws IOException;
|
||||
|
||||
void gets(@PathVariable String entity,
|
||||
HttpServletRequest request, HttpServletResponse response) throws IOException;
|
||||
|
||||
}
|
|
@ -59,7 +59,7 @@ public class AdminEntryControll extends BaseControll {
|
|||
if (admin.isAdmin()) {
|
||||
return createModelAndView("/admin/entry-admin.jsp");
|
||||
} else {
|
||||
response.sendError(403, "非管理员用户");
|
||||
response.sendError(403, "当前登录用户非管理员");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,21 +34,12 @@ import com.rebuild.web.BaseControll;
|
|||
import cn.devezhao.persist4j.engine.ID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author devezhao
|
||||
* @since 10/08/2018
|
||||
*/
|
||||
@Controller
|
||||
public class DepartmentControll extends BaseControll {
|
||||
|
||||
@RequestMapping("/admin/bizuser/departments")
|
||||
public ModelAndView pageList(HttpServletRequest request) throws IOException {
|
||||
ModelAndView mv = createModelAndView("/admin/bizuser/dept-list.jsp", "Department");
|
||||
JSON cfg = DataListManager.getColumnLayout("Department");
|
||||
mv.getModel().put("DataListConfig", JSON.toJSONString(cfg));
|
||||
return mv;
|
||||
}
|
||||
|
||||
@RequestMapping("/app/Department/view/{id}")
|
||||
public ModelAndView pageView(@PathVariable String id, HttpServletRequest request) throws IOException {
|
||||
ID recordId = ID.valueOf(id);
|
||||
|
@ -56,4 +47,12 @@ public class DepartmentControll extends BaseControll {
|
|||
mv.getModel().put("id", recordId);
|
||||
return mv;
|
||||
}
|
||||
|
||||
@RequestMapping("/admin/bizuser/departments")
|
||||
public ModelAndView pageList(HttpServletRequest request) throws IOException {
|
||||
ModelAndView mv = createModelAndView("/admin/bizuser/dept-list.jsp", "Department");
|
||||
JSON config = DataListManager.getColumnLayout("Department", getRequestUser(request));
|
||||
mv.getModel().put("DataListConfig", JSON.toJSONString(config));
|
||||
return mv;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
|
@ -83,6 +84,7 @@ public class RolePrivilegesControll extends BaseControll {
|
|||
mv.getModel().put("Entities", entities);
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("role-list")
|
||||
public void roleList(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
Object[][] array = Application.createQuery("select roleId,name,isDisabled from Role").array();
|
||||
|
@ -92,15 +94,15 @@ public class RolePrivilegesControll extends BaseControll {
|
|||
|
||||
@RequestMapping("privileges-list")
|
||||
public void privilegesList(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
ID role = getIdParameterNotNull(request, "role");
|
||||
if (RoleService.ADMIN_ROLE.equals(role)) {
|
||||
ID roleId = getIdParameterNotNull(request, "role");
|
||||
if (RoleService.ADMIN_ROLE.equals(roleId)) {
|
||||
writeFailure(response, "管理员权限不允许修改");
|
||||
return;
|
||||
}
|
||||
|
||||
Object[][] array = Application.createQuery(
|
||||
"select entity,definition,zeroKey from RolePrivileges where roleId = ?")
|
||||
.setParameter(1, role)
|
||||
.setParameter(1, roleId)
|
||||
.array();
|
||||
for (Object[] o : array) {
|
||||
String entity = o[0].toString();
|
||||
|
@ -113,11 +115,11 @@ public class RolePrivilegesControll extends BaseControll {
|
|||
writeSuccess(response, retJson);
|
||||
}
|
||||
|
||||
@RequestMapping("privileges-update")
|
||||
@RequestMapping( value = "privileges-update", method = RequestMethod.POST)
|
||||
public void privilegesUpdate(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
JSON post = ServletUtils.getRequestJson(request);
|
||||
ID role = getIdParameterNotNull(request, "role");
|
||||
Application.getBean(RoleService.class).batchUpdatePrivileges(role, (JSONObject) post);
|
||||
Application.getBean(RoleService.class).bulkUpdatePrivileges(role, (JSONObject) post);
|
||||
writeSuccess(response);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,14 +47,6 @@ import cn.devezhao.persist4j.engine.ID;
|
|||
@Controller
|
||||
public class UserControll extends BaseControll {
|
||||
|
||||
@RequestMapping("/admin/bizuser/users")
|
||||
public ModelAndView pageList(HttpServletRequest request) throws IOException {
|
||||
ModelAndView mv = createModelAndView("/admin/bizuser/user-list.jsp", "User");
|
||||
JSON cfg = DataListManager.getColumnLayout("User");
|
||||
mv.getModel().put("DataListConfig", JSON.toJSONString(cfg));
|
||||
return mv;
|
||||
}
|
||||
|
||||
@RequestMapping("/app/User/view/{id}")
|
||||
public ModelAndView pageView(@PathVariable String id, HttpServletRequest request) throws IOException {
|
||||
ID recordId = ID.valueOf(id);
|
||||
|
@ -63,6 +55,14 @@ public class UserControll extends BaseControll {
|
|||
return mv;
|
||||
}
|
||||
|
||||
@RequestMapping("/admin/bizuser/users")
|
||||
public ModelAndView pageList(HttpServletRequest request) throws IOException {
|
||||
ModelAndView mv = createModelAndView("/admin/bizuser/user-list.jsp", "User");
|
||||
JSON config = DataListManager.getColumnLayout("User", getRequestUser(request));
|
||||
mv.getModel().put("DataListConfig", JSON.toJSONString(config));
|
||||
return mv;
|
||||
}
|
||||
|
||||
@RequestMapping("/admin/bizuser/dept-tree")
|
||||
public void deptTreeGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
Object[][] firstDepts = Application.createQuery(
|
||||
|
@ -78,11 +78,11 @@ public class UserControll extends BaseControll {
|
|||
}
|
||||
|
||||
/**
|
||||
* 组织部门树
|
||||
* 部门结构
|
||||
*
|
||||
* @param parent
|
||||
*/
|
||||
private static JSONObject recursiveDeptTree(Department parent) {
|
||||
private JSONObject recursiveDeptTree(Department parent) {
|
||||
JSONObject parentJson = new JSONObject();
|
||||
parentJson.put("id", parent.getIdentity().toString());
|
||||
parentJson.put("name", parent.getName());
|
||||
|
|
|
@ -34,10 +34,10 @@ import com.rebuild.server.Application;
|
|||
import com.rebuild.server.helper.manager.FormManager;
|
||||
import com.rebuild.server.metadata.EntityHelper;
|
||||
import com.rebuild.web.BaseControll;
|
||||
import com.rebuild.web.LayoutConfig;
|
||||
|
||||
import cn.devezhao.commons.web.ServletUtils;
|
||||
import cn.devezhao.persist4j.Record;
|
||||
import cn.devezhao.persist4j.engine.ID;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -46,24 +46,32 @@ import cn.devezhao.persist4j.engine.ID;
|
|||
*/
|
||||
@Controller
|
||||
@RequestMapping("/admin/entity/")
|
||||
public class LayoutManagerControll extends BaseControll {
|
||||
public class FormDesignControll extends BaseControll implements LayoutConfig {
|
||||
|
||||
@RequestMapping("{entity}/form-design")
|
||||
public ModelAndView pageFormDesign(@PathVariable String entity, HttpServletRequest request) throws IOException {
|
||||
ModelAndView mv = createModelAndView("/admin/entity/form-design.jsp");
|
||||
MetaEntityControll.setEntityBase(mv, entity);
|
||||
JSON fc = FormManager.getFormLayout(entity);
|
||||
if (fc != null) {
|
||||
request.setAttribute("FormConfig", fc);
|
||||
JSON cfg = FormManager.getFormLayout(entity, getRequestUser(request));
|
||||
if (cfg != null) {
|
||||
request.setAttribute("FormConfig", cfg);
|
||||
}
|
||||
return mv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gets(String entity, HttpServletRequest request, HttpServletResponse response) throws IOException { }
|
||||
|
||||
@RequestMapping({ "{entity}/form-update" })
|
||||
public void formUpdate(@PathVariable String entity, HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
ID user = getRequestUser(request);
|
||||
@Override
|
||||
public void sets(String entity,
|
||||
HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
JSON formJson = ServletUtils.getRequestJson(request);
|
||||
Record record = EntityHelper.parse((JSONObject) formJson, user);
|
||||
Record record = EntityHelper.parse((JSONObject) formJson, getRequestUser(request));
|
||||
if (record.getPrimary() == null) {
|
||||
record.setString("applyTo", FormManager.APPLY_ALL);
|
||||
}
|
||||
|
||||
Application.getCommonService().createOrUpdate(record);
|
||||
writeSuccess(response);
|
||||
}
|
|
@ -33,34 +33,50 @@ import com.rebuild.server.helper.manager.LayoutManager;
|
|||
import com.rebuild.server.helper.manager.NavManager;
|
||||
import com.rebuild.server.metadata.EntityHelper;
|
||||
import com.rebuild.web.BaseControll;
|
||||
import com.rebuild.web.LayoutConfig;
|
||||
|
||||
import cn.devezhao.commons.web.ServletUtils;
|
||||
import cn.devezhao.persist4j.Record;
|
||||
import cn.devezhao.persist4j.engine.ID;
|
||||
|
||||
/**
|
||||
* 导航菜单设置
|
||||
*
|
||||
* @author zhaofang123@gmail.com
|
||||
* @since 09/19/2018
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/app/commons/")
|
||||
public class NavSettings extends BaseControll {
|
||||
|
||||
@RequestMapping("/app/settings/")
|
||||
public class NavSettings extends BaseControll implements LayoutConfig {
|
||||
|
||||
@Override
|
||||
public void sets(String entity, HttpServletRequest request, HttpServletResponse response) throws IOException { }
|
||||
@Override
|
||||
public void gets(String entity, HttpServletRequest request, HttpServletResponse response) throws IOException { }
|
||||
|
||||
@RequestMapping(value = "nav-settings", method = RequestMethod.POST)
|
||||
public void navsSet(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
public void sets(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
ID user = getRequestUser(request);
|
||||
|
||||
boolean toAll = "true".equals(getParameter(request, "toAll"));
|
||||
// 非管理员只能设置自己
|
||||
boolean isAdmin = Application.getUserStore().getUser(user).isAdmin();
|
||||
if (!isAdmin) {
|
||||
toAll = false;
|
||||
}
|
||||
|
||||
JSON config = ServletUtils.getRequestJson(request);
|
||||
ID configId = getIdParameter(request, "cfgid");
|
||||
ID cfgid = getIdParameter(request, "cfgid");
|
||||
ID cfgidDetected = NavManager.detectConfigId(cfgid, toAll, user);
|
||||
|
||||
Record record = null;
|
||||
if (configId == null) {
|
||||
if (cfgidDetected == null) {
|
||||
record = EntityHelper.forNew(EntityHelper.LayoutConfig, user);
|
||||
record.setString("belongEntity", "");
|
||||
record.setString("belongEntity", "N");
|
||||
record.setString("type", LayoutManager.TYPE_NAVI);
|
||||
record.setString("applyTo", toAll ? LayoutManager.APPLY_ALL : LayoutManager.APPLY_SELF);
|
||||
} else {
|
||||
record = EntityHelper.forUpdate(configId, user);
|
||||
record = EntityHelper.forUpdate(cfgidDetected, user);
|
||||
}
|
||||
record.setString("config", config.toJSONString());
|
||||
Application.getCommonService().createOrUpdate(record);
|
||||
|
@ -69,9 +85,8 @@ public class NavSettings extends BaseControll {
|
|||
}
|
||||
|
||||
@RequestMapping(value = "nav-settings", method = RequestMethod.GET)
|
||||
public void navsGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
ID user = getRequestUser(request);
|
||||
JSON config = NavManager.getNav(user);
|
||||
public void gets(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
JSON config = NavManager.getNav(getRequestUser(request));
|
||||
writeSuccess(response, config);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,102 +19,31 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
package com.rebuild.web.base.entity;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.rebuild.server.Application;
|
||||
import com.rebuild.server.entityhub.DisplayType;
|
||||
import com.rebuild.server.entityhub.EasyMeta;
|
||||
import com.rebuild.server.helper.manager.DataListManager;
|
||||
import com.rebuild.server.metadata.EntityHelper;
|
||||
import com.rebuild.server.metadata.MetadataHelper;
|
||||
import com.rebuild.server.query.AdvFilterManager;
|
||||
import com.rebuild.web.BaseControll;
|
||||
|
||||
import cn.devezhao.commons.web.ServletUtils;
|
||||
import cn.devezhao.persist4j.Entity;
|
||||
import cn.devezhao.persist4j.Field;
|
||||
import cn.devezhao.persist4j.Record;
|
||||
import cn.devezhao.persist4j.engine.ID;
|
||||
import com.rebuild.web.LayoutConfig;
|
||||
|
||||
/**
|
||||
* 高级查询
|
||||
*
|
||||
* @author devezhao
|
||||
* @since 09/30/2018
|
||||
* @since 10/14/2018
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/app/")
|
||||
public class AdvFilterControll extends BaseControll {
|
||||
|
||||
@RequestMapping(value="{entity}/advfilter/simple", method = RequestMethod.GET)
|
||||
public void getSimpleFilter(@PathVariable String entity,
|
||||
HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
Object[] config = AdvFilterManager.getSimpleFilterRaw(entity);
|
||||
if (config == null) {
|
||||
writeSuccess(response);
|
||||
return;
|
||||
}
|
||||
|
||||
JSONObject advfilter = (JSONObject) config[1];
|
||||
writeSuccess(response, advfilter);
|
||||
}
|
||||
|
||||
// --
|
||||
@RequestMapping("/app/{entity}/")
|
||||
public class AdvFilterControll extends BaseControll implements LayoutConfig {
|
||||
|
||||
@RequestMapping(value="{entity}/list-advfilter", method = RequestMethod.POST)
|
||||
public void qfieldsSet(@PathVariable String entity,
|
||||
HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
ID user = getRequestUser(request);
|
||||
Entity entityMeta = MetadataHelper.getEntity(entity);
|
||||
|
||||
JSON config = ServletUtils.getRequestJson(request);
|
||||
ID configId = getIdParameter(request, "cfgid");
|
||||
|
||||
Record record = null;
|
||||
if (configId == null) {
|
||||
record = EntityHelper.forNew(EntityHelper.FilterConfig, user);
|
||||
record.setString("belongEntity", entityMeta.getName());
|
||||
record.setString("filterName", AdvFilterManager.FN_SIMPLE);
|
||||
} else {
|
||||
record = EntityHelper.forUpdate(configId, user);
|
||||
}
|
||||
record.setString("config", config.toJSONString());
|
||||
Application.getCommonService().createOrUpdate(record);
|
||||
writeSuccess(response);
|
||||
@Override
|
||||
public void sets(String entity, HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
}
|
||||
|
||||
@RequestMapping(value="{entity}/list-advfilter", method = RequestMethod.GET)
|
||||
public void qfieldsGet(@PathVariable String entity,
|
||||
HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
Entity entityMeta = MetadataHelper.getEntity(entity);
|
||||
|
||||
List<Map<String, Object>> fieldList = new ArrayList<>();
|
||||
for (Field field : entityMeta.getFields()) {
|
||||
DisplayType dt = EasyMeta.getDisplayType(field);
|
||||
if (dt == DisplayType.TEXT || dt == DisplayType.URL || dt == DisplayType.EMAIL || dt == DisplayType.PHONE || dt == DisplayType.PICKLIST) {
|
||||
fieldList.add(DataListManager.warpColumn(field));
|
||||
}
|
||||
}
|
||||
|
||||
Object[] config = AdvFilterManager.getSimpleFilterRaw(entity);
|
||||
Map<String, Object> ret = new HashMap<>();
|
||||
ret.put("fieldList", fieldList);
|
||||
if (config != null) {
|
||||
ret.put("config", config[1]);
|
||||
ret.put("configId", config[0].toString());
|
||||
}
|
||||
writeSuccess(response, ret);
|
||||
@Override
|
||||
public void gets(String entity, HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ import com.rebuild.server.helper.manager.LayoutManager;
|
|||
import com.rebuild.server.metadata.EntityHelper;
|
||||
import com.rebuild.server.metadata.MetadataHelper;
|
||||
import com.rebuild.web.BaseControll;
|
||||
import com.rebuild.web.LayoutConfig;
|
||||
|
||||
import cn.devezhao.commons.web.ServletUtils;
|
||||
import cn.devezhao.persist4j.Entity;
|
||||
|
@ -57,31 +58,46 @@ import cn.devezhao.persist4j.engine.ID;
|
|||
*/
|
||||
@Controller
|
||||
@RequestMapping("/app/")
|
||||
public class DataListSettings extends BaseControll {
|
||||
|
||||
public class DataListSettings extends BaseControll implements LayoutConfig {
|
||||
|
||||
@RequestMapping(value = "{entity}/list-columns", method = RequestMethod.POST)
|
||||
public void columnsSet(@PathVariable String entity, HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
@Override
|
||||
public void sets(@PathVariable String entity,
|
||||
HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
ID user = getRequestUser(request);
|
||||
Entity entityMeta = MetadataHelper.getEntity(entity);
|
||||
|
||||
boolean toAll = "true".equals(getParameter(request, "toAll"));
|
||||
// 非管理员只能设置自己
|
||||
boolean isAdmin = Application.getUserStore().getUser(user).isAdmin();
|
||||
if (!isAdmin) {
|
||||
toAll = false;
|
||||
}
|
||||
|
||||
JSON config = ServletUtils.getRequestJson(request);
|
||||
ID configId = getIdParameter(request, "cfgid");
|
||||
ID cfgid = getIdParameter(request, "cfgid");
|
||||
ID cfgidDetected = DataListManager.detectConfigId(cfgid, toAll, entity, DataListManager.TYPE_DATALIST, user);
|
||||
|
||||
Record record = null;
|
||||
if (configId == null) {
|
||||
if (cfgidDetected == null) {
|
||||
record = EntityHelper.forNew(EntityHelper.LayoutConfig, user);
|
||||
record.setString("belongEntity", entityMeta.getName());
|
||||
record.setString("type", LayoutManager.TYPE_DATALIST);
|
||||
record.setString("applyTo", toAll ? LayoutManager.APPLY_ALL : LayoutManager.APPLY_SELF);
|
||||
} else {
|
||||
record = EntityHelper.forUpdate(configId, user);
|
||||
record = EntityHelper.forUpdate(cfgidDetected, user);
|
||||
}
|
||||
record.setString("config", config.toJSONString());
|
||||
Application.getCommonService().createOrUpdate(record);
|
||||
|
||||
writeSuccess(response);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "{entity}/list-columns", method = RequestMethod.GET)
|
||||
public void columnsGet(@PathVariable String entity, HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
@Override
|
||||
public void gets(@PathVariable String entity,
|
||||
HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
ID user = getRequestUser(request);
|
||||
Entity entityMeta = MetadataHelper.getEntity(entity);
|
||||
|
||||
List<Map<String, Object>> fieldList = new ArrayList<>();
|
||||
|
@ -89,19 +105,19 @@ public class DataListSettings extends BaseControll {
|
|||
if (field.getType() == FieldType.PRIMARY) {
|
||||
continue;
|
||||
}
|
||||
fieldList.add(DataListManager.warpColumn(field));
|
||||
fieldList.add(DataListManager.formattedColumn(field));
|
||||
}
|
||||
|
||||
List<Map<String, Object>> configList = new ArrayList<>();
|
||||
Object[] lcr = DataListManager.getLayoutConfigRaw(entity, DataListManager.TYPE_DATALIST);
|
||||
if (lcr != null) {
|
||||
for (Object o : (JSONArray) lcr[1]) {
|
||||
JSONObject jo = (JSONObject) o;
|
||||
String field = jo.getString("field");
|
||||
Object[] raw = DataListManager.getLayoutConfigRaw(entity, DataListManager.TYPE_DATALIST, user);
|
||||
if (raw != null) {
|
||||
for (Object o : (JSONArray) raw[1]) {
|
||||
JSONObject col = (JSONObject) o;
|
||||
String field = col.getString("field");
|
||||
if (entityMeta.containsField(field)) {
|
||||
configList.add(DataListManager.warpColumn(entityMeta.getField(field)));
|
||||
configList.add(DataListManager.formattedColumn(entityMeta.getField(field)));
|
||||
} else {
|
||||
LOG.warn("Invalid field : " + field);
|
||||
LOG.warn("Unknow field '" + field + "' in '" + entity + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -109,8 +125,8 @@ public class DataListSettings extends BaseControll {
|
|||
Map<String, Object> ret = new HashMap<>();
|
||||
ret.put("fieldList", fieldList);
|
||||
ret.put("configList", configList);
|
||||
if (lcr != null) {
|
||||
ret.put("configId", lcr[0].toString());
|
||||
if (raw != null) {
|
||||
ret.put("configId", raw[0].toString());
|
||||
}
|
||||
writeSuccess(response, ret);
|
||||
}
|
||||
|
|
|
@ -38,31 +38,29 @@ import com.rebuild.web.base.entity.datalist.DefaultDataListControl;
|
|||
import cn.devezhao.commons.web.ServletUtils;
|
||||
|
||||
/**
|
||||
* 数据列表-检索数据
|
||||
*
|
||||
* @author zhaofang123@gmail.com
|
||||
* @since 08/22/2018
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/app/")
|
||||
@RequestMapping("/app/{entity}/")
|
||||
public class GeneralListControll extends BaseControll {
|
||||
|
||||
@RequestMapping("{entity}/list")
|
||||
public ModelAndView pageList(@PathVariable String entity,
|
||||
HttpServletRequest request) throws IOException {
|
||||
@RequestMapping("list")
|
||||
public ModelAndView pageList(@PathVariable String entity, HttpServletRequest request) throws IOException {
|
||||
ModelAndView mv = createModelAndView("/general-entity/record-list.jsp", entity);
|
||||
JSON cfg = DataListManager.getColumnLayout(entity);
|
||||
mv.getModel().put("DataListConfig", JSON.toJSONString(cfg));
|
||||
JSON config = DataListManager.getColumnLayout(entity, getRequestUser(request));
|
||||
mv.getModel().put("DataListConfig", JSON.toJSONString(config));
|
||||
return mv;
|
||||
}
|
||||
|
||||
@RequestMapping("{entity}/record-list")
|
||||
@RequestMapping("record-list")
|
||||
public void recordList(@PathVariable String entity,
|
||||
HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
String reqdata = ServletUtils.getRequestString(request);
|
||||
JSONObject reqJson = JSON.parseObject(reqdata);
|
||||
|
||||
DataListControl control = new DefaultDataListControl(reqJson);
|
||||
String json = control.getResult();
|
||||
writeSuccess(response, JSON.parse(json));
|
||||
JSONObject query = (JSONObject) ServletUtils.getRequestJson(request);
|
||||
DataListControl control = new DefaultDataListControl(query, getRequestUser(request));
|
||||
JSON result = control.getResult();
|
||||
writeSuccess(response, result);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,135 @@
|
|||
/*
|
||||
rebuild - Building your system freely.
|
||||
Copyright (C) 2018 devezhao <zhaofang123@gmail.com>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.rebuild.web.base.entity;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.rebuild.server.Application;
|
||||
import com.rebuild.server.helper.manager.DataListManager;
|
||||
import com.rebuild.server.helper.manager.LayoutManager;
|
||||
import com.rebuild.server.metadata.EntityHelper;
|
||||
import com.rebuild.server.metadata.MetadataHelper;
|
||||
import com.rebuild.server.query.AdvFilterManager;
|
||||
import com.rebuild.web.BaseControll;
|
||||
import com.rebuild.web.LayoutConfig;
|
||||
|
||||
import cn.devezhao.commons.web.ServletUtils;
|
||||
import cn.devezhao.persist4j.Entity;
|
||||
import cn.devezhao.persist4j.Field;
|
||||
import cn.devezhao.persist4j.Record;
|
||||
import cn.devezhao.persist4j.engine.ID;
|
||||
|
||||
/**
|
||||
* 快速查询
|
||||
*
|
||||
* @author devezhao
|
||||
* @since 09/30/2018
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/app/{entity}/")
|
||||
public class QuickFilterControll extends BaseControll implements LayoutConfig {
|
||||
|
||||
@RequestMapping(value="advfilter/quick-fields", method = RequestMethod.POST)
|
||||
@Override
|
||||
public void sets(@PathVariable String entity,
|
||||
HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
ID user = getRequestUser(request);
|
||||
|
||||
boolean toAll = "true".equals(getParameter(request, "toAll"));
|
||||
// 非管理员只能设置自己
|
||||
boolean isAdmin = Application.getUserStore().getUser(user).isAdmin();
|
||||
if (!isAdmin) {
|
||||
toAll = false;
|
||||
}
|
||||
|
||||
Entity entityMeta = MetadataHelper.getEntity(entity);
|
||||
|
||||
JSON config = ServletUtils.getRequestJson(request);
|
||||
ID cfgid = getIdParameter(request, "cfgid");
|
||||
ID cfgidDetected = AdvFilterManager.detectQuickConfigId(cfgid, toAll, entityMeta.getName(), user);
|
||||
|
||||
Record record = null;
|
||||
if (cfgidDetected == null) {
|
||||
record = EntityHelper.forNew(EntityHelper.FilterConfig, user);
|
||||
record.setString("belongEntity", entityMeta.getName());
|
||||
record.setString("filterName", AdvFilterManager.FILTER_QUICK);
|
||||
record.setString("applyTo", toAll ? LayoutManager.APPLY_ALL : LayoutManager.APPLY_SELF);
|
||||
} else {
|
||||
record = EntityHelper.forUpdate(cfgidDetected, user);
|
||||
}
|
||||
record.setString("config", config.toJSONString());
|
||||
Application.getCommonService().createOrUpdate(record);
|
||||
|
||||
writeSuccess(response);
|
||||
}
|
||||
|
||||
@RequestMapping(value="advfilter/quick-fields", method = RequestMethod.GET)
|
||||
@Override
|
||||
public void gets(@PathVariable String entity,
|
||||
HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
ID user = getRequestUser(request);
|
||||
Entity entityMeta = MetadataHelper.getEntity(entity);
|
||||
|
||||
List<Map<String, Object>> fieldList = new ArrayList<>();
|
||||
for (Field field : entityMeta.getFields()) {
|
||||
if (AdvFilterManager.allowQuickFilter(field)) {
|
||||
fieldList.add(DataListManager.formattedColumn(field));
|
||||
}
|
||||
}
|
||||
|
||||
Object[] config = AdvFilterManager.getQuickFilterRaw(entity, user);
|
||||
Map<String, Object> ret = new HashMap<>();
|
||||
ret.put("fieldList", fieldList);
|
||||
if (config != null) {
|
||||
ret.put("config", config[1]);
|
||||
ret.put("configId", config[0] != null ? config[0].toString() : null);
|
||||
}
|
||||
writeSuccess(response, ret);
|
||||
}
|
||||
|
||||
@RequestMapping(value="advfilter/quick", method = RequestMethod.GET)
|
||||
public void getQuickFilter(@PathVariable String entity,
|
||||
HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
ID user = getRequestUser(request);
|
||||
Entity entityMeta = MetadataHelper.getEntity(entity);
|
||||
|
||||
Object[] config = AdvFilterManager.getQuickFilterRaw(entityMeta.getName(), user);
|
||||
if (config == null) {
|
||||
writeSuccess(response);
|
||||
return;
|
||||
}
|
||||
|
||||
JSONObject quick = (JSONObject) config[1];
|
||||
writeSuccess(response, quick);
|
||||
}
|
||||
}
|
|
@ -18,6 +18,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
|
||||
package com.rebuild.web.base.entity.datalist;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
|
||||
/**
|
||||
* @author Zhao Fangfang
|
||||
* @since 1.0, 2013-6-20
|
||||
|
@ -36,5 +38,5 @@ public interface DataListControl {
|
|||
*
|
||||
* @return
|
||||
*/
|
||||
String getResult();
|
||||
JSON getResult();
|
||||
}
|
||||
|
|
|
@ -18,9 +18,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
|
||||
package com.rebuild.web.base.entity.datalist;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
@ -30,6 +27,7 @@ import com.rebuild.server.Application;
|
|||
import com.rebuild.server.entityhub.EasyMeta;
|
||||
import com.rebuild.server.helper.manager.FieldValueWrapper;
|
||||
import com.rebuild.server.metadata.MetadataHelper;
|
||||
import com.rebuild.utils.JSONUtils;
|
||||
|
||||
import cn.devezhao.persist4j.Entity;
|
||||
import cn.devezhao.persist4j.Field;
|
||||
|
@ -69,7 +67,7 @@ public class DataWrapper extends FieldValueWrapper {
|
|||
/**
|
||||
* @return
|
||||
*/
|
||||
public String toJson() {
|
||||
public JSON toJson() {
|
||||
final Field namedFiled = entity.getNameField();
|
||||
for (Object[] row : data) {
|
||||
Object namedVal = null;
|
||||
|
@ -94,10 +92,9 @@ public class DataWrapper extends FieldValueWrapper {
|
|||
}
|
||||
}
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("total", total);
|
||||
map.put("data", data);
|
||||
return JSON.toJSONString(map);
|
||||
return JSONUtils.toJSONObject(
|
||||
new String[] { "total", "data" },
|
||||
new Object[] { total, data });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,10 +18,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
|
||||
package com.rebuild.web.base.entity.datalist;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.rebuild.server.Application;
|
||||
|
||||
import cn.devezhao.commons.ObjectUtils;
|
||||
import cn.devezhao.persist4j.Query;
|
||||
import cn.devezhao.persist4j.engine.ID;
|
||||
|
||||
/**
|
||||
* 数据列表控制器
|
||||
|
@ -33,18 +36,19 @@ public class DefaultDataListControl implements DataListControl {
|
|||
|
||||
protected static final int READ_TIMEOUT = 15 * 1000;
|
||||
|
||||
protected JSONQueryParser queryParser;
|
||||
private JSONQueryParser queryParser;
|
||||
private ID user;
|
||||
|
||||
/**
|
||||
*/
|
||||
protected DefaultDataListControl() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param queryElement
|
||||
* @param query
|
||||
* @param user
|
||||
*/
|
||||
public DefaultDataListControl(JSONObject queryElement) {
|
||||
this.queryParser = new JSONQueryParser(queryElement, this);
|
||||
public DefaultDataListControl(JSONObject query, ID user) {
|
||||
this.queryParser = new JSONQueryParser(query, this);
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -60,19 +64,19 @@ public class DefaultDataListControl implements DataListControl {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getResult() {
|
||||
int total = 0;
|
||||
public JSON getResult() {
|
||||
int totalRows = 0;
|
||||
if (queryParser.isNeedReload()) {
|
||||
String countSql = queryParser.toSqlCount();
|
||||
total = ((Long) Application.createQuery(countSql).unique()[0]).intValue();
|
||||
Object[] count = Application.getQueryFactory().createQuery(queryParser.toSqlCount(), user).unique();
|
||||
totalRows = ObjectUtils.toInt(count[0]);
|
||||
}
|
||||
|
||||
Query query = Application.createQuery(queryParser.toSql()).setTimeout(READ_TIMEOUT);
|
||||
Query query = Application.getQueryFactory().createQuery(queryParser.toSql(), user);
|
||||
int[] limits = queryParser.getSqlLimit();
|
||||
Object[][] array = query.setLimit(limits[0], limits[1]).array();
|
||||
|
||||
DataWrapper wrapper = new DataWrapper(
|
||||
total, array, query.getSelectItems(), query.getRootEntity());
|
||||
totalRows, array, query.getSelectItems(), query.getRootEntity());
|
||||
return wrapper.toJson();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,9 +102,9 @@
|
|||
<entity name="LayoutConfig" type-code="013" description="布局配置(表单/视图/列表)">
|
||||
<field name="layoutId" type="primary"/>
|
||||
<field name="belongEntity" type="string" max-length="100" nullable="false" />
|
||||
<field name="type" type="string" max-length="20" description="FORM,VIEW,LIST" nullable="false"/>
|
||||
<field name="type" type="string" max-length="20" description="FORM,DATALIST,NAVI" nullable="false"/>
|
||||
<field name="config" type="text" description="JSON格式配置" nullable="false"/>
|
||||
<field name="applyFor" type="string" description="应用到哪些人,可选值: ALL/SELF/$MemberID" />
|
||||
<field name="applyTo" type="string" default-value="SELF" description="应用到哪些人,可选值: ALL/SELF/$MemberID(U/D/R)" />
|
||||
</entity>
|
||||
|
||||
<entity name="FilterConfig" type-code="014" description="过滤条件配置">
|
||||
|
@ -112,7 +112,7 @@
|
|||
<field name="filterName" type="string" max-length="100" nullable="false" />
|
||||
<field name="belongEntity" type="string" max-length="100" nullable="false" />
|
||||
<field name="config" type="text" description="JSON格式配置" nullable="false"/>
|
||||
<field name="shareFor" type="string" description="共享给哪些人,可选值: ALL/SELF/$MemberID" />
|
||||
<field name="applyTo" type="string" default-value="SELF" description="共享给哪些人,可选值: ALL/SELF/$MemberID(U/D/R)" />
|
||||
</entity>
|
||||
|
||||
</metadata-config>
|
|
@ -2,11 +2,12 @@
|
|||
<%@ page import="cn.devezhao.commons.CodecUtils"%>
|
||||
<%@ page import="org.apache.commons.lang.StringUtils"%>
|
||||
<%@ page import="com.rebuild.server.ServerListener"%>
|
||||
<%@ page import="com.rebuild.utils.AppUtils"%>
|
||||
<%@ page import="com.alibaba.fastjson.JSONObject"%>
|
||||
<%@ page import="com.alibaba.fastjson.JSONArray"%>
|
||||
<%@ page import="com.rebuild.server.helper.manager.NavManager"%>
|
||||
<% final String activeNav = request.getParameter("activeNav"); %>
|
||||
<%
|
||||
final String activeNav = request.getParameter("activeNav");
|
||||
%>
|
||||
<div class="rb-left-sidebar">
|
||||
<div class="left-sidebar-wrapper">
|
||||
<a class="left-sidebar-toggle">MIN</a>
|
||||
|
@ -16,7 +17,7 @@
|
|||
<ul class="sidebar-elements">
|
||||
<li class="<%="dashboard-home".equals(activeNav) ? "active" : ""%>" id="nav_dashboard-home"><a href="${baseUrl}/dashboard/home"><i class="icon zmdi zmdi-home"></i><span>首页</span></a></li>
|
||||
<%
|
||||
JSONArray navs = NavManager.getNavForPortal();
|
||||
JSONArray navs = NavManager.getNavForPortal(request);
|
||||
for (Object o : navs) {
|
||||
JSONObject nav = (JSONObject) o;
|
||||
String navName = "nav_entity-" + nav.getString("value");
|
||||
|
@ -25,7 +26,7 @@
|
|||
if (!isUrlType) {
|
||||
navUrl = ServerListener.getContextPath() + "/app/" + navUrl + "/list";
|
||||
} else {
|
||||
navName = "nav_url-" + System.currentTimeMillis();
|
||||
navName = "nav_url-" + navName.hashCode();
|
||||
navUrl = ServerListener.getContextPath() + "/commons/url-safe?url=" + CodecUtils.urlEncode(navUrl);
|
||||
}
|
||||
String navIcon = StringUtils.defaultIfBlank(nav.getString("icon"), "texture");
|
||||
|
|
|
@ -180,4 +180,4 @@ const checkEmpty = function(){
|
|||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
|
@ -32,15 +32,14 @@
|
|||
});
|
||||
|
||||
$.ajaxSetup({
|
||||
dataType : 'json',
|
||||
headers:{
|
||||
'Content-Type':'text/plain;charset=utf-8'
|
||||
},
|
||||
cache : false,
|
||||
headers : {
|
||||
},
|
||||
xhrFields : {
|
||||
},
|
||||
complete : function(xhr) {
|
||||
if (xhr.status == 500) rb.notice(xhr.responseText || '系统繁忙!请稍后重试', 'danger', { timeout: 6000 })
|
||||
if (xhr.status == 403) rb.notice(xhr.responseText || '无权访问', 'danger')
|
||||
if (xhr.status == 200){ } // OK
|
||||
else if (xhr.status == 403) rb.notice(xhr.responseText || '无权访问', 'danger')
|
||||
else rb.notice((xhr.responseText || '系统繁忙,请稍后重试') + ' [' + xhr.status + ']', 'danger', { timeout: 6000 })
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -181,4 +180,11 @@ const $regex = {
|
|||
isNotBlank:function(val){
|
||||
return !val || $.trim(val).length == 0;
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
const $encode = function(s) {
|
||||
return encodeURIComponent(s);
|
||||
}
|
||||
const $decode = function(s) {
|
||||
return decodeURIComponent(s);
|
||||
}
|
|
@ -337,7 +337,7 @@ const QuickFilter = {
|
|||
|
||||
loadFilter() {
|
||||
let that = this
|
||||
$.get(`${rb.baseUrl}/app/${this.entity}/advfilter/simple`, function(res){
|
||||
$.get(`${rb.baseUrl}/app/${this.entity}/advfilter/quick`, function(res){
|
||||
that.filterExp = res.data || { items: [] }
|
||||
let qFields = []
|
||||
that.filterExp.items.forEach(function(item){
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
<div class="dialog-footer">
|
||||
<div class="float-left hide J_for-admin">
|
||||
<label class="custom-control custom-checkbox custom-control-inline">
|
||||
<input class="custom-control-input" type="checkbox" id="applyFor" value="ALL" checked="checked">
|
||||
<input class="custom-control-input" type="checkbox" id="applyTo" value="ALL" checked="checked">
|
||||
<span class="custom-control-label">应用到全部用户</span>
|
||||
</label>
|
||||
</div>
|
||||
|
@ -48,7 +48,7 @@ $(document).ready(function(){
|
|||
const entity = $urlp('entity');
|
||||
|
||||
let cfgid = null;
|
||||
$.get(rb.baseUrl + '/app/' + entity + '/list-advfilter', function(res){
|
||||
$.get(rb.baseUrl + '/app/' + entity + '/advfilter/quick-fields', function(res){
|
||||
let fieldNames = {}
|
||||
$(res.data['fieldList']).each(function(){
|
||||
item_render(this, '.J_fields')
|
||||
|
@ -74,7 +74,7 @@ $(document).ready(function(){
|
|||
config = { items: config }
|
||||
|
||||
let btn = $(this).button('loading')
|
||||
$.post(rb.baseUrl + '/app/' + entity + '/list-advfilter?cfgid=' + cfgid, JSON.stringify(config), function(res){
|
||||
$.post(rb.baseUrl + '/app/' + entity + '/advfilter/quick-fields?cfgid=' + cfgid + '&toAll=' + $('#applyTo').prop('checked'), JSON.stringify(config), function(res){
|
||||
btn.button('reset')
|
||||
if (res.error_code == 0){
|
||||
if (parent.QuickFilter) {
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
<div class="dialog-footer">
|
||||
<div class="float-left hide J_for-admin">
|
||||
<label class="custom-control custom-checkbox custom-control-inline">
|
||||
<input class="custom-control-input" type="checkbox" id="applyFor" value="ALL" checked="checked">
|
||||
<input class="custom-control-input" type="checkbox" id="applyTo" value="ALL" checked="checked">
|
||||
<span class="custom-control-label">应用到全部用户</span>
|
||||
</label>
|
||||
</div>
|
||||
|
@ -67,7 +67,7 @@ $(document).ready(function(){
|
|||
if (config.length == 0){ rb.notice('请至少设置一个显示列'); return }
|
||||
|
||||
let btn = $(this).button('loading')
|
||||
$.post(rb.baseUrl + '/app/' + entity + '/list-columns?cfgid=' + cfgid, JSON.stringify(config), function(res){
|
||||
$.post(rb.baseUrl + '/app/' + entity + '/list-columns?cfgid=' + cfgid + '&toAll=' + $('#applyTo').prop('checked'), JSON.stringify(config), function(res){
|
||||
btn.button('reset')
|
||||
if (res.error_code == 0) parent.location.reload()
|
||||
});
|
||||
|
|
|
@ -64,7 +64,7 @@
|
|||
<div class="dialog-footer">
|
||||
<div class="float-left hide J_for-admin">
|
||||
<label class="custom-control custom-checkbox custom-control-inline">
|
||||
<input class="custom-control-input" type="checkbox" id="applyFor" value="ALL" checked="checked">
|
||||
<input class="custom-control-input" type="checkbox" id="applyTo" value="ALL" checked="checked">
|
||||
<span class="custom-control-label">应用到全部用户</span>
|
||||
</label>
|
||||
</div>
|
||||
|
@ -101,11 +101,12 @@ $(document).ready(function(){
|
|||
})
|
||||
})
|
||||
$('.J_menuEntity').change(function(){
|
||||
let zmdi = $('.J_menuIcon .zmdi')
|
||||
//if (zmdi.hasClass('zmdi-' + UNICON_NAME)){
|
||||
let s = $('.J_menuEntity option:selected').data('icon')
|
||||
zmdi.attr('class', 'zmdi zmdi-' + s)
|
||||
//}
|
||||
if (item_current_isNew == true) {
|
||||
let icon = $('.J_menuEntity option:selected').data('icon')
|
||||
$('.J_menuIcon .zmdi').attr('class', 'zmdi zmdi-' + icon)
|
||||
let name = $('.J_menuEntity option:selected').text()
|
||||
$('.J_menuName').val(name)
|
||||
}
|
||||
})
|
||||
iconModal = null
|
||||
$('.J_menuIcon').click(function(){
|
||||
|
@ -152,13 +153,13 @@ $(document).ready(function(){
|
|||
if (navs.length == 0) { rb.notice('请至少设置一个菜单项'); return }
|
||||
|
||||
let btn = $(this).button('loading')
|
||||
$.post(rb.baseUrl + '/app/commons/nav-settings?cfgid=' + cfgid, JSON.stringify(navs), function(res){
|
||||
$.post(rb.baseUrl + '/app/settings/nav-settings?cfgid=' + cfgid + '&toAll=' + $('#applyTo').prop('checked'), JSON.stringify(navs), function(res){
|
||||
btn.button('reset')
|
||||
if (res.error_code == 0) parent.location.reload()
|
||||
});
|
||||
})
|
||||
|
||||
$.get(rb.baseUrl + '/app/commons/nav-settings', function(res){
|
||||
$.get(rb.baseUrl + '/app/settings/nav-settings', function(res){
|
||||
if (res.data){
|
||||
cfgid = res.data.id
|
||||
$(res.data.config).each(function(){
|
||||
|
@ -168,6 +169,7 @@ $(document).ready(function(){
|
|||
})
|
||||
});
|
||||
var item_currentid;
|
||||
var item_current_isNew;
|
||||
var item_randomid = new Date().getTime();
|
||||
const itemRender = function(data, fromAdd){
|
||||
data.id = data.id || item_randomid++
|
||||
|
@ -210,6 +212,7 @@ const itemRender = function(data, fromAdd){
|
|||
item.find('.dd3-content').trigger('click')
|
||||
$('.J_menuName').focus()
|
||||
}
|
||||
item_current_isNew = fromAdd
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
@ -54,19 +54,17 @@ $(document).ready(function() {
|
|||
});
|
||||
|
||||
$('.J_login-btn').click(function() {
|
||||
let user = $val('#user'),
|
||||
passwd = $val('#passwd');
|
||||
let user = $val('#user'), passwd = $val('#passwd');
|
||||
if (!user || !passwd){
|
||||
rb.notice('请输入用户名和密码')
|
||||
return;
|
||||
}
|
||||
|
||||
let btn = $(this).button('loading');
|
||||
let _data = { user: user, passwd: passwd };
|
||||
$.post(rb.baseUrl + '/user/user-login', _data, function(res) {
|
||||
$.post(rb.baseUrl + '/user/user-login?user=' + $encode(user) + '&passwd=' + $encode(passwd), function(res) {
|
||||
if (res.error_code == 0) location.replace('../dashboard/home');
|
||||
else{
|
||||
rb.notice(res.error_msg || '登录失败')
|
||||
rb.notice(res.error_msg || '登录失败,请稍后重试')
|
||||
btn.button('reset');
|
||||
}
|
||||
});
|
||||
|
|
|
@ -22,6 +22,8 @@ import org.dom4j.Element;
|
|||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import com.rebuild.server.metadata.EntityHelper;
|
||||
|
||||
import cn.devezhao.persist4j.Entity;
|
||||
import cn.devezhao.persist4j.PersistManagerFactory;
|
||||
import cn.devezhao.persist4j.engine.PersistManagerFactoryImpl;
|
||||
|
@ -43,13 +45,13 @@ public class SchemaGen {
|
|||
CTX = new ClassPathXmlApplicationContext(new String[] { "application-ctx.xml", });
|
||||
PMF = CTX.getBean(PersistManagerFactoryImpl.class);
|
||||
|
||||
genAll();
|
||||
// genAll();
|
||||
// gen(EntityHelper.MetaEntity);
|
||||
// gen(EntityHelper.MetaField);
|
||||
// gen(EntityHelper.PickList);
|
||||
// gen(EntityHelper.LayoutConfig);
|
||||
// gen(EntityHelper.RolePrivileges);
|
||||
// gen(EntityHelper.FilterConfig);
|
||||
gen(EntityHelper.LayoutConfig);
|
||||
gen(EntityHelper.FilterConfig);
|
||||
|
||||
System.exit(0);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue