Constructor
# new AdminBro(options)
Parameters:
Name | Type | Description |
---|---|---|
options |
AdminBroOptions | Options passed to AdminBro |
Example
const AdminBro = require('admin-bro')
const admin = new AdminBro(AdminBroOptions)
Members
# static ACTIONS
List of all default actions. If you want to change the behavior for all actions like: list, edit, show, delete and bulk delete you can do this here.
Example
const { ACTIONS } = require('admin-bro')
ACTIONS.show.isAccessible = () => {...}
# static BaseDatabase
An abstract class for all Database Adapters. External adapters have to implement it.
Example
const { BaseDatabase } = require('admin-bro')
class Database extends BaseDatabase {
constructor(ormInstance) {
this.ormInstance = ormInstance
}
resources() {
// fetch resources from your orm and convert to BaseResource
}
}
# static BaseProperty
Class for all properties. External adapters have to implement that or at least their BaseResource implementation should return records of this type.
# static BaseRecord
Class representing all records. External adapters have to implement that or at least their BaseResource implementation should return records of this type.
# static BaseResource
An abstract class for all resources. External adapters have to implement that.
# static Filter
Filter object passed to find method of BaseResource. External adapters have to use it
# static Router
Contains set of routes available within the application. It is used by external plugins.
Example
const { Router } = require('admin-bro')
Router.routes.forEach(route => {
// map your framework routes to admin-bro routes
// see how `admin-bro-expressjs` plugin does it.
})
# static ValidationError
Validation error which is thrown when record fails validation. External adapters have to use it, so AdminBro can print validation errors
# resources
List of all resources available for the AdminBro. They can be fetched with the AdminBro#findResource method
Methods
# static bundle(src) → {String}
Requires given .jsx/.tsx file, that it can be bundled to the frontend. It will be available under AdminBro.UserComponents[componentId].
Parameters:
Name | Type | Description |
---|---|---|
src |
String | Path to a file containing react component. |
componentId - uniq id of a component
Example
const adminBroOptions = {
dashboard: {
component: AdminBro.bundle('./path/to/component'),
}
}
# static registerAdapter(options)
Registers various database adapters written for AdminBro.
Parameters:
Name | Type | Description |
---|---|---|
options |
Object | |
Database |
Class.<BaseDatabase> | subclass of BaseDatabase |
Resource |
Class.<BaseResource> | subclass of BaseResource |
Example
const AdminBro = require('admin-bro')
const MongooseAdapter = require('admin-bro-mongoose')
AdminBro.registerAdapter(MongooseAdapter)
# async static renderLogin(options) → {Promise.<string>}
Renders an entire login page with email and password fields using Renderer.
Used by external plugins
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
Object | ||
action |
String | Login form action url - it could be '/admin/login' |
|
errorMessage |
String |
<optional> |
Optional error message. When set, renderer will print this message in the form |
HTML of the rendered page
# findResource(resourceId) → {BaseResource}
Returns resource base on its ID
Parameters:
Name | Type | Description |
---|---|---|
resourceId |
String | ID of a resource defined under BaseResource#id |
When resource with given id cannot be found
found resource
Example
const User = admin.findResource('users')
await User.findOne(userId)
# async initialize()
Initializes AdminBro instance in production. This function should be called by all external plugins.
Type Definitions
# CurrentAdmin
Currently logged in admin.
Usage with TypeScript
import { CurrentAdmin } from 'admin-bro'
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
email |
string | Admin has one required field which is an email |
|
id |
string |
<optional> |
Id of your admin user |
{...} |
any | Also you can put as many other fields to it as you like. |
# RouterType
Type representing the AdminBro.Router
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
assets |
Array.<object> | ||
assets[].path |
string | ||
assets[].src |
string | ||
routes |
Array.<object> | ||
routes[].method |
string | ||
routes[].path |
string | ||
routes[].Controller |
any | ||
routes[].action |
string | ||
routes[].contentType |
string |
<optional> |