Skip to content

Commit debd3c7

Browse files
committed
Add user reports
1 parent 3e9395b commit debd3c7

16 files changed

+45672
-25
lines changed

ckanext/twdh_reports/assets/script.js

-10
This file was deleted.
+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
"use strict";
2+
3+
ckan.module('twdh_reports', function ($) {
4+
return {
5+
options: {
6+
reportsParams: null
7+
},
8+
9+
initialize: function () {
10+
console.log('twdh_reports module initialized');
11+
12+
// Debug logs
13+
console.log('Params:', this.options.reportsParams);
14+
15+
if (!this.options.reportsParams || !this.options.reportsParams.collection) {
16+
console.error('No collection data available');
17+
return;
18+
}
19+
20+
try {
21+
const collection = JSON.parse(this.options.reportsParams.collection);
22+
console.log('Collection data:', collection);
23+
24+
const datatable = $(this.el).DataTable({
25+
data: collection,
26+
pageLength: 10,
27+
stateSave: true,
28+
orderCellsTop: true,
29+
autoWidth: true,
30+
31+
// Column Definitions
32+
columnDefs: [
33+
{
34+
targets: 0,
35+
data: "fullname",
36+
render: function(data) {
37+
return data || 'Not Provided';
38+
}
39+
},
40+
{
41+
targets: 1,
42+
data: "title",
43+
render: function(data) {
44+
45+
return data.charAt(0).toUpperCase() + data.slice(1).toLowerCase();
46+
}
47+
},
48+
{
49+
targets: 2,
50+
data: "email"
51+
},
52+
{
53+
targets: 3,
54+
data: "capacity",
55+
render: function(data) {
56+
if (!data) return 'Not Provided';
57+
return data.charAt(0).toUpperCase() + data.slice(1).toLowerCase();
58+
}
59+
},
60+
{
61+
targets: 4,
62+
data: "last_active",
63+
render: function(data) {
64+
if (!data) return 'Never';
65+
return new Date(data).toLocaleString();
66+
}
67+
}
68+
],
69+
70+
// DOM structure
71+
dom: '<"row"<"col-sm-12 col-md-6"l><"col-sm-12 col-md-6"f>>' +
72+
'<"row"<"col-sm-12 col-md-6"B>>' +
73+
'<"row"<"col-sm-12"tr>>' +
74+
'<"row"<"col-sm-12 col-md-5"i><"col-sm-12 col-md-7"p>>',
75+
76+
// Button configuration
77+
buttons: [
78+
{
79+
extend: 'csv',
80+
text: '<i class="fa fa-file-text-o"></i> CSV',
81+
className: 'btn btn-default',
82+
exportOptions: {
83+
columns: ':visible'
84+
}
85+
},
86+
{
87+
extend: 'excel',
88+
text: '<i class="fa fa-file-excel-o"></i> Excel',
89+
className: 'btn btn-default',
90+
exportOptions: {
91+
columns: ':visible'
92+
}
93+
},
94+
{
95+
extend: 'pdf',
96+
text: '<i class="fa fa-file-pdf-o"></i> PDF',
97+
className: 'btn btn-default',
98+
exportOptions: {
99+
columns: ':visible'
100+
}
101+
},
102+
{
103+
extend: 'print',
104+
text: '<i class="fa fa-print"></i> Print',
105+
className: 'btn btn-default',
106+
exportOptions: {
107+
columns: ':visible'
108+
}
109+
}
110+
],
111+
112+
// Initialize after table is ready
113+
initComplete: function() {
114+
const api = this.api();
115+
116+
// Add global search
117+
const searchDiv = $('<div class="dataTables_filter"><label>Search: <input type="search" class="form-control form-control-sm" placeholder="Global search..."></label></div>')
118+
.insertBefore($(api.table().container()).find('.dataTables_info'));
119+
120+
searchDiv.find('input').on('keyup change', function() {
121+
api.search(this.value).draw();
122+
});
123+
}
124+
});
125+
126+
// Store instance
127+
this.dataTable = datatable;
128+
129+
} catch (error) {
130+
console.error('Error initializing DataTable:', error);
131+
console.error(error.stack);
132+
}
133+
},
134+
135+
teardown: function() {
136+
if (this.dataTable) {
137+
this.dataTable.destroy();
138+
}
139+
}
140+
};
141+
});

0 commit comments

Comments
 (0)