2016-03-04 17:48:22 -05:00
|
|
|
|
// Copyright (C) 2016 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';
|
|
|
|
|
|
2017-05-16 13:56:20 -07:00
|
|
|
|
const UNRESOLVED_EXPAND_COUNT = 5;
|
|
|
|
|
const NEWLINE_PATTERN = /\n/g;
|
2016-12-07 13:36:49 -08:00
|
|
|
|
|
2016-03-04 17:48:22 -05:00
|
|
|
|
Polymer({
|
|
|
|
|
is: 'gr-diff-comment-thread',
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fired when the thread should be discarded.
|
|
|
|
|
*
|
2016-03-25 11:29:36 -04:00
|
|
|
|
* @event thread-discard
|
2016-03-04 17:48:22 -05:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
properties: {
|
|
|
|
|
changeNum: String,
|
|
|
|
|
comments: {
|
|
|
|
|
type: Array,
|
2017-05-16 13:56:20 -07:00
|
|
|
|
value() { return []; },
|
2016-03-04 17:48:22 -05:00
|
|
|
|
},
|
2017-01-27 15:33:08 -08:00
|
|
|
|
locationRange: String,
|
2016-10-10 17:31:56 -07:00
|
|
|
|
keyEventTarget: {
|
|
|
|
|
type: Object,
|
2017-05-16 13:56:20 -07:00
|
|
|
|
value() { return document.body; },
|
2016-10-10 17:31:56 -07:00
|
|
|
|
},
|
2017-01-30 12:03:13 -08:00
|
|
|
|
commentSide: String,
|
2016-03-04 17:48:22 -05:00
|
|
|
|
patchNum: String,
|
|
|
|
|
path: String,
|
2017-07-31 14:33:16 -07:00
|
|
|
|
projectName: {
|
|
|
|
|
type: String,
|
|
|
|
|
observer: '_projectNameChanged',
|
|
|
|
|
},
|
2018-02-05 17:16:30 -08:00
|
|
|
|
hasDraft: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
notify: true,
|
|
|
|
|
reflectToAttribute: true,
|
|
|
|
|
},
|
2017-03-13 16:40:01 -07:00
|
|
|
|
isOnParent: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
value: false,
|
2016-03-22 19:14:12 -04:00
|
|
|
|
},
|
2017-11-17 10:57:46 -08:00
|
|
|
|
parentIndex: {
|
|
|
|
|
type: Number,
|
|
|
|
|
value: null,
|
|
|
|
|
},
|
2018-02-05 17:16:30 -08:00
|
|
|
|
unresolved: {
|
2017-01-04 16:45:21 -08:00
|
|
|
|
type: Boolean,
|
|
|
|
|
notify: true,
|
2018-02-05 17:16:30 -08:00
|
|
|
|
reflectToAttribute: true,
|
2017-01-04 16:45:21 -08:00
|
|
|
|
},
|
2018-02-05 17:16:30 -08:00
|
|
|
|
_showActions: Boolean,
|
|
|
|
|
_lastComment: Object,
|
|
|
|
|
_orderedComments: Array,
|
2017-07-31 14:33:16 -07:00
|
|
|
|
_projectConfig: Object,
|
2016-03-04 17:48:22 -05:00
|
|
|
|
},
|
|
|
|
|
|
2016-10-10 17:31:56 -07:00
|
|
|
|
behaviors: [
|
|
|
|
|
Gerrit.KeyboardShortcutBehavior,
|
|
|
|
|
],
|
|
|
|
|
|
2016-06-14 16:57:23 -07:00
|
|
|
|
listeners: {
|
|
|
|
|
'comment-update': '_handleCommentUpdate',
|
|
|
|
|
},
|
|
|
|
|
|
2016-03-04 17:48:22 -05:00
|
|
|
|
observers: [
|
2017-01-04 16:45:21 -08:00
|
|
|
|
'_commentsChanged(comments.*)',
|
2016-03-04 17:48:22 -05:00
|
|
|
|
],
|
|
|
|
|
|
2016-11-15 17:01:15 -08:00
|
|
|
|
keyBindings: {
|
|
|
|
|
'e shift+e': '_handleEKey',
|
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:56:20 -07:00
|
|
|
|
attached() {
|
|
|
|
|
this._getLoggedIn().then(loggedIn => {
|
2016-03-20 14:14:20 -04:00
|
|
|
|
this._showActions = loggedIn;
|
2017-05-16 13:56:20 -07:00
|
|
|
|
});
|
2017-01-06 11:33:42 -08:00
|
|
|
|
this._setInitialExpandedState();
|
2016-03-04 17:48:22 -05:00
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:56:20 -07:00
|
|
|
|
addOrEditDraft(opt_lineNum, opt_range) {
|
|
|
|
|
const lastComment = this.comments[this.comments.length - 1] || {};
|
Move reply buttons to comment thread
Move all buttons that generate a reply of some sort (done, ack, reply,
quote) to the comment thread instead of the comment [1].
When there is a draft for a particular comment thread, all reply buttons
are hidden [2]. For example, if you click reply, you cannot click done
on the same thread, unless you remove the draft.
Each thread can have up to 1 draft. It's also worth noting that if a
thread has a draft, and the user clicks on the line or 'c' at the same
range, the existing draft will switch to 'editing' form.
[1] With the exception of "please fix" for robot comments.
[2] In this case, The please fix button will be disabled when other
reply buttons are hidden.
Feature: Issue 5410
Change-Id: Id847ee0cba0d0ce4e5b6476f58141866d41ffdad
2017-02-09 16:07:32 -08:00
|
|
|
|
if (lastComment.__draft) {
|
2017-05-16 13:56:20 -07:00
|
|
|
|
const commentEl = this._commentElWithDraftID(
|
2016-03-22 19:14:12 -04:00
|
|
|
|
lastComment.id || lastComment.__draftID);
|
|
|
|
|
commentEl.editing = true;
|
Move reply buttons to comment thread
Move all buttons that generate a reply of some sort (done, ack, reply,
quote) to the comment thread instead of the comment [1].
When there is a draft for a particular comment thread, all reply buttons
are hidden [2]. For example, if you click reply, you cannot click done
on the same thread, unless you remove the draft.
Each thread can have up to 1 draft. It's also worth noting that if a
thread has a draft, and the user clicks on the line or 'c' at the same
range, the existing draft will switch to 'editing' form.
[1] With the exception of "please fix" for robot comments.
[2] In this case, The please fix button will be disabled when other
reply buttons are hidden.
Feature: Issue 5410
Change-Id: Id847ee0cba0d0ce4e5b6476f58141866d41ffdad
2017-02-09 16:07:32 -08:00
|
|
|
|
|
|
|
|
|
// If the comment was collapsed, re-open it to make it clear which
|
|
|
|
|
// actions are available.
|
|
|
|
|
commentEl.collapsed = false;
|
2016-06-09 16:08:04 -07:00
|
|
|
|
} else {
|
2017-05-16 13:56:20 -07:00
|
|
|
|
const range = opt_range ? opt_range :
|
Move reply buttons to comment thread
Move all buttons that generate a reply of some sort (done, ack, reply,
quote) to the comment thread instead of the comment [1].
When there is a draft for a particular comment thread, all reply buttons
are hidden [2]. For example, if you click reply, you cannot click done
on the same thread, unless you remove the draft.
Each thread can have up to 1 draft. It's also worth noting that if a
thread has a draft, and the user clicks on the line or 'c' at the same
range, the existing draft will switch to 'editing' form.
[1] With the exception of "please fix" for robot comments.
[2] In this case, The please fix button will be disabled when other
reply buttons are hidden.
Feature: Issue 5410
Change-Id: Id847ee0cba0d0ce4e5b6476f58141866d41ffdad
2017-02-09 16:07:32 -08:00
|
|
|
|
lastComment ? lastComment.range : undefined;
|
2017-05-16 13:56:20 -07:00
|
|
|
|
const unresolved = lastComment ? lastComment.unresolved : undefined;
|
Move reply buttons to comment thread
Move all buttons that generate a reply of some sort (done, ack, reply,
quote) to the comment thread instead of the comment [1].
When there is a draft for a particular comment thread, all reply buttons
are hidden [2]. For example, if you click reply, you cannot click done
on the same thread, unless you remove the draft.
Each thread can have up to 1 draft. It's also worth noting that if a
thread has a draft, and the user clicks on the line or 'c' at the same
range, the existing draft will switch to 'editing' form.
[1] With the exception of "please fix" for robot comments.
[2] In this case, The please fix button will be disabled when other
reply buttons are hidden.
Feature: Issue 5410
Change-Id: Id847ee0cba0d0ce4e5b6476f58141866d41ffdad
2017-02-09 16:07:32 -08:00
|
|
|
|
this.addDraft(opt_lineNum, range, unresolved);
|
2016-03-22 19:14:12 -04:00
|
|
|
|
}
|
2016-06-09 16:08:04 -07:00
|
|
|
|
},
|
2016-03-22 19:14:12 -04:00
|
|
|
|
|
2017-05-16 13:56:20 -07:00
|
|
|
|
addDraft(opt_lineNum, opt_range, opt_unresolved) {
|
|
|
|
|
const draft = this._newDraft(opt_lineNum, opt_range);
|
2016-05-23 15:24:05 -07:00
|
|
|
|
draft.__editing = true;
|
2017-02-09 08:00:24 -08:00
|
|
|
|
draft.unresolved = opt_unresolved === false ? opt_unresolved : true;
|
2016-05-23 19:03:11 -04:00
|
|
|
|
this.push('comments', draft);
|
2016-03-22 19:14:12 -04:00
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:56:20 -07:00
|
|
|
|
_getLoggedIn() {
|
2016-03-20 14:14:20 -04:00
|
|
|
|
return this.$.restAPI.getLoggedIn();
|
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:56:20 -07:00
|
|
|
|
_commentsChanged(changeRecord) {
|
2016-03-04 17:48:22 -05:00
|
|
|
|
this._orderedComments = this._sortedComments(this.comments);
|
2017-12-05 11:03:52 -08:00
|
|
|
|
this.updateThreadProperties();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
updateThreadProperties() {
|
Move reply buttons to comment thread
Move all buttons that generate a reply of some sort (done, ack, reply,
quote) to the comment thread instead of the comment [1].
When there is a draft for a particular comment thread, all reply buttons
are hidden [2]. For example, if you click reply, you cannot click done
on the same thread, unless you remove the draft.
Each thread can have up to 1 draft. It's also worth noting that if a
thread has a draft, and the user clicks on the line or 'c' at the same
range, the existing draft will switch to 'editing' form.
[1] With the exception of "please fix" for robot comments.
[2] In this case, The please fix button will be disabled when other
reply buttons are hidden.
Feature: Issue 5410
Change-Id: Id847ee0cba0d0ce4e5b6476f58141866d41ffdad
2017-02-09 16:07:32 -08:00
|
|
|
|
if (this._orderedComments.length) {
|
|
|
|
|
this._lastComment = this._getLastComment();
|
2018-02-05 17:16:30 -08:00
|
|
|
|
this.unresolved = this._lastComment.unresolved;
|
Move reply buttons to comment thread
Move all buttons that generate a reply of some sort (done, ack, reply,
quote) to the comment thread instead of the comment [1].
When there is a draft for a particular comment thread, all reply buttons
are hidden [2]. For example, if you click reply, you cannot click done
on the same thread, unless you remove the draft.
Each thread can have up to 1 draft. It's also worth noting that if a
thread has a draft, and the user clicks on the line or 'c' at the same
range, the existing draft will switch to 'editing' form.
[1] With the exception of "please fix" for robot comments.
[2] In this case, The please fix button will be disabled when other
reply buttons are hidden.
Feature: Issue 5410
Change-Id: Id847ee0cba0d0ce4e5b6476f58141866d41ffdad
2017-02-09 16:07:32 -08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:56:20 -07:00
|
|
|
|
_hideActions(_showActions, _lastComment) {
|
Move reply buttons to comment thread
Move all buttons that generate a reply of some sort (done, ack, reply,
quote) to the comment thread instead of the comment [1].
When there is a draft for a particular comment thread, all reply buttons
are hidden [2]. For example, if you click reply, you cannot click done
on the same thread, unless you remove the draft.
Each thread can have up to 1 draft. It's also worth noting that if a
thread has a draft, and the user clicks on the line or 'c' at the same
range, the existing draft will switch to 'editing' form.
[1] With the exception of "please fix" for robot comments.
[2] In this case, The please fix button will be disabled when other
reply buttons are hidden.
Feature: Issue 5410
Change-Id: Id847ee0cba0d0ce4e5b6476f58141866d41ffdad
2017-02-09 16:07:32 -08:00
|
|
|
|
return !_showActions || !_lastComment || !!_lastComment.__draft;
|
2017-01-04 16:45:21 -08:00
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:56:20 -07:00
|
|
|
|
_getLastComment() {
|
2017-01-04 16:45:21 -08:00
|
|
|
|
return this._orderedComments[this._orderedComments.length - 1] || {};
|
2016-03-04 17:48:22 -05:00
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:56:20 -07:00
|
|
|
|
_handleEKey(e) {
|
2016-10-10 17:10:10 -07:00
|
|
|
|
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
|
2016-11-15 17:01:15 -08:00
|
|
|
|
|
|
|
|
|
// Don’t preventDefault in this case because it will render the event
|
|
|
|
|
// useless for other handlers (other gr-diff-comment-thread elements).
|
2016-12-07 18:02:34 -08:00
|
|
|
|
if (e.detail.keyboardEvent.shiftKey) {
|
|
|
|
|
this._expandCollapseComments(true);
|
|
|
|
|
} else {
|
|
|
|
|
if (this.modifierPressed(e)) { return; }
|
|
|
|
|
this._expandCollapseComments(false);
|
|
|
|
|
}
|
2016-10-10 17:31:56 -07:00
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:56:20 -07:00
|
|
|
|
_expandCollapseComments(actionIsCollapse) {
|
|
|
|
|
const comments =
|
2016-10-10 17:31:56 -07:00
|
|
|
|
Polymer.dom(this.root).querySelectorAll('gr-diff-comment');
|
2017-05-16 13:56:20 -07:00
|
|
|
|
for (const comment of comments) {
|
2016-10-10 17:31:56 -07:00
|
|
|
|
comment.collapsed = actionIsCollapse;
|
2017-05-16 13:56:20 -07:00
|
|
|
|
}
|
2016-10-10 17:31:56 -07:00
|
|
|
|
},
|
|
|
|
|
|
2017-01-06 11:33:42 -08:00
|
|
|
|
/**
|
2017-12-08 11:01:26 -08:00
|
|
|
|
* Sets the initial state of the comment thread.
|
|
|
|
|
* Expands the thread if one of the following is true:
|
|
|
|
|
* - last {UNRESOLVED_EXPAND_COUNT} comments expanded by default if the
|
|
|
|
|
* thread is unresolved,
|
|
|
|
|
* - it's a robot comment.
|
2017-01-06 11:33:42 -08:00
|
|
|
|
*/
|
2017-05-16 13:56:20 -07:00
|
|
|
|
_setInitialExpandedState() {
|
2017-02-06 18:15:14 -08:00
|
|
|
|
if (this._orderedComments) {
|
2017-05-16 13:56:20 -07:00
|
|
|
|
for (let i = 0; i < this._orderedComments.length; i++) {
|
2017-12-08 11:01:26 -08:00
|
|
|
|
const comment = this._orderedComments[i];
|
|
|
|
|
const isRobotComment = !!comment.robot_id;
|
|
|
|
|
// False if it's an unresolved comment under UNRESOLVED_EXPAND_COUNT.
|
2018-02-05 17:16:30 -08:00
|
|
|
|
const resolvedThread = !this.unresolved ||
|
2017-12-08 11:01:26 -08:00
|
|
|
|
this._orderedComments.length - i - 1 >= UNRESOLVED_EXPAND_COUNT;
|
|
|
|
|
comment.collapsed = !isRobotComment && resolvedThread;
|
2017-02-06 18:15:14 -08:00
|
|
|
|
}
|
2017-01-06 11:33:42 -08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:56:20 -07:00
|
|
|
|
_sortedComments(comments) {
|
|
|
|
|
return comments.slice().sort((c1, c2) => {
|
|
|
|
|
const c1Date = c1.__date || util.parseDate(c1.updated);
|
|
|
|
|
const c2Date = c2.__date || util.parseDate(c2.updated);
|
|
|
|
|
const dateCompare = c1Date - c2Date;
|
2018-02-05 17:16:30 -08:00
|
|
|
|
// Ensure drafts are at the end. There should only be one but in edge
|
|
|
|
|
// cases could be more. In the unlikely event two drafts are being
|
|
|
|
|
// compared, use the typical date compare.
|
|
|
|
|
if (c2.__draft && !c1.__draft ) { return 0; }
|
|
|
|
|
if (c1.__draft && !c2.__draft ) { return 1; }
|
2017-11-27 16:30:56 -08:00
|
|
|
|
if (dateCompare === 0 && (!c1.id || !c1.id.localeCompare)) { return 0; }
|
2016-12-15 10:42:43 -08:00
|
|
|
|
// If same date, fall back to sorting by id.
|
|
|
|
|
return dateCompare ? dateCompare : c1.id.localeCompare(c2.id);
|
2016-03-04 17:48:22 -05:00
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:56:20 -07:00
|
|
|
|
_createReplyComment(parent, content, opt_isEditing,
|
2017-01-04 16:45:21 -08:00
|
|
|
|
opt_unresolved) {
|
2017-05-16 13:56:20 -07:00
|
|
|
|
const reply = this._newReply(
|
2016-12-27 17:48:38 -05:00
|
|
|
|
this._orderedComments[this._orderedComments.length - 1].id,
|
|
|
|
|
parent.line,
|
2017-01-04 16:45:21 -08:00
|
|
|
|
content,
|
2017-02-06 17:03:57 -08:00
|
|
|
|
opt_unresolved,
|
|
|
|
|
parent.range);
|
2016-12-07 13:36:49 -08:00
|
|
|
|
|
2016-12-22 15:04:11 -08:00
|
|
|
|
// If there is currently a comment in an editing state, add an attribute
|
|
|
|
|
// so that the gr-diff-comment knows not to populate the draft text.
|
2017-05-16 13:56:20 -07:00
|
|
|
|
for (let i = 0; i < this.comments.length; i++) {
|
2016-12-22 15:04:11 -08:00
|
|
|
|
if (this.comments[i].__editing) {
|
|
|
|
|
reply.__otherEditing = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-07 13:36:49 -08:00
|
|
|
|
if (opt_isEditing) {
|
|
|
|
|
reply.__editing = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.push('comments', reply);
|
|
|
|
|
|
|
|
|
|
if (!opt_isEditing) {
|
|
|
|
|
// Allow the reply to render in the dom-repeat.
|
2017-05-16 13:56:20 -07:00
|
|
|
|
this.async(() => {
|
|
|
|
|
const commentEl = this._commentElWithDraftID(reply.__draftID);
|
2016-12-07 13:36:49 -08:00
|
|
|
|
commentEl.save();
|
|
|
|
|
}, 1);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2017-05-18 16:34:17 -07:00
|
|
|
|
_isDraft(comment) {
|
|
|
|
|
return !!comment.__draft;
|
|
|
|
|
},
|
|
|
|
|
|
2017-08-11 16:32:47 -07:00
|
|
|
|
/**
|
|
|
|
|
* @param {boolean=} opt_quote
|
|
|
|
|
*/
|
2017-05-16 13:56:20 -07:00
|
|
|
|
_processCommentReply(opt_quote) {
|
|
|
|
|
const comment = this._lastComment;
|
|
|
|
|
let quoteStr;
|
Move reply buttons to comment thread
Move all buttons that generate a reply of some sort (done, ack, reply,
quote) to the comment thread instead of the comment [1].
When there is a draft for a particular comment thread, all reply buttons
are hidden [2]. For example, if you click reply, you cannot click done
on the same thread, unless you remove the draft.
Each thread can have up to 1 draft. It's also worth noting that if a
thread has a draft, and the user clicks on the line or 'c' at the same
range, the existing draft will switch to 'editing' form.
[1] With the exception of "please fix" for robot comments.
[2] In this case, The please fix button will be disabled when other
reply buttons are hidden.
Feature: Issue 5410
Change-Id: Id847ee0cba0d0ce4e5b6476f58141866d41ffdad
2017-02-09 16:07:32 -08:00
|
|
|
|
if (opt_quote) {
|
2017-05-16 13:56:20 -07:00
|
|
|
|
const msg = comment.message;
|
2016-12-07 13:36:49 -08:00
|
|
|
|
quoteStr = '> ' + msg.replace(NEWLINE_PATTERN, '\n> ') + '\n\n';
|
2016-03-04 17:48:22 -05:00
|
|
|
|
}
|
2017-01-04 16:45:21 -08:00
|
|
|
|
this._createReplyComment(comment, quoteStr, true, comment.unresolved);
|
2016-03-04 17:48:22 -05:00
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:56:20 -07:00
|
|
|
|
_handleCommentReply(e) {
|
Move reply buttons to comment thread
Move all buttons that generate a reply of some sort (done, ack, reply,
quote) to the comment thread instead of the comment [1].
When there is a draft for a particular comment thread, all reply buttons
are hidden [2]. For example, if you click reply, you cannot click done
on the same thread, unless you remove the draft.
Each thread can have up to 1 draft. It's also worth noting that if a
thread has a draft, and the user clicks on the line or 'c' at the same
range, the existing draft will switch to 'editing' form.
[1] With the exception of "please fix" for robot comments.
[2] In this case, The please fix button will be disabled when other
reply buttons are hidden.
Feature: Issue 5410
Change-Id: Id847ee0cba0d0ce4e5b6476f58141866d41ffdad
2017-02-09 16:07:32 -08:00
|
|
|
|
this._processCommentReply();
|
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:56:20 -07:00
|
|
|
|
_handleCommentQuote(e) {
|
Move reply buttons to comment thread
Move all buttons that generate a reply of some sort (done, ack, reply,
quote) to the comment thread instead of the comment [1].
When there is a draft for a particular comment thread, all reply buttons
are hidden [2]. For example, if you click reply, you cannot click done
on the same thread, unless you remove the draft.
Each thread can have up to 1 draft. It's also worth noting that if a
thread has a draft, and the user clicks on the line or 'c' at the same
range, the existing draft will switch to 'editing' form.
[1] With the exception of "please fix" for robot comments.
[2] In this case, The please fix button will be disabled when other
reply buttons are hidden.
Feature: Issue 5410
Change-Id: Id847ee0cba0d0ce4e5b6476f58141866d41ffdad
2017-02-09 16:07:32 -08:00
|
|
|
|
this._processCommentReply(true);
|
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:56:20 -07:00
|
|
|
|
_handleCommentAck(e) {
|
|
|
|
|
const comment = this._lastComment;
|
2017-02-16 11:05:30 -08:00
|
|
|
|
this._createReplyComment(comment, 'Ack', false, false);
|
2016-11-29 16:46:12 -08:00
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:56:20 -07:00
|
|
|
|
_handleCommentDone(e) {
|
|
|
|
|
const comment = this._lastComment;
|
2017-01-04 16:45:21 -08:00
|
|
|
|
this._createReplyComment(comment, 'Done', false, false);
|
2016-12-07 13:36:49 -08:00
|
|
|
|
},
|
2016-03-04 17:48:22 -05:00
|
|
|
|
|
2017-05-16 13:56:20 -07:00
|
|
|
|
_handleCommentFix(e) {
|
|
|
|
|
const comment = e.detail.comment;
|
|
|
|
|
const msg = comment.message;
|
|
|
|
|
const quoteStr = '> ' + msg.replace(NEWLINE_PATTERN, '\n> ') + '\n\n';
|
|
|
|
|
const response = quoteStr + 'Please Fix';
|
2017-01-04 16:45:21 -08:00
|
|
|
|
this._createReplyComment(comment, response, false, true);
|
2016-03-04 17:48:22 -05:00
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:56:20 -07:00
|
|
|
|
_commentElWithDraftID(id) {
|
|
|
|
|
const els = Polymer.dom(this.root).querySelectorAll('gr-diff-comment');
|
|
|
|
|
for (const el of els) {
|
|
|
|
|
if (el.comment.id === id || el.comment.__draftID === id) {
|
|
|
|
|
return el;
|
2016-03-04 17:48:22 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:56:20 -07:00
|
|
|
|
_newReply(inReplyTo, opt_lineNum, opt_message, opt_unresolved,
|
|
|
|
|
opt_range) {
|
|
|
|
|
const d = this._newDraft(opt_lineNum);
|
2016-03-22 19:14:12 -04:00
|
|
|
|
d.in_reply_to = inReplyTo;
|
2017-02-06 17:03:57 -08:00
|
|
|
|
d.range = opt_range;
|
2016-03-22 19:14:12 -04:00
|
|
|
|
if (opt_message != null) {
|
|
|
|
|
d.message = opt_message;
|
|
|
|
|
}
|
2017-01-04 16:45:21 -08:00
|
|
|
|
if (opt_unresolved !== undefined) {
|
|
|
|
|
d.unresolved = opt_unresolved;
|
|
|
|
|
}
|
2016-03-22 19:14:12 -04:00
|
|
|
|
return d;
|
|
|
|
|
},
|
|
|
|
|
|
2017-08-11 16:32:47 -07:00
|
|
|
|
/**
|
|
|
|
|
* @param {number=} opt_lineNum
|
|
|
|
|
* @param {!Object=} opt_range
|
|
|
|
|
*/
|
2017-05-16 13:56:20 -07:00
|
|
|
|
_newDraft(opt_lineNum, opt_range) {
|
|
|
|
|
const d = {
|
2016-03-04 17:48:22 -05:00
|
|
|
|
__draft: true,
|
|
|
|
|
__draftID: Math.random().toString(36),
|
|
|
|
|
__date: new Date(),
|
2016-03-22 19:14:12 -04:00
|
|
|
|
path: this.path,
|
2017-02-09 07:34:23 -08:00
|
|
|
|
patchNum: this.patchNum,
|
2017-03-21 14:56:19 -07:00
|
|
|
|
side: this._getSide(this.isOnParent),
|
2017-01-30 12:03:13 -08:00
|
|
|
|
__commentSide: this.commentSide,
|
2016-03-04 17:48:22 -05:00
|
|
|
|
};
|
2016-03-24 17:59:35 -04:00
|
|
|
|
if (opt_lineNum) {
|
|
|
|
|
d.line = opt_lineNum;
|
|
|
|
|
}
|
2016-06-09 16:08:04 -07:00
|
|
|
|
if (opt_range) {
|
|
|
|
|
d.range = {
|
|
|
|
|
start_line: opt_range.startLine,
|
|
|
|
|
start_character: opt_range.startChar,
|
|
|
|
|
end_line: opt_range.endLine,
|
|
|
|
|
end_character: opt_range.endChar,
|
|
|
|
|
};
|
|
|
|
|
}
|
2017-11-17 10:57:46 -08:00
|
|
|
|
if (this.parentIndex) {
|
|
|
|
|
d.parent = this.parentIndex;
|
|
|
|
|
}
|
2016-03-24 17:59:35 -04:00
|
|
|
|
return d;
|
2016-03-04 17:48:22 -05:00
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:56:20 -07:00
|
|
|
|
_getSide(isOnParent) {
|
2017-03-21 14:56:19 -07:00
|
|
|
|
if (isOnParent) { return 'PARENT'; }
|
|
|
|
|
return 'REVISION';
|
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:56:20 -07:00
|
|
|
|
_handleCommentDiscard(e) {
|
|
|
|
|
const diffCommentEl = Polymer.dom(e).rootTarget;
|
|
|
|
|
const comment = diffCommentEl.comment;
|
|
|
|
|
const idx = this._indexOf(comment, this.comments);
|
2016-03-04 17:48:22 -05:00
|
|
|
|
if (idx == -1) {
|
|
|
|
|
throw Error('Cannot find comment ' +
|
|
|
|
|
JSON.stringify(diffCommentEl.comment));
|
|
|
|
|
}
|
|
|
|
|
this.splice('comments', idx, 1);
|
|
|
|
|
if (this.comments.length == 0) {
|
2016-06-09 16:08:04 -07:00
|
|
|
|
this.fire('thread-discard', {lastComment: comment});
|
2016-03-04 17:48:22 -05:00
|
|
|
|
}
|
2016-12-22 15:04:11 -08:00
|
|
|
|
|
|
|
|
|
// Check to see if there are any other open comments getting edited and
|
|
|
|
|
// set the local storage value to its message value.
|
2017-05-16 13:56:20 -07:00
|
|
|
|
for (const changeComment of this.comments) {
|
|
|
|
|
if (changeComment.__editing) {
|
|
|
|
|
const commentLocation = {
|
2016-12-22 15:04:11 -08:00
|
|
|
|
changeNum: this.changeNum,
|
|
|
|
|
patchNum: this.patchNum,
|
2017-05-16 13:56:20 -07:00
|
|
|
|
path: changeComment.path,
|
|
|
|
|
line: changeComment.line,
|
2016-12-22 15:04:11 -08:00
|
|
|
|
};
|
|
|
|
|
return this.$.storage.setDraftComment(commentLocation,
|
2017-05-16 13:56:20 -07:00
|
|
|
|
changeComment.message);
|
2016-12-22 15:04:11 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-04 17:48:22 -05:00
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:56:20 -07:00
|
|
|
|
_handleCommentUpdate(e) {
|
|
|
|
|
const comment = e.detail.comment;
|
|
|
|
|
const index = this._indexOf(comment, this.comments);
|
2016-06-14 16:57:23 -07:00
|
|
|
|
if (index === -1) {
|
|
|
|
|
// This should never happen: comment belongs to another thread.
|
2017-03-28 17:02:44 -07:00
|
|
|
|
console.warn('Comment update for another comment thread.');
|
2016-06-14 16:57:23 -07:00
|
|
|
|
return;
|
|
|
|
|
}
|
2017-01-04 16:45:21 -08:00
|
|
|
|
this.set(['comments', index], comment);
|
2017-12-05 11:03:52 -08:00
|
|
|
|
// Because of the way we pass these comment objects around by-ref, in
|
|
|
|
|
// combination with the fact that Polymer does dirty checking in
|
|
|
|
|
// observers, the this.set() call above will not cause a thread update in
|
|
|
|
|
// some situations.
|
|
|
|
|
this.updateThreadProperties();
|
2016-06-14 16:57:23 -07:00
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:56:20 -07:00
|
|
|
|
_indexOf(comment, arr) {
|
|
|
|
|
for (let i = 0; i < arr.length; i++) {
|
|
|
|
|
const c = arr[i];
|
2016-03-04 17:48:22 -05:00
|
|
|
|
if ((c.__draftID != null && c.__draftID == comment.__draftID) ||
|
|
|
|
|
(c.id != null && c.id == comment.id)) {
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
},
|
2017-01-04 16:45:21 -08:00
|
|
|
|
|
2017-05-16 13:56:20 -07:00
|
|
|
|
_computeHostClass(unresolved) {
|
2017-01-04 16:45:21 -08:00
|
|
|
|
return unresolved ? 'unresolved' : '';
|
|
|
|
|
},
|
2017-07-31 14:33:16 -07:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load the project config when a project name has been provided.
|
|
|
|
|
* @param {string} name The project name.
|
|
|
|
|
*/
|
|
|
|
|
_projectNameChanged(name) {
|
|
|
|
|
if (!name) { return; }
|
|
|
|
|
this.$.restAPI.getProjectConfig(name).then(config => {
|
|
|
|
|
this._projectConfig = config;
|
|
|
|
|
});
|
|
|
|
|
},
|
2016-03-04 17:48:22 -05:00
|
|
|
|
});
|
|
|
|
|
})();
|