diff --git a/src/main/java/com/rebuild/web/dashboard/ChartDesignControll.java b/src/main/java/com/rebuild/web/dashboard/ChartDesignControll.java
index 819ee2000..3ec18a591 100644
--- a/src/main/java/com/rebuild/web/dashboard/ChartDesignControll.java
+++ b/src/main/java/com/rebuild/web/dashboard/ChartDesignControll.java
@@ -18,25 +18,34 @@ along with this program. If not, see .
package com.rebuild.web.dashboard;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
import com.rebuild.server.Application;
+import com.rebuild.server.metadata.EntityHelper;
import com.rebuild.server.metadata.MetadataHelper;
import com.rebuild.server.metadata.MetadataSorter;
import com.rebuild.server.metadata.entityhub.DisplayType;
import com.rebuild.server.metadata.entityhub.EasyMeta;
+import com.rebuild.utils.JSONUtils;
import com.rebuild.web.BadParameterException;
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;
/**
@@ -67,6 +76,7 @@ public class ChartDesignControll extends BaseControll {
entityMeta = MetadataHelper.getEntity((String) config[0]);
} else if (entity != null) {
+ mv.getModel().put("chartConfig", "{}");
entityMeta = MetadataHelper.getEntity(entity);
} else {
throw new BadParameterException();
@@ -91,5 +101,35 @@ public class ChartDesignControll extends BaseControll {
return mv;
}
-
+ @RequestMapping("/chart-save")
+ public void chartSave(HttpServletRequest request, HttpServletResponse response) throws IOException {
+ ID user = getRequestUser(request);
+ JSON formJson = ServletUtils.getRequestJson(request);
+
+ Record record = EntityHelper.parse((JSONObject) formJson, user);
+ ID dashid = null;
+ if (record.getPrimary() == null) {
+ dashid = getIdParameterNotNull(request, "dashid");
+ }
+ record = Application.getCommonService().createOrUpdate(record);
+
+ // 添加到仪表盘
+ if (dashid != null) {
+ Object[] dash = Application.createQuery(
+ "select config from DashboardConfig where dashboardId = ?")
+ .setParameter(1, dashid)
+ .unique();
+ JSONArray config = JSON.parseArray((String) dash[0]);
+
+ JSONObject item = JSONUtils.toJSONObject("chart", record.getPrimary().toLiteral());
+ config.add(item);
+
+ Record record2 = EntityHelper.forUpdate(dashid, getRequestUser(request));
+ record2.setString("config", config.toJSONString());
+ Application.getCommonService().createOrUpdate(record2);
+ }
+
+ JSONObject ret = JSONUtils.toJSONObject("id", record.getPrimary().toLiteral());
+ writeSuccess(response, ret);
+ }
}
diff --git a/src/main/java/com/rebuild/web/dashboard/DashboardControll.java b/src/main/java/com/rebuild/web/dashboard/DashboardControll.java
index f0762a595..e0727e6fb 100644
--- a/src/main/java/com/rebuild/web/dashboard/DashboardControll.java
+++ b/src/main/java/com/rebuild/web/dashboard/DashboardControll.java
@@ -18,14 +18,24 @@ along with this program. If not, see .
package com.rebuild.web.dashboard;
+import java.io.IOException;
+
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
+import com.alibaba.fastjson.JSON;
+import com.rebuild.server.Application;
+import com.rebuild.server.metadata.EntityHelper;
import com.rebuild.web.BaseControll;
+import cn.devezhao.commons.web.ServletUtils;
+import cn.devezhao.persist4j.Record;
+import cn.devezhao.persist4j.engine.ID;
+
/**
*
* @author zhaofang123@gmail.com
@@ -39,4 +49,37 @@ public class DashboardControll extends BaseControll {
public ModelAndView pageHome(HttpServletRequest request) {
return createModelAndView("/dashboard/home.jsp");
}
+
+ @RequestMapping("/dash-gets")
+ public void dashGets(HttpServletRequest request, HttpServletResponse response) throws IOException {
+ ID user = getRequestUser(request);
+ Object[][] array = Application.createQuery(
+ "select dashboardId,title,config from DashboardConfig where createdBy = ?")
+ .setParameter(1, user)
+ .array();
+
+ // 没有就初始化一个
+ if (array.length == 0) {
+ Record record = EntityHelper.forNew(EntityHelper.DashboardConfig, user);
+ String dname = "默认仪表盘";
+ record.setString("title", dname);
+ record.setString("config", "[]");
+ record = Application.getCommonService().create(record);
+ array = new Object[][] { new Object[] { record.getPrimary(), dname, null } };
+ }
+
+ writeSuccess(response, array);
+ }
+
+ @RequestMapping("/dash-save")
+ public void dashSave(HttpServletRequest request, HttpServletResponse response) throws IOException {
+ ID dashid = getIdParameterNotNull(request, "id");
+ ID user = getRequestUser(request);
+ JSON config = ServletUtils.getRequestJson(request);
+
+ Record record = EntityHelper.forUpdate(dashid, user);
+ record.setString("config", config.toJSONString());
+ Application.getCommonService().update(record);
+ writeSuccess(response);
+ }
}
diff --git a/src/main/webapp/assets/css/charts.css b/src/main/webapp/assets/css/charts.css
index 19275d70b..3d4b5fb60 100644
--- a/src/main/webapp/assets/css/charts.css
+++ b/src/main/webapp/assets/css/charts.css
@@ -1,13 +1,25 @@
+.chart-box {
+ height: 100%;
+}
+
+.chart-box .chart-body {
+ height: 100%;
+ margin-top: -20px;
+ z-index: 1;
+}
+
.chart-box .chart-head {
position: relative;
margin: 0;
+ z-index: 2;
+ background-color: #fff;
}
.chart-box .chart-head .chart-title {
cursor: move;
- background-color: red;
margin-right: 80px;
font-weight: bold;
+ min-height: 20px;
}
.chart-box .chart-head .chart-oper {
diff --git a/src/main/webapp/assets/js/charts/chart-design.jsx b/src/main/webapp/assets/js/charts/chart-design.jsx
index f5a095e7f..4b7cd517b 100644
--- a/src/main/webapp/assets/js/charts/chart-design.jsx
+++ b/src/main/webapp/assets/js/charts/chart-design.jsx
@@ -33,7 +33,7 @@ $(document).ready(() => {
_data.metadata = { entity: 'ChartConfig', id: window.__chartId }
console.log(JSON.stringify(_data))
- $.post(rb.baseUrl + '/app/entity/record-save', JSON.stringify(_data), function(res){
+ $.post(rb.baseUrl + '/dashboard/chart-save?dashid=' + $urlp('dashid'), JSON.stringify(_data), function(res){
if (res.error_code == 0){
window.__chartId = res.data.id
}
diff --git a/src/main/webapp/assets/js/charts/charts.jsx b/src/main/webapp/assets/js/charts/charts.jsx
index 861e20b74..7687170b7 100644
--- a/src/main/webapp/assets/js/charts/charts.jsx
+++ b/src/main/webapp/assets/js/charts/charts.jsx
@@ -1,6 +1,26 @@
class BaseChart extends React.Component {
constructor(props) {
super(props)
+ this.state = {}
+ }
+ render() {
+ return (
+
+
{this.state.chartbox || }
+
)
+ }
+ componentDidMount() {
+ // TODO 获取数据
+// this.renderChart()
+ }
+ renderChart() {
}
}
@@ -9,4 +29,6 @@ class ChartIndex extends BaseChart {
constructor(props) {
super(props)
}
+ renderChart() {
+ }
}
\ No newline at end of file
diff --git a/src/main/webapp/assets/js/charts/dashboard.jsx b/src/main/webapp/assets/js/charts/dashboard.jsx
index 0fa48fa63..b696ed6e4 100644
--- a/src/main/webapp/assets/js/charts/dashboard.jsx
+++ b/src/main/webapp/assets/js/charts/dashboard.jsx
@@ -1,11 +1,63 @@
-let gridster = null
+// $Id$
+let dashid = null
$(document).ready(function(){
- $('.J_add-chart').click(function(){
- rb.modal(rb.baseUrl + '/p/dashboard/chart-new', '添加图表')
- //gridster.add_widget.apply(gridster, ['0', 4, 2])
- })
$(window).trigger('resize')
+ $.get(rb.baseUrl + '/dashboard/dash-gets', ((res) => {
+ let d = res.data[0]
+ $('.J_add-chart').click(() => {
+ renderRbcomp()
+ })
+ dashid = d[0]
+ render_dashboard($.parseJSON(d[2]))
+ }))
+})
+$(window).resize(() => {
+ $('.chart-grid').height($(window).height() - 131)
+})
+
+class DlgAddChart extends React.Component {
+ constructor(props) {
+ super(props)
+ }
+ render() {
+ return (
+
+ )
+ }
+ componentDidMount() {
+ let that = this
+ let sentity = $(this.refs['sentity'])
+ $.get(rb.baseUrl + '/commons/metadata/entities', function(res){
+ $(res.data).each(function(){
+ $('').appendTo(sentity)
+ })
+ that.select2 = sentity.select2({
+ language: 'zh-CN',
+ placeholder: '选择数据源',
+ width: '100%'
+ })
+ })
+ }
+ next() {
+ location.href = rb.baseUrl + '/dashboard/chart-design?source=' + this.select2.val() + '&dashid=' + this.props.dashid
+ }
+}
+
+let gridster = null
+let render_dashboard = function(cfg){
gridster = $('.gridster ul').gridster({
widget_base_dimensions: ['auto', 100],
autogenerate_stylesheet: true,
@@ -14,14 +66,45 @@ $(document).ready(function(){
widget_margins: [5, 5],
resize: {
enabled: true,
- min_size: [2, 2]
+ min_size: [2, 2],
+ stop: function(e, ui, $widget){
+ save_dashboard()
+ }
},
draggable: {
- handle: '.chart-title'
+ handle: '.chart-title',
+ stop: function(e, ui, $widget){
+ save_dashboard()
+ }
+ },
+ serialize_params: function($w, wgd) {
+ return {
+ col: wgd.col,
+ row: wgd.row,
+ size_x: wgd.size_x,
+ size_y: wgd.size_y,
+ chart: $w.data('chart')
+ }
}
}).data('gridster')
-})
+
+ gridster.remove_all_widgets()
+ //cfg = Gridster.sort_by_row_and_col_asc(cfg)
+ $(cfg).each((idx, item)=>{
+ let el = ''
+ gridster.add_widget(el, item.size_x||2, item.size_y||2, item.col||null, item.row||null)
+ })
+
+ $('.gridster li').each(function(){
+ let chartid = $(this).data('chart')
+ renderRbcomp(, 'chart-' + chartid)
+ })
+}
-$(window).resize(() => {
- $('.chart-grid').height($(window).height() - 131)
-})
\ No newline at end of file
+let save_dashboard = function(){
+ let s = gridster.serialize()
+ console.log(s)
+ $.post(rb.baseUrl + '/dashboard/dash-save?id=' + dashid, JSON.stringify(s), ((res) => {
+ console.log(res)
+ }))
+}
\ No newline at end of file
diff --git a/src/main/webapp/assets/js/rb-components.jsx b/src/main/webapp/assets/js/rb-components.jsx
index c5a76b003..1159d04d9 100644
--- a/src/main/webapp/assets/js/rb-components.jsx
+++ b/src/main/webapp/assets/js/rb-components.jsx
@@ -24,7 +24,7 @@ class RbModal extends React.Component {
}
componentDidMount() {
if (this.props.children) this.setState({ inLoad: false })
- this.show()
+ this.show(this.props.onShow)
}
resize() {
if (!!!this.state.url) return // 非 iframe 无需 resize
diff --git a/src/main/webapp/dashboard/chart-new.jsp b/src/main/webapp/dashboard/chart-new.jsp
index 3c35dfce9..328752827 100644
--- a/src/main/webapp/dashboard/chart-new.jsp
+++ b/src/main/webapp/dashboard/chart-new.jsp
@@ -51,7 +51,7 @@ $(document).ready(function(){
$('.btn-primary').click(function(){
let source = $val('#sourceEntity'),
title = $val('#chartTitle')
- parent.location.href = rb.baseUrl + '/dashboard/chart-design?source=' + source + '&title=' + title
+ parent.location.href = rb.baseUrl + '/dashboard/chart-design?source=' + source + '&title=' + title + '&das'
})
})
diff --git a/src/main/webapp/dashboard/home.jsp b/src/main/webapp/dashboard/home.jsp
index f47414c5b..1fca70165 100644
--- a/src/main/webapp/dashboard/home.jsp
+++ b/src/main/webapp/dashboard/home.jsp
@@ -12,6 +12,7 @@
.chart-grid{overflow:scroll;overflow-x:hidden;padding:0 20px;padding-bottom:20px;padding-right:14px}
.gridster ul,.gridster ul>li{margin:0;padding:0}
.gridster ul>li{background-color:#fff;padding:20px 25px;}
+.gridster ul>li>div{height:100%}
.gridster ul>li:hover{box-shadow:0 2px 4px 0 rgba(0, 0, 0, .1), 0 16px 24px 0 rgba(81, 129, 228, .1)}
.gridster ul>li:hover .chart-oper{display:block;}
@@ -38,29 +39,14 @@
<%@ include file="/_include/Foot.jsp"%>
-
+