Class: ModelAdmin

ModelAdmin(model)

Wrapper over Sequelize.Model

Constructor

new ModelAdmin(model)

Parameters:
Name Type Description
model Sequelize.Model The model produced by Sequelize.define
Properties:
Name Type Description
actions Array.<ModelAdmin~action> List of actions
list_fields array.<String> List of fields, visible on list view. You can define nonexistent field here and define its view method via addFieldsDescriptions
list_links array.<String> List of fields, which are links
list_exclude array.<String> List of fields, excluded from list view You can define nonexistent field here to show all fields
list_per_page number Number of entries on list view page
search_fields array.<String> Searchable fields if not set -- all STRING and TEXT fields
ordering array.<String> Default model list ordering, prepend minus means desc order example: ['date', '-active']
editor_fields array.<String> List of fields, visible on entry editor screen
readonly_fields array.<String> List of readonly fields
icon String Html code of icon in model list screen. Default <span class="oi oi-list"></span>
Source:

Members

(readonly) model :Sequelize.Model

Model instance
Type:
  • Sequelize.Model
Source:

(readonly) name :String

Model name
Type:
  • String
Source:

(readonly) namePlural :String

Model plural name
Type:
  • String
Source:

(readonly) pkName :String

Model primary key name
Type:
  • String
Source:

Methods

(static) entryRenderer(req, res, next)

Render entry editor view instead default one
Parameters:
Name Type Description
req Express.Request
res Express.Response
next function
Source:

(static) modelListRenderer(req, res, next)

Render model view instead default model list
Parameters:
Name Type Description
req Express.Request
res Express.Response
next function
Source:

addExtraResource(resources)

Push extra js or css to page section. Resources can be tag or url or array of those. Url type is determined by endsWith('js|css') so you can add #js to end.
Parameters:
Name Type Description
resources String | Array.<String>
Source:

addFieldDescriptions(descriptions)

Add field descriptions
Parameters:
Name Type Description
descriptions ModelAdmin~fieldDescriptions
Source:

beforeListRender(req, count, entries)

Override this to do something before model list will rendered, for example do subquery or compute average. You have to cache the result within req object to use it in ModelAdmin~viewRenderer callback
Parameters:
Name Type Description
req Express.Request
count Number Count of selected entries considering search param
entries Array.<Object> Selected entries
Source:

overrideTypeSetter(type, setter)

Override setter function for selected field type
Parameters:
Name Type Description
type String type for override, e.g. DATE, HasOne etc
setter ModelAdmin~setter render function
Source:

overrideTypeView(type, renderer)

Override view render function for selected field type
Parameters:
Name Type Description
type String type for override, e.g. DATE, HasOne etc
renderer ModelAdmin~viewRenderer render function
Source:

overrideTypeWidget(type, widgetRenderer)

Override widget render function for selected type
Parameters:
Name Type Description
type String type for override, e.g. enum of Sequelise.TYPE - DATE, HasOne etc
widgetRenderer ModelAdmin~widgetRenderer
Source:
Returns:
widget html

repr(req, entry) → {String|Promise.<String>}

Override this for custom entry representation, default is entry label + primary key
Parameters:
Name Type Description
req Express.Request
entry Sequelize.ModelInstance
Source:
Returns:
Type
String | Promise.<String>

setFieldDescription(fieldName, description)

Set description for field fieldName
Parameters:
Name Type Description
fieldName String
description ModelAdmin~fieldDescription
Source:

Type Definitions

action

Represent action structure. Define name and *ONE* of [renderer|changer] callback.
Type:
  • object
Properties:
Name Type Description
name String action name
renderer ModelAdmin~actionRenderer render function
changer ModelAdmin~actionChanger simple entry change function
Source:

actionChanger(entry) → {Promise|any}

Simple per-entry update callback, just get entry and update it fields
Parameters:
Name Type Description
entry Object
Source:
To Do:
  • show errors
Returns:
Type
Promise | any

actionRenderer(req, res, modelAdmin, ids, exit) → {Promise.<String>}

Full-featured render callback. You can create own navigation, confirmation, etc. Also, you must handle transaction manually. To return to entry list call exit callback
Parameters:
Name Type Description
req Express.Request
res Express.Response
modelAdmin ModelAdmin ModelAdmin instance, associated with current model
ids Array.<*> list of selected model primaryKeys
exit function return callback, redirects to entry list
Source:
To Do:
  • show errors
Returns:
page html
Type
Promise.<String>

fieldDescription

Type:
  • object
Properties:
Name Type Description
view ModelAdmin~viewRenderer | String View renderer or type name
html boolean Indicates that view produce html, so you must escape it self
widget ModelAdmin~widgetRenderer | String Widget renderer or type name
setter ModelAdmin~setter | String setter function or type name
Source:

fieldDescriptions

Type:
  • object
Properties:
Name Type Description
$fieldName ModelAdmin~fieldDescription
Source:

setter(req, entry, fieldName, transaction) → {Promise}

Set value of entry field $fieldName given at req.body[fieldName]
Parameters:
Name Type Description
req Express.Request
entry Sequelize.ModelInstance
fieldName String
transaction *
Source:
Returns:
Type
Promise

viewRenderer(req, entry, fieldName) → {String|Promise.<String>}

Render entry field for table view
Parameters:
Name Type Description
req Express.Request
entry Sequelize.ModelInstance
fieldName String
Source:
Returns:
Type
String | Promise.<String>

widgetRenderer(req, entry, fieldName, value, options) → {String|Promise.<String>}

Render entry field for editor widget
Parameters:
Name Type Description
req Express.Request
entry Sequelize.ModelInstance
fieldName String
value * Raw field value from database entry or http post request
options Object widget options, readOnly mostly
Source:
Returns:
rendered html widget
Type
String | Promise.<String>