Custom fields feature.

This commit is contained in:
Ahmed Bouhuolia
2019-09-13 20:24:09 +02:00
parent cba17739d6
commit ed4d37c8fb
64 changed files with 2307 additions and 121 deletions

View File

@@ -21,6 +21,11 @@ const Account = bookshelf.Model.extend({
balances() {
return this.hasMany('AccountBalance', 'accounnt_id');
},
}, {
/**
* Cascade delete dependents.
*/
dependents: ['balances'],
});
export default bookshelf.model('Account', Account);

View File

@@ -11,10 +11,18 @@ const Resource = bookshelf.Model.extend({
*/
hasTimestamps: false,
permissions() {
/**
* Resource model may has many views.
*/
views() {
return this.hasMany('View', 'resource_id');
},
roles() {
/**
* Resource model may has many fields.
*/
fields() {
return this.hasMany('ResourceField', 'resource_id');
},
});

View File

@@ -0,0 +1,37 @@
import { snakeCase } from 'lodash';
import bookshelf from './bookshelf';
const ResourceField = bookshelf.Model.extend({
/**
* Table name.
*/
tableName: 'resource_fields',
/**
* Timestamp columns.
*/
hasTimestamps: false,
virtuals: {
/**
* Resource field key.
*/
key() {
return snakeCase(this.attributes.label_name);
},
},
/**
* Resource field may belongs to resource model.
*/
resource() {
return this.belongsTo('Resource', 'resource_id');
},
}, {
/**
* JSON Columns.
*/
jsonColumns: ['options'],
});
export default bookshelf.model('ResourceField', ResourceField);

38
server/src/models/View.js Normal file
View File

@@ -0,0 +1,38 @@
import bookshelf from './bookshelf';
const View = bookshelf.Model.extend({
/**
* Table name.
*/
tableName: 'views',
/**
* Timestamp columns.
*/
hasTimestamps: false,
/**
* View model belongs to resource model.
*/
resource() {
return this.belongsTo('Resource', 'resource_id');
},
/**
* View model may has many columns.
*/
columns() {
return this.belongsToMany('ResourceField', 'view_has_columns', 'view_id', 'field_id');
},
/**
* View model may has many view roles.
*/
viewRoles() {
return this.hasMany('ViewRole', 'view_id');
},
}, {
dependents: ['columns', 'viewRoles'],
});
export default bookshelf.model('View', View);

View File

@@ -0,0 +1,19 @@
import bookshelf from './bookshelf';
const ViewColumn = bookshelf.Model.extend({
/**
* Table name.
*/
tableName: 'view_columns',
/**
* Timestamp columns.
*/
hasTimestamps: false,
view() {
}
});
export default bookshelf.model('ViewColumn', ViewColumn);

View File

@@ -0,0 +1,22 @@
import bookshelf from './bookshelf';
const ViewRole = bookshelf.Model.extend({
/**
* Table name.
*/
tableName: 'view_roles',
/**
* Timestamp columns.
*/
hasTimestamps: false,
/**
* View role model may belongs to view model.
*/
view() {
return this.belongsTo('View', 'view_id');
},
});
export default bookshelf.model('ViewRole', ViewRole);

View File

@@ -2,6 +2,7 @@ import Bookshelf from 'bookshelf';
import jsonColumns from 'bookshelf-json-columns';
import bookshelfParanoia from 'bookshelf-paranoia';
import bookshelfModelBase from 'bookshelf-modelbase';
import cascadeDelete from 'bookshelf-cascade-delete';
import knex from '../database/knex';
const bookshelf = Bookshelf(knex);
@@ -13,5 +14,6 @@ bookshelf.plugin('virtuals');
bookshelf.plugin(jsonColumns);
bookshelf.plugin(bookshelfParanoia);
bookshelf.plugin(bookshelfModelBase.pluggable);
bookshelf.plugin(cascadeDelete);
export default bookshelf;