forked from SoftwareBrothers/adminjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ba4cf4a
Showing
44 changed files
with
10,552 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"env": { | ||
"test": { | ||
"plugins": [ "istanbul" ] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
npm-debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module.exports = { | ||
'env': { | ||
'es6': true, | ||
'node': true, | ||
'mocha': true | ||
}, | ||
'extends': 'airbnb', | ||
'parserOptions': { | ||
'ecmaVersion': 2018, | ||
'sourceType': 'module' | ||
}, | ||
'rules': { | ||
'indent': [ | ||
'error', | ||
2 | ||
], | ||
'linebreak-style': [ | ||
'error', | ||
'unix' | ||
], | ||
'quotes': [ | ||
'error', | ||
'single' | ||
], | ||
'semi': [ | ||
'error', | ||
'never' | ||
], | ||
'import/no-unresolved': 'off', | ||
'no-underscore-dangle': 'off', | ||
'guard-for-in': 'off', | ||
'no-restricted-syntax': 'off', | ||
'no-await-in-loop': 'off', | ||
}, | ||
overrides: [ | ||
{ | ||
files: ['*-test.js', '*.spec.js'], | ||
rules: { | ||
'no-unused-expressions': 'off', | ||
'func-names': 'off', | ||
'prefer-arrow-callback': 'off' | ||
} | ||
} | ||
], | ||
globals: { | ||
'expect': true, | ||
'factory': true, | ||
'sandbox': true, | ||
'server': true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
.nyc_output | ||
docs | ||
coverage | ||
.DS_store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Admin Bro |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const NotImplementedError = require('../../utils/not-implemented-error') | ||
|
||
/** | ||
* Representation of an ORM/database AdminBro | ||
*/ | ||
class AbstractDatabase { | ||
/** | ||
* Return name of the database | ||
* @return {String} | ||
*/ | ||
name() { | ||
throw new NotImplementedError() | ||
} | ||
|
||
/** | ||
* returns array of all models (collections/tables) in the database | ||
* @return {AbstractModel[]} | ||
*/ | ||
models() { | ||
throw new NotImplementedError() | ||
} | ||
|
||
/** | ||
* returns model for given name | ||
* @return {AbstractModel} | ||
*/ | ||
find(modelName) { | ||
throw new NotImplementedError() | ||
} | ||
} | ||
|
||
module.exports = AbstractDatabase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class AbstractInstance { | ||
constructor(args) { | ||
this.args = args | ||
} | ||
|
||
save(params) { | ||
|
||
} | ||
} | ||
|
||
module.exports = AbstractInstance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const NotImplementedError = require('../../utils/not-implemented-error') | ||
|
||
/** | ||
* Representation of a ORM Model in AdminBro | ||
*/ | ||
class AbstractModel { | ||
/** | ||
* Return name of the model | ||
* @return {String} | ||
*/ | ||
name() { | ||
throw new NotImplementedError() | ||
} | ||
|
||
/** | ||
* returns array of properties | ||
* @return {AbstractProperty[]} | ||
*/ | ||
properties() { | ||
throw new NotImplementedError() | ||
} | ||
|
||
/** | ||
* returns property object for given field | ||
* @return {AbstractProperty} | ||
*/ | ||
property(name) { | ||
throw new NotImplementedError() | ||
} | ||
|
||
/** | ||
* Returns number of elements for given model | ||
* @return {[type]} [description] | ||
*/ | ||
count() { | ||
throw new NotImplementedError() | ||
} | ||
|
||
/** | ||
* Returns actual records for given model | ||
* @param {Object} where query | ||
* @param {Number} options.limit how many records should be taken | ||
* @param {Number} options.offset offset | ||
* @return {Object[]} list of all records | ||
*/ | ||
find(where, { limit=20, offset=0 }) { | ||
throw new NotImplementedError() | ||
} | ||
} | ||
|
||
module.exports = AbstractModel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const TITLE_COLUMN_NAMES = ['title', 'name', 'subject'] | ||
|
||
class AbstractProperty { | ||
|
||
/** | ||
* Name of the property | ||
* @return {[type]} [description] | ||
*/ | ||
name() { | ||
|
||
} | ||
|
||
/** | ||
* Return type of a property | ||
* @return {String} One of available property types: | ||
* [id, string, object, float, number, boolean, | ||
* text, date] | ||
*/ | ||
type() { | ||
|
||
} | ||
|
||
/** | ||
* When properties are nested - parent property should have its children | ||
* @return {AbstractProperty[]} [description] | ||
*/ | ||
childProperties() { | ||
return null | ||
} | ||
} | ||
|
||
module.exports = AbstractProperty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const MongooseDatabase = require('./mongoose/database') | ||
|
||
const DatabaseFactory = (database) => { | ||
if (database.constructor.name === 'Mongoose') { | ||
return database.connections.map(connection => new MongooseDatabase(connection)) | ||
} | ||
throw new Error(`unsupported database type ${database}`) | ||
} | ||
|
||
module.exports = DatabaseFactory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const AbstractDatabase = require('../abstract/database') | ||
const Model = require('./model') | ||
|
||
/** | ||
* Adapter for mongoose database | ||
*/ | ||
class Database extends AbstractDatabase { | ||
constructor(connection) { | ||
super(connection) | ||
this.connection = connection | ||
} | ||
|
||
models() { | ||
return Model.all(this.connection) | ||
} | ||
|
||
name() { | ||
return this.connection.name | ||
} | ||
|
||
find(modelName) { | ||
return Model.find(this.connection, modelName) | ||
} | ||
} | ||
|
||
module.exports = Database |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const AbstractInstance = require('../abstract/instance') | ||
|
||
class Instance extends AbstractInstance { | ||
} | ||
|
||
module.exports = Instance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
const AbstractModel = require('../abstract/model') | ||
const Instance = require('./instance') | ||
const Property = require('./property') | ||
|
||
/** | ||
* Adapter for mongoose model | ||
*/ | ||
class Model extends AbstractModel { | ||
/** | ||
* Return all available models for given connection | ||
* @param {Object} mongooseConnection mongoose connection object | ||
* @return {Model[]} list of all models in given mongo database | ||
* | ||
* @example | ||
* const mongoose = require('mongoose') | ||
* | ||
* const connection = await mongoose.connect(process.env.MONGO_URL) | ||
* Model.all(connection) | ||
*/ | ||
static all(mongooseConnection) { | ||
return mongooseConnection.modelNames().map(name => Model.find(mongooseConnection, name)) | ||
} | ||
|
||
/** | ||
* Return Model object for given collection name | ||
* @param {Object} mongooseConnection mongoose connection object | ||
* @param {String} name name of mongoose model | ||
* @return {Model} model adapter for given mongodb model | ||
* | ||
* @example | ||
* const mongoose = require('mongoose') | ||
* | ||
* const connection = await mongoose.connect(process.env.MONGO_URL) | ||
* Model.all(connection) | ||
*/ | ||
static find(mongooseConnection, name) { | ||
const mongoModel = mongooseConnection.model(name) | ||
return new Model(mongoModel) | ||
} | ||
|
||
constructor(mongoModel) { | ||
super(mongoModel) | ||
this.model = mongoModel | ||
} | ||
|
||
async count() { | ||
return this.model.countDocuments() | ||
} | ||
|
||
async find(query, { limit = 20, offset = 0 }) { | ||
const raw = await this.model.find({}).skip(offset).limit(limit) | ||
return raw.map(m => new Instance(m)) | ||
} | ||
|
||
name() { | ||
return this.model.modelName | ||
} | ||
|
||
properties() { | ||
const properties = [] | ||
for (const [name, path] of Object.entries(this.model.schema.paths)) { | ||
const prop = new Property(name, path) | ||
properties.push(prop) | ||
} | ||
return properties | ||
} | ||
|
||
property(name) { | ||
return new Property(name, this.model.schema.paths[name]) | ||
} | ||
} | ||
|
||
module.exports = Model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const AbstractProperty = require('../abstract/property') | ||
|
||
class Property extends AbstractProperty { | ||
constructor(name, mongoosePath) { | ||
super() | ||
this.name = name | ||
this.path = mongoosePath | ||
} | ||
} | ||
|
||
module.exports = Property |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class NotImplementedError extends Error { | ||
constructor(args) { | ||
super(args) | ||
this.message = 'You have to implement this' | ||
} | ||
} | ||
|
||
module.exports = NotImplementedError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const pug = require('pug') | ||
const sass = require('node-sass') | ||
const { promisify } = require('util') | ||
|
||
class Renderer { | ||
constructor(view, data) { | ||
this.view = view | ||
this.data = data | ||
|
||
this.styles_path = 'admin/frontend/styles/index.css.sass' | ||
this.views_path = 'admin/frontend/views/' | ||
} | ||
|
||
async styles() { | ||
const style = await promisify(sass.render)({ | ||
file: this.styles_path, | ||
}) | ||
return style.css.toString('utf-8') | ||
} | ||
|
||
async render() { | ||
const data = { | ||
adminStyles: await this.styles(), | ||
...this.data, | ||
} | ||
const viewFunction = pug.compileFile(`${this.views_path}${this.view}.pug`) | ||
return viewFunction(data) | ||
} | ||
} | ||
|
||
module.exports = Renderer |
Empty file.
Oops, something went wrong.