diff options
Diffstat (limited to 'app/assets/javascripts/silent_mode_settings')
-rw-r--r-- | app/assets/javascripts/silent_mode_settings/components/app.vue | 70 | ||||
-rw-r--r-- | app/assets/javascripts/silent_mode_settings/index.js | 27 |
2 files changed, 97 insertions, 0 deletions
diff --git a/app/assets/javascripts/silent_mode_settings/components/app.vue b/app/assets/javascripts/silent_mode_settings/components/app.vue new file mode 100644 index 00000000000..2dd0449448c --- /dev/null +++ b/app/assets/javascripts/silent_mode_settings/components/app.vue @@ -0,0 +1,70 @@ +<script> +import { GlToggle, GlBadge } from '@gitlab/ui'; +import { updateApplicationSettings } from '~/rest_api'; +import { createAlert } from '~/alert'; +import toast from '~/vue_shared/plugins/global_toast'; +import { sprintf, __, s__ } from '~/locale'; + +export default { + name: 'SilentModeSettingsApp', + i18n: { + toggleLabel: s__('SilentMode|Enable silent mode'), + saveSuccess: s__('SilentMode|Silent mode %{status}'), + saveError: s__('SilentMode|There was an error updating the Silent Mode Settings.'), + enabled: __('enabled'), + disabled: __('disabled'), + experiment: __('Experiment'), + }, + components: { + GlToggle, + GlBadge, + }, + props: { + isSilentModeEnabled: { + type: Boolean, + required: false, + default: false, + }, + }, + data() { + return { + isLoading: false, + silentModeEnabled: this.isSilentModeEnabled, + }; + }, + methods: { + updateSilentModeSettings() { + this.isLoading = true; + + updateApplicationSettings({ + silent_mode_enabled: this.silentModeEnabled, + }) + .then(() => { + const status = this.silentModeEnabled + ? this.$options.i18n.enabled + : this.$options.i18n.disabled; + toast(sprintf(this.$options.i18n.saveSuccess, { status })); + }) + .catch(() => { + createAlert({ message: this.$options.i18n.saveError }); + }) + .finally(() => { + this.isLoading = false; + }); + }, + }, +}; +</script> +<template> + <gl-toggle + v-model="silentModeEnabled" + label-id="silent-mode-toggle" + :label="$options.i18n.toggleLabel" + :is-loading="isLoading" + @change="updateSilentModeSettings" + > + <template #label + >{{ $options.i18n.toggleLabel }} <gl-badge>{{ $options.i18n.experiment }}</gl-badge></template + > + </gl-toggle> +</template> diff --git a/app/assets/javascripts/silent_mode_settings/index.js b/app/assets/javascripts/silent_mode_settings/index.js new file mode 100644 index 00000000000..b18f9c02964 --- /dev/null +++ b/app/assets/javascripts/silent_mode_settings/index.js @@ -0,0 +1,27 @@ +import Vue from 'vue'; +import Translate from '~/vue_shared/translate'; +import { parseBoolean } from '~/lib/utils/common_utils'; +import SilentModeSettingsApp from './components/app.vue'; + +Vue.use(Translate); + +export const initSilentModeSettings = () => { + const el = document.getElementById('js-silent-mode-settings'); + + if (!el) { + return false; + } + + const { silentModeEnabled } = el.dataset; + + return new Vue({ + el, + render(createElement) { + return createElement(SilentModeSettingsApp, { + props: { + isSilentModeEnabled: parseBoolean(silentModeEnabled), + }, + }); + }, + }); +}; |