summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/registry/settings/components/settings_form.vue
blob: 457bf35daaba280623e0c823d7a3b8daaf32202a (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<script>
import { mapActions, mapState } from 'vuex';
import { GlFormGroup, GlToggle, GlFormSelect, GlFormTextarea, GlButton, GlCard } from '@gitlab/ui';
import { s__, __, sprintf } from '~/locale';
import { NAME_REGEX_LENGTH } from '../constants';
import { mapComputed } from '~/vuex_shared/bindings';

export default {
  components: {
    GlFormGroup,
    GlToggle,
    GlFormSelect,
    GlFormTextarea,
    GlButton,
    GlCard,
  },
  labelsConfig: {
    cols: 3,
    align: 'right',
  },
  computed: {
    ...mapState(['formOptions']),
    ...mapComputed(
      [
        'enabled',
        { key: 'cadence', getter: 'getCadence' },
        { key: 'older_than', getter: 'getOlderThan' },
        { key: 'keep_n', getter: 'getKeepN' },
        'name_regex',
      ],
      'updateSettings',
      'settings',
    ),
    policyEnabledText() {
      return this.enabled ? __('enabled') : __('disabled');
    },
    toggleDescriptionText() {
      return sprintf(
        s__('ContainerRegistry|Docker tag expiration policy is %{toggleStatus}'),
        {
          toggleStatus: `<strong>${this.policyEnabledText}</strong>`,
        },
        false,
      );
    },
    regexHelpText() {
      return sprintf(
        s__(
          'ContainerRegistry|Wildcards such as %{codeStart}*-stable%{codeEnd} or %{codeStart}production/*%{codeEnd} are supported.  To select all tags, use %{codeStart}.*%{codeEnd}',
        ),
        {
          codeStart: '<code>',
          codeEnd: '</code>',
        },
        false,
      );
    },
    nameRegexPlaceholder() {
      return '.*';
    },
    nameRegexState() {
      return this.name_regex ? this.name_regex.length <= NAME_REGEX_LENGTH : null;
    },
    formIsInvalid() {
      return this.nameRegexState === false;
    },
  },
  methods: {
    ...mapActions(['resetSettings', 'saveSettings']),
  },
};
</script>

<template>
  <form ref="form-element" @submit.prevent="saveSettings" @reset.prevent="resetSettings">
    <gl-card>
      <template #header>
        {{ s__('ContainerRegistry|Tag expiration policy') }}
      </template>
      <template>
        <gl-form-group
          id="expiration-policy-toggle-group"
          :label-cols="$options.labelsConfig.cols"
          :label-align="$options.labelsConfig.align"
          label-for="expiration-policy-toggle"
          :label="s__('ContainerRegistry|Expiration policy:')"
        >
          <div class="d-flex align-items-start">
            <gl-toggle id="expiration-policy-toggle" v-model="enabled" />
            <span class="mb-2 ml-1 lh-2" v-html="toggleDescriptionText"></span>
          </div>
        </gl-form-group>

        <gl-form-group
          id="expiration-policy-interval-group"
          :label-cols="$options.labelsConfig.cols"
          :label-align="$options.labelsConfig.align"
          label-for="expiration-policy-interval"
          :label="s__('ContainerRegistry|Expiration interval:')"
        >
          <gl-form-select id="expiration-policy-interval" v-model="older_than" :disabled="!enabled">
            <option v-for="option in formOptions.olderThan" :key="option.key" :value="option.key">
              {{ option.label }}
            </option>
          </gl-form-select>
        </gl-form-group>

        <gl-form-group
          id="expiration-policy-schedule-group"
          :label-cols="$options.labelsConfig.cols"
          :label-align="$options.labelsConfig.align"
          label-for="expiration-policy-schedule"
          :label="s__('ContainerRegistry|Expiration schedule:')"
        >
          <gl-form-select id="expiration-policy-schedule" v-model="cadence" :disabled="!enabled">
            <option v-for="option in formOptions.cadence" :key="option.key" :value="option.key">
              {{ option.label }}
            </option>
          </gl-form-select>
        </gl-form-group>

        <gl-form-group
          id="expiration-policy-latest-group"
          :label-cols="$options.labelsConfig.cols"
          :label-align="$options.labelsConfig.align"
          label-for="expiration-policy-latest"
          :label="s__('ContainerRegistry|Number of tags to retain:')"
        >
          <gl-form-select id="expiration-policy-latest" v-model="keep_n" :disabled="!enabled">
            <option v-for="option in formOptions.keepN" :key="option.key" :value="option.key">
              {{ option.label }}
            </option>
          </gl-form-select>
        </gl-form-group>

        <gl-form-group
          id="expiration-policy-name-matching-group"
          :label-cols="$options.labelsConfig.cols"
          :label-align="$options.labelsConfig.align"
          label-for="expiration-policy-name-matching"
          :label="s__('ContainerRegistry|Expire Docker tags that match this regex:')"
          :state="nameRegexState"
          :invalid-feedback="
            s__('ContainerRegistry|The value of this input should be less than 255 characters')
          "
        >
          <gl-form-textarea
            id="expiration-policy-name-matching"
            v-model="name_regex"
            :placeholder="nameRegexPlaceholder"
            :state="nameRegexState"
            :disabled="!enabled"
            trim
          />
          <template #description>
            <span ref="regex-description" v-html="regexHelpText"></span>
          </template>
        </gl-form-group>
      </template>
      <template #footer>
        <div class="d-flex justify-content-end">
          <gl-button ref="cancel-button" type="reset" class="mr-2 d-block">{{
            __('Cancel')
          }}</gl-button>
          <gl-button
            ref="save-button"
            type="submit"
            :disabled="formIsInvalid"
            variant="success"
            class="d-block"
          >
            {{ __('Save expiration policy') }}
          </gl-button>
        </div>
      </template>
    </gl-card>
  </form>
</template>