forked from ignacy130/yadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.js
93 lines (84 loc) · 2.63 KB
/
admin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import Tabular from 'meteor/aldeed:tabular';
export const AdminConfig = {collections: {}};
globalThis.AdminConfig = AdminConfig; //TODO: delete this line
export const AdminTables = {};
export const adminTablesDom = '<"box"<"box-header"<"box-toolbar"<"pull-left"<lf>><"pull-right"p>>><"box-body"t>><r>';
export const adminEditButton = {
data: '_id',
title: 'Edit',
createdCell(node, cellData, rowData) {
return $(node).html(Blaze.toHTMLWithData(Template.adminEditBtn, {_id: cellData}));
},
width: '40px',
orderable: false
};
export const adminDelButton = {
data: '_id',
title: 'Delete',
createdCell(node, cellData, rowData) {
return $(node).html(Blaze.toHTMLWithData(Template.adminDeleteBtn, {_id: cellData}));
},
width: '40px',
orderable: false
};
export const adminEditDelButtons = [
adminEditButton,
adminDelButton
];
export const defaultColumns = () => [{
data: '_id',
title: 'ID'
}];
AdminTables.Users = new Tabular.Table({
// Modify selector to allow search by email
changeSelector(selector, userId) {
const $or = selector['$or'];
$or && (selector['$or'] = _.map($or, function (exp) {
if ((exp.emails != null ? exp.emails['$regex'] : undefined) != null) {
return {emails: {$elemMatch: {address: exp.emails}}};
} else {
return exp;
}
}));
return selector;
},
name: 'Users',
collection: Meteor.users,
columns: _.union([
{
data: '_id',
title: 'Admin',
// TODO: use `tmpl`
createdCell(node, cellData, rowData) {
if (Meteor.isServer) return null;
return $(node).html(Blaze.toHTMLWithData(Template.adminUsersIsAdmin, {_id: cellData}));
},
width: '40px'
},
{
data: 'username',
title: 'Username',
},
{
data: 'emails',
title: 'Email',
render(value) {
let result = '';
value?.forEach(v => result += `${v.address}, `);
return result.slice(0, -2);
},
},
{
data: 'emails',
title: 'Mail',
// TODO: use `tmpl`
createdCell(node, cellData, rowData) {
if (Meteor.isServer) return null;
return $(node).html(Blaze.toHTMLWithData(Template.adminUsersMailBtn, {emails: cellData}));
},
width: '40px'
},
{data: 'createdAt', title: 'Joined'}
], adminEditDelButtons),
dom: adminTablesDom
});