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
60c86cf8
Commit
60c86cf8
authored
Sep 27, 2019
by
Winnie Hellmann
Committed by
Tim Zallmann
Sep 27, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove nested Promise from admin email select
parent
2a5e7ffa
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
73 deletions
+62
-73
ee/app/assets/javascripts/pages/admin/emails/show/admin_email_select.js
...javascripts/pages/admin/emails/show/admin_email_select.js
+62
-73
No files found.
ee/app/assets/javascripts/pages/admin/emails/show/admin_email_select.js
View file @
60c86cf8
/* eslint-disable no-var, func-names, one-var, no-else-return */
import
$
from
'
jquery
'
;
import
Api
from
'
~/api
'
;
import
{
sprintf
,
__
}
from
'
~/locale
'
;
function
AdminEmailSelect
()
{
import
(
/* webpackChunkName: 'select2' */
'
select2/select2
'
)
.
then
(()
=>
{
$
(
'
.ajax-admin-email-select
'
).
each
(
(
function
(
_this
)
{
return
function
(
i
,
select
)
{
return
$
(
select
).
select2
({
placeholder
:
__
(
'
Select group or project
'
),
multiple
:
$
(
select
).
hasClass
(
'
multiselect
'
),
minimumInputLength
:
0
,
query
(
query
)
{
const
groupsFetch
=
Api
.
groups
(
query
.
term
,
{});
const
projectsFetch
=
Api
.
projects
(
query
.
term
,
{
order_by
:
'
id
'
,
membership
:
false
,
});
return
Promise
.
all
([
projectsFetch
,
groupsFetch
]).
then
(([
projects
,
groups
])
=>
{
var
all
,
data
;
all
=
{
id
:
'
all
'
,
};
data
=
[
all
].
concat
(
groups
,
projects
);
return
query
.
callback
({
results
:
data
,
});
});
},
id
(
object
)
{
if
(
object
.
path_with_namespace
)
{
return
`project-
${
object
.
id
}
`
;
}
else
if
(
object
.
path
)
{
return
`group-
${
object
.
id
}
`
;
}
else
{
return
'
all
'
;
}
},
formatResult
(...
args
)
{
return
_this
.
formatResult
(...
args
);
},
formatSelection
(...
args
)
{
return
_this
.
formatSelection
(...
args
);
},
dropdownCssClass
:
'
ajax-admin-email-dropdown
'
,
escapeMarkup
(
m
)
{
return
m
;
},
});
};
})(
this
),
);
})
.
catch
(()
=>
{});
}
AdminEmailSelect
.
prototype
.
formatResult
=
function
(
object
)
{
if
(
object
.
path_with_namespace
)
{
return
`<div class='project-result'> <div class='project-name'>
${
object
.
name
}
</div> <div class='project-path'>
${
object
.
path_with_namespace
}
</div> </div>`
;
}
else
if
(
object
.
path
)
{
return
`<div class='group-result'> <div class='group-name'>
${
object
.
name
}
</div> <div class='group-path'>
${
object
.
path
}
</div> </div>`
;
}
else
{
return
`<div class='group-result'> <div class='group-name'>
${
__
(
'
All
'
,
)}
</div> <div class='group-path'>
${
__
(
'
All groups and projects
'
)}
</div> </div>`
;
const
formatResult
=
selectedItem
=>
{
if
(
selectedItem
.
path_with_namespace
)
{
return
`<div class='project-result'> <div class='project-name'>
${
selectedItem
.
name
}
</div> <div class='project-path'>
${
selectedItem
.
path_with_namespace
}
</div> </div>`
;
}
else
if
(
selectedItem
.
path
)
{
return
`<div class='group-result'> <div class='group-name'>
${
selectedItem
.
name
}
</div> <div class='group-path'>
${
selectedItem
.
path
}
</div> </div>`
;
}
return
`<div class='group-result'> <div class='group-name'>
${
__
(
'
All
'
,
)}
</div> <div class='group-path'>
${
__
(
'
All groups and projects
'
)}
</div> </div>`
;
};
AdminEmailSelect
.
prototype
.
formatSelection
=
function
(
object
)
{
if
(
object
.
path_with_namespace
)
{
return
sprintf
(
__
(
'
Project: %{name}
'
),
{
name
:
object
.
name
});
}
else
if
(
object
.
path
)
{
return
sprintf
(
__
(
'
Group: %{name}
'
),
{
name
:
object
.
name
});
}
else
{
return
__
(
'
All groups and projects
'
);
const
formatSelection
=
selectedItem
=>
{
if
(
selectedItem
.
path_with_namespace
)
{
return
sprintf
(
__
(
'
Project: %{name}
'
),
{
name
:
selectedItem
.
name
});
}
else
if
(
selectedItem
.
path
)
{
return
sprintf
(
__
(
'
Group: %{name}
'
),
{
name
:
selectedItem
.
name
});
}
return
__
(
'
All groups and projects
'
);
};
export
default
AdminEmailSelect
;
const
AdminEmailSelect
=
()
=>
{
$
(
'
.ajax-admin-email-select
'
).
each
((
i
,
select
)
=>
$
(
select
).
select2
({
placeholder
:
__
(
'
Select group or project
'
),
multiple
:
$
(
select
).
hasClass
(
'
multiselect
'
),
minimumInputLength
:
0
,
query
(
query
)
{
const
groupsFetch
=
Api
.
groups
(
query
.
term
,
{});
const
projectsFetch
=
Api
.
projects
(
query
.
term
,
{
order_by
:
'
id
'
,
membership
:
false
,
});
return
Promise
.
all
([
projectsFetch
,
groupsFetch
]).
then
(([
projects
,
groups
])
=>
{
const
all
=
{
id
:
'
all
'
,
};
const
data
=
[
all
].
concat
(
groups
,
projects
);
return
query
.
callback
({
results
:
data
,
});
});
},
id
(
object
)
{
if
(
object
.
path_with_namespace
)
{
return
`project-
${
object
.
id
}
`
;
}
else
if
(
object
.
path
)
{
return
`group-
${
object
.
id
}
`
;
}
return
'
all
'
;
},
formatResult
(...
args
)
{
return
formatResult
(...
args
);
},
formatSelection
(...
args
)
{
return
formatSelection
(...
args
);
},
dropdownCssClass
:
'
ajax-admin-email-dropdown
'
,
escapeMarkup
(
m
)
{
return
m
;
},
}),
);
};
export
default
()
=>
import
(
/* webpackChunkName: 'select2' */
'
select2/select2
'
)
.
then
(
AdminEmailSelect
)
.
catch
(()
=>
{});
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