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
Jérome Perrin
gitlab-ce
Commits
a2dbdb88
Commit
a2dbdb88
authored
Oct 25, 2016
by
Filipa Lacerda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix tab filtering and counting
parent
9a7fa3b6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
17 deletions
+41
-17
app/assets/javascripts/environments/environments_bundle.js.es6
...ssets/javascripts/environments/environments_bundle.js.es6
+18
-11
app/assets/javascripts/environments/stores/environmnets_store.js.es6
...javascripts/environments/stores/environmnets_store.js.es6
+21
-4
app/views/projects/environments/index.html.haml
app/views/projects/environments/index.html.haml
+2
-2
No files found.
app/assets/javascripts/environments/environments_bundle.js.es6
View file @
a2dbdb88
...
@@ -16,14 +16,21 @@ $(() => {
...
@@ -16,14 +16,21 @@ $(() => {
gl.EnvironmentsListApp.$destroy(true);
gl.EnvironmentsListApp.$destroy(true);
}
}
const filterEnvironments = (environments = [], filter = "") => {
return environments.filter((env) => {
const filterState = (state) => (environment) => environment.state === state && environment;
if (env.children) {
return env.children.filter((child) => child.state === filter).length;
// recursiveMap :: (Function, Array) -> Array
} else {
const recursiveMap = (fn, arr) => {
return env.state === filter;
return arr.map((item) => {
};
if (!item.children) { return fn(item); }
});
const filteredChildren = recursiveMap(fn, item.children).filter(Boolean);
if (filteredChildren.length) {
item.children = filteredChildren;
return item;
}
}).filter(Boolean);
};
};
gl.EnvironmentsListApp = new Vue({
gl.EnvironmentsListApp = new Vue({
...
@@ -43,15 +50,15 @@ $(() => {
...
@@ -43,15 +50,15 @@ $(() => {
computed: {
computed: {
filteredEnvironments () {
filteredEnvironments () {
return
filterEnvironments(this.state.environments, this.visibility
);
return
recursiveMap(filterState(this.visibility), this.state.environments
);
},
},
countStopped () {
countStopped () {
return filterEnvironments(this.state.environments, 'stopped').length;
},
},
countAvailable () {
countAvailable () {
return filterEnvironments(this.state.environments, 'available'
).length;
// return recursiveMap(filterState('available'), this.state.environments
).length;
}
}
},
},
...
...
app/assets/javascripts/environments/stores/environmnets_store.js.es6
View file @
a2dbdb88
...
@@ -7,6 +7,8 @@
...
@@ -7,6 +7,8 @@
create () {
create () {
this.state.environments = [];
this.state.environments = [];
this.state.stoppedCounter = 0;
this.state.availableCounter = 0;
},
},
/**
/**
...
@@ -42,6 +44,10 @@
...
@@ -42,6 +44,10 @@
* @returns {Array} Tree structured array with the received environments.
* @returns {Array} Tree structured array with the received environments.
*/
*/
storeEnvironments(environments = []) {
storeEnvironments(environments = []) {
this.state.stoppedCounter = this.countByState(environments, 'stopped');
this.state.availableCounter = this.countByState(environments, 'available');
const environmentsTree = environments.reduce((acc, environment) => {
const environmentsTree = environments.reduce((acc, environment) => {
if (environment.last_deployment) {
if (environment.last_deployment) {
...
@@ -59,15 +65,14 @@
...
@@ -59,15 +65,14 @@
if (environment.environment_type !== null) {
if (environment.environment_type !== null) {
const occurs = acc.find((element, index, array) => {
const occurs = acc.find((element, index, array) => {
return element.
environment_typ
e === environment.environment_type;
return element.
children && element.nam
e === environment.environment_type;
});
});
environment["vue-isChildren"] = true;
environment["vue-isChildren"] = true;
if (occurs !== undefined) {
if (occurs !== undefined) {
acc[acc.indexOf(occurs)].children.push(environment);
acc[acc.indexOf(occurs)].children.push(environment);
acc[acc.indexOf(occurs)].children.
push(environment).
sort(this.sortByName)
acc[acc.indexOf(occurs)].children.sort(this.sortByName)
} else {
} else {
acc.push({
acc.push({
name: environment.environment_type,
name: environment.environment_type,
...
@@ -88,6 +93,18 @@
...
@@ -88,6 +93,18 @@
return environmentsTree;
return environmentsTree;
},
},
/**
* Given an array of environments, returns the number of environments
* that have the given state.
*
* @param {Array} environments
* @param {String} state
* @returns {Number}
*/
countByState(environments, state) {
return environments.filter((env) => env.state === state).length;
},
/**
/**
* Sorts the two objects provided by their name.
* Sorts the two objects provided by their name.
*
*
...
...
app/views/projects/environments/index.html.haml
View file @
a2dbdb88
...
@@ -12,13 +12,13 @@
...
@@ -12,13 +12,13 @@
=
link_to
project_environments_path
(
@project
)
do
=
link_to
project_environments_path
(
@project
)
do
Available
Available
%span
.badge.js-available-environments-count
%span
.badge.js-available-environments-count
{{
countAvailable
}}
{{
state.availableCounter
}}
%li
{
class:
(
'active'
if
@scope
==
'stopped'
)}
%li
{
class:
(
'active'
if
@scope
==
'stopped'
)}
=
link_to
project_environments_path
(
@project
,
scope: :stopped
)
do
=
link_to
project_environments_path
(
@project
,
scope: :stopped
)
do
Stopped
Stopped
%span
.badge.js-stopped-environments-count
%span
.badge.js-stopped-environments-count
{{
countStopped
}}
{{
state.stoppedCounter
}}
-
if
can?
(
current_user
,
:create_environment
,
@project
)
&&
!
@all_environments
.
blank?
-
if
can?
(
current_user
,
:create_environment
,
@project
)
&&
!
@all_environments
.
blank?
.nav-controls
.nav-controls
...
...
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