debian-mirror-gitlab/app/assets/javascripts/runner/components/runner_update_form.vue

200 lines
5.3 KiB
Vue
Raw Normal View History

2021-09-04 01:27:46 +05:30
<script>
import {
GlButton,
GlForm,
GlFormCheckbox,
GlFormGroup,
GlFormInputGroup,
GlTooltipDirective,
} from '@gitlab/ui';
2021-09-30 23:02:18 +05:30
import {
modelToUpdateMutationVariables,
runnerToModel,
2022-03-02 08:16:31 +05:30
} from 'ee_else_ce/runner/runner_update_form_utils';
import { createAlert, VARIANT_SUCCESS } from '~/flash';
2021-09-04 01:27:46 +05:30
import { __ } from '~/locale';
2021-09-30 23:02:18 +05:30
import { captureException } from '~/runner/sentry_utils';
2021-09-04 01:27:46 +05:30
import { ACCESS_LEVEL_NOT_PROTECTED, ACCESS_LEVEL_REF_PROTECTED, PROJECT_TYPE } from '../constants';
2022-05-07 20:08:51 +05:30
import runnerUpdateMutation from '../graphql/details/runner_update.mutation.graphql';
2021-09-04 01:27:46 +05:30
export default {
2021-09-30 23:02:18 +05:30
name: 'RunnerUpdateForm',
2021-09-04 01:27:46 +05:30
components: {
GlButton,
GlForm,
GlFormCheckbox,
GlFormGroup,
GlFormInputGroup,
2021-09-30 23:02:18 +05:30
RunnerUpdateCostFactorFields: () =>
import('ee_component/runner/components/runner_update_cost_factor_fields.vue'),
2021-09-04 01:27:46 +05:30
},
directives: {
GlTooltip: GlTooltipDirective,
},
props: {
runner: {
type: Object,
required: false,
default: null,
},
},
data() {
return {
saving: false,
model: runnerToModel(this.runner),
};
},
computed: {
canBeLockedToProject() {
return this.runner?.runnerType === PROJECT_TYPE;
},
readonlyIpAddress() {
return this.runner?.ipAddress;
},
},
watch: {
runner(newVal, oldVal) {
if (oldVal === null) {
this.model = runnerToModel(newVal);
}
},
},
methods: {
async onSubmit() {
this.saving = true;
try {
const {
data: {
runnerUpdate: { errors },
},
} = await this.$apollo.mutate({
mutation: runnerUpdateMutation,
2021-09-30 23:02:18 +05:30
variables: modelToUpdateMutationVariables(this.model),
2021-09-04 01:27:46 +05:30
});
if (errors?.length) {
2021-09-30 23:02:18 +05:30
// Validation errors need not be thrown
2022-03-02 08:16:31 +05:30
createAlert({ message: errors[0] });
2021-09-04 01:27:46 +05:30
return;
}
this.onSuccess();
2021-09-30 23:02:18 +05:30
} catch (error) {
const { message } = error;
2022-05-07 20:08:51 +05:30
createAlert({ message });
captureException({ error, component: this.$options.name });
2021-09-04 01:27:46 +05:30
} finally {
this.saving = false;
}
},
onSuccess() {
2022-03-02 08:16:31 +05:30
createAlert({ message: __('Changes saved.'), variant: VARIANT_SUCCESS });
2021-09-04 01:27:46 +05:30
this.model = runnerToModel(this.runner);
},
},
ACCESS_LEVEL_NOT_PROTECTED,
ACCESS_LEVEL_REF_PROTECTED,
};
</script>
<template>
<gl-form @submit.prevent="onSubmit">
<gl-form-checkbox
v-model="model.active"
data-testid="runner-field-paused"
:value="false"
:unchecked-value="true"
>
{{ __('Paused') }}
<template #help>
2021-10-27 15:23:28 +05:30
{{ s__('Runners|Stop the runner from accepting new jobs.') }}
2021-09-04 01:27:46 +05:30
</template>
</gl-form-checkbox>
<gl-form-checkbox
v-model="model.accessLevel"
data-testid="runner-field-protected"
:value="$options.ACCESS_LEVEL_REF_PROTECTED"
:unchecked-value="$options.ACCESS_LEVEL_NOT_PROTECTED"
>
{{ __('Protected') }}
<template #help>
2021-10-27 15:23:28 +05:30
{{ s__('Runners|Use the runner on pipelines for protected branches only.') }}
2021-09-04 01:27:46 +05:30
</template>
</gl-form-checkbox>
<gl-form-checkbox v-model="model.runUntagged" data-testid="runner-field-run-untagged">
{{ __('Run untagged jobs') }}
<template #help>
2021-10-27 15:23:28 +05:30
{{ s__('Runners|Use the runner for jobs without tags, in addition to tagged jobs.') }}
2021-09-04 01:27:46 +05:30
</template>
</gl-form-checkbox>
<gl-form-checkbox
2021-11-11 11:23:49 +05:30
v-if="canBeLockedToProject"
2021-09-04 01:27:46 +05:30
v-model="model.locked"
data-testid="runner-field-locked"
>
{{ __('Lock to current projects') }}
<template #help>
2021-10-27 15:23:28 +05:30
{{ s__('Runners|Use the runner for the currently assigned projects only.') }}
2021-09-04 01:27:46 +05:30
</template>
</gl-form-checkbox>
<gl-form-group :label="__('IP Address')" data-testid="runner-field-ip-address">
<gl-form-input-group :value="readonlyIpAddress" readonly select-on-click>
<template #append>
<gl-button
v-gl-tooltip.hover
:title="__('Copy IP Address')"
:aria-label="__('Copy IP Address')"
:data-clipboard-text="readonlyIpAddress"
icon="copy-to-clipboard"
class="d-inline-flex"
/>
</template>
</gl-form-input-group>
</gl-form-group>
<gl-form-group :label="__('Description')" data-testid="runner-field-description">
<gl-form-input-group v-model="model.description" />
</gl-form-group>
<gl-form-group
data-testid="runner-field-max-timeout"
:label="__('Maximum job timeout')"
:description="
s__(
'Runners|Enter the number of seconds. This timeout takes precedence over lower timeouts set for the project.',
)
"
>
<gl-form-input-group v-model.number="model.maximumTimeout" type="number" />
</gl-form-group>
<gl-form-group
data-testid="runner-field-tags"
:label="__('Tags')"
:description="
__('You can set up jobs to only use runners with specific tags. Separate tags with commas.')
"
>
<gl-form-input-group v-model="model.tagList" />
</gl-form-group>
2021-09-30 23:02:18 +05:30
<runner-update-cost-factor-fields v-model="model" />
2021-09-04 01:27:46 +05:30
<div class="form-actions">
<gl-button
type="submit"
variant="confirm"
class="js-no-auto-disable"
:loading="saving || !runner"
>
{{ __('Save changes') }}
</gl-button>
</div>
</gl-form>
</template>