Merge "Update URL generation in gr-comment-list"
This commit is contained in:
@@ -523,7 +523,7 @@ limitations under the License.
|
|||||||
messages="[[_change.messages]]"
|
messages="[[_change.messages]]"
|
||||||
reviewer-updates="[[_change.reviewer_updates]]"
|
reviewer-updates="[[_change.reviewer_updates]]"
|
||||||
comments="[[_comments]]"
|
comments="[[_comments]]"
|
||||||
project-config="[[_projectConfig]]"
|
project-name="[[_change.project]]"
|
||||||
show-reply-buttons="[[_loggedIn]]"
|
show-reply-buttons="[[_loggedIn]]"
|
||||||
on-reply="_handleMessageReply"></gr-messages-list>
|
on-reply="_handleMessageReply"></gr-messages-list>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ limitations under the License.
|
|||||||
<link rel="import" href="../../../behaviors/gr-path-list-behavior/gr-path-list-behavior.html">
|
<link rel="import" href="../../../behaviors/gr-path-list-behavior/gr-path-list-behavior.html">
|
||||||
<link rel="import" href="../../../behaviors/gr-url-encoding-behavior.html">
|
<link rel="import" href="../../../behaviors/gr-url-encoding-behavior.html">
|
||||||
<link rel="import" href="../../../bower_components/polymer/polymer.html">
|
<link rel="import" href="../../../bower_components/polymer/polymer.html">
|
||||||
|
<link rel="import" href="../../core/gr-navigation/gr-navigation.html">
|
||||||
<link rel="import" href="../../shared/gr-formatted-text/gr-formatted-text.html">
|
<link rel="import" href="../../shared/gr-formatted-text/gr-formatted-text.html">
|
||||||
<link rel="import" href="../../../styles/shared-styles.html">
|
<link rel="import" href="../../../styles/shared-styles.html">
|
||||||
|
|
||||||
@@ -76,7 +77,7 @@ limitations under the License.
|
|||||||
class="message"
|
class="message"
|
||||||
no-trailing-margin
|
no-trailing-margin
|
||||||
content="[[comment.message]]"
|
content="[[comment.message]]"
|
||||||
config="[[projectConfig.commentlinks]]"></gr-formatted-text>
|
config="[[commentLinks]]"></gr-formatted-text>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -30,7 +30,8 @@
|
|||||||
changeNum: Number,
|
changeNum: Number,
|
||||||
comments: Object,
|
comments: Object,
|
||||||
patchNum: Number,
|
patchNum: Number,
|
||||||
projectConfig: Object,
|
commentLinks: Object,
|
||||||
|
projectName: String,
|
||||||
},
|
},
|
||||||
|
|
||||||
_computeFilesFromComments(comments) {
|
_computeFilesFromComments(comments) {
|
||||||
@@ -39,8 +40,8 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
_computeFileDiffURL(file, changeNum, patchNum) {
|
_computeFileDiffURL(file, changeNum, patchNum) {
|
||||||
return this.getBaseUrl() + '/c/' + changeNum + '/' + patchNum + '/' +
|
return Gerrit.Nav.getUrlForDiffById(this.changeNum, this.projectName,
|
||||||
this.encodeURL(file);
|
file, patchNum);
|
||||||
},
|
},
|
||||||
|
|
||||||
_computeFileDisplayName(path) {
|
_computeFileDisplayName(path) {
|
||||||
@@ -57,13 +58,8 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
_computeDiffLineURL(file, changeNum, patchNum, comment) {
|
_computeDiffLineURL(file, changeNum, patchNum, comment) {
|
||||||
let diffURL = this._computeFileDiffURL(file, changeNum, patchNum);
|
return Gerrit.Nav.getUrlForDiffById(this.changeNum, this.projectName,
|
||||||
if (comment.line) {
|
file, patchNum, null, comment.line, this._isOnParent(comment));
|
||||||
diffURL += '#';
|
|
||||||
if (this._isOnParent(comment)) { diffURL += 'b'; }
|
|
||||||
diffURL += comment.line;
|
|
||||||
}
|
|
||||||
return diffURL;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_computeCommentsForFile(comments, file) {
|
_computeCommentsForFile(comments, file) {
|
||||||
|
|||||||
@@ -60,12 +60,6 @@ limitations under the License.
|
|||||||
assert.deepEqual(element._computeFilesFromComments(null), []);
|
assert.deepEqual(element._computeFilesFromComments(null), []);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('_computeFileDiffURL', () => {
|
|
||||||
const expected = '/c/change/patch/file';
|
|
||||||
const actual = element._computeFileDiffURL('file', 'change', 'patch');
|
|
||||||
assert.equal(actual, expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('_computeFileDisplayName', () => {
|
test('_computeFileDisplayName', () => {
|
||||||
assert.equal(element._computeFileDisplayName('/COMMIT_MSG'),
|
assert.equal(element._computeFileDisplayName('/COMMIT_MSG'),
|
||||||
'Commit message');
|
'Commit message');
|
||||||
@@ -75,27 +69,6 @@ limitations under the License.
|
|||||||
'/foo/bar/baz');
|
'/foo/bar/baz');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('_computeDiffLineURL', () => {
|
|
||||||
const comment = {line: 123, side: 'REVISION', patch_set: 10};
|
|
||||||
let expected = '/c/change/patch/file#123';
|
|
||||||
let actual = element._computeDiffLineURL('file', 'change', 'patch',
|
|
||||||
comment);
|
|
||||||
assert.equal(actual, expected);
|
|
||||||
|
|
||||||
comment.line = 321;
|
|
||||||
comment.side = 'PARENT';
|
|
||||||
|
|
||||||
expected = '/c/change/patch/file#b321';
|
|
||||||
actual = element._computeDiffLineURL('file', 'change', 'patch', comment);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('_computeDiffLineURL encoding', () => {
|
|
||||||
const comment = {line: 123, side: 'REVISION', patch_set: 10};
|
|
||||||
const expected = '/c/123/2/x%252By.md#123';
|
|
||||||
const actual = element._computeDiffLineURL('x+y.md', '123', '2', comment);
|
|
||||||
assert.equal(actual, expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('_computePatchDisplayName', () => {
|
test('_computePatchDisplayName', () => {
|
||||||
const comment = {line: 123, side: 'REVISION', patch_set: 10};
|
const comment = {line: 123, side: 'REVISION', patch_set: 10};
|
||||||
|
|
||||||
|
|||||||
@@ -152,12 +152,13 @@ limitations under the License.
|
|||||||
<gr-formatted-text
|
<gr-formatted-text
|
||||||
class="message hideOnCollapsed"
|
class="message hideOnCollapsed"
|
||||||
content="[[message.message]]"
|
content="[[message.message]]"
|
||||||
config="[[projectConfig.commentlinks]]"></gr-formatted-text>
|
config="[[_commentLinks]]"></gr-formatted-text>
|
||||||
<gr-comment-list
|
<gr-comment-list
|
||||||
comments="[[comments]]"
|
comments="[[comments]]"
|
||||||
change-num="[[changeNum]]"
|
change-num="[[changeNum]]"
|
||||||
patch-num="[[message._revision_number]]"
|
patch-num="[[message._revision_number]]"
|
||||||
project-config="[[projectConfig]]"></gr-comment-list>
|
project-name="[[projectName]]"
|
||||||
|
comment-links="[[_commentLinks]]"></gr-comment-list>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<template is="dom-if" if="[[_computeIsReviewerUpdate(message)]]">
|
<template is="dom-if" if="[[_computeIsReviewerUpdate(message)]]">
|
||||||
|
|||||||
@@ -74,7 +74,11 @@
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
computed: '_computeShowReplyButton(message, _loggedIn)',
|
computed: '_computeShowReplyButton(message, _loggedIn)',
|
||||||
},
|
},
|
||||||
projectConfig: Object,
|
projectName: {
|
||||||
|
type: String,
|
||||||
|
observer: '_projectNameChanged',
|
||||||
|
},
|
||||||
|
_commentLinks: Object,
|
||||||
// Computed property needed to trigger Polymer value observing.
|
// Computed property needed to trigger Polymer value observing.
|
||||||
_expanded: {
|
_expanded: {
|
||||||
type: Object,
|
type: Object,
|
||||||
@@ -240,5 +244,11 @@
|
|||||||
|
|
||||||
return this.getAnonymousName(this.config);
|
return this.getAnonymousName(this.config);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_projectNameChanged(name) {
|
||||||
|
this.$.restAPI.getProjectConfig(name).then(config => {
|
||||||
|
this._commentLinks = config.commentlinks;
|
||||||
|
});
|
||||||
|
},
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ limitations under the License.
|
|||||||
message="[[message]]"
|
message="[[message]]"
|
||||||
comments="[[_computeCommentsForMessage(comments, message)]]"
|
comments="[[_computeCommentsForMessage(comments, message)]]"
|
||||||
hide-automated="[[_hideAutomated]]"
|
hide-automated="[[_hideAutomated]]"
|
||||||
project-config="[[projectConfig]]"
|
project-name="[[projectName]]"
|
||||||
show-reply-button="[[showReplyButtons]]"
|
show-reply-button="[[showReplyButtons]]"
|
||||||
on-scroll-to="_handleScrollTo"
|
on-scroll-to="_handleScrollTo"
|
||||||
data-message-id$="[[message.id]]"></gr-message>
|
data-message-id$="[[message.id]]"></gr-message>
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
value() { return []; },
|
value() { return []; },
|
||||||
},
|
},
|
||||||
comments: Object,
|
comments: Object,
|
||||||
projectConfig: Object,
|
projectName: String,
|
||||||
showReplyButtons: {
|
showReplyButtons: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
value: false,
|
value: false,
|
||||||
|
|||||||
@@ -43,6 +43,10 @@ limitations under the License.
|
|||||||
// - `basePatchNum`, optional, Number, the patch for the left-hand-side
|
// - `basePatchNum`, optional, Number, the patch for the left-hand-side
|
||||||
// of the diff. If `basePatchNum` is provided, then `patchNum` must
|
// of the diff. If `basePatchNum` is provided, then `patchNum` must
|
||||||
// also be provided.
|
// also be provided.
|
||||||
|
// - `lineNum`, optional, Number, the line number to be selected on load.
|
||||||
|
// - `leftSide`, optional, Boolean, if a `lineNum` is provided, a value
|
||||||
|
// of true selects the line from base of the patch range. False by
|
||||||
|
// default.
|
||||||
|
|
||||||
window.Gerrit = window.Gerrit || {};
|
window.Gerrit = window.Gerrit || {};
|
||||||
|
|
||||||
@@ -166,9 +170,9 @@ limitations under the License.
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {!Object} change The change object.
|
* @param {!Object} change The change object.
|
||||||
* @param {number} opt_patchNum
|
* @param {number=} opt_patchNum
|
||||||
* @param {number|string} opt_basePatchNum The string 'PARENT' can be used
|
* @param {number|string=} opt_basePatchNum The string 'PARENT' can be
|
||||||
* for none.
|
* used for none.
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
getUrlForChange(change, opt_patchNum, opt_basePatchNum) {
|
getUrlForChange(change, opt_patchNum, opt_basePatchNum) {
|
||||||
@@ -187,9 +191,9 @@ limitations under the License.
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {!Object} change The change object.
|
* @param {!Object} change The change object.
|
||||||
* @param {number} opt_patchNum
|
* @param {number=} opt_patchNum
|
||||||
* @param {number|string} opt_basePatchNum The string 'PARENT' can be used
|
* @param {number|string=} opt_basePatchNum The string 'PARENT' can be
|
||||||
* for none.
|
* used for none.
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
navigateToChange(change, opt_patchNum, opt_basePatchNum) {
|
navigateToChange(change, opt_patchNum, opt_basePatchNum) {
|
||||||
@@ -199,13 +203,30 @@ limitations under the License.
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {!Object} change The change object.
|
* @param {!Object} change The change object.
|
||||||
* @param {!String} path The file path.
|
* @param {!string} path The file path.
|
||||||
* @param {number} opt_patchNum
|
* @param {number=} opt_patchNum
|
||||||
* @param {number|string} opt_basePatchNum The string 'PARENT' can be used
|
* @param {number|string=} opt_basePatchNum The string 'PARENT' can be
|
||||||
* for none.
|
* used for none.
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
getUrlForDiff(change, path, opt_patchNum, opt_basePatchNum) {
|
getUrlForDiff(change, path, opt_patchNum, opt_basePatchNum) {
|
||||||
|
return this.getUrlForDiffById(change._number, change.project, path,
|
||||||
|
opt_patchNum, opt_basePatchNum);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {!number} change The change object.
|
||||||
|
* @param {!string} projectName The name of the project.
|
||||||
|
* @param {!string} path The file path.
|
||||||
|
* @param {number=} opt_patchNum
|
||||||
|
* @param {number|string=} opt_basePatchNum The string 'PARENT' can be
|
||||||
|
* used for none.
|
||||||
|
* @param {number=} opt_lineNum
|
||||||
|
* @param {boolean=} opt_leftSide
|
||||||
|
* @return {string}
|
||||||
|
*/
|
||||||
|
getUrlForDiffById(changeNum, projectName, path, opt_patchNum,
|
||||||
|
opt_basePatchNum, opt_lineNum, opt_leftSide) {
|
||||||
if (opt_basePatchNum === PARENT_PATCHNUM) {
|
if (opt_basePatchNum === PARENT_PATCHNUM) {
|
||||||
opt_basePatchNum = undefined;
|
opt_basePatchNum = undefined;
|
||||||
}
|
}
|
||||||
@@ -213,19 +234,22 @@ limitations under the License.
|
|||||||
this._checkPatchRange(opt_patchNum, opt_basePatchNum);
|
this._checkPatchRange(opt_patchNum, opt_basePatchNum);
|
||||||
return this._getUrlFor({
|
return this._getUrlFor({
|
||||||
view: Gerrit.Nav.View.DIFF,
|
view: Gerrit.Nav.View.DIFF,
|
||||||
changeNum: change._number,
|
changeNum,
|
||||||
|
projectName,
|
||||||
path,
|
path,
|
||||||
patchNum: opt_patchNum,
|
patchNum: opt_patchNum,
|
||||||
basePatchNum: opt_basePatchNum,
|
basePatchNum: opt_basePatchNum,
|
||||||
|
lineNum: opt_lineNum,
|
||||||
|
leftSide: opt_leftSide,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {!Object} change The change object.
|
* @param {!Object} change The change object.
|
||||||
* @param {!String} path The file path.
|
* @param {!string} path The file path.
|
||||||
* @param {number} opt_patchNum
|
* @param {number=} opt_patchNum
|
||||||
* @param {number|string} opt_basePatchNum The string 'PARENT' can be used
|
* @param {number|string=} opt_basePatchNum The string 'PARENT' can be
|
||||||
* for none.
|
* used for none.
|
||||||
*/
|
*/
|
||||||
navigateToDiff(change, path, opt_patchNum, opt_basePatchNum) {
|
navigateToDiff(change, path, opt_patchNum, opt_basePatchNum) {
|
||||||
this._navigate(this.getUrlForDiff(change, path, opt_patchNum,
|
this._navigate(this.getUrlForDiff(change, path, opt_patchNum,
|
||||||
|
|||||||
@@ -580,6 +580,12 @@
|
|||||||
if (range.length) { range = '/' + range; }
|
if (range.length) { range = '/' + range; }
|
||||||
|
|
||||||
url = `/c/${params.changeNum}${range}/${encode(params.path, true)}`;
|
url = `/c/${params.changeNum}${range}/${encode(params.path, true)}`;
|
||||||
|
|
||||||
|
if (params.lineNum) {
|
||||||
|
url += '#';
|
||||||
|
if (params.leftSide) { url += 'b'; }
|
||||||
|
url += params.lineNum;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Can\'t generate');
|
throw new Error('Can\'t generate');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,6 +93,13 @@ limitations under the License.
|
|||||||
delete params.basePatchNum;
|
delete params.basePatchNum;
|
||||||
assert.equal(element._generateUrl(params),
|
assert.equal(element._generateUrl(params),
|
||||||
'/c/42/2/foo+bar/my%252Bfile.txt%2525');
|
'/c/42/2/foo+bar/my%252Bfile.txt%2525');
|
||||||
|
|
||||||
|
params.path = 'file.cpp';
|
||||||
|
params.lineNum = 123;
|
||||||
|
assert.equal(element._generateUrl(params), '/c/42/2/file.cpp#123');
|
||||||
|
|
||||||
|
params.leftSide = true;
|
||||||
|
assert.equal(element._generateUrl(params), '/c/42/2/file.cpp#b123');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user