angular-ui-calendar-rails 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c029fd8837134254a8bbdbc3383ed7d6d5aefa5d
4
+ data.tar.gz: f5dae8cfeaec12a20ddbf253778ad6e3959168fc
5
+ SHA512:
6
+ metadata.gz: ca4f5e8bc0dac8d0ab9ce58af6294e4b1ad462b10703ffdad9b651156e5c676fcdba065209bfe0899b75cc2a67900dd26bb7277be445c19708c710f792cdde01
7
+ data.tar.gz: 037933f91c4f23129a77275908490a1ebf4c9b40399b8a99f859b43e204e31caa3ea61d7c69aca357dea53c8e565538fdc2602ac652f4a72f58fc3d0bd2d7a85
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ vendor/bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in angular-ui-calendar-rails.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Wataru MIYAGUNI
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,36 @@
1
+ # angular-ui-calendar-rails
2
+
3
+ angular-ui-calendar-rails wraps the [AngularJS UI Calendar](http://angular-ui.github.io/ui-calendar/) library for use in Rails 3.1 and above. Assets will minify automatically during production.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'angular-ui-calendar-rails'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install angular-ui-calendar-rails
18
+
19
+ ## Usage
20
+
21
+ Add the following directive to your JavaScript manifest file (application.js):
22
+
23
+ //= require angular-ui-calendar
24
+
25
+ You may need to add 'ui.calendar' into your app declaration for example
26
+
27
+ app = angular.module('MyApp', ["ui.calendar"])
28
+
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it ( https://github.com/gongo/angular-ui-calendar-rails/fork )
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'angular/ui/calendar/rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'angular-ui-calendar-rails'
8
+ spec.version = Angular::Ui::Calendar::Rails::VERSION
9
+ spec.authors = ['Wataru MIYAGUNI']
10
+ spec.email = ['gonngo@gmail.com']
11
+ spec.summary = 'AngularJS UI Calendar on Rails'
12
+ spec.description = 'Injects AngularJS UI Calendar directives into your asset pipeline.'
13
+ spec.homepage = 'https://github.com/gongo/angular-ui-calendar-rails'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,12 @@
1
+ require "angular/ui/calendar/rails/version"
2
+
3
+ module Angular
4
+ module Ui
5
+ module Calendar
6
+ module Rails
7
+ class Engine < ::Rails::Engine
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ module Angular
2
+ module Ui
3
+ module Calendar
4
+ module Rails
5
+ VERSION = '0.8.1'
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,266 @@
1
+ /*
2
+ * AngularJs Fullcalendar Wrapper for the JQuery FullCalendar
3
+ * API @ http://arshaw.com/fullcalendar/
4
+ *
5
+ * Angular Calendar Directive that takes in the [eventSources] nested array object as the ng-model and watches it deeply changes.
6
+ * Can also take in multiple event urls as a source object(s) and feed the events per view.
7
+ * The calendar will watch any eventSource array and update itself when a change is made.
8
+ *
9
+ */
10
+
11
+ angular.module('ui.calendar', [])
12
+ .constant('uiCalendarConfig', {})
13
+ .controller('uiCalendarCtrl', ['$scope', '$timeout', function($scope, $timeout){
14
+
15
+ var sourceSerialId = 1,
16
+ eventSerialId = 1,
17
+ sources = $scope.eventSources,
18
+ extraEventSignature = $scope.calendarWatchEvent ? $scope.calendarWatchEvent : angular.noop,
19
+
20
+ wrapFunctionWithScopeApply = function(functionToWrap){
21
+ var wrapper;
22
+
23
+ if (functionToWrap){
24
+ wrapper = function(){
25
+ // This happens outside of angular context so we need to wrap it in a timeout which has an implied apply.
26
+ // In this way the function will be safely executed on the next digest.
27
+
28
+ var args = arguments;
29
+ $timeout(function(){
30
+ functionToWrap.apply(this, args);
31
+ });
32
+ };
33
+ }
34
+
35
+ return wrapper;
36
+ };
37
+
38
+ this.eventsFingerprint = function(e) {
39
+ if (!e.__uiCalId) {
40
+ e.__uiCalId = eventSerialId++;
41
+ }
42
+ // This extracts all the information we need from the event. http://jsperf.com/angular-calendar-events-fingerprint/3
43
+ return "" + e.__uiCalId + (e.id || '') + (e.title || '') + (e.url || '') + (+e.start || '') + (+e.end || '') +
44
+ (e.allDay || '') + (e.className || '') + extraEventSignature(e) || '';
45
+ };
46
+
47
+ this.sourcesFingerprint = function(source) {
48
+ return source.__id || (source.__id = sourceSerialId++);
49
+ };
50
+
51
+ this.allEvents = function() {
52
+ // return sources.flatten(); but we don't have flatten
53
+ var arraySources = [];
54
+ for (var i = 0, srcLen = sources.length; i < srcLen; i++) {
55
+ var source = sources[i];
56
+ if (angular.isArray(source)) {
57
+ // event source as array
58
+ arraySources.push(source);
59
+ } else if(angular.isObject(source) && angular.isArray(source.events)){
60
+ // event source as object, ie extended form
61
+ var extEvent = {};
62
+ for(var key in source){
63
+ if(key !== '_uiCalId' && key !== 'events'){
64
+ extEvent[key] = source[key];
65
+ }
66
+ }
67
+ for(var eI = 0;eI < source.events.length;eI++){
68
+ angular.extend(source.events[eI],extEvent);
69
+ }
70
+ arraySources.push(source.events);
71
+ }
72
+ }
73
+
74
+ return Array.prototype.concat.apply([], arraySources);
75
+ };
76
+
77
+ // Track changes in array by assigning id tokens to each element and watching the scope for changes in those tokens
78
+ // arguments:
79
+ // arraySource array of function that returns array of objects to watch
80
+ // tokenFn function(object) that returns the token for a given object
81
+ this.changeWatcher = function(arraySource, tokenFn) {
82
+ var self;
83
+ var getTokens = function() {
84
+ var array = angular.isFunction(arraySource) ? arraySource() : arraySource;
85
+ var result = [], token, el;
86
+ for (var i = 0, n = array.length; i < n; i++) {
87
+ el = array[i];
88
+ token = tokenFn(el);
89
+ map[token] = el;
90
+ result.push(token);
91
+ }
92
+ return result;
93
+ };
94
+ // returns elements in that are in a but not in b
95
+ // subtractAsSets([4, 5, 6], [4, 5, 7]) => [6]
96
+ var subtractAsSets = function(a, b) {
97
+ var result = [], inB = {}, i, n;
98
+ for (i = 0, n = b.length; i < n; i++) {
99
+ inB[b[i]] = true;
100
+ }
101
+ for (i = 0, n = a.length; i < n; i++) {
102
+ if (!inB[a[i]]) {
103
+ result.push(a[i]);
104
+ }
105
+ }
106
+ return result;
107
+ };
108
+
109
+ // Map objects to tokens and vice-versa
110
+ var map = {};
111
+
112
+ var applyChanges = function(newTokens, oldTokens) {
113
+ var i, n, el, token;
114
+ var replacedTokens = {};
115
+ var removedTokens = subtractAsSets(oldTokens, newTokens);
116
+ for (i = 0, n = removedTokens.length; i < n; i++) {
117
+ var removedToken = removedTokens[i];
118
+ el = map[removedToken];
119
+ delete map[removedToken];
120
+ var newToken = tokenFn(el);
121
+ // if the element wasn't removed but simply got a new token, its old token will be different from the current one
122
+ if (newToken === removedToken) {
123
+ self.onRemoved(el);
124
+ } else {
125
+ replacedTokens[newToken] = removedToken;
126
+ self.onChanged(el);
127
+ }
128
+ }
129
+
130
+ var addedTokens = subtractAsSets(newTokens, oldTokens);
131
+ for (i = 0, n = addedTokens.length; i < n; i++) {
132
+ token = addedTokens[i];
133
+ el = map[token];
134
+ if (!replacedTokens[token]) {
135
+ self.onAdded(el);
136
+ }
137
+ }
138
+ };
139
+ return self = {
140
+ subscribe: function(scope, onChanged) {
141
+ scope.$watch(getTokens, function(newTokens, oldTokens) {
142
+ if (!onChanged || onChanged(newTokens, oldTokens) !== false) {
143
+ applyChanges(newTokens, oldTokens);
144
+ }
145
+ }, true);
146
+ },
147
+ onAdded: angular.noop,
148
+ onChanged: angular.noop,
149
+ onRemoved: angular.noop
150
+ };
151
+ };
152
+
153
+ this.getFullCalendarConfig = function(calendarSettings, uiCalendarConfig){
154
+ var config = {};
155
+
156
+ angular.extend(config, uiCalendarConfig);
157
+ angular.extend(config, calendarSettings);
158
+
159
+ angular.forEach(config, function(value,key){
160
+ if (typeof value === 'function'){
161
+ config[key] = wrapFunctionWithScopeApply(config[key]);
162
+ }
163
+ });
164
+
165
+ return config;
166
+ };
167
+ }])
168
+ .directive('uiCalendar', ['uiCalendarConfig', '$locale', function(uiCalendarConfig, $locale) {
169
+ // Configure to use locale names by default
170
+ var tValues = function(data) {
171
+ // convert {0: "Jan", 1: "Feb", ...} to ["Jan", "Feb", ...]
172
+ var r, k;
173
+ r = [];
174
+ for (k in data) {
175
+ r[k] = data[k];
176
+ }
177
+ return r;
178
+ };
179
+ var dtf = $locale.DATETIME_FORMATS;
180
+ uiCalendarConfig = angular.extend({
181
+ monthNames: tValues(dtf.MONTH),
182
+ monthNamesShort: tValues(dtf.SHORTMONTH),
183
+ dayNames: tValues(dtf.DAY),
184
+ dayNamesShort: tValues(dtf.SHORTDAY)
185
+ }, uiCalendarConfig || {});
186
+
187
+ return {
188
+ restrict: 'A',
189
+ scope: {eventSources:'=ngModel',calendarWatchEvent: '&'},
190
+ controller: 'uiCalendarCtrl',
191
+ link: function(scope, elm, attrs, controller) {
192
+
193
+ var sources = scope.eventSources,
194
+ sourcesChanged = false,
195
+ eventSourcesWatcher = controller.changeWatcher(sources, controller.sourcesFingerprint),
196
+ eventsWatcher = controller.changeWatcher(controller.allEvents, controller.eventsFingerprint),
197
+ options = null;
198
+
199
+ function getOptions(){
200
+ var calendarSettings = attrs.uiCalendar ? scope.$parent.$eval(attrs.uiCalendar) : {},
201
+ fullCalendarConfig;
202
+
203
+ fullCalendarConfig = controller.getFullCalendarConfig(calendarSettings, uiCalendarConfig);
204
+
205
+ options = { eventSources: sources };
206
+ angular.extend(options, fullCalendarConfig);
207
+
208
+ var options2 = {};
209
+ for(var o in options){
210
+ if(o !== 'eventSources'){
211
+ options2[o] = options[o];
212
+ }
213
+ }
214
+ return JSON.stringify(options2);
215
+ }
216
+
217
+ scope.destroy = function(){
218
+ if(attrs.calendar) {
219
+ scope.calendar = scope.$parent[attrs.calendar] = elm.html('');
220
+ } else {
221
+ scope.calendar = elm.html('');
222
+ }
223
+ };
224
+
225
+ scope.init = function(){
226
+ scope.calendar.fullCalendar(options);
227
+ };
228
+
229
+ eventSourcesWatcher.onAdded = function(source) {
230
+ scope.calendar.fullCalendar('addEventSource', source);
231
+ sourcesChanged = true;
232
+ };
233
+
234
+ eventSourcesWatcher.onRemoved = function(source) {
235
+ scope.calendar.fullCalendar('removeEventSource', source);
236
+ sourcesChanged = true;
237
+ };
238
+
239
+ eventsWatcher.onAdded = function(event) {
240
+ scope.calendar.fullCalendar('renderEvent', event);
241
+ };
242
+
243
+ eventsWatcher.onRemoved = function(event) {
244
+ scope.calendar.fullCalendar('removeEvents', function(e) { return e === event; });
245
+ };
246
+
247
+ eventsWatcher.onChanged = function(event) {
248
+ scope.calendar.fullCalendar('updateEvent', event);
249
+ };
250
+
251
+ eventSourcesWatcher.subscribe(scope);
252
+ eventsWatcher.subscribe(scope, function(newTokens, oldTokens) {
253
+ if (sourcesChanged === true) {
254
+ sourcesChanged = false;
255
+ // prevent incremental updates in this case
256
+ return false;
257
+ }
258
+ });
259
+
260
+ scope.$watch(getOptions, function(newO,oldO){
261
+ scope.destroy();
262
+ scope.init();
263
+ });
264
+ }
265
+ };
266
+ }]);
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: angular-ui-calendar-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.1
5
+ platform: ruby
6
+ authors:
7
+ - Wataru MIYAGUNI
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Injects AngularJS UI Calendar directives into your asset pipeline.
42
+ email:
43
+ - gonngo@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - angular-ui-calendar-rails.gemspec
54
+ - lib/angular/ui/calendar/rails.rb
55
+ - lib/angular/ui/calendar/rails/version.rb
56
+ - vendor/assets/javascripts/angular-ui-calendar.js
57
+ homepage: https://github.com/gongo/angular-ui-calendar-rails
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.2.2
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: AngularJS UI Calendar on Rails
81
+ test_files: []