@testdracul/media-frontend 2.0.0 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +9 -5
- package/.env.development +0 -4
- package/.env.example +0 -3
- package/.eslintrc.json +0 -25
- package/babel.config.js +0 -5
- package/docs-en.md +0 -45
- package/docs-es.md +0 -45
- package/src/components/CsvWebViewer/CsvWebViewer.vue +0 -81
- package/src/components/CsvWebViewer/index.ts +0 -4
- package/src/components/FileUpload/FileUpload.vue +0 -94
- package/src/components/FileUpload/index.ts +0 -4
- package/src/components/FileUploadButton/FileUploadButton.vue +0 -127
- package/src/components/FileUploadButton/index.ts +0 -4
- package/src/components/FileUploadExpiration/FileUploadExpiration.vue +0 -274
- package/src/components/FileUploadExpiration/index.ts +0 -4
- package/src/components/FileUploadExpress/FileUploadExpress.vue +0 -208
- package/src/components/FileUploadExpress/index.ts +0 -4
- package/src/components/FileView/FileView.vue +0 -336
- package/src/components/FileView/index.ts +0 -4
- package/src/components/GroupsShow/GroupsShow.vue +0 -40
- package/src/components/GroupsShow/index.ts +0 -4
- package/src/components/MediaField/MediaField.vue +0 -62
- package/src/components/MediaField/index.ts +0 -4
- package/src/components/PdfWebViewer/PdfWebViewer.vue +0 -81
- package/src/components/PdfWebViewer/index.ts +0 -4
- package/src/components/UsersShow/UsersShow.vue +0 -39
- package/src/components/UsersShow/index.ts +0 -4
- package/src/components/XlsxWebViewer/XlsxWebViewer.vue +0 -70
- package/src/components/XlsxWebViewer/index.ts +0 -4
- package/src/helpers/redeableBytes.ts +0 -9
- package/src/i18n/index.ts +0 -22
- package/src/i18n/messages/DocMessages.ts +0 -31
- package/src/i18n/messages/ExtraMessages.ts +0 -29
- package/src/i18n/messages/FileMessages.ts +0 -223
- package/src/i18n/messages/UserStorageMessages.ts +0 -145
- package/src/i18n/permissions/FilePermissionMessages.ts +0 -50
- package/src/i18n/permissions/OldPermissionMessages.ts +0 -59
- package/src/i18n/permissions/UserStoragePermissionMessages.ts +0 -40
- package/src/index.ts +0 -70
- package/src/mixins/readableBytesMixin.ts +0 -9
- package/src/pages/FileManagementPage/FileCreate/FileCreate.vue +0 -108
- package/src/pages/FileManagementPage/FileCreate/index.ts +0 -3
- package/src/pages/FileManagementPage/FileCrud/FileCrud.vue +0 -133
- package/src/pages/FileManagementPage/FileCrud/index.ts +0 -4
- package/src/pages/FileManagementPage/FileDelete/FileDelete.vue +0 -61
- package/src/pages/FileManagementPage/FileDelete/index.ts +0 -3
- package/src/pages/FileManagementPage/FileFilters/FileFilters.vue +0 -150
- package/src/pages/FileManagementPage/FileFilters/index.ts +0 -3
- package/src/pages/FileManagementPage/FileForm/FileForm.vue +0 -184
- package/src/pages/FileManagementPage/FileForm/UserCombobox.vue +0 -66
- package/src/pages/FileManagementPage/FileForm/index.ts +0 -3
- package/src/pages/FileManagementPage/FileList/FileEditButton.vue +0 -410
- package/src/pages/FileManagementPage/FileList/FileList.vue +0 -178
- package/src/pages/FileManagementPage/FileList/index.ts +0 -4
- package/src/pages/FileManagementPage/FileShow/FileShow.vue +0 -23
- package/src/pages/FileManagementPage/FileShow/FileShowData.vue +0 -35
- package/src/pages/FileManagementPage/FileShow/index.ts +0 -3
- package/src/pages/FileManagementPage/FileUpdate/FileUpdate.vue +0 -107
- package/src/pages/FileManagementPage/FileUpdate/index.ts +0 -4
- package/src/pages/FileManagementPage/index.vue +0 -20
- package/src/pages/MediaDocPage/MediaDocCard.vue +0 -35
- package/src/pages/MediaDocPage/MediaDocPage.vue +0 -78
- package/src/pages/UserStoragePage/UserStorage.vue +0 -311
- package/src/pages/UserStoragePage/UserStorageForm/UserStorageForm.vue +0 -172
- package/src/pages/UserStoragePage/UserStorageUpdate/UserStorageUpdate.vue +0 -91
- package/src/pages/UserStoragePage/index.vue +0 -14
- package/src/providers/FileMetricsProvider.ts +0 -47
- package/src/providers/FileProvider.ts +0 -60
- package/src/providers/UploadProvider.ts +0 -32
- package/src/providers/UserStorageProvider.ts +0 -47
- package/src/providers/gql/almacenamientoPorUsuario.graphql +0 -10
- package/src/providers/gql/cantidadArchivosPorUsuario.graphql +0 -10
- package/src/providers/gql/fetchMediaVariables.graphql +0 -6
- package/src/providers/gql/fileCreate.graphql +0 -27
- package/src/providers/gql/fileDelete.graphql +0 -7
- package/src/providers/gql/fileFetch.graphql +0 -29
- package/src/providers/gql/fileFind.graphql +0 -29
- package/src/providers/gql/fileGlobalMetrics.graphql +0 -6
- package/src/providers/gql/filePaginate.graphql +0 -38
- package/src/providers/gql/fileUpdate.graphql +0 -29
- package/src/providers/gql/fileUpload.graphql +0 -29
- package/src/providers/gql/fileUploadAnonymous.graphql +0 -25
- package/src/providers/gql/fileUserMetrics.graphql +0 -9
- package/src/providers/gql/userStorageFetch.graphql +0 -17
- package/src/providers/gql/userStorageFindByUser.graphql +0 -17
- package/src/providers/gql/userStorageUpdate.graphql +0 -31
- package/src/routes/index.ts +0 -32
- package/vite.config.ts +0 -65
- package/vue.config.js +0 -22
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@testdracul/media-frontend",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/dracul-media-frontend.umd.js",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"preview": "vite preview"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@testdracul/common-frontend": "^2.0.
|
|
27
|
-
"@testdracul/dayjs-frontend": "^2.0.
|
|
28
|
-
"@testdracul/user-frontend": "^2.0.
|
|
26
|
+
"@testdracul/common-frontend": "^2.0.3",
|
|
27
|
+
"@testdracul/dayjs-frontend": "^2.0.3",
|
|
28
|
+
"@testdracul/user-frontend": "^2.0.3",
|
|
29
29
|
"buffer": "^6.0.3",
|
|
30
30
|
"papaparse": "^5.4.1",
|
|
31
31
|
"vue-pdf-embed": "^1.2.1",
|
|
@@ -52,5 +52,9 @@
|
|
|
52
52
|
"vite-plugin-vuetify": "^2.0.0",
|
|
53
53
|
"vue-tsc": "^2.0.19"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "e50b2eb6f93260ad0efdf03729c6718e1c8b62de",
|
|
56
|
+
"files": [
|
|
57
|
+
"dist",
|
|
58
|
+
"lib"
|
|
59
|
+
]
|
|
56
60
|
}
|
package/.env.development
DELETED
package/.env.example
DELETED
package/.eslintrc.json
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"root": true,
|
|
3
|
-
"env": {
|
|
4
|
-
"node": true
|
|
5
|
-
},
|
|
6
|
-
"extends": [
|
|
7
|
-
"plugin:vue/essential",
|
|
8
|
-
"eslint:recommended"
|
|
9
|
-
],
|
|
10
|
-
"parserOptions": {
|
|
11
|
-
"parser": "babel-eslint"
|
|
12
|
-
},
|
|
13
|
-
"rules": {},
|
|
14
|
-
"overrides": [
|
|
15
|
-
{
|
|
16
|
-
"files": [
|
|
17
|
-
"**/__tests__/*.{j,t}s?(x)",
|
|
18
|
-
"**/tests/unit/**/*.spec.{j,t}s?(x)"
|
|
19
|
-
],
|
|
20
|
-
"env": {
|
|
21
|
-
"jest": true
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
]
|
|
25
|
-
}
|
package/babel.config.js
DELETED
package/docs-en.md
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
#Dracul module: media-frontend
|
|
2
|
-
|
|
3
|
-
The dracul media module provides a file storage service and exposes Vue pages and components ready to integrate.
|
|
4
|
-
|
|
5
|
-
## Interface
|
|
6
|
-
This module provides the user interface for managing the file service. Includes pages, components, and providers.
|
|
7
|
-
|
|
8
|
-
## Pages
|
|
9
|
-
|
|
10
|
-
### File management page
|
|
11
|
-
FileManagementPage allows you to manage files, being able to list files, upload files, edit tags and description, delete files and view the metadata, URL and preview of the files.
|
|
12
|
-
|
|
13
|
-
** route **: / file management
|
|
14
|
-
|
|
15
|
-
### Files control panel page
|
|
16
|
-
|
|
17
|
-
FileDashboardPage allows you to view summary information about stored files
|
|
18
|
-
|
|
19
|
-
** route **: / file-dashboard
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
## Components
|
|
23
|
-
|
|
24
|
-
### Upload file
|
|
25
|
-
Exposes a modal that allows uploading a file
|
|
26
|
-
|
|
27
|
-
### FileUploadExpress
|
|
28
|
-
It exposes a button that allows to upload a file. The button shows a loading spinner while the file is uploaded, at the end it shows a different icon depending on the type of file.
|
|
29
|
-
|
|
30
|
-
### FileView
|
|
31
|
-
Show a preview of the file if possible (images, audios, video) otherwise it shows the download link. Metadata sample: file name, MIME type, size, URL
|
|
32
|
-
|
|
33
|
-
## Suppliers
|
|
34
|
-
|
|
35
|
-
### File metric provider
|
|
36
|
-
|
|
37
|
-
FileMetricsProvider exposes querys graphql to the backend module to obtain metrics for the dashboard
|
|
38
|
-
|
|
39
|
-
### File Provider
|
|
40
|
-
|
|
41
|
-
FileProvider exposes querys and graphql mutations to get and edit files from storage.
|
|
42
|
-
|
|
43
|
-
### Upload provider
|
|
44
|
-
|
|
45
|
-
UploadProvider exposes a mutation to upload the files.
|
package/docs-es.md
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
#Dracul modulo: media-frontend
|
|
2
|
-
|
|
3
|
-
El modulo media de dracul brinda un servicio de almacenamiento de archivos y expone páginas y componentes Vue listo para integrar.
|
|
4
|
-
|
|
5
|
-
## Frontend
|
|
6
|
-
Este modulo provee la interfaz de usuario que permite gestionar el servicio de archivos. Incluye páginas, componentes y providers.
|
|
7
|
-
|
|
8
|
-
## Pages
|
|
9
|
-
|
|
10
|
-
### File Management Page
|
|
11
|
-
FileManagementPage permite gestionar archivos pudiendo listar archivos, subir archivos, editar tags y descripción, eliminar archivos y visualizar la metadata, URL y preview de los archivos.
|
|
12
|
-
|
|
13
|
-
**ruta**: /file-management
|
|
14
|
-
|
|
15
|
-
### File Dashboard Page
|
|
16
|
-
|
|
17
|
-
FileDashboardPage permite visualizar información sumarizada sobre los archivos almacenados
|
|
18
|
-
|
|
19
|
-
**ruta**: /file-dashboard
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
## Components
|
|
23
|
-
|
|
24
|
-
### FileUpload
|
|
25
|
-
Expone un modal que permite subir un archivo
|
|
26
|
-
|
|
27
|
-
### FileUploadExpress
|
|
28
|
-
Expone un boton que permite subir un archivo. El boton muestra un spinner de loading mientras el archivo se sube, al finalizar muestra un icono diferente segun el tipo de archivo.
|
|
29
|
-
|
|
30
|
-
### FileView
|
|
31
|
-
Expone una preview del archivo si es posible (imagenes, audios, video) de lo contrario muestra el link de descarga. Muestra metadata: filename, mimetype, size, url
|
|
32
|
-
|
|
33
|
-
## Providers
|
|
34
|
-
|
|
35
|
-
### File Metrics Provider
|
|
36
|
-
|
|
37
|
-
FileMetricsProvider expone querys graphql al módulo backend para la obtención de métricas para el dashboard
|
|
38
|
-
|
|
39
|
-
### File Provider
|
|
40
|
-
|
|
41
|
-
FileProvider expone querys y mutations graphql para obtener y editar los archivos del storage.
|
|
42
|
-
|
|
43
|
-
### Upload Provider
|
|
44
|
-
|
|
45
|
-
UploadProvider expone una mutation para subir los archivos.
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div>
|
|
3
|
-
<v-data-table
|
|
4
|
-
class="mx-auto elevation-1"
|
|
5
|
-
height="50vh"
|
|
6
|
-
fixed-header
|
|
7
|
-
:hide-default-footer="!pagination"
|
|
8
|
-
:items-per-page="10"
|
|
9
|
-
:disable-pagination="!pagination"
|
|
10
|
-
:headers="headers"
|
|
11
|
-
:items="content"
|
|
12
|
-
:no-data-text="noDataText"
|
|
13
|
-
></v-data-table>
|
|
14
|
-
<snackbar
|
|
15
|
-
v-model="snackbarMessage"
|
|
16
|
-
:color="snackbarColor"
|
|
17
|
-
:timeout="snackbarTimeOut"
|
|
18
|
-
@update:modelValue="val => !val && (snackbarMessage = null)"
|
|
19
|
-
/>
|
|
20
|
-
</div>
|
|
21
|
-
</template>
|
|
22
|
-
|
|
23
|
-
<script setup>
|
|
24
|
-
import { ref, computed, onMounted } from 'vue'
|
|
25
|
-
import { useI18n } from 'vue-i18n'
|
|
26
|
-
import { Snackbar } from "@testdracul/common-frontend";
|
|
27
|
-
import Papa from 'papaparse';
|
|
28
|
-
|
|
29
|
-
const { t } = useI18n()
|
|
30
|
-
|
|
31
|
-
const props = defineProps({
|
|
32
|
-
url: {type: String}
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
const headers = ref([])
|
|
36
|
-
const content = ref([])
|
|
37
|
-
const snackbarColor = ref("")
|
|
38
|
-
const snackbarMessage = ref("")
|
|
39
|
-
const snackbarTimeOut = ref(3000)
|
|
40
|
-
const noDataText = ref("No se pudo procesar la información del csv. Por favor intente nuevamente más tarde!")
|
|
41
|
-
|
|
42
|
-
const pagination = computed(() => content.value.length > 10)
|
|
43
|
-
|
|
44
|
-
const parseFileCsv = () => {
|
|
45
|
-
Papa.parse(props.url, {
|
|
46
|
-
download: true,
|
|
47
|
-
delimiter: "",
|
|
48
|
-
header: true,
|
|
49
|
-
skipEmptyLines: true,
|
|
50
|
-
complete: function(results) {
|
|
51
|
-
if(results.errors.length == 0) {
|
|
52
|
-
results.meta.fields.forEach(elem => {
|
|
53
|
-
let width = elem.length * 6
|
|
54
|
-
|
|
55
|
-
results.data.forEach(data => {
|
|
56
|
-
if(width < (data[elem]?.length || 0) * 6) width = (data[elem]?.length || 0) * 6
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
const item = {title: elem, value: elem, width}
|
|
60
|
-
headers.value.push(item)
|
|
61
|
-
})
|
|
62
|
-
content.value = results.data
|
|
63
|
-
} else {
|
|
64
|
-
snackbarColor.value = "error";
|
|
65
|
-
snackbarMessage.value = t("media.file.errorCsvMessage");
|
|
66
|
-
console.log("Error al parsear el archivo csv, error: ", results.errors[0]);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
})
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
onMounted(() => {
|
|
73
|
-
parseFileCsv()
|
|
74
|
-
})
|
|
75
|
-
</script>
|
|
76
|
-
|
|
77
|
-
<style>
|
|
78
|
-
.tableContainer{
|
|
79
|
-
max-height: 50vh;
|
|
80
|
-
}
|
|
81
|
-
</style>
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<v-card outlined>
|
|
3
|
-
<v-card-text>
|
|
4
|
-
<v-row>
|
|
5
|
-
<v-col cols="12" sm="12">
|
|
6
|
-
<v-btn @click="pickFile"
|
|
7
|
-
class="mx-3"
|
|
8
|
-
fab
|
|
9
|
-
:color="color"
|
|
10
|
-
:loading="loading"
|
|
11
|
-
>
|
|
12
|
-
<v-icon>{{icon}}</v-icon>
|
|
13
|
-
</v-btn>
|
|
14
|
-
<input type="file"
|
|
15
|
-
style="display: none"
|
|
16
|
-
ref="fileInput"
|
|
17
|
-
:accept="accept"
|
|
18
|
-
@change="onFilePicked"
|
|
19
|
-
/>
|
|
20
|
-
</v-col>
|
|
21
|
-
|
|
22
|
-
<v-col v-if="file && file.name" cols="12" sm="12">
|
|
23
|
-
{{file.name}}
|
|
24
|
-
</v-col>
|
|
25
|
-
|
|
26
|
-
<v-col v-if="!!errorMessage" cols="12">
|
|
27
|
-
<v-alert type="error" variant="outlined">
|
|
28
|
-
{{$t(errorMessage)}}
|
|
29
|
-
</v-alert>
|
|
30
|
-
|
|
31
|
-
</v-col>
|
|
32
|
-
|
|
33
|
-
</v-row>
|
|
34
|
-
</v-card-text>
|
|
35
|
-
</v-card>
|
|
36
|
-
|
|
37
|
-
</template>
|
|
38
|
-
|
|
39
|
-
<script setup>
|
|
40
|
-
import { ref } from 'vue'
|
|
41
|
-
import uploadProvider from "../../providers/UploadProvider";
|
|
42
|
-
import {ClientError} from '@testdracul/common-frontend'
|
|
43
|
-
|
|
44
|
-
const props = defineProps({
|
|
45
|
-
autoSubmit: {type: Boolean, default: false}
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
const emit = defineEmits(['fileUploaded'])
|
|
49
|
-
|
|
50
|
-
const title = 'media.file.creating'
|
|
51
|
-
const errorMessage = ref('')
|
|
52
|
-
const inputErrors = ref({})
|
|
53
|
-
const file = ref(null)
|
|
54
|
-
const color = ref('blue-grey')
|
|
55
|
-
const icon = ref('cloud_upload')
|
|
56
|
-
const loading = ref(false)
|
|
57
|
-
const result = ref(null)
|
|
58
|
-
const accept = ref('*')
|
|
59
|
-
const fileInput = ref(null)
|
|
60
|
-
|
|
61
|
-
const pickFile = () => {
|
|
62
|
-
fileInput.value.click()
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const onFilePicked = (e) => {
|
|
66
|
-
file.value = e.target.files[0]
|
|
67
|
-
color.value = "green"
|
|
68
|
-
icon.value = "publish"
|
|
69
|
-
if (props.autoSubmit) {
|
|
70
|
-
upload()
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const upload = () => {
|
|
75
|
-
if (file.value) {
|
|
76
|
-
loading.value = true
|
|
77
|
-
uploadProvider.uploadFile(file.value).then(resultData => {
|
|
78
|
-
result.value = resultData
|
|
79
|
-
emit('fileUploaded')
|
|
80
|
-
}).catch(err => {
|
|
81
|
-
let clientError = new ClientError(err)
|
|
82
|
-
errorMessage.value = clientError.i18nMessage
|
|
83
|
-
}).finally(() => loading.value = false)
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
defineExpose({
|
|
88
|
-
upload
|
|
89
|
-
})
|
|
90
|
-
</script>
|
|
91
|
-
|
|
92
|
-
<style scoped>
|
|
93
|
-
|
|
94
|
-
</style>
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="d-flex flex-column align-center">
|
|
3
|
-
<input type="file"
|
|
4
|
-
style="display: none"
|
|
5
|
-
ref="fileInput"
|
|
6
|
-
:accept="accept"
|
|
7
|
-
@change="onFilePicked"
|
|
8
|
-
/>
|
|
9
|
-
<v-btn @click="pickFile()"
|
|
10
|
-
icon
|
|
11
|
-
:color="getState.color"
|
|
12
|
-
:loading="loading"
|
|
13
|
-
:size="xLarge ? 'x-large' : 'large'"
|
|
14
|
-
>
|
|
15
|
-
<v-avatar v-if="isImage" size="inherit">
|
|
16
|
-
<v-img :src="getSrc" alt="image"/>
|
|
17
|
-
</v-avatar>
|
|
18
|
-
|
|
19
|
-
<v-icon v-else-if="isAudio">mdi-headset</v-icon>
|
|
20
|
-
<v-icon v-else-if="isVideo">mdi-videocam</v-icon>
|
|
21
|
-
<v-icon v-else>{{ getState.icon }}</v-icon>
|
|
22
|
-
</v-btn>
|
|
23
|
-
|
|
24
|
-
<p class="mb-0 mt-5 text-body-1">{{ !file ? $t('media.file.chooseFile') : file.name}}</p>
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
<v-alert v-if="invalidSize" class="mt-3" border="start" type="error" variant="tonal" density="compact">
|
|
28
|
-
{{ $t("media.file.fileSizeExceeded") }} {{maxFileSize}} Mb
|
|
29
|
-
<template v-slot:append>
|
|
30
|
-
<v-btn variant="text" color="error" @click="resetUpload" class="ml-2">OK</v-btn>
|
|
31
|
-
</template>
|
|
32
|
-
</v-alert>
|
|
33
|
-
|
|
34
|
-
<v-alert v-if="invalidExtension" class="mt-3" border="start" type="error" variant="tonal" density="compact">
|
|
35
|
-
El nuevo fichero debe tener la misma extension que el original
|
|
36
|
-
<template v-slot:append>
|
|
37
|
-
<v-btn variant="text" color="error" @click="resetUpload" class="ml-2">OK</v-btn>
|
|
38
|
-
</template>
|
|
39
|
-
</v-alert>
|
|
40
|
-
|
|
41
|
-
</div>
|
|
42
|
-
</template>
|
|
43
|
-
|
|
44
|
-
<script setup>
|
|
45
|
-
import { ref, computed } from 'vue'
|
|
46
|
-
|
|
47
|
-
const props = defineProps({
|
|
48
|
-
accept: {type: String, default: '*'},
|
|
49
|
-
loading: {type: Boolean, default: false},
|
|
50
|
-
xLarge: {type: Boolean, default: false},
|
|
51
|
-
maxFileSize: {type: Number, default: 0},
|
|
52
|
-
errorMessage: {type: String},
|
|
53
|
-
uploadedFile: {type: Object},
|
|
54
|
-
updating: {type: Boolean, default: false},
|
|
55
|
-
oldFileExtension: {type: String},
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
const emit = defineEmits(['fileSelected'])
|
|
59
|
-
|
|
60
|
-
const file = ref(null)
|
|
61
|
-
const invalidSize = ref(false)
|
|
62
|
-
const invalidExtension = ref(false)
|
|
63
|
-
const fileInput = ref(null)
|
|
64
|
-
|
|
65
|
-
const isSelected = computed(() => !!file.value)
|
|
66
|
-
|
|
67
|
-
const getState = computed(() => {
|
|
68
|
-
if (props.loading) return states.loading
|
|
69
|
-
if (props.errorMessage) return states.error
|
|
70
|
-
if (props.uploadedFile) return states.uploaded
|
|
71
|
-
if (isSelected.value) return states.selected
|
|
72
|
-
return states.initial
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
const isImage = computed(() => (props.uploadedFile && props.uploadedFile.type === 'image'))
|
|
76
|
-
const isAudio = computed(() => (props.uploadedFile && props.uploadedFile.type === 'audio'))
|
|
77
|
-
const isVideo = computed(() => (props.uploadedFile && props.uploadedFile.type === 'video'))
|
|
78
|
-
const getSrc = computed(() => (props.uploadedFile && props.uploadedFile.url) ? props.uploadedFile.url : null)
|
|
79
|
-
|
|
80
|
-
const states = {
|
|
81
|
-
initial: { color: 'blue-grey', icon: 'mdi-cloud-upload' },
|
|
82
|
-
selected: { color: 'cyan-darken-3', icon: 'mdi-check-circle' },
|
|
83
|
-
loading: { color: 'amber-darken-3', icon: '' },
|
|
84
|
-
uploaded: { color: 'green-darken-3', icon: 'mdi-magnify-plus' },
|
|
85
|
-
error: { color: 'red-darken-3', icon: 'mdi-alert' }
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const pickFile = () => {
|
|
89
|
-
fileInput.value.click()
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const validateSize = () => {
|
|
93
|
-
const fileSize = (file.value && file.value.size) ? file.value.size / (1024 * 1024) : null;
|
|
94
|
-
if (fileSize > props.maxFileSize) {
|
|
95
|
-
invalidSize.value = true
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const validateExtension = async () => {
|
|
100
|
-
const newFileExtension = '.' + file.value.name.split('.').pop()
|
|
101
|
-
if (props.oldFileExtension != newFileExtension) {
|
|
102
|
-
invalidExtension.value = true
|
|
103
|
-
file.value = null
|
|
104
|
-
} else {
|
|
105
|
-
invalidExtension.value = false
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const onFilePicked = (e) => {
|
|
110
|
-
file.value = e.target.files[0]
|
|
111
|
-
if (file.value) {
|
|
112
|
-
validateSize()
|
|
113
|
-
if (props.updating) validateExtension()
|
|
114
|
-
emit('fileSelected', file.value)
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const resetUpload = () => {
|
|
119
|
-
file.value = null
|
|
120
|
-
invalidSize.value = false
|
|
121
|
-
invalidExtension.value = false
|
|
122
|
-
}
|
|
123
|
-
</script>
|
|
124
|
-
|
|
125
|
-
<style scoped>
|
|
126
|
-
|
|
127
|
-
</style>
|