Marian Harbach | ebeb154 | 2019-12-13 10:42:46 +0100 | [diff] [blame] | 1 | :linkattrs: |
Viktar Donich | 2b2fdb7 | 2017-03-13 16:21:44 -0700 | [diff] [blame] | 2 | = Gerrit Code Review - PolyGerrit Plugin Development |
| 3 | |
Viktar Donich | 5055e8d | 2017-11-09 13:02:42 -0800 | [diff] [blame] | 4 | CAUTION: Work in progress. Hard hat area. Please |
| 5 | link:https://bugs.chromium.org/p/gerrit/issues/entry?template=PolyGerrit%20plugins[send |
Marian Harbach | 3425337 | 2019-12-10 18:01:31 +0100 | [diff] [blame] | 6 | feedback,role=external,window=_blank] if something's not right. |
Viktar Donich | 5055e8d | 2017-11-09 13:02:42 -0800 | [diff] [blame] | 7 | |
Viktar Donich | 15ef24c | 2017-12-07 16:04:38 -0800 | [diff] [blame] | 8 | For migrating existing GWT UI plugins, please check out the |
| 9 | link:pg-plugin-migration.html#migration[migration guide]. |
| 10 | |
Viktar Donich | 9bd0ce6 | 2017-02-07 08:56:33 -0800 | [diff] [blame] | 11 | [[loading]] |
Viktar Donich | 2b2fdb7 | 2017-03-13 16:21:44 -0700 | [diff] [blame] | 12 | == Plugin loading and initialization |
| 13 | |
Tao Zhou | d2a8ded | 2020-06-05 16:08:54 +0200 | [diff] [blame^] | 14 | link:js-api.html#_entry_point[Entry point] for the plugin. |
Viktar Donich | 2b2fdb7 | 2017-03-13 16:21:44 -0700 | [diff] [blame] | 15 | |
Tao Zhou | d2a8ded | 2020-06-05 16:08:54 +0200 | [diff] [blame^] | 16 | * The plugin provides pluginname.js, and can be a standalone file or a static |
Viktar Donich | 5055e8d | 2017-11-09 13:02:42 -0800 | [diff] [blame] | 17 | asset in a jar as a link:dev-plugins.html#deployment[Web UI plugin]. |
Tao Zhou | d2a8ded | 2020-06-05 16:08:54 +0200 | [diff] [blame^] | 18 | * pluginname.js contains a call to `Gerrit.install()`. There should |
| 19 | only be single `Gerrit.install()` per file. |
| 20 | * PolyGerrit imports pluginname.js. |
| 21 | * For standalone plugins, the entry point file is a `pluginname.js` file |
Viktar Donich | cbc2567 | 2017-07-24 13:23:18 -0700 | [diff] [blame] | 22 | located in `gerrit-site/plugins` folder, where `pluginname` is an alphanumeric |
| 23 | plugin name. |
Viktar Donich | 2b2fdb7 | 2017-03-13 16:21:44 -0700 | [diff] [blame] | 24 | |
Quinten Yearsley | 888e638 | 2017-12-05 11:11:09 -0800 | [diff] [blame] | 25 | Note: Code examples target modern browsers (Chrome, Firefox, Safari, Edge). |
Viktar Donich | 5055e8d | 2017-11-09 13:02:42 -0800 | [diff] [blame] | 26 | |
Tao Zhou | d2a8ded | 2020-06-05 16:08:54 +0200 | [diff] [blame^] | 27 | Here's a recommended starter `myplugin.js`: |
Viktar Donich | 2b2fdb7 | 2017-03-13 16:21:44 -0700 | [diff] [blame] | 28 | |
Tao Zhou | d2a8ded | 2020-06-05 16:08:54 +0200 | [diff] [blame^] | 29 | ``` js |
| 30 | Gerrit.install(plugin => { |
| 31 | 'use strict'; |
Viktar Donich | 5055e8d | 2017-11-09 13:02:42 -0800 | [diff] [blame] | 32 | |
Tao Zhou | d2a8ded | 2020-06-05 16:08:54 +0200 | [diff] [blame^] | 33 | // Your code here. |
| 34 | }); |
Viktar Donich | 2b2fdb7 | 2017-03-13 16:21:44 -0700 | [diff] [blame] | 35 | ``` |
Viktar Donich | cbc2567 | 2017-07-24 13:23:18 -0700 | [diff] [blame] | 36 | |
Viktar Donich | 7610f78 | 2017-10-02 11:51:41 +0100 | [diff] [blame] | 37 | [[low-level-api-concepts]] |
| 38 | == Low-level DOM API concepts |
Viktar Donich | cbc2567 | 2017-07-24 13:23:18 -0700 | [diff] [blame] | 39 | |
| 40 | Basically, the DOM is the API surface. Low-level API provides methods for |
| 41 | decorating, replacing, and styling DOM elements exposed through a set of |
Viktar Donich | 6d10eca | 2017-11-13 17:57:43 -0800 | [diff] [blame] | 42 | link:pg-plugin-endpoints.html[endpoints]. |
Viktar Donich | cbc2567 | 2017-07-24 13:23:18 -0700 | [diff] [blame] | 43 | |
| 44 | PolyGerrit provides a simple way for accessing the DOM via DOM hooks API. A DOM |
| 45 | hook is a custom element that is instantiated for the plugin endpoint. In the |
| 46 | decoration case, a hook is set with a `content` attribute that points to the DOM |
| 47 | element. |
| 48 | |
Viktar Donich | ab491f77 | 2017-08-15 08:02:58 -0700 | [diff] [blame] | 49 | 1. Get the DOM hook API instance via `plugin.hook(endpointName)` |
Viktar Donich | cbc2567 | 2017-07-24 13:23:18 -0700 | [diff] [blame] | 50 | 2. Set up an `onAttached` callback |
| 51 | 3. Callback is called when the hook element is created and inserted into DOM |
| 52 | 4. Use element.content to get UI element |
| 53 | |
| 54 | ``` js |
Viktar Donich | 5055e8d | 2017-11-09 13:02:42 -0800 | [diff] [blame] | 55 | Gerrit.install(plugin => { |
Viktar Donich | ab491f77 | 2017-08-15 08:02:58 -0700 | [diff] [blame] | 56 | const domHook = plugin.hook('reply-text'); |
Viktar Donich | cbc2567 | 2017-07-24 13:23:18 -0700 | [diff] [blame] | 57 | domHook.onAttached(element => { |
| 58 | if (!element.content) { return; } |
| 59 | // element.content is a reply dialog text area. |
| 60 | }); |
| 61 | }); |
| 62 | ``` |
| 63 | |
| 64 | [[low-level-decorating]] |
| 65 | === Decorating DOM Elements |
| 66 | |
| 67 | For each endpoint, PolyGerrit provides a list of DOM properties (such as |
| 68 | attributes and events) that are supported in the long-term. |
| 69 | |
Viktar Donich | cbc2567 | 2017-07-24 13:23:18 -0700 | [diff] [blame] | 70 | ``` js |
Viktar Donich | 5055e8d | 2017-11-09 13:02:42 -0800 | [diff] [blame] | 71 | Gerrit.install(plugin => { |
Viktar Donich | ab491f77 | 2017-08-15 08:02:58 -0700 | [diff] [blame] | 72 | const domHook = plugin.hook('reply-text'); |
Viktar Donich | cbc2567 | 2017-07-24 13:23:18 -0700 | [diff] [blame] | 73 | domHook.onAttached(element => { |
| 74 | if (!element.content) { return; } |
| 75 | element.content.style.border = '1px red dashed'; |
| 76 | }); |
| 77 | }); |
| 78 | ``` |
| 79 | |
| 80 | [[low-level-replacing]] |
| 81 | === Replacing DOM Elements |
| 82 | |
| 83 | An endpoint's contents can be replaced by passing the replace attribute as an |
| 84 | option. |
| 85 | |
| 86 | ``` js |
Viktar Donich | 5055e8d | 2017-11-09 13:02:42 -0800 | [diff] [blame] | 87 | Gerrit.install(plugin => { |
Viktar Donich | ab491f77 | 2017-08-15 08:02:58 -0700 | [diff] [blame] | 88 | const domHook = plugin.hook('header-title', {replace: true}); |
Viktar Donich | cbc2567 | 2017-07-24 13:23:18 -0700 | [diff] [blame] | 89 | domHook.onAttached(element => { |
| 90 | element.appendChild(document.createElement('my-site-header')); |
| 91 | }); |
| 92 | }); |
| 93 | ``` |
| 94 | |
| 95 | [[low-level-style]] |
| 96 | === Styling DOM Elements |
| 97 | |
| 98 | A plugin may provide Polymer's |
Tao Zhou | d2a8ded | 2020-06-05 16:08:54 +0200 | [diff] [blame^] | 99 | https://polymer-library.polymer-project.org/3.0/docs/devguide/style-shadow-dom[style |
Marian Harbach | 3425337 | 2019-12-10 18:01:31 +0100 | [diff] [blame] | 100 | modules,role=external,window=_blank] to style individual endpoints using |
Viktar Donich | cbc2567 | 2017-07-24 13:23:18 -0700 | [diff] [blame] | 101 | `plugin.registerStyleModule(endpointName, moduleName)`. A style must be defined |
Tao Zhou | d2a8ded | 2020-06-05 16:08:54 +0200 | [diff] [blame^] | 102 | as a standalone `<dom-module>` defined in the same .js file. |
| 103 | |
| 104 | See `samples/theme-plugin.js` for examples. |
Viktar Donich | cbc2567 | 2017-07-24 13:23:18 -0700 | [diff] [blame] | 105 | |
| 106 | Note: TODO: Insert link to the full styling API. |
| 107 | |
Tao Zhou | d2a8ded | 2020-06-05 16:08:54 +0200 | [diff] [blame^] | 108 | ``` js |
| 109 | const styleElement = document.createElement('dom-module'); |
| 110 | styleElement.innerHTML = |
| 111 | `<template> |
| 112 | <style> |
Viktar Donich | cbc2567 | 2017-07-24 13:23:18 -0700 | [diff] [blame] | 113 | html { |
Tao Zhou | d2a8ded | 2020-06-05 16:08:54 +0200 | [diff] [blame^] | 114 | --primary-text-color: red; |
Viktar Donich | cbc2567 | 2017-07-24 13:23:18 -0700 | [diff] [blame] | 115 | } |
Tao Zhou | d2a8ded | 2020-06-05 16:08:54 +0200 | [diff] [blame^] | 116 | </style> |
| 117 | </template>`; |
| 118 | |
| 119 | styleElement.register('some-style-module'); |
| 120 | |
| 121 | Gerrit.install(plugin => { |
| 122 | plugin.registerStyleModule('change-metadata', 'some-style-module'); |
| 123 | }); |
Viktar Donich | cbc2567 | 2017-07-24 13:23:18 -0700 | [diff] [blame] | 124 | ``` |
Viktar Donich | 7610f78 | 2017-10-02 11:51:41 +0100 | [diff] [blame] | 125 | |
| 126 | [[high-level-api-concepts]] |
| 127 | == High-level DOM API concepts |
| 128 | |
Quinten Yearsley | 888e638 | 2017-12-05 11:11:09 -0800 | [diff] [blame] | 129 | High level API is based on low-level DOM API and is essentially a standardized |
Viktar Donich | 7610f78 | 2017-10-02 11:51:41 +0100 | [diff] [blame] | 130 | way for doing common tasks. It's less flexible, but will be a bit more stable. |
| 131 | |
Quinten Yearsley | 888e638 | 2017-12-05 11:11:09 -0800 | [diff] [blame] | 132 | The common way to access high-level API is through `plugin` instance passed |
| 133 | into setup callback parameter of `Gerrit.install()`, also sometimes referred to |
| 134 | as `self`. |
Viktar Donich | 7610f78 | 2017-10-02 11:51:41 +0100 | [diff] [blame] | 135 | |
| 136 | [[low-level-api]] |
| 137 | == Low-level DOM API |
| 138 | |
Quinten Yearsley | 888e638 | 2017-12-05 11:11:09 -0800 | [diff] [blame] | 139 | The low-level DOM API methods are the base of all UI customization. |
Viktar Donich | 7610f78 | 2017-10-02 11:51:41 +0100 | [diff] [blame] | 140 | |
| 141 | === attributeHelper |
| 142 | `plugin.attributeHelper(element)` |
| 143 | |
Viktar Donich | 6e1e69b | 2018-01-22 14:08:21 -0800 | [diff] [blame] | 144 | Alternative for |
Tao Zhou | d2a8ded | 2020-06-05 16:08:54 +0200 | [diff] [blame^] | 145 | link:https://polymer-library.polymer-project.org/3.0/docs/devguide/data-binding[Polymer data |
Marian Harbach | 3425337 | 2019-12-10 18:01:31 +0100 | [diff] [blame] | 146 | binding,role=external,window=_blank] for plugins that don't use Polymer. Can be used to bind element |
Viktar Donich | 6e1e69b | 2018-01-22 14:08:21 -0800 | [diff] [blame] | 147 | attribute changes to callbacks. |
| 148 | |
Tao Zhou | d2a8ded | 2020-06-05 16:08:54 +0200 | [diff] [blame^] | 149 | See `samples/bind-parameters.js` for examples on both Polymer data bindings |
Viktar Donich | 6e1e69b | 2018-01-22 14:08:21 -0800 | [diff] [blame] | 150 | and `attibuteHelper` usage. |
Viktar Donich | 7610f78 | 2017-10-02 11:51:41 +0100 | [diff] [blame] | 151 | |
| 152 | === eventHelper |
| 153 | `plugin.eventHelper(element)` |
| 154 | |
| 155 | Note: TODO |
| 156 | |
| 157 | === hook |
| 158 | `plugin.hook(endpointName, opt_options)` |
| 159 | |
Viktar Donich | 6d10eca | 2017-11-13 17:57:43 -0800 | [diff] [blame] | 160 | See list of supported link:pg-plugin-endpoints.html[endpoints]. |
Viktar Donich | 6ea8c8a | 2017-12-12 14:41:47 -0800 | [diff] [blame] | 161 | |
Viktar Donich | 7610f78 | 2017-10-02 11:51:41 +0100 | [diff] [blame] | 162 | Note: TODO |
| 163 | |
| 164 | === registerCustomComponent |
| 165 | `plugin.registerCustomComponent(endpointName, opt_moduleName, opt_options)` |
| 166 | |
Viktar Donich | 6ea8c8a | 2017-12-12 14:41:47 -0800 | [diff] [blame] | 167 | See list of supported link:pg-plugin-endpoints.html[endpoints]. |
| 168 | |
Viktar Donich | 7610f78 | 2017-10-02 11:51:41 +0100 | [diff] [blame] | 169 | Note: TODO |
| 170 | |
Thomas Shafer | 0327586 | 2019-02-26 15:39:16 -0800 | [diff] [blame] | 171 | === registerDynamicCustomComponent |
| 172 | `plugin.registerDynamicCustomComponent(dynamicEndpointName, opt_moduleName, |
| 173 | opt_options)` |
| 174 | |
| 175 | See list of supported link:pg-plugin-endpoints.html[endpoints]. |
| 176 | |
| 177 | Note: TODO |
| 178 | |
Viktar Donich | 7610f78 | 2017-10-02 11:51:41 +0100 | [diff] [blame] | 179 | === registerStyleModule |
| 180 | `plugin.registerStyleModule(endpointName, moduleName)` |
| 181 | |
| 182 | Note: TODO |
| 183 | |
| 184 | [[high-level-api]] |
| 185 | == High-level API |
| 186 | |
| 187 | Plugin instance provides access to number of more specific APIs and methods |
| 188 | to be used by plugin authors. |
| 189 | |
Wyatt Allen | c148593 | 2018-03-30 10:53:36 -0700 | [diff] [blame] | 190 | === admin |
| 191 | `plugin.admin()` |
| 192 | |
| 193 | .Params: |
| 194 | - none |
| 195 | |
| 196 | .Returns: |
| 197 | - Instance of link:pg-plugin-admin-api.html[GrAdminApi]. |
| 198 | |
Viktar Donich | 7610f78 | 2017-10-02 11:51:41 +0100 | [diff] [blame] | 199 | === changeReply |
| 200 | `plugin.changeReply()` |
| 201 | |
| 202 | Note: TODO |
| 203 | |
Viktar Donich | 7610f78 | 2017-10-02 11:51:41 +0100 | [diff] [blame] | 204 | === delete |
| 205 | `plugin.delete(url, opt_callback)` |
| 206 | |
| 207 | Note: TODO |
| 208 | |
| 209 | === get |
| 210 | `plugin.get(url, opt_callback)` |
| 211 | |
| 212 | Note: TODO |
| 213 | |
| 214 | === getPluginName |
| 215 | `plugin.getPluginName()` |
| 216 | |
| 217 | Note: TODO |
| 218 | |
| 219 | === getServerInfo |
| 220 | `plugin.getServerInfo()` |
| 221 | |
| 222 | Note: TODO |
| 223 | |
| 224 | === on |
| 225 | `plugin.on(eventName, callback)` |
| 226 | |
| 227 | Note: TODO |
| 228 | |
Viktar Donich | 9c7164a | 2017-12-19 15:03:58 -0800 | [diff] [blame] | 229 | === panel |
| 230 | `plugin.panel(extensionpoint, callback)` |
| 231 | |
| 232 | Deprecated. Use `plugin.registerCustomComponent()` instead. |
| 233 | |
| 234 | ``` js |
| 235 | Gerrit.install(function(self) { |
| 236 | self.panel('CHANGE_SCREEN_BELOW_COMMIT_INFO_BLOCK', function(context) { |
| 237 | context.body.innerHTML = |
| 238 | 'Sample link: <a href="http://some.com/foo">Foo</a>'; |
| 239 | context.show(); |
| 240 | }); |
| 241 | }); |
| 242 | ``` |
| 243 | |
| 244 | Here's the recommended approach that uses Polymer for generating custom elements: |
| 245 | |
Tao Zhou | d2a8ded | 2020-06-05 16:08:54 +0200 | [diff] [blame^] | 246 | ``` js |
| 247 | class SomeCiModule extends Polymer.Element { |
| 248 | static get is() { |
| 249 | return "some-ci-module"; |
| 250 | } |
| 251 | static get template() { |
| 252 | return Polymer.html` |
| 253 | Sample link: <a href="http://some.com/foo">Foo</a> |
| 254 | `; |
| 255 | } |
| 256 | } |
Viktar Donich | 9c7164a | 2017-12-19 15:03:58 -0800 | [diff] [blame] | 257 | |
Tao Zhou | d2a8ded | 2020-06-05 16:08:54 +0200 | [diff] [blame^] | 258 | // Register this element |
| 259 | customElements.define(SomeCiModule.is, SomeCiModule); |
| 260 | |
| 261 | // Install the plugin |
| 262 | Gerrit.install(plugin => { |
| 263 | plugin.registerCustomComponent('change-view-integration', 'some-ci-module'); |
| 264 | }); |
Viktar Donich | 9c7164a | 2017-12-19 15:03:58 -0800 | [diff] [blame] | 265 | ``` |
| 266 | |
Tao Zhou | d2a8ded | 2020-06-05 16:08:54 +0200 | [diff] [blame^] | 267 | See `samples/` for more examples. |
| 268 | |
Viktar Donich | 9c7164a | 2017-12-19 15:03:58 -0800 | [diff] [blame] | 269 | Here's a minimal example that uses low-level DOM Hooks API for the same purpose: |
| 270 | |
| 271 | ``` js |
| 272 | Gerrit.install(plugin => { |
| 273 | plugin.hook('change-view-integration', el => { |
| 274 | el.innerHTML = 'Sample link: <a href="http://some.com/foo">Foo</a>'; |
| 275 | }); |
| 276 | }); |
| 277 | ``` |
| 278 | |
Viktar Donich | 7610f78 | 2017-10-02 11:51:41 +0100 | [diff] [blame] | 279 | === popup |
| 280 | `plugin.popup(moduleName)` |
| 281 | |
| 282 | Note: TODO |
| 283 | |
| 284 | === post |
| 285 | `plugin.post(url, payload, opt_callback)` |
| 286 | |
| 287 | Note: TODO |
| 288 | |
Viktar Donich | bc8088e | 2018-04-23 15:29:57 -0700 | [diff] [blame] | 289 | [[plugin-rest-api]] |
| 290 | === restApi |
| 291 | `plugin.restApi(opt_prefix)` |
| 292 | |
| 293 | .Params: |
| 294 | - (optional) URL prefix, for easy switching into plugin URL space, |
| 295 | e.g. `changes/1/revisions/1/cookbook~say-hello` |
| 296 | |
| 297 | .Returns: |
| 298 | - Instance of link:pg-plugin-rest-api.html[GrPluginRestApi]. |
| 299 | |
| 300 | [[plugin-repo]] |
Paladox none | 2bd5c21 | 2017-11-16 18:54:02 +0000 | [diff] [blame] | 301 | === repo |
| 302 | `plugin.repo()` |
Viktar Donich | 7610f78 | 2017-10-02 11:51:41 +0100 | [diff] [blame] | 303 | |
| 304 | .Params: |
| 305 | - none |
| 306 | |
| 307 | .Returns: |
Paladox none | 2bd5c21 | 2017-11-16 18:54:02 +0000 | [diff] [blame] | 308 | - Instance of link:pg-plugin-repo-api.html[GrRepoApi]. |
Viktar Donich | 7610f78 | 2017-10-02 11:51:41 +0100 | [diff] [blame] | 309 | |
| 310 | === put |
| 311 | `plugin.put(url, payload, opt_callback)` |
| 312 | |
| 313 | Note: TODO |
| 314 | |
Viktar Donich | 6ea8c8a | 2017-12-12 14:41:47 -0800 | [diff] [blame] | 315 | === screen |
| 316 | `plugin.screen(screenName, opt_moduleName)` |
| 317 | |
| 318 | .Params: |
| 319 | - `*string* screenName` URL path fragment of the screen, e.g. |
| 320 | `/x/pluginname/*screenname*` |
| 321 | - `*string* opt_moduleName` (Optional) Web component to be instantiated for this |
| 322 | screen. |
| 323 | |
| 324 | .Returns: |
| 325 | - Instance of GrDomHook. |
| 326 | |
| 327 | === screenUrl |
| 328 | `plugin.url(opt_screenName)` |
| 329 | |
| 330 | .Params: |
| 331 | - `*string* screenName` (optional) URL path fragment of the screen, e.g. |
| 332 | `/x/pluginname/*screenname*` |
| 333 | |
| 334 | .Returns: |
| 335 | - Absolute URL for the screen, e.g. `http://localhost/base/x/pluginname/screenname` |
| 336 | |
Viktar Donich | 17c0226 | 2017-12-21 15:46:02 -0800 | [diff] [blame] | 337 | [[plugin-settings]] |
| 338 | === settings |
| 339 | `plugin.settings()` |
| 340 | |
| 341 | .Params: |
| 342 | - none |
| 343 | |
| 344 | .Returns: |
| 345 | - Instance of link:pg-plugin-settings-api.html[GrSettingsApi]. |
| 346 | |
| 347 | === settingsScreen |
| 348 | `plugin.settingsScreen(path, menu, callback)` |
| 349 | |
| 350 | Deprecated. Use link:#plugin-settings[`plugin.settings()`] instead. |
| 351 | |
Dmitrii Filippov | 941ee63 | 2019-08-22 15:52:37 +0000 | [diff] [blame] | 352 | [[plugin-styles]] |
| 353 | === styles |
| 354 | `plugin.styles()` |
| 355 | |
| 356 | .Params: |
| 357 | - none |
| 358 | |
| 359 | .Returns: |
| 360 | - Instance of link:pg-plugin-styles-api.html[GrStylesApi] |
| 361 | |
Viktar Donich | b6db19e | 2018-04-03 15:32:54 -0700 | [diff] [blame] | 362 | === changeMetadata |
| 363 | `plugin.changeMetadata()` |
| 364 | |
| 365 | .Params: |
| 366 | - none |
| 367 | |
| 368 | .Returns: |
| 369 | - Instance of link:pg-plugin-change-metadata-api.html[GrChangeMetadataApi]. |
| 370 | |
Viktar Donich | 7610f78 | 2017-10-02 11:51:41 +0100 | [diff] [blame] | 371 | === theme |
| 372 | `plugin.theme()` |
| 373 | |
Dmitrii Filippov | 941ee63 | 2019-08-22 15:52:37 +0000 | [diff] [blame] | 374 | |
Viktar Donich | 7610f78 | 2017-10-02 11:51:41 +0100 | [diff] [blame] | 375 | Note: TODO |
| 376 | |
| 377 | === url |
| 378 | `plugin.url(opt_path)` |
| 379 | |
| 380 | Note: TODO |
Viktar Donich | 9c7164a | 2017-12-19 15:03:58 -0800 | [diff] [blame] | 381 | |
| 382 | [[deprecated-api]] |
| 383 | == Deprecated APIs |
| 384 | |
| 385 | Some of the deprecated APIs have limited implementation in PolyGerrit to serve |
| 386 | as a "stepping stone" to allow gradual migration. |
| 387 | |
| 388 | === install |
| 389 | `plugin.deprecated.install()` |
| 390 | |
| 391 | .Params: |
| 392 | - none |
| 393 | |
| 394 | Replaces plugin APIs with a deprecated version. This allows use of deprecated |
| 395 | APIs without changing JS code. For example, `onAction` is not available by |
| 396 | default, and after `plugin.deprecated.install()` it's accessible via |
| 397 | `self.onAction()`. |
| 398 | |
| 399 | === onAction |
| 400 | `plugin.deprecated.onAction(type, view_name, callback)` |
| 401 | |
| 402 | .Params: |
| 403 | - `*string* type` Action type. |
| 404 | - `*string* view_name` REST API action. |
| 405 | - `*function(actionContext)* callback` Callback invoked on action button click. |
| 406 | |
| 407 | Adds a button to the UI with a click callback. Exact button location depends on |
| 408 | parameters. Callback is triggered with an instance of |
| 409 | link:#deprecated-action-context[action context]. |
| 410 | |
| 411 | Support is limited: |
| 412 | |
| 413 | - type is either `change` or `revision`. |
| 414 | |
| 415 | See link:js-api.html#self_onAction[self.onAction] for more info. |
| 416 | |
| 417 | === panel |
| 418 | `plugin.deprecated.panel(extensionpoint, callback)` |
| 419 | |
| 420 | .Params: |
| 421 | - `*string* extensionpoint` |
| 422 | - `*function(screenContext)* callback` |
| 423 | |
| 424 | Adds a UI DOM element and triggers a callback with context to allow direct DOM |
| 425 | access. |
| 426 | |
| 427 | Support is limited: |
| 428 | |
| 429 | - extensionpoint is one of the following: |
| 430 | * CHANGE_SCREEN_BELOW_COMMIT_INFO_BLOCK |
| 431 | * CHANGE_SCREEN_BELOW_CHANGE_INFO_BLOCK |
| 432 | |
| 433 | See link:js-api.html#self_panel[self.panel] for more info. |
| 434 | |
Viktar Donich | 17c0226 | 2017-12-21 15:46:02 -0800 | [diff] [blame] | 435 | === settingsScreen |
| 436 | `plugin.deprecated.settingsScreent(path, menu, callback)` |
| 437 | |
| 438 | .Params: |
| 439 | - `*string* path` URL path fragment of the screen for direct link. |
| 440 | - `*string* menu` Menu item title. |
| 441 | - `*function(settingsScreenContext)* callback` |
| 442 | |
| 443 | Adds a settings menu item and a section in the settings screen that is provided |
| 444 | to plugin for setup. |
| 445 | |
| 446 | See link:js-api.html#self_settingsScreen[self.settingsScreen] for more info. |
| 447 | |
Viktar Donich | 9c7164a | 2017-12-19 15:03:58 -0800 | [diff] [blame] | 448 | [[deprecated-action-context]] |
| 449 | === Action Context (deprecated) |
| 450 | Instance of Action Context is passed to `onAction()` callback. |
| 451 | |
| 452 | Support is limited: |
| 453 | |
| 454 | - `popup()` |
| 455 | - `hide()` |
| 456 | - `refresh()` |
| 457 | - `textfield()` |
| 458 | - `br()` |
| 459 | - `msg()` |
| 460 | - `div()` |
| 461 | - `button()` |
| 462 | - `checkbox()` |
| 463 | - `label()` |
| 464 | - `prependLabel()` |
| 465 | - `call()` |
| 466 | |
| 467 | See link:js-api.html#ActionContext[Action Context] for more info. |