2018-03-17 18:26:18 +05:30
|
|
|
<script>
|
2021-01-03 14:25:43 +05:30
|
|
|
import { GlBadge, GlButton, GlModalDirective, GlTab, GlTabs } from '@gitlab/ui';
|
2020-10-24 23:57:45 +05:30
|
|
|
import { deprecatedCreateFlash as Flash } from '~/flash';
|
2020-03-13 15:44:24 +05:30
|
|
|
import { s__ } from '~/locale';
|
2018-12-13 13:39:08 +05:30
|
|
|
import eventHub from '../event_hub';
|
|
|
|
import environmentsMixin from '../mixins/environments_mixin';
|
2021-03-11 19:13:27 +05:30
|
|
|
import EnvironmentsPaginationApiMixin from '../mixins/environments_pagination_api_mixin';
|
|
|
|
import ConfirmRollbackModal from './confirm_rollback_modal.vue';
|
|
|
|
import DeleteEnvironmentModal from './delete_environment_modal.vue';
|
|
|
|
import emptyState from './empty_state.vue';
|
2021-01-03 14:25:43 +05:30
|
|
|
import EnableReviewAppModal from './enable_review_app_modal.vue';
|
2018-12-13 13:39:08 +05:30
|
|
|
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 {
|
2021-01-03 14:25:43 +05:30
|
|
|
i18n: {
|
|
|
|
newEnvironmentButtonLabel: s__('Environments|New environment'),
|
|
|
|
reviewAppButtonLabel: s__('Environments|Enable review app'),
|
|
|
|
},
|
|
|
|
modal: {
|
|
|
|
id: 'enable-review-app-info',
|
|
|
|
},
|
2018-12-13 13:39:08 +05:30
|
|
|
components: {
|
2020-03-13 15:44:24 +05:30
|
|
|
ConfirmRollbackModal,
|
2018-12-13 13:39:08 +05:30
|
|
|
emptyState,
|
2021-01-03 14:25:43 +05:30
|
|
|
EnableReviewAppModal,
|
|
|
|
GlBadge,
|
|
|
|
GlButton,
|
|
|
|
GlTab,
|
|
|
|
GlTabs,
|
2018-12-13 13:39:08 +05:30
|
|
|
StopEnvironmentModal,
|
2020-04-22 19:07:51 +05:30
|
|
|
DeleteEnvironmentModal,
|
2018-12-13 13:39:08 +05:30
|
|
|
},
|
2021-01-03 14:25:43 +05:30
|
|
|
directives: {
|
|
|
|
'gl-modal': GlModalDirective,
|
|
|
|
},
|
2021-03-11 19:13:27 +05:30
|
|
|
mixins: [EnvironmentsPaginationApiMixin, environmentsMixin],
|
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
|
|
|
canReadEnvironment: {
|
|
|
|
type: Boolean,
|
|
|
|
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);
|
2020-05-24 23:13:21 +05:30
|
|
|
eventHub.$on('toggleDeployBoard', this.toggleDeployBoard);
|
2018-12-13 13:39:08 +05:30
|
|
|
},
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
beforeDestroy() {
|
2021-02-22 17:27:13 +05:30
|
|
|
// eslint-disable-next-line @gitlab/no-global-event-off
|
2018-12-13 13:39:08 +05:30
|
|
|
eventHub.$off('toggleFolder');
|
2021-02-22 17:27:13 +05:30
|
|
|
// eslint-disable-next-line @gitlab/no-global-event-off
|
2020-05-24 23:13:21 +05:30
|
|
|
eventHub.$off('toggleDeployBoard');
|
2018-12-13 13:39:08 +05:30
|
|
|
},
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
methods: {
|
2020-05-24 23:13:21 +05:30
|
|
|
toggleDeployBoard(model) {
|
|
|
|
this.store.toggleDeployBoard(model.id);
|
|
|
|
},
|
2018-12-13 13:39:08 +05:30
|
|
|
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
|
2021-04-17 20:07:23 +05:30
|
|
|
.getFolderContent(folder.folder_path, folder.state)
|
2021-03-08 18:12:59 +05:30
|
|
|
.then((response) => this.store.setfolderContent(folder, response.data.environments))
|
2018-12-13 13:39:08 +05:30
|
|
|
.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) {
|
2021-03-08 18:12:59 +05:30
|
|
|
openFolders.forEach((folder) => this.fetchChildEnvironments(folder));
|
2018-12-13 13:39:08 +05:30
|
|
|
}
|
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>
|
2021-01-03 14:25:43 +05:30
|
|
|
<div class="environments-section">
|
2018-11-18 11:00:15 +05:30
|
|
|
<stop-environment-modal :environment="environmentInStopModal" />
|
2020-04-22 19:07:51 +05:30
|
|
|
<delete-environment-modal :environment="environmentInDeleteModal" />
|
2019-07-07 11:18:12 +05:30
|
|
|
<confirm-rollback-modal :environment="environmentInRollbackModal" />
|
2018-11-18 11:00:15 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
<div class="gl-w-full">
|
2021-03-11 19:13:27 +05:30
|
|
|
<div class="gl-display-flex gl-flex-direction-column gl-mt-3 gl-md-display-none!">
|
2021-01-03 14:25:43 +05:30
|
|
|
<gl-button
|
|
|
|
v-if="state.reviewAppDetails.can_setup_review_app"
|
|
|
|
v-gl-modal="$options.modal.id"
|
|
|
|
data-testid="enable-review-app"
|
|
|
|
variant="info"
|
|
|
|
category="secondary"
|
|
|
|
type="button"
|
|
|
|
class="gl-mb-3 gl-flex-fill-1"
|
2021-02-22 17:27:13 +05:30
|
|
|
>{{ $options.i18n.reviewAppButtonLabel }}</gl-button
|
2021-01-03 14:25:43 +05:30
|
|
|
>
|
|
|
|
<gl-button
|
|
|
|
v-if="canCreateEnvironment"
|
2020-03-13 15:44:24 +05:30
|
|
|
:href="newEnvironmentPath"
|
2021-01-03 14:25:43 +05:30
|
|
|
data-testid="new-environment"
|
2020-03-13 15:44:24 +05:30
|
|
|
category="primary"
|
2021-04-17 20:07:23 +05:30
|
|
|
variant="confirm"
|
2021-02-22 17:27:13 +05:30
|
|
|
>{{ $options.i18n.newEnvironmentButtonLabel }}</gl-button
|
2020-03-13 15:44:24 +05:30
|
|
|
>
|
2018-03-17 18:26:18 +05:30
|
|
|
</div>
|
2021-01-03 14:25:43 +05:30
|
|
|
<gl-tabs content-class="gl-display-none">
|
|
|
|
<gl-tab
|
|
|
|
v-for="(tab, idx) in tabs"
|
|
|
|
:key="idx"
|
|
|
|
:title-item-class="`js-environments-tab-${tab.scope}`"
|
|
|
|
@click="onChangeTab(tab.scope)"
|
|
|
|
>
|
|
|
|
<template #title>
|
|
|
|
<span>{{ tab.name }}</span>
|
|
|
|
<gl-badge size="sm" class="gl-tab-counter-badge">{{ tab.count }}</gl-badge>
|
|
|
|
</template>
|
|
|
|
</gl-tab>
|
|
|
|
<template #tabs-end>
|
|
|
|
<div
|
2021-03-11 19:13:27 +05:30
|
|
|
class="gl-display-none gl-md-display-flex gl-lg-align-items-center gl-lg-flex-direction-row gl-lg-flex-fill-1 gl-lg-justify-content-end gl-lg-mt-0"
|
2021-01-03 14:25:43 +05:30
|
|
|
>
|
|
|
|
<gl-button
|
|
|
|
v-if="state.reviewAppDetails.can_setup_review_app"
|
|
|
|
v-gl-modal="$options.modal.id"
|
|
|
|
data-testid="enable-review-app"
|
|
|
|
variant="info"
|
|
|
|
category="secondary"
|
|
|
|
type="button"
|
|
|
|
class="gl-mb-3 gl-lg-mr-3 gl-lg-mb-0"
|
2021-02-22 17:27:13 +05:30
|
|
|
>{{ $options.i18n.reviewAppButtonLabel }}</gl-button
|
2021-01-03 14:25:43 +05:30
|
|
|
>
|
|
|
|
<gl-button
|
|
|
|
v-if="canCreateEnvironment"
|
|
|
|
:href="newEnvironmentPath"
|
|
|
|
data-testid="new-environment"
|
|
|
|
category="primary"
|
2021-04-17 20:07:23 +05:30
|
|
|
variant="confirm"
|
2021-02-22 17:27:13 +05:30
|
|
|
>{{ $options.i18n.newEnvironmentButtonLabel }}</gl-button
|
2021-01-03 14:25:43 +05:30
|
|
|
>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</gl-tabs>
|
|
|
|
<container
|
|
|
|
:is-loading="isLoading"
|
|
|
|
:environments="state.environments"
|
|
|
|
:pagination="state.paginationInformation"
|
|
|
|
:can-read-environment="canReadEnvironment"
|
|
|
|
@onChangePage="onChangePage"
|
|
|
|
>
|
2021-01-29 00:20:46 +05:30
|
|
|
<template v-if="!isLoading && state.environments.length === 0" #empty-state>
|
2021-01-03 14:25:43 +05:30
|
|
|
<empty-state :help-path="helpPagePath" />
|
|
|
|
</template>
|
|
|
|
</container>
|
|
|
|
<enable-review-app-modal
|
|
|
|
v-if="state.reviewAppDetails.can_setup_review_app"
|
|
|
|
:modal-id="$options.modal.id"
|
|
|
|
data-testid="enable-review-app-modal"
|
|
|
|
/>
|
2018-03-17 18:26:18 +05:30
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|