Code Monkey home page Code Monkey logo

angularjs-responsivecalendar's Introduction

ui-rCalendar directive

A pure AngularJS responsive calendar directive

You could also check https://github.com/twinssbc/Angular-Customizable-Calendar for the Angular version.
If you want to only use it in Ionic framework, please check https://github.com/twinssbc/Ionic2-Calendar for the Ionic specific version

Demo

http://twinssbc.github.io/AngularJS-ResponsiveCalendar/demo/

Usage

Bower Install: bower install ng-responsive-calendar

Load the necessary dependent files:

<link rel="stylesheet" href="../lib/bootstrap/dist/css/bootstrap.css"/>
<link rel="stylesheet" href="<bower lib installation path>/ng-responsive-calendar/dist/css/calendar.min.css"/>
<script src="../lib/angular/angular.js"></script>
<script src="<bower lib installation path>/ng-responsive-calendar/dist/js/calendar-tpls.min.js"></script>

Add the calendar module as a dependency to your application module:

var myAppModule = angular.module('MyApp', ['ui.rCalendar'])

Add the directive in the html page

<calendar calendar-mode="mode" event-source="eventSource">

Options

  • formatDay
    The format of the date displayed in the month view.
    Default value: 'dd'

  • formatDayHeader
    The format of the header displayed in the month view.
    Default value: 'EEE'

  • formatDayTitle
    The format of the title displayed in the month view.
    Default value: 'MMMM dd, yyyy'

  • formatWeekTitle
    The format of the title displayed in the week view.
    Default value: 'MMMM yyyy, Week w'

  • formatMonthTitle
    The format of the title displayed in the month view.
    Default value: 'MMMM yyyy'

  • formatWeekViewHeader
    The format of the header displayed in the week view.
    Default value: 'EEE d'

  • formatHourColumn
    The format of the hour column displayed in the week and day view.
    Default value: 'ha'

  • calendarMode
    The initial mode of the calendar.
    Default value: 'month'

  • showWeeks
    If set to true, a week number column will be displayed in the month view.
    Default value: false

  • showEventDetail
    If set to true, when selecting the date in the month view, the events happened on that day will be shown below.
    Default value: true

  • startingDay
    Control month view starting from which day.
    Default value: 0

  • allDayLabel
    The text displayed in the allDay column header.
    Default value: 'all day'

  • noEventsLabel
    The text displayed when there’s no event on the selected date in month view.
    Default value: 'No Events'

  • eventSource
    The data source of the calendar, when the eventSource is set, the view will be updated accordingly.
    Default value: null
    The format of the eventSource is described in the EventSource section

  • queryMode
    If queryMode is set to 'local', when the range or mode is changed, the calendar will use the already bound eventSource to update the view
    If queryMode is set to 'remote', when the range or mode is changed, the calendar will trigger a callback function rangeChanged.
    Users will need to implement their custom loading data logic in this function, and fill it into the eventSource. The eventSource is watched, so the view will be updated once the eventSource is changed.
    Default value: 'local'

  • step
    It can be set to 15 or 30, so that the event can be displayed at more accurate position in weekview or dayview.

  • rangeChanged
    The callback function triggered when the range or mode is changed if the queryMode is set to 'remote'

      $scope.rangeChanged = function (startTime, endTime) {
          Events.query({startTime: startTime, endTime: endTime}, function(events){
              $scope.eventSource=events;
          });
      };
    
  • eventSelected
    The callback function triggered when an event is clicked

      <calendar ... event-selected="onEventSelected(event)"></calendar>
    
    
      $scope.onEventSelected = function (event) {
          console.log(event.title);
      };
    
  • timeSelected
    The callback function triggered when a date or time is selected

      <calendar ... time-selected="onTimeSelected(selectedTime, events)"></calendar>
      
      $scope.onTimeSelected = function (selectedTime, events) {
      	console.log('Selected time: ' + selectedTime + ' hasEvents: ' + (events !== undefined && events.length !== 0));
      };
    

EventSource

EventSource is an array of event object which contains at least below fields:

  • title

  • startTime
    If allDay is set to true, the startTime has to be as a UTC date which time is set to 0:00 AM, because in an allDay event, only the date is considered, the exact time or timezone doesn't matter.
    For example, if an allDay event starting from 2014-05-09, then startTime is

      var startTime = new Date(Date.UTC(2014, 4, 8));
    
  • endTime
    If allDay is set to true, the startTime has to be as a UTC date which time is set to 0:00 AM, because in an allDay event, only the date is considered, the exact time or timezone doesn't matter.
    For example, if an allDay event ending to 2014-05-10, then endTime is

      var endTime = new Date(Date.UTC(2014, 4, 9));
    
  • allDay
    Indicates the event is allDay event or regular event

Note In the current version, the calendar controller only watches for the eventSource reference as it's the least expensive. That means only you manually reassign the eventSource value, the controller get notified, and this is usually fit to the scenario when the range is changed, you load a new data set from the backend. In case you want to manually insert/remove/update the element in the eventSource array, you can call broadcast the 'eventSourceChanged' event to notify the controller manually.

Events

  • changeDate When receiving this event, the calendar will move the current view to previous or next range.
    Parameter: direction
    1 - Forward
    -1 - Backward

      $scope.$broadcast('changeDate', 1);
    
  • eventSourceChanged This event is only needed when you manually modify the element in the eventSource array.
    Parameter: value
    The whole event source object

      $scope.$broadcast('eventSourceChanged',$scope.eventSource);
    

angularjs-responsivecalendar's People

Contributors

alexswensen avatar fabiowitt avatar jogusd avatar kenangel avatar twinssbc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

angularjs-responsivecalendar's Issues

Clicking a field in week-view

Is it possible to pass an object to the controller by clicking on an empty cell in the weekview, containing the start and end-hour + date?

All Day event not showing in Next and Previous months

I have created an event in the previous month, current month and next month. When I load the calendar, in the current month view, I can see one dark blue day and 2 light blue days (for the events in the previous an next month). When I go to the previous or next month the all day event is not displayed (the day is not dark blue, it remains white). And when I click on the day it displays "No Events" You can see this event in week and day views.

Call a method on Next and Previous icon click

Hai @twinssbc

I like to call a method on Previous and Next icon click.

E.g:

I have a controller in body tag. Name is my_controller.

I have declared a method here.

I like to call the method while click on the Next or previous icon.

Please suggest.

Best
nishadotcom

License

Can you provide a license for this project?

Replace anonymous function with closure

In the code https://github.com/twinssbc/AngularJS-ResponsiveCalendar/blob/master/src/rcalendar/calendar.js#L196-L201:

angular.forEach(cells[index].events, function (e) {
  if (!e.overlapNumber) {
    e.overlapNumber = overlapNumber;
    eventQueue.push(e);
  }
});

Is it possible to replace the anonymous function in the loop with closure? jshint warns that Don't make functions within a loop.

It seems that with angular.forEach we don't get the looping variable. We might have to use for loop instead to get the looping variable to generate closure.

Change week start date

Is it possible to change the starting day in 'Week' view from Sunday to Monday?

Thanks.

Times in weekview not showing right

Hi,

I am currently using this module to create my own calendar variant. While doing that I discovered a little bug. The times in the weekview are not showing right. Somehow it keep incrementing the time.getHours(). And sinds I am using that I had to fix it.

This is what I did:

old code (line 528 calendar.js):

function createDateObjects(startTime) {
var times = [],
row,
time = new Date(startTime.getTime());

            for (var hour = 0; hour < 24; hour++) {
                row = [];
                for (var day = 0; day < 7; day++) {
                    time.setHours(time.getHours() + hour);
                    time.setDate(time.getDate() + day);
                    row.push({
                        time: new Date(time.getTime())
                    });

                    console.log(day, time.getDate());
                }
                times.push(row);
            }

            return times;
        }

New code:

function createDateObjects(startTime) {
var times = [],
row,
time = new Date(startTime.getTime());

            var timeHours = time.getHours();
            var timeDay = time.getDate();

            for (var hour = 0; hour < 24; hour++) {
                row = [];
                for (var day = 0; day < 7; day++) {
                    time.setHours(timeHours + hour);
                    time.setDate(timeDay + day);
                    row.push({
                        time: new Date(time.getTime())
                    });

                    console.log(day, time.getDate());
                }
                times.push(row);
            }

            return times;
        }

I hope this helps!

Updating eventSource array

I'm a little confused as to how the eventSource array gets displayed.

Using the 'Week' view I can push in my events I have retrieved from an API.
These display correctly, however if I then try to splice the eventSource array or push additional objects into the array, the array is updated but the view isn't. Changing the view to next / prev week causes it to display events correctly.

How can I get the view to refresh with current events in eventSource?

Thanks.

The event is displayed wrongly in calendar

This is my event source

$scope.eventSource = [
{
title: 'All Day - 1',
startTime: new Date(2016,2,1),
endTime: new Date(2016,2,2),
allDay: true
},
{
title: 'All Day - 2' ,
startTime: new Date(2016,2,1),
endTime: new Date(2016,2,2),
allDay: true
},
{
title: 'All Day - 3' ,
startTime: new Date(2016,2,2),
endTime: new Date(2016,2,2),
allDay: true
}];

The events are displayed one day prior when it comes to calendar, do we need to specify time zone also?

CalendarController should be named before used

I believe it will be good to namespace CalendarController. It caused a conflict with another controller in my app named as CalendarController. While I should have namespaced it as well, I guess it would be good to do this in this code as a best practice.

Thank you for this great library!

Bootstrap dependency

Are their particular components of Bootstrap CSS that are used in this? If I can make a custom build of the Bootstrap CSS file I would like to. I'm having issues with full Bootstrap CSS overwriting styles in my application's CSS.

Event is appearing in two days for an all day event

I have an event with a startTime set to Wed May 18 2016 00:00:00 GMT+1000 (AUS Eastern Standard Time) and the endTime set to Wed May 18 2016 23:59:00 GMT+1000 (AUS Eastern Standard Time).
When the calendar loads, the all day event is showing on May 17 and 18. I have tried this with the allday flag set to true and false and I get the same result

How i set the options?

How i set the options.
I'm trying: $scope.calendar = {showEventDetail:true};
but don´t work.

Suggested Features

Thanks for putting this together; it gave me a great starting point on a small angular app I am working on.

Just some suggested features (a.k.a things I am working through now)

  1. User friendly hour rows on day/week view (instead of 0-23 index)
  2. Day/week view auto scroll to first event on load (instead of showing 6-12 empty rows for early morning)
  3. CLNDR.js Integration (http://kylestetz.github.io/CLNDR/) - I could be wrong about this but I saw that CLNDR.js "plays nice" with angular and has a pretty large following. Thought that you could maybe leverage that project's abstracted business logic!?

If I move forward with your solution, I will be sure to send a pull request with my anything I add.

Cheers!

How to add Dynamic Template whenever i click on particular Date.

My Idea is to add Dynamic content (partial HTML file) whenever i perform click action on particular Date.Its like a Google Calendar create event or task Quick popup.How Do I achieve this .Any help appreciated

month.html

   <tbody>
     <tr ng-repeat="row in rows track by $index">
        <td ng-show="showWeeks" class="calendar-week-column ">
           <small><em>{{ weekNumbers[$index] }}</em></small>
        </td>
        <td ng-repeat="dt in row track by dt.date" class="monthview-dateCell"  ng-click="select(dt.date)">
           <div ng-class="{'text-muted':dt.secondary}" ng-click="empty()">
              {{dt.label}}
           </div>
           <div ng-if="!dt.events" ng-click="emptySelected()"  >&nbsp;</div>
           <div class="eventin"  ng-repeat="event in dt.events | filter:search| limitTo:3" ng-if="dt.events"   ng-class="{'text-center':true, 'monthview-current': dt.current&&!dt.selected&&!dt.hasEvent,'monthview-secondary-with-event': dt.secondary&&dt.hasEvent, 'monthview-primary-with-event':!dt.secondary&&dt.hasEvent&&!dt.selected, 'monthview-selected': dt.selected}" >
              <div  ng-click="eventSelected({event:dt.events})">
                 <div ng-if="dt.hasEvent" class="monthview-eventdetail-timecolumn">
                    {{event.title}}
                 </div>
              </div>
           </div>
           <div class="dynamicHtmlClass">
          </div>
        </td>
     </tr>
  </tbody>

In Calendar.js
I tried in following ways
Not worked.

scope.select = function (selectedDate) {
 scope.partialHtml = '<div><button >Event</button><button >Task</button><button >Followup</button></div>';
 element.find('.dynamicHtmlClass').html(scope.partialHtml);
}

Applied to All 'td'

  scope.select = function (selectedDate) {
    scope.partialHtml = '<div><button >Event</button><button >Task</button>
     <button >Followup</button></div>';
   element.find('td').html(scope.partialHtml);
  }

Bower Installable

Hi,

Thanks for making this super easy to use library.

Could you please make it bower installable?

Thanks,
Edmond

How do I create more than one calendar and link them together?

Hi,

I need to create two calendars, showing current month & current month + 1 (for example, september and october 2015).

These calendar would be linked together; if I click the "Next" button on one calendar, the other one will also advance to the next month, like:

Calendar 1: September 2016
Calendar 2: October 2016

I click "Next" on calendar 1, then they'll be:

Calendar 1: October 2016
Calendar 2: November 2016

What is the best way to do this?

Thanks.

Integrate with ionic app ?

hello i try to integrate this with an ionic app , the calendar shows well but the event not showing , here is my code :

Controller :

app.controller('testCtrl', function($scope, $stateParams,ReservationService,$ionicContentBanner) {
$scope.events = [];//createRandomEvents();
// Rest api Call 
ReservationService.getById(33,setbookings);

function setbookings(data){
    $scope.groups = data.data; 
    _.each($scope.groups, function(group) {
        add_event(group);
    })
    console.log('bookings '+JSON.stringify(_.groupBy($scope.groups, "bookdate")));

}

function add_event(group){
    $scope.events.push({
        title: group.pick_point +'<i class="icon ion-ios-arrow-thin-right" style="font-size:16px;vertical-align: middle;">'+ group.drop_point,
        startTime: new Date(group.pick_datetime),
        endTime: '',
        allDay: false
        });
}});

the view :
ion-content ng-controller="testCtrl" ng-init="loadEvents()">
calendar calendar-mode="month" event-source="events" >
/ion-content>

any help please

Add time to calendar

Hello

I have a few questions about the system.

  • Add text to sunday that it´s closed.
  • Add in week, that the time is showing 07.00 - 16.30 and every event is 15 min.

Check the image, hope you understand what i mean.
screenshot_1

Update eventSource without refresh page

I create an delete event function, all is ok and the event is delete from backend but the calendar didn't refresh. to see the change i must refresh the page....how can i archieve this without refreshing page...
Merci

How to build it?

I did see this issue #48
but I always get

Fatal error: Unable to find local grunt.

I downloaded it with git clone and not bower so all files are present (even gruntfile.js)

I've never used grunt before, and I'm kind of stuck.

Switch to day view from month view by clicking on a date

Is it possible to switch to day view from month view by clicking on a day with events ?.On click of a date in month view I need to switch to day view and show its events there.I am new to angular ,and unable to figure out how to do it.

Localization

Pretty cool, it's in a need of localization though.
I will be glad to help btw.

All Day Event displayed in Two cells eventhough that is one Day Event

This is one of the event data
This is All day event that starts at "Sat, Aug 2, 2014 11:59 PM" and ends at "Sat, Aug 2, 2014 12:00 AM"
Current :This event displayed in Aug 1 and Aug 2 cells
Expected :This event should be displayed in Aug 2 cell

   {
      allDayEvent: "Y"
      description: "Desc"
      endDate: "Sat, Aug 2, 2014 11:59 PM"
      location: "Chennai"
      startDate: "Sat, Aug 2, 2014 12:00 AM"
      statusName: "Not Started"
      subject: "aug 2 Event"
    }

Don't colour day in month view based on event title

I've been given a requirement not to have the day (in month view) highlight blue if there is only one event on a day and that event contains "Unavailable" in the title. Is this something that would easily be done? I can't figure out in your code, how I should do it.

rangeChanged not triggering

Here is my HTML:
<calendar ng-model="currentDate" calendar-mode="calendarMode" event-source="bookingSource" query-mode="remote" range-changed="rangeChanged(startTime, endTime)" event-selected="onEventSelected(event, $event)"></calendar>

and here is what I have in my controller:
$scope.rangeChanged = function (startTime, endTime) { Events.query({ startTime: startTime, endTime: endTime }, function (events) { console.log("THIS IS A TEST"); $scope.eventSource = events; }); };

When I run my code, the "THIS IS A TEST" log message does not appear, which tells me the rangeChanged function is not fired. Am I doing something wrong?

Go to date

I'd like to add a datepicker and be able to go to a specified date. Any idea how I can implement this?
Thanks.

Display events on Calendar

Is it possible to display the events directly on the calendar instead of I need to hover it or click the circle icon to view the events? I need it badly but cannot figure out how to do it.

Events inside Event Details not Sorted

Current if the events in the eventSource is not sorted, events on the same day are not displayed in chronological orders within the event details views.

We need to add sorting to the array after this code segment (https://github.com/twinssbc/AngularJS-ResponsiveCalendar/blob/master/src/rcalendar/calendar.js#L422-L429)

              rows[rowIndex][dayIndex].hasEvent = true;
              eventSet = rows[rowIndex][dayIndex].events;
              if (eventSet) {
                eventSet.push(event);
              } else {
                eventSet = [];
                eventSet.push(event);
                rows[rowIndex][dayIndex].events = eventSet;
              }

Code to add

              rows[rowIndex][dayIndex].events.sort(
                function(event1, event2) {
                  return (event1.startTime.getTime() - event2.startTime.getTime());
                }
              );

Callback on "Prev" and "Next" click

Hi @twinssbc ,

Thanks for the directive, it's really helpful.

I need to create a callback when the next / prev button is clicked. Something similar with this: #40.

As suggested there, I tried using the "range-changed" attribute, but I'm still unable to get my callback function triggered.

My HTML:

<calendar
    calendar-mode="month"    
    range-changed="rangeChanged(startTime, endTime)"
 ></calendar>

My Javascript:

$scope.rangeChanged = function (startTime, endTime) {
    console.log(startTime, endTime); // should print something, but empty
}

Any help would be appreciated. Thanks.

Ajax request

Awesome job on this. I'm new the Angular but I believe I've poked around enough to get the ajax request working that'll retrieve events from a mysql database via php script and return the events in json format. I'd appreciate any help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.