数据集表单页添加列类别集、列标签集设置项

This commit is contained in:
datagear 2020-01-05 21:32:43 +08:00
parent 58ab9c19e2
commit a125b3a0dd
10 changed files with 294 additions and 28 deletions

View File

@ -22,6 +22,9 @@ public class ColumnMeta
/** 数据类型 */
private DataType dataType;
/** 数据类别 */
private DataCategory dataCategory;
/** 展示标签 */
private String label;
@ -29,11 +32,12 @@ public class ColumnMeta
{
}
public ColumnMeta(String name, DataType dataType)
public ColumnMeta(String name, DataType dataType, DataCategory dataCategory)
{
super();
this.name = name;
this.dataType = dataType;
this.dataCategory = dataCategory;
}
public String getName()
@ -56,6 +60,16 @@ public class ColumnMeta
this.dataType = dataType;
}
public DataCategory getDataCategory()
{
return dataCategory;
}
public void setDataCategory(DataCategory dataCategory)
{
this.dataCategory = dataCategory;
}
public boolean hasLabel()
{
return (this.label != null && !this.label.isEmpty());
@ -74,6 +88,7 @@ public class ColumnMeta
@Override
public String toString()
{
return getClass().getSimpleName() + " [name=" + name + ", dataType=" + dataType + "]";
return getClass().getSimpleName() + " [name=" + name + ", dataType=" + dataType + ", dataCategory="
+ dataCategory + ", label=" + label + "]";
}
}

View File

@ -0,0 +1,23 @@
/*
* Copyright (c) 2018 datagear.tech. All Rights Reserved.
*/
/**
*
*/
package org.datagear.analysis;
/**
* 数据类别
*
* @author datagear@163.com
*
*/
public enum DataCategory
{
/** 维度 */
DIMENSION,
/** 标量 */
SCALAR
}

View File

@ -22,6 +22,7 @@ import java.util.List;
import java.util.Map;
import org.datagear.analysis.ColumnMeta;
import org.datagear.analysis.DataCategory;
import org.datagear.analysis.DataSet;
import org.datagear.analysis.DataSetException;
import org.datagear.analysis.DataSetExportValues;
@ -53,6 +54,8 @@ public class SqlDataSetFactory extends AbstractDataSetFactory
private String sql;
private DataCategory[] dataCategories;
private String[] columnLabels;
public SqlDataSetFactory()
@ -60,11 +63,12 @@ public class SqlDataSetFactory extends AbstractDataSetFactory
super();
}
public SqlDataSetFactory(String id, ConnectionFactory connectionFactory, String sql)
public SqlDataSetFactory(String id, ConnectionFactory connectionFactory, String sql, DataCategory[] dataCategories)
{
super(id);
this.connectionFactory = connectionFactory;
this.sql = sql;
this.dataCategories = dataCategories;
}
public ConnectionFactory getConnectionFactory()
@ -87,6 +91,16 @@ public class SqlDataSetFactory extends AbstractDataSetFactory
this.sql = sql;
}
public DataCategory[] getDataCategories()
{
return dataCategories;
}
public void setDataCategories(DataCategory[] dataCategories)
{
this.dataCategories = dataCategories;
}
public String[] getColumnLabels()
{
return columnLabels;
@ -595,8 +609,11 @@ public class SqlDataSetFactory extends AbstractDataSetFactory
DataType dataType = toDataType(metaData, i);
ColumnMeta columnMeta = new ColumnMeta(columnName, dataType);
columnMeta.setLabel(getColumnLabel(i - 1));
ColumnMeta columnMeta = createColumnMeta();
columnMeta.setName(columnName);
columnMeta.setDataType(dataType);
setDataCategory(columnMeta, i);
setColumnLabel(columnMeta, i);
columnMetas.add(columnMeta);
}
@ -604,18 +621,20 @@ public class SqlDataSetFactory extends AbstractDataSetFactory
return new DataSetMeta(columnMetas);
}
/**
* 获取列标签没有则返回{@code null}
*
* @param index
* @return
*/
protected String getColumnLabel(int index)
protected void setDataCategory(ColumnMeta columnMeta, int column)
{
if (this.columnLabels == null || index >= this.columnLabels.length)
return null;
if (this.dataCategories == null || (column - 1) >= this.dataCategories.length)
throw new DataSetException("The data category must be set for column [" + column + "]");
return this.columnLabels[index];
columnMeta.setDataCategory(this.dataCategories[column - 1]);
}
protected void setColumnLabel(ColumnMeta columnMeta, int column)
{
if (this.columnLabels == null || (column - 1) >= this.columnLabels.length)
return;
columnMeta.setLabel(this.columnLabels[column - 1]);
}
/**
@ -700,4 +719,9 @@ public class SqlDataSetFactory extends AbstractDataSetFactory
{
return PARAMETER_SQL_RESOLVER.resolve(sql);
}
protected ColumnMeta createColumnMeta()
{
return new ColumnMeta();
}
}

View File

@ -13,6 +13,7 @@ import java.util.List;
import java.util.Map;
import org.datagear.analysis.ColumnMeta;
import org.datagear.analysis.DataCategory;
import org.datagear.analysis.DataSet;
import org.datagear.analysis.DataSetMeta;
import org.datagear.analysis.DataSetParam;
@ -67,7 +68,8 @@ public class SqlDataSetFactoryTest extends DBTestSupport
dataSetParams.add(new DataSetParam("id", DataType.INTEGER, true));
dataSetParams.add(new DataSetParam("name", DataType.STRING, true));
SqlDataSetFactory sqlDataSetFactory = new SqlDataSetFactory("1", connectionFactory, sql);
SqlDataSetFactory sqlDataSetFactory = new SqlDataSetFactory("1", connectionFactory, sql,
new DataCategory[] { DataCategory.DIMENSION, DataCategory.SCALAR });
sqlDataSetFactory.setParams(dataSetParams);
sqlDataSetFactory.setColumnLabels(columnLabels);
@ -87,6 +89,7 @@ public class SqlDataSetFactoryTest extends DBTestSupport
Assert.assertEquals("ID", columnMeta.getName());
Assert.assertEquals(DataType.INTEGER, columnMeta.getDataType());
Assert.assertEquals(DataCategory.DIMENSION, columnMeta.getDataCategory());
Assert.assertEquals(columnLabels[0], columnMeta.getLabel());
}
@ -95,6 +98,7 @@ public class SqlDataSetFactoryTest extends DBTestSupport
Assert.assertEquals("NAME", columnMeta.getName());
Assert.assertEquals(DataType.STRING, columnMeta.getDataType());
Assert.assertEquals(DataCategory.SCALAR, columnMeta.getDataCategory());
Assert.assertEquals(columnLabels[1], columnMeta.getLabel());
}

View File

@ -9,6 +9,7 @@ package org.datagear.management.domain;
import java.util.Date;
import org.datagear.analysis.DataCategory;
import org.datagear.analysis.support.SqlDataSetFactory;
import org.datagear.util.resource.ConnectionFactory;
@ -23,6 +24,8 @@ public class SqlDataSetFactoryEntity extends SqlDataSetFactory
{
private static final long serialVersionUID = 1L;
public static final String SPLITTER = ",";
/** 授权资源类型 */
public static final String AUTHORIZATION_RESOURCE_TYPE = "DataSet";
@ -44,10 +47,10 @@ public class SqlDataSetFactoryEntity extends SqlDataSetFactory
this.createTime = new Date();
}
public SqlDataSetFactoryEntity(String id, SchemaConnectionFactory connectionFactory, String sql, String name,
User createUser)
public SqlDataSetFactoryEntity(String id, SchemaConnectionFactory connectionFactory, String sql,
DataCategory[] dataCategories, String name, User createUser)
{
super(id, connectionFactory, sql);
super(id, connectionFactory, sql, dataCategories);
this.name = name;
this.createTime = new Date();
}
@ -87,6 +90,73 @@ public class SqlDataSetFactoryEntity extends SqlDataSetFactory
this.name = name;
}
public String getDataCategoriesText()
{
StringBuilder sb = new StringBuilder();
DataCategory[] dataCategories = getDataCategories();
if (dataCategories != null)
{
for (int i = 0; i < dataCategories.length; i++)
{
if (i > 0)
sb.append(SPLITTER + " ");
sb.append(dataCategories[i].name());
}
}
return sb.toString();
}
public void setDataCategoriesText(String dataCategoriesText)
{
String[] texts = split(dataCategoriesText);
DataCategory[] dataCategories = new DataCategory[texts.length];
for (int i = 0; i < texts.length; i++)
{
String text = texts[i].trim();
if (DataCategory.DIMENSION.name().equalsIgnoreCase(text))
dataCategories[i] = DataCategory.DIMENSION;
else if (DataCategory.SCALAR.name().equalsIgnoreCase(text))
dataCategories[i] = DataCategory.SCALAR;
else
throw new IllegalArgumentException("illegal data categories text [" + dataCategoriesText + "]");
}
setDataCategories(dataCategories);
}
public String getColumnLabelsText()
{
StringBuilder sb = new StringBuilder();
String[] columnLabels = getColumnLabels();
if (columnLabels != null)
{
for (int i = 0; i < columnLabels.length; i++)
{
if (i > 0)
sb.append(SPLITTER + " ");
sb.append(columnLabels[i]);
}
}
return sb.toString();
}
public void setColumnLabelsText(String columnLabelsText)
{
String[] texts = split(columnLabelsText);
setColumnLabels(texts);
}
@Override
public User getCreateUser()
{
@ -120,4 +190,20 @@ public class SqlDataSetFactoryEntity extends SqlDataSetFactory
{
this.dataPermission = dataPermission;
}
protected String[] split(String texts)
{
texts = texts.trim();
if (texts.startsWith(SPLITTER))
texts = texts.substring(SPLITTER.length());
if (texts.endsWith(SPLITTER))
texts = texts.substring(0, texts.length() - SPLITTER.length());
String[] array = texts.split(SPLITTER);
for (int i = 0; i < array.length; i++)
array[i] = array[i].trim();
return array;
}
}

View File

@ -170,6 +170,8 @@ CREATE TABLE DATAGEAR_SQL_DATA_SET_FACTORY
DSF_NAME VARCHAR(100) NOT NULL,
DSF_SCHEMA_ID VARCHAR(50) NOT NULL,
DSF_SQL VARCHAR(1000) NOT NULL,
DSF_DC_TEXT VARCHAR(500) NOT NULL,
DSF_CL_TEXT VARCHAR(500),
DSF_CREATE_USER_ID VARCHAR(50),
DSF_CREATE_TIME TIMESTAMP,
PRIMARY KEY (DSF_ID)

View File

@ -6,13 +6,13 @@
<insert id="insert">
INSERT INTO DATAGEAR_SQL_DATA_SET_FACTORY
(
DSF_ID, DSF_NAME, DSF_SCHEMA_ID, DSF_SQL, DSF_CREATE_USER_ID,
DSF_CREATE_TIME
DSF_ID, DSF_NAME, DSF_SCHEMA_ID, DSF_SQL, DSF_DC_TEXT,
DSF_CL_TEXT, DSF_CREATE_USER_ID, DSF_CREATE_TIME
)
VALUES
(
#{entity.id}, #{entity.name}, #{entity.schemaConnectionFactory.schema.id}, #{entity.sql}, #{entity.createUser.id},
#{entity.createTime}
#{entity.id}, #{entity.name}, #{entity.schemaConnectionFactory.schema.id}, #{entity.sql}, #{entity.dataCategoriesText},
#{entity.columnLabelsText, jdbcType=VARCHAR}, #{entity.createUser.id}, #{entity.createTime}
)
</insert>
@ -20,7 +20,9 @@
UPDATE DATAGEAR_SQL_DATA_SET_FACTORY SET
DSF_NAME = #{entity.name},
DSF_SCHEMA_ID = #{entity.schemaConnectionFactory.schema.id},
DSF_SQL = #{entity.sql}
DSF_SQL = #{entity.sql},
DSF_DC_TEXT = #{entity.dataCategoriesText},
DSF_CL_TEXT = #{entity.columnLabelsText, jdbcType=VARCHAR}
WHERE
DSF_ID = #{entity.id}
</update>
@ -137,6 +139,8 @@
B.SCHEMA_ID AS ${_iq_}schemaConnectionFactory.schema.id${_iq_},
B.SCHEMA_TITLE AS ${_iq_}schemaConnectionFactory.schema.title${_iq_},
A.DSF_SQL AS ${_iq_}sql${_iq_},
A.DSF_DC_TEXT AS ${_iq_}dataCategoriesText${_iq_},
A.DSF_CL_TEXT AS ${_iq_}columnLabelsText${_iq_},
<include refid="common.fieldsForCreateUser" />,
A.DSF_CREATE_TIME AS ${_iq_}createTime${_iq_}
FROM

View File

@ -617,12 +617,18 @@ dataSet.selectDataSet=\u9009\u62E9\u6570\u636E\u96C6
dataSet.name=\u540D\u79F0
dataSet.dataSource=\u6570\u636E\u6E90
dataSet.sql=SQL\u8BED\u53E5
dataSet.dataCategories=SQL\u5217\u7C7B\u522B\u96C6
dataSet.columnLabels=SQL\u5217\u6807\u7B7E\u96C6
dataSet.createUser=\u521B\u5EFA\u7528\u6237
dataSet.createTime=\u521B\u5EFA\u65F6\u95F4
dataSet.loadMoreData=\u52A0\u8F7D\u66F4\u591A\u6570\u636E
dataSet.refreshSqlResult=\u5237\u65B0\u67E5\u8BE2\u7ED3\u679C
dataSet.noMoreData=\u6CA1\u6709\u66F4\u591A\u6570\u636E\u4E86
dataSet.sqlPreviewButtonTip=\u9884\u89C8SQL\u67E5\u8BE2\u7ED3\u679C\uFF08\u7F16\u8F91\u533A\uFF1ACtrl+Enter\uFF09
dataSet.DataCategory.DIMENSION=\u7EF4\u5EA6
dataSet.DataCategory.SCALAR=\u91CF\u5EA6
dataSet.dataCategoriesSplitByComma=\u591A\u4E2A\u7C7B\u522B\u4EE5\u82F1\u6587\u9017\u53F7\uFF08,\uFF09\u5206\u9694
dataSet.columnLabelsSplitByComma=\u591A\u4E2A\u6807\u7B7E\u4EE5\u82F1\u6587\u9017\u53F7\uFF08,\uFF09\u5206\u9694
#Chart
chart.manageChart=\u7BA1\u7406\u56FE\u8868

View File

@ -65,6 +65,23 @@ readonly 是否只读操作允许为null
</#if>
</div>
</div>
<div class="form-item">
<div class="form-item-label">
<label><@spring.message code='dataSet.dataCategories' /></label>
</div>
<div class="form-item-value">
<input type="hidden" name="dataCategoriesText" value="${(dataSet.dataCategoriesText)!''?html}" />
<input type="text" name="dataCategoriesTextLabel" class="ui-widget ui-widget-content" value="" placeholder="<@spring.message code='dataSet.dataCategoriesSplitByComma' />" />
</div>
</div>
<div class="form-item">
<div class="form-item-label">
<label><@spring.message code='dataSet.columnLabels' /></label>
</div>
<div class="form-item-value">
<input type="text" name="columnLabelsText" class="ui-widget ui-widget-content" value="${(dataSet.columnLabelsText)!''?html}" placeholder="<@spring.message code='dataSet.columnLabelsSplitByComma' />" />
</div>
</div>
</div>
<div class="form-foot" style="text-align:center;">
<#if !readonly>
@ -82,7 +99,7 @@ readonly 是否只读操作允许为null
(function(po)
{
$.initButtons(po.element());
var sqlEditorHeight = $(window).height()/5*2;
var sqlEditorHeight = $(window).height()/10*3;
po.element(".sql-editor-wrapper").height(sqlEditorHeight);
po.element(".sql-preview-wrapper").height(sqlEditorHeight);
po.element(".form-item-value-sql").height(sqlEditorHeight + 25);
@ -109,6 +126,48 @@ readonly 是否只读操作允许为null
po.sqlEditor.setReadOnly(true);
</#if>
po.dataCategoriesLabels = ["<@spring.message code='dataSet.DataCategory.DIMENSION' />", "<@spring.message code='dataSet.DataCategory.SCALAR' />"];
po.dataCategoriesValues = ["DIMENSION", "SCALAR"];
po.splitByComma = function(val)
{
return val.split(/,\s*/);
};
po.convertCommaText = function(srcAry, destAry, srcText)
{
if(!srcText)
return "";
var destText = "";
var srcs = po.splitByComma(srcText);
for(var i=0; i<srcs.length; i++)
{
var srcIdx = -1;
for(var j=0; j<srcAry.length; j++)
{
if(srcAry[j] == srcs[i])
{
srcIdx = j;
break;
}
}
if(srcIdx> -1)
{
if(destText != "")
destText += ", ";
destText += destAry[srcIdx];
}
}
return destText;
};
var dataCategoriesText = po.element("input[name='dataCategoriesText']").val();
po.element("input[name='dataCategoriesTextLabel']").attr("value",
po.convertCommaText(po.dataCategoriesValues, po.dataCategoriesLabels, dataCategoriesText));
<#if !readonly>
po.element(".select-schema-button").click(function()
{
@ -230,7 +289,7 @@ readonly 是否只读操作允许为null
var newColumns = [
{
title : "<@spring.message code='rowNumber' />", data : "", defaultContent: "",
render : po.renderRowNumberColumn, className : "column-row-number", width : "5em"
render : po.renderRowNumberColumn, className : "column-row-number", width : "3em"
}
];
newColumns = newColumns.concat(columns);
@ -285,6 +344,42 @@ readonly 是否只读操作允许为null
});
};
po.extractLastDataCategoryText = function(term)
{
return po.splitByComma(term).pop();
};
po.element("input[name='dataCategoriesTextLabel']")
.on("keydown", function()
{
if (event.keyCode === $.ui.keyCode.TAB && $(this).autocomplete( "instance" ).menu.active)
event.preventDefault();
})
.on("focus", function()
{
$(this).autocomplete("search", "");
})
.autocomplete(
{
minLength: 0,
source: function(request,response)
{
response($.ui.autocomplete.filter(po.dataCategoriesLabels, po.extractLastDataCategoryText(request.term)));
},
focus: function()
{
return false;
},
select: function(event, ui)
{
var terms = po.splitByComma(this.value);
terms.pop();
terms.push(ui.item.value);
this.value = terms;
return false;
}
});
$.validator.addMethod("dataSetSqlRequired", function(value, element)
{
var sql = po.sqlEditor.getValue();
@ -299,17 +394,23 @@ readonly 是否只读操作允许为null
"name" : "required",
"schemaConnectionFactory.schema.title" : "required",
"sql" : "dataSetSqlRequired",
"dataCategoriesTextLabel" : "required"
},
messages :
{
"name" : "<@spring.message code='validation.required' />",
"schemaConnectionFactory.schema.title" : "<@spring.message code='validation.required' />",
"sql" : "<@spring.message code='validation.required' />"
"sql" : "<@spring.message code='validation.required' />",
"dataCategoriesTextLabel" : "<@spring.message code='validation.required' />"
},
submitHandler : function(form)
{
po.element("textarea[name='sql']").val(po.sqlEditor.getValue());
var dataCategoriesTextLabel = po.element("input[name='dataCategoriesTextLabel']").val();
po.element("input[name='dataCategoriesText']").val(
po.convertCommaText(po.dataCategoriesLabels, po.dataCategoriesValues, dataCategoriesTextLabel));
$(form).ajaxSubmit(
{
success : function()

View File

@ -110,7 +110,8 @@ form .form-content .form-item .form-item-value .input{
vertical-align: middle;
}
form .form-content .form-item .form-item-value input[type=text],
form .form-content .form-item .form-item-value input[type=password]{
form .form-content .form-item .form-item-value input[type=password],
form .form-content .form-item .form-item-value .input{
height: 1.5em;
}
form .form-content .form-item .form-item-value textarea{