Meteor-Community-Packages / Meteor-Community-Packages/meteor-tabular

Tabular with PublishComposite

Open
#218 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
360
Forks
132
PR merge metrics
No merged PRs in 30d

Description

Hello,
sorry if my question is too easy, I'm starting with Meteor

I have the following configuration, but the columns with title "Ingrediente", "Updated By" are empty in the DataDatable

/app/lib/controllers/preco_ingredientes_controller.js

TabularTables = {};

Meteor.isClient && Template.registerHelper('TabularTables', TabularTables);

PrecoIngredientes.helpers({
  ingrediente: function () {
    console.log("PrecoIngredientes.helpers this.ingredienteId:" + JSON.stringify(this));
    return Ingredientes.find(this.ingredienteId).name;
    // return Ingrediente;
  },
  updated: function () {
    var user = Meteor.users.findOne({_id: this.updatedById});
    console.log("user:" + JSON.stringify(user));
    return user && user.name;
    // return Ingrediente;
  },

});

TabularTables.PrecoIngredientes = new Tabular.Table({
  name: "PrecoIngredientes",
  collection: PrecoIngredientes,
  pub: "precoIngredientes_Composite",
  columns: [
    {data: "quantidade", title: "Quantidade"},
    {data: "preco", title: "Preco"},
    {data: "ingrediente()", title: "Ingrediente"},
    {data: "updated()", title: "Updated By"},

  ]
});

/app/server/publish.js

Meteor.publishComposite('precoIngredientes_Composite',function (tableName, ids, fields) {
    check(tableName, String);
    check(ids, Array);
    check(fields, Match.Optional(Object));

    this.unblock(); // requires meteorhacks:unblock package
    return {
    find: function() {
       this.unblock(); // requires meteorhacks:unblock package
       console.log("Publish:" + JSON.stringify(PrecoIngredientes.findOne()));
        return PrecoIngredientes.find({});
    },  
    children: [ 
        {
            find: function(precoIngrediente) {
              this.unblock(); 
                return Meteor.users.find(
                    { _id: precoIngrediente.updatedById },
                    { limit: 1});
            }
        },
        {
            find: function(precoIngrediente) {

              // console.log("child2:");
              this.unblock(); 
                return Ingredientes.find({ _id: precoIngrediente.ingredienteId });
            }
        }
    ]
  }
});

/app/client/templates/preco_ingredientes/preco_list/preco_ingredientes_list_new.html

....
 {{> tabular table=TabularTables.PrecoIngredientes class="table table-striped table-bordered table-condensed"}}
....

/app/lib/collections/preco_ingredientes.js

PrecoIngredientes = new Mongo.Collection('precoIngredientes');

var schemasPrecoIngrediente = new SimpleSchema({
    ...,
    ingredienteId: {
    label: "Ingrediente",
    type:  String,
    optional: true,

    autoValue: function() {
      if ( this.isSet ){
        return this.value;
      } else {
        return '';
      }
    },
    autoform: {
      afFieldInput:{
        placeholder: 'Select One'
      },
      label: "Ingrediente",
      selectOnBlur: true,
      type: "select2",
      options: function() {
       var list = [];
       list.push({label: "", value: ""});
        var ingredientesList = Ingredientes.find();
        ingredientesList.map(function(ingrediente) {
          list.push({
            label: ingrediente.name,
            value: ingrediente._id
          });
        });
        return list;
      }
    }
  },
    updatedById: {
        type: String,
        label: "Updated by",
        autoValue: function() {
            if (!this.value)
                return this.userId;
        },
        optional: true
    },
...
});

Chrome Console

PrecoIngredientes.helpers this.ingredienteId:{"preco":1111.22,"quantidade":123,"_id":"g2NMe7DwCxPQWivD9"} preco_ingredientes_controller.js:53 
user:undefined

Server log from publishComposite:

I20151012-11:18:31.611(-3)? Publish:{"_id":"FWuxM5wKE7969kkMk","ingredienteId":"kwqRCm8kaNCofmPqN","quantidade":123,"preco":79.78,"createdAt":"2015-10-01T20:24:38.304Z","updatedAt":"2015-10-01T20:24:38.304Z","updatedById":"XBGiQDNdW25JdMHew"}

What am I doing wrong?

Thank you

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with /app/lib/controllers/preco_ingredientes_controller.js and /app/server/publish.js, then reproduce the empty DataTable columns from the template in /app/client/templates/preco_ingredientes/preco_list/preco_ingredientes_list_new.html. Compare the client document and related records with the server publish log; done means the Ingrediente and Updated By columns display their expected values.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
full-stack
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.