fix: moved util functions to util.js
This commit is contained in:
parent
c86d080306
commit
21379b6cf4
@ -56,7 +56,13 @@ import FileAudioIcon from '@/components/Icons/FileAudioIcon.vue'
|
|||||||
import FileTextIcon from '@/components/Icons/FileTextIcon.vue'
|
import FileTextIcon from '@/components/Icons/FileTextIcon.vue'
|
||||||
import FileVideoIcon from '@/components/Icons/FileVideoIcon.vue'
|
import FileVideoIcon from '@/components/Icons/FileVideoIcon.vue'
|
||||||
import { Tooltip } from 'frappe-ui'
|
import { Tooltip } from 'frappe-ui'
|
||||||
import { dateFormat, timeAgo, dateTooltipFormat } from '@/utils'
|
import {
|
||||||
|
dateFormat,
|
||||||
|
timeAgo,
|
||||||
|
dateTooltipFormat,
|
||||||
|
convertSize,
|
||||||
|
isImage,
|
||||||
|
} from '@/utils'
|
||||||
import FeatherIcon from 'frappe-ui/src/components/FeatherIcon.vue'
|
import FeatherIcon from 'frappe-ui/src/components/FeatherIcon.vue'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
@ -75,23 +81,6 @@ function deleteAttachment() {
|
|||||||
// FilesUploadHandler.deleteAttachment(attachment)
|
// FilesUploadHandler.deleteAttachment(attachment)
|
||||||
}
|
}
|
||||||
|
|
||||||
function convertSize(size) {
|
|
||||||
const units = ['B', 'KB', 'MB', 'GB', 'TB']
|
|
||||||
let unitIndex = 0
|
|
||||||
while (size > 1024) {
|
|
||||||
size /= 1024
|
|
||||||
unitIndex++
|
|
||||||
}
|
|
||||||
return `${size?.toFixed(2)} ${units[unitIndex]}`
|
|
||||||
}
|
|
||||||
|
|
||||||
function isImage(type) {
|
|
||||||
if (!type) return false
|
|
||||||
return ['png', 'jpg', 'jpeg', 'gif', 'svg', 'bmp', 'webp'].includes(
|
|
||||||
type.toLowerCase(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function fileIcon(type) {
|
function fileIcon(type) {
|
||||||
if (!type) return FileTextIcon
|
if (!type) return FileTextIcon
|
||||||
let audioExtentions = ['wav', 'mp3', 'ogg', 'flac', 'aac']
|
let audioExtentions = ['wav', 'mp3', 'ogg', 'flac', 'aac']
|
||||||
|
|||||||
@ -126,7 +126,7 @@
|
|||||||
import FileTextIcon from '@/components/Icons/FileTextIcon.vue'
|
import FileTextIcon from '@/components/Icons/FileTextIcon.vue'
|
||||||
import FileAudioIcon from '@/components/Icons/FileAudioIcon.vue'
|
import FileAudioIcon from '@/components/Icons/FileAudioIcon.vue'
|
||||||
import FileVideoIcon from '@/components/Icons/FileVideoIcon.vue'
|
import FileVideoIcon from '@/components/Icons/FileVideoIcon.vue'
|
||||||
import { createToast, dateFormat } from '@/utils'
|
import { createToast, dateFormat, convertSize } from '@/utils'
|
||||||
import { FormControl, CircularProgressBar, createResource } from 'frappe-ui'
|
import { FormControl, CircularProgressBar, createResource } from 'frappe-ui'
|
||||||
import { ref, onMounted } from 'vue'
|
import { ref, onMounted } from 'vue'
|
||||||
|
|
||||||
@ -366,16 +366,6 @@ function removeFile(name) {
|
|||||||
files.value = files.value.filter((file) => file.name !== name)
|
files.value = files.value.filter((file) => file.name !== name)
|
||||||
}
|
}
|
||||||
|
|
||||||
function convertSize(size) {
|
|
||||||
const units = ['B', 'KB', 'MB', 'GB', 'TB']
|
|
||||||
let unitIndex = 0
|
|
||||||
while (size > 1024) {
|
|
||||||
size /= 1024
|
|
||||||
unitIndex++
|
|
||||||
}
|
|
||||||
return `${size?.toFixed(2)} ${units[unitIndex]}`
|
|
||||||
}
|
|
||||||
|
|
||||||
function fileIcon(type) {
|
function fileIcon(type) {
|
||||||
if (type?.startsWith('audio')) {
|
if (type?.startsWith('audio')) {
|
||||||
return FileAudioIcon
|
return FileAudioIcon
|
||||||
|
|||||||
@ -39,7 +39,7 @@ import {
|
|||||||
Badge,
|
Badge,
|
||||||
ErrorMessage,
|
ErrorMessage,
|
||||||
} from 'frappe-ui'
|
} from 'frappe-ui'
|
||||||
import { evaluate_depends_on_value, createToast } from '@/utils'
|
import { evaluateDependsOnValue, createToast } from '@/utils'
|
||||||
import { ref, computed } from 'vue'
|
import { ref, computed } from 'vue'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
@ -123,11 +123,11 @@ const sections = computed(() => {
|
|||||||
_sections[_sections.length - 1].fields.push({
|
_sections[_sections.length - 1].fields.push({
|
||||||
...field,
|
...field,
|
||||||
filters: field.link_filters && JSON.parse(field.link_filters),
|
filters: field.link_filters && JSON.parse(field.link_filters),
|
||||||
display_via_depends_on: evaluate_depends_on_value(
|
display_via_depends_on: evaluateDependsOnValue(
|
||||||
field.depends_on,
|
field.depends_on,
|
||||||
data.doc,
|
data.doc,
|
||||||
),
|
),
|
||||||
mandatory_via_depends_on: evaluate_depends_on_value(
|
mandatory_via_depends_on: evaluateDependsOnValue(
|
||||||
field.mandatory_depends_on,
|
field.mandatory_depends_on,
|
||||||
data.doc,
|
data.doc,
|
||||||
),
|
),
|
||||||
|
|||||||
@ -247,7 +247,7 @@ export function _eval(code, context = {}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function evaluate_depends_on_value(expression, doc) {
|
export function evaluateDependsOnValue(expression, doc) {
|
||||||
if (!expression) return true
|
if (!expression) return true
|
||||||
if (!doc) return true
|
if (!doc) return true
|
||||||
|
|
||||||
@ -274,3 +274,20 @@ export function evaluate_depends_on_value(expression, doc) {
|
|||||||
|
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function convertSize(size) {
|
||||||
|
const units = ['B', 'KB', 'MB', 'GB', 'TB']
|
||||||
|
let unitIndex = 0
|
||||||
|
while (size > 1024) {
|
||||||
|
size /= 1024
|
||||||
|
unitIndex++
|
||||||
|
}
|
||||||
|
return `${size?.toFixed(2)} ${units[unitIndex]}`
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isImage(extention) {
|
||||||
|
if (!extention) return false
|
||||||
|
return ['png', 'jpg', 'jpeg', 'gif', 'svg', 'bmp', 'webp'].includes(
|
||||||
|
extention.toLowerCase(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user