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
c4a8939a
Commit
c4a8939a
authored
Feb 07, 2018
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Converted EE protected tags & branches to axios
parent
0e4e2d96
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
66 additions
and
109 deletions
+66
-109
ee/app/assets/javascripts/protected_branches/protected_branch_access_dropdown.js
...ts/protected_branches/protected_branch_access_dropdown.js
+12
-22
ee/app/assets/javascripts/protected_branches/protected_branch_create.js
...javascripts/protected_branches/protected_branch_create.js
+6
-9
ee/app/assets/javascripts/protected_branches/protected_branch_edit.js
...s/javascripts/protected_branches/protected_branch_edit.js
+16
-22
ee/app/assets/javascripts/protected_tags/protected_tag_access_dropdown.js
...vascripts/protected_tags/protected_tag_access_dropdown.js
+12
-23
ee/app/assets/javascripts/protected_tags/protected_tag_create.js
...assets/javascripts/protected_tags/protected_tag_create.js
+5
-9
ee/app/assets/javascripts/protected_tags/protected_tag_edit.js
...p/assets/javascripts/protected_tags/protected_tag_edit.js
+15
-24
No files found.
ee/app/assets/javascripts/protected_branches/protected_branch_access_dropdown.js
View file @
c4a8939a
/* eslint-disable no-underscore-dangle, class-methods-use-this */
import
_
from
'
underscore
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
Flash
from
'
~/flash
'
;
import
{
LEVEL_TYPES
,
LEVEL_ID_PROP
,
ACCESS_LEVEL_NONE
}
from
'
./constants
'
;
...
...
@@ -274,20 +275,13 @@ export default class ProtectedBranchAccessDropdown {
}
getData
(
query
,
callback
)
{
this
.
getUsers
(
query
)
.
done
((
usersResponse
)
=>
{
if
(
this
.
groups
.
length
)
{
callback
(
this
.
consolidateData
(
usersResponse
,
this
.
groups
));
}
else
{
this
.
getGroups
(
query
)
.
done
((
groupsResponse
)
=>
{
// Cache groups to avoid multiple requests
this
.
groups
=
groupsResponse
;
callback
(
this
.
consolidateData
(
usersResponse
,
groupsResponse
));
})
.
error
(()
=>
new
Flash
(
'
Failed to load groups.
'
));
}
}).
error
(()
=>
new
Flash
(
'
Failed to load users.
'
));
Promise
.
all
([
this
.
getUsers
(
query
),
this
.
groupsData
?
Promise
.
resolve
(
this
.
groupsData
)
:
this
.
getGroups
(),
]).
then
(([
usersResponse
,
groupsResponse
])
=>
{
this
.
groupsData
=
groupsResponse
;
callback
(
this
.
consolidateData
(
usersResponse
.
data
,
groupsResponse
.
data
));
}).
catch
(()
=>
Flash
(
'
Failed to load groups & users.
'
));
}
consolidateData
(
usersResponse
,
groupsResponse
)
{
...
...
@@ -375,10 +369,8 @@ export default class ProtectedBranchAccessDropdown {
}
getUsers
(
query
)
{
return
$
.
ajax
({
dataType
:
'
json
'
,
url
:
this
.
buildUrl
(
gon
.
relative_url_root
,
this
.
usersPath
),
data
:
{
return
axios
.
get
(
this
.
buildUrl
(
gon
.
relative_url_root
,
this
.
usersPath
),
{
params
:
{
search
:
query
,
per_page
:
20
,
active
:
true
,
...
...
@@ -389,10 +381,8 @@ export default class ProtectedBranchAccessDropdown {
}
getGroups
()
{
return
$
.
ajax
({
dataType
:
'
json
'
,
url
:
this
.
buildUrl
(
gon
.
relative_url_root
,
this
.
groupsPath
),
data
:
{
return
axios
.
get
(
this
.
buildUrl
(
gon
.
relative_url_root
,
this
.
groupsPath
),
{
params
:
{
project_id
:
gon
.
current_project_id
,
},
});
...
...
ee/app/assets/javascripts/protected_branches/protected_branch_create.js
View file @
c4a8939a
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
AccessorUtilities
from
'
~/lib/utils/accessor
'
;
import
Flash
from
'
~/flash
'
;
import
CreateItemDropdown
from
'
~/create_item_dropdown
'
;
...
...
@@ -124,15 +125,11 @@ export default class ProtectedBranchCreate {
onFormSubmit
(
e
)
{
e
.
preventDefault
();
$
.
ajax
({
url
:
this
.
$form
.
attr
(
'
action
'
),
method
:
this
.
$form
.
attr
(
'
method
'
),
data
:
this
.
getFormData
(),
})
.
success
(()
=>
{
location
.
reload
();
})
.
fail
(()
=>
new
Flash
(
'
Failed to protect the branch
'
));
axios
[
this
.
$form
.
attr
(
'
method
'
)](
this
.
$form
.
attr
(
'
action
'
),
this
.
getFormData
())
.
then
(()
=>
{
location
.
reload
();
})
.
catch
(()
=>
Flash
(
'
Failed to protect the branch
'
));
}
savePreviousSelection
(
mergeSelection
,
pushSelection
)
{
...
...
ee/app/assets/javascripts/protected_branches/protected_branch_edit.js
View file @
c4a8939a
/* eslint-disable no-new */
import
_
from
'
underscore
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
Flash
from
'
~/flash
'
;
import
{
ACCESS_LEVELS
,
LEVEL_TYPES
}
from
'
./constants
'
;
import
ProtectedBranchAccessDropdown
from
'
./protected_branch_access_dropdown
'
;
...
...
@@ -61,30 +62,23 @@ export default class ProtectedBranchEdit {
return
acc
;
},
{});
return
$
.
ajax
({
type
:
'
POST
'
,
url
:
this
.
$wrap
.
data
(
'
url
'
),
dataType
:
'
json
'
,
data
:
{
_method
:
'
PATCH
'
,
protected_branch
:
formData
,
},
success
:
(
response
)
=>
{
this
.
hasChanges
=
false
;
Object
.
keys
(
ACCESS_LEVELS
).
forEach
((
level
)
=>
{
const
accessLevelName
=
ACCESS_LEVELS
[
level
];
// The data coming from server will be the new persisted *state* for each dropdown
this
.
setSelectedItemsToDropdown
(
response
[
accessLevelName
],
`
${
accessLevelName
}
_dropdown`
);
});
},
error
()
{
new
Flash
(
'
Failed to update branch!
'
,
null
,
$
(
'
.js-protected-branches-list
'
));
},
}).
always
(()
=>
{
axios
.
patch
(
this
.
$wrap
.
data
(
'
url
'
),
{
protected_branch
:
formData
,
}).
then
(({
data
})
=>
{
this
.
hasChanges
=
false
;
Object
.
keys
(
ACCESS_LEVELS
).
forEach
((
level
)
=>
{
const
accessLevelName
=
ACCESS_LEVELS
[
level
];
// The data coming from server will be the new persisted *state* for each dropdown
this
.
setSelectedItemsToDropdown
(
data
[
accessLevelName
],
`
${
accessLevelName
}
_dropdown`
);
});
this
.
$allowedToMergeDropdown
.
enable
();
this
.
$allowedToPushDropdown
.
enable
();
}).
catch
(()
=>
{
this
.
$allowedToMergeDropdown
.
enable
();
this
.
$allowedToPushDropdown
.
enable
();
Flash
(
'
Failed to update branch!
'
,
null
,
$
(
'
.js-protected-branches-list
'
));
});
}
...
...
ee/app/assets/javascripts/protected_tags/protected_tag_access_dropdown.js
View file @
c4a8939a
/* eslint-disable no-underscore-dangle, class-methods-use-this */
import
_
from
'
underscore
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
Flash
from
'
~/flash
'
;
import
{
LEVEL_TYPES
,
LEVEL_ID_PROP
,
ACCESS_LEVEL_NONE
}
from
'
./constants
'
;
...
...
@@ -270,21 +271,13 @@ export default class ProtectedTagAccessDropdown {
}
getData
(
query
,
callback
)
{
this
.
getUsers
(
query
)
.
done
((
usersResponse
)
=>
{
if
(
this
.
groups
.
length
)
{
callback
(
this
.
consolidateData
(
usersResponse
,
this
.
groups
));
}
else
{
this
.
getGroups
(
query
)
.
done
((
groupsResponse
)
=>
{
// Cache groups to avoid multiple requests
this
.
groups
=
groupsResponse
;
callback
(
this
.
consolidateData
(
usersResponse
,
groupsResponse
));
})
.
error
(()
=>
new
Flash
(
'
Failed to load groups.
'
));
}
})
.
error
(()
=>
new
Flash
(
'
Failed to load users.
'
));
Promise
.
all
([
this
.
getUsers
(
query
),
this
.
groupsData
?
Promise
.
resolve
(
this
.
groupsData
)
:
this
.
getGroups
(),
]).
then
(([
usersResponse
,
groupsResponse
])
=>
{
this
.
groupsData
=
groupsResponse
;
callback
(
this
.
consolidateData
(
usersResponse
.
data
,
groupsResponse
.
data
));
}).
catch
(()
=>
Flash
(
'
Failed to load groups & users.
'
));
}
consolidateData
(
usersResponse
,
groupsResponse
)
{
...
...
@@ -372,10 +365,8 @@ export default class ProtectedTagAccessDropdown {
}
getUsers
(
query
)
{
return
$
.
ajax
({
dataType
:
'
json
'
,
url
:
this
.
buildUrl
(
gon
.
relative_url_root
,
this
.
usersPath
),
data
:
{
return
axios
.
get
(
this
.
buildUrl
(
gon
.
relative_url_root
,
this
.
usersPath
),
{
params
:
{
search
:
query
,
per_page
:
20
,
active
:
true
,
...
...
@@ -386,10 +377,8 @@ export default class ProtectedTagAccessDropdown {
}
getGroups
()
{
return
$
.
ajax
({
dataType
:
'
json
'
,
url
:
this
.
buildUrl
(
gon
.
relative_url_root
,
this
.
groupsPath
),
data
:
{
return
axios
.
get
(
this
.
buildUrl
(
gon
.
relative_url_root
,
this
.
groupsPath
),
{
params
:
{
project_id
:
gon
.
current_project_id
,
},
});
...
...
ee/app/assets/javascripts/protected_tags/protected_tag_create.js
View file @
c4a8939a
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
Flash
from
'
~/flash
'
;
import
CreateItemDropdown
from
'
~/create_item_dropdown
'
;
import
{
ACCESS_LEVELS
,
LEVEL_TYPES
}
from
'
./constants
'
;
...
...
@@ -89,14 +90,9 @@ export default class ProtectedTagCreate {
onFormSubmit
(
e
)
{
e
.
preventDefault
();
$
.
ajax
({
url
:
this
.
$form
.
attr
(
'
action
'
),
method
:
this
.
$form
.
attr
(
'
method
'
),
data
:
this
.
getFormData
(),
})
.
success
(()
=>
{
location
.
reload
();
})
.
fail
(()
=>
new
Flash
(
'
Failed to protect the tag
'
));
axios
[
this
.
$form
.
attr
(
'
method
'
)](
this
.
$form
.
attr
(
'
action
'
),
this
.
getFormData
())
.
then
(()
=>
{
location
.
reload
();
}).
catch
(()
=>
Flash
(
'
Failed to protect the tag
'
));
}
}
ee/app/assets/javascripts/protected_tags/protected_tag_edit.js
View file @
c4a8939a
/* eslint-disable no-new */
import
_
from
'
underscore
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
Flash
from
'
~/flash
'
;
import
{
ACCESS_LEVELS
,
LEVEL_TYPES
}
from
'
./constants
'
;
import
ProtectedTagAccessDropdown
from
'
./protected_tag_access_dropdown
'
;
...
...
@@ -49,30 +50,20 @@ export default class ProtectedTagEdit {
return
acc
;
},
{});
return
$
.
ajax
({
type
:
'
POST
'
,
url
:
this
.
$wrap
.
data
(
'
url
'
),
dataType
:
'
json
'
,
data
:
{
_method
:
'
PATCH
'
,
protected_tag
:
formData
,
},
success
:
(
response
)
=>
{
this
.
hasChanges
=
false
;
Object
.
keys
(
ACCESS_LEVELS
).
forEach
((
level
)
=>
{
const
accessLevelName
=
ACCESS_LEVELS
[
level
];
// The data coming from server will be the new persisted *state* for each dropdown
this
.
setSelectedItemsToDropdown
(
response
[
accessLevelName
],
`
${
accessLevelName
}
_dropdown`
);
});
},
error
()
{
$
.
scrollTo
(
0
);
new
Flash
(
'
Failed to update tag!
'
);
},
}).
always
(()
=>
{
this
.
$allowedToCreateDropdownButton
.
enable
();
axios
.
patch
(
this
.
$wrap
.
data
(
'
url
'
),
{
protected_tag
:
formData
,
}).
then
(({
data
})
=>
{
this
.
hasChanges
=
false
;
Object
.
keys
(
ACCESS_LEVELS
).
forEach
((
level
)
=>
{
const
accessLevelName
=
ACCESS_LEVELS
[
level
];
// The data coming from server will be the new persisted *state* for each dropdown
this
.
setSelectedItemsToDropdown
(
data
[
accessLevelName
],
`
${
accessLevelName
}
_dropdown`
);
});
}).
catch
(()
=>
{
$
.
scrollTo
(
0
);
Flash
(
'
Failed to update tag!
'
);
});
}
...
...
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