Merge pull request #542 from shariquerik/filter-sort-groupby
This commit is contained in:
commit
b2e6c3b47c
@ -19,21 +19,23 @@ def sort_options(doctype: str):
|
|||||||
{
|
{
|
||||||
"label": _(field.label),
|
"label": _(field.label),
|
||||||
"value": field.fieldname,
|
"value": field.fieldname,
|
||||||
|
"fieldname": field.fieldname,
|
||||||
}
|
}
|
||||||
for field in fields
|
for field in fields
|
||||||
if field.label and field.fieldname
|
if field.label and field.fieldname
|
||||||
]
|
]
|
||||||
|
|
||||||
standard_fields = [
|
standard_fields = [
|
||||||
{"label": "Name", "value": "name"},
|
{"label": "Name", "fieldname": "name"},
|
||||||
{"label": "Created On", "value": "creation"},
|
{"label": "Created On", "fieldname": "creation"},
|
||||||
{"label": "Last Modified", "value": "modified"},
|
{"label": "Last Modified", "fieldname": "modified"},
|
||||||
{"label": "Modified By", "value": "modified_by"},
|
{"label": "Modified By", "fieldname": "modified_by"},
|
||||||
{"label": "Owner", "value": "owner"},
|
{"label": "Owner", "fieldname": "owner"},
|
||||||
]
|
]
|
||||||
|
|
||||||
for field in standard_fields:
|
for field in standard_fields:
|
||||||
field["label"] = _(field["label"])
|
field["label"] = _(field["label"])
|
||||||
|
field["value"] = field["fieldname"]
|
||||||
fields.append(field)
|
fields.append(field)
|
||||||
|
|
||||||
return fields
|
return fields
|
||||||
@ -100,6 +102,7 @@ def get_filterable_fields(doctype: str):
|
|||||||
|
|
||||||
for field in res:
|
for field in res:
|
||||||
field["label"] = _(field.get("label"))
|
field["label"] = _(field.get("label"))
|
||||||
|
field["value"] = field.get("fieldname")
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@ -129,23 +132,23 @@ def get_group_by_fields(doctype: str):
|
|||||||
fields = [
|
fields = [
|
||||||
{
|
{
|
||||||
"label": _(field.label),
|
"label": _(field.label),
|
||||||
"value": field.fieldname,
|
"fieldname": field.fieldname,
|
||||||
}
|
}
|
||||||
for field in fields
|
for field in fields
|
||||||
if field.label and field.fieldname
|
if field.label and field.fieldname
|
||||||
]
|
]
|
||||||
|
|
||||||
standard_fields = [
|
standard_fields = [
|
||||||
{"label": "Name", "value": "name"},
|
{"label": "Name", "fieldname": "name"},
|
||||||
{"label": "Created On", "value": "creation"},
|
{"label": "Created On", "fieldname": "creation"},
|
||||||
{"label": "Last Modified", "value": "modified"},
|
{"label": "Last Modified", "fieldname": "modified"},
|
||||||
{"label": "Modified By", "value": "modified_by"},
|
{"label": "Modified By", "fieldname": "modified_by"},
|
||||||
{"label": "Owner", "value": "owner"},
|
{"label": "Owner", "fieldname": "owner"},
|
||||||
{"label": "Liked By", "value": "_liked_by"},
|
{"label": "Liked By", "fieldname": "_liked_by"},
|
||||||
{"label": "Assigned To", "value": "_assign"},
|
{"label": "Assigned To", "fieldname": "_assign"},
|
||||||
{"label": "Comments", "value": "_comments"},
|
{"label": "Comments", "fieldname": "_comments"},
|
||||||
{"label": "Created On", "value": "creation"},
|
{"label": "Created On", "fieldname": "creation"},
|
||||||
{"label": "Modified On", "value": "modified"},
|
{"label": "Modified On", "fieldname": "modified"},
|
||||||
]
|
]
|
||||||
|
|
||||||
for field in standard_fields:
|
for field in standard_fields:
|
||||||
@ -197,7 +200,7 @@ def get_quick_filters(doctype: str):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if doctype == "CRM Lead":
|
if doctype == "CRM Lead":
|
||||||
quick_filters = [filter for filter in quick_filters if filter.get("name") != "converted"]
|
quick_filters = [filter for filter in quick_filters if filter.get("fieldname") != "converted"]
|
||||||
|
|
||||||
return quick_filters
|
return quick_filters
|
||||||
|
|
||||||
@ -344,7 +347,7 @@ def get_data(
|
|||||||
for kc in kanban_columns:
|
for kc in kanban_columns:
|
||||||
column_filters = {column_field: kc.get("name")}
|
column_filters = {column_field: kc.get("name")}
|
||||||
order = kc.get("order")
|
order = kc.get("order")
|
||||||
if (column_field in filters and filters.get(column_field) != kc.name) or kc.get("delete"):
|
if (column_field in filters and filters.get(column_field) != kc.get("name")) or kc.get("delete"):
|
||||||
column_data = []
|
column_data = []
|
||||||
else:
|
else:
|
||||||
column_filters.update(filters.copy())
|
column_filters.update(filters.copy())
|
||||||
@ -392,8 +395,8 @@ def get_data(
|
|||||||
fields = [
|
fields = [
|
||||||
{
|
{
|
||||||
"label": _(field.label),
|
"label": _(field.label),
|
||||||
"type": field.fieldtype,
|
"fieldtype": field.fieldtype,
|
||||||
"value": field.fieldname,
|
"fieldname": field.fieldname,
|
||||||
"options": field.options,
|
"options": field.options,
|
||||||
}
|
}
|
||||||
for field in fields
|
for field in fields
|
||||||
@ -401,23 +404,23 @@ def get_data(
|
|||||||
]
|
]
|
||||||
|
|
||||||
std_fields = [
|
std_fields = [
|
||||||
{"label": "Name", "type": "Data", "value": "name"},
|
{"label": "Name", "fieldtype": "Data", "fieldname": "name"},
|
||||||
{"label": "Created On", "type": "Datetime", "value": "creation"},
|
{"label": "Created On", "fieldtype": "Datetime", "fieldname": "creation"},
|
||||||
{"label": "Last Modified", "type": "Datetime", "value": "modified"},
|
{"label": "Last Modified", "fieldtype": "Datetime", "fieldname": "modified"},
|
||||||
{
|
{
|
||||||
"label": "Modified By",
|
"label": "Modified By",
|
||||||
"type": "Link",
|
"fieldtype": "Link",
|
||||||
"value": "modified_by",
|
"fieldname": "modified_by",
|
||||||
"options": "User",
|
"options": "User",
|
||||||
},
|
},
|
||||||
{"label": "Assigned To", "type": "Text", "value": "_assign"},
|
{"label": "Assigned To", "fieldtype": "Text", "fieldname": "_assign"},
|
||||||
{"label": "Owner", "type": "Link", "value": "owner", "options": "User"},
|
{"label": "Owner", "fieldtype": "Link", "fieldname": "owner", "options": "User"},
|
||||||
{"label": "Like", "type": "Data", "value": "_liked_by"},
|
{"label": "Like", "fieldtype": "Data", "fieldname": "_liked_by"},
|
||||||
]
|
]
|
||||||
|
|
||||||
for field in std_fields:
|
for field in std_fields:
|
||||||
if field.get("value") not in rows:
|
if field.get("fieldname") not in rows:
|
||||||
rows.append(field.get("value"))
|
rows.append(field.get("fieldname"))
|
||||||
if field not in fields:
|
if field not in fields:
|
||||||
field["label"] = _(field["label"])
|
field["label"] = _(field["label"])
|
||||||
fields.append(field)
|
fields.append(field)
|
||||||
@ -451,12 +454,12 @@ def get_data(
|
|||||||
return options
|
return options
|
||||||
|
|
||||||
for field in fields:
|
for field in fields:
|
||||||
if field.get("value") == group_by_field:
|
if field.get("fieldname") == group_by_field:
|
||||||
group_by_field = {
|
group_by_field = {
|
||||||
"label": field.get("label"),
|
"label": field.get("label"),
|
||||||
"name": field.get("value"),
|
"fieldname": field.get("fieldname"),
|
||||||
"type": field.get("type"),
|
"fieldtype": field.get("fieldtype"),
|
||||||
"options": get_options(field.get("type"), field.get("options")),
|
"options": get_options(field.get("fieldtype"), field.get("options")),
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -116,6 +116,9 @@ def get_contact_by_phone_number(phone_number):
|
|||||||
|
|
||||||
|
|
||||||
def get_contact(phone_number, exact_match=False):
|
def get_contact(phone_number, exact_match=False):
|
||||||
|
if not phone_number:
|
||||||
|
return {"mobile_no": phone_number}
|
||||||
|
|
||||||
cleaned_number = (
|
cleaned_number = (
|
||||||
phone_number.strip()
|
phone_number.strip()
|
||||||
.replace(" ", "")
|
.replace(" ", "")
|
||||||
|
|||||||
@ -197,19 +197,7 @@ const list = defineModel()
|
|||||||
const filterableFields = createResource({
|
const filterableFields = createResource({
|
||||||
url: 'crm.api.doc.get_filterable_fields',
|
url: 'crm.api.doc.get_filterable_fields',
|
||||||
cache: ['filterableFields', props.doctype],
|
cache: ['filterableFields', props.doctype],
|
||||||
params: {
|
params: { doctype: props.doctype },
|
||||||
doctype: props.doctype,
|
|
||||||
},
|
|
||||||
transform(fields) {
|
|
||||||
fields = fields.map((field) => {
|
|
||||||
return {
|
|
||||||
label: field.label,
|
|
||||||
value: field.fieldname,
|
|
||||||
...field,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return fields
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
@ -447,11 +435,11 @@ function setfilter(data) {
|
|||||||
filters.value.add({
|
filters.value.add({
|
||||||
field: {
|
field: {
|
||||||
label: data.label,
|
label: data.label,
|
||||||
fieldname: data.value,
|
fieldname: data.fieldname,
|
||||||
fieldtype: data.fieldtype,
|
fieldtype: data.fieldtype,
|
||||||
options: data.options,
|
options: data.options,
|
||||||
},
|
},
|
||||||
fieldname: data.value,
|
fieldname: data.fieldname,
|
||||||
operator: getDefaultOperator(data.fieldtype),
|
operator: getDefaultOperator(data.fieldtype),
|
||||||
value: getDefaultValue(data),
|
value: getDefaultValue(data),
|
||||||
})
|
})
|
||||||
@ -459,14 +447,16 @@ function setfilter(data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateFilter(data, index) {
|
function updateFilter(data, index) {
|
||||||
|
if (!data.fieldname) return
|
||||||
|
|
||||||
filters.value.delete(Array.from(filters.value)[index])
|
filters.value.delete(Array.from(filters.value)[index])
|
||||||
filters.value.add({
|
filters.value.add({
|
||||||
fieldname: data.value,
|
fieldname: data.fieldname,
|
||||||
operator: getDefaultOperator(data.fieldtype),
|
operator: getDefaultOperator(data.fieldtype),
|
||||||
value: getDefaultValue(data),
|
value: getDefaultValue(data),
|
||||||
field: {
|
field: {
|
||||||
label: data.label,
|
label: data.label,
|
||||||
fieldname: data.value,
|
fieldname: data.fieldname,
|
||||||
fieldtype: data.fieldtype,
|
fieldtype: data.fieldtype,
|
||||||
options: data.options,
|
options: data.options,
|
||||||
},
|
},
|
||||||
|
|||||||
@ -45,15 +45,13 @@ const list = defineModel()
|
|||||||
|
|
||||||
const groupByValue = ref({
|
const groupByValue = ref({
|
||||||
label: '',
|
label: '',
|
||||||
value: '',
|
fieldname: '',
|
||||||
})
|
})
|
||||||
|
|
||||||
const groupByOptions = createResource({
|
const groupByOptions = createResource({
|
||||||
url: 'crm.api.doc.get_group_by_fields',
|
url: 'crm.api.doc.get_group_by_fields',
|
||||||
cache: ['groupByOptions', props.doctype],
|
cache: ['groupByOptions', props.doctype],
|
||||||
params: {
|
params: { doctype: props.doctype },
|
||||||
doctype: props.doctype,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
@ -62,8 +60,9 @@ onMounted(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
function setGroupBy(data) {
|
function setGroupBy(data) {
|
||||||
|
if (!data?.fieldname) return
|
||||||
groupByValue.value = data
|
groupByValue.value = data
|
||||||
nextTick(() => emit('update', data.value))
|
nextTick(() => emit('update', data.fieldname))
|
||||||
}
|
}
|
||||||
|
|
||||||
const options = computed(() => {
|
const options = computed(() => {
|
||||||
@ -71,7 +70,7 @@ const options = computed(() => {
|
|||||||
if (!list.value?.data?.group_by_field) return groupByOptions.data
|
if (!list.value?.data?.group_by_field) return groupByOptions.data
|
||||||
groupByValue.value = list.value.data.group_by_field
|
groupByValue.value = list.value.data.group_by_field
|
||||||
return groupByOptions.data.filter(
|
return groupByOptions.data.filter(
|
||||||
(option) => option !== groupByValue.value.value
|
(option) => option.fieldname !== groupByValue.value.fieldname,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -195,9 +195,7 @@ const list = defineModel()
|
|||||||
const sortOptions = createResource({
|
const sortOptions = createResource({
|
||||||
url: 'crm.api.doc.sort_options',
|
url: 'crm.api.doc.sort_options',
|
||||||
cache: ['sortOptions', props.doctype],
|
cache: ['sortOptions', props.doctype],
|
||||||
params: {
|
params: { doctype: props.doctype },
|
||||||
doctype: props.doctype,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
@ -228,7 +226,7 @@ const options = computed(() => {
|
|||||||
const selectedOptions = [...sortValues.value].map((sort) => sort.fieldname)
|
const selectedOptions = [...sortValues.value].map((sort) => sort.fieldname)
|
||||||
restartSort()
|
restartSort()
|
||||||
return sortOptions.data.filter((option) => {
|
return sortOptions.data.filter((option) => {
|
||||||
return !selectedOptions.includes(option.value)
|
return !selectedOptions.includes(option.fieldname)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -242,13 +240,13 @@ function getSortLabel() {
|
|||||||
if (!sortValues.value.size) return __('Sort')
|
if (!sortValues.value.size) return __('Sort')
|
||||||
let values = Array.from(sortValues.value)
|
let values = Array.from(sortValues.value)
|
||||||
let label = sortOptions.data?.find(
|
let label = sortOptions.data?.find(
|
||||||
(option) => option.value === values[0].fieldname,
|
(option) => option.fieldname === values[0].fieldname,
|
||||||
)?.label
|
)?.label
|
||||||
return label || values[0].fieldname
|
return label || values[0].fieldname
|
||||||
}
|
}
|
||||||
|
|
||||||
function setSort(data) {
|
function setSort(data) {
|
||||||
sortValues.value.add({ fieldname: data.value, direction: 'asc' })
|
sortValues.value.add({ fieldname: data.fieldname, direction: 'asc' })
|
||||||
restartSort()
|
restartSort()
|
||||||
apply()
|
apply()
|
||||||
}
|
}
|
||||||
@ -257,7 +255,7 @@ function updateSort(data, index) {
|
|||||||
let oldSort = Array.from(sortValues.value)[index]
|
let oldSort = Array.from(sortValues.value)[index]
|
||||||
sortValues.value.delete(oldSort)
|
sortValues.value.delete(oldSort)
|
||||||
sortValues.value.add({
|
sortValues.value.add({
|
||||||
fieldname: data.value,
|
fieldname: data.fieldname,
|
||||||
direction: oldSort.direction,
|
direction: oldSort.direction,
|
||||||
})
|
})
|
||||||
apply()
|
apply()
|
||||||
|
|||||||
@ -589,7 +589,7 @@ const viewsDropdownOptions = computed(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const quickFilterList = computed(() => {
|
const quickFilterList = computed(() => {
|
||||||
let filters = [{ name: 'name', label: __('ID') }]
|
let filters = [{ fieldname: 'name', fieldtype: 'Data', label: __('ID') }]
|
||||||
if (quickFilters.data) {
|
if (quickFilters.data) {
|
||||||
filters.push(...quickFilters.data)
|
filters.push(...quickFilters.data)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -328,7 +328,7 @@ function getRow(name, field) {
|
|||||||
const rows = computed(() => {
|
const rows = computed(() => {
|
||||||
if (!deals.value?.data?.data) return []
|
if (!deals.value?.data?.data) return []
|
||||||
if (deals.value.data.view_type === 'group_by') {
|
if (deals.value.data.view_type === 'group_by') {
|
||||||
if (!deals.value?.data.group_by_field?.name) return []
|
if (!deals.value?.data.group_by_field?.fieldname) return []
|
||||||
return getGroupedByRows(
|
return getGroupedByRows(
|
||||||
deals.value?.data.data,
|
deals.value?.data.data,
|
||||||
deals.value?.data.group_by_field,
|
deals.value?.data.group_by_field,
|
||||||
@ -348,9 +348,9 @@ function getGroupedByRows(listRows, groupByField, columns) {
|
|||||||
let filteredRows = []
|
let filteredRows = []
|
||||||
|
|
||||||
if (!option) {
|
if (!option) {
|
||||||
filteredRows = listRows.filter((row) => !row[groupByField.name])
|
filteredRows = listRows.filter((row) => !row[groupByField.fieldname])
|
||||||
} else {
|
} else {
|
||||||
filteredRows = listRows.filter((row) => row[groupByField.name] == option)
|
filteredRows = listRows.filter((row) => row[groupByField.fieldname] == option)
|
||||||
}
|
}
|
||||||
|
|
||||||
let groupDetail = {
|
let groupDetail = {
|
||||||
@ -359,7 +359,7 @@ function getGroupedByRows(listRows, groupByField, columns) {
|
|||||||
collapsed: false,
|
collapsed: false,
|
||||||
rows: parseRows(filteredRows, columns),
|
rows: parseRows(filteredRows, columns),
|
||||||
}
|
}
|
||||||
if (groupByField.name == 'status') {
|
if (groupByField.fieldname == 'status') {
|
||||||
groupDetail.icon = () =>
|
groupDetail.icon = () =>
|
||||||
h(IndicatorIcon, {
|
h(IndicatorIcon, {
|
||||||
class: getDealStatus(option)?.color,
|
class: getDealStatus(option)?.color,
|
||||||
|
|||||||
@ -348,7 +348,7 @@ function getRow(name, field) {
|
|||||||
const rows = computed(() => {
|
const rows = computed(() => {
|
||||||
if (!leads.value?.data?.data) return []
|
if (!leads.value?.data?.data) return []
|
||||||
if (leads.value.data.view_type === 'group_by') {
|
if (leads.value.data.view_type === 'group_by') {
|
||||||
if (!leads.value?.data.group_by_field?.name) return []
|
if (!leads.value?.data.group_by_field?.fieldname) return []
|
||||||
return getGroupedByRows(
|
return getGroupedByRows(
|
||||||
leads.value?.data.data,
|
leads.value?.data.data,
|
||||||
leads.value?.data.group_by_field,
|
leads.value?.data.group_by_field,
|
||||||
@ -368,9 +368,9 @@ function getGroupedByRows(listRows, groupByField, columns) {
|
|||||||
let filteredRows = []
|
let filteredRows = []
|
||||||
|
|
||||||
if (!option) {
|
if (!option) {
|
||||||
filteredRows = listRows.filter((row) => !row[groupByField.name])
|
filteredRows = listRows.filter((row) => !row[groupByField.fieldname])
|
||||||
} else {
|
} else {
|
||||||
filteredRows = listRows.filter((row) => row[groupByField.name] == option)
|
filteredRows = listRows.filter((row) => row[groupByField.fieldname] == option)
|
||||||
}
|
}
|
||||||
|
|
||||||
let groupDetail = {
|
let groupDetail = {
|
||||||
@ -379,7 +379,7 @@ function getGroupedByRows(listRows, groupByField, columns) {
|
|||||||
collapsed: false,
|
collapsed: false,
|
||||||
rows: parseRows(filteredRows, columns),
|
rows: parseRows(filteredRows, columns),
|
||||||
}
|
}
|
||||||
if (groupByField.name == 'status') {
|
if (groupByField.fieldname == 'status') {
|
||||||
groupDetail.icon = () =>
|
groupDetail.icon = () =>
|
||||||
h(IndicatorIcon, {
|
h(IndicatorIcon, {
|
||||||
class: getLeadStatus(option)?.color,
|
class: getLeadStatus(option)?.color,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user