summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/registry/components/app.vue
blob: c4d663828500ce73cf2f61882f2c45d2d7a3a9d7 (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
<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>