Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
641f1d2c
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,体验更适合开发者的 AI 搜索 >>
未验证
提交
641f1d2c
编写于
1月 31, 2018
作者:
P
Phil Hughes
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Converted common_utils to axios
上级
ae401d03
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
19 addition
and
17 deletion
+19
-17
app/assets/javascripts/lib/utils/common_utils.js
app/assets/javascripts/lib/utils/common_utils.js
+7
-9
app/assets/javascripts/notes.js
app/assets/javascripts/notes.js
+7
-5
spec/javascripts/lib/utils/common_utils_spec.js
spec/javascripts/lib/utils/common_utils_spec.js
+5
-3
未找到文件。
app/assets/javascripts/lib/utils/common_utils.js
浏览文件 @
641f1d2c
import
axios
from
'
./axios_utils
'
;
import
{
getLocationHash
}
from
'
./url_utility
'
;
export
const
getPagePath
=
(
index
=
0
)
=>
$
(
'
body
'
).
attr
(
'
data-page
'
).
split
(
'
:
'
)[
index
];
...
...
@@ -27,17 +28,14 @@ export const isInIssuePage = () => {
return
page
===
'
issues
'
&&
action
===
'
show
'
;
};
export
const
ajaxGet
=
url
=>
$
.
ajax
({
type
:
'
GET
'
,
url
,
dataType
:
'
script
'
,
export
const
ajaxGet
=
url
=>
axios
.
get
(
url
,
{
params
:
{
format
:
'
js
'
},
responseType
:
'
text
'
,
}).
then
(({
data
})
=>
{
$
.
globalEval
(
data
);
});
export
const
ajaxPost
=
(
url
,
data
)
=>
$
.
ajax
({
type
:
'
POST
'
,
url
,
data
,
});
export
const
ajaxPost
=
(
url
,
data
)
=>
axios
.
post
(
url
,
data
);
export
const
rstrip
=
(
val
)
=>
{
if
(
val
)
{
...
...
app/assets/javascripts/notes.js
浏览文件 @
641f1d2c
...
...
@@ -1487,7 +1487,9 @@ export default class Notes {
/* eslint-disable promise/catch-or-return */
// Make request to submit comment on server
ajaxPost
(
formAction
,
formData
)
.
then
((
note
)
=>
{
.
then
((
res
)
=>
{
const
note
=
res
.
data
;
// Submission successful! remove placeholder
$notesContainer
.
find
(
`#
${
noteUniqueId
}
`
).
remove
();
...
...
@@ -1560,7 +1562,7 @@ export default class Notes {
}
$form
.
trigger
(
'
ajax:success
'
,
[
note
]);
}).
fail
(()
=>
{
}).
catch
(()
=>
{
// Submission failed, remove placeholder note and show Flash error message
$notesContainer
.
find
(
`#
${
noteUniqueId
}
`
).
remove
();
...
...
@@ -1631,11 +1633,11 @@ export default class Notes {
/* eslint-disable promise/catch-or-return */
// Make request to update comment on server
ajaxPost
(
formAction
,
formData
)
.
then
((
note
)
=>
{
.
then
((
{
data
}
)
=>
{
// Submission successful! render final note element
this
.
updateNote
(
note
,
$editingNote
);
this
.
updateNote
(
data
,
$editingNote
);
})
.
fail
(()
=>
{
.
catch
(()
=>
{
// Submission failed, revert back to original note
$noteBodyText
.
html
(
_
.
escape
(
cachedNoteBodyText
));
$editingNote
.
removeClass
(
'
being-posted fade-in
'
);
...
...
spec/javascripts/lib/utils/common_utils_spec.js
浏览文件 @
641f1d2c
/* eslint-disable promise/catch-or-return */
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
*
as
commonUtils
from
'
~/lib/utils/common_utils
'
;
describe
(
'
common_utils
'
,
()
=>
{
...
...
@@ -451,10 +451,12 @@ describe('common_utils', () => {
it
(
'
should perform `$.ajax` call and do `POST` request
'
,
()
=>
{
const
requestURL
=
'
/some/random/api
'
;
const
data
=
{
keyname
:
'
value
'
};
const
ajaxSpy
=
spyOn
(
$
,
'
ajax
'
).
and
.
callFake
(()
=>
{});
const
ajaxSpy
=
spyOn
(
axios
,
'
post
'
).
and
.
callFake
(()
=>
{});
commonUtils
.
ajaxPost
(
requestURL
,
data
);
expect
(
ajaxSpy
.
calls
.
allArgs
()[
0
][
0
].
type
).
toEqual
(
'
POST
'
);
expect
(
ajaxSpy
.
calls
.
allArgs
()[
0
][
0
]).
toEqual
(
requestURL
);
expect
(
ajaxSpy
.
calls
.
allArgs
()[
0
][
1
]).
toEqual
(
data
);
});
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录