revert: made contacts a listview

This commit is contained in:
Shariq Ansari 2023-11-04 00:25:49 +05:30
parent 5acfac869b
commit 5caf5101e2
5 changed files with 205 additions and 51 deletions

View File

@ -25,7 +25,7 @@ def get_contacts():
contacts = frappe.qb.get_query( contacts = frappe.qb.get_query(
"Contact", "Contact",
fields=['name', 'first_name', 'last_name', 'full_name', 'image', 'email_id', 'mobile_no', 'phone', 'salutation', 'company_name'], fields=['name', 'first_name', 'last_name', 'full_name', 'image', 'email_id', 'mobile_no', 'phone', 'salutation', 'company_name', 'modified'],
order_by="first_name asc", order_by="first_name asc",
distinct=True, distinct=True,
).run(as_dict=1) ).run(as_dict=1)

View File

@ -1,14 +1,65 @@
<template> <template>
<ListView <ListView
class="px-5"
v-if="rows"
:columns="columns" :columns="columns"
:rows="rows" :rows="rows"
:options="{
getRowRoute: (row) => ({ name: 'Contact', params: { contactId: row.name } }),
}"
row-key="name" row-key="name"
/> >
<ListHeader class="mx-5" />
<ListRows>
<ListRow
class="mx-5"
v-for="row in rows"
:key="row.name"
v-slot="{ column, item }"
:row="row"
>
<ListRowItem :item="item">
<template #prefix>
<div v-if="column.key === 'full_name'">
<Avatar
v-if="item.label"
class="flex items-center"
:image="item.image"
:label="item.image_label"
size="sm"
/>
</div>
<div v-else-if="column.key === 'company_name'">
<Avatar
v-if="item.label"
class="flex items-center"
:image="item.logo"
:label="item.label"
size="sm"
/>
</div>
<div v-else-if="column.key === 'mobile_no'">
<PhoneIcon class="h-4 w-4" />
</div>
</template>
<div v-if="column.key === 'modified'" class="truncate text-base">
{{ item.timeAgo }}
</div>
</ListRowItem>
</ListRow>
</ListRows>
<ListSelectBanner />
</ListView>
</template> </template>
<script setup> <script setup>
import { ListView } from 'frappe-ui' import PhoneIcon from '@/components/Icons/PhoneIcon.vue'
import {
Avatar,
ListView,
ListHeader,
ListRows,
ListRow,
ListSelectBanner,
ListRowItem,
} from 'frappe-ui'
const props = defineProps({ const props = defineProps({
rows: { rows: {

View File

@ -9,42 +9,31 @@
</Button> </Button>
</template> </template>
</LayoutHeader> </LayoutHeader>
<div class="flex h-full overflow-hidden"> <div class="flex items-center justify-between px-5 pb-4 pt-3">
<div class="flex flex-col overflow-y-auto border-r"> <div class="flex items-center gap-2">
<router-link <Dropdown :options="viewsDropdownOptions">
:to="{ name: 'Contact', params: { contactId: contact.name } }" <template #default="{ open }">
v-for="(contact, i) in contacts.data" <Button :label="currentView.label">
:key="i" <template #prefix>
:class="[ <FeatherIcon :name="currentView.icon" class="h-4" />
currentContact?.name === contact.name </template>
? 'bg-gray-50 hover:bg-gray-100' <template #suffix>
: 'hover:bg-gray-50', <FeatherIcon
]" :name="open ? 'chevron-up' : 'chevron-down'"
> class="h-4 text-gray-600"
<div class="flex w-[352px] items-center gap-3 border-b px-5 py-4"> />
<Avatar :image="contact.image" :label="contact.full_name" size="xl" /> </template>
<div class="flex flex-col items-start gap-1"> </Button>
<span class="text-base font-medium text-gray-900"> </template>
{{ contact.full_name }} </Dropdown>
</span>
<span class="text-sm text-gray-700">{{ contact.email_id }}</span>
</div>
</div>
</router-link>
</div> </div>
<div class="flex-1"> <div class="flex items-center gap-2">
<router-view v-if="currentContact" :contact="currentContact" /> <Filter doctype="Contact" />
<div <SortBy doctype="Contact" />
v-else <Button icon="more-horizontal" />
class="grid h-full place-items-center text-xl font-medium text-gray-500"
>
<div class="flex flex-col items-center justify-center space-y-2">
<ContactsIcon class="h-10 w-10" />
<div>No contact selected</div>
</div>
</div>
</div> </div>
</div> </div>
<ContactsListView :rows="rows" :columns="columns" />
<ContactModal <ContactModal
v-model="showContactModal" v-model="showContactModal"
v-model:reloadContacts="contacts" v-model:reloadContacts="contacts"
@ -55,13 +44,18 @@
<script setup> <script setup>
import LayoutHeader from '@/components/LayoutHeader.vue' import LayoutHeader from '@/components/LayoutHeader.vue'
import ContactModal from '@/components/ContactModal.vue' import ContactModal from '@/components/ContactModal.vue'
import ContactsIcon from '@/components/Icons/ContactsIcon.vue' import ContactsListView from '@/components/ListViews/ContactsListView.vue'
import { FeatherIcon, Breadcrumbs, Avatar } from 'frappe-ui' import SortBy from '@/components/SortBy.vue'
import Filter from '@/components/Filter.vue'
import { FeatherIcon, Breadcrumbs, Dropdown } from 'frappe-ui'
import { contactsStore } from '@/stores/contacts.js' import { contactsStore } from '@/stores/contacts.js'
import { organizationsStore } from '@/stores/organizations.js'
import { dateFormat, dateTooltipFormat, timeAgo } from '@/utils'
import { ref, computed, onMounted } from 'vue' import { ref, computed, onMounted } from 'vue'
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
const { contacts } = contactsStore() const { contacts } = contactsStore()
const { getOrganization } = organizationsStore()
const route = useRoute() const route = useRoute()
const showContactModal = ref(false) const showContactModal = ref(false)
@ -85,6 +79,105 @@ const breadcrumbs = computed(() => {
return items return items
}) })
const currentView = ref({
label: 'List',
icon: 'list',
})
const viewsDropdownOptions = [
{
label: 'List',
icon: 'list',
onClick() {
currentView.value = {
label: 'List',
icon: 'list',
}
},
},
{
label: 'Table',
icon: 'grid',
onClick() {
currentView.value = {
label: 'Table',
icon: 'grid',
}
},
},
{
label: 'Calender',
icon: 'calendar',
onClick() {
currentView.value = {
label: 'Calender',
icon: 'calendar',
}
},
},
{
label: 'Board',
icon: 'columns',
onClick() {
currentView.value = {
label: 'Board',
icon: 'columns',
}
},
},
]
const rows = computed(() => {
return contacts.data.map((contact) => {
return {
name: contact.name,
full_name: {
label: contact.full_name,
image_label: contact.full_name,
image: contact.image,
},
email: contact.email_id,
mobile_no: contact.mobile_no,
company_name: {
label: contact.company_name,
logo: getOrganization(contact.company_name)?.organization_logo,
},
modified: {
label: dateFormat(contact.modified, dateTooltipFormat),
timeAgo: timeAgo(contact.modified),
},
}
})
})
const columns = [
{
label: 'Name',
key: 'full_name',
width: '17rem',
},
{
label: 'Email',
key: 'email',
width: '12rem',
},
{
label: 'Phone',
key: 'mobile_no',
width: '12rem',
},
{
label: 'Organization',
key: 'company_name',
width: '12rem',
},
{
label: 'Last modified',
key: 'modified',
width: '8rem',
},
]
onMounted(() => { onMounted(() => {
const el = document.querySelector('.router-link-active') const el = document.querySelector('.router-link-active')
if (el) if (el)

View File

@ -430,7 +430,14 @@ function getContactRowObject(contact) {
}, },
email: contact.email_id, email: contact.email_id,
mobile_no: contact.mobile_no, mobile_no: contact.mobile_no,
company_name: contact.company_name, company_name: {
label: contact.company_name,
logo: props.organization?.organization_logo,
},
modified: {
label: dateFormat(contact.modified, dateTooltipFormat),
timeAgo: timeAgo(contact.modified),
},
} }
} }
@ -512,9 +519,9 @@ const dealColumns = [
const contactColumns = [ const contactColumns = [
{ {
label: 'Full name', label: 'Name',
key: 'full_name', key: 'full_name',
width: '12rem', width: '17rem',
}, },
{ {
label: 'Email', label: 'Email',
@ -531,6 +538,11 @@ const contactColumns = [
key: 'company_name', key: 'company_name',
width: '12rem', width: '12rem',
}, },
{
label: 'Last modified',
key: 'modified',
width: '8rem',
},
] ]
function reload(val) { function reload(val) {

View File

@ -38,14 +38,12 @@ const routes = [
path: '/contacts', path: '/contacts',
name: 'Contacts', name: 'Contacts',
component: () => import('@/pages/Contacts.vue'), component: () => import('@/pages/Contacts.vue'),
children: [ },
{ {
path: '/contacts/:contactId?', path: '/contacts/:contactId',
name: 'Contact', name: 'Contact',
component: () => import('@/pages/Contact.vue'), component: () => import('@/pages/Contact.vue'),
props: true, props: true,
},
],
}, },
{ {
path: '/organizations', path: '/organizations',