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 FileVideoIcon from '@/components/Icons/FileVideoIcon.vue'
|
||||
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'
|
||||
|
||||
const props = defineProps({
|
||||
@ -75,23 +81,6 @@ function deleteAttachment() {
|
||||
// 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) {
|
||||
if (!type) return FileTextIcon
|
||||
let audioExtentions = ['wav', 'mp3', 'ogg', 'flac', 'aac']
|
||||
|
||||
@ -126,7 +126,7 @@
|
||||
import FileTextIcon from '@/components/Icons/FileTextIcon.vue'
|
||||
import FileAudioIcon from '@/components/Icons/FileAudioIcon.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 { ref, onMounted } from 'vue'
|
||||
|
||||
@ -366,16 +366,6 @@ function removeFile(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) {
|
||||
if (type?.startsWith('audio')) {
|
||||
return FileAudioIcon
|
||||
|
||||
@ -39,7 +39,7 @@ import {
|
||||
Badge,
|
||||
ErrorMessage,
|
||||
} from 'frappe-ui'
|
||||
import { evaluate_depends_on_value, createToast } from '@/utils'
|
||||
import { evaluateDependsOnValue, createToast } from '@/utils'
|
||||
import { ref, computed } from 'vue'
|
||||
|
||||
const props = defineProps({
|
||||
@ -123,11 +123,11 @@ const sections = computed(() => {
|
||||
_sections[_sections.length - 1].fields.push({
|
||||
...field,
|
||||
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,
|
||||
data.doc,
|
||||
),
|
||||
mandatory_via_depends_on: evaluate_depends_on_value(
|
||||
mandatory_via_depends_on: evaluateDependsOnValue(
|
||||
field.mandatory_depends_on,
|
||||
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 (!doc) return true
|
||||
|
||||
@ -274,3 +274,20 @@ export function evaluate_depends_on_value(expression, doc) {
|
||||
|
||||
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