Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions app/components/DragAndDrop.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<template>
<v-hover v-slot="{ isHovering, props: hoverProps }">
<v-card
v-bind="hoverProps"
class="text-center cursor-pointer"
:class="{
'elevation-4': isHovering || isDragging,
'elevation-0': !(isHovering || isDragging),
}"
:style="{
position: 'relative',
overflow: 'hidden',
transition: 'all 0.3s ease',
background:
isHovering || isDragging
? 'rgba(var(--v-theme-primary), 0.05)'
: 'rgba(0, 0, 0, 0.02)',
border: `2px dashed ${isHovering || isDragging ? 'rgb(var(--v-theme-primary))' : '#e0e0e0'}`,
transform: isHovering || isDragging ? 'translateY(-2px)' : 'none',
pointerEvents: loading ? 'none' : 'auto',
opacity: loading ? 0.6 : 1,
}"
rounded="xl"
@click="triggerFileDialog"
@dragover.prevent="isDragging = true"
@dragleave.prevent="isDragging = false"
@drop.prevent="handleDrop"
>
<v-card-text class="pa-8">
<v-sheet
class="mx-auto mb-6 d-flex align-center justify-center"
:color="isHovering || isDragging ? 'primary' : 'grey-lighten-2'"
:style="{
width: '80px',
height: '80px',
transition: 'all 0.3s ease',
}"
rounded="circle"
:elevation="isHovering || isDragging ? 4 : 0"
>
<v-icon
:icon="loading ? 'mdi-loading' : 'mdi-cloud-upload'"
size="40"
:color="isHovering || isDragging ? 'white' : 'grey-darken-1'"
:class="{ rotating: loading }"
/>
</v-sheet>

<div
class="text-h6 font-weight-bold mb-1"
:class="
isHovering || isDragging ? 'text-primary' : 'text-grey-darken-2'
"
style="transition: color 0.3s ease"
>
{{ loading ? loadingText : isDragging ? dropText : idleText }}
</div>

<div v-if="showExtensions" class="text-body-2 text-grey-darken-1">
{{ accept ? `(${accept} files)` : "All files allowed" }}
</div>
</v-card-text>

<input
ref="fileInput"
type="file"
class="d-none"
:multiple="multiple"
:accept="accept"
@change="handleFileSelect"
/>
</v-card>
</v-hover>
</template>

<script setup>
const props = defineProps({
multiple: { type: Boolean, default: false },
accept: { type: String, default: "" },
loading: { type: Boolean, default: false },
showExtensions: { type: Boolean, default: true },
idleText: { type: String, default: "Click or Drag & Drop files" },
dropText: { type: String, default: "Drop to upload" },
loadingText: { type: String, default: "Uploading..." },
})

const emit = defineEmits(["files-selected"])

const isDragging = ref(false)
const fileInput = ref(null)

const triggerFileDialog = () => fileInput.value?.click()

function handleDrop(e) {
isDragging.value = false
const files = Array.from(e.dataTransfer.files)
emit("files-selected", files)
}

function handleFileSelect(e) {
const files = Array.from(e.target.files)
emit("files-selected", files)
e.target.value = ""
}
</script>

<style scoped>
.rotating {
animation: rotate 1s linear infinite;
}

@keyframes rotate {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
</style>
3 changes: 2 additions & 1 deletion app/components/FileSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
},
{ deep: true },
)
watch(props.auto_upload, (newVal) => {
const auto_upload_prop = toRef(props, "auto_upload")
watch(auto_upload_prop, (newVal) => {
auto_upload.value = newVal
})

Expand Down
111 changes: 76 additions & 35 deletions app/components/FileUploader.vue
Original file line number Diff line number Diff line change
@@ -1,31 +1,48 @@
<template>
<v-row>
<v-col class="pa-0">
<v-file-input
v-model="internal_files"
:multiple="props.multiple"
:label="label"
:accept="props.accept"
:rules="[(value) => !!value || 'The file is mandatory']"
<DragAndDrop
:multiple="props.multiple"
:accept="props.accept"
:loading="loading"
:show-extensions="false"
@files-selected="processSelectedFiles"
/>

<div v-if="internal_files.length" class="mt-6">
<div class="text-subtitle-2 font-weight-bold mb-3 d-flex align-center">
<v-icon icon="mdi-file-check" class="mr-2" color="primary" />
Selected Files
<v-chip size="x-small" class="ml-2" color="primary" variant="flat">
{{ internal_files.length }}
</v-chip>
</div>
<div class="d-flex flex-wrap gap-2">
<v-chip
v-for="(file, index) in internal_files"
:key="index"
closable
size="small"
color="primary"
:hide-input="props.mini"
:hide-details="props.mini"
chips
counter
show-size
@click:clear="clear()"
/>
</v-col>
</v-row>
<v-row v-if="!props.auto_upload">
variant="tonal"
class="font-weight-medium"
@click:close="removeFile(index)"
>
<v-icon start size="16">mdi-file-outline</v-icon>
{{ file.name }}
</v-chip>
</div>
</div>

<v-row v-if="!props.auto_upload && internal_files.length" class="mt-6">
<v-col cols="auto">
<v-btn
color="primary"
:disabled="!internal_files.length && !files_uploaded"
:loading="loading"
class="pa-2"
class="text-none px-8"
rounded="lg"
elevation="2"
@click="upload_files"
>
<v-icon start>mdi-upload</v-icon>
Upload file(s)
</v-btn>
</v-col>
Expand All @@ -35,9 +52,11 @@
<script setup>
import schemas from "@geode/opengeodeweb-back/opengeodeweb_back_schemas.json"
import { upload_file } from "@ogw_front/utils/upload_file"
import DragAndDrop from "@ogw_front/components/DragAndDrop"

const schema = schemas.opengeodeweb_back.upload_file

const emit = defineEmits(["files_uploaded", "decrement_step"])
const emit = defineEmits(["files_uploaded", "decrement_step", "reset_values"])

const props = defineProps({
multiple: { type: Boolean, required: true },
Expand All @@ -47,15 +66,28 @@
mini: { type: Boolean, required: false, default: false },
})

const label = props.multiple
? "Please select file(s) to import"
: "Please select a file to import"
const internal_files = ref(props.files)
const loading = ref(false)
const files_uploaded = ref(false)

const toggle_loading = useToggle(loading)

function processSelectedFiles(files) {
if (props.multiple) {
internal_files.value = [...internal_files.value, ...files]
} else {
internal_files.value = [files[0]]
}
}

function removeFile(index) {
internal_files.value.splice(index, 1)
if (internal_files.value.length === 0) {
files_uploaded.value = false
emit("files_uploaded", [])
}
}

async function upload_files() {
toggle_loading()
var promise_array = []
Expand Down Expand Up @@ -92,11 +124,6 @@
}
}

function clear() {
internal_files.value = []
emit("files_uploaded", internal_files.value)
}

watch(
() => props.files,
(newVal) => {
Expand All @@ -107,17 +134,31 @@

watch(internal_files, (value) => {
files_uploaded.value = false
if (props.auto_upload) {
if (props.multiple.value == false) {
internal_files.value = [value]
}
if (props.auto_upload && value.length > 0) {
upload_files()
}
})
</script>

<style scoped>
.div.v-input__details {
display: none;
.rotating {
animation: rotate 1s linear infinite;
}

@keyframes rotate {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

.gap-2 {
gap: 8px;
}

.text-primary {
color: rgb(var(--v-theme-primary)) !important;
}
</style>
2 changes: 1 addition & 1 deletion app/components/Launcher.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
align-self="center"
style="z-index: 1000"
>
<Recaptcha :color="'secondary'" />
<Recaptcha :button_color="'secondary'" />
</v-col>
<v-col v-else-if="infraStore.status == Status.CREATING">
<Loading />
Expand Down
7 changes: 6 additions & 1 deletion app/components/Recaptcha.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<VCol cols="4" class="d-flex justify-center align-center">
<VBtn
:text="props.button_label"
:color="props.button_color"
:color="props.color || props.button_color"
@click="submit_recaptcha"
/>
</VCol>
Expand All @@ -53,11 +53,16 @@
required: false,
default: "white",
},
color: {
type: String,
required: false,
},
})
const infraStore = useInfraStore()
const name = ref("")
const email = ref("")
const launch = ref(false)
const valid = ref(false)
const emailRules = [
(value) => {
if (value) {
Expand Down
Loading
Loading