Weblinks API for embedded scenario using Gerrit.Nav interface
Gerrit.Nav.setup() now takes a weblinks generator function as a third
parameter. Here's the function signature:
``` js
Gerrit.Nav.setup(navigate, generateUrl, generateWeblinks)
```
Weblinks generator function takes single payload parameter with
`type` property that determines which part of the UI is the consumer of
the weblinks. `type` property can be one of `file`, `change`, or
`patchset`.
For `file` type, payload will also contain string properties:
`repo`, `commit`, `file`.
For `pachset` type, payload will also contain string properties:
`repo`, `commit`.
For `change` type, payload will also contain string properties:
`repo`, `commit`.
If server provides weblinks, those will be passed as `options.weblinks`
property on the main payload object.
Change-Id: I0d9de3a295435304e2b6aad551112440075cf098
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js
index f0b70c1..8c2954b 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js
+++ b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js
@@ -63,6 +63,8 @@
},
/** @type {?} */
_patchRange: Object,
+ /** @type {?} */
+ _commitRange: Object,
/**
* @type {{
* subject: string,
@@ -208,6 +210,7 @@
_getChangeDetail(changeNum) {
return this.$.restAPI.getDiffChangeDetail(changeNum).then(change => {
this._change = change;
+ return change;
});
},
@@ -531,7 +534,20 @@
this._userPrefs = prefs;
}));
- promises.push(this._getChangeDetail(this._changeNum));
+ promises.push(this._getChangeDetail(this._changeNum).then(change => {
+ let commit;
+ let baseCommit;
+ for (const k in change.revisions) {
+ if (!change.revisions.hasOwnProperty(k)) continue;
+ const patchNum = change.revisions[k]._number.toString();
+ if (patchNum === this._patchRange.patchNum) {
+ commit = k;
+ } else if (patchNum === this._patchRange.basePatchNum) {
+ baseCommit = k;
+ }
+ }
+ this._commitRange = {commit, baseCommit};
+ }));
promises.push(this._loadComments());