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-01-06 11:33:42 -08:00
|
|
|
|
var UNRESOLVED_EXPAND_COUNT = 5;
|
2016-12-07 13:36:49 -08:00
|
|
|
|
var NEWLINE_PATTERN = /\n/g;
|
|
|
|
|
|
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,
|
|
|
|
|
value: function() { return []; },
|
|
|
|
|
},
|
2017-01-27 15:33:08 -08:00
|
|
|
|
locationRange: String,
|
2016-10-10 17:31:56 -07:00
|
|
|
|
keyEventTarget: {
|
|
|
|
|
type: Object,
|
|
|
|
|
value: function() { return document.body; },
|
|
|
|
|
},
|
2017-01-30 12:03:13 -08:00
|
|
|
|
commentSide: String,
|
2016-03-04 17:48:22 -05:00
|
|
|
|
patchNum: String,
|
|
|
|
|
path: String,
|
|
|
|
|
projectConfig: Object,
|
2016-03-22 19:14:12 -04:00
|
|
|
|
side: {
|
|
|
|
|
type: String,
|
|
|
|
|
value: 'REVISION',
|
|
|
|
|
},
|
2016-03-04 17:48:22 -05:00
|
|
|
|
|
2016-03-20 14:14:20 -04:00
|
|
|
|
_showActions: Boolean,
|
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: Object,
|
2016-03-04 17:48:22 -05:00
|
|
|
|
_orderedComments: Array,
|
2017-01-04 16:45:21 -08:00
|
|
|
|
_unresolved: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
notify: true,
|
|
|
|
|
},
|
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',
|
|
|
|
|
},
|
|
|
|
|
|
2016-03-04 17:48:22 -05:00
|
|
|
|
attached: function() {
|
2016-03-20 14:14:20 -04:00
|
|
|
|
this._getLoggedIn().then(function(loggedIn) {
|
|
|
|
|
this._showActions = loggedIn;
|
|
|
|
|
}.bind(this));
|
2017-01-06 11:33:42 -08:00
|
|
|
|
this._setInitialExpandedState();
|
2016-03-04 17:48:22 -05:00
|
|
|
|
},
|
|
|
|
|
|
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
|
|
|
|
addOrEditDraft: function(opt_lineNum, opt_range) {
|
|
|
|
|
var lastComment = this.comments[this.comments.length - 1] || {};
|
|
|
|
|
if (lastComment.__draft) {
|
2016-03-22 19:14:12 -04:00
|
|
|
|
var commentEl = this._commentElWithDraftID(
|
|
|
|
|
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 {
|
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
|
|
|
|
var range = opt_range ? opt_range :
|
|
|
|
|
lastComment ? lastComment.range : undefined;
|
|
|
|
|
var unresolved = lastComment ? lastComment.unresolved : undefined;
|
|
|
|
|
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-02-09 08:00:24 -08:00
|
|
|
|
addDraft: function(opt_lineNum, opt_range, opt_unresolved) {
|
2016-06-09 16:08:04 -07:00
|
|
|
|
var 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
|
|
|
|
},
|
|
|
|
|
|
2016-03-20 14:14:20 -04:00
|
|
|
|
_getLoggedIn: function() {
|
|
|
|
|
return this.$.restAPI.getLoggedIn();
|
|
|
|
|
},
|
|
|
|
|
|
2016-03-04 17:48:22 -05:00
|
|
|
|
_commentsChanged: function(changeRecord) {
|
|
|
|
|
this._orderedComments = this._sortedComments(this.comments);
|
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();
|
|
|
|
|
this._unresolved = this._lastComment.unresolved;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_hideActions: function(_showActions, _lastComment) {
|
|
|
|
|
return !_showActions || !_lastComment || !!_lastComment.__draft;
|
2017-01-04 16:45:21 -08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_getLastComment: function() {
|
|
|
|
|
return this._orderedComments[this._orderedComments.length - 1] || {};
|
2016-03-04 17:48:22 -05:00
|
|
|
|
},
|
|
|
|
|
|
2016-11-15 17:01:15 -08:00
|
|
|
|
_handleEKey: function(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
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_expandCollapseComments: function(actionIsCollapse) {
|
|
|
|
|
var comments =
|
|
|
|
|
Polymer.dom(this.root).querySelectorAll('gr-diff-comment');
|
|
|
|
|
comments.forEach(function(comment) {
|
|
|
|
|
comment.collapsed = actionIsCollapse;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
2017-01-06 11:33:42 -08:00
|
|
|
|
/**
|
|
|
|
|
* Sets the initial state of the comment thread to have the last
|
|
|
|
|
* {UNRESOLVED_EXPAND_COUNT} comments expanded by default if the
|
|
|
|
|
* thread is unresolved.
|
|
|
|
|
*/
|
|
|
|
|
_setInitialExpandedState: function() {
|
|
|
|
|
var comment;
|
2017-02-06 18:15:14 -08:00
|
|
|
|
if (this._orderedComments) {
|
|
|
|
|
for (var i = 0; i < this._orderedComments.length; i++) {
|
|
|
|
|
comment = this._orderedComments[i];
|
|
|
|
|
comment.collapsed =
|
|
|
|
|
this._orderedComments.length - i - 1 >= UNRESOLVED_EXPAND_COUNT ||
|
|
|
|
|
!this._unresolved;
|
|
|
|
|
}
|
2017-01-06 11:33:42 -08:00
|
|
|
|
}
|
2017-02-06 18:15:14 -08:00
|
|
|
|
|
2017-01-06 11:33:42 -08:00
|
|
|
|
},
|
|
|
|
|
|
2016-03-04 17:48:22 -05:00
|
|
|
|
_sortedComments: function(comments) {
|
2016-12-15 10:42:43 -08:00
|
|
|
|
return comments.slice().sort(function(c1, c2) {
|
2016-03-04 17:48:22 -05:00
|
|
|
|
var c1Date = c1.__date || util.parseDate(c1.updated);
|
|
|
|
|
var c2Date = c2.__date || util.parseDate(c2.updated);
|
2016-12-15 10:42:43 -08:00
|
|
|
|
var dateCompare = c1Date - c2Date;
|
|
|
|
|
// 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-01-04 16:45:21 -08:00
|
|
|
|
_createReplyComment: function(parent, content, opt_isEditing,
|
|
|
|
|
opt_unresolved) {
|
2016-12-27 17:48:38 -05:00
|
|
|
|
var reply = this._newReply(
|
|
|
|
|
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.
|
|
|
|
|
for (var i = 0; i < this.comments.length; i++) {
|
|
|
|
|
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.
|
|
|
|
|
this.async(function() {
|
|
|
|
|
var commentEl = this._commentElWithDraftID(reply.__draftID);
|
|
|
|
|
commentEl.save();
|
|
|
|
|
}, 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
|
|
|
|
_processCommentReply: function(opt_quote) {
|
|
|
|
|
var comment = this._lastComment;
|
2016-03-04 17:48:22 -05:00
|
|
|
|
var 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) {
|
2016-03-04 17:48:22 -05:00
|
|
|
|
var 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
|
|
|
|
},
|
|
|
|
|
|
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
|
|
|
|
_handleCommentReply: function(e) {
|
|
|
|
|
this._processCommentReply();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_handleCommentQuote: function(e) {
|
|
|
|
|
this._processCommentReply(true);
|
|
|
|
|
},
|
|
|
|
|
|
2016-11-29 16:46:12 -08:00
|
|
|
|
_handleCommentAck: function(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
|
|
|
|
var comment = this._lastComment;
|
2017-01-04 16:45:21 -08:00
|
|
|
|
this._createReplyComment(comment, 'Ack', false, comment.unresolved);
|
2016-11-29 16:46:12 -08:00
|
|
|
|
},
|
|
|
|
|
|
2016-03-04 17:48:22 -05:00
|
|
|
|
_handleCommentDone: function(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
|
|
|
|
var 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
|
|
|
|
|
2016-12-07 13:36:49 -08:00
|
|
|
|
_handleCommentFix: function(e) {
|
|
|
|
|
var comment = e.detail.comment;
|
|
|
|
|
var msg = comment.message;
|
|
|
|
|
var quoteStr = '> ' + msg.replace(NEWLINE_PATTERN, '\n> ') + '\n\n';
|
|
|
|
|
var 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
|
|
|
|
},
|
|
|
|
|
|
2016-03-22 19:14:12 -04:00
|
|
|
|
_commentElWithDraftID: function(id) {
|
|
|
|
|
var els = Polymer.dom(this.root).querySelectorAll('gr-diff-comment');
|
|
|
|
|
for (var i = 0; i < els.length; i++) {
|
|
|
|
|
if (els[i].comment.id === id || els[i].comment.__draftID === id) {
|
|
|
|
|
return els[i];
|
2016-03-04 17:48:22 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
},
|
|
|
|
|
|
2017-02-06 17:03:57 -08:00
|
|
|
|
_newReply: function(inReplyTo, opt_lineNum, opt_message, opt_unresolved,
|
|
|
|
|
opt_range) {
|
2016-03-24 17:59:35 -04:00
|
|
|
|
var 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;
|
|
|
|
|
},
|
|
|
|
|
|
2016-06-09 16:08:04 -07:00
|
|
|
|
_newDraft: function(opt_lineNum, opt_range) {
|
2016-03-24 17:59:35 -04:00
|
|
|
|
var 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,
|
|
|
|
|
side: this.side,
|
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,
|
|
|
|
|
};
|
|
|
|
|
}
|
2016-03-24 17:59:35 -04:00
|
|
|
|
return d;
|
2016-03-04 17:48:22 -05:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_handleCommentDiscard: function(e) {
|
|
|
|
|
var diffCommentEl = Polymer.dom(e).rootTarget;
|
2016-06-09 16:08:04 -07:00
|
|
|
|
var comment = diffCommentEl.comment;
|
|
|
|
|
var 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.
|
|
|
|
|
for (var i = 0; i < this.comments.length; i++) {
|
|
|
|
|
if (this.comments[i].__editing) {
|
|
|
|
|
var commentLocation = {
|
|
|
|
|
changeNum: this.changeNum,
|
|
|
|
|
patchNum: this.patchNum,
|
|
|
|
|
path: this.comments[i].path,
|
|
|
|
|
line: this.comments[i].line,
|
|
|
|
|
};
|
|
|
|
|
return this.$.storage.setDraftComment(commentLocation,
|
|
|
|
|
this.comments[i].message);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-04 17:48:22 -05:00
|
|
|
|
},
|
|
|
|
|
|
2016-06-14 16:57:23 -07:00
|
|
|
|
_handleCommentUpdate: function(e) {
|
|
|
|
|
var comment = e.detail.comment;
|
|
|
|
|
var index = this._indexOf(comment, this.comments);
|
|
|
|
|
if (index === -1) {
|
|
|
|
|
// This should never happen: comment belongs to another thread.
|
|
|
|
|
console.error('Comment update for another comment thread.');
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-01-04 16:45:21 -08:00
|
|
|
|
this.set(['comments', index], comment);
|
2016-06-14 16:57:23 -07:00
|
|
|
|
},
|
|
|
|
|
|
2016-03-04 17:48:22 -05:00
|
|
|
|
_indexOf: function(comment, arr) {
|
|
|
|
|
for (var i = 0; i < arr.length; i++) {
|
|
|
|
|
var c = arr[i];
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
_computeHostClass: function(unresolved) {
|
|
|
|
|
return unresolved ? 'unresolved' : '';
|
|
|
|
|
},
|
2016-03-04 17:48:22 -05:00
|
|
|
|
});
|
|
|
|
|
})();
|