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
Léo-Paul Géneau
gitlab-ce
Commits
f68b3aaa
Commit
f68b3aaa
authored
Sep 20, 2017
by
Jose Ivan Vargas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added defaults for the protected branches dropdowns for the repository settings
parent
d15109dc
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
9 deletions
+71
-9
app/assets/javascripts/gl_dropdown.js
app/assets/javascripts/gl_dropdown.js
+3
-3
app/assets/javascripts/protected_branches/protected_branch_create.js
...javascripts/protected_branches/protected_branch_create.js
+45
-6
changelogs/unreleased/32163-protected-branch-form-should-have-sane-defaults-for-dropdowns.yml
...d-branch-form-should-have-sane-defaults-for-dropdowns.yml
+5
-0
spec/features/protected_branches_spec.rb
spec/features/protected_branches_spec.rb
+18
-0
No files found.
app/assets/javascripts/gl_dropdown.js
View file @
f68b3aaa
...
@@ -737,7 +737,7 @@ GitLabDropdown = (function() {
...
@@ -737,7 +737,7 @@ GitLabDropdown = (function() {
:
selectedObject
.
id
;
:
selectedObject
.
id
;
if
(
isInput
)
{
if
(
isInput
)
{
field
=
$
(
this
.
el
);
field
=
$
(
this
.
el
);
}
else
if
(
value
)
{
}
else
if
(
value
!=
null
)
{
field
=
this
.
dropdown
.
parent
().
find
(
"
input[name='
"
+
fieldName
+
"
'][value='
"
+
value
.
toString
().
replace
(
/'/g
,
'
\\\'
'
)
+
"
']
"
);
field
=
this
.
dropdown
.
parent
().
find
(
"
input[name='
"
+
fieldName
+
"
'][value='
"
+
value
.
toString
().
replace
(
/'/g
,
'
\\\'
'
)
+
"
']
"
);
}
}
...
@@ -745,7 +745,7 @@ GitLabDropdown = (function() {
...
@@ -745,7 +745,7 @@ GitLabDropdown = (function() {
return
;
return
;
}
}
if
(
el
.
hasClass
(
ACTIVE_CLASS
))
{
if
(
el
.
hasClass
(
ACTIVE_CLASS
)
&&
value
!==
0
)
{
isMarking
=
false
;
isMarking
=
false
;
el
.
removeClass
(
ACTIVE_CLASS
);
el
.
removeClass
(
ACTIVE_CLASS
);
if
(
field
&&
field
.
length
)
{
if
(
field
&&
field
.
length
)
{
...
@@ -851,7 +851,7 @@ GitLabDropdown = (function() {
...
@@ -851,7 +851,7 @@ GitLabDropdown = (function() {
if
(
href
&&
href
!==
'
#
'
)
{
if
(
href
&&
href
!==
'
#
'
)
{
gl
.
utils
.
visitUrl
(
href
);
gl
.
utils
.
visitUrl
(
href
);
}
else
{
}
else
{
$el
.
first
().
trigger
(
'
click
'
);
$el
.
trigger
(
'
click
'
);
}
}
}
}
};
};
...
...
app/assets/javascripts/protected_branches/protected_branch_create.js
View file @
f68b3aaa
import
_
from
'
underscore
'
;
import
ProtectedBranchAccessDropdown
from
'
./protected_branch_access_dropdown
'
;
import
ProtectedBranchAccessDropdown
from
'
./protected_branch_access_dropdown
'
;
import
ProtectedBranchDropdown
from
'
./protected_branch_dropdown
'
;
import
ProtectedBranchDropdown
from
'
./protected_branch_dropdown
'
;
import
AccessorUtilities
from
'
../lib/utils/accessor
'
;
const
PB_LOCAL_STORAGE_KEY
=
'
protected-branches-defaults
'
;
export
default
class
ProtectedBranchCreate
{
export
default
class
ProtectedBranchCreate
{
constructor
()
{
constructor
()
{
this
.
$form
=
$
(
'
.js-new-protected-branch
'
);
this
.
$form
=
$
(
'
.js-new-protected-branch
'
);
this
.
isLocalStorageAvailable
=
AccessorUtilities
.
isLocalStorageAccessSafe
();
this
.
currentProjectUserDefaults
=
{};
this
.
buildDropdowns
();
this
.
buildDropdowns
();
}
}
buildDropdowns
()
{
buildDropdowns
()
{
const
$allowedToMergeDropdown
=
this
.
$form
.
find
(
'
.js-allowed-to-merge
'
);
const
$allowedToMergeDropdown
=
this
.
$form
.
find
(
'
.js-allowed-to-merge
'
);
const
$allowedToPushDropdown
=
this
.
$form
.
find
(
'
.js-allowed-to-push
'
);
const
$allowedToPushDropdown
=
this
.
$form
.
find
(
'
.js-allowed-to-push
'
);
const
$protectedBranchDropdown
=
this
.
$form
.
find
(
'
.js-protected-branch-select
'
);
// Cache callback
// Cache callback
this
.
onSelectCallback
=
this
.
onSelect
.
bind
(
this
);
this
.
onSelectCallback
=
this
.
onSelect
.
bind
(
this
);
...
@@ -28,15 +35,13 @@ export default class ProtectedBranchCreate {
...
@@ -28,15 +35,13 @@ export default class ProtectedBranchCreate {
onSelect
:
this
.
onSelectCallback
,
onSelect
:
this
.
onSelectCallback
,
});
});
// Select default
$allowedToPushDropdown
.
data
(
'
glDropdown
'
).
selectRowAtIndex
(
0
);
$allowedToMergeDropdown
.
data
(
'
glDropdown
'
).
selectRowAtIndex
(
0
);
// Protected branch dropdown
// Protected branch dropdown
this
.
protectedBranchDropdown
=
new
ProtectedBranchDropdown
({
this
.
protectedBranchDropdown
=
new
ProtectedBranchDropdown
({
$dropdown
:
this
.
$form
.
find
(
'
.js-protected-branch-select
'
)
,
$dropdown
:
$protectedBranchDropdown
,
onSelect
:
this
.
onSelectCallback
,
onSelect
:
this
.
onSelectCallback
,
});
});
this
.
loadPreviousSelection
(
$allowedToMergeDropdown
.
data
(
'
glDropdown
'
),
$allowedToPushDropdown
.
data
(
'
glDropdown
'
));
}
}
// This will run after clicked callback
// This will run after clicked callback
...
@@ -45,7 +50,41 @@ export default class ProtectedBranchCreate {
...
@@ -45,7 +50,41 @@ export default class ProtectedBranchCreate {
const
$branchInput
=
this
.
$form
.
find
(
'
input[name="protected_branch[name]"]
'
);
const
$branchInput
=
this
.
$form
.
find
(
'
input[name="protected_branch[name]"]
'
);
const
$allowedToMergeInput
=
this
.
$form
.
find
(
'
input[name="protected_branch[merge_access_levels_attributes][0][access_level]"]
'
);
const
$allowedToMergeInput
=
this
.
$form
.
find
(
'
input[name="protected_branch[merge_access_levels_attributes][0][access_level]"]
'
);
const
$allowedToPushInput
=
this
.
$form
.
find
(
'
input[name="protected_branch[push_access_levels_attributes][0][access_level]"]
'
);
const
$allowedToPushInput
=
this
.
$form
.
find
(
'
input[name="protected_branch[push_access_levels_attributes][0][access_level]"]
'
);
const
completedForm
=
!
(
$branchInput
.
val
()
&&
$allowedToMergeInput
.
length
&&
$allowedToPushInput
.
length
);
// Save previously used settings
if
(
!
completedForm
)
{
this
.
savePreviousSelection
(
$allowedToMergeInput
.
val
(),
$allowedToPushInput
.
val
());
}
this
.
$form
.
find
(
'
input[type="submit"]
'
).
attr
(
'
disabled
'
,
completedForm
);
}
loadPreviousSelection
(
mergeDropdown
,
pushDropdown
)
{
let
mergeIndex
=
0
;
let
pushIndex
=
0
;
if
(
this
.
isLocalStorageAvailable
)
{
const
savedDefaults
=
JSON
.
parse
(
window
.
localStorage
.
getItem
(
PB_LOCAL_STORAGE_KEY
));
if
(
savedDefaults
!=
null
)
{
mergeIndex
=
_
.
findLastIndex
(
mergeDropdown
.
fullData
.
roles
,
{
id
:
parseInt
(
savedDefaults
.
mergeSelection
,
0
),
});
pushIndex
=
_
.
findLastIndex
(
pushDropdown
.
fullData
.
roles
,
{
id
:
parseInt
(
savedDefaults
.
pushSelection
,
0
),
});
}
}
mergeDropdown
.
selectRowAtIndex
(
mergeIndex
);
pushDropdown
.
selectRowAtIndex
(
pushIndex
);
}
this
.
$form
.
find
(
'
input[type="submit"]
'
).
attr
(
'
disabled
'
,
!
(
$branchInput
.
val
()
&&
$allowedToMergeInput
.
length
&&
$allowedToPushInput
.
length
));
savePreviousSelection
(
mergeSelection
,
pushSelection
)
{
if
(
this
.
isLocalStorageAvailable
)
{
const
branchDefaults
=
{
mergeSelection
,
pushSelection
,
};
window
.
localStorage
.
setItem
(
PB_LOCAL_STORAGE_KEY
,
JSON
.
stringify
(
branchDefaults
));
}
}
}
}
}
changelogs/unreleased/32163-protected-branch-form-should-have-sane-defaults-for-dropdowns.yml
0 → 100644
View file @
f68b3aaa
---
title
:
Added defaults for protected branches dropdowns on the repository settings
merge_request
:
14278
author
:
type
:
changed
spec/features/protected_branches_spec.rb
View file @
f68b3aaa
...
@@ -90,4 +90,22 @@ feature 'Protected Branches', js: true do
...
@@ -90,4 +90,22 @@ feature 'Protected Branches', js: true do
describe
"access control"
do
describe
"access control"
do
include_examples
"protected branches > access control > CE"
include_examples
"protected branches > access control > CE"
end
end
describe
"saved defaults"
do
it
"keeps the allowed to merge and push dropdowns defaults based on the previous selection"
do
visit
project_protected_branches_path
(
project
)
set_protected_branch_name
(
'some-branch'
)
find
(
".js-allowed-to-merge"
).
trigger
(
'click'
)
click_link
'No one'
find
(
".js-allowed-to-push"
).
trigger
(
'click'
)
click_link
'Developers + Masters'
visit
project_protected_branches_path
(
project
)
page
.
within
(
".js-allowed-to-merge"
)
do
expect
(
page
.
find
(
".dropdown-toggle-text"
)).
to
have_content
(
"No one"
)
end
page
.
within
(
".js-allowed-to-push"
)
do
expect
(
page
.
find
(
".dropdown-toggle-text"
)).
to
have_content
(
"Developers + Masters"
)
end
end
end
end
end
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