forked from p85126437/datagear
完善看板多模板编辑功能,储存格式由逗号间隔改为JSON格式
This commit is contained in:
parent
1f5b18a47c
commit
b7b46fe4b9
|
@ -32,6 +32,12 @@ public class TemplateDashboard extends Dashboard
|
|||
this.template = template;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateDashboardWidget<?> getWidget()
|
||||
{
|
||||
return (TemplateDashboardWidget<?>) super.getWidget();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWidget(DashboardWidget<?> widget)
|
||||
{
|
||||
|
|
|
@ -67,8 +67,8 @@ public abstract class TemplateDashboardWidget<T extends RenderContext> extends A
|
|||
*/
|
||||
public String getFirstTemplate()
|
||||
{
|
||||
if (this.templates == null || this.templates.length < 1)
|
||||
return null;
|
||||
if (getTemplateCount() < 1)
|
||||
throw new IllegalStateException();
|
||||
|
||||
return this.templates[0];
|
||||
}
|
||||
|
@ -84,12 +84,12 @@ public abstract class TemplateDashboardWidget<T extends RenderContext> extends A
|
|||
if (this.templates == null)
|
||||
return false;
|
||||
|
||||
for(String t : this.templates)
|
||||
for (String t : this.templates)
|
||||
{
|
||||
if(t.equals(template))
|
||||
if (t.equals(template))
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -142,7 +142,8 @@ public abstract class TemplateDashboardWidget<T extends RenderContext> extends A
|
|||
* @param template
|
||||
* @return
|
||||
* @throws RenderException
|
||||
* @throws IllegalArgumentException {@code template}不是模板时
|
||||
* @throws IllegalArgumentException
|
||||
* {@code template}不是模板时
|
||||
*/
|
||||
public TemplateDashboard render(T renderContext, String template) throws RenderException, IllegalArgumentException
|
||||
{
|
||||
|
|
|
@ -126,7 +126,7 @@ public class FileTemplateDashboardWidgetResManager extends AbstractTemplateDashb
|
|||
@Override
|
||||
public InputStream getResourceInputStream(String id, String name) throws IOException
|
||||
{
|
||||
File file = getFile(id, name, true);
|
||||
File file = getFile(id, name, false);
|
||||
|
||||
if (!file.exists())
|
||||
return new ByteArrayInputStream(new byte[0]);
|
||||
|
|
|
@ -11,7 +11,6 @@ import java.io.IOException;
|
|||
import java.io.Writer;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.datagear.analysis.DashboardWidget;
|
||||
import org.datagear.analysis.RenderContext;
|
||||
import org.datagear.analysis.RenderException;
|
||||
import org.datagear.analysis.TemplateDashboard;
|
||||
|
@ -76,17 +75,17 @@ public class HtmlTplDashboardScriptObjectWriter extends AbstractHtmlScriptObject
|
|||
public JsonHtmlTplDashboard(HtmlTplDashboard dashboard, String renderContextVarName)
|
||||
{
|
||||
super(dashboard.getId(), dashboard.getTemplate(), new RefHtmlRenderContext(renderContextVarName),
|
||||
new IdTemplateDashboardWidget(dashboard.getWidget()), dashboard.getVarName());
|
||||
new JsonTemplateDashboardWidget(dashboard.getWidget()), dashboard.getVarName());
|
||||
|
||||
setCharts(Collections.EMPTY_LIST);
|
||||
}
|
||||
}
|
||||
|
||||
protected static class IdTemplateDashboardWidget extends TemplateDashboardWidget<RenderContext>
|
||||
protected static class JsonTemplateDashboardWidget extends TemplateDashboardWidget<RenderContext>
|
||||
{
|
||||
public IdTemplateDashboardWidget(DashboardWidget<?> dashboardWidget)
|
||||
public JsonTemplateDashboardWidget(TemplateDashboardWidget<?> dashboardWidget)
|
||||
{
|
||||
super(dashboardWidget.getId());
|
||||
super(dashboardWidget.getId(), dashboardWidget.getTemplates());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -16,6 +16,7 @@ import java.util.List;
|
|||
import org.datagear.analysis.Chart;
|
||||
import org.datagear.analysis.TemplateDashboardWidgetResManager;
|
||||
import org.datagear.analysis.support.ChartWidgetSource;
|
||||
import org.datagear.util.IOUtil;
|
||||
import org.datagear.util.StringUtil;
|
||||
|
||||
/**
|
||||
|
@ -230,7 +231,14 @@ public class HtmlTplDashboardWidgetHtmlRenderer<T extends HtmlRenderContext> ext
|
|||
HtmlTplDashboardWidget<?> dashboardWidget = (HtmlTplDashboardWidget<?>) dashboard.getWidget();
|
||||
Reader in = getTemplateReaderNotNull(dashboardWidget, dashboard.getTemplate());
|
||||
|
||||
renderHtmlTplDashboard(renderContext, dashboard, in);
|
||||
try
|
||||
{
|
||||
renderHtmlTplDashboard(renderContext, dashboard, in);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close(in);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -242,7 +250,8 @@ public class HtmlTplDashboardWidgetHtmlRenderer<T extends HtmlRenderContext> ext
|
|||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
protected DashboardInfo renderHtmlTplDashboard(T renderContext, HtmlTplDashboard dashboard, Reader in) throws Exception
|
||||
protected DashboardInfo renderHtmlTplDashboard(T renderContext, HtmlTplDashboard dashboard, Reader in)
|
||||
throws Exception
|
||||
{
|
||||
Writer out = renderContext.getWriter();
|
||||
|
||||
|
|
|
@ -9,12 +9,15 @@ package org.datagear.management.domain;
|
|||
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.datagear.analysis.support.html.HtmlRenderContext;
|
||||
import org.datagear.analysis.support.html.HtmlTplDashboardWidget;
|
||||
import org.datagear.analysis.support.html.HtmlTplDashboardWidgetFmkRenderer;
|
||||
import org.datagear.util.StringUtil;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
|
||||
/**
|
||||
* {@linkplain HtmlTplDashboardWidget}实体。
|
||||
*
|
||||
|
@ -104,12 +107,49 @@ public class HtmlTplDashboardWidgetEntity extends HtmlTplDashboardWidget<HtmlRen
|
|||
this.dataPermission = dataPermission;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回{@linkplain #getTemplates()}的JSON。
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getTemplatesJson()
|
||||
{
|
||||
String[] templates = getTemplates();
|
||||
|
||||
if (templates == null)
|
||||
return "[]";
|
||||
|
||||
return JSON.toJSONString(templates);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置{@linkplain #setTemplates(String...)}的JSON。
|
||||
*
|
||||
* @param json
|
||||
*/
|
||||
public void setTemplatesJson(String json)
|
||||
{
|
||||
if (StringUtil.isEmpty(json))
|
||||
setTemplates(new String[0]);
|
||||
|
||||
json = json.trim();
|
||||
|
||||
// XXX 兼容非JSON格式,比如旧版数据库中已存储的格式
|
||||
if (!json.startsWith("[") && !json.endsWith("]"))
|
||||
setTemplates(splitTemplates(json));
|
||||
else
|
||||
{
|
||||
List<String> templates = JSON.parseArray(json, String.class);
|
||||
setTemplates(templates.toArray(new String[templates.size()]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取{@linkplain #getTemplates()}以{@linkplain #TEMPLATE_SPLITTER}分隔符合并后的字符串。
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getTemplate()
|
||||
public String getTemplatesSplit()
|
||||
{
|
||||
return concatTemplates(getTemplates());
|
||||
}
|
||||
|
@ -119,7 +159,7 @@ public class HtmlTplDashboardWidgetEntity extends HtmlTplDashboardWidget<HtmlRen
|
|||
*
|
||||
* @param template
|
||||
*/
|
||||
public void setTemplate(String template)
|
||||
public void setTemplateSplit(String template)
|
||||
{
|
||||
setTemplates(splitTemplates(template));
|
||||
}
|
||||
|
|
|
@ -149,6 +149,13 @@ public class HtmlTplDashboardWidgetEntityServiceImpl
|
|||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkInput(HtmlTplDashboardWidgetEntity entity)
|
||||
{
|
||||
if (isBlank(entity.getId()) || isEmpty(entity.getTemplates()))
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addDataPermissionParameters(Map<String, Object> params, User user)
|
||||
{
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
)
|
||||
VALUES
|
||||
(
|
||||
#{entity.id}, #{entity.name}, #{entity.template}, #{entity.templateEncoding}, #{entity.createUser.id},
|
||||
#{entity.id}, #{entity.name}, #{entity.templatesJson}, #{entity.templateEncoding}, #{entity.createUser.id},
|
||||
#{entity.createTime}
|
||||
)
|
||||
</insert>
|
||||
|
@ -19,7 +19,7 @@
|
|||
<update id="update">
|
||||
UPDATE DATAGEAR_HTML_DASHBOARD SET
|
||||
HD_NAME = #{entity.name},
|
||||
HD_TEMPLATE = #{entity.template},
|
||||
HD_TEMPLATE = #{entity.templatesJson},
|
||||
HD_TEMPLATE_ENCODING = #{entity.templateEncoding}
|
||||
WHERE
|
||||
HD_ID = #{entity.id}
|
||||
|
@ -136,7 +136,7 @@
|
|||
SELECT
|
||||
A.HD_ID AS ${_iq_}id${_iq_},
|
||||
A.HD_NAME AS ${_iq_}name${_iq_},
|
||||
A.HD_TEMPLATE AS ${_iq_}template${_iq_},
|
||||
A.HD_TEMPLATE AS ${_iq_}templatesJson${_iq_},
|
||||
A.HD_TEMPLATE_ENCODING AS ${_iq_}templateEncoding${_iq_},
|
||||
A.HD_CREATE_USER_ID AS ${_iq_}createUser.id${_iq_},
|
||||
<include refid="common.fieldsForCreateUser" />,
|
||||
|
|
|
@ -347,7 +347,14 @@ public class ChartController extends AbstractChartPluginAwareController implemen
|
|||
InputStream in = resManager.getResourceInputStream(id, resName);
|
||||
OutputStream out = response.getOutputStream();
|
||||
|
||||
IOUtil.write(in, out);
|
||||
try
|
||||
{
|
||||
IOUtil.write(in, out);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close(in);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -309,34 +309,13 @@ public class DashboardController extends AbstractDataAnalysisController implemen
|
|||
|
||||
if (dashboard == null)
|
||||
throw new RecordNotFoundException();
|
||||
|
||||
if(dashboard.isTemplate(name))
|
||||
{
|
||||
dashboard.removeTemplate(name);
|
||||
|
||||
// 不允许删除唯一的模板文件
|
||||
if (dashboard.getTemplateCount() == 0)
|
||||
{
|
||||
return buildOperationMessageFailResponseEntity(request, HttpStatus.BAD_REQUEST,
|
||||
"dashboard.deleteFailForAtLeastOneTemplate");
|
||||
}
|
||||
else
|
||||
this.htmlTplDashboardWidgetEntityService.update(user, dashboard);
|
||||
}
|
||||
|
||||
TemplateDashboardWidgetResManager dashboardWidgetResManager = this.htmlTplDashboardWidgetEntityService
|
||||
.getHtmlTplDashboardWidgetRenderer().getTemplateDashboardWidgetResManager();
|
||||
|
||||
dashboardWidgetResManager.delete(id, name);
|
||||
|
||||
Map<String, Object> data = new HashMap<String, Object>();
|
||||
data.put("id", id);
|
||||
data.put("templates", dashboard.getTemplates());
|
||||
|
||||
ResponseEntity<OperationMessage> responseEntity = buildOperationMessageSuccessEmptyResponseEntity();
|
||||
responseEntity.getBody().setData(data);
|
||||
|
||||
return responseEntity;
|
||||
return buildOperationMessageSuccessEmptyResponseEntity();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/uploadResourceFile", produces = CONTENT_TYPE_JSON)
|
||||
|
@ -523,7 +502,7 @@ public class DashboardController extends AbstractDataAnalysisController implemen
|
|||
User user = WebUtils.getUser(request, response);
|
||||
|
||||
HtmlTplDashboardWidgetEntity dashboard = new HtmlTplDashboardWidgetEntity();
|
||||
dashboard.setTemplate(template);
|
||||
dashboard.setTemplateSplit(template);
|
||||
dashboard.setTemplateEncoding(templateEncoding);
|
||||
dashboard.setName(name);
|
||||
|
||||
|
@ -682,7 +661,14 @@ public class DashboardController extends AbstractDataAnalysisController implemen
|
|||
InputStream in = resManager.getResourceInputStream(id, resName);
|
||||
OutputStream out = response.getOutputStream();
|
||||
|
||||
IOUtil.write(in, out);
|
||||
try
|
||||
{
|
||||
IOUtil.write(in, out);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close(in);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -614,7 +614,8 @@ readonly 是否只读操作,允许为null
|
|||
if(!id || !resourceFilePath || !resourceName)
|
||||
return;
|
||||
|
||||
$.post(po.url("saveResourceFile"), {"id": id, "resourceFilePath": resourceFilePath, "resourceName": resourceName}, function()
|
||||
$.post(po.url("saveResourceFile"), {"id": id, "resourceFilePath": resourceFilePath, "resourceName": resourceName},
|
||||
function()
|
||||
{
|
||||
po.refreshDashboardResources();
|
||||
po.element(".add-resource-panel").hide();
|
||||
|
@ -642,8 +643,6 @@ readonly 是否只读操作,允许为null
|
|||
$.post(po.url("deleteResource"), {"id": id, "name" : name},
|
||||
function(response)
|
||||
{
|
||||
po.templates = response.data.templates;
|
||||
|
||||
if(po.isTemplateCurrent(name))
|
||||
po.setTemplateNameAndContent("", "");
|
||||
|
||||
|
|
Loading…
Reference in New Issue