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:50:27 -07:00
|
|
|
|
const STORAGE_DEBOUNCE_INTERVAL = 400;
|
2016-05-18 12:37:53 -07:00
|
|
|
|
|
2016-03-04 17:48:22 -05:00
|
|
|
|
Polymer({
|
|
|
|
|
is: 'gr-diff-comment',
|
|
|
|
|
|
2016-12-07 13:36:49 -08:00
|
|
|
|
/**
|
|
|
|
|
* Fired when the create fix comment action is triggered.
|
|
|
|
|
*
|
|
|
|
|
* @event create-fix-comment
|
2016-03-04 17:48:22 -05:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fired when this comment is discarded.
|
|
|
|
|
*
|
2016-03-25 11:29:36 -04:00
|
|
|
|
* @event comment-discard
|
2016-03-04 17:48:22 -05:00
|
|
|
|
*/
|
|
|
|
|
|
2016-05-19 17:24:45 -07:00
|
|
|
|
/**
|
|
|
|
|
* Fired when this comment is saved.
|
|
|
|
|
*
|
|
|
|
|
* @event comment-save
|
|
|
|
|
*/
|
|
|
|
|
|
2016-05-23 15:24:05 -07:00
|
|
|
|
/**
|
|
|
|
|
* Fired when this comment is updated.
|
|
|
|
|
*
|
|
|
|
|
* @event comment-update
|
|
|
|
|
*/
|
|
|
|
|
|
2016-06-09 16:08:04 -07:00
|
|
|
|
/**
|
|
|
|
|
* @event comment-mouse-over
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @event comment-mouse-out
|
|
|
|
|
*/
|
|
|
|
|
|
2016-03-04 17:48:22 -05:00
|
|
|
|
properties: {
|
|
|
|
|
changeNum: String,
|
2017-08-11 16:32:47 -07:00
|
|
|
|
/** @type {?} */
|
2016-03-04 17:48:22 -05:00
|
|
|
|
comment: {
|
|
|
|
|
type: Object,
|
|
|
|
|
notify: true,
|
2016-05-23 15:24:05 -07:00
|
|
|
|
observer: '_commentChanged',
|
2016-03-04 17:48:22 -05:00
|
|
|
|
},
|
2016-12-07 13:36:49 -08:00
|
|
|
|
isRobotComment: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
value: false,
|
|
|
|
|
reflectToAttribute: true,
|
|
|
|
|
},
|
2016-03-04 17:48:22 -05:00
|
|
|
|
disabled: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
value: false,
|
|
|
|
|
reflectToAttribute: true,
|
|
|
|
|
},
|
|
|
|
|
draft: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
value: false,
|
|
|
|
|
observer: '_draftChanged',
|
|
|
|
|
},
|
|
|
|
|
editing: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
value: false,
|
|
|
|
|
observer: '_editingChanged',
|
|
|
|
|
},
|
2016-12-07 13:36:49 -08:00
|
|
|
|
hasChildren: Boolean,
|
2016-03-04 17:48:22 -05:00
|
|
|
|
patchNum: String,
|
|
|
|
|
showActions: Boolean,
|
2016-12-07 13:36:49 -08:00
|
|
|
|
_showHumanActions: Boolean,
|
|
|
|
|
_showRobotActions: Boolean,
|
2016-10-10 17:31:56 -07:00
|
|
|
|
collapsed: {
|
2016-10-06 10:18:32 -07:00
|
|
|
|
type: Boolean,
|
|
|
|
|
value: true,
|
|
|
|
|
observer: '_toggleCollapseClass',
|
|
|
|
|
},
|
2017-08-11 16:32:47 -07:00
|
|
|
|
/** @type {?} */
|
2016-03-04 17:48:22 -05:00
|
|
|
|
projectConfig: Object,
|
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
|
|
|
|
robotButtonDisabled: Boolean,
|
2017-05-08 10:40:06 -07:00
|
|
|
|
_isAdmin: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
value: false,
|
|
|
|
|
},
|
2016-03-04 17:48:22 -05:00
|
|
|
|
|
2017-07-05 11:17:26 -07:00
|
|
|
|
_xhrPromise: Object, // Used for testing.
|
2016-05-23 13:53:10 -07:00
|
|
|
|
_messageText: {
|
2016-05-18 12:37:53 -07:00
|
|
|
|
type: String,
|
2016-05-23 19:03:11 -04:00
|
|
|
|
value: '',
|
2016-05-23 13:53:10 -07:00
|
|
|
|
observer: '_messageTextChanged',
|
2016-05-18 12:37:53 -07:00
|
|
|
|
},
|
2017-01-30 12:03:13 -08:00
|
|
|
|
commentSide: String,
|
2017-01-04 16:45:21 -08:00
|
|
|
|
|
|
|
|
|
resolved: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
observer: '_toggleResolved',
|
|
|
|
|
},
|
2016-03-04 17:48:22 -05:00
|
|
|
|
},
|
|
|
|
|
|
2016-05-23 19:03:11 -04:00
|
|
|
|
observers: [
|
|
|
|
|
'_commentMessageChanged(comment.message)',
|
|
|
|
|
'_loadLocalDraft(changeNum, patchNum, comment)',
|
2016-12-07 13:36:49 -08:00
|
|
|
|
'_isRobotComment(comment)',
|
|
|
|
|
'_calculateActionstoShow(showActions, isRobotComment)',
|
2016-05-23 19:03:11 -04:00
|
|
|
|
],
|
2016-03-04 17:48:22 -05:00
|
|
|
|
|
2017-06-19 11:27:22 -07:00
|
|
|
|
behaviors: [
|
|
|
|
|
Gerrit.KeyboardShortcutBehavior,
|
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
keyBindings: {
|
|
|
|
|
'ctrl+enter meta+enter ctrl+s meta+s': '_handleSaveKey',
|
|
|
|
|
'esc': '_handleEsc',
|
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
attached() {
|
2016-10-06 10:18:32 -07:00
|
|
|
|
if (this.editing) {
|
2016-10-10 17:31:56 -07:00
|
|
|
|
this.collapsed = false;
|
2017-01-06 11:33:42 -08:00
|
|
|
|
} else if (this.comment) {
|
|
|
|
|
this.collapsed = this.comment.collapsed;
|
2016-10-06 10:18:32 -07:00
|
|
|
|
}
|
2017-05-16 13:50:27 -07:00
|
|
|
|
this._getIsAdmin().then(isAdmin => {
|
2017-05-08 10:40:06 -07:00
|
|
|
|
this._isAdmin = isAdmin;
|
2017-05-16 13:50:27 -07:00
|
|
|
|
});
|
2016-10-06 10:18:32 -07:00
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
detached() {
|
2016-06-09 16:08:04 -07:00
|
|
|
|
this.cancelDebouncer('fire-update');
|
2017-05-03 10:03:35 -07:00
|
|
|
|
this.$.editTextarea.closeDropdown();
|
2016-05-23 15:24:05 -07:00
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_computeShowHideText(collapsed) {
|
2016-10-06 10:18:32 -07:00
|
|
|
|
return collapsed ? '◀' : '▼';
|
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_calculateActionstoShow(showActions, isRobotComment) {
|
2016-12-07 13:36:49 -08:00
|
|
|
|
this._showHumanActions = showActions && !isRobotComment;
|
|
|
|
|
this._showRobotActions = showActions && isRobotComment;
|
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_isRobotComment(comment) {
|
2016-12-07 13:36:49 -08:00
|
|
|
|
this.isRobotComment = !!comment.robot_id;
|
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
isOnParent() {
|
2017-03-21 14:56:19 -07:00
|
|
|
|
return this.side === 'PARENT';
|
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_getIsAdmin() {
|
2017-05-08 10:40:06 -07:00
|
|
|
|
return this.$.restAPI.getIsAdmin();
|
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
save() {
|
2016-05-23 13:53:10 -07:00
|
|
|
|
this.comment.message = this._messageText;
|
2017-03-13 16:40:01 -07:00
|
|
|
|
|
2016-03-04 17:48:22 -05:00
|
|
|
|
this.disabled = true;
|
2016-05-18 12:37:53 -07:00
|
|
|
|
|
2016-12-01 10:55:14 -08:00
|
|
|
|
this._eraseDraftComment();
|
2016-05-18 12:37:53 -07:00
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
this._xhrPromise = this._saveDraft(this.comment).then(response => {
|
2016-03-04 17:48:22 -05:00
|
|
|
|
this.disabled = false;
|
2016-05-02 15:59:59 -04:00
|
|
|
|
if (!response.ok) { return response; }
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
return this.$.restAPI.getResponseObject(response).then(obj => {
|
|
|
|
|
const comment = obj;
|
2016-05-03 15:14:57 -04:00
|
|
|
|
comment.__draft = true;
|
|
|
|
|
// Maintain the ephemeral draft ID for identification by other
|
|
|
|
|
// elements.
|
|
|
|
|
if (this.comment.__draftID) {
|
|
|
|
|
comment.__draftID = this.comment.__draftID;
|
|
|
|
|
}
|
2017-01-30 12:03:13 -08:00
|
|
|
|
comment.__commentSide = this.commentSide;
|
2016-05-03 15:14:57 -04:00
|
|
|
|
this.comment = comment;
|
|
|
|
|
this.editing = false;
|
2016-06-09 16:08:04 -07:00
|
|
|
|
this._fireSave();
|
2016-05-03 15:14:57 -04:00
|
|
|
|
return obj;
|
2017-05-16 13:50:27 -07:00
|
|
|
|
});
|
|
|
|
|
}).catch(err => {
|
2016-03-04 17:48:22 -05:00
|
|
|
|
this.disabled = false;
|
2016-05-02 15:59:59 -04:00
|
|
|
|
throw err;
|
2017-05-16 13:50:27 -07:00
|
|
|
|
});
|
2016-03-04 17:48:22 -05:00
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_eraseDraftComment() {
|
2017-05-16 15:12:08 -07:00
|
|
|
|
// Prevents a race condition in which removing the draft comment occurs
|
|
|
|
|
// prior to it being saved.
|
|
|
|
|
this.cancelDebouncer('store');
|
2017-05-16 13:50:27 -07:00
|
|
|
|
|
2016-12-01 10:55:14 -08:00
|
|
|
|
this.$.storage.eraseDraftComment({
|
|
|
|
|
changeNum: this.changeNum,
|
2017-03-13 11:42:42 -07:00
|
|
|
|
patchNum: this._getPatchNum(),
|
2016-12-01 10:55:14 -08:00
|
|
|
|
path: this.comment.path,
|
|
|
|
|
line: this.comment.line,
|
2017-01-31 16:57:14 -08:00
|
|
|
|
range: this.comment.range,
|
2016-12-01 10:55:14 -08:00
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_commentChanged(comment) {
|
2016-05-23 15:24:05 -07:00
|
|
|
|
this.editing = !!comment.__editing;
|
2017-01-04 16:45:21 -08:00
|
|
|
|
this.resolved = !comment.unresolved;
|
2016-06-09 16:08:04 -07:00
|
|
|
|
if (this.editing) { // It's a new draft/reply, notify.
|
|
|
|
|
this._fireUpdate();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2017-08-11 16:32:47 -07:00
|
|
|
|
/**
|
|
|
|
|
* @param {!Object=} opt_mixin
|
|
|
|
|
*
|
|
|
|
|
* @return {!Object}
|
|
|
|
|
*/
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_getEventPayload(opt_mixin) {
|
|
|
|
|
return Object.assign({}, opt_mixin, {
|
2016-06-09 16:08:04 -07:00
|
|
|
|
comment: this.comment,
|
|
|
|
|
patchNum: this.patchNum,
|
2017-05-16 13:50:27 -07:00
|
|
|
|
});
|
2016-06-09 16:08:04 -07:00
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_fireSave() {
|
2016-06-09 16:08:04 -07:00
|
|
|
|
this.fire('comment-save', this._getEventPayload());
|
2016-05-23 15:24:05 -07:00
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_fireUpdate() {
|
|
|
|
|
this.debounce('fire-update', () => {
|
2016-06-09 16:08:04 -07:00
|
|
|
|
this.fire('comment-update', this._getEventPayload());
|
2016-07-14 12:31:09 -07:00
|
|
|
|
});
|
2016-05-23 15:24:05 -07:00
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_draftChanged(draft) {
|
2016-03-04 17:48:22 -05:00
|
|
|
|
this.$.container.classList.toggle('draft', draft);
|
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_editingChanged(editing, previousValue) {
|
2016-03-04 17:48:22 -05:00
|
|
|
|
this.$.container.classList.toggle('editing', editing);
|
|
|
|
|
if (editing) {
|
2017-05-03 10:03:35 -07:00
|
|
|
|
this.$.editTextarea.putCursorAtEnd();
|
2016-03-04 17:48:22 -05:00
|
|
|
|
}
|
|
|
|
|
if (this.comment && this.comment.id) {
|
|
|
|
|
this.$$('.cancel').hidden = !editing;
|
|
|
|
|
}
|
2016-05-23 15:24:05 -07:00
|
|
|
|
if (this.comment) {
|
|
|
|
|
this.comment.__editing = this.editing;
|
|
|
|
|
}
|
2016-06-09 16:08:04 -07:00
|
|
|
|
if (editing != !!previousValue) {
|
|
|
|
|
// To prevent event firing on comment creation.
|
|
|
|
|
this._fireUpdate();
|
|
|
|
|
}
|
2016-03-04 17:48:22 -05:00
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_computeLinkToComment(comment) {
|
2016-03-04 17:48:22 -05:00
|
|
|
|
return '#' + comment.line;
|
|
|
|
|
},
|
|
|
|
|
|
2017-05-18 16:34:17 -07:00
|
|
|
|
_computeDeleteButtonClass(isAdmin, draft) {
|
|
|
|
|
return isAdmin && !draft ? 'showDeleteButtons' : '';
|
2017-05-18 13:02:14 -07:00
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_computeSaveDisabled(draft) {
|
2016-03-04 17:48:22 -05:00
|
|
|
|
return draft == null || draft.trim() == '';
|
|
|
|
|
},
|
|
|
|
|
|
2017-06-19 11:27:22 -07:00
|
|
|
|
_handleSaveKey(e) {
|
|
|
|
|
if (this._messageText.length) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
this._handleSave(e);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_handleEsc(e) {
|
|
|
|
|
if (!this._messageText.length) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
this._handleCancel(e);
|
2016-03-04 17:48:22 -05:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_handleToggleCollapsed() {
|
2016-10-10 17:31:56 -07:00
|
|
|
|
this.collapsed = !this.collapsed;
|
2016-10-06 10:18:32 -07:00
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_toggleCollapseClass(collapsed) {
|
2016-10-10 17:31:56 -07:00
|
|
|
|
if (collapsed) {
|
2016-10-06 10:18:32 -07:00
|
|
|
|
this.$.container.classList.add('collapsed');
|
|
|
|
|
} else {
|
|
|
|
|
this.$.container.classList.remove('collapsed');
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_commentMessageChanged(message) {
|
2016-05-23 19:03:11 -04:00
|
|
|
|
this._messageText = message || '';
|
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_messageTextChanged(newValue, oldValue) {
|
2016-05-23 19:03:11 -04:00
|
|
|
|
if (!this.comment || (this.comment && this.comment.id)) { return; }
|
2016-05-18 12:37:53 -07:00
|
|
|
|
|
2016-12-22 15:04:11 -08:00
|
|
|
|
// Keep comment.message in sync so that gr-diff-comment-thread is aware
|
|
|
|
|
// of the current message in the case that another comment is deleted.
|
|
|
|
|
this.comment.message = this._messageText || '';
|
2017-05-16 13:50:27 -07:00
|
|
|
|
this.debounce('store', () => {
|
|
|
|
|
const message = this._messageText;
|
2016-05-23 13:53:10 -07:00
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
const commentLocation = {
|
2016-05-23 13:53:10 -07:00
|
|
|
|
changeNum: this.changeNum,
|
2017-03-13 11:42:42 -07:00
|
|
|
|
patchNum: this._getPatchNum(),
|
2016-05-23 13:53:10 -07:00
|
|
|
|
path: this.comment.path,
|
|
|
|
|
line: this.comment.line,
|
2017-01-31 16:57:14 -08:00
|
|
|
|
range: this.comment.range,
|
2016-05-23 13:53:10 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if ((!this._messageText || !this._messageText.length) && oldValue) {
|
|
|
|
|
// If the draft has been modified to be empty, then erase the storage
|
|
|
|
|
// entry.
|
|
|
|
|
this.$.storage.eraseDraftComment(commentLocation);
|
|
|
|
|
} else {
|
|
|
|
|
this.$.storage.setDraftComment(commentLocation, message);
|
2016-05-18 12:37:53 -07:00
|
|
|
|
}
|
2016-05-23 15:24:05 -07:00
|
|
|
|
this._fireUpdate();
|
2016-05-23 13:53:10 -07:00
|
|
|
|
}, STORAGE_DEBOUNCE_INTERVAL);
|
2016-05-18 12:37:53 -07:00
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_handleLinkTap(e) {
|
2016-03-04 17:48:22 -05:00
|
|
|
|
e.preventDefault();
|
2017-05-16 13:50:27 -07:00
|
|
|
|
const hash = this._computeLinkToComment(this.comment);
|
2016-03-04 17:48:22 -05:00
|
|
|
|
// Don't add the hash to the window history if it's already there.
|
|
|
|
|
// Otherwise you mess up expected back button behavior.
|
|
|
|
|
if (window.location.hash == hash) { return; }
|
|
|
|
|
// Change the URL but don’t trigger a nav event. Otherwise it will
|
|
|
|
|
// reload the page.
|
|
|
|
|
page.show(window.location.pathname + hash, null, false);
|
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_handleReply(e) {
|
2016-11-15 17:01:15 -08:00
|
|
|
|
e.preventDefault();
|
2016-12-07 13:36:49 -08:00
|
|
|
|
this.fire('create-reply-comment', this._getEventPayload(),
|
|
|
|
|
{bubbles: false});
|
2016-03-04 17:48:22 -05:00
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_handleQuote(e) {
|
2016-11-15 17:01:15 -08:00
|
|
|
|
e.preventDefault();
|
2016-12-19 17:59:48 -08:00
|
|
|
|
this.fire('create-reply-comment', this._getEventPayload({quote: true}),
|
2016-12-07 13:36:49 -08:00
|
|
|
|
{bubbles: false});
|
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_handleFix(e) {
|
2016-12-07 13:36:49 -08:00
|
|
|
|
e.preventDefault();
|
|
|
|
|
this.fire('create-fix-comment', this._getEventPayload({quote: true}),
|
|
|
|
|
{bubbles: false});
|
2016-03-04 17:48:22 -05:00
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_handleAck(e) {
|
2016-11-29 16:46:12 -08:00
|
|
|
|
e.preventDefault();
|
2016-12-07 13:36:49 -08:00
|
|
|
|
this.fire('create-ack-comment', this._getEventPayload(),
|
|
|
|
|
{bubbles: false});
|
2016-11-29 16:46:12 -08:00
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_handleDone(e) {
|
2016-11-15 17:01:15 -08:00
|
|
|
|
e.preventDefault();
|
2016-12-07 13:36:49 -08:00
|
|
|
|
this.fire('create-done-comment', this._getEventPayload(),
|
|
|
|
|
{bubbles: false});
|
2016-03-04 17:48:22 -05:00
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_handleEdit(e) {
|
2016-11-15 17:01:15 -08:00
|
|
|
|
e.preventDefault();
|
2016-05-23 13:53:10 -07:00
|
|
|
|
this._messageText = this.comment.message;
|
2016-03-04 17:48:22 -05:00
|
|
|
|
this.editing = true;
|
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_handleSave(e) {
|
2016-11-15 17:01:15 -08:00
|
|
|
|
e.preventDefault();
|
2017-01-04 16:45:21 -08:00
|
|
|
|
this.set('comment.__editing', false);
|
2016-03-04 17:48:22 -05:00
|
|
|
|
this.save();
|
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_handleCancel(e) {
|
2016-11-15 17:01:15 -08:00
|
|
|
|
e.preventDefault();
|
2017-05-16 13:50:27 -07:00
|
|
|
|
if (!this.comment.message || this.comment.message.trim().length === 0) {
|
2016-06-09 16:08:04 -07:00
|
|
|
|
this._fireDiscard();
|
2016-03-04 17:48:22 -05:00
|
|
|
|
return;
|
|
|
|
|
}
|
2016-05-23 13:53:10 -07:00
|
|
|
|
this._messageText = this.comment.message;
|
2016-03-04 17:48:22 -05:00
|
|
|
|
this.editing = false;
|
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_fireDiscard() {
|
2016-08-05 15:05:50 -07:00
|
|
|
|
this.cancelDebouncer('fire-update');
|
2016-06-09 16:08:04 -07:00
|
|
|
|
this.fire('comment-discard', this._getEventPayload());
|
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_handleDiscard(e) {
|
2016-11-15 17:01:15 -08:00
|
|
|
|
e.preventDefault();
|
2016-03-04 17:48:22 -05:00
|
|
|
|
if (!this.comment.__draft) {
|
|
|
|
|
throw Error('Cannot discard a non-draft comment.');
|
|
|
|
|
}
|
2016-05-23 19:03:11 -04:00
|
|
|
|
this.editing = false;
|
2016-03-04 17:48:22 -05:00
|
|
|
|
this.disabled = true;
|
2016-12-01 10:55:14 -08:00
|
|
|
|
this._eraseDraftComment();
|
|
|
|
|
|
2016-05-03 15:14:57 -04:00
|
|
|
|
if (!this.comment.id) {
|
2016-05-23 19:03:11 -04:00
|
|
|
|
this.disabled = false;
|
2016-06-09 16:08:04 -07:00
|
|
|
|
this._fireDiscard();
|
2016-03-04 17:48:22 -05:00
|
|
|
|
return;
|
|
|
|
|
}
|
2016-05-03 15:14:57 -04:00
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
this._xhrPromise = this._deleteDraft(this.comment).then(response => {
|
|
|
|
|
this.disabled = false;
|
|
|
|
|
if (!response.ok) { return response; }
|
2016-05-02 15:59:59 -04:00
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
this._fireDiscard();
|
|
|
|
|
}).catch(err => {
|
|
|
|
|
this.disabled = false;
|
|
|
|
|
throw err;
|
|
|
|
|
});
|
2016-03-04 17:48:22 -05:00
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_saveDraft(draft) {
|
2016-05-03 15:14:57 -04:00
|
|
|
|
return this.$.restAPI.saveDiffDraft(this.changeNum, this.patchNum, draft);
|
2016-03-04 17:48:22 -05:00
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_deleteDraft(draft) {
|
2016-05-03 15:14:57 -04:00
|
|
|
|
return this.$.restAPI.deleteDiffDraft(this.changeNum, this.patchNum,
|
|
|
|
|
draft);
|
2016-03-04 17:48:22 -05:00
|
|
|
|
},
|
2016-05-18 12:37:53 -07:00
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_getPatchNum() {
|
2017-03-21 14:56:19 -07:00
|
|
|
|
return this.isOnParent() ? 'PARENT' : this.patchNum;
|
2017-03-13 11:42:42 -07:00
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_loadLocalDraft(changeNum, patchNum, comment) {
|
2016-05-23 19:03:11 -04:00
|
|
|
|
// Only apply local drafts to comments that haven't been saved
|
|
|
|
|
// remotely, and haven't been given a default message already.
|
2016-12-22 15:04:11 -08:00
|
|
|
|
//
|
|
|
|
|
// Don't get local draft if there is another comment that is currently
|
|
|
|
|
// in an editing state.
|
|
|
|
|
if (!comment || comment.id || comment.message || comment.__otherEditing) {
|
|
|
|
|
delete comment.__otherEditing;
|
2016-05-23 19:03:11 -04:00
|
|
|
|
return;
|
|
|
|
|
}
|
2016-05-18 12:37:53 -07:00
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
const draft = this.$.storage.getDraftComment({
|
|
|
|
|
changeNum,
|
2017-03-13 11:42:42 -07:00
|
|
|
|
patchNum: this._getPatchNum(),
|
2016-05-23 19:03:11 -04:00
|
|
|
|
path: comment.path,
|
|
|
|
|
line: comment.line,
|
2017-01-31 16:57:14 -08:00
|
|
|
|
range: comment.range,
|
2016-05-23 19:03:11 -04:00
|
|
|
|
});
|
2016-05-18 12:37:53 -07:00
|
|
|
|
|
2016-05-23 19:03:11 -04:00
|
|
|
|
if (draft) {
|
|
|
|
|
this.set('comment.message', draft.message);
|
|
|
|
|
}
|
2016-05-18 12:37:53 -07:00
|
|
|
|
},
|
2016-06-09 16:08:04 -07:00
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_handleMouseEnter(e) {
|
2016-06-09 16:08:04 -07:00
|
|
|
|
this.fire('comment-mouse-over', this._getEventPayload());
|
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_handleMouseLeave(e) {
|
2016-06-09 16:08:04 -07:00
|
|
|
|
this.fire('comment-mouse-out', this._getEventPayload());
|
|
|
|
|
},
|
2017-01-04 16:45:21 -08:00
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_handleToggleResolved() {
|
2017-01-04 16:45:21 -08:00
|
|
|
|
this.resolved = !this.resolved;
|
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_toggleResolved(resolved) {
|
2017-01-04 16:45:21 -08:00
|
|
|
|
this.comment.unresolved = !resolved;
|
|
|
|
|
this.fire('comment-update', this._getEventPayload());
|
|
|
|
|
},
|
2017-05-08 10:40:06 -07:00
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_handleCommentDelete() {
|
2017-05-08 10:40:06 -07:00
|
|
|
|
Polymer.dom(Gerrit.getRootElement()).appendChild(this.$.overlay);
|
2017-05-23 14:05:07 -07:00
|
|
|
|
this.async(() => {
|
|
|
|
|
this.$.overlay.open();
|
|
|
|
|
}, 1);
|
2017-05-08 10:40:06 -07:00
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_handleCancelDeleteComment() {
|
2017-05-08 10:40:06 -07:00
|
|
|
|
Polymer.dom(Gerrit.getRootElement()).removeChild(this.$.overlay);
|
|
|
|
|
this.$.overlay.close();
|
|
|
|
|
},
|
|
|
|
|
|
2017-05-16 13:50:27 -07:00
|
|
|
|
_handleConfirmDeleteComment() {
|
2017-05-08 10:40:06 -07:00
|
|
|
|
this.$.restAPI.deleteComment(
|
|
|
|
|
this.changeNum, this.patchNum, this.comment.id,
|
2017-05-16 13:50:27 -07:00
|
|
|
|
this.$.confirmDeleteComment.message).then(newComment => {
|
|
|
|
|
this._handleCancelDeleteComment();
|
|
|
|
|
this.comment = newComment;
|
|
|
|
|
});
|
2017-05-08 10:40:06 -07:00
|
|
|
|
},
|
2016-03-04 17:48:22 -05:00
|
|
|
|
});
|
|
|
|
|
})();
|