From 46bfc28cc8578d0e7662dcafb8ee0bb646d33665 Mon Sep 17 00:00:00 2001 From: Gustavo Reyes Date: Wed, 2 Dec 2015 16:32:36 -0600 Subject: [PATCH 1/2] Added resourceWatcher Resources are supported and work with FullCalendar Scheduler Plugin. --- src/calendar.js | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/calendar.js b/src/calendar.js index 181dd88..5b03bf2 100644 --- a/src/calendar.js +++ b/src/calendar.js @@ -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: '='}, 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), 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; } }; 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) { From a3953f0bf2d48b40a380ae82e9a54f1af91500a5 Mon Sep 17 00:00:00 2001 From: Gustavo Reyes Date: Wed, 2 Dec 2015 16:38:26 -0600 Subject: [PATCH 2/2] Added missing semicolon --- src/calendar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calendar.js b/src/calendar.js index 5b03bf2..c88c130 100644 --- a/src/calendar.js +++ b/src/calendar.js @@ -58,7 +58,7 @@ angular.module('ui.calendar', []) } // This extracts all the information we need from the resource. http://jsperf.com/angular-calendar-events-fingerprint/3 - return r.id + return r.id; }; var sourceSerialId = 1, sourceEventsSerialId = 1;