fix: filter developer mode with isTruly/isFalsy

This commit is contained in:
chenos 2021-01-04 13:14:45 +08:00
parent 10b2199e54
commit 74600f0eb5
3 changed files with 30 additions and 23 deletions

View File

@ -19,7 +19,7 @@ export default async (ctx, next) => {
const options = Tab.parseApiJson({ const options = Tab.parseApiJson({
filter: { filter: {
enabled: true, enabled: true,
developerMode: ctx.state.developerMode, developerMode: ctx.state.developerMode ? {'$isTruly': true} : {'$isFalsy': true},
}, },
fields: { fields: {
appends: ['associationField'], appends: ['associationField'],

View File

@ -42,7 +42,7 @@ export default async function getRoutes(ctx, next) {
const Collection = database.getModel('collections'); const Collection = database.getModel('collections');
let pages = await Page.findAll(Page.parseApiJson({ let pages = await Page.findAll(Page.parseApiJson({
filter: { filter: {
'developerMode': ctx.state.developerMode, developerMode: ctx.state.developerMode ? {'$isTruly': true} : {'$isFalsy': true},
}, },
sort: ['sort'], sort: ['sort'],
})); }));
@ -52,7 +52,7 @@ export default async function getRoutes(ctx, next) {
if (page.get('path') === '/collections') { if (page.get('path') === '/collections') {
const collections = await Collection.findAll(Collection.parseApiJson({ const collections = await Collection.findAll(Collection.parseApiJson({
filter: { filter: {
developerMode: ctx.state.developerMode, developerMode: ctx.state.developerMode ? {'$isTruly': true} : {'$isFalsy': true},
showInDataMenu: true, showInDataMenu: true,
}, },
sort: ['sort'], sort: ['sort'],

View File

@ -38,13 +38,14 @@ const transforms = {
} }
if (field.get('name') === 'filter' && field.get('collection_name') === 'views') { if (field.get('name') === 'filter' && field.get('collection_name') === 'views') {
const { values } = ctx.action.params; const { values } = ctx.action.params;
const all = await Field.findAll({ const options = Field.parseApiJson({
where: { filter: {
collection_name: get(values, 'associatedKey'), collection_name: get(values, 'associatedKey'),
developerMode: ctx.state.developerMode, developerMode: ctx.state.developerMode ? {'$isTruly': true} : {'$isFalsy': true},
}, },
order: [['sort', 'asc']], sort: 'sort',
}); });
const all = await Field.findAll(options);
set(prop, 'x-component-props.fields', all.filter(f => f.get('filterable'))); set(prop, 'x-component-props.fields', all.filter(f => f.get('filterable')));
} }
if (type === 'select') { if (type === 'select') {
@ -160,20 +161,22 @@ export default async (ctx, next) => {
name: resourceName, name: resourceName,
}, },
}); });
const where: any = { // const where: any = {
developerMode: ctx.state.developerMode, // developerMode: ctx.state.developerMode,
// }
const filter: any = {
developerMode: ctx.state.developerMode ? {'$isTruly': true} : {'$isFalsy': true},
} }
if (!view.get('draggable')) { if (!view.get('draggable')) {
where.type = { filter.type = {
[Op.not]: 'sort', not: 'sort',
}; };
} }
let fields = await collection.getFields({ const fieldOptions = Field.parseApiJson({
where, filter,
order: [ sort: 'sort',
['sort', 'asc'],
]
}); });
let fields = await collection.getFields(fieldOptions);
fields = fields.filter(field => { fields = fields.filter(field => {
if (field.get('interface') === 'linkTo') { if (field.get('interface') === 'linkTo') {
if (throughName && throughName === field.get('through')) { if (throughName && throughName === field.get('through')) {
@ -182,18 +185,18 @@ export default async (ctx, next) => {
} }
return true; return true;
}) })
const actions = await collection.getActions({ const options = Action.parseApiJson({
where: { filter: {
developerMode: ctx.state.developerMode, developerMode: ctx.state.developerMode ? {'$isTruly': true} : {'$isFalsy': true},
}, },
order: [ sort: 'sort',
['sort', 'asc'],
]
}); });
const actions = await collection.getActions(options);
let actionNames = view.get('actionNames') || []; let actionNames = view.get('actionNames') || [];
if (actionNames.length === 0) { if (actionNames.length === 0) {
actionNames = ['filter', 'create', 'destroy']; actionNames = ['filter', 'create', 'destroy'];
} }
if (view.get('type') === 'table') { if (view.get('type') === 'table') {
const defaultTabs = await collection.getTabs({ const defaultTabs = await collection.getTabs({
where: { where: {
@ -202,10 +205,14 @@ export default async (ctx, next) => {
}); });
view.setDataValue('defaultTabName', get(defaultTabs, [0, 'name'])); view.setDataValue('defaultTabName', get(defaultTabs, [0, 'name']));
} }
if (view.get('type') === 'table') { if (view.get('type') === 'table') {
view.setDataValue('rowViewName', 'form'); view.setDataValue('rowViewName', 'form');
} }
if (view.get('type') === 'calendar') {
view.setDataValue('template', 'Calendar');
view.setDataValue('rowViewName', 'form');
}
if (view.get('updateViewName')) { if (view.get('updateViewName')) {
view.setDataValue('rowViewName', view.get('updateViewName')); view.setDataValue('rowViewName', view.get('updateViewName'));
} }