summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/registry/settings/components/registry_settings_app.vue
blob: b4a59fd01784b5d6b289033901a56e3859496446 (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
91
92
93
94
95
96
97
98
99
<script>
import { mapActions, mapGetters, mapState } from 'vuex';
import { GlAlert, GlSprintf, GlLink } from '@gitlab/ui';
import { s__ } from '~/locale';

import { FETCH_SETTINGS_ERROR_MESSAGE } from '../../shared/constants';

import SettingsForm from './settings_form.vue';

export default {
  components: {
    SettingsForm,
    GlAlert,
    GlSprintf,
    GlLink,
  },
  i18n: {
    unavailableFeatureTitle: s__(
      `ContainerRegistry|Container Registry tag expiration and retention policy is disabled`,
    ),
    unavailableFeatureIntroText: s__(
      `ContainerRegistry|The Container Registry tag expiration and retention policies for this project have not been enabled.`,
    ),
    unavailableUserFeatureText: s__(`ContainerRegistry|Please contact your administrator.`),
    unavailableAdminFeatureText: s__(
      `ContainerRegistry| Please visit the %{linkStart}administration settings%{linkEnd} to enable this feature.`,
    ),
    fetchSettingsErrorText: FETCH_SETTINGS_ERROR_MESSAGE,
  },
  data() {
    return {
      fetchSettingsError: false,
    };
  },
  computed: {
    ...mapState(['isAdmin', 'adminSettingsPath']),
    ...mapGetters({ isDisabled: 'getIsDisabled' }),
    showSettingForm() {
      return !this.isDisabled && !this.fetchSettingsError;
    },
    showDisabledFormMessage() {
      return this.isDisabled && !this.fetchSettingsError;
    },
    unavailableFeatureMessage() {
      return this.isAdmin
        ? this.$options.i18n.unavailableAdminFeatureText
        : this.$options.i18n.unavailableUserFeatureText;
    },
  },
  mounted() {
    this.fetchSettings().catch(() => {
      this.fetchSettingsError = true;
    });
  },
  methods: {
    ...mapActions(['fetchSettings']),
  },
};
</script>

<template>
  <div>
    <p>
      {{ s__('ContainerRegistry|Tag expiration policy is designed to:') }}
    </p>
    <ul>
      <li>{{ s__('ContainerRegistry|Keep and protect the images that matter most.') }}</li>
      <li>
        {{
          s__(
            "ContainerRegistry|Automatically remove extra images that aren't designed to be kept.",
          )
        }}
      </li>
    </ul>
    <settings-form v-if="showSettingForm" />
    <template v-else>
      <gl-alert
        v-if="showDisabledFormMessage"
        :dismissible="false"
        :title="$options.i18n.unavailableFeatureTitle"
        variant="tip"
      >
        {{ $options.i18n.unavailableFeatureIntroText }}

        <gl-sprintf :message="unavailableFeatureMessage">
          <template #link="{ content }">
            <gl-link :href="adminSettingsPath" target="_blank">
              {{ content }}
            </gl-link>
          </template>
        </gl-sprintf>
      </gl-alert>
      <gl-alert v-else-if="fetchSettingsError" variant="warning" :dismissible="false">
        <gl-sprintf :message="$options.i18n.fetchSettingsErrorText" />
      </gl-alert>
    </template>
  </div>
</template>