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
a33d35c0
Commit
a33d35c0
authored
Feb 13, 2018
by
Clement Ho
Committed by
Jacob Schatz
Feb 13, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace $.ajax with axios in approvers select
parent
1d237d4b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
44 deletions
+53
-44
ee/app/assets/javascripts/approvers_select.js
ee/app/assets/javascripts/approvers_select.js
+30
-26
spec/javascripts/approvers_select_spec.js
spec/javascripts/approvers_select_spec.js
+23
-18
No files found.
ee/app/assets/javascripts/approvers_select.js
View file @
a33d35c0
import
Api
from
'
~/api
'
;
import
Api
from
'
~/api
'
;
import
{
__
}
from
'
~/locale
'
;
import
Flash
from
'
~/flash
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
export
default
class
ApproversSelect
{
export
default
class
ApproversSelect
{
constructor
()
{
constructor
()
{
...
@@ -147,7 +150,7 @@ export default class ApproversSelect {
...
@@ -147,7 +150,7 @@ export default class ApproversSelect {
}
}
static
saveApprovers
(
fieldName
)
{
static
saveApprovers
(
fieldName
)
{
const
$input
=
window
.
$
(
`[name="
${
fieldName
}
"]`
);
const
$input
=
$
(
`[name="
${
fieldName
}
"]`
);
const
newValue
=
$input
.
val
();
const
newValue
=
$input
.
val
();
const
$loadWrapper
=
$
(
'
.load-wrapper
'
);
const
$loadWrapper
=
$
(
'
.load-wrapper
'
);
const
$approverSelect
=
$
(
'
.js-select-user-and-group
'
);
const
$approverSelect
=
$
(
'
.js-select-user-and-group
'
);
...
@@ -158,41 +161,42 @@ export default class ApproversSelect {
...
@@ -158,41 +161,42 @@ export default class ApproversSelect {
const
$form
=
$
(
'
.js-add-approvers
'
).
closest
(
'
form
'
);
const
$form
=
$
(
'
.js-add-approvers
'
).
closest
(
'
form
'
);
$loadWrapper
.
removeClass
(
'
hidden
'
);
$loadWrapper
.
removeClass
(
'
hidden
'
);
window
.
$
.
ajax
({
url
:
$form
.
attr
(
'
action
'
),
axios
.
post
(
$form
.
attr
(
'
action
'
),
`_method=PATCH&
${[
encodeURIComponent
(
fieldName
)]}
=
${
newValue
}
`
,
{
type
:
'
POST
'
,
headers
:
{
data
:
{
'
Content-Type
'
:
'
application/x-www-form-urlencoded;charset=UTF-8
'
,
_method
:
'
PATCH
'
,
[
fieldName
]:
newValue
,
},
success
:
ApproversSelect
.
updateApproverList
,
complete
()
{
$input
.
val
(
''
);
$approverSelect
.
select2
(
'
val
'
,
''
);
$loadWrapper
.
addClass
(
'
hidden
'
);
},
error
()
{
window
.
Flash
(
'
Failed to add Approver
'
,
'
alert
'
);
},
},
}).
then
(({
data
})
=>
{
ApproversSelect
.
updateApproverList
(
data
);
ApproversSelect
.
saveApproversComplete
(
$input
,
$approverSelect
,
$loadWrapper
);
}).
catch
(()
=>
{
Flash
(
__
(
'
An error occurred while adding approver
'
));
ApproversSelect
.
saveApproversComplete
(
$input
,
$approverSelect
,
$loadWrapper
);
});
});
}
}
static
saveApproversComplete
(
$input
,
$approverSelect
,
$loadWrapper
)
{
$input
.
val
(
''
);
$approverSelect
.
select2
(
'
val
'
,
''
);
$loadWrapper
.
addClass
(
'
hidden
'
);
}
static
removeApprover
(
e
)
{
static
removeApprover
(
e
)
{
e
.
preventDefault
();
e
.
preventDefault
();
const
target
=
e
.
currentTarget
;
const
target
=
e
.
currentTarget
;
const
$loadWrapper
=
$
(
'
.load-wrapper
'
);
const
$loadWrapper
=
$
(
'
.load-wrapper
'
);
$loadWrapper
.
removeClass
(
'
hidden
'
);
$loadWrapper
.
removeClass
(
'
hidden
'
);
$
.
ajax
({
url
:
target
.
getAttribute
(
'
href
'
),
axios
.
post
(
target
.
getAttribute
(
'
href
'
),
'
_method=DELETE
'
,
{
type
:
'
POST
'
,
headers
:
{
data
:
{
'
Content-Type
'
:
'
application/x-www-form-urlencoded;charset=UTF-8
'
,
_method
:
'
DELETE
'
,
},
success
:
ApproversSelect
.
updateApproverList
,
complete
:
()
=>
$loadWrapper
.
addClass
(
'
hidden
'
),
error
()
{
window
.
Flash
(
'
Failed to remove Approver
'
,
'
alert
'
);
},
},
}).
then
(({
data
})
=>
{
ApproversSelect
.
updateApproverList
(
data
);
$loadWrapper
.
addClass
(
'
hidden
'
);
}).
catch
(()
=>
{
Flash
(
__
(
'
An error occurred while removing approver
'
));
$loadWrapper
.
addClass
(
'
hidden
'
);
});
});
}
}
...
...
spec/javascripts/approvers_select_spec.js
View file @
a33d35c0
import
ApproversSelect
from
'
ee/approvers_select
'
;
import
ApproversSelect
from
'
ee/approvers_select
'
;
import
ClassSpecHelper
from
'
./helpers/class_spec_helper
'
;
describe
(
'
ApproversSelect
'
,
()
=>
{
describe
(
'
ApproversSelect
'
,
()
=>
{
describe
(
'
saveApprovers
'
,
()
=>
{
describe
(
'
saveApproversComplete
'
,
()
=>
{
let
complete
;
let
$input
;
const
$input
=
jasmine
.
createSpyObj
(
'
$input
'
,
[
'
val
'
]);
let
$approverSelect
;
let
$loadWrapper
;
beforeEach
(()
=>
{
beforeEach
(()
=>
{
spyOn
(
window
,
'
$
'
).
and
.
returnValue
(
$input
);
$input
=
{
spyOn
(
window
.
$
,
'
ajax
'
).
and
.
callFake
((
options
)
=>
{
val
:
jasmine
.
createSpy
(),
complete
=
options
.
complete
;
};
});
$input
.
val
.
and
.
returnValue
(
'
newValue
'
);
$approverSelect
=
{
select2
:
jasmine
.
createSpy
(),
};
ApproversSelect
.
saveApprovers
(
'
fieldName
'
);
$loadWrapper
=
{
});
addClass
:
jasmine
.
createSpy
(),
};
ClassSpecHelper
.
itShouldBeAStaticMethod
(
ApproversSelect
,
'
saveApprovers
'
);
ApproversSelect
.
saveApproversComplete
(
$input
,
$approverSelect
,
$loadWrapper
);
});
describe
(
'
when request completes
'
,
()
=>
{
it
(
'
should empty the $input value
'
,
()
=>
{
it
(
'
should empty the $input value
'
,
()
=>
{
expect
(
$input
.
val
).
toHaveBeenCalledWith
(
''
);
$input
.
val
.
calls
.
reset
(
);
}
);
complete
();
it
(
'
should empty the select2 value
'
,
()
=>
{
expect
(
$approverSelect
.
select2
).
toHaveBeenCalledWith
(
'
val
'
,
''
);
});
expect
(
$input
.
val
).
toHaveBeenCalledWith
(
''
);
it
(
'
should hide loadWrapper
'
,
()
=>
{
}
);
expect
(
$loadWrapper
.
addClass
).
toHaveBeenCalledWith
(
'
hidden
'
);
});
});
});
});
});
});
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