Esempio n. 1
0
  public static void chartVariables(String chartId, int page, String encoded) {
    ChartInfo chart = ChartUtil.fetchChart(chartId);
    if (page < 0 || page >= chart.getChartMeta().getPages().size())
      notFound("this page is not found");
    ChartPageMeta pageMeta = chart.getChartMeta().getPages().get(page);
    if (!"start".equals(encoded)) {
      Map<String, String> variables = ChartUtil.decodeVariables(encoded);
      for (ChartVarMeta var : pageMeta.getVariables()) {
        String value = variables.get(var.getNameInJavascript());
        var.setValue(value);
      }
    }

    String subtitle = "(" + (page + 1) + " of " + chart.getChartMeta().getPages().size() + ")";
    boolean isLastPage = false;
    if (page == chart.getChartMeta().getPages().size() - 1) isLastPage = true;
    render(chart, pageMeta, chartId, page, encoded, isLastPage, subtitle);
  }
Esempio n. 2
0
  public static void postVariables(String chartId, int page, String encoded) {
    ChartInfo chart = ChartUtil.fetchChart(chartId);

    Map<String, String[]> paramMap = params.all();
    Map<String, String> variablesMap = ChartUtil.decodeVariables(encoded);
    for (String key : paramMap.keySet()) {
      if (key.startsWith("chart.")) {
        String[] values = paramMap.get(key);
        String value = values[0];
        String javascriptKey = key.substring("chart.".length());
        if (javascriptKey.endsWith("url")) value = stripOffHost(value);
        variablesMap.put(javascriptKey, value);
      }
    }

    encoded = ChartUtil.encodeVariables(variablesMap);

    page = page + 1;
    if (page >= chart.getChartMeta().getPages().size()) drawChart(chartId, encoded);
    else chartVariables(chartId, page, encoded);
  }