2018-03-17 18:26:18 +05:30
|
|
|
<script>
|
2018-12-13 13:39:08 +05:30
|
|
|
import Flash from '../../flash';
|
|
|
|
import { s__ } from '../../locale';
|
|
|
|
import emptyState from './empty_state.vue';
|
|
|
|
import eventHub from '../event_hub';
|
|
|
|
import environmentsMixin from '../mixins/environments_mixin';
|
|
|
|
import CIPaginationMixin from '../../vue_shared/mixins/ci_pagination_api_mixin';
|
|
|
|
import StopEnvironmentModal from './stop_environment_modal.vue';
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
emptyState,
|
|
|
|
StopEnvironmentModal,
|
|
|
|
},
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
mixins: [CIPaginationMixin, environmentsMixin],
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
props: {
|
|
|
|
endpoint: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
2018-03-17 18:26:18 +05:30
|
|
|
},
|
2018-12-13 13:39:08 +05:30
|
|
|
canCreateEnvironment: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true,
|
2018-03-17 18:26:18 +05:30
|
|
|
},
|
2018-12-13 13:39:08 +05:30
|
|
|
canCreateDeployment: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
canReadEnvironment: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
cssContainerClass: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
newEnvironmentPath: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
2018-03-17 18:26:18 +05:30
|
|
|
},
|
2018-12-13 13:39:08 +05:30
|
|
|
helpPagePath: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
created() {
|
|
|
|
eventHub.$on('toggleFolder', this.toggleFolder);
|
|
|
|
},
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
beforeDestroy() {
|
|
|
|
eventHub.$off('toggleFolder');
|
|
|
|
},
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
methods: {
|
|
|
|
toggleFolder(folder) {
|
|
|
|
this.store.toggleFolder(folder);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
if (!folder.isOpen) {
|
|
|
|
this.fetchChildEnvironments(folder, true);
|
|
|
|
}
|
|
|
|
},
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
fetchChildEnvironments(folder, showLoader = false) {
|
|
|
|
this.store.updateEnvironmentProp(folder, 'isLoadingFolderContent', showLoader);
|
|
|
|
|
|
|
|
this.service
|
|
|
|
.getFolderContent(folder.folder_path)
|
|
|
|
.then(response => this.store.setfolderContent(folder, response.data.environments))
|
|
|
|
.then(() => this.store.updateEnvironmentProp(folder, 'isLoadingFolderContent', false))
|
|
|
|
.catch(() => {
|
|
|
|
Flash(s__('Environments|An error occurred while fetching the environments.'));
|
|
|
|
this.store.updateEnvironmentProp(folder, 'isLoadingFolderContent', false);
|
|
|
|
});
|
|
|
|
},
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
successCallback(resp) {
|
|
|
|
this.saveData(resp);
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
// We need to verify if any folder is open to also update it
|
|
|
|
const openFolders = this.store.getOpenFolders();
|
|
|
|
if (openFolders.length) {
|
|
|
|
openFolders.forEach(folder => this.fetchChildEnvironments(folder));
|
|
|
|
}
|
2018-03-17 18:26:18 +05:30
|
|
|
},
|
2018-12-13 13:39:08 +05:30
|
|
|
},
|
|
|
|
};
|
2018-03-17 18:26:18 +05:30
|
|
|
</script>
|
|
|
|
<template>
|
|
|
|
<div :class="cssContainerClass">
|
2018-11-18 11:00:15 +05:30
|
|
|
<stop-environment-modal :environment="environmentInStopModal" />
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
<div class="top-area">
|
|
|
|
<tabs
|
|
|
|
:tabs="tabs"
|
|
|
|
scope="environments"
|
2018-11-08 19:23:39 +05:30
|
|
|
@onChangeTab="onChangeTab"
|
2018-03-17 18:26:18 +05:30
|
|
|
/>
|
|
|
|
|
|
|
|
<div
|
|
|
|
v-if="canCreateEnvironment && !isLoading"
|
|
|
|
class="nav-controls"
|
|
|
|
>
|
|
|
|
<a
|
|
|
|
:href="newEnvironmentPath"
|
2018-12-05 23:21:45 +05:30
|
|
|
class="btn btn-success"
|
2018-03-17 18:26:18 +05:30
|
|
|
>
|
|
|
|
{{ s__("Environments|New environment") }}
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<container
|
|
|
|
:is-loading="isLoading"
|
|
|
|
:environments="state.environments"
|
|
|
|
:pagination="state.paginationInformation"
|
|
|
|
:can-create-deployment="canCreateDeployment"
|
|
|
|
:can-read-environment="canReadEnvironment"
|
|
|
|
@onChangePage="onChangePage"
|
|
|
|
>
|
|
|
|
<empty-state
|
|
|
|
v-if="!isLoading && state.environments.length === 0"
|
2018-11-08 19:23:39 +05:30
|
|
|
slot="emptyState"
|
2018-03-17 18:26:18 +05:30
|
|
|
:new-path="newEnvironmentPath"
|
|
|
|
:help-path="helpPagePath"
|
|
|
|
:can-create-environment="canCreateEnvironment"
|
|
|
|
/>
|
|
|
|
</container>
|
|
|
|
</div>
|
|
|
|
</template>
|