diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/Dispatcher.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/Dispatcher.java index aefad27ddf..2030597b99 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/Dispatcher.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/Dispatcher.java @@ -54,6 +54,7 @@ import com.google.gerrit.client.admin.GroupListScreen; import com.google.gerrit.client.admin.PluginListScreen; import com.google.gerrit.client.admin.ProjectAccessScreen; import com.google.gerrit.client.admin.ProjectBranchesScreen; +import com.google.gerrit.client.admin.ProjectDashboardsScreen; import com.google.gerrit.client.admin.ProjectInfoScreen; import com.google.gerrit.client.admin.ProjectListScreen; import com.google.gerrit.client.admin.ProjectScreen; @@ -729,6 +730,10 @@ public class Dispatcher { if (ProjectScreen.ACCESS.equals(panel)) { return new ProjectAccessScreen(k); } + + if (ProjectScreen.DASHBOARDS.equals(panel)) { + return new ProjectDashboardsScreen(k); + } } return new NotFoundScreen(); } diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/AdminConstants.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/AdminConstants.java index 277d7545ae..a5b5027622 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/AdminConstants.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/AdminConstants.java @@ -106,6 +106,7 @@ public interface AdminConstants extends Constants { String projectAdminTabBranches(); String projectAdminTabAccess(); String projectListQueryLink(); + String projectAdminTabDashboards(); String plugins(); String pluginEnabled(); diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/AdminConstants.properties b/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/AdminConstants.properties index 08c6cce3a7..82c9b40d37 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/AdminConstants.properties +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/AdminConstants.properties @@ -85,6 +85,7 @@ createProjectTitle = Create Project projectAdminTabGeneral = General projectAdminTabBranches = Branches projectAdminTabAccess = Access +projectAdminTabDashboards = Dashboards projectListQueryLink = Search for changes on this project plugins = Plugins diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectDashboardsScreen.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectDashboardsScreen.java new file mode 100644 index 0000000000..802e1ceab1 --- /dev/null +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectDashboardsScreen.java @@ -0,0 +1,59 @@ +// Copyright (C) 2012 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.gerrit.client.admin; + +import com.google.gerrit.client.dashboards.DashboardMap; +import com.google.gerrit.client.dashboards.DashboardsTable; +import com.google.gerrit.client.rpc.ScreenLoadCallback; +import com.google.gerrit.reviewdb.client.Project; + +import com.google.gwt.user.client.ui.FlowPanel; + +public class ProjectDashboardsScreen extends ProjectScreen { + private DashboardsTable dashes; + + public ProjectDashboardsScreen(final Project.NameKey toShow) { + super(toShow); + } + + @Override + protected void onLoad() { + super.onLoad(); + DashboardMap.allOnProject(getProjectKey(), + new ScreenLoadCallback(this) { + @Override + protected void preDisplay(final DashboardMap result) { + dashes.display(result); + } + }); + } + + @Override + protected void onInitUI() { + super.onInitUI(); + dashes = new DashboardsTable(); + FlowPanel fp = new FlowPanel(); + fp.add(dashes); + add(fp); + dashes.setSavePointerId("dashboards/project/" + getProjectKey().get()); + display(); + } + + @Override + public void registerKeys() { + super.registerKeys(); + dashes.setRegisterKeys(true); + } +} diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectScreen.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectScreen.java index dd5b070bfd..964dda7930 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectScreen.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectScreen.java @@ -23,6 +23,7 @@ public abstract class ProjectScreen extends MenuScreen { public static final String INFO = "info"; public static final String BRANCH = "branches"; public static final String ACCESS = "access"; + public static final String DASHBOARDS = "dashboards"; private final Project.NameKey name; @@ -32,6 +33,7 @@ public abstract class ProjectScreen extends MenuScreen { link(Util.C.projectAdminTabGeneral(), toProjectAdmin(name, INFO)); link(Util.C.projectAdminTabBranches(), toProjectAdmin(name, BRANCH)); link(Util.C.projectAdminTabAccess(), toProjectAdmin(name, ACCESS)); + link(Util.C.projectAdminTabDashboards(), toProjectAdmin(name, DASHBOARDS)); } protected Project.NameKey getProjectKey() { diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/dashboards/DashboardConstants.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/dashboards/DashboardConstants.java new file mode 100644 index 0000000000..1a7b2680a9 --- /dev/null +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/dashboards/DashboardConstants.java @@ -0,0 +1,25 @@ +// Copyright (C) 2012 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.gerrit.client.dashboards; + +import com.google.gwt.i18n.client.Constants; + +import java.util.Map; + +public interface DashboardConstants extends Constants { + String dashboardName(); + String dashboardDescription(); + String dashboardItem(); +} diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/dashboards/DashboardConstants.properties b/gerrit-gwtui/src/main/java/com/google/gerrit/client/dashboards/DashboardConstants.properties new file mode 100644 index 0000000000..548b391ae7 --- /dev/null +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/dashboards/DashboardConstants.properties @@ -0,0 +1,3 @@ +dashboardName = Dashboard Name +dashboardDescription = Dashboard Description +dashboardItem = dashboard diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/dashboards/DashboardsTable.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/dashboards/DashboardsTable.java new file mode 100644 index 0000000000..f5b0822131 --- /dev/null +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/dashboards/DashboardsTable.java @@ -0,0 +1,112 @@ +// Copyright (C) 2012 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.gerrit.client.dashboards; + +import com.google.gerrit.client.ui.NavigationTable; +import com.google.gerrit.client.Gerrit; +import com.google.gwt.user.client.History; +import com.google.gwt.user.client.ui.Anchor; +import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter; + +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +public class DashboardsTable extends NavigationTable { + public DashboardsTable() { + super(Util.C.dashboardItem()); + initColumnHeaders(); + } + + protected void initColumnHeaders() { + table.setText(0, 1, Util.C.dashboardName()); + table.setText(0, 2, Util.C.dashboardDescription()); + + final FlexCellFormatter fmt = table.getFlexCellFormatter(); + fmt.addStyleName(0, 1, Gerrit.RESOURCES.css().dataHeader()); + fmt.addStyleName(0, 2, Gerrit.RESOURCES.css().dataHeader()); + } + + public void display(DashboardMap dashes) { + while (1 < table.getRowCount()) { + table.removeRow(table.getRowCount() - 1); + } + + List list = dashes.values().asList(); + Collections.sort(list, new Comparator() { + @Override + public int compare(DashboardInfo a, DashboardInfo b) { + return a.id().compareTo(b.id()); + } + }); + + String section = null; + for(DashboardInfo d : list) { + if (!d.refName().equals(section)) { + section = d.refName(); + insertTitleRow(table.getRowCount(), section); + } + insert(table.getRowCount(), d); + } + + finishDisplay(); + } + + protected void insertTitleRow(final int row, String section) { + table.insertRow(row); + + table.setText(row, 0, section); + + final FlexCellFormatter fmt = table.getFlexCellFormatter(); + fmt.setColSpan(row, 0, 3); + fmt.addStyleName(row, 0, Gerrit.RESOURCES.css().sectionHeader()); + } + + protected void insert(final int row, final DashboardInfo k) { + table.insertRow(row); + + applyDataRowStyle(row); + + final FlexCellFormatter fmt = table.getFlexCellFormatter(); + fmt.addStyleName(row, 1, Gerrit.RESOURCES.css().dataCell()); + fmt.addStyleName(row, 2, Gerrit.RESOURCES.css().dataCell()); + + populate(row, k); + } + + protected void populate(final int row, final DashboardInfo k) { + table.setWidget(row, 1, new Anchor(k.name(), "#" + link(k))); + table.setText(row, 2, k.description()); + + setRowItem(row, k); + } + + @Override + protected Object getRowItemKey(final DashboardInfo item) { + return item.name(); + } + + @Override + protected void onOpenRow(final int row) { + if (row > 0) { + movePointerTo(row); + } + History.newItem(link(getRowItem(row))); + } + + private String link(final DashboardInfo item) { + return "/dashboard/?" + item.parameters(); + } +} diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/dashboards/Util.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/dashboards/Util.java new file mode 100644 index 0000000000..b15bf734ad --- /dev/null +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/dashboards/Util.java @@ -0,0 +1,21 @@ +// Copyright (C) 2012 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.gerrit.client.dashboards; + +import com.google.gwt.core.client.GWT; + +public class Util { + public static final DashboardConstants C = GWT.create(DashboardConstants.class); +}