summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/registry/explorer/pages/list.vue
blob: c6ba06cd68c45b97cc0dfd6881cdc53d55dac436 (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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<script>
import { mapState, mapActions } from 'vuex';
import {
  GlEmptyState,
  GlPagination,
  GlTooltipDirective,
  GlButton,
  GlIcon,
  GlModal,
  GlSprintf,
  GlLink,
  GlSkeletonLoader,
} from '@gitlab/ui';
import Tracking from '~/tracking';
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
import ProjectEmptyState from '../components/project_empty_state.vue';
import GroupEmptyState from '../components/group_empty_state.vue';
import ProjectPolicyAlert from '../components/project_policy_alert.vue';

export default {
  name: 'RegistryListApp',
  components: {
    GlEmptyState,
    GlPagination,
    ProjectEmptyState,
    GroupEmptyState,
    ProjectPolicyAlert,
    ClipboardButton,
    GlButton,
    GlIcon,
    GlModal,
    GlSprintf,
    GlLink,
    GlSkeletonLoader,
  },
  directives: {
    GlTooltip: GlTooltipDirective,
  },
  mixins: [Tracking.mixin()],
  loader: {
    repeat: 10,
    width: 1000,
    height: 40,
  },
  data() {
    return {
      itemToDelete: {},
    };
  },
  computed: {
    ...mapState(['config', 'isLoading', 'images', 'pagination']),
    tracking() {
      return {
        label: 'registry_repository_delete',
      };
    },
    currentPage: {
      get() {
        return this.pagination.page;
      },
      set(page) {
        this.requestImagesList({ page });
      },
    },
  },
  methods: {
    ...mapActions(['requestImagesList', 'requestDeleteImage']),
    deleteImage(item) {
      // This event is already tracked in the system and so the name must be kept to aggregate the data
      this.track('click_button');
      this.itemToDelete = item;
      this.$refs.deleteModal.show();
    },
    handleDeleteRepository() {
      this.track('confirm_delete');
      this.requestDeleteImage(this.itemToDelete.destroy_path);
      this.itemToDelete = {};
    },
    encodeListItem(item) {
      const params = JSON.stringify({ name: item.path, tags_path: item.tags_path, id: item.id });
      return window.btoa(params);
    },
  },
};
</script>

<template>
  <div class="w-100 slide-enter-from-element">
    <project-policy-alert v-if="!config.isGroupPage" />

    <gl-empty-state
      v-if="config.characterError"
      :title="s__('ContainerRegistry|Docker connection error')"
      :svg-path="config.containersErrorImage"
    >
      <template #description>
        <p>
          <gl-sprintf
            :message="
              s__(`ContainerRegistry|We are having trouble connecting to Docker, which could be due to an
            issue with your project name or path.
            %{docLinkStart}More Information%{docLinkEnd}`)
            "
          >
            <template #docLink="{content}">
              <gl-link :href="`${config.helpPagePath}#docker-connection-error`" target="_blank">
                {{ content }}
              </gl-link>
            </template>
          </gl-sprintf>
        </p>
      </template>
    </gl-empty-state>

    <template v-else>
      <div>
        <h4>{{ s__('ContainerRegistry|Container Registry') }}</h4>
        <p>
          <gl-sprintf
            :message="
              s__(`ContainerRegistry|With the Docker Container Registry integrated into GitLab, every
            project can have its own space to store its Docker images.
            %{docLinkStart}More Information%{docLinkEnd}`)
            "
          >
            <template #docLink="{content}">
              <gl-link :href="config.helpPagePath" target="_blank">
                {{ content }}
              </gl-link>
            </template>
          </gl-sprintf>
        </p>
      </div>

      <div v-if="isLoading" class="mt-2">
        <gl-skeleton-loader
          v-for="index in $options.loader.repeat"
          :key="index"
          :width="$options.loader.width"
          :height="$options.loader.height"
          preserve-aspect-ratio="xMinYMax meet"
        >
          <rect width="500" x="10" y="10" height="20" rx="4" />
          <circle cx="525" cy="20" r="10" />
          <rect x="960" y="0" width="40" height="40" rx="4" />
        </gl-skeleton-loader>
      </div>
      <template v-else>
        <div v-if="images.length" ref="imagesList" class="d-flex flex-column">
          <div
            v-for="(listItem, index) in images"
            :key="index"
            ref="rowItem"
            :class="{ 'border-top': index === 0 }"
            class="d-flex justify-content-between align-items-center py-2 border-bottom"
          >
            <div>
              <router-link
                ref="detailsLink"
                :to="{ name: 'details', params: { id: encodeListItem(listItem) } }"
              >
                {{ listItem.path }}
              </router-link>
              <clipboard-button
                v-if="listItem.location"
                ref="clipboardButton"
                :text="listItem.location"
                :title="listItem.location"
                css-class="btn-default btn-transparent btn-clipboard"
              />
            </div>
            <div
              v-gl-tooltip="{ disabled: listItem.destroy_path }"
              class="d-none d-sm-block"
              :title="
                s__('ContainerRegistry|Missing or insufficient permission, delete button disabled')
              "
            >
              <gl-button
                ref="deleteImageButton"
                v-gl-tooltip
                :disabled="!listItem.destroy_path"
                :title="s__('ContainerRegistry|Remove repository')"
                :aria-label="s__('ContainerRegistry|Remove repository')"
                class="btn-inverted"
                variant="danger"
                @click="deleteImage(listItem)"
              >
                <gl-icon name="remove" />
              </gl-button>
            </div>
          </div>
          <gl-pagination
            v-model="currentPage"
            :per-page="pagination.perPage"
            :total-items="pagination.total"
            align="center"
            class="w-100 mt-2"
          />
        </div>

        <template v-else>
          <project-empty-state v-if="!config.isGroupPage" />
          <group-empty-state v-else />
        </template>
      </template>

      <gl-modal
        ref="deleteModal"
        modal-id="delete-image-modal"
        ok-variant="danger"
        @ok="handleDeleteRepository"
        @cancel="track('cancel_delete')"
      >
        <template #modal-title>{{ s__('ContainerRegistry|Remove repository') }}</template>
        <p>
          <gl-sprintf
            :message=" s__(
                'ContainerRegistry|You are about to remove repository %{title}. Once you confirm, this repository will be permanently deleted.',
              ),"
          >
            <template #title>
              <b>{{ itemToDelete.path }}</b>
            </template>
          </gl-sprintf>
        </p>
        <template #modal-ok>{{ __('Remove') }}</template>
      </gl-modal>
    </template>
  </div>
</template>