Add UI to see imported projects
There is a new menu entry 'Projects' > 'List Imports' that shows a
screen which lists the past project imports.
Change-Id: I4bd2befecced9743c302da3165371f775a5f6d2d
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/ImportProjectMenu.java b/src/main/java/com/googlesource/gerrit/plugins/importer/ImportProjectMenu.java
index 50f5529..f470720 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/importer/ImportProjectMenu.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/ImportProjectMenu.java
@@ -40,6 +40,7 @@
List<MenuItem> projectItems = Lists.newArrayListWithExpectedSize(2);
if (canImport()) {
projectItems.add(new MenuItem("Import Project", "#/x/" + pluginName + "/project", ""));
+ projectItems.add(new MenuItem("List Imports", "#/x/" + pluginName + "/list", ""));
}
if (!projectItems.isEmpty()) {
menuEntries.add(new MenuEntry("Projects", projectItems));
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/client/AccountInfo.java b/src/main/java/com/googlesource/gerrit/plugins/importer/client/AccountInfo.java
new file mode 100644
index 0000000..18b44fa
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/client/AccountInfo.java
@@ -0,0 +1,27 @@
+// 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.core.client.JavaScriptObject;
+
+public class AccountInfo extends JavaScriptObject {
+ public final native int _account_id() /*-{ return this._account_id || 0; }-*/;
+ public final native String name() /*-{ return this.name; }-*/;
+ public final native String username() /*-{ return this.username; }-*/;
+ public final native String email() /*-{ return this.email; }-*/;
+
+ protected AccountInfo() {
+ }
+}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportInfo.java b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportInfo.java
new file mode 100644
index 0000000..82978f0
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportInfo.java
@@ -0,0 +1,26 @@
+// 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.core.client.JavaScriptObject;
+
+public class ImportInfo extends JavaScriptObject {
+ public final native String timestamp() /*-{ return this.timestamp; }-*/;
+ public final native AccountInfo user() /*-{ return this.user; }-*/;
+ public final native String remoteUser() /*-{ return this.remote_user; }-*/;
+
+ protected ImportInfo() {
+ }
+}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportProjectInfo.java b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportProjectInfo.java
new file mode 100644
index 0000000..e89f058
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportProjectInfo.java
@@ -0,0 +1,28 @@
+// 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.core.client.JavaScriptObject;
+import com.google.gwt.core.client.JsArray;
+
+public class ImportProjectInfo extends JavaScriptObject {
+ public final native String from() /*-{ return this.from; }-*/;
+ public final native String name() /*-{ return this.name; }-*/;
+ public final native String parent() /*-{ return this.parent; }-*/;
+ public final native JsArray<ImportInfo> imports() /*-{ return this.imports; }-*/;
+
+ protected ImportProjectInfo() {
+ }
+}
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
new file mode 100644
index 0000000..54f1880
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/importer/client/ImportProjectListScreen.java
@@ -0,0 +1,115 @@
+// 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.gerrit.client.rpc.NativeMap;
+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.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.ui.Anchor;
+import com.google.gwt.user.client.ui.FlexTable;
+import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
+import com.google.gwt.user.client.ui.VerticalPanel;
+
+import java.util.List;
+
+public class ImportProjectListScreen extends VerticalPanel {
+ static class Factory implements Screen.EntryPoint {
+ @Override
+ public void onLoad(Screen screen) {
+ screen.setPageTitle("Imported Projects");
+ screen.show(new ImportProjectListScreen());
+ }
+ }
+
+ ImportProjectListScreen() {
+ setStyleName("importer-imports-panel");
+
+ new RestApi("config").id("server")
+ .view(Plugin.get().getPluginName(), "projects")
+ .get(new AsyncCallback<NativeMap<ImportProjectInfo>>() {
+ @Override
+ public void onSuccess(NativeMap<ImportProjectInfo> info) {
+ display(info);
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ // never invoked
+ }
+ });
+ }
+
+ private void display(NativeMap<ImportProjectInfo> map) {
+ int columns = 4;
+ FlexTable t = new FlexTable();
+ t.setStyleName("importer-importProjectTable");
+ FlexCellFormatter fmt = t.getFlexCellFormatter();
+ for (int c = 0; c < columns; c++) {
+ fmt.addStyleName(0, c, "dataHeader");
+ fmt.addStyleName(0, c, "topMostCell");
+ }
+ fmt.addStyleName(0, 0, "leftMostCell");
+
+ t.setText(0, 0, "Project Name");
+ t.setText(0, 1, "From");
+ t.setText(0, 2, "Last Import By");
+ t.setText(0, 3, "Last Import At");
+
+ int row = 1;
+ for (String project : map.keySet()) {
+ ImportProjectInfo info = map.get(project);
+
+ for (int c = 0; c < columns; c++) {
+ fmt.addStyleName(row, c, "dataCell");
+ fmt.addStyleName(row, 0, "leftMostCell");
+ }
+
+ t.setText(row, 0, project);
+
+ String srcProjectUrl = ensureSlash(info.from())
+ + "#/admin/projects/"
+ + (info.name() != null ? info.name() : project);
+ t.setWidget(row, 1, new Anchor(srcProjectUrl, srcProjectUrl));
+
+ List<ImportInfo> importList = Natives.asList(info.imports());
+ if (!importList.isEmpty()) {
+ ImportInfo lastImportInfo = importList.get(importList.size() - 1);
+ t.setText(row, 2, lastImportInfo.user().username());
+ t.setText(row, 3, removeNs(lastImportInfo.timestamp()));
+ } else {
+ t.setText(row, 2, "N/A");
+ t.setText(row, 3, "N/A");
+ }
+
+ row++;
+ }
+
+ add(t);
+ }
+
+ private static String removeNs(String timestamp) {
+ return timestamp.substring(0, timestamp.lastIndexOf('.'));
+ }
+
+ private static String ensureSlash(String in) {
+ if (in != null && !in.endsWith("/")) {
+ return in + "/";
+ }
+ 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 88473d9..10ff0a6 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
@@ -25,5 +25,6 @@
@Override
public void onPluginLoad() {
Plugin.get().screen("project", new ImportProjectScreen.Factory());
+ Plugin.get().screen("list", new ImportProjectListScreen.Factory());
}
}
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 d3e79ea..7731558 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
@@ -13,10 +13,43 @@
* limitations under the License.
*/
-.importer-import-panel, .importer-message-panel {
+.importer-import-panel,
+.importer-message-panel,
+.importer-imports-panel {
border-spacing: 0px 5px;
}
.importer-importButton {
margin-left: 10px !important;
}
+
+.importer-importProjectTable {
+ border-collapse: separate;
+ border-spacing: 0;
+}
+
+.importer-importProjectTable .leftMostCell {
+ border-left: 1px solid #EEE;
+}
+
+.importer-importProjectTable .topMostCell {
+ border-top: 1px solid #EEE;
+}
+
+.importer-importProjectTable .dataHeader {
+ border: 1px solid #FFF;
+ padding: 2px 6px 1px;
+ background-color: #EEE;
+ font-style: italic;
+ white-space: nowrap;
+ color: textColor;
+}
+
+.importer-importProjectTable .dataCell {
+ padding-left: 5px;
+ padding-right: 5px;
+ border-right: 1px solid #EEE;
+ border-bottom: 1px solid #EEE;
+ vertical-align: middle;
+ height: 20px;
+}