diff --git a/packages/app/src/components/pages/CollectionLoader/index.tsx b/packages/app/src/components/pages/CollectionLoader/index.tsx index 1d194c109..8df491106 100644 --- a/packages/app/src/components/pages/CollectionLoader/index.tsx +++ b/packages/app/src/components/pages/CollectionLoader/index.tsx @@ -24,7 +24,7 @@ export function CollectionLoader(props: any) { tabName: match[2], })); props.match.params['items'] = items; - console.log(props.match, path); + console.log('props.match', props.match, path); const { data = {}, error, loading, run } = useRequest(() => api.resource(collection).getCollection()); if (loading) { diff --git a/packages/app/src/components/views/SortableTable/index.tsx b/packages/app/src/components/views/SortableTable/index.tsx index bbab8ae01..105b24f45 100644 --- a/packages/app/src/components/views/SortableTable/index.tsx +++ b/packages/app/src/components/views/SortableTable/index.tsx @@ -40,6 +40,8 @@ export const components = ({data = {}, rowKey, mutate, onMoved}: Props) => { }); const resourceKey = get(list, [newIndex, rowKey]); await onMoved({resourceKey, target: {[rowKey]: targetIndex}}); + // @ts-ignore + window.routesReload && window.routesReload(); } }} {...props} diff --git a/packages/plugin-pages/src/actions/getRoutes.ts b/packages/plugin-pages/src/actions/getRoutes.ts index 323815f33..d331c0e2a 100644 --- a/packages/plugin-pages/src/actions/getRoutes.ts +++ b/packages/plugin-pages/src/actions/getRoutes.ts @@ -2,6 +2,7 @@ import Database from '@nocobase/database'; import { ResourceOptions } from '@nocobase/resourcer'; import { flatToTree } from '../utils'; import { get } from 'lodash'; +import { Op } from 'sequelize'; function pages2routes(pages: Array) { let routes: any = {}; @@ -38,13 +39,65 @@ function pages2routes(pages: Array) { export default async function getRoutes(ctx, next) { const database: Database = ctx.database; const Page = database.getModel('pages'); - let pages = await Page.findAll({ - where: { - developerMode: ctx.state.developerMode, + const Collection = database.getModel('collections'); + let pages = await Page.findAll(Page.parseApiJson({ + filter: { + 'developerMode': ctx.state.developerMode, }, - order: [['sort', 'asc']], - }); - const data = flatToTree(pages.map(row => row.toJSON()), { + sort: ['sort'], + })); + const items = []; + for (const page of pages) { + items.push(page.toJSON()); + if (page.get('path') === '/collections') { + const collections = await Collection.findAll(Collection.parseApiJson({ + filter: { + developerMode: ctx.state.developerMode, + showInDataMenu: true, + }, + sort: ['sort'], + })); + for (const collection of collections) { + const pageId = `collection-${collection.id}`; + items.push({ + id: pageId, + type: 'collection', + collection: collection.get('name'), + title: collection.get('title'), + icon: collection.get('icon'), + path: `/collections/${collection.name}`, + parent_id: page.id, + showInMenu: true, + sort: collection.get('sort'), + }); + const views = await collection.getViews({ + where: { + [Op.or]: [ + { showInDataMenu: true }, + { default: true } + ] + }, + order: [['sort', 'asc']] + }); + if (views.length > 1) { + for (const view of views) { + items.push({ + id: `view-${view.get('id')}`, + type: 'collection', + collection: collection.get('name'), + title: view.title, + viewName: view.name, + path: `/collections/${collection.name}/views/${view.name}`, + parent_id: pageId, + showInMenu: true, + sort: view.get('sort'), + }); + } + } + } + } + } + const data = flatToTree(items, { id: 'id', parentId: 'parent_id', children: 'children', diff --git a/packages/plugin-pages/src/actions/getView.ts b/packages/plugin-pages/src/actions/getView.ts index 0c9f5d3cb..a2c1e9cb4 100644 --- a/packages/plugin-pages/src/actions/getView.ts +++ b/packages/plugin-pages/src/actions/getView.ts @@ -219,6 +219,9 @@ export default async (ctx, next) => { } const viewType = view.get('type'); const actionDefaultParams:any = {}; + if (resourceName === 'collections') { + actionDefaultParams.sort = ['sort']; + } const appends = []; for (const field of fields) { diff --git a/packages/plugin-pages/src/server.ts b/packages/plugin-pages/src/server.ts index afa8cd425..1b20a52a4 100644 --- a/packages/plugin-pages/src/server.ts +++ b/packages/plugin-pages/src/server.ts @@ -18,7 +18,7 @@ export default async function (options = {}) { resourcer.registerActionHandler('getView', getView); resourcer.registerActionHandler('getPageInfo', getPageInfo); resourcer.registerActionHandler('pages:getRoutes', getRoutes); - +/* const [Collection, Page, View] = database.getModels(['collections', 'pages', 'views']); async function createCollectionPage(model, options) { @@ -61,6 +61,7 @@ export default async function (options = {}) { await page.save({ transaction, }); + await Page.collectionPagesResort({transaction}); await transaction.commit(); } @@ -75,6 +76,7 @@ export default async function (options = {}) { path: `/collections/${model.get('name')}`, }, }); + await Page.collectionPagesResort({transaction}); }); async function syncViewCollectionPage(model, options) { @@ -140,4 +142,5 @@ export default async function (options = {}) { }, }); }); +*/ }