This repository has been archived by the owner on Sep 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 727
Added resourceWatcher #354
Open
gusreyes01
wants to merge
2
commits into
angular-ui:master
Choose a base branch
from
gusreyes01:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.resources
isundefined
.I believe line 238 should be modified (see comment there)