Add screen that shows all imports of a project
Change-Id: Ia1f850d5ff7fa308648150f211b566495725d144
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportActionPanel.java b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportActionPanel.java
new file mode 100644
index 0000000..408dd89
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportActionPanel.java
@@ -0,0 +1,39 @@
+// Copyright (C) 2015 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.googlesource.gerrit.plugins.importer.client;
+
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.user.client.ui.Button;
+import com.google.gwt.user.client.ui.FlowPanel;
+
+public class ImportActionPanel extends FlowPanel {
+
+ ImportActionPanel(final String project) {
+ setStyleName("importer-action-panel");
+ add(new Button("Resume...", new ClickHandler() {
+ @Override
+ public void onClick(ClickEvent event) {
+ (new ResumeImportDialog(project)).center();
+ }
+ }));
+ add(new Button("Complete...", new ClickHandler() {
+ @Override
+ public void onClick(ClickEvent event) {
+ (new CompleteImportDialog(project)).center();
+ }
+ }));
+ }
+}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportProjectListScreen.java b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportProjectListScreen.java
index acdbd4d..36be3dc 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportProjectListScreen.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportProjectListScreen.java
@@ -19,14 +19,11 @@
import com.google.gerrit.plugin.client.Plugin;
import com.google.gerrit.plugin.client.rpc.RestApi;
import com.google.gerrit.plugin.client.screen.Screen;
-import com.google.gwt.event.dom.client.ClickEvent;
-import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Anchor;
-import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
-import com.google.gwt.user.client.ui.FlowPanel;
+import com.google.gwt.user.client.ui.InlineHyperlink;
import com.google.gwt.user.client.ui.VerticalPanel;
import java.util.List;
@@ -84,11 +81,10 @@
fmt.addStyleName(row, 0, "leftMostCell");
}
- t.setText(row, 0, project);
+ t.setWidget(row, 0, new InlineHyperlink(
+ project, "/x/" + Plugin.get().getName() + "/projects/" + project));
- String srcProjectUrl = ensureSlash(info.from())
- + "#/admin/projects/"
- + (info.name() != null ? info.name() : project);
+ String srcProjectUrl = projectUrl(info, project);
t.setWidget(row, 1, new Anchor(srcProjectUrl, srcProjectUrl));
List<ImportInfo> importList = Natives.asList(info.imports());
@@ -101,21 +97,7 @@
t.setText(row, 3, "N/A");
}
- FlowPanel p = new FlowPanel();
- p.setStyleName("importer-action-panel");
- p.add(new Button("Resume...", new ClickHandler() {
- @Override
- public void onClick(ClickEvent event) {
- (new ResumeImportDialog(project)).center();
- }
- }));
- p.add(new Button("Complete...", new ClickHandler() {
- @Override
- public void onClick(ClickEvent event) {
- (new CompleteImportDialog(project)).center();
- }
- }));
- t.setWidget(row, 4, p);
+ t.setWidget(row, 4, new ImportActionPanel(project));
row++;
}
@@ -123,10 +105,16 @@
add(t);
}
- private static String removeNs(String timestamp) {
+ public static String removeNs(String timestamp) {
return timestamp.substring(0, timestamp.lastIndexOf('.'));
}
+ public static String projectUrl(ImportProjectInfo info, String project) {
+ return ensureSlash(info.from())
+ + "#/admin/projects/"
+ + (info.name() != null ? info.name() : project);
+ }
+
private static String ensureSlash(String in) {
if (in != null && !in.endsWith("/")) {
return in + "/";
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImporterPlugin.java b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImporterPlugin.java
index 10ff0a6..c1e9973 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImporterPlugin.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImporterPlugin.java
@@ -26,5 +26,6 @@
public void onPluginLoad() {
Plugin.get().screen("project", new ImportProjectScreen.Factory());
Plugin.get().screen("list", new ImportProjectListScreen.Factory());
+ Plugin.get().screenRegex("projects/(.*)", new ProjectImportsScreen.Factory());
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ProjectImportsScreen.java b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ProjectImportsScreen.java
new file mode 100644
index 0000000..d031708
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ProjectImportsScreen.java
@@ -0,0 +1,122 @@
+// Copyright (C) 2015 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.googlesource.gerrit.plugins.importer.client;
+
+import static com.googlesource.gerrit.plugins.importer.client.ImportProjectListScreen.projectUrl;
+import static com.googlesource.gerrit.plugins.importer.client.ImportProjectListScreen.removeNs;
+
+import com.google.gerrit.client.rpc.Natives;
+import com.google.gerrit.plugin.client.Plugin;
+import com.google.gerrit.plugin.client.rpc.RestApi;
+import com.google.gerrit.plugin.client.screen.Screen;
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.ui.Anchor;
+import com.google.gwt.user.client.ui.Button;
+import com.google.gwt.user.client.ui.FlexTable;
+import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
+import com.google.gwt.user.client.ui.Label;
+import com.google.gwt.user.client.ui.VerticalPanel;
+import com.google.gwt.user.client.ui.Widget;
+
+import java.util.Collections;
+import java.util.List;
+
+public class ProjectImportsScreen extends VerticalPanel {
+ static class Factory implements Screen.EntryPoint {
+ @Override
+ public void onLoad(Screen screen) {
+ screen.setPageTitle("Imports of " + screen.getToken(1));
+ screen.show(new ProjectImportsScreen(screen.getToken(1)));
+ }
+ }
+
+ ProjectImportsScreen(final String project) {
+ setStyleName("importer-import-panel");
+
+ new RestApi("config").id("server").view(Plugin.get().getPluginName(), "projects")
+ .id(project).get(new AsyncCallback<ImportProjectInfo>() {
+ @Override
+ public void onSuccess(ImportProjectInfo importProjectInfo) {
+ display(project, importProjectInfo);
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ // never invoked
+ }
+ });
+ }
+
+ private void display(final String project, ImportProjectInfo info) {
+ MyTable t = new MyTable();
+ t.setStyleName("importer-projectImportInfoTable");
+ t.addRow("Project Name", project);
+ String srcProjectUrl = projectUrl(info, project);
+ t.addRow("From", new Anchor(srcProjectUrl, srcProjectUrl));
+ t.addRow("Parent", info.parent());
+ t.addRow("Actions", new ImportActionPanel(project));
+ add(t);
+
+ add(new Label("Imports:"));
+ int columns = 3;
+ FlexTable importsTable = new FlexTable();
+ importsTable.setStyleName("importer-importProjectTable");
+ FlexCellFormatter fmt = importsTable.getFlexCellFormatter();
+ for (int c = 0; c < columns; c++) {
+ fmt.addStyleName(0, c, "dataHeader");
+ fmt.addStyleName(0, c, "topMostCell");
+ }
+ fmt.addStyleName(0, 0, "leftMostCell");
+
+ importsTable.setText(0, 0, "Timestamp");
+ importsTable.setText(0, 1, "User");
+ importsTable.setText(0, 2, "Remote User");
+ int row = 1;
+ List<ImportInfo> imports = Natives.asList(info.imports());
+ Collections.reverse(imports);
+ for (ImportInfo importInfo : imports) {
+ for (int c = 0; c < columns; c++) {
+ fmt.addStyleName(row, c, "dataCell");
+ fmt.addStyleName(row, 0, "leftMostCell");
+ }
+
+ importsTable.setText(row, 0, removeNs(importInfo.timestamp()));
+ importsTable.setText(row, 1, importInfo.user().username());
+ importsTable.setText(row, 2, importInfo.remoteUser());
+
+ row++;
+ }
+
+ add(importsTable);
+ }
+
+ private static class MyTable extends FlexTable {
+ private static int row = 0;
+
+ private void addRow(String label, String value) {
+ setWidget(row, 0, new Label(label + ":"));
+ setWidget(row, 1, new Label(value));
+ row++;
+ }
+
+ private void addRow(String label, Widget w) {
+ setWidget(row, 0, new Label(label + ":"));
+ setWidget(row, 1, w);
+ row++;
+ }
+ }
+}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/public/importer.css b/src/main/java/com/googlesource/gerrit/plugins/importer/public/importer.css
index 770081a..5eef977 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/public/importer.css
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/public/importer.css
@@ -66,3 +66,7 @@
.importer-action-panel .gwt-Button {
margin: 2px;
}
+
+.importer-projectImportInfoTable {
+ margin-bottom: 10px;
+}