• Stars
    star
    157
  • Rank 238,399 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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=(action "calendarAddOccurrence")
  onUpdateOccurrence=(action "calendarUpdateOccurrence")
  onRemoveOccurrence=(action "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, isPreview) {
      occurrence.setProperties(properties);

      if (!isPreview) {
        occurrence.save();
      }
    },

    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
  onNavigateWeek=(action "calendarNavigateWeek")
  onAddOccurrence=(action "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=(action "calendarUpdateOccurrence")
      onRemove=(action "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

You can specify the initial week displayed by the calendar using the startingDate option. In addition, if you want the week to begin from that day, pass startFromDate=true.

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 'bower_components/fontawesome/scss/variables';
@import 'bower_components/fontawesome/scss/path';
@import 'bower_components/fontawesome/scss/mixins';
@import 'bower_components/fontawesome/scss/icons';

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

There are some basic resets applied by default on .as-calendar, like box-sizing: border-box and list-style: none for all inner ul > lis.

If you already have those resets in your app add an $as-calendar-global-resets: false; before loading the main stylesheet.

Build Options

Font Aweseome assets are exported during a build by default which may conflict with assets already being exported by your project. To prevent this, add the following option to your ember-cli-build.js file:

// ember-cli-build.js

module.exports = function(defaults) {
  var app = new EmberApp(defaults, {

    // Add options here
    emberCalendar: {
      includeFontAwesomeAssets: false
    }
  });

  return app.toTree();
};

Developing

Setup

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

Running

  • ember server

Running Tests

  • ember test --server

Credits

More Repositories

1

ember-graphql-adapter

GraphQL adapter for Ember Data
JavaScript
245
star
2

paint

CSS framework like Bootstrap but more modern and delivered through SCSS mixins
SCSS
44
star
3

walnut

Lightweight, simplistic dashboard to monitor web services, CI and applications
JavaScript
36
star
4

sneakers_handlers

Retries with exponential backoff for sneakers
Ruby
33
star
5

ember-scrollable

A simple Ember wrapper around Trackpad Scroll Emulator
JavaScript
24
star
6

doofenshmirtz

Make your legacy code self destruct in Rails
Ruby
10
star
7

ember-cli-paint

Ember-cli wrapper for paint
JavaScript
7
star
8

take-home-assessment

A take home assessment designed for Full-stack or Backend developers
5
star
9

ember-style-guide

A beautiful, hand-crafted guide for building ambitious Ember apps, with love.
5
star
10

crawl

Crawl pages within a domain, reporting any page that returns a bad response code
Ruby
5
star
11

buildpack-migrations

Runs migrations on a deployment
Shell
5
star
12

tech-assessments

4
star
13

as_UIAutomation_QA

QA Test Automation Project
Java
3
star
14

ember-cli-mirage-example

An example usage of ember-cli-mirage to test an application.
JavaScript
3
star
15

hiring-challenges

Our hiring challenges for potential new team members
Ruby
3
star
16

paint-app-switcher

AppSwitcher Component styles and assets
CSS
2
star
17

fraud-detection

1
star
18

select2-capybara

Capybara helpers for select2
Ruby
1
star
19

docker-logstash

A logstash in Docker
Shell
1
star
20

github-shipit

A Chrome extension to make it easier to approve Github pull requests.
JavaScript
1
star
21

filbert

A utility to download backups of heroku followers
Ruby
1
star
22

tap

Homebrew repository for alphasights dependencies
Ruby
1
star
23

ember-cli-alphasights

JavaScript
1
star
24

dataclipper

Moves dataclips from one source to another
Elixir
1
star
25

ember-histo-slider

An Ember addon for a histo-slider component
JavaScript
1
star
26

paint-rails

Rails integration for Paint gem
Ruby
1
star
27

netprospex

NetProspex Ruby API wrapper
Ruby
1
star
28

sneakers_toolbox

Various helpers and convenience classes/modules/methods to help simplify working with Sneakers and get around common issues
Ruby
1
star
29

lean_stamper

A stripped down version of original userstamp plugin. References the stamper object itself, not the id. Only creator and updater.
Ruby
1
star