-
Couldn't load subscription status.
- Fork 719
Added resourceWatcher #354
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ angular.module('ui.calendar', []) | |
| }; | ||
|
|
||
| var eventSerialId = 1; | ||
| var resourceSerialId = 1; | ||
| // @return {String} fingerprint of the event object and its properties | ||
| this.eventFingerprint = function(e) { | ||
| if (!e._id) { | ||
|
|
@@ -50,6 +51,16 @@ angular.module('ui.calendar', []) | |
| (e.allDay || '') + (e.className || '') + extraSignature; | ||
| }; | ||
|
|
||
| // @return {String} fingerprint of the event object and its properties | ||
| this.resourceFingerprint = function(r) { | ||
| if (!r._id) { | ||
| r._id = resourceSerialId++; | ||
| } | ||
|
|
||
| // This extracts all the information we need from the resource. http://jsperf.com/angular-calendar-events-fingerprint/3 | ||
| return r.id; | ||
| }; | ||
|
|
||
| var sourceSerialId = 1, sourceEventsSerialId = 1; | ||
| // @return {String} fingerprint of the source object and its events array | ||
| this.sourceFingerprint = function(source) { | ||
|
|
@@ -98,6 +109,7 @@ angular.module('ui.calendar', []) | |
| this.changeWatcher = function(arraySource, tokenFn) { | ||
| var self; | ||
| var getTokens = function() { | ||
| // console.log(arraySource); | ||
| var array = angular.isFunction(arraySource) ? arraySource() : arraySource; | ||
| var result = [], token, el; | ||
| for (var i = 0, n = array.length; i < n; i++) { | ||
|
|
@@ -214,15 +226,16 @@ angular.module('ui.calendar', []) | |
| .directive('uiCalendar', ['uiCalendarConfig', function(uiCalendarConfig) { | ||
| return { | ||
| restrict: 'A', | ||
| scope: {eventSources:'=ngModel',calendarWatchEvent: '&'}, | ||
| scope: {eventSources:'=ngModel',calendarWatchEvent: '&', resources: '='}, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To keep the API consistent, we should also add a |
||
| controller: 'uiCalendarCtrl', | ||
| link: function(scope, elm, attrs, controller) { | ||
|
|
||
| var sources = scope.eventSources, | ||
| evResources = scope.resources, | ||
| sourcesChanged = false, | ||
| calendar, | ||
| eventSourcesWatcher = controller.changeWatcher(sources, controller.sourceFingerprint), | ||
| eventsWatcher = controller.changeWatcher(controller.allEvents, controller.eventFingerprint), | ||
| resourceWatcher = controller.changeWatcher(scope.resources, controller.resourceFingerprint), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would change |
||
| options = null; | ||
|
|
||
| function getOptions(){ | ||
|
|
@@ -233,7 +246,8 @@ angular.module('ui.calendar', []) | |
|
|
||
| var localeFullCalendarConfig = controller.getLocaleConfig(fullCalendarConfig); | ||
| angular.extend(localeFullCalendarConfig, fullCalendarConfig); | ||
| options = { eventSources: sources }; | ||
| options = { eventSources: sources, | ||
| resources: evResources }; | ||
| angular.extend(options, localeFullCalendarConfig); | ||
| //remove calendars from options | ||
| options.calendars = null; | ||
|
|
@@ -265,6 +279,7 @@ angular.module('ui.calendar', []) | |
| calendar.fullCalendar(options); | ||
| if(attrs.calendar) { | ||
| uiCalendarConfig.calendars[attrs.calendar] = calendar; | ||
| window.calendar = calendar; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am unsure why we need to expose the calendar on |
||
| } | ||
| }; | ||
| scope.$on('$destroy', function() { | ||
|
|
@@ -299,7 +314,7 @@ angular.module('ui.calendar', []) | |
|
|
||
| eventsWatcher.onAdded = function(event) { | ||
| if (calendar && calendar.fullCalendar) { | ||
| calendar.fullCalendar('renderEvent', event, (event.stick ? true : false)); | ||
| calendar.fullCalendar('renderEvent', event, true); | ||
| } | ||
| }; | ||
|
|
||
|
|
@@ -309,6 +324,18 @@ angular.module('ui.calendar', []) | |
| } | ||
| }; | ||
|
|
||
| resourceWatcher.onAdded = function(resource) { | ||
| if (calendar && calendar.fullCalendar) { | ||
| calendar.fullCalendar('addResource', resource); | ||
| } | ||
| }; | ||
|
|
||
| resourceWatcher.onRemoved = function(resource) { | ||
| if (calendar && calendar.fullCalendar) { | ||
| calendar.fullCalendar('removeResource', resource); | ||
| } | ||
| }; | ||
|
|
||
| eventsWatcher.onChanged = function(event) { | ||
| if (calendar && calendar.fullCalendar) { | ||
| var clientEvents = calendar.fullCalendar('clientEvents', event._id); | ||
|
|
@@ -320,6 +347,7 @@ angular.module('ui.calendar', []) | |
| } | ||
| }; | ||
|
|
||
| resourceWatcher.subscribe(scope); | ||
| eventSourcesWatcher.subscribe(scope); | ||
| eventsWatcher.subscribe(scope, function() { | ||
| if (sourcesChanged === true) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Travis fails here since test files where not updated. Therefore
scope.resourcesisundefined.I believe line 238 should be modified (see comment there)