BigW Consortium Gitlab

environments_app.vue 3.29 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
<script>
  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';

  export default {
    props: {
      endpoint: {
        type: String,
        required: true,
      },
      canCreateEnvironment: {
        type: Boolean,
        required: true,
      },
      canCreateDeployment: {
        type: Boolean,
        required: true,
      },
      canReadEnvironment: {
        type: Boolean,
        required: true,
      },
      cssContainerClass: {
        type: String,
        required: true,
      },
      newEnvironmentPath: {
        type: String,
        required: true,
      },
      helpPagePath: {
        type: String,
        required: true,
      },
    },
    components: {
      emptyState,
    },

    mixins: [
      CIPaginationMixin,
      environmentsMixin,
    ],

    created() {
      eventHub.$on('toggleFolder', this.toggleFolder);
    },

    beforeDestroy() {
      eventHub.$off('toggleFolder');
    },

    methods: {
      toggleFolder(folder) {
        this.store.toggleFolder(folder);

        if (!folder.isOpen) {
          this.fetchChildEnvironments(folder, true);
        }
      },

      fetchChildEnvironments(folder, showLoader = false) {
        this.store.updateEnvironmentProp(folder, 'isLoadingFolderContent', showLoader);

        this.service.getFolderContent(folder.folder_path)
          .then(resp => resp.json())
          .then(response => this.store.setfolderContent(folder, response.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);
          });
      },

      successCallback(resp) {
        this.saveData(resp);

        // 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));
        }
      },
    },
  };
</script>
<template>
  <div :class="cssContainerClass">
    <div class="top-area">
      <tabs
        :tabs="tabs"
        @onChangeTab="onChangeTab"
        scope="environments"
        />

      <div
        v-if="canCreateEnvironment && !isLoading"
        class="nav-controls">
        <a
          :href="newEnvironmentPath"
          class="btn btn-create">
          {{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
        slot="emptyState"
        v-if="!isLoading && state.environments.length === 0"
        :new-path="newEnvironmentPath"
        :help-path="helpPagePath"
        :can-create-environment="canCreateEnvironment"
        />
    </container>
  </div>
</template>