Code Monkey home page Code Monkey logo

formage's Introduction

Formage

Bootstraped Admin GUI addon for Mongoose, JugglingDB, or just as a form generator. Originally forked from mongoose-admin.

Build Status

NPM

Example Usage

var express = require('express'),
    app = express();

require('formage').init(app, express, models);

Look at the \example directory.

Options

// Site-wide options, and their default values
require('formage').init(app, express, models, {
    title: 'Admin',
    root: '/admin',
    default_section: 'main',
    username: 'admin',
    password: 'admin',
    admin_users_gui: true
});

Model options

var model = new mongoose.model('songs', schema);

// external files specific to this model
model.header_lines = [
   '<script src="/js/songs.js"></script>',
   '<style href="/css/songs.css"></style>'
];

model.formage = {
    // one-document models
    is_single: true,

    // labels
    label: 'My Songs',
    singular: 'Song',

    filters: ['artist', 'year'],

    // additional actions on this model
    actions: [
       {
          id: 'release',
          label: 'Release',
          func: function (user, ids, callback) {
             console.log('You just released songs ' + ids);
             callback();
          }
       }
    ],

    // list of fields to be displayed by formage for this model
    list: ['number', 'title', 'album', 'artist', 'year'],
    
    // order documents, save order in this field (type: Number)
    sortable: 'order',

    // list of order fields
    order_by: ['-year', 'album', 'number'],

    // list of fields that must be populated
    // (see http://mongoosejs.com/docs/api.html#document_Document-populate)
    list_populate: ['album'],

    // list of fields on which full-text search is available
    search: ['title', 'album', 'artist']
};

Fields

Formage comes with the following built-in fields, but custom fields can be written if needed.

You can pass options to the underlying fields and widgets:

var schema = new mongoose.Schema({
    artist: { type: String, label: 'Who made it?' },
    location: { type: Schema.Types.GeoPoint, widget_options: { lang: 'nl' }}
});

(The map widget lang setting is a two-letter ISO 639-1 code.)

Hmm

License

MIT

Sponsor

formage's People

Contributors

alonronin avatar andgrankin avatar comartmit avatar eyy avatar ishai avatar jlopezr avatar laurentvb avatar leonardoalifraco avatar leweaver avatar mediabounds avatar moul avatar refack avatar robbyoconnor avatar rogerz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

formage's Issues

Client Side Pagination

Need to organize the client side representation of the pagination. Currently it is showing all pages.

RTL

Need the ability to alter design to match right-to-left orientation

Get default value for ArrayField

model:
var TestSchema = new Schema({
// basic
num_arr : [{type:Number,default:0}]
});
var TestModel = mongoose.model('TestModel', TestSchema);

the default 0 can't be fill in the textbox and

when save:
CastError: Cast to number failed for value "1,NaN,2" at path "num_arr"

Picture Field in VIews

Should display Picture field by type not by name (currently render images in view only if field name is 'picture')

Boolean Field won't save

Either on create or save.

model:

var schema = new Schema({
    parent: { type: Types.ObjectId, ref: 'navigation' },
    meta: [{
        name: { type: String },
        content: { type: Types.Text }
    }],
    title: { type: String, required: true },
    url: { type: String, trim: true, lowercase: true, unique: true },
    template: { type: String, enum: require('../views/') },
    language: { type: String, enum: ['he', 'en'], default: 'he'},
    order: { type: Number, editable: false },
    menu: { type: Boolean, 'default': true },
    show: { type: Boolean, 'default': true }
});

Model registration name should come from mongoose (if available)

When I access to add a new document if the model has a Reference field the app crash.

TypeError: Cannot read property 'model' of undefined
    at Object.exports.getModel (/Users/xxxx/xxxx/xxxx/server/node_modules/formage/lib/index.js:25:69)
    at Class.formage.fields.EnumField.extend.init (/Users/xxxx/xxxx/xxxx/server/node_modules/formage/lib/forms/RefField.js:4:32)
    at Class.prototype.(anonymous function) [as init] (/Users/xxxx/xxxx/xxxx/server/node_modules/formage/node_modules/sji/index.js:38:34)
    at new Class (/Users/xxxx/xxxx/xxxx/server/node_modules/formage/node_modules/sji/index.js:51:23)

Map Paint In Embed Doc

map doesn't load well inside an Embed Document

Model:

var mongoose = require('mongoose'),
    Schema = mongoose.Schema,
    Types = Schema.Types;

var schema = new Schema({
    homepage: String,
    site_name: String,
    copyrights: String,
    snippets: [Types.Text],
    contact: {
        form: {
            name: String,
            email: String,
            phone: String,
            submit: String,
            message: String,
            success: String,
            fail: String,
            template: Types.Text
        },
        subject: String,
        email: String,
        map_point:{ type: Types.GeoPoint },
        text: Types.Html,
        picture: Types.Picture
    },
    _404: {
        title: String,
        content: Types.Html
    }
});

var model = module.exports = mongoose.model('config', schema);
model.formage = {section: 'Configuration', single: true };

(I think you need to trigger resize event to the map)

Search on array of fields produces invalid mongoDB query

I configure the search as followed:

models.Enrichment.formage = {
    search: ['match', 'name']
};

When I search in the UI for FOO, the generated query is :
{ $where: "FOO.test(this.match)||FOO.test(this.name)" }

which is invalid.
Adding the / / characters around my search does not help as theyr're escaped before the query.

Export

Add an Export action to a list of documents.
can export as JSON, Excel, CSV?

Delete is not working

I worked on Hamchnot haolim and wanted to delete the Home page tab and it look like it is working but in the web it is not working :-(

Value 0 of nested array not displayed and module can not be saved.

When use [{type:Number}]

the value 0 will not be displayed in the input widget, I found
res.write('\n<input' + (this.value ? ' value="' + escapeHTMLComponent(this.value) + '"' : '') );
at line 60, widgets.js. where this.value will treat 0 as no value and display nothing.

And,
when you try to save an array [{type:Number}], for the 0 was not fill in the input field,
the form will post nothing to the server, and make exception in the server like:

Cast to number failed for value "NaN,NaN,NaN,NaN,NaN" at path "xxxx"

Error message from DB

I added new user and the info was not correct and press on save the save did not work and didn't send me error on the problem.

Change language on map

Is there a way I can override the widgets so I can change the language on the GeoPoint widget?

example app: image upload fails; nowhere to put credentials?

When I use the example app and attempt an image upload, it fails with "Must supply api_key," but there is no indication of how -- in the example app, the formage or formage-admin READMEs, or as far as I can tell, the whole codebase.

From ack-ing around in the code, I see that some cloud gem is being used ('cloudinary') for image uploads, but that the example/app.js contains no reference to it, or to these credentials.

Acking around further, I see a usage of cloudinary.uploader.upload(...) in forms/fields.js, but it doesn't use any credentials.

According to the cloudinary package, there are 3 ways to configure cloudinary, one of which is calling it with a certain environment variable (which is not demonstrated in the README.md). The other two ways are cloudinary.config(), which is not used, and per-call for things like upload, which is also not happening, at least as revealed by acking for 'cloudinary.'

field options refactoring

these are the current field options i know of:

  • formageField
  • label
  • widget
  • widget_options

please, variables should be underlined_seperated, not camelCased,
and all of these (maybe except label) should be inside a formage object:

var schema = mongoose.Schema({
    title: { type: String, label: 'My Title', formage: {
        field: SpecialField,
        widget: SomeWidget,
        options: {}
    } }
});

why do we even need these fields? we have mongoose fields and validators, it's more than enough.

Mixed type saved as "\r\n"

I have a field:
records : Schema.Types.Mixed,

the editor form render this field as an textarea, leave it empty and save,
the reopen the editor, the texarea will be filled "\r\n"

Regression: display of virtual fields crashes the list view

Hello,

I have the following formage configuration for my EarlyBird model:

models.EarlyBird.formage = {
    list: ['email', 'invitationLink', 'invitationId', 'userId'],
    order_by: ['email'],
    actions: [{
        value: 'invite',
        label: 'Invite',
        func: function(user, ids, callback){
            models.EarlyBird.invite(ids, callback);
        }
    }]
};

,where 'invitationLink' is a virtual field.

When I try to access the list of records, it crashes with the following stack trace:

TypeError: Cannot read property 'options' of undefined
at Object.buf.push.
at Object. (<REDACTED>\node_modules\formage\templates.js:445:4)
at Object.anonymous [as model] (<REDACTED>\node_modules\formage\templates.js:524:4)
at View.engine (<REDACTED>\node_modules\formage\routes.js:552:34)
at View.render (<REDACTED>\node_modules\express\lib\view.js:76:8)
at Function.app.render (<REDACTED>\node_modules\express\lib\application.js:506:10)
at ServerResponse.res.render (<REDACTED>\node_modules\express\lib\response.js:760:7)
at <REDACTED>\node_modules\formage\routes.js:419:28
at Promise. (<REDACTED>\node_modules\formage\MongooseAdmin.js:248:13)
at Promise. (<REDACTED>\node_modules\mongoose\node_modules\mpromise\lib\promise.js:162:8)
at Promise.EventEmitter.emit (events.js:95:17)
at Promise.emit (<REDACTED>\node_modules\mongoose\node_modules\mpromise\lib\promise.js:79:38)
at Promise.fulfill (<REDACTED>\node_modules\mongoose\node_modules\mpromise\lib\promise.js:92:20)
at <REDACTED>\node_modules\mongoose\lib\query.js:1726:26
at model.Document.init (<REDACTED>\node_modules\mongoose\lib\document.js:251:11)
at completeMany (<REDACTED>\node_modules\mongoose\lib\query.js:1724:12)
at cb (<REDACTED>\node_modules\mongoose\lib\query.js:1687:11)
at <REDACTED>\node_modules\mongoose\lib\utils.js:414:16
at <REDACTED>\node_modules\mongoose\node_modules\mongodb\lib\mongodb\cursor.js:158:16
at commandHandler (<REDACTED>\node_modules\mongoose\node_modules\mongodb\lib\mongodb\cursor.js:651:16)
at <REDACTED>\node_modules\mongoose\node_modules\mongodb\lib\mongodb\db.js:1670:9
at Server.Base._callHandler (<REDACTED>\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\base.js:382:41)
at <REDACTED>\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\server.js:472:18
at MongoReply.parseBody (<REDACTED>\node_modules\mongoose\node_modules\mongodb\lib\mongodb\responses\mongo_reply.js:68:5)
at null. (<REDACTED>\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\server.js:430:20)
at EventEmitter.emit (events.js:95:17)
at null. (<REDACTED>\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\connection_pool.js:191:13)
at EventEmitter.emit (events.js:98:17)
at Socket. (<REDACTED>\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\connection.js:384:22)
at Socket.EventEmitter.emit (events.js:95:17)
at Socket. (_stream_readable.js:746:14)
at Socket.EventEmitter.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:408:10)
at emitReadable (_stream_readable.js:404:5)
at readableAddChunk (_stream_readable.js:165:9)
at Socket.Readable.push (_stream_readable.js:127:10)
at TCP.onread (net.js:526:21)

It used to work correctly with previous versions of formage (latest tested: 1.6.6) but I updated to 1.6.13 this morning and it breaks now.

Fix dependency versions

Currently, dependency versions are not specified in package.json:

"dependencies": {
    "lodash": "",
    "async": "",
    "cloudinary": "",
    "nodestrum": "",
    "node-ckeditor": ""
},

This is dangerous, as a npm install command will give different results at different times for the exact same commit history.
Case in point: last Friday, an npm install of 1.6.18 would bring nodestrum (?) 0.4.0, which wouldn't even allow my formage app to start. More problematic: there was no way for me to revert to a previous stable version of formage, as they would all bring the broken nodestrum module.
Today, npm install of the 1.6.18 version fetches nodestrum 0.6.0 which apparently fixes the issue. I've tested this version extensively in my dev environment and it works ok for my needs, but I'm afraid that when I move to production, and npm install, even with a fixed formage version in my package.json, it will break without hope of rolling back.

Regards,

Laurent

changing out auth middleware

Checking out formage for the first time today, pretty sweet so far. I'd like to be able to switch out the auth middleware without modifying your routes at all. I'm currently using mongoose backed passport.js and would like to pull users from there.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.