How to build a simple calendar/appointment booking application?

How would I go about handling ‘days’ and formatting days into a weekly, monthly or yearly format in a calendar/appointment booking application?

I’ve been thinking about this for a few days and can’t think of a good solution.

I don’t want to store thousands of ‘day’ objects and their appointments in the database. I’d only like to persist appointments.

That means I have to create all the ‘day’ objects when the application boots, loop through the appointments and assign them to the correct days. Then loop through the list of days in my template, displaying appointments on days when there are appointments.

Then I somehow need to output the days in a weekly, monthly or yearly format (configurable by the user). I’m not sure what the best way of doing that would be since handlebars is logicless beyond the most simple control structures (a good thing!).

So basically, I’m asking:

  1. Am I approaching this problem correctly

then if so:

  1. Where abouts in the application should I create all my day objects (there must be an init hook somewhere that’s suitable?

  2. What’s the best way to loop through all my day objects once they’re created where they’ll have access to the appointments objects, and what’s the best way to determine whether the appointment falls on that day? The only way I can think of is (semi-pseudo code):

    for(day in days) {

    for(appointment in appointments) {

     if(day == appointment.get('date')) {
    
       day.get('appointments').pushObject(appointment);
    
     }
    

    }

    }

Which will probably perform terrible if I’m iterating through a year or five and have a couple of hundred appointments.

  1. After that’s done, I should be able to loop through my day objects and output appointments where they appear, but how would I go about formatting them into a grid in a week/month/year view?

Edit: Fixed code formatting Edit 2: …or not, Markdown won’t let me format it correctly. Whatever, you get the point!

Have you seen this? https://github.com/joinspoton/ember-calendar

Hello, I also made a calendar/agenda in ember and as you said, the grid’s rendering is not pretty efficient.

I’m curious about what solution you got into ?

(a google search about “ember” and “calendar” pop this thread in the firsts results so let’s clear the question out !)

thanks !

Hello @chrisb did you figured out how to build a calendar with Ember at the end? I would be very interested to see your way