environments_table.vue 2.9 KB
Newer Older
1 2 3 4
<script>
/**
 * Render environments table.
 */
C
Clement Ho 已提交
5
import { GlLoadingIcon } from '@gitlab/ui';
F
Filipa Lacerda 已提交
6
import environmentItem from './environment_item.vue';
7 8 9

export default {
  components: {
F
Filipa Lacerda 已提交
10
    environmentItem,
11
    GlLoadingIcon,
12 13 14 15 16 17
  },

  props: {
    environments: {
      type: Array,
      required: true,
18
      default: () => [],
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
    },

    canReadEnvironment: {
      type: Boolean,
      required: false,
      default: false,
    },

    canCreateDeployment: {
      type: Boolean,
      required: false,
      default: false,
    },
  },
  methods: {
    folderUrl(model) {
      return `${window.location.pathname}/folders/${model.folderName}`;
    },
F
Filipa Lacerda 已提交
37
    shouldRenderFolderContent(env) {
38
      return env.isFolder && env.isOpen && env.children && env.children.length > 0;
F
Filipa Lacerda 已提交
39
    },
40 41 42 43
  },
};
</script>
<template>
F
Filipa Lacerda 已提交
44 45 46 47 48 49 50 51 52
  <div
    class="ci-table"
    role="grid"
  >
    <div
      class="gl-responsive-table-row table-row-header"
      role="row"
    >
      <div
53
        class="table-section section-15 environments-name"
F
Filipa Lacerda 已提交
54 55 56
        role="columnheader"
      >
        {{ s__("Environments|Environment") }}
57
      </div>
F
Filipa Lacerda 已提交
58 59 60 61 62
      <div
        class="table-section section-10 environments-deploy"
        role="columnheader"
      >
        {{ s__("Environments|Deployment") }}
63
      </div>
F
Filipa Lacerda 已提交
64 65 66 67 68
      <div
        class="table-section section-15 environments-build"
        role="columnheader"
      >
        {{ s__("Environments|Job") }}
69
      </div>
F
Filipa Lacerda 已提交
70
      <div
71
        class="table-section section-20 environments-commit"
F
Filipa Lacerda 已提交
72 73 74
        role="columnheader"
      >
        {{ s__("Environments|Commit") }}
75
      </div>
F
Filipa Lacerda 已提交
76 77 78 79 80
      <div
        class="table-section section-10 environments-date"
        role="columnheader"
      >
        {{ s__("Environments|Updated") }}
81 82 83
      </div>
    </div>
    <template
F
Filipa Lacerda 已提交
84 85
      v-for="(model, i) in environments"
      :model="model">
86 87
      <div
        is="environment-item"
M
Mike Greiling 已提交
88
        :key="`environment-item-${i}`"
89 90 91
        :model="model"
        :can-create-deployment="canCreateDeployment"
        :can-read-environment="canReadEnvironment"
F
Filipa Lacerda 已提交
92
      />
93

F
Filipa Lacerda 已提交
94
      <template
F
Filipa Lacerda 已提交
95
        v-if="shouldRenderFolderContent(model)"
F
Filipa Lacerda 已提交
96 97 98
      >
        <div
          v-if="model.isLoadingFolderContent"
T
Tim Zallmann 已提交
99
          :key="`loading-item-${i}`">
C
Clement Ho 已提交
100
          <gl-loading-icon :size="2" />
101
        </div>
102

103 104 105
        <template v-else>
          <div
            is="environment-item"
F
Filipa Lacerda 已提交
106
            v-for="(children, index) in model.children"
M
Mike Greiling 已提交
107
            :key="`env-item-${i}-${index}`"
108 109 110
            :model="children"
            :can-create-deployment="canCreateDeployment"
            :can-read-environment="canReadEnvironment"
F
Filipa Lacerda 已提交
111
          />
112

T
Tim Zallmann 已提交
113
          <div :key="`sub-div-${i}`">
114 115 116
            <div class="text-center prepend-top-10">
              <a
                :href="folderUrl(model)"
F
Filipa Lacerda 已提交
117 118 119
                class="btn btn-default"
              >
                {{ s__("Environments|Show all") }}
120 121 122
              </a>
            </div>
          </div>
123 124
        </template>
      </template>
125 126
    </template>
  </div>
127
</template>