debian-mirror-gitlab/app/assets/javascripts/registry/components/table_registry.vue

154 lines
4.5 KiB
Vue
Raw Normal View History

2018-03-17 18:26:18 +05:30
<script>
2018-12-13 13:39:08 +05:30
import { mapActions } from 'vuex';
2019-09-30 21:07:59 +05:30
import { GlButton, GlTooltipDirective, GlModal, GlModalDirective } from '@gitlab/ui';
2018-12-13 13:39:08 +05:30
import { n__ } from '../../locale';
2019-02-15 15:39:39 +05:30
import createFlash from '../../flash';
import ClipboardButton from '../../vue_shared/components/clipboard_button.vue';
2019-09-04 21:01:54 +05:30
import TablePagination from '../../vue_shared/components/pagination/table_pagination.vue';
2019-02-15 15:39:39 +05:30
import Icon from '../../vue_shared/components/icon.vue';
2018-12-13 13:39:08 +05:30
import timeagoMixin from '../../vue_shared/mixins/timeago';
import { errorMessages, errorMessagesTypes } from '../constants';
import { numberToHumanSize } from '../../lib/utils/number_utils';
2018-03-17 18:26:18 +05:30
2018-12-13 13:39:08 +05:30
export default {
components: {
2019-02-15 15:39:39 +05:30
ClipboardButton,
TablePagination,
GlButton,
Icon,
2019-09-30 21:07:59 +05:30
GlModal,
2018-12-13 13:39:08 +05:30
},
directives: {
2019-02-15 15:39:39 +05:30
GlTooltip: GlTooltipDirective,
2019-09-30 21:07:59 +05:30
GlModal: GlModalDirective,
2018-12-13 13:39:08 +05:30
},
mixins: [timeagoMixin],
props: {
repo: {
type: Object,
required: true,
2018-03-17 18:26:18 +05:30
},
2018-12-13 13:39:08 +05:30
},
2019-09-30 21:07:59 +05:30
data() {
return {
itemToBeDeleted: null,
modalId: `confirm-image-deletion-modal-${this.repo.id}`,
};
},
2018-12-13 13:39:08 +05:30
computed: {
shouldRenderPagination() {
return this.repo.pagination.total > this.repo.pagination.perPage;
2018-03-17 18:26:18 +05:30
},
2018-12-13 13:39:08 +05:30
},
methods: {
2019-09-30 21:07:59 +05:30
...mapActions(['fetchList', 'deleteItem']),
2018-12-13 13:39:08 +05:30
layers(item) {
return item.layers ? n__('%d layer', '%d layers', item.layers) : '';
},
formatSize(size) {
return numberToHumanSize(size);
},
2019-09-30 21:07:59 +05:30
setItemToBeDeleted(item) {
this.itemToBeDeleted = item;
},
handleDeleteRegistry() {
const { itemToBeDeleted } = this;
this.itemToBeDeleted = null;
this.deleteItem(itemToBeDeleted)
2018-12-13 13:39:08 +05:30
.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) {
2019-02-15 15:39:39 +05:30
createFlash(errorMessages[message]);
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>
<div>
<table class="table tags">
<thead>
<tr>
<th>{{ s__('ContainerRegistry|Tag') }}</th>
<th>{{ s__('ContainerRegistry|Tag ID') }}</th>
2019-02-15 15:39:39 +05:30
<th>{{ s__('ContainerRegistry|Size') }}</th>
2019-09-04 21:01:54 +05:30
<th>{{ s__('ContainerRegistry|Last Updated') }}</th>
2018-03-17 18:26:18 +05:30
<th></th>
</tr>
</thead>
<tbody>
2019-02-15 15:39:39 +05:30
<tr v-for="item in repo.list" :key="item.tag">
2019-03-02 22:35:43 +05:30
<td class="monospace">
2018-03-17 18:26:18 +05:30
{{ item.tag }}
<clipboard-button
v-if="item.location"
:title="item.location"
2018-11-08 19:23:39 +05:30
:text="item.location"
2018-03-27 19:54:05 +05:30
css-class="btn-default btn-transparent btn-clipboard"
2018-03-17 18:26:18 +05:30
/>
</td>
<td>
2019-09-30 21:07:59 +05:30
<span v-gl-tooltip.bottom class="monospace" :title="item.revision">
{{ item.shortRevision }}
</span>
2018-03-17 18:26:18 +05:30
</td>
<td>
{{ formatSize(item.size) }}
2019-02-15 15:39:39 +05:30
<template v-if="item.size && item.layers"
>&middot;</template
>
2018-03-17 18:26:18 +05:30
{{ layers(item) }}
</td>
<td>
2019-09-30 21:07:59 +05:30
<span v-gl-tooltip.bottom :title="tooltipTitle(item.createdAt)">
{{ timeFormated(item.createdAt) }}
</span>
2018-03-17 18:26:18 +05:30
</td>
<td class="content">
2019-02-15 15:39:39 +05:30
<gl-button
2018-03-17 18:26:18 +05:30
v-if="item.canDelete"
2019-02-15 15:39:39 +05:30
v-gl-tooltip
2019-09-30 21:07:59 +05:30
v-gl-modal="modalId"
:title="s__('ContainerRegistry|Remove image')"
:aria-label="s__('ContainerRegistry|Remove image')"
2019-02-15 15:39:39 +05:30
variant="danger"
class="js-delete-registry d-none d-sm-block float-right"
2019-09-30 21:07:59 +05:30
@click="setItemToBeDeleted(item)"
2018-03-17 18:26:18 +05:30
>
2019-02-15 15:39:39 +05:30
<icon name="remove" />
</gl-button>
2018-03-17 18:26:18 +05:30
</td>
</tr>
</tbody>
</table>
<table-pagination
v-if="shouldRenderPagination"
:change="onPageChange"
:page-info="repo.pagination"
/>
2019-09-30 21:07:59 +05:30
<gl-modal :modal-id="modalId" ok-variant="danger" @ok="handleDeleteRegistry">
<template v-slot:modal-title>{{ s__('ContainerRegistry|Remove image') }}</template>
<template v-slot:modal-ok>{{ s__('ContainerRegistry|Remove image and tags') }}</template>
<p
v-html="
sprintf(
s__(
'ContainerRegistry|You are about to delete the image <b>%{title}</b>. This will delete the image and all tags pointing to this image.',
),
{ title: repo.name },
)
"
></p>
</gl-modal>
2018-03-17 18:26:18 +05:30
</div>
</template>