Skip to content

Commit

Permalink
fix: moved util functions to util.js
Browse files Browse the repository at this point in the history
  • Loading branch information
shariquerik committed Oct 15, 2024
1 parent c86d080 commit 21379b6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 33 deletions.
25 changes: 7 additions & 18 deletions frontend/src/components/Activities/AttachmentArea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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']
Expand Down
12 changes: 1 addition & 11 deletions frontend/src/components/FilesUploader/FilesUploaderArea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/Settings/SettingsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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,
),
Expand Down
19 changes: 18 additions & 1 deletion frontend/src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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(),
)
}

0 comments on commit 21379b6

Please sign in to comment.