mirror of
https://gitee.com/nocobase/nocobase.git
synced 2024-12-01 03:38:32 +08:00
fix: view filtering does not work
This commit is contained in:
parent
f7f8e12ac9
commit
6a9bf9572c
@ -91,26 +91,26 @@ api.resourcer.use(async (ctx: actions.Context, next) => {
|
||||
await next();
|
||||
});
|
||||
|
||||
api.resourcer.use(async (ctx: actions.Context, next) => {
|
||||
const { resourceField, resourceName, viewName, filter } = ctx.action.params;
|
||||
// TODO: 需要补充默认视图的情况
|
||||
let view: any;
|
||||
if (viewName) {
|
||||
view = await ctx.db.getModel('views').findOne({
|
||||
where: {
|
||||
collection_name: resourceField ? resourceField.options.target : resourceName,
|
||||
name: viewName,
|
||||
}
|
||||
});
|
||||
const viewFilter = view.get('filter');
|
||||
if (viewFilter) {
|
||||
const args = [viewFilter, filter].filter(Boolean);
|
||||
ctx.action.setParam('filter', {and: args});
|
||||
console.log(ctx.action.params.filter);
|
||||
}
|
||||
}
|
||||
await next();
|
||||
});
|
||||
// api.resourcer.use(async (ctx: actions.Context, next) => {
|
||||
// const { resourceField, resourceName, viewName, filter } = ctx.action.params;
|
||||
// // TODO: 需要补充默认视图的情况
|
||||
// let view: any;
|
||||
// if (viewName) {
|
||||
// view = await ctx.db.getModel('views').findOne({
|
||||
// where: {
|
||||
// collection_name: resourceField ? resourceField.options.target : resourceName,
|
||||
// name: viewName,
|
||||
// }
|
||||
// });
|
||||
// const viewFilter = view.get('filter');
|
||||
// if (viewFilter) {
|
||||
// const args = [viewFilter, filter].filter(Boolean);
|
||||
// ctx.action.setParam('filter', {and: args});
|
||||
// console.log(ctx.action.params.filter);
|
||||
// }
|
||||
// }
|
||||
// await next();
|
||||
// });
|
||||
|
||||
api.registerPlugin('plugin-collections', [path.resolve(__dirname, '../../../plugin-collections'), {}]);
|
||||
api.registerPlugin('plugin-pages', [path.resolve(__dirname, '../../../plugin-pages'), {}]);
|
||||
@ -119,6 +119,7 @@ api.registerPlugin('plugin-file-manager', [path.resolve(__dirname, '../../../plu
|
||||
|
||||
(async () => {
|
||||
await api.loadPlugins();
|
||||
await api.database.getModel('collections').load({skipExisting: true});
|
||||
api.listen(process.env.HTTP_PORT, () => {
|
||||
console.log(`http://localhost:${process.env.HTTP_PORT}/`);
|
||||
});
|
||||
|
@ -53,7 +53,7 @@ export function toWhere(options: any, context: ToWhereContext = {}) {
|
||||
let k;
|
||||
switch (typeof opKey) {
|
||||
case 'function':
|
||||
const name = model ? model.options.name.plural : '';
|
||||
const name = model ? model.name : '';
|
||||
const result = opKey(items[key], {
|
||||
model,
|
||||
database,
|
||||
|
@ -222,6 +222,9 @@ export default async (ctx, next) => {
|
||||
if (resourceName === 'collections') {
|
||||
actionDefaultParams.sort = ['sort'];
|
||||
}
|
||||
if (view.filter) {
|
||||
actionDefaultParams.filter = view.filter;
|
||||
}
|
||||
const appends = [];
|
||||
|
||||
for (const field of fields) {
|
||||
|
Loading…
Reference in New Issue
Block a user