restorando / angular-pickadate

A simple and fluid inline datepicker for AngularJS with no extra dependencies.
MIT License
273 stars 91 forks source link

Expose internal date and add support for events in calendar view #70

Open jeffhuys opened 8 years ago

jeffhuys commented 8 years ago

Exposing the internal date object I've added support for exposing the internal date object of the calendar view. You can use this as follows:

<div pickadate ng-model="calendarDate" current-date="calendarCurrentDate"></div>

Now, calendarCurrentDate will be the Date object of the calendars' current view. For instance, when the user sees "December 2015", and calls calendarCurrentDate.getMonth() it will return the month number.

Showing events on the calendar I've also added support for supplying an array with formatted dates to show in the calendar. Use it like this:

<div pickadate ng-model="calendarDate" dates-with-events="calendarPopulatedDates"></div>

In my case, I've added dates like this:

// Get all events from the API
Event.getAll(function(events) {
    console.log('Events retrieved', events);
    $scope.events = events;

    // Add every event to the calendar
    events.forEach(function(event) {
        var date = new Date(event.begin * 1000);
        var year = date.getFullYear().toString();
        var month = (date.getMonth()+1).toString();
        var day = date.getDate().toString();

        $scope.calendarPopulatedDates.push(year + '-' + (month[1]? month : '0'+month[0]) + '-' + (day[1]? day : '0' + day[0]));
    });
});

Note: this may not be the most efficient way to do this.

It looks like this:

screen shot 2015-12-15 at 14 21 58

To conclude

This is one of my first pull requests. I hope everything is right! If not, please let me know. I'll gladly update my code.

restorandodeploy commented 8 years ago

By analyzing the blame information on this pull request, we identified @gschammah, @ndrisso and @asharbitz to be potential reviewers

jeffhuys commented 8 years ago

The build seems to have failed. I've updated the code.

EDIT: If someone could help me out with parsing the errors, I'd appreciate it.