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
Tatuya Kamada
gitlab-ce
Commits
52c4f8ef
Commit
52c4f8ef
authored
Oct 14, 2016
by
Filipa Lacerda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Stores environmnets in tree
parent
2c0f97cd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
8 deletions
+47
-8
app/assets/javascripts/environments/environments_bundle.js.es6
...ssets/javascripts/environments/environments_bundle.js.es6
+1
-1
app/assets/javascripts/environments/stores/environmnets_store.js.es6
...javascripts/environments/stores/environmnets_store.js.es6
+46
-7
No files found.
app/assets/javascripts/environments/environments_bundle.js.es6
View file @
52c4f8ef
...
...
@@ -40,7 +40,7 @@ $(() => {
*/
ready() {
gl.environmentsService.all().then((resp) => {
Store.
add
Environments(resp.json());
Store.
store
Environments(resp.json());
this.loading = false;
});
...
...
app/assets/javascripts/environments/stores/environmnets_store.js.es6
View file @
52c4f8ef
...
...
@@ -3,19 +3,58 @@
window.gl.environmentsList = window.gl.environmentsList || {};
gl.environmentsList.EnvironmentsStore = {
state: {},
create () {
this.state.environments = [];
},
/**
* Stores the received environmnets.
* In order to display a tree view we need to modify the received
* data in to a tree structure based on `environment_type`
* sorted alphabetically.
*
* @example
* it will transform this:
* [
* { name: "environment", environment_type: "review" },
* { name: "environment_1", environment_type: null }
* { name: "environment_2, environment_type: "review" }
* ]
* into this:
* [
* { name: "review", children:
* [
* { name: "environment", environment_type: "review"},
* { name: "environment_2", environment_type: "review"}
* ]
* },
* {name: "environment_1", environment_type: null}
* ]
* @param {Array} environments List of environments
* @return {type}
*/
addEnvironments(environments) {
console.log(environments);
}
*/
storeEnvironments(environments) {
this.state.environments = environments.reduce((acc, environment) => {
if (environment.environment_type !== null) {
const occurs = acc.find((element, index, array) => {
return element.name === environment.environment_type;
});
if (occurs !== undefined) {
acc[acc.indexOf(occurs)].children.push(environment);
acc[acc.indexOf(occurs)].children.sort();
} else {
acc.push({
name: environment.environment_type,
children: [environment]
});
}
} else {
acc.push(environment);
}
return acc;
}, []).sort();
}
}
})();
\ No newline at end of file
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