Add information about LFS config to PolyGerrit UI
In the GWT UI information about the LFS configuration for a project was
displayed in the project's detail screen. This panel was missing in the
PolyGerrit UI, since the JavaScript-script adding it was not compatible
with the PolyGerrit UI.
This change adds the panel to the PolyGerrit UI as well.
Change-Id: Ib6d07685fbb6e6fb8718cd4c693169632e052812
diff --git a/src/main/java/com/googlesource/gerrit/plugins/lfs/HttpModule.java b/src/main/java/com/googlesource/gerrit/plugins/lfs/HttpModule.java
index f8c219a..2bd7091 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/lfs/HttpModule.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/lfs/HttpModule.java
@@ -62,8 +62,12 @@
populateRepository(backend);
}
+ // Only for GWT-UI
DynamicSet.bind(binder(), WebUiPlugin.class)
.toInstance(new JavaScriptPlugin("lfs-project-info.js"));
+
+ // Only for PolyGerrit-UI
+ DynamicSet.bind(binder(), WebUiPlugin.class).toInstance(new JavaScriptPlugin("gr-lfs.html"));
}
private void populateRepository(LfsBackend backend) {
diff --git a/src/main/resources/static/gr-lfs-project-info.html b/src/main/resources/static/gr-lfs-project-info.html
new file mode 100644
index 0000000..4008f89
--- /dev/null
+++ b/src/main/resources/static/gr-lfs-project-info.html
@@ -0,0 +1,48 @@
+<!--
+@license
+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="gr-lfs-project-info">
+ <template>
+ <style include="shared-styles"></style>
+ <style include="gr-form-styles"></style>
+ <style>
+ .sectionTitle {
+ padding-top: 2em;
+ }
+ </style>
+ <fieldset id="lfsProjectInfo" class="gr-form-styles">
+ <h2 class="sectionTitle">LFS Info</h2>
+ <section>
+ <span class="title">Enabled</span>
+ <span class="value">[[_appliedConfig.enabled]]</span>
+ </section>
+ <section>
+ <span class="title">Max Object Size</span>
+ <span class="value">[[_appliedConfig.max_object_size]]</span>
+ </section>
+ <section>
+ <span class="title">Read Only</span>
+ <span class="value">[[_appliedConfig.read_only]]</span>
+ </section>
+ <section hidden="[[!_appliedConfig.backend]]">
+ <span class="title">Backend</span>
+ <span class="value">[[_appliedConfig.backend]]</span>
+ </section>
+ </fieldset>
+ </template>
+ <script src="gr-lfs-project-info.js"></script>
+</dom-module>
diff --git a/src/main/resources/static/gr-lfs-project-info.js b/src/main/resources/static/gr-lfs-project-info.js
new file mode 100644
index 0000000..ce733b9
--- /dev/null
+++ b/src/main/resources/static/gr-lfs-project-info.js
@@ -0,0 +1,43 @@
+// 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.
+
+(function () {
+ 'use strict';
+
+ Polymer({
+ is: 'gr-lfs-project-info',
+
+ properties: {
+ repoName: String,
+ _appliedConfig: Object,
+ },
+
+ attached() {
+ this._getPreferences()
+ },
+
+ _getPreferences() {
+ return this.plugin.restApi('/projects/')
+ .get(`${this.repoName}/${this.plugin.getPluginName()}~lfs:config-project`)
+ .then(config => {
+ if (!config || Object.entries(config).length === 0) {
+ this.$.lfsProjectInfo.hidden = true;
+ return;
+ }
+
+ this._appliedConfig = config
+ })
+ },
+ });
+})();
diff --git a/src/main/resources/static/gr-lfs.html b/src/main/resources/static/gr-lfs.html
new file mode 100644
index 0000000..8493051
--- /dev/null
+++ b/src/main/resources/static/gr-lfs.html
@@ -0,0 +1,28 @@
+<!--
+@license
+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.
+-->
+
+<link rel="import" href="./gr-lfs-project-info.html">
+
+<dom-module id="gr-lfs">
+ <script>
+ Gerrit.install(plugin => {
+ if (!window.Polymer) { return; }
+
+ plugin.registerCustomComponent('repo-config', 'gr-lfs-project-info');
+ });
+ </script>
+</dom-module>
diff --git a/src/main/resources/static/lfs-project-info.js b/src/main/resources/static/lfs-project-info.js
index b514822..f81f975 100644
--- a/src/main/resources/static/lfs-project-info.js
+++ b/src/main/resources/static/lfs-project-info.js
@@ -13,6 +13,11 @@
// limitations under the License.
Gerrit.install(function(self) {
+
+ if (window.Polymer) { return; }
+
+ // The code below is only used by the GWT-UI
+
function toUpperCamel(str) {
var words = str.split('_');
for (i=0; i<words.length; i++) {
@@ -66,4 +71,4 @@
}
self.panel('PROJECT_INFO_SCREEN_BOTTOM', onProjectInfo);
- });
\ No newline at end of file
+ });