debian-mirror-gitlab/app/assets/javascripts/ide/components/file_templates/bar.vue

74 lines
1.9 KiB
Vue
Raw Normal View History

2018-11-20 20:47:30 +05:30
<script>
import { mapActions, mapGetters, mapState } from 'vuex';
import Dropdown from './dropdown.vue';
export default {
components: {
Dropdown,
},
computed: {
...mapGetters(['activeFile']),
...mapGetters('fileTemplates', ['templateTypes']),
...mapState('fileTemplates', ['selectedTemplateType', 'updateSuccess']),
showTemplatesDropdown() {
return Object.keys(this.selectedTemplateType).length > 0;
},
},
watch: {
activeFile: 'setInitialType',
},
mounted() {
this.setInitialType();
},
methods: {
...mapActions('fileTemplates', [
'setSelectedTemplateType',
'fetchTemplate',
'undoFileTemplate',
]),
setInitialType() {
const initialTemplateType = this.templateTypes.find(t => t.name === this.activeFile.name);
if (initialTemplateType) {
this.setSelectedTemplateType(initialTemplateType);
}
},
selectTemplateType(templateType) {
this.setSelectedTemplateType(templateType);
},
selectTemplate(template) {
this.fetchTemplate(template);
},
undo() {
this.undoFileTemplate();
},
},
};
</script>
<template>
2018-12-13 13:39:08 +05:30
<div class="d-flex align-items-center ide-file-templates qa-file-templates-bar">
2019-02-15 15:39:39 +05:30
<strong class="append-right-default"> {{ __('File templates') }} </strong>
2018-11-20 20:47:30 +05:30
<dropdown
:data="templateTypes"
:label="selectedTemplateType.name || __('Choose a type...')"
class="mr-2"
@click="selectTemplateType"
/>
<dropdown
v-if="showTemplatesDropdown"
:label="__('Choose a template...')"
:is-async-data="true"
:searchable="true"
:title="__('File templates')"
2018-12-13 13:39:08 +05:30
class="mr-2 qa-file-template-dropdown"
2018-11-20 20:47:30 +05:30
@click="selectTemplate"
/>
<transition name="fade">
2019-02-15 15:39:39 +05:30
<button v-show="updateSuccess" type="button" class="btn btn-default" @click="undo">
2018-11-20 20:47:30 +05:30
{{ __('Undo') }}
</button>
</transition>
</div>
</template>