1+ <template >
2+ <div class =" flex flex-col border-black border-2 rounded-3xl border-dashed mx-12 mb-12 p-5 justify-center items-center
3+ space-y-6"
4+ @dragenter.prevent =" toggleActive"
5+ @dragleave.prevent =" toggleActive"
6+ @dragover.prevent
7+ @drop.prevent =" select_file"
8+ :class =" {'bg-blue-200 transition-all duration-300' :active }" >
9+ <input type =" file" ref =" moodle_file" class =" hidden" @change =" select_file" >
10+ <svg-icon class =" w-1/4 h-1/4 justify-center"
11+ type =" mdi" :path =" upload_file_icon" ></svg-icon >
12+ <span class =" font-bold text-center text-5xl" > Drag & Drop file here </span >
13+ <span class =" text-center text-4xl" > or </span >
14+ <BrowseFilesButton class =" w-max" :class =" {'bg-white transition-all duration-300' :active }" />
15+ <div class =" flex flex-row w-full h-1/5 justify-end content-end" >
16+ <div class =" flex items-end cursor-pointer" >
17+ <svg-icon type =" mdi" :path =" information_icon" @click =" informationPopUp" ></svg-icon >
18+ </div >
19+ </div >
20+ </div >
21+ </template >
22+
23+ <script >
24+ import BrowseFilesButton from " @/components/ImportData/BrowseFilesButton" ;
25+ import SvgIcon from ' @jamescoyle/vue-icon'
26+ import { mdiFileUpload , mdiHelpCircleOutline } from " @mdi/js"
27+ import { ref } from ' vue'
28+
29+ export default {
30+ name: " DragDropArea" ,
31+ components: {
32+ BrowseFilesButton,
33+ SvgIcon
34+ },
35+ emits: [' onUpload' , ' popUp' ],
36+ data () {
37+ return {
38+ upload_file_icon: mdiFileUpload,
39+ information_icon: mdiHelpCircleOutline,
40+ data_file: null
41+ }
42+ },
43+ setup () {
44+ const active = ref (false )
45+ const toggleActive = () => {
46+ active .value = ! active .value
47+ }
48+
49+ return { active, toggleActive }
50+ },
51+ methods: {
52+ informationPopUp : function () {
53+ this .$emit (' popUp' )
54+ },
55+ /**
56+ * Checks whether is a drop or a input change event
57+ * Stores the selected file and enables a popup
58+ * for the user to confirm the upload to the backend
59+ * @param e : drop or change event
60+ */
61+ select_file : function (e ) {
62+ let uploaded_file
63+ if (e .type === " drop" ) {
64+ this .toggleActive ()
65+ uploaded_file = e .dataTransfer .files [0 ]
66+ if ( ! uploaded_file ) return
67+ this .data_file = uploaded_file
68+ this .confirm_upload ()
69+ return
70+ }
71+ uploaded_file = e .target .files [0 ]
72+ if ( ! uploaded_file ) return
73+ this .data_file = uploaded_file
74+ this .$refs .moodle_file .value = null
75+ this .confirm_upload ()
76+ },
77+ confirm_upload : function () {
78+ this .$emit (' onUpload' , this .data_file .name )
79+ }
80+ }
81+ }
82+ </script >
83+
84+ <style scoped>
85+
86+ </style >
0 commit comments