This commit is contained in:
devezhao 2020-10-29 23:52:21 +08:00
parent f105d53a77
commit 141210d74a
9 changed files with 87 additions and 17 deletions

2
@rbv

@ -1 +1 @@
Subproject commit 7842889096513fd0e8a89a23ffdb79f940295365
Subproject commit 283764e8697a5976981d0d7f1c6041fbab8db28e

View file

@ -36,6 +36,8 @@ public class TransformManager implements ConfigManager {
private TransformManager() { }
/**
* 前端使用
*
* @param sourceEntity
* @return
*/
@ -51,9 +53,10 @@ public class TransformManager implements ConfigManager {
continue;
}
EasyMeta easyMeta = EasyMeta.valueOf(targetEntity);
JSONObject item = JSONUtils.toJSONObject(
new String[] { "targetEntity", "targetEntityLabel", "id" },
new Object[] { target, EasyMeta.getLabel(targetEntity), c.getID("id") });
new String[] { "entityIcon", "entityLabel", "transid" },
new Object[] { easyMeta.getIcon(), easyMeta.getLabel(), c.getID("id") });
data.add(item);
}
return data;

View file

@ -10,6 +10,7 @@ package com.rebuild.core.service.general.transform;
import cn.devezhao.persist4j.Entity;
import cn.devezhao.persist4j.engine.ID;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
/**
* TODO
@ -20,20 +21,27 @@ import com.alibaba.fastjson.JSON;
public class RecordTransfomer {
private Entity targetEntity;
private JSONObject transConfig;
/**
* @param targetEntity
*/
public RecordTransfomer(Entity targetEntity) {
public RecordTransfomer(Entity targetEntity, JSONObject transConfig) {
this.targetEntity = targetEntity;
}
/**
* @param sourceRecord
* @param useMapping
* @return
*/
public ID transform(ID sourceRecord, JSON useMapping) {
public boolean checkFilter() {
return false;
}
/**
* @param sourceRecord
* @return
*/
public ID transform(ID sourceRecord) {
return null;
}
}

View file

@ -117,6 +117,10 @@ public class TransformConfigController extends BaseController {
fullType += "." + field.getReferenceEntity().getName();
} else if (DisplayType.STATE.name().equals(fullType)) {
fullType += "." + easyMeta.getExtraAttr(FieldExtConfigProps.STATE_STATECLASS);
} else if (DisplayType.CLASSIFICATION.name().equals(fullType)) {
fullType += "." + easyMeta.getExtraAttr(FieldExtConfigProps.CLASSIFICATION_USE);
} else if (DisplayType.ID.name().equals(fullType)) {
fullType = DisplayType.REFERENCE.name() + "." + field.getOwnEntity().getName();
}
item.put("type", fullType);
return item;

View file

@ -11,6 +11,8 @@ import cn.devezhao.persist4j.Entity;
import cn.devezhao.persist4j.Field;
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.configuration.ConfigBean;
import com.rebuild.core.configuration.general.AutoFillinManager;
import com.rebuild.core.configuration.general.TransformManager;
@ -18,6 +20,7 @@ import com.rebuild.core.metadata.MetadataHelper;
import com.rebuild.core.service.general.transform.RecordTransfomer;
import com.rebuild.web.BaseController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
@ -54,14 +57,19 @@ public class FormExtrasController extends BaseController {
* @param request
*/
@RequestMapping("transform")
public ID transform(HttpServletRequest request) {
ID configId = getIdParameterNotNull(request, "id");
public RespBody transform(HttpServletRequest request) {
ID transid = getIdParameterNotNull(request, "transid");
ID sourceRecord = getIdParameterNotNull(request, "source");
ConfigBean config = TransformManager.instance.getTransformConfig(configId, null);
ConfigBean config = TransformManager.instance.getTransformConfig(transid, null);
Entity targetEntity = MetadataHelper.getEntity(config.getString("target"));
RecordTransfomer transfomer = new RecordTransfomer(targetEntity);
return transfomer.transform(sourceRecord, config.getJSON("mapping"));
RecordTransfomer transfomer = new RecordTransfomer(targetEntity, (JSONObject) config.getJSON("config"));
if (!transfomer.checkFilter()) {
return RespBody.errorl("TransformNotAllow");
}
ID newId = transfomer.transform(sourceRecord);
return RespBody.ok(newId);
}
}

View file

@ -1195,6 +1195,11 @@
"NoUsesEntity": "无可用实体",
"NoUsesField": "无可用字段",
"To": "至",
"Transform": "转换",
"TransformAs": "转换为",
"TransformAsTips": "确认将当前记录转换为 %s 吗?",
"TransformAsAndOpen": "转换后打开",
"TransformNotAllow": "当前记录不符合转换条件",
"s.__": "状态",
"s.ApprovalState.DRAFT": "草稿",

View file

@ -201,6 +201,8 @@ body {
.view-action .col-lg-6 .btn {
width: 100%;
overflow: hidden;
text-overflow: ellipsis;
}
.view-action.empty {

View file

@ -14,7 +14,7 @@ class RbViewForm extends React.Component {
super(props)
this.state = { ...props }
this.onViewEditable = wpc.onViewEditable === false ? false : true
this.onViewEditable = wpc.onViewEditable !== false
this.__FormData = {}
}
@ -446,6 +446,7 @@ const RbViewPage = {
)
$('.J_assign').click(() => DlgAssign.create({ entity: entity[0], ids: [id] }))
$('.J_share').click(() => DlgShare.create({ entity: entity[0], ids: [id] }))
$('.J_report').click(() => SelectReport.create(entity[0], id))
$('.J_add-detail').click(function () {
const iv = { $MAINID$: id }
const $this = $(this)
@ -456,7 +457,13 @@ const RbViewPage = {
initialValue: iv,
})
})
$('.J_report').click(() => SelectReport.create(entity[0], id))
if (wpc.transformTos && wpc.transformTos.length > 0) {
this.initTrans(wpc.transformTos)
$('.J_trans').removeClass('hide')
} else {
$('.J_trans').remove()
}
// Privileges
if (ep) {
@ -464,8 +471,10 @@ const RbViewPage = {
if (ep.U === false) $('.J_edit, .J_add-detail').remove()
if (ep.A !== true) $('.J_assign').remove()
if (ep.S !== true) $('.J_share').remove()
that.cleanViewActionButton()
}
// Clean
that.cleanViewActionButton()
},
// 元数据
@ -479,7 +488,7 @@ const RbViewPage = {
for (let k in res.data) {
const v = res.data[k]
if (!v || v === undefined) return
if (!v) return
const $el = $('.J_' + k)
if ($el.length === 0) return
@ -585,7 +594,29 @@ const RbViewPage = {
})
$('.J_adds .dropdown-divider').before($item)
})
this.cleanViewActionButton()
},
// 转换
initTrans(config) {
const that = this
config.forEach((item) => {
const $item = $(`<a class="dropdown-item"><i class="icon zmdi zmdi-${item.entityIcon}"></i>${item.entityLabel}</a>`)
$item.click(() => {
RbAlert.create($L('TransformAsTips').replace('%s', item.entityLabel), {
confirm: function () {
this.disabled(true)
$.post(`/app/entity/extras/transform?transid=${item.transid}&source=${that.__id}`, (res) => {
if (res.error_code === 0) {
RbHighbar.success($L('SomeSuccess,Transform'))
} else {
RbHighbar.error(res.error_msg)
}
})
},
})
})
$('.J_trans .dropdown-divider').before($item)
})
},
// 通过父级页面打开
@ -608,6 +639,7 @@ const RbViewPage = {
() => {
$cleanMenu('.view-action .J_mores')
$cleanMenu('.view-action .J_adds')
$cleanMenu('.view-action .J_trans')
$('.view-action .col-lg-6').each(function () {
if ($(this).children().length === 0) $(this).remove()
})

View file

@ -59,6 +59,13 @@
<a class="dropdown-item admin-show J_view-addons" data-type="ADD"><i class="icon zmdi zmdi-settings"></i> [[${bundle.L('ConfSome,ViewNewAddon')}]]</a>
</div>
</div>
<div class="col-12 col-lg-6 btn-group J_trans hide">
<button class="btn btn-secondary dropdown-toggle" type="button" data-toggle="dropdown"><i class="icon zmdi zmdi-repeat"></i> [[${bundle.L('TransformAs')}]]</button>
<div class="dropdown-menu dropdown-menu-right">
<div class="dropdown-divider"></div>
<a class="dropdown-item admin-show" target="_blank" th:href="${baseUrl} + '/admin/transforms'"><i class="icon zmdi zmdi-settings"></i> [[${bundle.L('ConfSome,e.TransformConfig')}]]</a>
</div>
</div>
</div>
<div class="view-user">
<div class="form-line">
@ -97,6 +104,7 @@
privileges: _$unthy('[[${entityPrivileges}]]'),
viewTabs: _$unthy('[[${ViewTabs}]]'),
viewAdds: _$unthy('[[${ViewAdds}]]'),
transformTos: _$unthy('[[${TransformTos}]]'),
recordId: '[[${id}]]',
}
</script>