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
0bee0186
Commit
0bee0186
authored
Nov 24, 2017
by
Filipa Lacerda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds JS to toggle buttons [ci skip]
parent
5413bf04
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
178 additions
and
31 deletions
+178
-31
app/assets/javascripts/clusters/clusters_index.js
app/assets/javascripts/clusters/clusters_index.js
+62
-0
app/assets/javascripts/clusters/services/clusters_service.js
app/assets/javascripts/clusters/services/clusters_service.js
+4
-0
app/assets/javascripts/dispatcher.js
app/assets/javascripts/dispatcher.js
+9
-1
app/controllers/projects/clusters_controller.rb
app/controllers/projects/clusters_controller.rb
+14
-4
app/views/projects/clusters/_empty_state.html.haml
app/views/projects/clusters/_empty_state.html.haml
+1
-1
app/views/projects/clusters/index.html.haml
app/views/projects/clusters/index.html.haml
+28
-25
spec/features/projects/clusters_spec.rb
spec/features/projects/clusters_spec.rb
+29
-0
spec/javascripts/clusters/clusters_index_spec.js
spec/javascripts/clusters/clusters_index_spec.js
+31
-0
No files found.
app/assets/javascripts/clusters/clusters_index.js
0 → 100644
View file @
0bee0186
import
Flash
from
'
../flash
'
;
import
{
s__
}
from
'
../locale
'
;
import
ClustersService
from
'
./services/clusters_service
'
;
/**
* Handles toggle buttons in the cluster's table.
*
* When the user clicks the toggle button for each cluster, it:
* - toggles the button
* - shows a loding and disabled state
* - Makes a put request to the given endpoint
* Once we receive the response, either:
* 1) Show updated status in case of successfull response
* 2) Show initial status in case of failed response
*/
export
default
class
ClusterTable
{
constructor
()
{
this
.
container
=
'
.js-clusters-list
'
;
document
.
querySelectorAll
(
`
${
this
.
container
}
.js-toggle-cluster-list`
).
forEach
(
button
=>
button
.
addEventListener
(
'
click
'
,
e
=>
ClusterTable
.
updateCluster
(
e
)));
}
removeListeners
()
{
document
.
querySelectorAll
(
`
${
this
.
container
}
.js-toggle-cluster-list`
).
forEach
(
button
=>
button
.
removeEventListener
(
'
click
'
));
}
static
updateCluster
(
e
)
{
const
toggleButton
=
e
.
currentTarget
;
const
value
=
toggleButton
.
classList
.
contains
(
'
checked
'
).
toString
();
const
endpoint
=
toggleButton
.
getAttribute
(
'
data-endpoint
'
);
ClusterTable
.
toggleValue
(
toggleButton
);
ClusterTable
.
toggleLoadingButton
(
toggleButton
);
ClustersService
.
updateCluster
(
endpoint
,
{
cluster
:
{
enabled
:
value
}
})
.
then
(()
=>
{
ClusterTable
.
toggleLoadingButton
(
toggleButton
);
})
.
catch
(()
=>
{
ClusterTable
.
toggleLoadingButton
(
toggleButton
);
ClusterTable
.
toggleValue
(
toggleButton
);
Flash
(
s__
(
'
ClusterIntegration|Something went wrong on our end.
'
));
});
}
/**
* Toggles loading and disabled classes.
* @param {HTMLElement} button
*/
static
toggleLoadingButton
(
button
)
{
button
.
setAttribute
(
'
disabled
'
,
button
.
getAttribute
(
'
disabled
'
));
button
.
classList
.
toggle
(
'
disabled
'
);
button
.
classList
.
toggle
(
'
loading
'
);
}
/**
* Toggles checked class for the given button
* @param {HTMLElement} button
*/
static
toggleValue
(
button
)
{
button
.
classList
.
toggle
(
'
checked
'
);
}
}
app/assets/javascripts/clusters/services/clusters_service.js
View file @
0bee0186
...
...
@@ -17,4 +17,8 @@ export default class ClusterService {
installApplication
(
appId
)
{
return
axios
.
post
(
this
.
appInstallEndpointMap
[
appId
]);
}
static
updateCluster
(
endpoint
,
data
)
{
return
axios
.
put
(
endpoint
,
data
);
}
}
app/assets/javascripts/dispatcher.js
View file @
0bee0186
...
...
@@ -550,7 +550,15 @@ import ProjectVariables from './project_variables';
import
(
/* webpackChunkName: "clusters" */
'
./clusters/clusters_bundle
'
)
.
then
(
cluster
=>
new
cluster
.
default
())
// eslint-disable-line new-cap
.
catch
((
err
)
=>
{
Flash
(
s__
(
'
ClusterIntegration|Problem setting up the cluster JavaScript
'
));
Flash
(
s__
(
'
ClusterIntegration|Problem setting up the cluster
'
));
throw
err
;
});
break
;
case
'
projects:clusters:index
'
:
import
(
/* webpackChunkName: "clusters_index" */
'
./clusters/clusters_index
'
)
.
then
(
clusterIndex
=>
new
clusterIndex
.
default
())
// eslint-disable-line new-cap
.
catch
((
err
)
=>
{
Flash
(
s__
(
'
ClusterIntegration|Problem setting up the clusters list
'
));
throw
err
;
});
break
;
...
...
app/controllers/projects/clusters_controller.rb
View file @
0bee0186
...
...
@@ -7,7 +7,7 @@ class Projects::ClustersController < Projects::ApplicationController
before_action
:authorize_admin_cluster!
,
only:
[
:destroy
]
def
index
@clusters
||=
project
.
clusters
.
map
{
|
cluster
|
cluster
.
present
(
current_user:
current_user
)
}
@clusters
||=
project
.
clusters
.
page
(
params
[
:page
]).
per
(
20
).
map
{
|
cluster
|
cluster
.
present
(
current_user:
current_user
)
}
end
def
login
...
...
@@ -64,10 +64,20 @@ class Projects::ClustersController < Projects::ApplicationController
.
execute
(
cluster
)
if
cluster
.
valid?
respond_to
do
|
format
|
format
.
json
do
head
:no_content
end
format
.
html
do
flash
[
:notice
]
=
"Cluster was successfully updated."
redirect_to
project_cluster_path
(
project
,
project
.
cluster
)
end
end
else
render
:show
respond_to
do
|
format
|
format
.
json
{
head
:bad_request
}
format
.
html
{
render
:show
}
end
end
end
...
...
app/views/projects/clusters/_empty_state.html.haml
View file @
0bee0186
...
...
@@ -5,6 +5,6 @@
%p
=
s_
(
'ClusterIntegration|Clusters allow you to use review apps, deploy your applications, run your pipelines, and much more in an easy way. %{link_to_help_page}'
).
html_safe
%
{
link_to_help_page:
link_to_help_page
}
%p
=
link_to
s_
(
'ClusterIntegration|Add cluster'
),
''
,
class:
'btn btn-success'
,
title:
'Add cluster'
=
link_to
s_
(
'ClusterIntegration|Add cluster'
),
new_project_cluster_path
(
@project
)
,
class:
'btn btn-success'
,
title:
'Add cluster'
.svg-content
=
image_tag
'illustrations/labels.svg'
app/views/projects/clusters/index.html.haml
View file @
0bee0186
...
...
@@ -21,8 +21,8 @@
%span
.badge
0
.nav-controls
=
link_to
s_
(
'ClusterIntegration|Add cluster'
),
''
,
class:
'btn btn-success'
,
title:
'Add cluster'
.ci-table
=
link_to
s_
(
'ClusterIntegration|Add cluster'
),
new_project_cluster_path
(
@project
)
,
class:
'btn btn-success'
,
title:
'Add cluster'
.ci-table
.js-clusters-list
.gl-responsive-table-row.table-row-header
{
role:
'row'
}
.table-section.section-30
{
role:
'rowheader'
}
=
s_
(
'ClusterIntegration|Cluster'
)
...
...
@@ -31,12 +31,11 @@
.table-section.section-30
{
role:
'rowheader'
}
=
s_
(
'ClusterIntegration|Project namespace'
)
.table-section.section-10
{
role:
'rowheader'
}
-
@clusters
.
each
do
|
cluster
|
.gl-responsive-table-row
.table-section.section-30
.table-mobile-header
{
role:
'rowheader'
}
=
s_
(
'ClusterIntegration|Cluster'
)
.table-mobile-content
Content goes here
.table-mobile-header
{
role:
'rowheader'
}=
s_
(
'ClusterIntegration|Cluster'
)
.table-mobile-content
=
cluster
.
name
.table-section.section-30
.table-mobile-header
{
role:
'rowheader'
}
=
s_
(
'ClusterIntegration|Environment pattern'
)
...
...
@@ -51,7 +50,11 @@
.table-mobile-header
{
role:
'rowheader'
}
.table-mobile-content
%button
{
type:
'button'
,
class:
"js-toggle-cluster project-feature-toggle
"
,
class:
"js-toggle-cluster-list project-feature-toggle #{'checked' unless !cluster.enabled?} #{'disabled' unless can?(current_user, :update_cluster, cluster)}
"
,
'aria-label'
:
s_
(
'ClusterIntegration|Toggle Cluster'
),
data:
{
'enabled-text'
:
'Enabled'
,
'disabled-text'
:
'Disabled'
}
}
disabled:
!
can?
(
current_user
,
:update_cluster
,
cluster
),
data:
{
'enabled-text'
:
'Enabled'
,
'disabled-text'
:
'Disabled'
,
endpoint:
namespace_project_cluster_path
(
@project
.
namespace
,
@project
,
cluster
,
format: :json
)
}
}
=
icon
(
'loading'
,
class:
'hidden'
)
spec/features/projects/clusters_spec.rb
View file @
0bee0186
...
...
@@ -94,6 +94,33 @@ feature 'Clusters', :js do
visit
project_clusters_path
(
project
)
end
it
'user sees a table with one cluster'
do
end
it
'user sees a disabled add cluster button '
do
end
it
'user sees navigation tabs'
do
end
context
'update cluster'
do
it
'user can update cluster'
do
end
context
'with sucessfull request'
do
it
'user sees updated cluster'
do
end
end
context
'with failed request'
do
it
'user sees not update cluster and error message'
do
end
end
end
context
'when user clicks on a cluster'
do
before
do
# TODO: Replace with Click on cluster after frontend implements list
...
...
@@ -216,4 +243,6 @@ feature 'Clusters', :js do
expect
(
page
).
to
have_css
(
'.signin-with-google'
)
end
end
context
end
spec/javascripts/clusters/clusters_index_spec.js
0 → 100644
View file @
0bee0186
import
ClusterTable
from
'
~/clusters/clusters_index
'
;
describe
(
'
Clusters table
'
,
()
=>
{
let
ClustersClass
;
beforeEach
(()
=>
{
ClustersClass
=
new
ClusterTable
();
});
afterEach
(()
=>
{
ClustersClass
.
removeListeners
();
});
describe
(
'
update cluster
'
,
()
=>
{
it
(
'
renders a toggle button
'
,
()
=>
{
});
it
(
'
renders loading state while request is made
'
,
()
=>
{
});
it
(
'
shows updated state after sucessfull request
'
,
()
=>
{
});
it
(
'
shows inital state after failed request
'
,
()
=>
{
});
});
});
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