Monday, June 24, 2013

Hacking a calendar with meteor [Iteration 8] {Fail: unstable}

We call this iteration a failure:

  • Data from the publishing mechanism doesn't want to push properly
  • Get inconsistent errors for my Collection variables

This document is about meteor version 0.6.3, code is in coffeescript

I am not sure if the tabs below will work until I publish, we'll see and apologies if it doesn't work.

Templates and CSS

I am keeping nothing in this directory except templates and CSS and a model.coffee file

CoffeeScript with server stuff

This directory has server code, in this case one file

  • Planner.js

Public

An ico file

Server

A file containing publish code

Packages

Meteorite packages: fullcalendar, jquery, jquery-ui, router

In Planner.js file under the client directory:

eventdata = (start,end,callback)-> 
    #I am setting the object event using a session key
    #session keys are "reactive", ie they should trigger the function to change
    docs = Session.get "docs"
    console.log "Got docs" 
    if docs
        #I am mapping this because I want specific elements for the calendar
        #You may not need to do it this way, for example, you can publish a specific data set (in theory)
        formatted_docs = docs.map (item)->
            { title: item.title, start:item.start,end:item.end }
        console.log formatted_docs
        callback formatted_docs


#because javascript calls functions, which may become modified at the last
#moment, our session var creates a trigger to re-render and our eventdata function changes
#so rendering the template gets called with the new eventdata     
Template.calendar.rendered = ->
 $('#calendar').fullCalendar
        dayClick: daycallback
        events: eventdata
        header: 
            left: 'prev,next today',
            center: 'title',
            right: 'month,basicWeek,basicDay' 
 return ""

Now I've been updating this since having moved on, but I could never quite get the publish code working right. In principle meteor serves up client and server stuff separately if they are under the respective directory. Now my model.coffee file was in the base directory, but even though the only call I have in there is the Collection which should (and is) utilized by both client and server, the client would never be able to find this variable if it is held in a different file. This was a very curious issue for which I haven't yet found resolution.

No comments:

Post a Comment