Skip to content

oakscastle/ember-calendar

 
 

Repository files navigation

Ember Calendar

Npm Version Ember Observer Score Code Climate Build Status

An awesome Ember calendar, designed with composability and reusability in mind.

Calendar in action

Check out the demo

Features

  • Click to add occurrences
  • Resize occurrences
  • Drag and drop occurrences
  • Timezone aware
  • Search and change timezones

Installation

ember install ember-calendar

Philosophy

Following the principle "Data down, Actions up", the calendar sends these actions up:

  • onAddOccurrence
  • onUpdateOccurrence
  • onRemoveOccurrence

In addition, you need to provide an occurrences Ember Array to the component. Each occurrence should have these properties:

  • title
  • startsAt
  • endsAt

The component never mutates your data, but merely decorates them and uses these proxies to display the occurrences in the calendar. In the case you need to access the original object in the template, it is available as occurrence.content.

Basic Usage

{{! app/templates/index.hbs }}

{{as-calendar
  title="Ember Calendar"
  occurrences=occurrences
  defaultTimeZoneQuery="New York|London|Dubai|Hong Kong"
  dayStartingTime="9:00"
  dayEndingTime="18:00"
  timeSlotDuration="00:30"
  onAddOccurrence="calendarAddOccurrence"
  onUpdateOccurrence="calendarUpdateOccurrence"
  onRemoveOccurrence="calendarRemoveOccurrence"}}
// app/controllers/index.js

import Ember from 'ember';

export default Ember.Controller.extend({
  occurrences: Ember.A(),

  actions: {
    calendarAddOccurrence: function(occurrence) {
      this.get('occurrences').pushObject(Ember.Object.create({
        title: occurrence.get('title'),
        startsAt: occurrence.get('startsAt'),
        endsAt: occurrence.get('endsAt')
      }));
    },

    calendarUpdateOccurrence: function(occurrence, properties) {
      occurrence.setProperties(properties);
    },

    calendarRemoveOccurrence: function(occurrence) {
      this.get('occurrences').removeObject(occurrence);
    }
  }
});

Advanced Usage

All the components which are used in the calendar are highly reusable. For example, you can customize the appearance of the occurrences by passing a block:

{{#as-calendar
  title="Schedule call"
  occurrences=occurrences
  dayStartingTime="7:00"
  dayEndingTime="21:30"
  timeSlotDuration="00:30"
  timeZoneOptions=timeZoneOptions
  showTimeZoneSearch=false
  timeZone=timeZone
  onAddOccurrence="calendarAddOccurrence" as |occurrence timetable calendar|}}
  {{#if occurrence.content.isEditable}}
    {{as-calendar/timetable/occurrence
      class="selection"
      model=occurrence
      timeSlotHeight=calendar.timeSlotHeight
      timetable=timetable
      timeSlotDuration=calendar.timeSlotDuration
      isResizable=false
      onUpdate="calendarUpdateOccurrence"
      onRemove="calendarRemoveOccurrence"}}
  {{else}}
    {{as-calendar/occurrence
      model=occurrence
      timeSlotHeight=calendar.timeSlotHeight
      timeSlotDuration=calendar.timeSlotDuration}}
  {{/if}}
{{/as-calendar}}

In this example, we check if the original occurrence is editable and either show an occurrence which can be interacted with (as-calendar/timetable/occurrence) or just a static occurrence (as-calendar/occurrence). Furthermore, the nested components try to assume as less as possible about their ancestors, so we pass in most of their attributes manually.

You can customize the time slots by passing these options:

  • dayStartingTime
  • dayEndingTime
  • timeSlotDuration
  • timeSlotHeight
  • defaultOccurrenceTitle
  • defaultOccurrenceDuration

In addition, you can customize the timezone handling using these options:

  • timeZone
  • timeZoneOptions
  • defaultTimeZoneQuery
  • showTimeZoneSearch

Styles

We do not add any vendor CSS to your app by default, but you can include it if you want by doing:

// app/styles/app.scss

@import 'addons/ember-calendar/main';

Bear in mind that the default styles require ember-cli-paint. To install it, run:

ember install ember-cli-paint

Developing

Setup

  • git clone https://github.com/alphasights/ember-calendar.git
  • npm install && bower install

Running

  • ember server

Running Tests

  • ember test --server

Credits

About

An awesome Ember calendar, designed with composability and reusability in mind.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 73.2%
  • CSS 13.4%
  • Handlebars 8.8%
  • HTML 3.0%
  • Makefile 0.8%
  • Ruby 0.5%
  • Shell 0.3%