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

293 lines
8.8 KiB
Vue
Raw Normal View History

2018-03-17 18:26:18 +05:30
<script>
2019-12-21 20:55:43 +05:30
import { mapActions, mapGetters } from 'vuex';
2019-12-26 22:10:19 +05:30
import { GlButton, GlFormCheckbox, GlTooltipDirective, GlModal } from '@gitlab/ui';
import Tracking from '~/tracking';
import { n__, s__, sprintf } from '~/locale';
import createFlash from '~/flash';
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
import TablePagination from '~/vue_shared/components/pagination/table_pagination.vue';
import Icon from '~/vue_shared/components/icon.vue';
import timeagoMixin from '~/vue_shared/mixins/timeago';
import { numberToHumanSize } from '~/lib/utils/number_utils';
import { FETCH_REGISTRY_ERROR_MESSAGE, DELETE_REGISTRY_ERROR_MESSAGE } from '../constants';
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,
2019-10-12 21:52:04 +05:30
GlFormCheckbox,
2019-02-15 15:39:39 +05:30
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,
2018-12-13 13:39:08 +05:30
},
mixins: [timeagoMixin],
props: {
repo: {
type: Object,
required: true,
2018-03-17 18:26:18 +05:30
},
2019-12-21 20:55:43 +05:30
canDeleteRepo: {
type: Boolean,
default: false,
required: false,
},
2018-12-13 13:39:08 +05:30
},
2019-09-30 21:07:59 +05:30
data() {
return {
2019-12-21 20:55:43 +05:30
selectedItems: [],
2019-10-12 21:52:04 +05:30
itemsToBeDeleted: [],
2019-09-30 21:07:59 +05:30
modalId: `confirm-image-deletion-modal-${this.repo.id}`,
2019-10-12 21:52:04 +05:30
selectAllChecked: false,
modalDescription: '',
2019-09-30 21:07:59 +05:30
};
},
2018-12-13 13:39:08 +05:30
computed: {
2019-12-21 20:55:43 +05:30
...mapGetters(['isDeleteDisabled']),
2019-10-12 21:52:04 +05:30
bulkDeletePath() {
return this.repo.tagsPath ? this.repo.tagsPath.replace('?format=json', '/bulk_destroy') : '';
},
2018-12-13 13:39:08 +05:30
shouldRenderPagination() {
return this.repo.pagination.total > this.repo.pagination.perPage;
2018-03-17 18:26:18 +05:30
},
2019-12-21 20:55:43 +05:30
modalAction() {
2019-10-12 21:52:04 +05:30
return n__(
2019-12-21 20:55:43 +05:30
'ContainerRegistry|Remove tag',
'ContainerRegistry|Remove tags',
2019-10-12 21:52:04 +05:30
this.itemsToBeDeleted.length === 0 ? 1 : this.itemsToBeDeleted.length,
);
},
2019-12-26 22:10:19 +05:30
isMultiDelete() {
return this.itemsToBeDeleted.length > 1;
},
tracking() {
return {
property: this.repo.name,
label: this.isMultiDelete ? 'bulk_registry_tag_delete' : 'registry_tag_delete',
};
},
2018-12-13 13:39:08 +05:30
},
methods: {
2019-10-12 21:52:04 +05:30
...mapActions(['fetchList', 'deleteItem', 'multiDeleteItems']),
2019-12-26 22:10:19 +05:30
track(action) {
Tracking.event(document.body.dataset.page, action, this.tracking);
},
2019-10-12 21:52:04 +05:30
setModalDescription(itemIndex = -1) {
if (itemIndex === -1) {
this.modalDescription = sprintf(
2019-12-21 20:55:43 +05:30
s__(`ContainerRegistry|You are about to remove <b>%{count}</b> tags. Are you sure?`),
2019-10-12 21:52:04 +05:30
{ count: this.itemsToBeDeleted.length },
);
} else {
const { tag } = this.repo.list[itemIndex];
this.modalDescription = sprintf(
2019-12-21 20:55:43 +05:30
s__(`ContainerRegistry|You are about to remove <b>%{title}</b>. Are you sure?`),
2019-10-12 21:52:04 +05:30
{ title: `${this.repo.name}:${tag}` },
);
}
},
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-10-12 21:52:04 +05:30
deleteSingleItem(index) {
this.setModalDescription(index);
2019-12-21 20:55:43 +05:30
this.itemsToBeDeleted = [index];
2019-12-26 22:10:19 +05:30
this.track('click_button');
this.$refs.deleteModal.show();
2019-10-12 21:52:04 +05:30
},
deleteMultipleItems() {
2019-12-21 20:55:43 +05:30
this.itemsToBeDeleted = [...this.selectedItems];
if (this.selectedItems.length === 1) {
2019-10-12 21:52:04 +05:30
this.setModalDescription(this.itemsToBeDeleted[0]);
2019-12-21 20:55:43 +05:30
} else if (this.selectedItems.length > 1) {
2019-10-12 21:52:04 +05:30
this.setModalDescription();
}
2019-12-26 22:10:19 +05:30
this.track('click_button');
this.$refs.deleteModal.show();
2019-09-30 21:07:59 +05:30
},
2019-10-12 21:52:04 +05:30
handleSingleDelete(itemToDelete) {
2019-12-21 20:55:43 +05:30
this.itemsToBeDeleted = [];
2019-10-12 21:52:04 +05:30
this.deleteItem(itemToDelete)
2018-12-13 13:39:08 +05:30
.then(() => this.fetchList({ repo: this.repo }))
2019-12-26 22:10:19 +05:30
.catch(() => createFlash(DELETE_REGISTRY_ERROR_MESSAGE));
2018-12-13 13:39:08 +05:30
},
2019-10-12 21:52:04 +05:30
handleMultipleDelete() {
const { itemsToBeDeleted } = this;
this.itemsToBeDeleted = [];
2019-12-21 20:55:43 +05:30
this.selectedItems = [];
2019-10-12 21:52:04 +05:30
if (this.bulkDeletePath) {
this.multiDeleteItems({
path: this.bulkDeletePath,
items: itemsToBeDeleted.map(x => this.repo.list[x].tag),
})
.then(() => this.fetchList({ repo: this.repo }))
2019-12-26 22:10:19 +05:30
.catch(() => createFlash(DELETE_REGISTRY_ERROR_MESSAGE));
2019-10-12 21:52:04 +05:30
} else {
2019-12-26 22:10:19 +05:30
createFlash(DELETE_REGISTRY_ERROR_MESSAGE);
2019-10-12 21:52:04 +05:30
}
},
2018-12-13 13:39:08 +05:30
onPageChange(pageNumber) {
this.fetchList({ repo: this.repo, page: pageNumber }).catch(() =>
2019-12-26 22:10:19 +05:30
createFlash(FETCH_REGISTRY_ERROR_MESSAGE),
2018-12-13 13:39:08 +05:30
);
},
2019-10-12 21:52:04 +05:30
onSelectAllChange() {
if (this.selectAllChecked) {
this.deselectAll();
} else {
this.selectAll();
}
},
selectAll() {
2019-12-21 20:55:43 +05:30
this.selectedItems = this.repo.list.map((x, index) => index);
2019-10-12 21:52:04 +05:30
this.selectAllChecked = true;
},
deselectAll() {
2019-12-21 20:55:43 +05:30
this.selectedItems = [];
2019-10-12 21:52:04 +05:30
this.selectAllChecked = false;
},
2019-12-21 20:55:43 +05:30
updateselectedItems(index) {
const delIndex = this.selectedItems.findIndex(x => x === index);
2019-10-12 21:52:04 +05:30
if (delIndex > -1) {
2019-12-21 20:55:43 +05:30
this.selectedItems.splice(delIndex, 1);
2019-10-12 21:52:04 +05:30
this.selectAllChecked = false;
} else {
2019-12-21 20:55:43 +05:30
this.selectedItems.push(index);
2019-10-12 21:52:04 +05:30
2019-12-21 20:55:43 +05:30
if (this.selectedItems.length === this.repo.list.length) {
2019-10-12 21:52:04 +05:30
this.selectAllChecked = true;
}
}
},
2019-12-21 20:55:43 +05:30
canDeleteRow(item) {
return item && item.canDelete && !this.isDeleteDisabled;
},
2019-12-26 22:10:19 +05:30
onDeletionConfirmed() {
this.track('confirm_delete');
if (this.isMultiDelete) {
this.handleMultipleDelete();
} else {
const index = this.itemsToBeDeleted[0];
this.handleSingleDelete(this.repo.list[index]);
}
},
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>
2019-10-12 21:52:04 +05:30
<th>
<gl-form-checkbox
2019-12-21 20:55:43 +05:30
v-if="canDeleteRepo"
2019-10-12 21:52:04 +05:30
class="js-select-all-checkbox"
:checked="selectAllChecked"
@change="onSelectAllChange"
/>
</th>
2018-03-17 18:26:18 +05:30
<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>
2019-10-12 21:52:04 +05:30
<th>
<gl-button
2019-12-21 20:55:43 +05:30
v-if="canDeleteRepo"
2019-12-26 22:10:19 +05:30
ref="bulkDeleteButton"
2019-10-12 21:52:04 +05:30
v-gl-tooltip
2019-12-21 20:55:43 +05:30
:disabled="!selectedItems || selectedItems.length === 0"
2019-12-26 22:10:19 +05:30
class="float-right"
2019-10-12 21:52:04 +05:30
variant="danger"
2019-12-21 20:55:43 +05:30
:title="s__('ContainerRegistry|Remove selected tags')"
:aria-label="s__('ContainerRegistry|Remove selected tags')"
2019-10-12 21:52:04 +05:30
@click="deleteMultipleItems()"
2019-12-21 20:55:43 +05:30
>
<icon name="remove" />
</gl-button>
2019-10-12 21:52:04 +05:30
</th>
2018-03-17 18:26:18 +05:30
</tr>
</thead>
<tbody>
2019-10-12 21:52:04 +05:30
<tr v-for="(item, index) in repo.list" :key="item.tag" class="registry-image-row">
<td class="check">
<gl-form-checkbox
2019-12-21 20:55:43 +05:30
v-if="canDeleteRow(item)"
2019-10-12 21:52:04 +05:30
class="js-select-checkbox"
2019-12-21 20:55:43 +05:30
:checked="selectedItems && selectedItems.includes(index)"
@change="updateselectedItems(index)"
2019-10-12 21:52:04 +05:30
/>
</td>
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-12-21 20:55:43 +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-12-21 20:55:43 +05:30
<span v-gl-tooltip.bottom :title="tooltipTitle(item.createdAt)">{{
timeFormated(item.createdAt)
}}</span>
2018-03-17 18:26:18 +05:30
</td>
2019-10-12 21:52:04 +05:30
<td class="content action-buttons">
2019-02-15 15:39:39 +05:30
<gl-button
2019-12-21 20:55:43 +05:30
v-if="canDeleteRow(item)"
:title="s__('ContainerRegistry|Remove tag')"
:aria-label="s__('ContainerRegistry|Remove tag')"
2019-02-15 15:39:39 +05:30
variant="danger"
2019-10-12 21:52:04 +05:30
class="js-delete-registry-row float-right btn-inverted btn-border-color btn-icon"
@click="deleteSingleItem(index)"
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-12-21 20:55:43 +05:30
class="js-registry-pagination"
2018-03-17 18:26:18 +05:30
/>
2019-09-30 21:07:59 +05:30
2019-12-26 22:10:19 +05:30
<gl-modal
ref="deleteModal"
:modal-id="modalId"
ok-variant="danger"
@ok="onDeletionConfirmed"
@cancel="track('cancel_delete')"
>
2019-12-21 20:55:43 +05:30
<template v-slot:modal-title>{{ modalAction }}</template>
<template v-slot:modal-ok>{{ modalAction }}</template>
2019-10-12 21:52:04 +05:30
<p v-html="modalDescription"></p>
2019-09-30 21:07:59 +05:30
</gl-modal>
2018-03-17 18:26:18 +05:30
</div>
</template>