fix: include type of the column field to render it correctly on list row

This commit is contained in:
Shariq Ansari 2023-11-28 15:03:59 +05:30
parent 00e97d19e3
commit 72a7770d31
9 changed files with 91 additions and 16 deletions

View File

@ -1,5 +1,6 @@
import frappe
from frappe.model.document import get_controller
from frappe.model import no_value_fields
from pypika import Criterion
@ -77,22 +78,30 @@ def get_list_data(doctype: str, filters: dict, order_by: str):
page_length=20,
) or []
not_allowed_fieldtypes = [
"Section Break",
"Column Break",
"Tab Break",
fields = frappe.get_meta(doctype).fields
fields = [field for field in fields if field.fieldtype not in no_value_fields]
fields = [
{
"label": field.label,
"type": field.fieldtype,
"value": field.fieldname,
"options": field.options,
}
for field in fields
if field.label and field.fieldname
]
fields = frappe.get_meta(doctype).fields
fields = [field for field in fields if field.fieldtype not in not_allowed_fieldtypes]
fields = [{"label": field.label, "value": field.fieldname} for field in fields if field.label and field.fieldname]
std_fields = [
{'label': 'Name', 'value': 'name'},
{'label': 'Created On', 'value': 'creation'},
{'label': 'Last Modified', 'value': 'modified'},
{'label': 'Modified By', 'value': 'modified_by'},
{'label': 'Owner', 'value': 'owner'},
{"label": "Name", "type": "Data", "value": "name"},
{"label": "Created On", "type": "Datetime", "value": "creation"},
{"label": "Last Modified", "type": "Datetime", "value": "modified"},
{
"label": "Modified By",
"type": "Link",
"value": "modified_by",
"options": "User",
},
{"label": "Owner", "type": "Link", "value": "owner", "options": "User"},
]
for field in std_fields:

View File

@ -62,36 +62,45 @@ class CRMDeal(Document):
columns = [
{
'label': 'Organization',
'type': 'Link',
'key': 'organization',
'options': 'CRM Organization',
'width': '11rem',
},
{
'label': 'Amount',
'type': 'Currency',
'key': 'annual_revenue',
'width': '9rem',
},
{
'label': 'Status',
'type': 'Select',
'key': 'status',
'width': '10rem',
},
{
'label': 'Email',
'type': 'Data',
'key': 'email',
'width': '12rem',
},
{
'label': 'Mobile no',
'type': 'Data',
'key': 'mobile_no',
'width': '11rem',
},
{
'label': 'Deal owner',
'type': 'Link',
'key': 'deal_owner',
'options': 'User',
'width': '10rem',
},
{
'label': 'Last modified',
'type': 'Datetime',
'key': 'modified',
'width': '8rem',
},

View File

@ -141,36 +141,45 @@ class CRMLead(Document):
columns = [
{
'label': 'Name',
'type': 'Data',
'key': 'lead_name',
'width': '12rem',
},
{
'label': 'Organization',
'type': 'Link',
'key': 'organization',
'options': 'CRM Organization',
'width': '10rem',
},
{
'label': 'Status',
'type': 'Select',
'key': 'status',
'width': '8rem',
},
{
'label': 'Email',
'type': 'Data',
'key': 'email',
'width': '12rem',
},
{
'label': 'Mobile no',
'type': 'Data',
'key': 'mobile_no',
'width': '11rem',
},
{
'label': 'Lead owner',
'type': 'Link',
'key': 'lead_owner',
'options': 'User',
'width': '10rem',
},
{
'label': 'Last modified',
'type': 'Datetime',
'key': 'modified',
'width': '8rem',
},

View File

@ -22,26 +22,31 @@ class CustomContact(Contact):
columns = [
{
'label': 'Name',
'type': 'Data',
'key': 'full_name',
'width': '17rem',
},
{
'label': 'Email',
'type': 'Data',
'key': 'email_id',
'width': '12rem',
},
{
'label': 'Phone',
'type': 'Data',
'key': 'mobile_no',
'width': '12rem',
},
{
'label': 'Organization',
'type': 'Data',
'key': 'company_name',
'width': '12rem',
},
{
'label': 'Last modified',
'type': 'Datetime',
'key': 'modified',
'width': '8rem',
},

View File

@ -3,7 +3,10 @@
:columns="columns"
:rows="rows"
:options="{
getRowRoute: (row) => ({ name: 'Contact', params: { contactId: row.name } }),
getRowRoute: (row) => ({
name: 'Contact',
params: { contactId: row.name },
}),
selectable: options.selectable,
}"
row-key="name"
@ -41,9 +44,20 @@
<PhoneIcon class="h-4 w-4" />
</div>
</template>
<div v-if="column.key === 'modified'" class="truncate text-base">
<div
v-if="['modified', 'creation'].includes(column.key)"
class="truncate text-base"
>
{{ item.timeAgo }}
</div>
<div v-else-if="column.type === 'Check'">
<FormControl
type="checkbox"
:modelValue="item"
:disabled="true"
class="text-gray-900"
/>
</div>
</ListRowItem>
</ListRow>
</ListRows>
@ -60,6 +74,7 @@ import {
ListRow,
ListSelectBanner,
ListRowItem,
FormControl,
} from 'frappe-ui'
const props = defineProps({

View File

@ -47,6 +47,14 @@
<div v-if="['modified', 'creation'].includes(column.key)" class="truncate text-base">
{{ item.timeAgo }}
</div>
<div v-else-if="column.type === 'Check'">
<FormControl
type="checkbox"
:modelValue="item"
:disabled="true"
class="text-gray-900"
/>
</div>
</ListRowItem>
</ListRow>
</ListRows>
@ -65,6 +73,7 @@ import {
ListRow,
ListRowItem,
ListSelectBanner,
FormControl,
} from 'frappe-ui'
const props = defineProps({

View File

@ -56,6 +56,14 @@
<div v-if="['modified', 'creation'].includes(column.key)" class="truncate text-base">
{{ item.timeAgo }}
</div>
<div v-else-if="column.type === 'Check'">
<FormControl
type="checkbox"
:modelValue="item"
:disabled="true"
class="text-gray-900"
/>
</div>
</ListRowItem>
</ListRow>
</ListRows>
@ -74,6 +82,7 @@ import {
ListRow,
ListSelectBanner,
ListRowItem,
FormControl,
} from 'frappe-ui'
const props = defineProps({

View File

@ -32,9 +32,17 @@
/>
</div>
</template>
<div v-if="column.key === 'modified'" class="truncate text-base">
<div v-if="['modified', 'creation'].includes(column.key)" class="truncate text-base">
{{ item.timeAgo }}
</div>
<div v-else-if="column.type === 'Check'">
<FormControl
type="checkbox"
:modelValue="item"
:disabled="true"
class="text-gray-900"
/>
</div>
</ListRowItem>
</ListRow>
</ListRows>
@ -50,6 +58,7 @@ import {
ListRow,
ListSelectBanner,
ListRowItem,
FormControl,
} from 'frappe-ui'
const props = defineProps({

View File

@ -163,6 +163,7 @@ const fields = computed(() => {
async function addColumn(c) {
let _column = {
label: c.label,
type: c.type,
key: c.value,
width: '10rem',
}