Ejemplo n.º 1
0
  @Override
  public void doService(ToolPageContext page) throws IOException, ServletException {
    ToolUser user = page.getUser();
    Dashboard dashboard = user.getDashboard();
    String dashboardId = "user";

    if (dashboard == null) {
      ToolRole role = user.getRole();

      if (role != null) {
        dashboard = role.getDashboard();
        dashboardId = "role";
      }
    }

    if (dashboard == null) {
      dashboard = page.getCmsTool().getDefaultDashboard();
      dashboardId = "tool";
    }

    if (dashboard == null) {
      dashboard = Dashboard.createDefaultDashboard();
      dashboardId = "default";
    }

    page.writeHeader();
    page.writeStart("div", "class", "dashboard-columns");
    List<DashboardColumn> columns = dashboard.getColumns();
    double totalWidth = 0;

    for (DashboardColumn column : columns) {
      double width = column.getWidth();
      totalWidth += width > 0 ? width : 1;
    }

    CmsTool cms = Query.from(CmsTool.class).first();
    Set<String> disabled = cms != null ? cms.getDisabledPlugins() : Collections.emptySet();

    for (int c = 0, cSize = columns.size(); c < cSize; ++c) {
      DashboardColumn column = columns.get(c);
      double width = column.getWidth();

      page.writeStart(
          "div",
          "class",
          "dashboard-column",
          "style",
          page.cssString("width", ((width > 0 ? width : 1) / totalWidth * 100) + "%"));

      List<DashboardWidget> widgets = column.getWidgets();

      for (int w = 0, wSize = widgets.size(); w < wSize; ++w) {
        DashboardWidget widget = widgets.get(w);

        if (disabled.contains(widget.getClass().getName())) {
          continue;
        }

        String widgetUrl =
            page.toolUrl(
                CmsTool.class,
                "/dashboardWidget/"
                    + dashboardId
                    + "/"
                    + widget.getClass().getName()
                    + "/"
                    + widget.getId());

        page.writeStart(
            "div", "class", "frame dashboard-widget", "data-dashboard-widget-url", widgetUrl);
        page.writeStart("a", "href", widgetUrl);
        page.writeEnd();
        page.writeEnd();
      }
      page.writeEnd();
    }
    page.writeEnd();
    page.writeFooter();
  }