fix: better call logs list

This commit is contained in:
Shariq Ansari 2023-08-30 15:14:58 +05:30
parent f0514f1a21
commit dd35b615d5
4 changed files with 58 additions and 38 deletions

View File

@ -1,13 +1,14 @@
<template> <template>
<Tooltip <Tooltip
:text="tooltipText" :text="tooltipText"
:html="tooltipHTML"
class="flex items-center space-x-2.5" class="flex items-center space-x-2.5"
> >
<slot name="prefix"></slot> <slot name="prefix"></slot>
<div class="text-base truncate"> <slot>
{{ label }} <div class="text-base truncate">
</div> {{ label }}
</div>
</slot>
</Tooltip> </Tooltip>
</template> </template>
<script setup> <script setup>
@ -26,13 +27,6 @@ const props = defineProps({
}, },
}) })
const tooltipHTML = computed(() => {
if (props.type === 'html') {
return props.value?.toString()
}
return ''
})
const tooltipText = computed(() => { const tooltipText = computed(() => {
if (props.type === 'html') return '' if (props.type === 'html') return ''
if (props.type === 'pretty_date') { if (props.type === 'pretty_date') {

View File

@ -41,7 +41,10 @@
:key="column.key" :key="column.key"
:class="[column.size, column.align]" :class="[column.size, column.align]"
> >
<ListRowItem :value="getValue(row[column.key]).label" :type="column.type"> <ListRowItem
:value="getValue(row[column.key]).label"
:type="column.type"
>
<template #prefix> <template #prefix>
<div v-if="column.type === 'indicator'"> <div v-if="column.type === 'indicator'">
<IndicatorIcon :class="getValue(row[column.key]).color" /> <IndicatorIcon :class="getValue(row[column.key]).color" />
@ -65,7 +68,21 @@
shape="square" shape="square"
/> />
</div> </div>
<div v-else-if="column.type === 'icon'">
<FeatherIcon
:name="getValue(row[column.key]).icon"
class="h-3 w-3"
/>
</div>
</template> </template>
<div v-if="column.type === 'badge'">
<Badge
:variant="'subtle'"
:theme="row[column.key].color"
size="md"
:label="row[column.key].label"
/>
</div>
</ListRowItem> </ListRowItem>
</div> </div>
</router-link> </router-link>
@ -116,7 +133,7 @@
<script setup> <script setup>
import IndicatorIcon from '@/components/Icons/IndicatorIcon.vue' import IndicatorIcon from '@/components/Icons/IndicatorIcon.vue'
import ListRowItem from '@/components/ListRowItem.vue' import ListRowItem from '@/components/ListRowItem.vue'
import { Checkbox, Avatar } from 'frappe-ui' import { Checkbox, Avatar, Badge, FeatherIcon } from 'frappe-ui'
import { reactive, computed } from 'vue' import { reactive, computed } from 'vue'
const props = defineProps({ const props = defineProps({

View File

@ -26,6 +26,7 @@ import LayoutHeader from '@/components/LayoutHeader.vue'
import Breadcrumbs from '@/components/Breadcrumbs.vue' import Breadcrumbs from '@/components/Breadcrumbs.vue'
import SortIcon from '@/components/Icons/SortIcon.vue' import SortIcon from '@/components/Icons/SortIcon.vue'
import FilterIcon from '@/components/Icons/FilterIcon.vue' import FilterIcon from '@/components/Icons/FilterIcon.vue'
import { secondsToDuration } from '@/utils'
import { Button, createListResource } from 'frappe-ui' import { Button, createListResource } from 'frappe-ui'
import { computed } from 'vue' import { computed } from 'vue'
@ -48,9 +49,9 @@ const callLogs = createListResource({
'status', 'status',
'type', 'type',
'recording_url', 'recording_url',
'modified', 'creation',
], ],
orderBy: 'modified desc', orderBy: 'creation desc',
cache: 'Call Logs', cache: 'Call Logs',
pageLength: 999, pageLength: 999,
auto: true, auto: true,
@ -72,36 +73,24 @@ const columns = [
{ {
label: 'Duration', label: 'Duration',
key: 'duration', key: 'duration',
type: 'data', type: 'icon',
size: 'w-20', size: 'w-20',
}, },
{ {
label: 'Type', label: 'Type',
key: 'type', key: 'type',
type: 'data', type: 'icon',
size: 'w-32', size: 'w-32',
}, },
{ {
label: 'Status', label: 'Status',
key: 'status', key: 'status',
type: 'data', type: 'badge',
size: 'w-32', size: 'w-32',
}, },
{ {
label: 'Start Time', label: 'Created on',
key: 'start_time', key: 'creation',
type: 'data',
size: 'w-32',
},
{
label: 'End Time',
key: 'end_time',
type: 'data',
size: 'w-32',
},
{
label: 'Last modified',
key: 'modified',
type: 'pretty_date', type: 'pretty_date',
size: 'w-28', size: 'w-28',
}, },
@ -113,12 +102,19 @@ const rows = computed(() => {
name: callLog.name, name: callLog.name,
from: callLog.from, from: callLog.from,
to: callLog.to, to: callLog.to,
duration: callLog.duration, duration: {
type: callLog.type, label: secondsToDuration(callLog.duration),
status: callLog.status, icon: 'clock',
start_time: callLog.start_time, },
end_time: callLog.end_time, type: {
modified: callLog.modified, label: callLog.type,
icon: callLog.type === 'Incoming' ? 'phone-incoming' : 'phone-outgoing',
},
status: {
label: callLog.status,
color: callLog.status === 'Completed' ? 'green' : 'gray',
},
creation: callLog.creation,
} }
}) })
}) })

View File

@ -99,3 +99,16 @@ export function htmlToText(html) {
div.innerHTML = html div.innerHTML = html
return div.textContent || div.innerText || '' return div.textContent || div.innerText || ''
} }
export function secondsToDuration(seconds) {
const hours = Math.floor(seconds / 3600)
const minutes = Math.floor((seconds % 3600) / 60)
const _seconds = Math.floor((seconds % 3600) % 60)
if (hours == 0 && minutes == 0) {
return `${_seconds}s`
} else if (hours == 0) {
return `${minutes}m ${_seconds}s`
}
return `${hours}h ${minutes}m ${_seconds}s`
}