Commit 09c45429 authored by Filipa Lacerda's avatar Filipa Lacerda

Refactor to work with vue 2 with just one root element

parent a7a13ed3
...@@ -81,7 +81,9 @@ $(() => { ...@@ -81,7 +81,9 @@ $(() => {
* Toggles loading property. * Toggles loading property.
*/ */
mounted() { mounted() {
window.gl.environmentsService.all().then(resp => resp.json()).then((json) => { window.gl.environmentsService.all()
.then(resp => resp.json())
.then((json) => {
this.store.storeEnvironments(json); this.store.storeEnvironments(json);
this.loading = false; this.loading = false;
}); });
...@@ -114,20 +116,30 @@ $(() => { ...@@ -114,20 +116,30 @@ $(() => {
return false; return false;
}, },
methods: {
toggleRow(model) {
return this.store.toggleFolder(model.name);
},
},
template: ` template: `
<div> <div class="container-fluid container-limited">
<div class="top-area"> <div class="top-area">
<ul v-if="!isLoading" class="nav-links"> <ul v-if="!isLoading" class="nav-links">
<li v-bind:class="{ 'active': scope === undefined}"> <li v-bind:class="{ 'active': scope === undefined}">
<a :href="projectEnvironmentsPath"> <a :href="projectEnvironmentsPath">
Available Available
<span class="badge js-available-environments-count" v-html="state.availableCounter"></span> <span
class="badge js-available-environments-count"
v-html="state.availableCounter"></span>
</a> </a>
</li> </li>
<li v-bind:class="{ 'active': scope === 'stopped'}"> <li v-bind:class="{ 'active' : scope === 'stopped'}">
<a :href="projectStoppedEnvironmentsPath"> <a :href="projectStoppedEnvironmentsPath">
Stopped Stopped
<span class="badge js-stopped-environments-count" v-html="state.stoppedCounter"></span> <span
class="badge js-stopped-environments-count"
v-html="state.stoppedCounter"></span>
</a> </a>
</li> </li>
</ul> </ul>
...@@ -143,7 +155,9 @@ $(() => { ...@@ -143,7 +155,9 @@ $(() => {
<i class="fa fa-spinner spin"></i> <i class="fa fa-spinner spin"></i>
</div> </div>
<div class="blank-state blank-state-no-icon" v-if="!loading && state.environments.length === 0"> <div
class="blank-state blank-state-no-icon"
v-if="!loading && state.environments.length === 0">
<h2 class="blank-state-title"> <h2 class="blank-state-title">
You don't have any environments right now. You don't have any environments right now.
</h2> </h2>
...@@ -155,28 +169,48 @@ $(() => { ...@@ -155,28 +169,48 @@ $(() => {
<a :href="helpPagePath"> <a :href="helpPagePath">
Read more about environments Read more about environments
</a> </a>
<a v-if="canCreateEnvironment" :href="newEnvironmentPath" class="btn btn-create"> <a
v-if="canCreateEnvironment"
:href="newEnvironmentPath"
class="btn btn-create">
New Environment New Environment
</a> </a>
</p> </p>
</div> </div>
<div class="table-holder" v-if="!loading && state.environments.length > 0"> <div
class="table-holder"
v-if="!loading && state.environments.length > 0">
<table class="table ci-table environments"> <table class="table ci-table environments">
<thead> <thead>
<tr>
<th>Environment</th> <th>Environment</th>
<th>Last deployment</th> <th>Last deployment</th>
<th>Build</th> <th>Build</th>
<th>Commit</th> <th>Commit</th>
<th></th> <th></th>
<th class="hidden-xs"></th> <th class="hidden-xs"></th>
</tr>
</thead> </thead>
<tbody> <tbody>
<tr is="environment-item" <template v-for="model in filteredEnvironments"
v-for="model in filteredEnvironments" v-bind:model="model">
<tr
is="environment-item"
:model="model" :model="model"
:toggleRow="toggleRow.bind(model)"
:can-create-deployment="canCreateDeploymentParsed" :can-create-deployment="canCreateDeploymentParsed"
:can-read-environment="canReadEnvironmentParsed"></tr> :can-read-environment="canReadEnvironmentParsed"></tr>
<tr v-if="model.isOpen && model.children && model.children.length > 0"
is="environment-item"
v-for="children in model.children"
:model="children"
:toggleRow="toggleRow.bind(children)">
</tr>
</template>
</tbody> </tbody>
</table> </table>
</div> </div>
......
...@@ -31,11 +31,10 @@ ...@@ -31,11 +31,10 @@
'rollback-component': window.gl.environmentsList.RollbackComponent, 'rollback-component': window.gl.environmentsList.RollbackComponent,
}, },
props: ['model', 'can-create-deployment', 'can-read-environment'], props: ['model', 'toggleRow', 'can-create-deployment', 'can-read-environment'],
data() { data() {
return { return {
open: false,
rowClass: { rowClass: {
'children-row': this.model['vue-isChildren'], 'children-row': this.model['vue-isChildren'],
}, },
...@@ -282,30 +281,19 @@ ...@@ -282,30 +281,19 @@
return {}.hasOwnProperty.call(obj, key); return {}.hasOwnProperty.call(obj, key);
}, },
methods: {
/**
* Toggles the visibility of a folders' children.
*/
toggle() {
if (this.isFolder) {
this.open = !this.open;
}
},
},
template: ` template: `
<tr> <tr>
<td v-bind:class="{ 'children-row': isChildren}" class="col-sm-2"> <td v-bind:class="{ 'children-row': isChildren}">
<a <a
v-if="!isFolder" v-if="!isFolder"
class="environment-name" class="environment-name"
:href="model.environment_url" :href="model.environment_url"
v-html="model.name"> v-html="model.name">
</a> </a>
<span v-else v-on:click="toggle" class="folder-name"> <span v-else v-on:click="toggleRow(model)" class="folder-name">
<span class="folder-icon"> <span class="folder-icon">
<i v-show="open" class="fa fa-caret-down"></i> <i v-show="model.isOpen" class="fa fa-caret-down"></i>
<i v-show="!open" class="fa fa-caret-right"></i> <i v-show="!model.isOpen" class="fa fa-caret-right"></i>
</span> </span>
<span v-html="model.name"></span> <span v-html="model.name"></span>
...@@ -314,7 +302,7 @@ ...@@ -314,7 +302,7 @@
</span> </span>
</td> </td>
<td class="deployment-column col-sm-2"> <td class="deployment-column">
<span v-if="!isFolder && model.last_deployment && model.last_deployment.iid" v-html="deploymentInternalId"> <span v-if="!isFolder && model.last_deployment && model.last_deployment.iid" v-html="deploymentInternalId">
<span v-if="model.last_deployment.user"> <span v-if="model.last_deployment.user">
...@@ -329,7 +317,7 @@ ...@@ -329,7 +317,7 @@
</span> </span>
</td> </td>
<td class="col-sm-2"> <td>
<a v-if="!isFolder && model.last_deployment && model.last_deployment.deployable" <a v-if="!isFolder && model.last_deployment && model.last_deployment.deployable"
class="build-link" class="build-link"
:href="model.last_deployment.deployable.build_url" :href="model.last_deployment.deployable.build_url"
...@@ -337,7 +325,7 @@ ...@@ -337,7 +325,7 @@
</a> </a>
</td> </td>
<td class="col-sm-2"> <td>
<div v-if="!isFolder && model.last_deployment"> <div v-if="!isFolder && model.last_deployment">
<commit-component <commit-component
:tag="commitTag" :tag="commitTag"
...@@ -353,7 +341,7 @@ ...@@ -353,7 +341,7 @@
</p> </p>
</td> </td>
<td class="col-sm-1"> <td>
<span <span
v-if="!isFolder && model.last_deployment" v-if="!isFolder && model.last_deployment"
class="environment-created-date-timeago" class="environment-created-date-timeago"
...@@ -361,7 +349,7 @@ ...@@ -361,7 +349,7 @@
</span> </span>
</td> </td>
<td class="hidden-xs col-sm-3"> <td class="hidden-xs">
<div v-if="!isFolder"> <div v-if="!isFolder">
<div v-if="hasManualActions && canCreateDeployment" class="inline"> <div v-if="hasManualActions && canCreateDeployment" class="inline">
<actions-component <actions-component
...@@ -390,12 +378,6 @@ ...@@ -390,12 +378,6 @@
</div> </div>
</td> </td>
</tr> </tr>
<tr v-if="open && isFolder"
is="environment-item"
v-for="model in model.children"
:model="model">
</tr>
`, `,
}); });
})(); })();
...@@ -64,6 +64,8 @@ ...@@ -64,6 +64,8 @@
acc.push({ acc.push({
name: environment.environment_type, name: environment.environment_type,
children: [environment], children: [environment],
isOpen: false,
'vue-isChildren': environment['vue-isChildren'],
}); });
} }
} else { } else {
...@@ -78,6 +80,28 @@ ...@@ -78,6 +80,28 @@
return environmentsTree; return environmentsTree;
}, },
/**
* Toggles folder open property given the environment type.
*
* @param {String} envType
* @return {Array}
*/
toggleFolder(envType) {
const environments = this.state.environments;
const environmnetsCopy = environments.map((env) => {
if (env['vue-isChildren'] === true && env.name === envType) {
env.isOpen = !env.isOpen;
}
return env;
});
this.state.environments = environmnetsCopy;
return environmnetsCopy;
},
/** /**
* Given an array of environments, returns the number of environments * Given an array of environments, returns the number of environments
* that have the given state. * that have the given state.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment