Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
eae72cc7
Commit
eae72cc7
authored
Jul 14, 2017
by
Fatih Acet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
IssueNotesRefactor: Move quick actions logic to Store.
parent
4dce23c0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
97 additions
and
80 deletions
+97
-80
app/assets/javascripts/notes/components/issue_comment_form.vue
...ssets/javascripts/notes/components/issue_comment_form.vue
+7
-66
app/assets/javascripts/notes/components/issue_discussion.vue
app/assets/javascripts/notes/components/issue_discussion.vue
+3
-3
app/assets/javascripts/notes/stores/issue_notes_store.js
app/assets/javascripts/notes/stores/issue_notes_store.js
+55
-11
app/assets/javascripts/notes/stores/issue_notes_utils.js
app/assets/javascripts/notes/stores/issue_notes_utils.js
+32
-0
No files found.
app/assets/javascripts/notes/components/issue_comment_form.vue
View file @
eae72cc7
<
script
>
/* global Flash */
import
AjaxCache
from
'
~/lib/utils/ajax_cache
'
;
import
UserAvatarLink
from
'
../../vue_shared/components/user_avatar/user_avatar_link.vue
'
;
import
MarkdownField
from
'
../../vue_shared/components/markdown/field.vue
'
;
import
IssueNoteSignedOutWidget
from
'
./issue_note_signed_out_widget.vue
'
;
import
eventHub
from
'
../event_hub
'
;
const
REGEX_QUICK_ACTIONS
=
/^
\/\w
+.*$/gm
;
export
default
{
data
()
{
const
{
create_note_path
,
state
}
=
window
.
gl
.
issueData
;
...
...
@@ -51,9 +49,10 @@ export default {
methods
:
{
handleSave
(
withIssueAction
)
{
if
(
this
.
note
.
length
)
{
const
d
ata
=
{
const
noteD
ata
=
{
endpoint
:
this
.
endpoint
,
noteData
:
{
flashContainer
:
this
.
$el
,
data
:
{
full_data
:
true
,
note
:
{
noteable_type
:
'
Issue
'
,
...
...
@@ -64,42 +63,13 @@ export default {
};
if
(
this
.
noteType
===
'
discussion
'
)
{
data
.
noteD
ata
.
note
.
type
=
'
DiscussionNote
'
;
noteData
.
d
ata
.
note
.
type
=
'
DiscussionNote
'
;
}
let
placeholderText
=
this
.
note
;
const
hasQuickActions
=
this
.
hasQuickActions
();
if
(
hasQuickActions
)
{
placeholderText
=
this
.
stripQuickActions
();
}
if
(
placeholderText
.
length
)
{
this
.
$store
.
commit
(
'
showPlaceholderNote
'
,
{
noteBody
:
placeholderText
,
});
}
if
(
hasQuickActions
)
{
this
.
$store
.
commit
(
'
showPlaceholderNote
'
,
{
isSystemNote
:
true
,
noteBody
:
this
.
getQuickActionText
(),
});
}
this
.
$store
.
dispatch
(
'
createNewNote
'
,
data
)
this
.
$store
.
dispatch
(
'
saveNote
'
,
noteData
)
.
then
((
res
)
=>
{
const
{
errors
}
=
res
;
if
(
hasQuickActions
)
{
this
.
$store
.
dispatch
(
'
poll
'
);
$
(
this
.
$refs
.
textarea
).
trigger
(
'
clear-commands-cache.atwho
'
);
new
Flash
(
'
Commands applied
'
,
'
notice
'
,
$
(
this
.
$el
));
// eslint-disable-line
}
if
(
errors
)
{
if
(
errors
.
commands_only
)
{
new
Flash
(
errors
.
commands_only
,
'
notice
'
,
$
(
this
.
$el
));
// eslint-disable-line
if
(
res
.
errors
)
{
if
(
res
.
errors
.
commands_only
)
{
this
.
discard
();
}
else
{
this
.
handleError
();
...
...
@@ -107,8 +77,6 @@ export default {
}
else
{
this
.
discard
();
}
this
.
$store
.
commit
(
'
removePlaceholderNotes
'
);
})
.
catch
(
this
.
handleError
);
}
...
...
@@ -153,33 +121,6 @@ export default {
}
}
},
getQuickActionText
()
{
let
text
=
'
Applying command
'
;
const
quickActions
=
AjaxCache
.
get
(
gl
.
GfmAutoComplete
.
dataSources
.
commands
);
const
{
note
}
=
this
;
const
executedCommands
=
quickActions
.
filter
((
command
)
=>
{
const
commandRegex
=
new
RegExp
(
`/
${
command
.
name
}
`
);
return
commandRegex
.
test
(
note
);
});
if
(
executedCommands
&&
executedCommands
.
length
)
{
if
(
executedCommands
.
length
>
1
)
{
text
=
'
Applying multiple commands
'
;
}
else
{
const
commandDescription
=
executedCommands
[
0
].
description
.
toLowerCase
();
text
=
`Applying command to
${
commandDescription
}
`
;
}
}
return
text
;
},
hasQuickActions
()
{
return
REGEX_QUICK_ACTIONS
.
test
(
this
.
note
);
},
stripQuickActions
()
{
return
this
.
note
.
replace
(
REGEX_QUICK_ACTIONS
,
''
).
trim
();
},
},
mounted
()
{
const
issuableDataEl
=
document
.
getElementById
(
'
js-issuable-app-initial-data
'
);
...
...
app/assets/javascripts/notes/components/issue_discussion.vue
View file @
eae72cc7
...
...
@@ -63,9 +63,9 @@ export default {
this
.
isReplying
=
false
;
},
saveReply
({
note
})
{
const
d
ata
=
{
const
replyD
ata
=
{
endpoint
:
this
.
newNotePath
,
reply
:
{
data
:
{
in_reply_to_discussion_id
:
this
.
note
.
reply_id
,
target_type
:
'
issue
'
,
target_id
:
this
.
discussion
.
noteable_id
,
...
...
@@ -74,7 +74,7 @@ export default {
},
};
this
.
$store
.
dispatch
(
'
replyToDiscussion
'
,
d
ata
)
this
.
$store
.
dispatch
(
'
saveNote
'
,
replyD
ata
)
.
then
(()
=>
{
this
.
isReplying
=
false
;
})
...
...
app/assets/javascripts/notes/stores/issue_notes_store.js
View file @
eae72cc7
/* eslint-disable no-param-reassign */
import
service
from
'
../services/issue_notes_service
'
;
import
utils
from
'
./issue_notes_utils
'
;
const
findNoteObjectById
=
(
notes
,
id
)
=>
notes
.
filter
(
n
=>
n
.
id
===
id
)[
0
];
...
...
@@ -147,31 +148,31 @@ const actions = {
context
.
commit
(
'
deleteNote
'
,
note
);
});
},
replyToDiscussion
(
context
,
data
)
{
const
{
endpoint
,
reply
}
=
data
;
updateNote
(
context
,
data
)
{
const
{
endpoint
,
note
}
=
data
;
return
service
.
replyToDiscussion
(
endpoint
,
reply
)
.
updateNote
(
endpoint
,
note
)
.
then
(
res
=>
res
.
json
())
.
then
((
res
)
=>
{
context
.
commit
(
'
addNewReplyToDiscussion
'
,
res
);
context
.
commit
(
'
updateNote
'
,
res
);
});
},
updateNote
(
context
,
d
ata
)
{
const
{
endpoint
,
note
}
=
d
ata
;
replyToDiscussion
(
context
,
noteD
ata
)
{
const
{
endpoint
,
data
}
=
noteD
ata
;
return
service
.
updateNote
(
endpoint
,
note
)
.
replyToDiscussion
(
endpoint
,
data
)
.
then
(
res
=>
res
.
json
())
.
then
((
res
)
=>
{
context
.
commit
(
'
updateNote
'
,
res
);
context
.
commit
(
'
addNewReplyToDiscussion
'
,
res
);
});
},
createNewNote
(
context
,
d
ata
)
{
const
{
endpoint
,
noteData
}
=
d
ata
;
createNewNote
(
context
,
noteD
ata
)
{
const
{
endpoint
,
data
}
=
noteD
ata
;
return
service
.
createNewNote
(
endpoint
,
noteD
ata
)
.
createNewNote
(
endpoint
,
d
ata
)
.
then
(
res
=>
res
.
json
())
.
then
((
res
)
=>
{
if
(
!
res
.
errors
)
{
...
...
@@ -180,6 +181,49 @@ const actions = {
return
res
;
});
},
saveNote
(
context
,
noteData
)
{
const
{
note
}
=
noteData
.
data
.
note
;
let
placeholderText
=
note
;
const
hasQuickActions
=
utils
.
hasQuickActions
(
placeholderText
);
if
(
hasQuickActions
)
{
placeholderText
=
utils
.
stripQuickActions
(
placeholderText
);
}
if
(
placeholderText
.
length
)
{
context
.
commit
(
'
showPlaceholderNote
'
,
{
noteBody
:
placeholderText
,
});
}
if
(
hasQuickActions
)
{
context
.
commit
(
'
showPlaceholderNote
'
,
{
isSystemNote
:
true
,
noteBody
:
utils
.
getQuickActionText
(
note
),
});
}
const
hasReplyId
=
noteData
.
data
.
in_reply_to_discussion_id
;
const
methodToDispatch
=
hasReplyId
?
'
replyToDiscussion
'
:
'
createNewNote
'
;
return
context
.
dispatch
(
methodToDispatch
,
noteData
)
.
then
((
res
)
=>
{
const
{
errors
}
=
res
;
if
(
hasQuickActions
)
{
context
.
dispatch
(
'
poll
'
);
$
(
'
.js-gfm-input
'
).
trigger
(
'
clear-commands-cache.atwho
'
);
new
Flash
(
'
Commands applied
'
,
'
notice
'
,
$
(
noteData
.
flashContainer
));
// eslint-disable-line
}
if
(
errors
&&
errors
.
commands_only
)
{
new
Flash
(
errors
.
commands_only
,
'
notice
'
,
$
(
noteData
.
flashContainer
));
// eslint-disable-line
}
context
.
commit
(
'
removePlaceholderNotes
'
);
return
res
;
});
},
poll
(
context
)
{
const
{
notesPath
}
=
$
(
'
.js-notes-wrapper
'
)[
0
].
dataset
;
...
...
app/assets/javascripts/notes/stores/issue_notes_utils.js
0 → 100644
View file @
eae72cc7
import
AjaxCache
from
'
~/lib/utils/ajax_cache
'
;
const
REGEX_QUICK_ACTIONS
=
/^
\/\w
+.*$/gm
;
export
default
{
getQuickActionText
(
note
)
{
let
text
=
'
Applying command
'
;
const
quickActions
=
AjaxCache
.
get
(
gl
.
GfmAutoComplete
.
dataSources
.
commands
);
const
executedCommands
=
quickActions
.
filter
((
command
)
=>
{
const
commandRegex
=
new
RegExp
(
`/
${
command
.
name
}
`
);
return
commandRegex
.
test
(
note
);
});
if
(
executedCommands
&&
executedCommands
.
length
)
{
if
(
executedCommands
.
length
>
1
)
{
text
=
'
Applying multiple commands
'
;
}
else
{
const
commandDescription
=
executedCommands
[
0
].
description
.
toLowerCase
();
text
=
`Applying command to
${
commandDescription
}
`
;
}
}
return
text
;
},
hasQuickActions
(
note
)
{
return
REGEX_QUICK_ACTIONS
.
test
(
note
);
},
stripQuickActions
(
note
)
{
return
note
.
replace
(
REGEX_QUICK_ACTIONS
,
''
).
trim
();
},
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment