gitlab-org--gitlab-foss/app/assets/javascripts/registry/components/app.vue
Filipa Lacerda ee3cf5d6f3
[ci skip] Adds tests to vuex and collapsibe component
Formats dates
Fixes clipboard button
Simplifies HTML
2017-09-20 19:03:53 +01:00

90 lines
2.2 KiB
Vue

<script>
/* globals Flash */
import { mapGetters, mapActions } from 'vuex';
import '../../flash';
import loadingIcon from '../../vue_shared/components/loading_icon.vue';
import store from '../stores';
import collapsibleContainer from './collapsible_container.vue';
import { errorMessages, errorMessagesTypes } from '../constants';
export default {
name: 'registryListApp',
props: {
endpoint: {
type: String,
required: true
},
},
store,
components: {
collapsibleContainer,
loadingIcon,
},
computed: {
...mapGetters([
'isLoading',
'repos',
]),
},
methods: {
...mapActions([
'setMainEndpoint',
'fetchRepos',
'fetchList',
'deleteRepo',
'deleteRegistry',
'toggleLoading',
]),
fetchRegistryList(repo) {
this.fetchList(repo)
.catch(() => this.showError(errorMessagesTypes.FETCH_REGISTRY))
},
deleteRegistry(repo, registry) {
this.deleteRegistry(registry)
.then(() => this.fetchRegistry(repo))
.catch(() => this.showError(errorMessagesTypes.DELETE_REGISTRY));
},
deleteRepository(repo) {
this.deleteRepo(repo)
.then(() => this.fetchRepos())
.catch(() => this.showError(errorMessagesTypes.DELETE_REPO));
},
showError(message){
Flash(__(errorMessages[message]));
}
},
created() {
this.setMainEndpoint(this.endpoint);
},
mounted() {
this.fetchRepos()
.catch(() => this.showError(errorMessagesTypes.FETCH_REPOS));
}
};
</script>
<template>
<div>
<loading-icon
v-if="isLoading"
size="3"
/>
<collapsible-container
v-else-if="!isLoading && repos.length"
v-for="(item, index) in repos"
:key="index"
:repo="item"
@fetchRegistryList="fetchRegistryList"
@deleteRepository="deleteRepository"
@deleteRegistry="deleteRegistry"
/>
<p v-else-if="!isLoading && !repos.length">
{{__("No container images stored for this project. Add one by following the instructions above")}}
</p>
</div>
</template>