summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/registry/components/table_registry.vue
blob: e4a4b3bb1294a3b7b85f4297517acffb1e4635ff (plain)
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<script>
  import { mapActions } from 'vuex';
  import { n__ } from '../../locale';
  import Flash from '../../flash';
  import clipboardButton from '../../vue_shared/components/clipboard_button.vue';
  import tablePagination from '../../vue_shared/components/table_pagination.vue';
  import tooltip from '../../vue_shared/directives/tooltip';
  import timeagoMixin from '../../vue_shared/mixins/timeago';
  import { errorMessages, errorMessagesTypes } from '../constants';
  import { numberToHumanSize } from '../../lib/utils/number_utils';

  export default {
    components: {
      clipboardButton,
      tablePagination,
    },
    directives: {
      tooltip,
    },
    mixins: [
      timeagoMixin,
    ],
    props: {
      repo: {
        type: Object,
        required: true,
      },
    },
    computed: {
      shouldRenderPagination() {
        return this.repo.pagination.total > this.repo.pagination.perPage;
      },
    },
    methods: {
      ...mapActions([
        'fetchList',
        'deleteRegistry',
      ]),

      layers(item) {
        return item.layers ? n__('%d layer', '%d layers', item.layers) : '';
      },

      formatSize(size) {
        return numberToHumanSize(size);
      },

      handleDeleteRegistry(registry) {
        this.deleteRegistry(registry)
          .then(() => this.fetchList({ repo: this.repo }))
          .catch(() => this.showError(errorMessagesTypes.DELETE_REGISTRY));
      },

      onPageChange(pageNumber) {
        this.fetchList({ repo: this.repo, page: pageNumber })
          .catch(() => this.showError(errorMessagesTypes.FETCH_REGISTRY));
      },

      showError(message) {
        Flash(errorMessages[message]);
      },
    },
  };
</script>
<template>
  <div>
    <table class="table tags">
      <thead>
        <tr>
          <th>{{ s__('ContainerRegistry|Tag') }}</th>
          <th>{{ s__('ContainerRegistry|Tag ID') }}</th>
          <th>{{ s__("ContainerRegistry|Size") }}</th>
          <th>{{ s__("ContainerRegistry|Created") }}</th>
          <th></th>
        </tr>
      </thead>
      <tbody>
        <tr
          v-for="(item, i) in repo.list"
          :key="i">
          <td>

            {{ item.tag }}

            <clipboard-button
              v-if="item.location"
              :title="item.location"
              :text="item.location"
              css-class="btn-default btn-transparent btn-clipboard"
            />
          </td>
          <td>
            <span
              v-tooltip
              :title="item.revision"
              data-placement="bottom"
            >
              {{ item.shortRevision }}
            </span>
          </td>
          <td>
            {{ formatSize(item.size) }}
            <template v-if="item.size && item.layers">
              &middot;
            </template>
            {{ layers(item) }}
          </td>

          <td>
            <span
              v-tooltip
              :title="tooltipTitle(item.createdAt)"
              data-placement="bottom"
            >
              {{ timeFormated(item.createdAt) }}
            </span>
          </td>

          <td class="content">
            <button
              v-if="item.canDelete"
              type="button"
              class="js-delete-registry btn btn-danger d-none d-sm-block float-right"
              :title="s__('ContainerRegistry|Remove tag')"
              :aria-label="s__('ContainerRegistry|Remove tag')"
              data-container="body"
              v-tooltip
              @click="handleDeleteRegistry(item)"
            >
              <i
                class="fa fa-trash"
                aria-hidden="true"
              >
              </i>
            </button>
          </td>
        </tr>
      </tbody>
    </table>

    <table-pagination
      v-if="shouldRenderPagination"
      :change="onPageChange"
      :page-info="repo.pagination"
    />
  </div>
</template>