You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GlobalDefaultDashboard.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * SonarQube, open source software quality management tool.
  3. * Copyright (C) 2008-2014 SonarSource
  4. * mailto:contact AT sonarsource DOT com
  5. *
  6. * SonarQube is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * SonarQube is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.server.dashboard.template;
  21. import org.sonar.api.web.Dashboard;
  22. import org.sonar.api.web.DashboardLayout;
  23. import org.sonar.api.web.DashboardTemplate;
  24. import org.sonar.db.measure.MeasureFilterDao;
  25. import org.sonar.db.measure.MeasureFilterDto;
  26. import org.sonar.server.dashboard.widget.MeasureFilterAsTreemapWidget;
  27. import org.sonar.server.dashboard.widget.MeasureFilterListWidget;
  28. import org.sonar.server.dashboard.widget.WelcomeWidget;
  29. import org.sonar.server.measure.template.MyFavouritesFilter;
  30. import org.sonar.server.measure.template.ProjectFilter;
  31. /**
  32. * Projects global dashboard for Sonar
  33. *
  34. * @since 3.1
  35. */
  36. public final class GlobalDefaultDashboard extends DashboardTemplate {
  37. private MeasureFilterDao filterDao;
  38. public GlobalDefaultDashboard(MeasureFilterDao filterDao) {
  39. this.filterDao = filterDao;
  40. }
  41. @Override
  42. public Dashboard createDashboard() {
  43. Dashboard dashboard = Dashboard.create()
  44. .setGlobal(true)
  45. .setLayout(DashboardLayout.TWO_COLUMNS);
  46. dashboard.addWidget(WelcomeWidget.ID, 1);
  47. addMyFavouritesWidget(dashboard);
  48. addProjectsWidgets(dashboard);
  49. return dashboard;
  50. }
  51. private void addMyFavouritesWidget(Dashboard dashboard) {
  52. MeasureFilterDto filter = findSystemFilter(MyFavouritesFilter.NAME);
  53. if (filter != null) {
  54. dashboard
  55. .addWidget(MeasureFilterListWidget.ID, 1)
  56. .setProperty(MeasureFilterListWidget.FILTER_PROPERTY, filter.getId().toString())
  57. .setProperty(MeasureFilterListWidget.PAGE_SIZE_PROPERTY, "50");
  58. }
  59. }
  60. private void addProjectsWidgets(Dashboard dashboard) {
  61. MeasureFilterDto filter = findSystemFilter(ProjectFilter.NAME);
  62. if (filter != null) {
  63. dashboard
  64. .addWidget(MeasureFilterListWidget.ID, 2)
  65. .setProperty(MeasureFilterListWidget.FILTER_PROPERTY, filter.getId().toString())
  66. .setProperty(MeasureFilterListWidget.PAGE_SIZE_PROPERTY, "20");
  67. dashboard
  68. .addWidget(MeasureFilterAsTreemapWidget.ID, 2)
  69. .setProperty(MeasureFilterListWidget.FILTER_PROPERTY, filter.getId().toString())
  70. .setProperty(MeasureFilterAsTreemapWidget.SIZE_METRIC_PROPERTY, "ncloc")
  71. .setProperty(MeasureFilterAsTreemapWidget.COLOR_METRIC_PROPERTY, "coverage");
  72. }
  73. }
  74. @Override
  75. public String getName() {
  76. return "Home";
  77. }
  78. private MeasureFilterDto findSystemFilter(String name) {
  79. return filterDao.findSystemFilterByName(name);
  80. }
  81. }