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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
641f1d2c
Commit
641f1d2c
authored
Jan 31, 2018
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Converted common_utils to axios
parent
ae401d03
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
17 deletions
+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
No files found.
app/assets/javascripts/lib/utils/common_utils.js
View file @
641f1d2c
import
axios
from
'
./axios_utils
'
;
import
{
getLocationHash
}
from
'
./url_utility
'
;
import
{
getLocationHash
}
from
'
./url_utility
'
;
export
const
getPagePath
=
(
index
=
0
)
=>
$
(
'
body
'
).
attr
(
'
data-page
'
).
split
(
'
:
'
)[
index
];
export
const
getPagePath
=
(
index
=
0
)
=>
$
(
'
body
'
).
attr
(
'
data-page
'
).
split
(
'
:
'
)[
index
];
...
@@ -27,17 +28,14 @@ export const isInIssuePage = () => {
...
@@ -27,17 +28,14 @@ export const isInIssuePage = () => {
return
page
===
'
issues
'
&&
action
===
'
show
'
;
return
page
===
'
issues
'
&&
action
===
'
show
'
;
};
};
export
const
ajaxGet
=
url
=>
$
.
ajax
({
export
const
ajaxGet
=
url
=>
axios
.
get
(
url
,
{
type
:
'
GET
'
,
params
:
{
format
:
'
js
'
},
url
,
responseType
:
'
text
'
,
dataType
:
'
script
'
,
}).
then
(({
data
})
=>
{
$
.
globalEval
(
data
);
});
});
export
const
ajaxPost
=
(
url
,
data
)
=>
$
.
ajax
({
export
const
ajaxPost
=
(
url
,
data
)
=>
axios
.
post
(
url
,
data
);
type
:
'
POST
'
,
url
,
data
,
});
export
const
rstrip
=
(
val
)
=>
{
export
const
rstrip
=
(
val
)
=>
{
if
(
val
)
{
if
(
val
)
{
...
...
app/assets/javascripts/notes.js
View file @
641f1d2c
...
@@ -1487,7 +1487,9 @@ export default class Notes {
...
@@ -1487,7 +1487,9 @@ export default class Notes {
/* eslint-disable promise/catch-or-return */
/* eslint-disable promise/catch-or-return */
// Make request to submit comment on server
// Make request to submit comment on server
ajaxPost
(
formAction
,
formData
)
ajaxPost
(
formAction
,
formData
)
.
then
((
note
)
=>
{
.
then
((
res
)
=>
{
const
note
=
res
.
data
;
// Submission successful! remove placeholder
// Submission successful! remove placeholder
$notesContainer
.
find
(
`#
${
noteUniqueId
}
`
).
remove
();
$notesContainer
.
find
(
`#
${
noteUniqueId
}
`
).
remove
();
...
@@ -1560,7 +1562,7 @@ export default class Notes {
...
@@ -1560,7 +1562,7 @@ export default class Notes {
}
}
$form
.
trigger
(
'
ajax:success
'
,
[
note
]);
$form
.
trigger
(
'
ajax:success
'
,
[
note
]);
}).
fail
(()
=>
{
}).
catch
(()
=>
{
// Submission failed, remove placeholder note and show Flash error message
// Submission failed, remove placeholder note and show Flash error message
$notesContainer
.
find
(
`#
${
noteUniqueId
}
`
).
remove
();
$notesContainer
.
find
(
`#
${
noteUniqueId
}
`
).
remove
();
...
@@ -1631,11 +1633,11 @@ export default class Notes {
...
@@ -1631,11 +1633,11 @@ export default class Notes {
/* eslint-disable promise/catch-or-return */
/* eslint-disable promise/catch-or-return */
// Make request to update comment on server
// Make request to update comment on server
ajaxPost
(
formAction
,
formData
)
ajaxPost
(
formAction
,
formData
)
.
then
((
note
)
=>
{
.
then
((
{
data
}
)
=>
{
// Submission successful! render final note element
// Submission successful! render final note element
this
.
updateNote
(
note
,
$editingNote
);
this
.
updateNote
(
data
,
$editingNote
);
})
})
.
fail
(()
=>
{
.
catch
(()
=>
{
// Submission failed, revert back to original note
// Submission failed, revert back to original note
$noteBodyText
.
html
(
_
.
escape
(
cachedNoteBodyText
));
$noteBodyText
.
html
(
_
.
escape
(
cachedNoteBodyText
));
$editingNote
.
removeClass
(
'
being-posted fade-in
'
);
$editingNote
.
removeClass
(
'
being-posted fade-in
'
);
...
...
spec/javascripts/lib/utils/common_utils_spec.js
View file @
641f1d2c
/* eslint-disable promise/catch-or-return */
/* eslint-disable promise/catch-or-return */
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
*
as
commonUtils
from
'
~/lib/utils/common_utils
'
;
import
*
as
commonUtils
from
'
~/lib/utils/common_utils
'
;
describe
(
'
common_utils
'
,
()
=>
{
describe
(
'
common_utils
'
,
()
=>
{
...
@@ -451,10 +451,12 @@ describe('common_utils', () => {
...
@@ -451,10 +451,12 @@ describe('common_utils', () => {
it
(
'
should perform `$.ajax` call and do `POST` request
'
,
()
=>
{
it
(
'
should perform `$.ajax` call and do `POST` request
'
,
()
=>
{
const
requestURL
=
'
/some/random/api
'
;
const
requestURL
=
'
/some/random/api
'
;
const
data
=
{
keyname
:
'
value
'
};
const
data
=
{
keyname
:
'
value
'
};
const
ajaxSpy
=
spyOn
(
$
,
'
ajax
'
).
and
.
callFake
(()
=>
{});
const
ajaxSpy
=
spyOn
(
axios
,
'
post
'
).
and
.
callFake
(()
=>
{});
commonUtils
.
ajaxPost
(
requestURL
,
data
);
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
);
});
});
});
});
...
...
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