From bf4dbe6619477e4528caebe503eed1c3cf4b29e1 Mon Sep 17 00:00:00 2001 From: Ravi Mistry Date: Thu, 28 Dec 2017 13:14:02 -0500 Subject: [PATCH] Adding checkbox to annotations API to toggle annotations on/off Change-Id: I661869c5ef60da9180aecd2fb4e672648cdc80f4 --- .../diff/gr-diff-view/gr-diff-view.html | 6 +++ .../gr-annotation-actions-js-api.js | 39 +++++++++++++++ .../gr-annotation-actions-js-api_test.html | 50 ++++++++++++++++++- .../app/samples/coverage-plugin.html | 46 +++++++++++------ 4 files changed, 126 insertions(+), 15 deletions(-) diff --git a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.html b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.html index 2ce29db0d1..107ae2f8e1 100644 --- a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.html +++ b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.html @@ -277,6 +277,12 @@ limitations under the License. on-tap="_handlePrefsTap">Preferences + + + } onAttached The function that will be called + * when the checkbox is attached to the page. + */ + GrAnnotationActionsInterface.prototype.enableToggleCheckbox = function( + checkboxLabel, onAttached) { + this.plugin.hook('annotation-toggler').onAttached(element => { + if (!element.content.hidden) { + console.error( + element.content.id + ' is already enabled. Cannot re-enable.'); + return; + } + element.content.removeAttribute('hidden'); + + const label = element.content.querySelector('#annotation-label'); + if (checkboxLabel) { + label.textContent = checkboxLabel; + } else { + label.textContent = 'Enable'; + } + const checkbox = element.content.querySelector('#annotation-checkbox'); + onAttached(checkbox); + }); + return this; + }; + /** * The notify function will call the listeners of all required annotation * layers. Intended to be called by the plugin when all required data for diff --git a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-annotation-actions-js-api_test.html b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-annotation-actions-js-api_test.html index 39623edf8e..a19df85a65 100644 --- a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-annotation-actions-js-api_test.html +++ b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-annotation-actions-js-api_test.html @@ -23,14 +23,23 @@ limitations under the License. + + + +