8000 feat: track dashboard views · frappe/insights@df7d33d · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit df7d33d

Browse files
feat: track dashboard views
1 parent fab6ce5 commit df7d33d

File tree

8 files changed

+38
-8
lines changed

8 files changed

+38
-8
lines changed

frontend/src2/dashboard/DashboardList.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ watchEffect(() => {
9595
<div class="mt-1.5 flex gap-2">
9696
<div class="flex items-center gap-1">
9797
<Eye class="h-3 w-3 text-gray-600" stroke-width="1.5" />
98-
<span class="text-xs text-gray-600">10</span>
98+
<span class="text-xs text-gray-600">
99+
{{ dashboard.views }}
100+
</span>
99101
</div>
100102
<div class="flex items-center gap-1">
101103
<BarChart2 class="h-3 w-3 text-gray-600" stroke-width="1.5" />

frontend/src2/dashboard/dashboard.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ function getDashboardResource(name: string) {
304304
return doc
305305
},
306306
})
307+
dashboard.onAfterLoad(() => dashboard.call('track_view').catch(() => {}))
307308
wheneverChanges(() => dashboard.doc.read_only, () => {
308309
if (dashboard.doc.read_only) {
309310
dashboard.autoSave = false

frontend/src2/dashboard/dashboards.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export type DashboardListItem = {
1414
created_from_now: string
1515
modified_from_now: string
1616
preview_image: string
17+
views: number
1718
}
1819

1920
const dashboards = ref<DashboardListItem[]>([])

insights/api/dashboards.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ def get_dashboards(search_term=None, limit=50):
9999
items = frappe.parse_json(dashboard["items"])
100100
charts = [item for item in items if item["type"] == "chart"]
101101
dashboard["charts"] = len(charts)
102+
dashboard["views"] = frappe.db.count(
103+
"View Log",
104+
filters={
105+
"reference_doctype": "Insights Dashboard v3",
106+
"reference_name": dashboard.name,
107+
},
108+
)
102109
del dashboard["items"]
103110

104111
return dashboards

insights/insights/doctype/insights_dashboard_v3/insights_dashboard_v3.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
],
8383
"index_web_pages_for_search": 1,
8484
"links": [],
85-
"modified": "2025-03-19 14:51:58.451701",
85+
"modified": "2025-04-11 17:23:03.687968",
8686
"modified_by": "Administrator",
8787
"module": "Insights",
8888
"name": "Insights Dashboard v3",
@@ -113,10 +113,11 @@
113113
"write": 1
114114
}
115115
],
116+
"row_format": "Dynamic",
116117
"show_title_field_in_link": 1,
117118
"sort_field": "creation",
118119
"sort_order": "DESC",
119120
"states": [],
120121
"title_field": "title",
121122
"track_changes": 1
122-
}
123+
}

insights/insights/doctype/insights_dashboard_v3/insights_dashboard_v3.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import frappe
88
import requests
99
from frappe.model.document import Document
10+
from frappe.query_builder import Interval
11+
from frappe.query_builder.functions import Now
1012

1113
from insights.utils import DocShare, File
1214

@@ -34,6 +36,22 @@ class InsightsDashboardv3(Document):
3436
workbook: DF.Link
3537
# end: auto-generated types
3638

39+
@frappe.whitelist()
40+
def track_view(self):
41+
view_log = frappe.qb.DocType("View Log")
42+
last_viewed_recently = frappe.db.get_value(
43+
view_log,
44+
filters=(
45+
(view_log.creation > (Now() - Interval(minutes=5)))
46+
& (view_log.reference_doctype == self.doctype)
47+
& (view_log.reference_name == self.name)
48+
& (view_log.viewed_by == frappe.session.user)
49+
),
50+
pluck="name",
51+
)
52+
if not last_viewed_recently:
53+
self.add_viewed(force=True)
54+
3755
def get_valid_dict(self, *args, **kwargs):
3856
if isinstance(self.items, list):
3957
self.items = frappe.as_json(self.items)

insights/insights/doctype/insights_workbook/insights_workbook.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"link_fieldname": "workbook"
4040
}
4141
],
42-
"modified": "2025-03-18 13:14:41.713081",
42+
"modified": "2025-04-11 17:26:45.109680",
4343
"modified_by": "Administrator",
4444
"module": "Insights",
4545
"name": "Insights Workbook",
@@ -71,11 +71,11 @@
7171
"write": 1
7272
}
7373
],
74+
"row_format": "Dynamic",
7475
"show_title_field_in_link": 1,
7576
"sort_field": "creation",
7677
"sort_order": "DESC",
7778
"states": [],
7879
"title_field": "title",
79-
"track_changes": 1,
80-
"track_views": 1
81-
}
80+
"track_changes": 1
81+
}

insights/insights/doctype/insights_workbook/insights_workbook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,4 @@ def track_view(self):
9999
pluck="name",
100100
)
101101
if not last_viewed_recently:
102-
self.add_viewed()
102+
self.add_viewed(force=True)

0 commit comments

Comments
 (0)
0