Files
gerrit/polygerrit-ui/app/elements/plugins/gr-external-style/gr-external-style.js
Viktar Donich 9bd0ce688d Make metadata sections configurable from plugin
For plugins, imported with HTML imports, and providing CSS modules, use
provided styles to control metadata sections in gr-change-view.

Related Polymer API:
https://www.polymer-project.org/1.0/docs/devguide/styling#custom-style

Includes sample integration test.

Sample code for using proposed API, in plugin.js:

Gerrit.install(function(plugin) {
  plugin.registerStyleModule('change-metadata', 'my-plugin-style');
});

Please note that `my-plugin-style` has to be unique, so plugin name
should be included.

Sample code for using proposed API, in myplugin.html:

<dom-module id="my-plugin-style">
  <template>
    <style>
      :root {
        --change-metadata-assignee: {
          display: none;
        }
        --change-metadata-label-status: {
          display: none;
        }
        --change-metadata-strategy: {
          display: none;
        }
        --change-metadata-topic: {
          display: none;
        }
      }
    </style>
  </template>
</dom-module>

Feature: Issue 5402
Change-Id: Iba2645f28d5b411df2d0310a05aa0cbec4cca26a
2017-04-25 17:27:13 -07:00

40 lines
1.2 KiB
JavaScript

// Copyright (C) 2017 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-external-style',
properties: {
name: String,
},
_applyStyle: function(name) {
var s = document.createElement('style', 'custom-style');
s.setAttribute('include', name);
Polymer.dom(this.root).appendChild(s);
},
ready: function() {
Gerrit.awaitPluginsLoaded().then(function() {
var sharedStyles = Gerrit._styleModules[this.name];
if (sharedStyles) {
sharedStyles.map(this._applyStyle.bind(this));
}
}.bind(this));
},
});
})();