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.title}
+
+ + + +
+
+
{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 ( +
    +
    + +
    +