summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/notes.js
diff options
context:
space:
mode:
authorPawel Chojnacki <pawel@chojnacki.ws>2017-06-22 15:05:52 +0200
committerPawel Chojnacki <pawel@chojnacki.ws>2017-06-22 15:05:52 +0200
commit97c42df3b804a37e659c3cda6bd8a52570f31366 (patch)
tree97c38db7f71a93a7b0db5ca2c682d6d17479cbdb /app/assets/javascripts/notes.js
parent3833f1dd84dfec844443a5b1d9ba2bd2b911c0bc (diff)
parent11716f310dcc495600f5a17e08456a1abb296482 (diff)
downloadgitlab-ce-97c42df3b804a37e659c3cda6bd8a52570f31366.tar.gz
Merge remote-tracking branch 'upstream/master' into 28717-additional-metrics-review-branch28717-additional-metrics-review-branch
Diffstat (limited to 'app/assets/javascripts/notes.js')
-rw-r--r--app/assets/javascripts/notes.js50
1 files changed, 26 insertions, 24 deletions
diff --git a/app/assets/javascripts/notes.js b/app/assets/javascripts/notes.js
index d56cf959486..624dd336786 100644
--- a/app/assets/javascripts/notes.js
+++ b/app/assets/javascripts/notes.js
@@ -32,7 +32,7 @@ const normalizeNewlines = function(str) {
(function() {
this.Notes = (function() {
const MAX_VISIBLE_COMMIT_LIST_COUNT = 3;
- const REGEX_SLASH_COMMANDS = /^\/\w+.*$/gm;
+ const REGEX_QUICK_ACTIONS = /^\/\w+.*$/gm;
Notes.interval = null;
@@ -187,7 +187,7 @@ const normalizeNewlines = function(str) {
if ($textarea.val() !== '') {
return;
}
- myLastNote = $(`li.note[data-author-id='${gon.current_user_id}'][data-editable]:last`, $textarea.closest('.note, #notes'));
+ myLastNote = $(`li.note[data-author-id='${gon.current_user_id}'][data-editable]:last`, $textarea.closest('.note, .notes_holder, #notes'));
if (myLastNote.length) {
myLastNoteEditBtn = myLastNote.find('.js-note-edit');
return myLastNoteEditBtn.trigger('click', [true, myLastNote]);
@@ -284,7 +284,7 @@ const normalizeNewlines = function(str) {
return this.initRefresh();
};
- Notes.prototype.handleSlashCommands = function(noteEntity) {
+ Notes.prototype.handleQuickActions = function(noteEntity) {
var votesBlock;
if (noteEntity.commands_changes) {
if ('merge' in noteEntity.commands_changes) {
@@ -322,7 +322,9 @@ const normalizeNewlines = function(str) {
Notes.updateNoteTargetSelector = function($note) {
const hash = gl.utils.getLocationHash();
- $note.toggleClass('target', hash && $note.filter(`#${hash}`).length > 0);
+ // Needs to be an explicit true/false for the jQuery `toggleClass(force)`
+ const addTargetClass = Boolean(hash && $note.filter(`#${hash}`).length > 0);
+ $note.toggleClass('target', addTargetClass);
};
/*
@@ -1220,27 +1222,27 @@ const normalizeNewlines = function(str) {
};
/**
- * Identify if comment has any slash commands
+ * Identify if comment has any quick actions
*/
- Notes.prototype.hasSlashCommands = function(formContent) {
- return REGEX_SLASH_COMMANDS.test(formContent);
+ Notes.prototype.hasQuickActions = function(formContent) {
+ return REGEX_QUICK_ACTIONS.test(formContent);
};
/**
- * Remove slash commands and leave comment with pure message
+ * Remove quick actions and leave comment with pure message
*/
- Notes.prototype.stripSlashCommands = function(formContent) {
- return formContent.replace(REGEX_SLASH_COMMANDS, '').trim();
+ Notes.prototype.stripQuickActions = function(formContent) {
+ return formContent.replace(REGEX_QUICK_ACTIONS, '').trim();
};
/**
- * Gets appropriate description from slash commands found in provided `formContent`
+ * Gets appropriate description from quick actions found in provided `formContent`
*/
- Notes.prototype.getSlashCommandDescription = function (formContent, availableSlashCommands = []) {
+ Notes.prototype.getQuickActionDescription = function (formContent, availableQuickActions = []) {
let tempFormContent;
- // Identify executed slash commands from `formContent`
- const executedCommands = availableSlashCommands.filter((command, index) => {
+ // Identify executed quick actions from `formContent`
+ const executedCommands = availableQuickActions.filter((command, index) => {
const commandRegex = new RegExp(`/${command.name}`);
return commandRegex.test(formContent);
});
@@ -1298,7 +1300,7 @@ const normalizeNewlines = function(str) {
};
/**
- * Create Placeholder System Note DOM element populated with slash command description
+ * Create Placeholder System Note DOM element populated with quick action description
*/
Notes.prototype.createPlaceholderSystemNote = function ({ formContent, uniqueId }) {
const $tempNote = $(
@@ -1347,7 +1349,7 @@ const normalizeNewlines = function(str) {
const { formData, formContent, formAction } = this.getFormData($form);
let noteUniqueId;
let systemNoteUniqueId;
- let hasSlashCommands = false;
+ let hasQuickActions = false;
let $notesContainer;
let tempFormContent;
@@ -1366,9 +1368,9 @@ const normalizeNewlines = function(str) {
}
tempFormContent = formContent;
- if (this.hasSlashCommands(formContent)) {
- tempFormContent = this.stripSlashCommands(formContent);
- hasSlashCommands = true;
+ if (this.hasQuickActions(formContent)) {
+ tempFormContent = this.stripQuickActions(formContent);
+ hasQuickActions = true;
}
// Show placeholder note
@@ -1385,10 +1387,10 @@ const normalizeNewlines = function(str) {
}
// Show placeholder system note
- if (hasSlashCommands) {
+ if (hasQuickActions) {
systemNoteUniqueId = _.uniqueId('tempSystemNote_');
$notesContainer.append(this.createPlaceholderSystemNote({
- formContent: this.getSlashCommandDescription(formContent, AjaxCache.get(gl.GfmAutoComplete.dataSources.commands)),
+ formContent: this.getQuickActionDescription(formContent, AjaxCache.get(gl.GfmAutoComplete.dataSources.commands)),
uniqueId: systemNoteUniqueId,
}));
}
@@ -1410,7 +1412,7 @@ const normalizeNewlines = function(str) {
$notesContainer.find(`#${noteUniqueId}`).remove();
// Reset cached commands list when command is applied
- if (hasSlashCommands) {
+ if (hasQuickActions) {
$form.find('textarea.js-note-text').trigger('clear-commands-cache.atwho');
}
@@ -1444,7 +1446,7 @@ const normalizeNewlines = function(str) {
}
if (note.commands_changes) {
- this.handleSlashCommands(note);
+ this.handleQuickActions(note);
}
$form.trigger('ajax:success', [note]);
@@ -1452,7 +1454,7 @@ const normalizeNewlines = function(str) {
// Submission failed, remove placeholder note and show Flash error message
$notesContainer.find(`#${noteUniqueId}`).remove();
- if (hasSlashCommands) {
+ if (hasQuickActions) {
$notesContainer.find(`#${systemNoteUniqueId}`).remove();
}