BigW Consortium Gitlab

Commit adec9194 by Filipa Lacerda

Adds expandable folder back.

Makes request to get environments
parent f6f56ddd
...@@ -24,6 +24,7 @@ export default Vue.component('environment-component', { ...@@ -24,6 +24,7 @@ export default Vue.component('environment-component', {
state: store.state, state: store.state,
visibility: 'available', visibility: 'available',
isLoading: false, isLoading: false,
isLoadingFolderContent: false,
cssContainerClass: environmentsData.cssClass, cssContainerClass: environmentsData.cssClass,
endpoint: environmentsData.environmentsDataEndpoint, endpoint: environmentsData.environmentsDataEndpoint,
canCreateDeployment: environmentsData.canCreateDeployment, canCreateDeployment: environmentsData.canCreateDeployment,
...@@ -68,15 +69,21 @@ export default Vue.component('environment-component', { ...@@ -68,15 +69,21 @@ export default Vue.component('environment-component', {
this.fetchEnvironments(); this.fetchEnvironments();
eventHub.$on('refreshEnvironments', this.fetchEnvironments); eventHub.$on('refreshEnvironments', this.fetchEnvironments);
eventHub.$on('toggleFolder', this.toggleFolder);
}, },
beforeDestroyed() { beforeDestroyed() {
eventHub.$off('refreshEnvironments'); eventHub.$off('refreshEnvironments');
eventHub.$off('toggleFolder');
}, },
methods: { methods: {
toggleRow(model) { toggleFolder(folder) {
return this.store.toggleFolder(model.name); this.store.toggleFolder(folder);
if (!folder.isOpen) {
this.fetchChildEnvironments(folder);
}
}, },
/** /**
...@@ -117,6 +124,24 @@ export default Vue.component('environment-component', { ...@@ -117,6 +124,24 @@ export default Vue.component('environment-component', {
new Flash('An error occurred while fetching the environments.'); new Flash('An error occurred while fetching the environments.');
}); });
}, },
fetchChildEnvironments(folder) {
this.isLoadingFolderContent = true;
this.service.getFolderContent(folder.folderName)
.then(resp => resp.json())
.then((response) => {
console.log(response);
this.store.folderContent(folder, response.environments);
})
.then(() => {
this.isLoadingFolderContent = false;
})
.catch(() => {
this.isLoadingFolderContent = false;
new Flash('An error occurred while fetching the environments.');
});
},
}, },
template: ` template: `
......
...@@ -6,6 +6,7 @@ import StopComponent from './environment_stop'; ...@@ -6,6 +6,7 @@ import StopComponent from './environment_stop';
import RollbackComponent from './environment_rollback'; import RollbackComponent from './environment_rollback';
import TerminalButtonComponent from './environment_terminal_button'; import TerminalButtonComponent from './environment_terminal_button';
import CommitComponent from '../../vue_shared/components/commit'; import CommitComponent from '../../vue_shared/components/commit';
import eventHub from '../event_hub';
/** /**
* Envrionment Item Component * Envrionment Item Component
...@@ -391,16 +392,6 @@ export default { ...@@ -391,16 +392,6 @@ export default {
return ''; return '';
}, },
/**
* Constructs folder URL based on the current location and the folder id.
*
* @return {String}
*/
folderUrl() {
return `${window.location.pathname}/folders/${this.model.folderName}`;
},
}, },
/** /**
...@@ -418,6 +409,12 @@ export default { ...@@ -418,6 +409,12 @@ export default {
return true; return true;
}, },
methods: {
onClickFolder() {
eventHub.$emit('toggleFolder', this.model);
},
},
template: ` template: `
<tr> <tr>
<td> <td>
...@@ -426,7 +423,21 @@ export default { ...@@ -426,7 +423,21 @@ export default {
:href="environmentPath"> :href="environmentPath">
{{model.name}} {{model.name}}
</a> </a>
<a v-else class="folder-name" :href="folderUrl"> <span v-else
class="folder-name"
@click="onClickFolder">
<span class="folder-icon">
<i
v-show="model.isOpen"
class="fa fa-caret-down"
aria-hidden="true" />
<i
v-show="!model.isOpen"
class="fa fa-caret-right"
aria-hidden="true"/>
</span>
<span class="folder-icon"> <span class="folder-icon">
<i class="fa fa-folder" aria-hidden="true"></i> <i class="fa fa-folder" aria-hidden="true"></i>
</span> </span>
...@@ -438,7 +449,7 @@ export default { ...@@ -438,7 +449,7 @@ export default {
<span class="badge"> <span class="badge">
{{model.size}} {{model.size}}
</span> </span>
</a> </span>
</td> </td>
<td class="deployment-column"> <td class="deployment-column">
......
...@@ -54,11 +54,10 @@ export default { ...@@ -54,11 +54,10 @@ export default {
:can-read-environment="canReadEnvironment" :can-read-environment="canReadEnvironment"
:service="service"></tr> :service="service"></tr>
<tr v-if="model.isOpen && model.children && model.children.length > 0" <tr v-if="model.isFolder && model.isOpen && model.children && model.children.length > 0"
is="environment-item" is="environment-item"
v-for="children in model.children" v-for="children in model.children"
:model="children" :model="children"
:toggleRow="toggleRow.bind(children)"
:can-create-deployment="canCreateDeploymentParsed" :can-create-deployment="canCreateDeploymentParsed"
:can-read-environment="canReadEnvironmentParsed" :can-read-environment="canReadEnvironmentParsed"
:service="service"></tr> :service="service"></tr>
......
...@@ -6,7 +6,14 @@ Vue.use(VueResource); ...@@ -6,7 +6,14 @@ Vue.use(VueResource);
export default class EnvironmentsService { export default class EnvironmentsService {
constructor(endpoint) { constructor(endpoint) {
this.environments = Vue.resource(endpoint); /**
* FIX ME: This should be sent by backend.
*/
const customActions = {
folderContent: { method: 'GET', url: `${window.location.pathname}/folders{/name}?perPage=2` },
};
this.environments = Vue.resource(endpoint, {}, customActions);
} }
get(scope, page) { get(scope, page) {
...@@ -16,4 +23,9 @@ export default class EnvironmentsService { ...@@ -16,4 +23,9 @@ export default class EnvironmentsService {
postAction(endpoint) { postAction(endpoint) {
return Vue.http.post(endpoint, {}, { emulateJSON: true }); return Vue.http.post(endpoint, {}, { emulateJSON: true });
} }
getFolderContent(folderName) {
debugger
return this.environments.folderContent({ name: folderName });
}
} }
...@@ -38,7 +38,12 @@ export default class EnvironmentsStore { ...@@ -38,7 +38,12 @@ export default class EnvironmentsStore {
let filtered = {}; let filtered = {};
if (env.size > 1) { if (env.size > 1) {
filtered = Object.assign({}, env, { isFolder: true, folderName: env.name }); filtered = Object.assign({}, env, {
isFolder: true,
folderName: env.name,
isOpen: false,
children: [],
});
} }
if (env.latest) { if (env.latest) {
...@@ -86,7 +91,36 @@ export default class EnvironmentsStore { ...@@ -86,7 +91,36 @@ export default class EnvironmentsStore {
return count; return count;
} }
toggleRow(name) { /**
* Toggles folder open property given the given folder.
*
* @param {String} envType
* @return {Array}
*/
toggleFolder(folder) {
return this.updateFolder(folder, 'isOpen', !folder.isOpen);
}
folderContent(folder, environments) {
debugger;
return this.updateFolder(folder, 'children', environments);
} }
updateFolder(folder, prop, newValue) {
const environments = this.state.environments;
debugger;
const updatedEnvironments = environments.map((env) => {
const updateEnv = Object.assign({}, env);
if (env.isFolder && env.id === folder.id) {
updateEnv[prop] = newValue;
}
return updateEnv;
});
debugger;
console.log(updatedEnvironments);
this.state.environments = updatedEnvironments;
}
} }
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