Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
eae72cc7
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
eae72cc7
编写于
7月 14, 2017
作者:
F
Fatih Acet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
IssueNotesRefactor: Move quick actions logic to Store.
上级
4dce23c0
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
97 addition
and
80 deletion
+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
未找到文件。
app/assets/javascripts/notes/components/issue_comment_form.vue
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
();
},
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录