Convert to Polymer 3
Change-Id: I96805eb374613b7657cd19c5de5f284d3e978c40
diff --git a/BUILD b/BUILD
index ab1c177..30c9dad 100644
--- a/BUILD
+++ b/BUILD
@@ -1,4 +1,7 @@
+load("@npm//@bazel/rollup:index.bzl", "rollup_bundle")
load("//tools/bzl:plugin.bzl", "gerrit_plugin")
+load("//tools/bzl:genrule2.bzl", "genrule2")
+load("//tools/bzl:js.bzl", "polygerrit_plugin")
gerrit_plugin(
name = "messageoftheday",
@@ -10,5 +13,36 @@
"Implementation-Title: Plugin messageoftheday",
"Implementation-URL: https://gerrit-review.googlesource.com/#/admin/projects/plugins/messageoftheday",
],
+ resource_jars = [":gr-messageoftheday-static"],
resources = glob(["src/main/resources/**/*"]),
)
+
+genrule2(
+ name = "gr-messageoftheday-static",
+ srcs = [":gr-messageoftheday"],
+ outs = ["gr-messageoftheday-static.jar"],
+ cmd = " && ".join([
+ "mkdir $$TMP/static",
+ "cp -r $(locations :gr-messageoftheday) $$TMP/static",
+ "cd $$TMP",
+ "zip -Drq $$ROOT/$@ -g .",
+ ]),
+)
+
+polygerrit_plugin(
+ name = "gr-messageoftheday",
+ app = "gr-messageoftheday-bundle.js",
+ plugin_name = "gr-messageoftheday",
+)
+
+rollup_bundle(
+ name = "gr-messageoftheday-bundle",
+ srcs = glob(["gr-messageoftheday/*.js"]),
+ entry_point = "gr-messageoftheday/plugin.js",
+ format = "iife",
+ rollup_bin = "//tools/node_tools:rollup-bin",
+ sourcemap = "hidden",
+ deps = [
+ "@tools_npm//rollup-plugin-node-resolve",
+ ],
+)
diff --git a/gr-messageoftheday/gr-messageoftheday-banner.js b/gr-messageoftheday/gr-messageoftheday-banner.js
new file mode 100644
index 0000000..ae84e85
--- /dev/null
+++ b/gr-messageoftheday/gr-messageoftheday-banner.js
@@ -0,0 +1,64 @@
+/**
+ * @license
+ * Copyright (C) 2021 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.
+ */
+import {htmlTemplate} from './gr-messageoftheday-banner_html.js';
+
+class GrMessageOfTheDayBanner extends Polymer.Element {
+ static get is() {
+ return 'gr-messageoftheday-banner';
+ }
+
+ static get template() {
+ return htmlTemplate;
+ }
+
+ static get properties() {
+ return {
+ _message: Object,
+ _hidden: {
+ type: Boolean,
+ value: true,
+ }
+ };
+ }
+
+ connectedCallback() {
+ super.connectedCallback();
+
+ this.plugin.restApi()
+ .get(`/config/server/${this.plugin.getPluginName()}~message`)
+ .then(message => {
+ if (!message || !message.html) {
+ return;
+ }
+ this._message = message;
+ this._isHidden();
+ this.$.message.innerHTML = this._message.html;
+ });
+ }
+
+ _handleDismissMessage() {
+ document.cookie =
+ `msg-${this._message.id}=1; expires=${this._message.redisplay}`;
+ this._hidden = true;
+ }
+
+ _isHidden() {
+ this._hidden = window.util.getCookie(`msg-${this._message.id}`) === '1';
+ }
+}
+
+customElements.define(GrMessageOfTheDayBanner.is, GrMessageOfTheDayBanner);
diff --git a/gr-messageoftheday/gr-messageoftheday-banner_html.js b/gr-messageoftheday/gr-messageoftheday-banner_html.js
new file mode 100644
index 0000000..235633e
--- /dev/null
+++ b/gr-messageoftheday/gr-messageoftheday-banner_html.js
@@ -0,0 +1,34 @@
+/**
+ * @license
+ * Copyright (C) 2021 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.
+ */
+
+export const htmlTemplate = Polymer.html`
+<style include="shared-styles">
+ #container {
+ background-color: lightyellow;
+ display: flex;
+ height: fit-content;
+ justify-content: space-between;
+ padding: 1em;
+ }
+</style>
+<div id="container" hidden$="[[_hidden]]">
+ <div id="message"></div>
+ <gr-button id="dismissMessageBtn"
+ link
+ on-tap="_handleDismissMessage">Dismiss</gr-button>
+</div>
+<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>`;
diff --git a/gr-messageoftheday/plugin.js b/gr-messageoftheday/plugin.js
new file mode 100644
index 0000000..6385e04
--- /dev/null
+++ b/gr-messageoftheday/plugin.js
@@ -0,0 +1,22 @@
+/**
+ * @license
+ * Copyright (C) 2021 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.
+ */
+
+import './gr-messageoftheday-banner.js';
+
+Gerrit.install(plugin => {
+ plugin.registerCustomComponent('banner', 'gr-messageoftheday-banner');
+});
diff --git a/src/main/java/com/googlesource/gerrit/plugins/messageoftheday/HttpModule.java b/src/main/java/com/googlesource/gerrit/plugins/messageoftheday/HttpModule.java
index d10983a..4a43938 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/messageoftheday/HttpModule.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/messageoftheday/HttpModule.java
@@ -23,6 +23,6 @@
@Override
protected void configure() {
DynamicSet.bind(binder(), WebUiPlugin.class)
- .toInstance(new JavaScriptPlugin("gr-messageoftheday.html"));
+ .toInstance(new JavaScriptPlugin("gr-messageoftheday.js"));
}
}
diff --git a/src/main/resources/static/gr-messageoftheday-banner.html b/src/main/resources/static/gr-messageoftheday-banner.html
deleted file mode 100644
index 102645d..0000000
--- a/src/main/resources/static/gr-messageoftheday-banner.html
+++ /dev/null
@@ -1,38 +0,0 @@
-<!--
-@license
-Copyright (C) 2020 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="gr-messageoftheday-banner">
- <template>
- <style include="shared-styles">
- #container {
- background-color: lightyellow;
- display: flex;
- height: fit-content;
- justify-content: space-between;
- padding: 1em;
- }
- </style>
- <div id="container" hidden$="[[_hidden]]">
- <div id="message"></div>
- <gr-button id="dismissMessageBtn"
- link
- on-tap="_handleDismissMessage">Dismiss</gr-button>
- </div>
- <gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
- </template>
- <script src="gr-messageoftheday-banner.js"></script>
-</dom-module>
diff --git a/src/main/resources/static/gr-messageoftheday-banner.js b/src/main/resources/static/gr-messageoftheday-banner.js
deleted file mode 100644
index 536c05d..0000000
--- a/src/main/resources/static/gr-messageoftheday-banner.js
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * @license
- * Copyright (C) 2020 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.
- */
-(function() {
- 'use strict';
-
- Polymer({
- is: 'gr-messageoftheday-banner',
-
- properties: {
- _message: Object,
- _hidden: {
- type: Boolean,
- value: true,
- },
- },
-
- attached() {
- this.plugin.restApi()
- .get(`/config/server/${this.plugin.getPluginName()}~message`)
- .then(message => {
- if (!message || !message.html) {
- return;
- }
- this._message = message;
- this._isHidden();
- this.$.message.innerHTML = this._message.html;
- });
- },
-
- _handleDismissMessage() {
- document.cookie =
- `msg-${this._message.id}=1; expires=${this._message.redisplay}`;
- this._hidden = true;
- },
-
- _isHidden() {
- this._hidden = window.util.getCookie(`msg-${this._message.id}`) === '1';
- },
- });
-})();
diff --git a/src/main/resources/static/gr-messageoftheday.html b/src/main/resources/static/gr-messageoftheday.html
deleted file mode 100644
index 8758502..0000000
--- a/src/main/resources/static/gr-messageoftheday.html
+++ /dev/null
@@ -1,27 +0,0 @@
-<!--
-@license
-Copyright (C) 2020 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.
--->
-
-<link rel="import"
- href="./gr-messageoftheday-banner.html">
-
-<dom-module id="gr-messageoftheday">
- <script>
- Gerrit.install(plugin => {
- plugin.registerCustomComponent("banner", "gr-messageoftheday-banner");
- });
- </script>
-</dom-module>