debian-mirror-gitlab/app/assets/javascripts/ide/components/new_dropdown/index.vue

121 lines
2.3 KiB
Vue
Raw Normal View History

2018-05-09 12:01:36 +05:30
<script>
2018-10-15 14:42:47 +05:30
import { mapActions } from 'vuex';
import icon from '~/vue_shared/components/icon.vue';
import newModal from './modal.vue';
import upload from './upload.vue';
2018-05-09 12:01:36 +05:30
2018-10-15 14:42:47 +05:30
export default {
components: {
icon,
newModal,
upload,
},
props: {
branch: {
type: String,
required: true,
2018-05-09 12:01:36 +05:30
},
2018-10-15 14:42:47 +05:30
path: {
type: String,
required: false,
default: '',
2018-05-09 12:01:36 +05:30
},
2018-10-15 14:42:47 +05:30
},
data() {
return {
openModal: false,
modalType: '',
dropdownOpen: false,
};
},
watch: {
dropdownOpen() {
this.$nextTick(() => {
this.$refs.dropdownMenu.scrollIntoView();
});
2018-05-09 12:01:36 +05:30
},
2018-10-15 14:42:47 +05:30
},
methods: {
...mapActions(['createTempEntry']),
createNewItem(type) {
this.modalType = type;
this.openModal = true;
this.dropdownOpen = false;
2018-05-09 12:01:36 +05:30
},
2018-10-15 14:42:47 +05:30
hideModal() {
this.openModal = false;
},
openDropdown() {
this.dropdownOpen = !this.dropdownOpen;
},
},
};
2018-05-09 12:01:36 +05:30
</script>
<template>
<div class="ide-new-btn">
<div
class="dropdown"
:class="{
open: dropdownOpen,
}"
>
<button
type="button"
class="btn btn-sm btn-default dropdown-toggle add-to-tree"
aria-label="Create new file or directory"
@click.stop="openDropdown()"
>
<icon
name="plus"
:size="12"
css-classes="pull-left"
/>
<icon
name="arrow-down"
:size="12"
css-classes="pull-left"
/>
</button>
2018-10-15 14:42:47 +05:30
<ul
class="dropdown-menu dropdown-menu-right"
ref="dropdownMenu"
>
2018-05-09 12:01:36 +05:30
<li>
<a
href="#"
role="button"
@click.stop.prevent="createNewItem('blob')"
>
{{ __('New file') }}
</a>
</li>
<li>
<upload
:branch-id="branch"
:path="path"
@create="createTempEntry"
/>
</li>
<li>
<a
href="#"
role="button"
@click.stop.prevent="createNewItem('tree')"
>
{{ __('New directory') }}
</a>
</li>
</ul>
</div>
<new-modal
v-if="openModal"
:type="modalType"
:branch-id="branch"
:path="path"
@hide="hideModal"
@create="createTempEntry"
/>
</div>
</template>