Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
7c9b47e31a28
Unverified
Commit
2cc64855
authored
Feb 15, 2017
by
Luke "Jared" Bennett
Browse files
Improved team selection
Review changes
parent
845b9272df8b
Changes
7
Hide whitespace changes
Inline
Side-by-side
app/assets/stylesheets/framework/layout.scss
View file @
7c9b47e3
...
...
@@ -8,6 +8,19 @@ body {
&
.navless
{
background-color
:
$white-light
!
important
;
}
&
.card-content
{
background-color
:
$gray-darker
;
.content-wrapper
{
padding
:
0
;
.container-fluid
,
.container-limited
{
background-color
:
$gray-darker
;
}
}
}
}
.container
{
...
...
app/helpers/mattermost_helper.rb
View file @
7c9b47e3
module
MattermostHelper
def
mattermost_teams_options
(
teams
)
teams
_options
=
teams
.
map
do
|
id
,
options
|
[
options
[
'display_name'
]
||
options
[
'name'
],
id
]
teams
.
map
do
|
team
|
[
team
[
'display_name'
]
||
team
[
'name'
],
team
[
'id'
]
]
end
teams_options
.
compact
.
unshift
([
'Select team...'
,
'0'
])
end
end
app/views/layouts/application.html.haml
View file @
7c9b47e3
!!! 5
%html
{
lang:
"en"
,
class:
"#{page_class}"
}
=
render
"layouts/head"
%body
{
data:
{
page:
body_data_page
,
project:
"#{@project.path if @project}"
,
group:
"#{@group.path if @group}"
}
}
%body
{
class:
@body_class
,
data:
{
page:
body_data_page
,
project:
"#{@project.path if @project}"
,
group:
"#{@group.path if @group}"
}
}
=
Gon
::
Base
.
render_data
=
render
"layouts/header/default"
,
title:
header_title
...
...
app/views/projects/mattermosts/_team_selection.html.haml
View file @
7c9b47e3
...
...
@@ -2,16 +2,15 @@
This service will be installed on the Mattermost instance at
%strong
=
link_to
Gitlab
.
config
.
mattermost
.
host
,
Gitlab
.
config
.
mattermost
.
host
%hr
=
form_for
(
:mattermost
,
method: :post
,
url:
namespace_project_mattermost_path
(
@project
.
namespace
,
@project
))
do
|
f
|
=
form_for
(
:mattermost
,
method: :post
,
url:
namespace_project_mattermost_path
(
@project
.
namespace
,
@project
)
,
html:
{
class:
'js-requires-input'
}
)
do
|
f
|
%h4
Team
%p
=
@teams
.
one?
?
'The team'
:
'Select the team'
where the slash commands will be used in
-
selected_id
=
@teams
.
one?
?
@teams
.
keys
.
first
:
0
-
options
=
mattermost_teams_options
(
@teams
)
-
options
=
options_for_select
(
options
,
selected_id
)
=
f
.
select
(
:team_id
,
options
,
{},
{
class:
'form-control'
,
disabled:
@teams
.
one?
,
selected:
selected_id
})
=
f
.
hidden_field
(
:team_id
,
value:
selected_id
)
if
@teams
.
one?
-
selected_id
=
@teams
.
one?
?
@teams
.
first
[
'id'
]
:
nil
-
options
=
options_for_select
(
mattermost_teams_options
(
@teams
),
selected_id
)
=
f
.
select
(
:team_id
,
options
,
{
include_blank:
'Select team...'
},
{
class:
'form-control'
,
disabled:
@teams
.
one?
,
selected:
selected_id
,
required:
true
})
=
f
.
hidden_field
(
:team_id
,
value:
selected_id
,
required:
true
)
if
@teams
.
one?
.help-block
-
if
@teams
.
one?
This is the only available team.
...
...
@@ -25,7 +24,7 @@
%hr
%h4
Command trigger word
%p
Choose the word that will trigger commands
=
f
.
text_field
(
:trigger
,
value:
@project
.
path
,
class:
'form-control'
)
=
f
.
text_field
(
:trigger
,
value:
@project
.
path
,
class:
'form-control'
,
required:
true
)
.help-block
%p
Trigger word must be unique, and can't begin with a slash or contain any spaces.
...
...
app/views/projects/mattermosts/new.html.haml
View file @
7c9b47e3
-
@body_class
=
'card-content'
.service-installation
.inline.pull-right
=
custom_icon
(
'mattermost_logo'
,
size:
48
)
...
...
lib/mattermost/team.rb
View file @
7c9b47e3
module
Mattermost
class
Team
<
Client
def
all
session_get
(
'/api/v3/teams/all'
)
session_get
(
'/api/v3/teams/all'
)
.
values
end
end
end
spec/features/projects/services/mattermost_slash_command_spec.rb
View file @
7c9b47e3
require
'spec_helper'
feature
'Setup Mattermost slash commands'
,
feature
:
true
do
feature
'Setup Mattermost slash commands'
,
:
feature
,
:js
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:service
)
{
project
.
create_mattermost_slash_commands_service
}
...
...
@@ -62,11 +62,11 @@
click_link
'Add to Mattermost'
team_name
=
teams
.
first
[
1
][
'display_name'
]
select_element
=
find
(
'
select
#mattermost_team_id'
)
team_name
=
teams
.
first
[
'display_name'
]
select_element
=
find
(
'#mattermost_team_id'
)
selected_option
=
select_element
.
find
(
'option[selected]'
)
expect
(
select_element
[
'disabled'
]).
to
eq
(
'disabled'
)
expect
(
select_element
[
'disabled'
]).
to
be
(
true
)
expect
(
selected_option
).
to
have_content
(
team_name
.
to_s
)
end
...
...
@@ -75,7 +75,7 @@
click_link
'Add to Mattermost'
expect
(
find
(
'input#mattermost_team_id'
,
visible:
false
).
value
).
to
eq
(
teams
.
first
[
0
].
to_s
)
expect
(
find
(
'input#mattermost_team_id'
,
visible:
false
).
value
).
to
eq
(
teams
.
first
[
'id'
]
)
end
it
'shows an explanation user is a member of multiple teams'
do
...
...
@@ -92,12 +92,9 @@
click_link
'Add to Mattermost'
select_element
=
find
(
'select#mattermost_team_id'
)
selected_option
=
select_element
.
find
(
'option[selected]'
)
select_element
=
find
(
'#mattermost_team_id'
)
expect
(
select_element
[
'disabled'
]).
to
be
(
nil
)
expect
(
selected_option
).
to
have_content
(
'Select team...'
)
# The 'Select team...' placeholder is item `0`.
expect
(
select_element
[
'disabled'
]).
to
be
(
false
)
expect
(
select_element
.
all
(
'option'
).
count
).
to
eq
(
3
)
end
...
...
@@ -110,20 +107,37 @@
expect
(
page
).
to
have_content
(
'test mattermost error message'
)
end
it
'enables the submit button if the required fields are provided'
,
:js
do
stub_teams
(
count:
1
)
click_link
'Add to Mattermost'
expect
(
find
(
'input[type="submit"]'
)[
'disabled'
]).
not_to
be
(
true
)
end
it
'disables the submit button if the required fields are not provided'
,
:js
do
stub_teams
(
count:
1
)
click_link
'Add to Mattermost'
fill_in
(
'mattermost_trigger'
,
with:
''
)
expect
(
find
(
'input[type="submit"]'
)[
'disabled'
]).
to
be
(
true
)
end
def
stub_teams
(
count:
0
)
teams
=
create_teams
(
count
)
allow_any_instance_of
(
MattermostSlashCommandsService
).
to
receive
(
:list_teams
)
{
teams
}
allow_any_instance_of
(
MattermostSlashCommandsService
).
to
receive
(
:list_teams
)
{
[
teams
,
nil
]
}
teams
end
def
create_teams
(
count
=
0
)
teams
=
{}
teams
=
[]
count
.
times
do
|
i
|
i
+=
1
teams
[
i
]
=
{
id:
i
,
display_name:
i
}
teams
.
push
({
"id"
=>
"x
#{
i
}
"
,
"display_name"
=>
"x
#{
i
}
-name"
})
end
teams
...
...
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