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
671be9d9
Commit
671be9d9
authored
Oct 23, 2017
by
Filipa Lacerda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove groups_select from global namespace & simplifies the code
parent
1c317af4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
113 deletions
+77
-113
app/assets/javascripts/dispatcher.js
app/assets/javascripts/dispatcher.js
+2
-2
app/assets/javascripts/groups_select.js
app/assets/javascripts/groups_select.js
+75
-110
app/assets/javascripts/main.js
app/assets/javascripts/main.js
+0
-1
No files found.
app/assets/javascripts/dispatcher.js
View file @
671be9d9
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
/* global LineHighlighter */
/* global LineHighlighter */
import
BuildArtifacts
from
'
./build_artifacts
'
;
import
BuildArtifacts
from
'
./build_artifacts
'
;
import
CILintEditor
from
'
./ci_lint_editor
'
;
import
CILintEditor
from
'
./ci_lint_editor
'
;
/* global GroupsSelect */
import
groupsSelect
from
'
./groups_select
'
;
/* global Search */
/* global Search */
/* global Admin */
/* global Admin */
/* global NamespaceSelects */
/* global NamespaceSelects */
...
@@ -448,7 +448,7 @@ import initGroupAnalytics from './init_group_analytics';
...
@@ -448,7 +448,7 @@ import initGroupAnalytics from './init_group_analytics';
break
;
break
;
case
'
projects:project_members:index
'
:
case
'
projects:project_members:index
'
:
memberExpirationDate
(
'
.js-access-expiration-date-groups
'
);
memberExpirationDate
(
'
.js-access-expiration-date-groups
'
);
new
G
roupsSelect
();
g
roupsSelect
();
memberExpirationDate
();
memberExpirationDate
();
new
Members
();
new
Members
();
new
UsersSelect
();
new
UsersSelect
();
...
...
app/assets/javascripts/groups_select.js
View file @
671be9d9
/* eslint-disable func-names, space-before-function-paren, no-var, wrap-iife, one-var,
camelcase, one-var-declaration-per-line, quotes, object-shorthand,
prefer-arrow-callback, comma-dangle, consistent-return, yoda,
prefer-rest-params, prefer-spread, no-unused-vars, prefer-template,
promise/catch-or-return */
import
Api
from
'
./api
'
;
import
Api
from
'
./api
'
;
import
{
normalizeCRLFHeaders
}
from
'
./lib/utils/common_utils
'
;
import
{
normalizeCRLFHeaders
}
from
'
./lib/utils/common_utils
'
;
var
slice
=
[].
slice
;
export
default
function
groupsSelect
()
{
const
PER_PAGE
=
20
;
$
(
'
.ajax-groups-select
'
).
each
(
function
setAjaxGroupsSelect2
()
{
const
$select
=
$
(
this
);
const
allAvailable
=
$select
.
data
(
'
all-available
'
);
const
skipGroups
=
$select
.
data
(
'
skip-groups
'
)
||
[];
$select
.
select2
({
placeholder
:
'
Search for a group
'
,
multiple
:
$select
.
hasClass
(
'
multiselect
'
),
minimumInputLength
:
0
,
ajax
:
{
url
:
Api
.
buildUrl
(
Api
.
groupsPath
),
dataType
:
'
json
'
,
quietMillis
:
250
,
transport
(
params
)
{
// eslint-disable-next-line promise/catch-or-return
$
.
ajax
(
params
)
.
then
((
data
,
status
,
xhr
)
=>
{
const
results
=
data
||
[];
window
.
GroupsSelect
=
(
function
()
{
const
headers
=
normalizeCRLFHeaders
(
xhr
.
getAllResponseHeaders
());
function
GroupsSelect
()
{
const
currentPage
=
parseInt
(
headers
[
'
X-PAGE
'
],
10
)
||
0
;
$
(
'
.ajax-groups-select
'
).
each
((
function
(
_this
)
{
const
totalPages
=
parseInt
(
headers
[
'
X-TOTAL-PAGES
'
],
10
)
||
0
;
const
self
=
_this
;
const
more
=
currentPage
<
totalPages
;
return
function
(
i
,
select
)
{
var
all_available
,
skip_groups
;
const
$select
=
$
(
select
);
all_available
=
$select
.
data
(
'
all-available
'
);
skip_groups
=
$select
.
data
(
'
skip-groups
'
)
||
[];
$select
.
select2
({
placeholder
:
"
Search for a group
"
,
multiple
:
$select
.
hasClass
(
'
multiselect
'
),
minimumInputLength
:
0
,
ajax
:
{
url
:
Api
.
buildUrl
(
Api
.
groupsPath
),
dataType
:
'
json
'
,
quietMillis
:
250
,
transport
:
function
(
params
)
{
$
.
ajax
(
params
).
then
((
data
,
status
,
xhr
)
=>
{
const
results
=
data
||
[];
const
headers
=
normalizeCRLFHeaders
(
xhr
.
getAllResponseHeaders
());
const
currentPage
=
parseInt
(
headers
[
'
X-PAGE
'
],
10
)
||
0
;
const
totalPages
=
parseInt
(
headers
[
'
X-TOTAL-PAGES
'
],
10
)
||
0
;
const
more
=
currentPage
<
totalPages
;
return
{
results
,
pagination
:
{
more
,
},
};
}).
then
(
params
.
success
).
fail
(
params
.
error
);
},
data
:
function
(
search
,
page
)
{
return
{
search
,
page
,
per_page
:
GroupsSelect
.
PER_PAGE
,
all_available
,
};
},
results
:
function
(
data
,
page
)
{
if
(
data
.
length
)
return
{
results
:
[]
};
const
groups
=
data
.
length
?
data
:
data
.
results
||
[];
const
more
=
data
.
pagination
?
data
.
pagination
.
more
:
false
;
const
results
=
groups
.
filter
(
group
=>
skip_groups
.
indexOf
(
group
.
id
)
===
-
1
);
return
{
return
{
results
,
results
,
page
,
pagination
:
{
more
,
more
,
},
};
};
},
})
},
.
then
(
params
.
success
)
initSelection
:
function
(
element
,
callback
)
{
.
fail
(
params
.
error
);
var
id
;
},
id
=
$
(
element
).
val
();
data
(
search
,
page
)
{
if
(
id
!==
""
)
{
return
{
return
Api
.
group
(
id
,
callback
);
search
,
}
page
,
},
per_page
:
PER_PAGE
,
formatResult
:
function
()
{
all_available
:
allAvailable
,
var
args
;
};
args
=
1
<=
arguments
.
length
?
slice
.
call
(
arguments
,
0
)
:
[];
},
return
self
.
formatResult
.
apply
(
self
,
args
);
results
(
data
,
page
)
{
},
if
(
data
.
length
)
return
{
results
:
[]
};
formatSelection
:
function
()
{
var
args
;
args
=
1
<=
arguments
.
length
?
slice
.
call
(
arguments
,
0
)
:
[];
return
self
.
formatSelection
.
apply
(
self
,
args
);
},
dropdownCssClass
:
"
ajax-groups-dropdown select2-infinite
"
,
// we do not want to escape markup since we are displaying html in results
escapeMarkup
:
function
(
m
)
{
return
m
;
}
});
self
.
dropdown
=
document
.
querySelector
(
'
.select2-infinite .select2-results
'
);
$select
.
on
(
'
select2-loaded
'
,
self
.
forceOverflow
.
bind
(
self
));
};
})(
this
));
}
GroupsSelect
.
prototype
.
formatResult
=
function
(
group
)
{
var
avatar
;
if
(
group
.
avatar_url
)
{
avatar
=
group
.
avatar_url
;
}
else
{
avatar
=
gon
.
default_avatar_url
;
}
return
"
<div class='group-result'> <div class='group-name'>
"
+
group
.
full_name
+
"
</div> <div class='group-path'>
"
+
group
.
full_path
+
"
</div> </div>
"
;
};
GroupsSelect
.
prototype
.
formatSelection
=
function
(
group
)
{
return
group
.
full_name
;
};
GroupsSelect
.
prototype
.
forceOverflow
=
function
(
e
)
{
const
groups
=
data
.
length
?
data
:
data
.
results
||
[];
this
.
dropdown
.
style
.
height
=
`
${
Math
.
floor
(
this
.
dropdown
.
scrollHeight
)}
px`
;
const
more
=
data
.
pagination
?
data
.
pagination
.
more
:
false
;
}
;
const
results
=
groups
.
filter
(
group
=>
skipGroups
.
indexOf
(
group
.
id
)
===
-
1
)
;
GroupsSelect
.
PER_PAGE
=
20
;
return
{
results
,
page
,
more
,
};
},
},
// eslint-disable-next-line consistent-return
initSelection
(
element
,
callback
)
{
const
id
=
$
(
element
).
val
();
if
(
id
!==
''
)
{
return
Api
.
group
(
id
,
callback
);
}
},
formatResult
(
object
)
{
return
`<div class='group-result'> <div class='group-name'>
${
object
.
full_name
}
</div> <div class='group-path'>
${
object
.
full_path
}
</div> </div>`
;
},
formatSelection
(
object
)
{
return
object
.
full_name
;
},
dropdownCssClass
:
'
ajax-groups-dropdown select2-infinite
'
,
// we do not want to escape markup since we are displaying html in results
escapeMarkup
(
m
)
{
return
m
;
},
});
return
GroupsSelect
;
$select
.
on
(
'
select2-loaded
'
,
()
=>
{
})();
const
dropdown
=
document
.
querySelector
(
'
.select2-infinite .select2-results
'
);
dropdown
.
style
.
height
=
`
${
Math
.
floor
(
dropdown
.
scrollHeight
)}
px`
;
});
});
}
app/assets/javascripts/main.js
View file @
671be9d9
...
@@ -58,7 +58,6 @@ import './gl_field_errors';
...
@@ -58,7 +58,6 @@ import './gl_field_errors';
import
'
./gl_form
'
;
import
'
./gl_form
'
;
import
'
./group_avatar
'
;
import
'
./group_avatar
'
;
import
'
./group_label_subscription
'
;
import
'
./group_label_subscription
'
;
import
'
./groups_select
'
;
import
'
./header
'
;
import
'
./header
'
;
import
'
./importer_status
'
;
import
'
./importer_status
'
;
import
'
./issuable_index
'
;
import
'
./issuable_index
'
;
...
...
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