PolyGerrit UI integration

Working integration into PolyGerrit UI.

Currently the status is rendered below the votes with a summary
line and a table for the individual votes.

Change-Id: Ie82059551c658b478715c4537d2d3feccb69fb63
diff --git a/BUILD b/BUILD
index 93bb716..27d5da3 100644
--- a/BUILD
+++ b/BUILD
@@ -6,6 +6,8 @@
     "gerrit_plugin",
 )
 load("//tools/bzl:junit.bzl", "junit_tests")
+load("//tools/bzl:genrule2.bzl", "genrule2")
+load("//tools/bzl:js.bzl", "polygerrit_plugin")
 
 gerrit_plugin(
     name = "verify-status",
@@ -20,6 +22,7 @@
         "Implementation-Title: Verify Status Plugin",
         "Implementation-URL: https://gerrit-review.googlesource.com/#/admin/projects/plugins/verify-status",
     ],
+    resource_jars = [":gr-verify-status-static"],
     resources = glob(["src/main/**/*"]),
 )
 
@@ -41,3 +44,20 @@
         ":verify-status__plugin",
     ],
 )
+
+genrule2(
+    name = "gr-verify-status-static",
+    srcs = [":gr-verify-status"],
+    outs = ["gr-verify-status-static.jar"],
+    cmd = " && ".join([
+        "mkdir $$TMP/static",
+        "cp -r $(locations :gr-verify-status) $$TMP/static",
+        "cd $$TMP",
+        "zip -Drq $$ROOT/$@ -g .",
+    ]),
+)
+
+polygerrit_plugin(
+    name = "gr-verify-status",
+    app = "gr-verify-status-plugin.html",
+)
diff --git a/WORKSPACE b/WORKSPACE
index 9e679f2..50de554 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -7,6 +7,30 @@
     #local_path = "/home/<user>/projects/bazlets",
 )
 
+# Polymer dependencies
+load(
+    "@com_googlesource_gerrit_bazlets//:gerrit_polymer.bzl",
+    "gerrit_polymer",
+)
+
+gerrit_polymer()
+
+# Load closure compiler with transitive dependencies
+load("@io_bazel_rules_closure//closure:defs.bzl", "closure_repositories")
+
+closure_repositories()
+
+# Load Gerrit npm_binary toolchain
+load("@com_googlesource_gerrit_bazlets//tools:js.bzl", "GERRIT", "npm_binary")
+npm_binary(
+    name = "polymer-bundler",
+    repository = GERRIT,
+)
+npm_binary(
+    name = "crisper",
+    repository = GERRIT,
+)
+
 # Snapshot Plugin API
 #load(
 #    "@com_googlesource_gerrit_bazlets//:gerrit_api_maven_local.bzl",
diff --git a/gr-verify-status-plugin.html b/gr-verify-status-plugin.html
new file mode 100644
index 0000000..42786f6
--- /dev/null
+++ b/gr-verify-status-plugin.html
@@ -0,0 +1,121 @@
+<!--
+Copyright (C) 2019 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.
+-->
+<dom-module id="verify-status">
+<script type="text/javascript">
+    if (window.Polymer) {
+      Gerrit.install(function(plugin) {
+          plugin.registerCustomComponent(
+          'change-metadata-item', 'gr-verify-status-panel');
+      });
+    }
+</script>
+</dom-module>
+
+<dom-module id="gr-verify-status-panel"> <template>
+<style include="gr-form-styles" type="text/css"></style>
+<style type="text/css">
+    .u-green {
+        color: #388E3C;
+    }
+
+    .u-red {
+        color: #D32F2F;
+    }
+</style>
+
+<gr-verifiy-status-panel>
+<div id="verify-status">
+    <span class="u-green">Passed:[[verifystatus.summary.passed]]</span>,
+    <span class="u-red">Failed:[[verifystatus.summary.failed]]</span>,
+    <span class="u-black">Not done:[[verifystatus.summary.notdone]]</span>
+</div>
+<div class="separatedSection style-scope gr-change-metadata"
+    style="margin-top: 0; padding: 0">
+    <table class="test_result_table">
+        <tbody>
+            <template is="dom-repeat" items="{{verifystatus.results}}">
+            <tr>
+                <td class="cell verifiedstatus"><a href$="[[item.url]]">[[item.name]]</a></td>
+                <td class="cell verifiedstatus verifiedstatus_value">[[item.value]]</td>
+            </tr>
+            </template>
+        </tbody>
+    </table>
+</div>
+
+</gr-verifiy-status-panel> </template>
+<script type="text/javascript">
+/*(function() {
+  'use strict';*/
+const Defs = {};
+/**
+ * @typedef {{
+ *   summary: Object,
+ *   results: Array,
+ * }}
+ */
+Defs.verifystatus;
+
+Polymer({
+    is: 'gr-verify-status-panel',
+
+    properties: {
+        verifystatus: {
+            /** @type {Defs.verifystatus} */
+            type: Object,
+        },
+        _verifystatus: {
+             /** @type {Defs.verifystatus} */
+             type: Object,
+             computed: '_fetchData(revision)',
+        },
+    },
+    attached() {
+        this.plugin.attributeHelper(this).bind('revision', this._onRevisionChanged.bind(this));
+    },
+
+    _fetchData(revision) {
+        const query ='/verify-status~verifications?sort=REPORTER&filter=CURRENT';
+        const endpoint = '/changes/' + this.change.id + '/revisions/' +
+                         this.__data__.revision._number + query;
+
+        const errFn = response => {
+            this.fire('page-error', {response});
+        };
+
+        this.plugin.restApi().get(endpoint, errFn).then(r => {
+            let summary = {failed:0, passed:0, notdone:0};
+            let results = [];
+            for (let checkid in r) {
+                let check= r[checkid];
+                if (check.value == '0') {
+                    summary.notdone +=1;}
+                else if (check.value == 1) {
+                    summary.passed +=1;
+                }
+                else {
+                    summary.failed +=1;
+                }
+                results.push(check);
+            };
+
+            this.set('verifystatus', {summary:summary, results: results});
+        });
+    },
+    _onRevisionChanged(value) {
+        console.log(`(attributeHelper.bind) revision number: ${value._number}`);
+    },
+});
+/*}());*/
+</script>
+</dom-module>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/verifystatus/HttpModule.java b/src/main/java/com/googlesource/gerrit/plugins/verifystatus/HttpModule.java
index d0959e0..517b162 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/verifystatus/HttpModule.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/verifystatus/HttpModule.java
@@ -16,6 +16,7 @@
 
 import com.google.gerrit.extensions.registration.DynamicSet;
 import com.google.gerrit.extensions.webui.GwtPlugin;
+import com.google.gerrit.extensions.webui.JavaScriptPlugin;
 import com.google.gerrit.extensions.webui.WebUiPlugin;
 import com.google.inject.servlet.ServletModule;
 
@@ -23,5 +24,6 @@
   @Override
   protected void configureServlets() {
     DynamicSet.bind(binder(), WebUiPlugin.class).toInstance(new GwtPlugin("verifystatus"));
+    DynamicSet.bind(binder(), WebUiPlugin.class).toInstance(new JavaScriptPlugin("gr-verify-status.html"));
   }
 }
diff --git a/tools/bzl/genrule2.bzl b/tools/bzl/genrule2.bzl
new file mode 100644
index 0000000..61c4e18
--- /dev/null
+++ b/tools/bzl/genrule2.bzl
@@ -0,0 +1,3 @@
+load("@com_googlesource_gerrit_bazlets//tools:genrule2.bzl", _genrule2 = "genrule2")
+
+genrule2 = _genrule2
diff --git a/tools/bzl/js.bzl b/tools/bzl/js.bzl
new file mode 100644
index 0000000..0f9e367
--- /dev/null
+++ b/tools/bzl/js.bzl
@@ -0,0 +1,3 @@
+load("@com_googlesource_gerrit_bazlets//tools:js.bzl", _polygerrit_plugin = "polygerrit_plugin")
+
+polygerrit_plugin = _polygerrit_plugin