提问人:Rawand ofj 提问时间:11/15/2023 最后编辑:Rawand ofj 更新时间:11/15/2023 访问量:26
admin js 中的嵌套过滤器
Nested filter in admin js
问:
我已经使用 AdminJS 一段时间了,我遇到了一个不确定如何解决它的挑战。
我管理两个集合,用户和任务。Users 集合中的每个用户都包含多个属性,例如 Unit、fullName、email 和 phone_number。访问 AdminJs 仪表板页面中的“任务”页面时,我看到一个表格,其中显示了 Tasks 集合中的数据。但是,当前的过滤机制仅基于用户电子邮件运行,我正在寻找一种基于各种用户属性过滤任务的方法。具体来说,我希望能够根据用户的 Unit、fullName 和可能的其他属性筛选任务。
请告诉我如何根据用户的属性设置过滤器任务的方法。
这是我的 AdminJs 代码:
const contentParent = {
name: "Employees",
icon: "User",
};
const adminOptions = {
// We pass Employees to `resources`
resources: [
{
resource: tasks,
options: {
listProperties: ["user", "date", "submitted"],
// editProperties: ["reason_for_not_submiting", "submitted", "task"],
filterProperties: ["user", "date", "submitted"],
actions: {
new: { isAccessible: false }, // Disable the create action
delete: { isAccessible: false }, // Disable the delete action
},
parent: contentParent,
sort: {
sortBy: "date",
direction: "desc",
},
},
},
{
resource: Users,
options: {
actions: {
new: {
isAccessible: true,
History: false,
before: async (request) => {
if (request.payload.password) {
const salt = await bcrypt.genSalt(12);
const hashedPassword = await bcrypt.hash(
request.payload.password,
salt
);
request.payload = {
...request.payload,
password: hashedPassword,
created_at: new Date(),
};
}
return request;
},
},
delete: { isAccessible: false },
},
parent: contentParent,
sort: {
sortBy: "created_at",
direction: "desc",
},
},
},
],
componentLoader,
};
const admin = new AdminJS({
...adminOptions,
defaultTheme: light.id,
availableThemes: [dark, light, noSidebar],
branding: {
companyName: "Tasks",
withMadeWithLove: false,
},
});
const adminRouter = AdminJSExpress.buildRouter(
admin
);
app.use(admin.options.rootPath, adminRouter);
答: 暂无答案
评论