yogiben / meteor-admin

A complete admin dashboard solution
https://atmospherejs.com/yogiben/admin
GNU General Public License v3.0
827 stars 261 forks source link

Error when running the project - Leading decorators must be attached to a class declaration! #376

Open BehrouzRiahu opened 8 years ago

BehrouzRiahu commented 8 years ago

When I try and add the Posts collection as it is shown int he package example as follows:

@Schemas = {}

@Posts = new Meteor.Collection('posts');

Schemas.Posts = new SimpleSchema
    title:
        type: String
        max: 60
    content:
        type: String
        autoform:
            rows: 5
    createdAt:
        type: Date
        label: 'Date'
        autoValue: ->
            if this.isInsert
                return new Date()
    owner:
        type: String
        regEx: SimpleSchema.RegEx.Id
        autoValue: ->
            if this.isInsert
                return Meteor.userId()
        autoform:
            options: ->
                _.map Meteor.users.find().fetch(), (user)->
                    label: user.emails[0].address
                    value: user._id

Posts.attachSchema(Schemas.Posts)

I get back the following error: "Leading decorators must be attached to a class declaration"

What am I doing wrong here?

And is it possible to play around with the design the content of the /admin content? because I couldn't figure out how, I would appreciate it if someone could confirm it for me before I start using it :)

tsrandrei commented 7 years ago

take a look at this : https://github.com/aldeed/meteor-autoform

I think need some reformatting. I am trying to figure out how it works everything.

Did you find any solution?

tsrandrei commented 7 years ago

They have written all the documentation in CoffeeScript, so basically you should translate it in JavaScript if you are not running CoffeeScript.

By far this is in JS :

collections/posts.js ( or collection common.js file )


var Schemas = {};

Posts = new Meteor.Collection('posts');

Schemas.Posts = new SimpleSchema({
    title:{
        type: String,
        max: 60
    },
    content:{
        type: String,
        min: 20,
        max: 1000,
        autoform: {
            rows: 5
        }
    },
    createdAt:{
        type: Date,
        label: "Date",
        autoform:{
            value: new Date()
        }
    },
    owner: {
        type: String,
        regEx: SimpleSchema.RegEx.Id,
        optional: true
        autoValue: function(){
                  if (this.isInsert)
                             return Meteor.userId()
        },
        autoform:{
                      type: "select",
                      options: function(){
                                   return _.map(Meteor.users.find().fetch(), function(user) {
                                                        return {
                                                               label: user.emails[0].address,
                                                               value: user._id
                                                        };
                                         });
                             }
              }
      }
});

Posts.attachSchema(Schemas.Posts);

In lib/admin_config.js AdminConfig = { collections: { Posts: {} } };