fix: clean up code and fix tests

This commit is contained in:
chenos 2021-03-19 21:27:42 +08:00
parent 53c62e922d
commit 81399f6037
25 changed files with 26 additions and 662 deletions

View File

@ -53,13 +53,4 @@ export default {
title: '查看' title: '查看'
} }
], ],
views: [
{
type: 'table',
name: 'table',
title: '列表',
template: 'Table',
default: true,
},
],
} as TableOptions; } as TableOptions;

View File

@ -97,21 +97,6 @@ export default {
// sort: '-created_at' // sort: '-created_at'
}, },
], ],
views: [
{
type: 'table',
name: 'table',
title: '列表',
template: 'Table',
default: true
},
{
type: 'details',
name: 'details',
title: '详情',
template: 'Details',
},
],
views_v2: [ views_v2: [
{ {
developerMode: true, developerMode: true,

View File

@ -465,48 +465,6 @@ export default {
title: '任务', title: '任务',
}, },
], ],
views: [
{
type: 'form',
name: 'form',
title: '表单',
template: 'DrawerForm',
developerMode: true,
},
{
type: 'details',
name: 'details',
title: '详情',
template: 'Details',
actionNames: ['update'],
developerMode: true,
},
{
type: 'table',
name: 'table',
title: '全部数据',
template: 'Table',
actionNames: ['destroy', 'create'],
default: true,
draggable: true,
},
],
tabs: [
{
type: 'details',
name: 'details',
title: '详情',
viewName: 'details',
},
{
type: 'association',
name: 'jobs',
title: '任务',
association: 'jobs',
viewName: 'table',
default: true,
},
],
views_v2: [ views_v2: [
{ {
developerMode: true, developerMode: true,

View File

@ -124,42 +124,6 @@ export default {
}, },
}, },
], ],
views: [
{
type: 'form',
name: 'form',
title: '表单',
template: 'DrawerForm',
developerMode: true,
},
{
type: 'details',
name: 'details',
title: '详情',
template: 'Details',
actionNames: ['update'],
developerMode: true,
},
{
type: 'table',
name: 'table',
title: '全部数据',
template: 'Table',
mode: 'simple',
actionNames: ['destroy', 'create'],
default: true,
draggable: true,
},
],
tabs: [
{
type: 'details',
name: 'details',
title: '详情',
viewName: 'details',
default: true,
},
],
views_v2: [ views_v2: [
{ {
developerMode: true, developerMode: true,

View File

@ -26,6 +26,7 @@ describe('models.collection', () => {
title: '示例', title: '示例',
name: 'examples', name: 'examples',
showInDataMenu: true, showInDataMenu: true,
statusable: false,
fields: [ fields: [
{ {
interface: 'string', interface: 'string',

View File

@ -114,34 +114,4 @@ export default {
viewName: 'form', viewName: 'form',
}, },
], ],
views: [
{
type: 'form',
name: 'form',
title: '表单',
template: 'DrawerForm',
developerMode: true,
},
{
type: 'details',
name: 'details',
title: '详情',
template: 'Details',
actionNames: ['update'],
developerMode: true,
},
{
type: 'table',
name: 'simple',
title: '简易模式',
template: 'Table',
mode: 'simple',
default: true,
actionNames: ['destroy', 'create'],
detailsViewName: 'details',
updateViewName: 'form',
paginated: false,
draggable: true,
},
],
} as TableOptions; } as TableOptions;

View File

@ -378,94 +378,6 @@ export default {
viewName: 'form', viewName: 'form',
}, },
], ],
views: [
{
type: 'form',
name: 'form',
title: '表单',
template: 'DrawerForm',
developerMode: true,
},
{
type: 'details',
name: 'details',
title: '详情',
template: 'Details',
actionNames: ['update'],
developerMode: true,
},
{
type: 'table',
name: 'permissionTable',
title: '权限设置表格',
mode: 'simple',
template: 'SimpleTable',
// actionNames: ['create', 'destroy'],
detailsViewName: 'details',
updateViewName: 'permissionForm',
},
{
type: 'form',
name: 'permissionForm',
title: '权限设置表单',
mode: 'simple',
template: 'DrawerForm',
},
{
type: 'table',
name: 'table',
title: '全部数据',
template: 'Table',
actionNames: ['destroy', 'create'],
default: true,
draggable: true,
},
],
tabs: [
{
type: 'details',
name: 'details',
title: '详情',
viewName: 'details',
default: true,
},
{
type: 'association',
name: 'fields',
title: '字段',
association: 'fields',
viewName: 'simple',
},
{
type: 'association',
name: 'views',
title: '视图',
association: 'views',
viewName: 'simple',
},
{
type: 'association',
name: 'actions',
title: '动作',
association: 'actions',
viewName: 'simple',
developerMode: true,
},
{
type: 'association',
name: 'tabs',
title: '标签页',
association: 'tabs',
viewName: 'simple',
},
// {
// type: 'association',
// name: 'roles',
// title: '权限',
// association: 'roles',
// viewName: 'simple2',
// },
],
views_v2: [ views_v2: [
{ {
developerMode: true, developerMode: true,

View File

@ -614,36 +614,6 @@ export default {
viewName: 'form', viewName: 'form',
}, },
], ],
views: [
{
type: 'form',
name: 'form',
title: '表单',
template: 'DrawerForm',
developerMode: true,
},
{
type: 'details',
name: 'details',
title: '详情',
template: 'Details',
actionNames: ['update'],
developerMode: true,
},
{
type: 'table',
name: 'simple',
title: '简易模式',
template: 'Table',
mode: 'simple',
default: true,
actionNames: ['destroy', 'create'],
detailsViewName: 'details',
updateViewName: 'form',
paginated: false,
draggable: true,
},
],
views_v2: [ views_v2: [
{ {
developerMode: true, developerMode: true,

View File

@ -30,49 +30,6 @@ const defaultValues = {
viewName: 'form', viewName: 'form',
}, },
], ],
views: [
{
type: 'form',
name: 'form',
title: '表单',
template: 'DrawerForm',
developerMode: true,
},
{
type: 'details',
name: 'details',
title: '详情',
template: 'Details',
actionNames: ['update'],
developerMode: true,
},
// {
// type: 'table',
// name: 'simple',
// title: '简易模式',
// template: 'SimpleTable',
// actionNames: ['create', 'destroy'],
// detailsViewName: 'details',
// updateViewName: 'form',
// },
{
type: 'table',
name: 'table',
title: '全部数据',
template: 'Table',
actionNames: ['filter', 'destroy', 'create'],
default: true,
},
],
tabs: [
{
type: 'details',
name: 'details',
title: '详情',
viewName: 'details',
default: true,
},
],
}; };
export default async function (model: CollectionModel, options: any = {}) { export default async function (model: CollectionModel, options: any = {}) {

View File

@ -120,12 +120,18 @@ export class CollectionModel extends BaseModel {
} }
async getOptions(): Promise<TableOptions> { async getOptions(): Promise<TableOptions> {
return { const options: any = {
...this.get(), ...this.get(),
actions: await this.getActions(), actions: await this.getActions(),
fields: await this.getFieldsOptions(), fields: await this.getFieldsOptions(),
views_v2: await this.getViews_v2(), }
}; // @ts-ignore
// console.log(this.constructor.associations);
// @ts-ignore
if (this.constructor.hasAlias('views_v2')) {
options.views_v2 = await this.getViews_v2();
}
return options;
} }
/** /**
@ -178,6 +184,9 @@ export class CollectionModel extends BaseModel {
continue; continue;
} }
const Model = this.database.getModel(key); const Model = this.database.getModel(key);
if (!Model) {
continue;
}
let ids = []; let ids = [];
for (const index in data[key]) { for (const index in data[key]) {
if (key === 'fields') { if (key === 'fields') {

View File

@ -40,6 +40,10 @@ export default async function (this: Application, options = {}) {
return; return;
} }
if (model.get('statusable') === false) {
return;
}
console.log("model.get('developerMode')", model.get('name')); console.log("model.get('developerMode')", model.get('name'));
const { transaction = await model.sequelize.transaction() } = options; const { transaction = await model.sequelize.transaction() } = options;

View File

@ -83,36 +83,4 @@ export default {
title: '删除', title: '删除',
}, },
], ],
views: [
{
type: 'form',
name: 'form',
title: '表单',
template: 'DrawerForm',
},
{
type: 'details',
name: 'details',
title: '详情',
template: 'Details',
actionNames: ['update'],
},
{
type: 'simple',
name: 'simple',
title: '简易模式',
template: 'SimpleTable',
actionNames: ['create', 'destroy'],
detailsViewName: 'details',
updateViewName: 'form',
default: true,
},
{
type: 'table',
name: 'table',
title: '列表',
template: 'Table',
actionNames: ['create', 'destroy'],
},
],
} as TableOptions; } as TableOptions;

View File

@ -27,7 +27,7 @@ describe('fields', () => {
afterEach(() => app.database.close()); afterEach(() => app.database.close());
async function createField(options: Options) { async function createField(options: any) {
return await collection.createField(options); return await collection.createField(options);
} }

View File

@ -235,48 +235,4 @@ export default {
title: '删除', title: '删除',
}, },
], ],
views: [
{
type: 'form',
name: 'form',
title: '表单',
template: 'DrawerForm',
},
{
type: 'details',
name: 'details',
title: '详情',
template: 'Details',
actionNames: ['update'],
},
{
type: 'table',
name: 'simple',
title: '简易模式',
template: 'SimpleTable',
default: true,
mode: 'simple',
actionNames: ['create', 'destroy'],
detailsViewName: 'details',
updateViewName: 'form',
paginated: false,
},
{
type: 'table',
name: 'table',
title: '列表',
template: 'Table',
actionNames: ['create', 'destroy'],
},
{
type: 'table',
name: 'permissionTable',
title: '菜单权限',
template: 'Table',
mode: 'simple',
detailsViewName: 'details',
updateViewName: 'form',
paginated: false,
},
],
} as TableOptions; } as TableOptions;

View File

@ -160,40 +160,6 @@ export default {
title: '删除', title: '删除',
}, },
], ],
views: [
{
type: 'form',
name: 'form',
title: '表单',
template: 'DrawerForm',
},
{
type: 'details',
name: 'details',
title: '详情',
template: 'Details',
actionNames: ['update'],
},
{
type: 'table',
name: 'simple',
title: '简易模式',
template: 'SimpleTable',
default: true,
mode: 'simple',
actionNames: ['create', 'destroy'],
detailsViewName: 'details',
updateViewName: 'form',
paginated: false,
},
{
type: 'table',
name: 'table',
title: '列表',
template: 'Table',
actionNames: ['create', 'destroy'],
},
],
views_v2: [ views_v2: [
{ {
developerMode: true, developerMode: true,

View File

@ -20,24 +20,4 @@ export default extend({
constraints: false, // 多态关联建立外键约束会有问题 constraints: false, // 多态关联建立外键约束会有问题
} }
], ],
tabs: [
{
type: 'association',
name: 'pages',
title: '系统菜单权限',
association: 'pages',
viewName: 'permissionTable',
},
]
}, {
customMerge(key) {
if (['tabs'].includes(key)) {
return (x = [], y = []) => {
const last = x.pop();
const tabs = x.concat(y);
tabs.push(last);
return tabs;
};
}
}
}); });

View File

@ -27,6 +27,7 @@ export default {
labelField: 'title', labelField: 'title',
valueField: 'id', valueField: 'id',
multiple: false, multiple: false,
viewName: 'fields.form',
component: { component: {
type: 'drawerSelect', type: 'drawerSelect',
'x-component-props': { 'x-component-props': {

View File

@ -219,40 +219,6 @@ export default {
title: '删除', title: '删除',
}, },
], ],
views: [
{
type: 'form',
name: 'form',
title: '表单',
template: 'DrawerForm',
},
{
type: 'details',
name: 'details',
title: '详情',
template: 'Details',
actionNames: ['update'],
},
{
type: 'table',
name: 'simple',
title: '简易模式',
template: 'SimpleTable',
default: true,
mode: 'simple',
actionNames: ['create', 'destroy'],
detailsViewName: 'details',
updateViewName: 'form',
paginated: false,
},
{
type: 'table',
name: 'table',
title: '列表',
template: 'Table',
actionNames: ['create', 'destroy'],
},
],
views_v2: [ views_v2: [
{ {
developerMode: true, developerMode: true,

View File

@ -15,10 +15,9 @@ describe('list', () => {
const User = db.getModel('users'); const User = db.getModel('users');
const users = await User.findAll({ order: [['id', 'ASC']] }); const users = await User.findAll({ order: [['id', 'ASC']] });
userAgents = users.map(user => { userAgents = users.map(user => {
const userAgent = getAgent(app); const userAgent = getAgent(app);
userAgent.set('Authorization', `Bearer ${users[0].token}`); userAgent.set('Authorization', `Bearer ${user.token}`);
return userAgent; return userAgent;
}); });

View File

@ -144,9 +144,9 @@ export default async function(db) {
const Post = db.getModel('posts'); const Post = db.getModel('posts');
await Post.bulkCreate([ await Post.bulkCreate([
{ title: 'title1', created_by_id: users[0].id }, { title: 'title1', created_by_id: users[0].id, status: 'draft' },
{ title: 'title2', created_by_id: users[0].id }, { title: 'title2', created_by_id: users[0].id, status: 'draft' },
{ title: 'title3', created_by_id: users[1].id }, { title: 'title3', created_by_id: users[1].id, status: 'draft' },
{ title: 'title4', created_by_id: users[3].id }, { title: 'title4', created_by_id: users[3].id, status: 'draft' },
]); ]);
} }

View File

@ -4,6 +4,7 @@ export default {
name: 'posts', name: 'posts',
// 目前默认就带了 // 目前默认就带了
// createdBy: true, // createdBy: true,
statusable: false,
fields: [ fields: [
{ {
type: 'string', type: 'string',
@ -12,6 +13,7 @@ export default {
{ {
type: 'string', type: 'string',
name: 'status', name: 'status',
// TODO(BUG): 默认值无效
defaultValue: 'draft', defaultValue: 'draft',
}, },
{ {

View File

@ -18,38 +18,4 @@ export default extend({
// foreignKey: 'collection_name' // foreignKey: 'collection_name'
// } // }
], ],
views: [
{
type: 'table',
name: 'permissionTable',
title: '权限设置表格',
mode: 'simple',
template: 'SimpleTable',
// actionNames: ['create', 'destroy'],
detailsViewName: 'details',
updateViewName: 'permissionForm',
},
{
type: 'form',
name: 'permissionForm',
title: '权限设置表单',
mode: 'simple',
template: 'DrawerForm',
},
],
tabs: [
{
type: 'association',
name: 'permissions',
title: '权限',
association: 'roles',
viewName: 'permissionTable',
},
],
}, {
customMerge(key) {
if (['views', 'tabs'].includes(key)) {
return (x = [], y = []) => x.concat(y);
}
}
}); });

View File

@ -72,37 +72,4 @@ export default {
name: 'tabs_permissions', name: 'tabs_permissions',
}, },
], ],
views: [
{
type: 'form',
name: 'form',
title: '表单',
template: 'DrawerForm',
},
{
type: 'details',
name: 'details',
title: '详情',
template: 'Details',
actionNames: ['update'],
},
{
type: 'simple',
name: 'simple',
title: '简易模式',
mode: 'simple',
template: 'SimpleTable',
actionNames: ['create', 'destroy'],
detailsViewName: 'details',
updateViewName: 'form',
},
{
type: 'table',
name: 'table',
title: '列表',
template: 'Table',
actionNames: ['create', 'destroy'],
default: true,
},
],
} as TableOptions; } as TableOptions;

View File

@ -125,85 +125,6 @@ export default {
} }
}, },
], ],
views: [
{
type: 'form',
name: 'form',
title: '表单',
template: 'DrawerForm',
},
{
type: 'details',
name: 'details',
title: '详情',
template: 'Details',
actionNames: ['update'],
},
{
type: 'table',
name: 'simple',
title: '简易模式',
mode: 'simple',
template: 'SimpleTable',
actionNames: ['create', 'destroy'],
detailsViewName: 'details',
updateViewName: 'form',
},
{
type: 'table',
name: 'table',
title: '列表',
template: 'Table',
actionNames: ['create', 'destroy'],
default: true,
},
{
type: 'table',
name: 'permissionTable',
title: '权限设置表格',
mode: 'simple',
template: 'SimpleTable',
// actionNames: ['create', 'destroy'],
detailsViewName: 'details',
updateViewName: 'permissionForm',
},
{
type: 'form',
name: 'permissionForm',
title: '权限设置表单',
mode: 'simple',
template: 'DrawerForm',
},
],
tabs: [
{
type: 'details',
name: 'details',
title: '详情',
viewName: 'details',
default: true,
},
// {
// type: 'details',
// name: 'collections',
// title: '数据表权限',
// viewName: 'simple',
// },
{
type: 'association',
name: 'collections',
title: '数据表权限',
association: 'collections',
viewName: 'permissionTable',
},
{
type: 'association',
name: 'users',
title: '当前组用户',
association: 'users',
viewName: 'simple',
},
],
views_v2: [ views_v2: [
{ {
developerMode: true, developerMode: true,

View File

@ -110,55 +110,6 @@ export default {
viewName: 'form', viewName: 'form',
}, },
], ],
views: [
{
type: 'form',
name: 'form',
title: '表单',
template: 'DrawerForm',
developerMode: true,
},
{
type: 'form',
name: 'login',
title: '登录',
template: 'Login',
developerMode: true,
},
{
type: 'form',
name: 'register',
title: '注册',
template: 'Register',
developerMode: true,
},
{
type: 'details',
name: 'details',
title: '详情',
template: 'Details',
actionNames: ['update'],
developerMode: true,
},
{
type: 'table',
name: 'simple',
title: '简易模式',
mode: 'simple',
template: 'Table',
actionNames: ['create', 'destroy'],
detailsViewName: 'details',
updateViewName: 'form',
default: true,
},
{
type: 'table',
name: 'table',
title: '列表',
template: 'Table',
actionNames: ['create', 'destroy'],
},
],
views_v2: [ views_v2: [
{ {
developerMode: true, developerMode: true,