gitlab-org--gitlab-foss/app/assets/javascripts/registry/components/collapsible_container.vue

231 lines
6.1 KiB
Vue
Raw Normal View History

2017-09-15 09:10:08 -04:00
<script>
2017-09-25 07:29:55 -04:00
import { mapActions } from 'vuex';
import { n__, s__ } from '../../locale';
2017-09-15 12:05:46 -04:00
import clipboardButton from '../../vue_shared/components/clipboard_button.vue';
import loadingIcon from '../../vue_shared/components/loading_icon.vue';
2017-09-22 06:46:55 -04:00
import tablePagination from '../../vue_shared/components/table_pagination.vue';
import tooltip from '../../vue_shared/directives/tooltip';
import timeagoMixin from '../../vue_shared/mixins/timeago';
2017-09-25 07:29:55 -04:00
import { errorMessages, errorMessagesTypes } from '../constants';
2017-09-15 12:05:46 -04:00
2017-09-15 09:10:08 -04:00
export default {
name: 'collapsibeContainerRegisty',
props: {
repo: {
2017-09-15 12:05:46 -04:00
type: Object,
required: true,
},
2017-09-15 09:10:08 -04:00
},
components: {
2017-09-15 12:05:46 -04:00
clipboardButton,
loadingIcon,
2017-09-22 06:46:55 -04:00
tablePagination,
},
mixins: [
timeagoMixin,
],
directives: {
tooltip,
2017-09-15 09:10:08 -04:00
},
data() {
return {
isOpen: false,
};
},
2017-09-22 06:46:55 -04:00
computed: {
shouldRenderPagination() {
return this.repo.pagination.total > this.repo.pagination.perPage;
},
},
2017-09-15 09:10:08 -04:00
methods: {
2017-09-25 07:29:55 -04:00
...mapActions([
'fetchList',
'deleteRepo',
'deleteRegistry',
'toggleLoading',
]),
layers(item) {
2017-09-25 07:29:55 -04:00
const pluralize = n__('layer', 'layers', item.layers);
return `${item.layers} ${pluralize}`;
},
toggleRepo() {
if (this.isOpen === false) {
2017-09-25 07:29:55 -04:00
this.fetchList({ repo: this.repo })
.catch(() => this.showError(errorMessagesTypes.FETCH_REGISTRY));
}
this.isOpen = !this.isOpen;
},
handleDeleteRepository() {
2017-09-25 07:29:55 -04:00
this.deleteRepo(this.repo)
.then(() => this.fetchRepos())
.catch(() => this.showError(errorMessagesTypes.DELETE_REPO));
},
handleDeleteRegistry(registry) {
2017-09-25 07:29:55 -04:00
this.deleteRegistry(registry)
.then(() => this.fetchRegistry(this.repo))
.catch(() => this.showError(errorMessagesTypes.DELETE_REGISTRY));
},
2017-09-22 06:46:55 -04:00
onPageChange(pageNumber) {
2017-09-25 07:29:55 -04:00
this.fetchList({ repo: this.repo, page })
.catch(() => this.showError(errorMessagesTypes.FETCH_REGISTRY));
},
clipboardText(text) {
return `docker pull ${text}`;
},
showError(message) {
Flash((errorMessages[message]));
2017-09-22 06:46:55 -04:00
},
},
};
2017-09-15 09:10:08 -04:00
</script>
<template>
<div class="container-image">
<div
class="container-image-head">
2017-09-25 07:29:55 -04:00
<button
type="button"
@click="toggleRepo"
2017-09-25 07:29:55 -04:00
class="js-toggle-repo btn-link">
<i
class="fa"
:class="{
'fa-chevron-right': !isOpen,
'fa-chevron-up': isOpen,
}"
aria-hidden="true">
</i>
{{repo.name}}
2017-09-25 07:29:55 -04:00
</button>
<clipboard-button
v-if="repo.location"
2017-09-25 07:29:55 -04:00
:text="clipboardText(repo.location)"
:title="repo.location"
/>
<div class="controls hidden-xs pull-right">
<button
v-if="repo.canDelete"
type="button"
2017-09-25 07:29:55 -04:00
class="js-remove-repo btn btn-danger"
:title="s__('ContainerRegistry|Remove repository')"
:aria-label="s__('ContainerRegistry|Remove repository')"
v-tooltip
@click="handleDeleteRepository">
<i
class="fa fa-trash"
aria-hidden="true">
</i>
</button>
</div>
2017-09-15 12:05:46 -04:00
</div>
<loading-icon
v-if="repo.isLoading"
/>
2017-09-15 12:05:46 -04:00
<div
v-else-if="!repo.isLoading && isOpen"
class="container-image-tags">
2017-09-15 12:05:46 -04:00
2017-09-22 06:46:55 -04:00
<template v-if="repo.list.length">
<table class="table tags">
<thead>
<tr>
2017-09-25 07:29:55 -04:00
<th>{{s__('ContainerRegistry|Tag')}}</th>
<th>{{s__('ContainerRegistry|Tag ID')}}</th>
<th>{{s__("ContainerRegistry|Size")}}</th>
<th>{{s__("ContainerRegistry|Created")}}</th>
2017-09-22 06:46:55 -04:00
<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"
2017-09-25 07:29:55 -04:00
:text="clipboardText(item.location)"
2017-09-22 06:46:55 -04:00
/>
</td>
<td>
<span
v-tooltip
:title="item.revision"
data-placement="bottom">
{{item.shortRevision}}
</span>
</td>
<td>
<template v-if="item.size">
{{item.size}}
&middot;
{{layers(item)}}
</template>
<div
v-else
class="light">
\-
</div>
</td>
<td>
<template v-if="item.createdAt">
{{timeFormated(item.createdAt)}}
</template>
<div
v-else
class="light">
\-
</div>
</td>
<td class="content">
<button
v-if="item.canDelete"
type="button"
2017-09-25 07:29:55 -04:00
class="js-delete-registry btn btn-danger hidden-xs pull-right"
:title="s__('ContainerRegistry|Remove tag')"
:aria-label="s__('ContainerRegistry|Remove tag')"
2017-09-22 06:46:55 -04:00
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"
/>
</template>
2017-09-15 12:05:46 -04:00
<div
v-else
class="nothing-here-block">
2017-09-25 07:29:55 -04:00
{{s__("ContainerRegistry|No tags in Container Registry for this container image.")}}
2017-09-15 12:05:46 -04:00
</div>
</div>
2017-09-15 09:10:08 -04:00
</div>
</template>