Skip to content

Commit

Permalink
*fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jspears committed Apr 24, 2012
1 parent b76e7a8 commit e11783f
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 42 deletions.
10 changes: 9 additions & 1 deletion examples/model/user.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
var crypto = require('crypto'), mongoose = require('mongoose'), Schema = mongoose.Schema;
var RoleSchema = new Schema({
name:{type:String},
read:{type:Boolean},
edit:{type:Boolean},
remove:{type:Boolean},
changeOwnership:{type:Boolean}

})
var UserSchema = new Schema({
username:{type:String, required:true, unique:true, index:true, display:{help:'This must be a unique name'}},
first_name:{type:String},
Expand All @@ -13,7 +21,7 @@ var UserSchema = new Schema({
stars:Number,
favorite:{type:Number,display:{title:'Favorite'}}
},

roles:[RoleSchema],
created_at:{type:Date, display:{display:'none'}},
created_by:{type:Schema.ObjectId, ref:'user'},
modified_at:{type:Date}
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ app.configure('production', function () {

// Routes

app.get('/', function(req,res){ res.redirect('/index.html')});
app.get('/', function(req,res){ res.render('redir_index.html', {layout:false})});

app.listen(3001);
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
2 changes: 1 addition & 1 deletion examples/simple/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
*/

exports.index = function(req, res){
res.render('index', { title: 'Express' })
res.render('redir_index', { title: 'Express' })
};
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/display-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ function Field(path, args) {

this.__defineGetter__('subSchema', function () {
var subSchema = findAll('subSchema', args);
if (subSchema && this.type == 'Object') {
if (subSchema && (this.type == 'Object' || this.listType == 'Object')) {
var ret = {}
_u.each(subSchema, function onSubSchemaNest(v, k) {
_u(v).each(function (vv, kk) {
Expand Down
4 changes: 2 additions & 2 deletions lib/plugin-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var path = require('path'), _u = require('underscore'), DisplayModel = require('
*/
var PluginManager = function (options, express) {
this.options = _u.extend({}, options);
this.configFile = this.options.configFile || path.join(process.cwd, 'conf', 'bobamo.json');
this.configFile = this.options.configFile || path.join(process.cwd(), 'conf', 'bobamo.json');
this.persist = options.persist || new FilePersistence(this.configFile);
this.plugins = this.loadPlugins(this.options, express);
this.appModel = new DisplayModel(this.options);
Expand All @@ -30,7 +30,7 @@ PluginManager.prototype.configure = function (req) {
/**
* Default plugins to load.
*/
PluginManager.prototype.defaultPlugins = [ 'appeditor', 'modeleditor', 'less', 'generator', 'rest', 'mongoose', 'static', 'package'];
PluginManager.prototype.defaultPlugins = [ 'static','appeditor', 'modeleditor', 'less', 'generator', 'rest', 'mongoose', 'package'];
/**
*
*/
Expand Down
1 change: 1 addition & 0 deletions plugins/appeditor/appeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ AppEditorPlugin.prototype.appModel = function(){
}
AppEditorPlugin.prototype.configure = function(options){
_u.extend(this._appModel,options);
console.log('AppEditorPlugin AppModel', this._appModel);

}
AppEditorPlugin.prototype.filters = function(){
Expand Down
23 changes: 13 additions & 10 deletions plugins/modeleditor/edit-display-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,24 @@ var EditModel = function (k, Model, options) {
});
})
this.__defineGetter__('fields', function () {
return Object.keys(util.flatten(this.model.paths));
var fields = Object.keys(util.flatten(this.model.paths));
return fields;
});
this.__defineGetter__('fieldsets', function (v, k) {
this.__defineGetter__('fieldsets', function () {
var fieldsets = [
{
legend:'Edit ' + this.title,
fields:['title', 'plural', 'hidden', 'labelAttr', 'fieldsets', 'list_fields']
}
];
_u(this.fields).each(function (k) {
fieldsets.push({
// var _paths = util.flatten(this.schemaFor());

_u(this.fields).each(function (v, k) {
var fieldset = {
legend:this.title + '.' + k,
fields:['paths.' + k + '.title', 'paths.' + k + '.help', 'paths.' + k + '.views', 'paths.' + k + '.type', 'paths.' + k + '.dataType', 'paths.' + k + '.required']
})
fields:['paths.' + k + '.title','paths.' + k + '.help', 'paths.' + k + '.views', 'paths.' + k + '.type', 'paths.' + k + '.dataType', 'paths.' + k + '.required']
};
fieldsets.push(fieldset);
}, this);
return fieldsets;
})
Expand All @@ -89,6 +93,7 @@ EditModel.prototype.schema = {
help:'This is a label that gives a sussinct description of object'
}
};

EditModel.prototype.schemaFor = function () {
var fields = this.fields;
var schema = this._schema = _u.extend({}, this.schema);
Expand Down Expand Up @@ -123,9 +128,7 @@ EditModel.prototype.schemaFor = function () {

var obj = (this._schema.paths = { subSchema:{}, type:'Object'}).subSchema;
_u(this.model.paths).each(function (v, k) {
obj[k] = {type:'Object'};
obj[k].subSchema = createSubSchema(this.editors, k, v);

obj[k] = {type:'Object', subSchema:createSubSchema(this.editors, k, v) };

}, this);

Expand Down Expand Up @@ -173,7 +176,7 @@ function createSubSchema(editors, k, v) {
}
}
_u(v.subSchema).each(function (vv, kk) {
obj[kk] = {type:'Object', subSchema:createSubSchema(editors, kk, vv)};
obj[kk] = {type:'Object', labelAttr:{type:'Text', help:'A label for this attribute'},subSchema:createSubSchema(editors, kk, vv)};
});
return obj;
}
Expand Down
3 changes: 3 additions & 0 deletions plugins/modeleditor/views/admin/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ define([
var fieldsets = eval('({{html JSON.stringify(model.fieldsets) }})');
var schema = eval('({{html JSON.stringify(model.schemaFor()) }})');
schema.fieldsets.itemToString = function (obj) {
if (obj.fields && _.isString(obj.fields)){
obj.fields = obj.fields.split(',');
}
var fields = '[' + obj.fields.join(',') + ']';
if (fields.length > 30)
fields = fields.substring(0, 27) + '...';
Expand Down
29 changes: 16 additions & 13 deletions plugins/mongoose/mongoose.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ MongoosePlugin.prototype.appModel = function (options) {
}

MongoosePlugin.prototype.editorFor = function (path, p, Model) {
var schema = Model.schema;
var schema = Model.schema || Model;
var tmpP = schema && (schema.paths[path] || schema.virtuals[path] );
if (tmpP)
p = tmpP
Expand All @@ -35,13 +35,13 @@ MongoosePlugin.prototype.editorFor = function (path, p, Model) {
return null;
}

if (! tmpP && Model) {
if (!tmpP && Model) {
var obj = { subSchema:{}, type:'Object'}
_u(p).each(function (v, k) {
var ref = schema && schema[path + '.' + k];
var editor = this.pluginManager.pluginFor(path + '.' + k, ref || v, Model);
if (editor)
obj.subSchema[k] = editor;
var editor = this.pluginManager.pluginFor(path + '.' + k, ref || v, Model);
if (editor)
obj.subSchema[k] = editor;
}, this);
return obj;
}
Expand Down Expand Up @@ -83,14 +83,17 @@ MongoosePlugin.prototype.editorFor = function (path, p, Model) {
_u.extend(defaults, {
type:'List'
});
// if (type.length) {
// var o = type[0];
// var s = defaults.listType = {};
// _u.each(o, function onListType(v, k) {
// s[k] = this.pluginManager.pluginFor(k, v, o);
// }, this);
// console.log('defaults', defaults);
// }
if (type.length) {
var o = type[0];
defaults.listType = 'Object';
var s = defaults.subSchema = {};
if (o.paths)
_u.each(o.paths, function onListType(v, k) {
s[k] = this.pluginManager.pluginFor(k, v, o);
}, this);

}
console.log('defaults', defaults);
} else if (type) {

switch (type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,13 +690,14 @@
var errClass = Form.classNames.error;

this.$el.removeClass(errClass);
if (this.$help){
this.$help.empty();

this.$help.empty();

//Reset help text if available
var helpMsg = this.schema.help;
if (helpMsg) this.$help.html(helpMsg);
},
//Reset help text if available
var helpMsg = this.schema.help;
if (helpMsg) this.$help.html(helpMsg);
}
},

/**
* Update the model with the new value from the editor
Expand Down
27 changes: 25 additions & 2 deletions plugins/static/public/js/libs/bobamo/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,31 @@ define([
'libs/table/jquery.wiz'
], function ($, _, Backbone, Form, replacer) {
"use strict";
function nullEmptyStr(obj){
_(obj).each(function(v,k){
if (k == '_id' && _.isEmpty(v) ){
delete obj[k];
}else if (_.isString(v) ){

obj[k] = _.isEmpty(v) ? null : v;
}
else if (_.isArray(v)){
obj[k] = _(v).filter(function(vv){
if(_.isString(vv)){
return !(_.isEmpty(vv));
}else if (vv){
nullEmptyStr(vv);
}
return true;
});

}
else if (_.isObject(v) &! _.isFunction(v)){
nullEmptyStr(v);
}
});

}
var EditView = Backbone.View.extend({
tagName:'div',
events:{
Expand Down Expand Up @@ -72,10 +96,9 @@ define([
var errors = this.form.commit();

var save = this.form.getValue();
nullEmptyStr(save);
//handle nested objects.
_(save).each(function (v, k) {
if (_.isString(v) && _.isEmpty(v))
v = null;

if (k && k.indexOf('.') > -1) {
var split = k.split('.');
Expand Down
3 changes: 2 additions & 1 deletion plugins/static/public/js/libs/editors/multi-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ define(['Backbone.Form', 'jquery', 'underscore'], function (Form, $, _) {
editors.Base.prototype.initialize.call(this, options);

if (!this.schema || !(this.schema.options || this.schema.url)) throw "Missing required 'schema.options'";
if (!_.isUndefined(this.schema.multiple) || this.schema.multiple || this.schema.dataType == 'Array'){
if (this.schema && ( this.schema.multiple !== false || this.schema.dataType == 'Array' || this.schema.type == 'Array' )){
this.$el.attr('multiple', 'multiple');
this._multiple = true;
}
},
setValue:function (value) {
Expand Down
9 changes: 5 additions & 4 deletions plugins/static/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@ StaticPlugin.prototype.editors = function () {
StaticPlugin.prototype.filters = function () {
var prefix = this.baseUrl;
var sdir = path.join(this.path, 'public');
var psdir = path.join(this.path, '../../', 'public');
console.log('sdir', sdir, psdir);
var psdir = path.join(process.cwd(), 'public');

var public = static(sdir);
var publicUser = static(psdir);

console.log("Public Dir: ", psdir);
this.app.get(prefix + '*', function (req, res, next) {
req._url = req.url;
req.url = req.url.substring(prefix.length - 1);

next();

}, public, publicUser, function (req, res, next) {
}, publicUser, public, function (req, res, next) {
req.url = req._url;
next();
});
Expand Down

0 comments on commit e11783f

Please sign in to comment.