diff --git a/src/main/java/com/rebuild/server/metadata/MetadataHelper.java b/src/main/java/com/rebuild/server/metadata/MetadataHelper.java
index 8e97a1a51..9bd57ab4f 100644
--- a/src/main/java/com/rebuild/server/metadata/MetadataHelper.java
+++ b/src/main/java/com/rebuild/server/metadata/MetadataHelper.java
@@ -333,7 +333,7 @@ public class MetadataHelper {
* @param fieldPath
* @return
*/
- public static Field getLastField(Entity entity, String fieldPath) {
+ public static Field getLastJoinField(Entity entity, String fieldPath) {
String[] paths = fieldPath.split(".");
Field lastField = null;
Entity father = entity;
diff --git a/src/main/java/com/rebuild/server/metadata/entityhub/Entity2Schema.java b/src/main/java/com/rebuild/server/metadata/entityhub/Entity2Schema.java
index 57d83c740..a13311063 100644
--- a/src/main/java/com/rebuild/server/metadata/entityhub/Entity2Schema.java
+++ b/src/main/java/com/rebuild/server/metadata/entityhub/Entity2Schema.java
@@ -214,10 +214,16 @@ public class Entity2Schema extends Field2Schema {
throw new ModifiyMetadataException("不能删除主实体");
}
+ for (Field whoRef : entity.getReferenceToFields()) {
+ if (!whoRef.getOwnEntity().equals(entity)) {
+ throw new ModifiyMetadataException("实体已被引用 (引用实体: " + EasyMeta.getLabel(whoRef.getOwnEntity()) + ")");
+ }
+ }
+
if (!force) {
long count = 0;
if ((count = checkRecordCount(entity)) > 0) {
- throw new ModifiyMetadataException("不能删除有记录的实体 (" + entity.getName() + "=" + count + ")");
+ throw new ModifiyMetadataException("不能删除有数据的实体 (数量: " + count + ")");
}
}
diff --git a/src/main/java/com/rebuild/server/metadata/entityhub/Field2Schema.java b/src/main/java/com/rebuild/server/metadata/entityhub/Field2Schema.java
index 99739580a..651291378 100644
--- a/src/main/java/com/rebuild/server/metadata/entityhub/Field2Schema.java
+++ b/src/main/java/com/rebuild/server/metadata/entityhub/Field2Schema.java
@@ -90,7 +90,7 @@ public class Field2Schema {
public String create(Entity entity, String fieldLabel, DisplayType type, String comments, String refEntity, JSON extConfig) {
long count = 0;
if ((count = checkRecordCount(entity)) > 50000) {
- throw new ModifiyMetadataException("本实体记录过大,增加字段可能导致表损坏 (" + entity.getName() + "=" + count + ")");
+ throw new ModifiyMetadataException("本实体记录过大,增加字段可能导致表损坏 (记录数: " + count + ")");
}
String fieldName = toPinyinName(fieldLabel);
@@ -108,7 +108,7 @@ public class Field2Schema {
boolean schemaReady = schema2Database(entity, field);
if (!schemaReady) {
Application.getCommonService().delete(tempMetaId.toArray(new ID[tempMetaId.size()]));
- return null;
+ throw new ModifiyMetadataException("无法创建字段到数据库");
}
Application.getMetadataFactory().refresh(false);
diff --git a/src/main/java/com/rebuild/web/admin/entityhub/MetaEntityControll.java b/src/main/java/com/rebuild/web/admin/entityhub/MetaEntityControll.java
index a440ce772..69013a86d 100644
--- a/src/main/java/com/rebuild/web/admin/entityhub/MetaEntityControll.java
+++ b/src/main/java/com/rebuild/web/admin/entityhub/MetaEntityControll.java
@@ -185,6 +185,7 @@ public class MetaEntityControll extends BasePageControll {
public void entityDrop(HttpServletRequest request, HttpServletResponse response) throws IOException {
ID user = getRequestUser(request);
ID entityId = getIdParameterNotNull(request, "id");
+ boolean force = getBoolParameter(request, "force", false);
Object[] entityRecord = Application.createQueryNoFilter(
"select entityName from MetaEntity where entityId = ?")
@@ -192,7 +193,7 @@ public class MetaEntityControll extends BasePageControll {
.unique();
Entity entity = MetadataHelper.getEntity((String) entityRecord[0]);
- boolean drop = new Entity2Schema(user).drop(entity);
+ boolean drop = new Entity2Schema(user).drop(entity, force);
if (drop) {
writeSuccess(response);
} else {
diff --git a/src/main/webapp/admin/entityhub/entity-advanced.jsp b/src/main/webapp/admin/entityhub/entity-advanced.jsp
index fe44dc5f5..d4bb43956 100644
--- a/src/main/webapp/admin/entityhub/entity-advanced.jsp
+++ b/src/main/webapp/admin/entityhub/entity-advanced.jsp
@@ -52,6 +52,9 @@ a#entityIcon:hover{opacity:0.8}
+
@@ -84,11 +87,12 @@ $(document).ready(function(){
})
let sbtn = $('.J_drop-confirm').click(() => {
+ if ($('.J_drop-check').prop('checked') == false) return
if (!window.__PageConfig.isSuperAdmin){ rb.hberror('仅超级管理员可删除实体'); return }
- rb.alert('实体删除后将无法恢复,请务必谨慎操作!确认删除吗?', '删除实体', { type: 'danger', confirmText: '删除', confirm: function(){
+ rb.alert('实体删除后将无法恢复,请务必谨慎操作!确认删除吗?', '删除实体', { type: 'danger', confirmText: '删除', confirm: function () {
sbtn.button('loading')
this.disabled(true)
- $.post('../entity-drop?id=' + metaId, (res) => {
+ $.post('../entity-drop?id=' + metaId + '&force=' + $('.J_drop-force').prop('checked'), (res) => {
if (res.error_code == 0) {
rb.hbsuccess('实体已删除')
setTimeout(function() { location.replace('../../entities') }, 1500)
diff --git a/src/main/webapp/assets/css/rb-page.css b/src/main/webapp/assets/css/rb-page.css
index 9d9daa956..1e90cfdc1 100644
--- a/src/main/webapp/assets/css/rb-page.css
+++ b/src/main/webapp/assets/css/rb-page.css
@@ -1,15 +1,10 @@
-.dev-show {
- display: none;
-}
-
-html.dev .dev-show {
- display: block;
-}
-
-.admin-show {
+.dev-show,
+.admin-show,
+.bosskey-show {
display: none;
}
+html.dev .dev-show,
html.admin .admin-show {
display: block;
}
diff --git a/src/main/webapp/assets/js/rb-page.js b/src/main/webapp/assets/js/rb-page.js
index d3c282d86..77be480d1 100644
--- a/src/main/webapp/assets/js/rb-page.js
+++ b/src/main/webapp/assets/js/rb-page.js
@@ -10,8 +10,8 @@ $(function () {
}, 500, 'rb-scroller-update')
})
if (window.lessIE11) {
- $('.left-sidebar-scroll').height($('.left-sidebar-spacer').height())
- $('html').addClass('ie10')
+ $('.left-sidebar-scroll').height($('.left-sidebar-spacer').height())
+ $('html').addClass('ie10')
}
// tooltip
@@ -44,9 +44,12 @@ $(function () {
$('.J_notifications-top').on('shown.bs.dropdown', __loadMessages)
}
- var keydown_times = 0
+ var bkeydown_times = 0
$(document.body).keydown(function (e) {
- if (e.ctrlKey && e.altKey && e.which === 88) command_exec(++keydown_times)
+ if (e.ctrlKey && e.altKey && e.which === 88) {
+ if (++bkeydown_times === 6) $('.bosskey-show').show()
+ command_exec(bkeydown_times)
+ }
})
})
// Trigger on Ctrl+Alt+X
@@ -196,7 +199,9 @@ var $fileExtName = function (fileName) {
}
var $gotoSection = function (top, target) {
- $(target || 'body').animate({ scrollTop: top || 0 }, 600)
+ $(target || 'body').animate({
+ scrollTop: top || 0
+ }, 600)
}
// Use H5 or Qiuniu
@@ -206,12 +211,16 @@ var $createUploader = function (input, next, complete, error) {
if (window.qiniu && rb.storageUrl) {
input.on('change', function () {
var file = this.files[0]
- var putExtra = imgOnly ? { mimeType: ['image/png', 'image/jpeg', 'image/gif', 'image/bmp', 'image/tiff'] } : null
+ var putExtra = imgOnly ? {
+ mimeType: ['image/png', 'image/jpeg', 'image/gif', 'image/bmp', 'image/tiff']
+ } : null
$.get(rb.baseUrl + '/filex/qiniu/upload-keys?file=' + $encode(file.name), function (res) {
var o = qiniu.upload(file, res.data.key, res.data.token, putExtra)
o.subscribe({
next: function (res) {
- typeof next === 'function' && next({ percent: res.total.percent })
+ typeof next === 'function' && next({
+ percent: res.total.percent
+ })
},
error: function (err) {
var msg = (err.message || 'UnknowError').toUpperCase()
@@ -222,17 +231,20 @@ var $createUploader = function (input, next, complete, error) {
rb.highbar('超出文件大小限制')
return false
}
- if (error) error({ error: msg })
+ if (error) error({
+ error: msg
+ })
else rb.hberror('上传失败: ' + msg)
},
complete: function (res) {
- typeof complete === 'function' && complete({ key: res.key })
+ typeof complete === 'function' && complete({
+ key: res.key
+ })
}
})
})
})
- }
- else {
+ } else {
input.html5Uploader({
name: input.attr('id') || input.attr('name') || 'H5Upload',
postUrl: rb.baseUrl + '/filex/upload?type=' + (imgOnly ? 'image' : 'file'),
@@ -247,21 +259,29 @@ var $createUploader = function (input, next, complete, error) {
},
onClientLoad: function (e, file) {},
onClientProgress: function (e, file) {
- typeof next === 'function' && next({ percent: e.loaded * 100 / e.total })
+ typeof next === 'function' && next({
+ percent: e.loaded * 100 / e.total
+ })
},
onSuccess: function (d) {
d = $.parseJSON(d.currentTarget.response)
if (d.error_code === 0) {
- complete({ key: d.data })
+ complete({
+ key: d.data
+ })
} else {
var msg = d.error_msg || '上传失败,请稍后重试'
- if (error) error({ error: msg })
+ if (error) error({
+ error: msg
+ })
else rb.hberror(msg)
}
},
onClientError: function (e, file) {
var msg = '上传失败,请稍后重试'
- if (error) error({ error: msg })
+ if (error) error({
+ error: msg
+ })
else rb.hberror(msg)
}
})
diff --git a/src/test/java/com/rebuild/server/metadata/entityhub/Meta2SchemaTest.java b/src/test/java/com/rebuild/server/metadata/entityhub/Meta2SchemaTest.java
index fa3ede8e3..bb12a28be 100644
--- a/src/test/java/com/rebuild/server/metadata/entityhub/Meta2SchemaTest.java
+++ b/src/test/java/com/rebuild/server/metadata/entityhub/Meta2SchemaTest.java
@@ -59,4 +59,13 @@ public class Meta2SchemaTest extends TestSupport {
drop = new Entity2Schema(UserService.ADMIN_USER).drop(newEntity);
System.out.println("New Entity (for Field) is dropped : " + newEntityName + " > " + drop);
}
+
+ @Test
+ public void testForceDropEntity() throws Exception {
+ String entityName = "dingdan";
+ if (!MetadataHelper.containsEntity(entityName)) {
+ return;
+ }
+ new Entity2Schema(UserService.ADMIN_USER).drop(MetadataHelper.getEntity("kehu"), true);
+ }
}