mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 10:17:00 +00:00
feat: support users views as submenu
This commit is contained in:
parent
9a27eac0e0
commit
a98f5af183
@ -39,6 +39,7 @@ function pages2routes(pages: Array<any>) {
|
||||
export default async function getRoutes(ctx, next) {
|
||||
const database: Database = ctx.database;
|
||||
const Page = database.getModel('pages');
|
||||
const View = database.getModel('views');
|
||||
const Collection = database.getModel('collections');
|
||||
const RoutePermission = database.getModel('routes_permissions');
|
||||
const roles = await ctx.ac.getRoles();
|
||||
@ -134,6 +135,39 @@ export default async function getRoutes(ctx, next) {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (page.get('path') === '/users/users') {
|
||||
const userViews = await View.findAll(View.parseApiJson(ctx.state.developerMode ? {
|
||||
filter: {
|
||||
collection_name: 'users',
|
||||
showInDataMenu: true,
|
||||
},
|
||||
sort: ['sort'],
|
||||
}: {
|
||||
filter: {
|
||||
collection_name: 'users',
|
||||
developerMode: {'$isFalsy': true},
|
||||
showInDataMenu: true,
|
||||
},
|
||||
sort: ['sort'],
|
||||
}));
|
||||
if (userViews.length > 1) {
|
||||
for (const view of userViews) {
|
||||
if (!isRoot && !routesPermissionsMap.has(`views:${view.id}`)) {
|
||||
continue;
|
||||
}
|
||||
items.push({
|
||||
id: `view-${view.get('id')}`,
|
||||
type: 'collection',
|
||||
collection: 'users',
|
||||
title: view.title,
|
||||
viewName: view.name,
|
||||
path: `${page.get('path')}/views/${view.name}`,
|
||||
parent_id: page.id,
|
||||
showInMenu: true,
|
||||
sort: view.get('sort'),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const data = flatToTree(items, {
|
||||
|
@ -6,6 +6,7 @@ import { Op } from 'sequelize';
|
||||
async function getRoutes(ctx) {
|
||||
const database: Database = ctx.db;
|
||||
const Page = database.getModel('pages');
|
||||
const View = database.getModel('views');
|
||||
const Collection = database.getModel('collections');
|
||||
let pages = await Page.findAll(Page.parseApiJson(ctx.state.developerMode ? {
|
||||
filter: {
|
||||
@ -61,6 +62,29 @@ async function getRoutes(ctx) {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (page.get('path') === '/users/users') {
|
||||
const userViews = await View.findAll(View.parseApiJson(ctx.state.developerMode ? {
|
||||
filter: {
|
||||
showInDataMenu: true,
|
||||
collection_name: 'users',
|
||||
},
|
||||
sort: ['sort'],
|
||||
}: {
|
||||
filter: {
|
||||
developerMode: {'$isFalsy': true},
|
||||
showInDataMenu: true,
|
||||
collection_name: 'users',
|
||||
},
|
||||
sort: ['sort'],
|
||||
}));
|
||||
if (userViews.length > 1) {
|
||||
for (const view of userViews) {
|
||||
items.push({
|
||||
routable_id: view.id,
|
||||
routable_type: 'views',
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return items;
|
||||
@ -70,6 +94,7 @@ export async function list(ctx: actions.Context, next: actions.Next) {
|
||||
const database: Database = ctx.db;
|
||||
const { associatedKey, associated } = ctx.action.params;
|
||||
const Page = database.getModel('pages');
|
||||
const View = database.getModel('views');
|
||||
const Collection = database.getModel('collections');
|
||||
// TODO(optimize): isRoot 的判断需要在内部完成,尽量不要交给调用者
|
||||
const isRoot = ctx.ac.constructor.isRoot(associated);
|
||||
@ -150,6 +175,34 @@ export async function list(ctx: actions.Context, next: actions.Next) {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (page.get('path') === '/users/users') {
|
||||
const userViews = await View.findAll(View.parseApiJson(ctx.state.developerMode ? {
|
||||
filter: {
|
||||
showInDataMenu: true,
|
||||
collection_name: 'users',
|
||||
},
|
||||
sort: ['sort'],
|
||||
}: {
|
||||
filter: {
|
||||
collection_name: 'users',
|
||||
developerMode: {'$isFalsy': true},
|
||||
showInDataMenu: true,
|
||||
},
|
||||
sort: ['sort'],
|
||||
}));
|
||||
if (userViews.length > 1) {
|
||||
for (const view of userViews) {
|
||||
items.push({
|
||||
associatedKey,
|
||||
id: view.id,
|
||||
tableName: 'views',
|
||||
title: view.title,
|
||||
key: `view-${view.id}`,
|
||||
parent_id: `page-${page.id}`,
|
||||
accessible: isRoot || routesPermissionsMap.has(`views:${view.id}`), // TODO 对接权限
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const data = flatToTree(items, {
|
||||
|
Loading…
Reference in New Issue
Block a user