modularity-rails 0.12.2 → 0.12.3
Sign up to get free protection for your applications and to get access to all the features.
- data/demo/spec/javascripts/data/ajax_loader_spec.coffee +12 -0
- data/demo/spec/javascripts/data/persistence_manager_spec.coffee +47 -0
- data/lib/modularity-rails/version.rb +1 -1
- data/vendor/assets/javascripts/modularity/data/ajax_loader.coffee +6 -0
- data/vendor/assets/javascripts/modularity/data/persistence_manager.coffee +33 -10
- data/vendor/assets/javascripts/modularity/modules/ajax_indicator.coffee +24 -0
- metadata +13 -12
@@ -17,6 +17,18 @@ describe 'ajax_loader', ->
|
|
17
17
|
loader = new modularity.AjaxLoader {caching: yes}
|
18
18
|
loader.caching.should.be.true
|
19
19
|
|
20
|
+
describe 'ajax', ->
|
21
|
+
|
22
|
+
describe 'GET request', ->
|
23
|
+
|
24
|
+
it 'buffers the request'
|
25
|
+
|
26
|
+
it 'fires the events'
|
27
|
+
|
28
|
+
it ''
|
29
|
+
|
30
|
+
describe 'other requests'
|
31
|
+
|
20
32
|
|
21
33
|
describe 'get', ->
|
22
34
|
url = "/users/4"
|
@@ -41,6 +41,7 @@ describe 'PersistenceManager', ->
|
|
41
41
|
persistence_manager.add_all data
|
42
42
|
spy.should.have.been.calledOnce
|
43
43
|
|
44
|
+
|
44
45
|
describe 'create', ->
|
45
46
|
new_obj = {value: 'foo'}
|
46
47
|
|
@@ -136,6 +137,52 @@ describe 'PersistenceManager', ->
|
|
136
137
|
loading_done_callback.should.have.been.calledOnce
|
137
138
|
|
138
139
|
|
140
|
+
describe 'load_local', ->
|
141
|
+
|
142
|
+
describe 'entry exists in client data cache', ->
|
143
|
+
it 'returns the entry from the @client_data cache if it exists there', ->
|
144
|
+
persistence_manager.client_data.add entry_1
|
145
|
+
result = persistence_manager.load_local 1
|
146
|
+
result.should.equal entry_1
|
147
|
+
|
148
|
+
describe 'entry exists in server data cache', ->
|
149
|
+
|
150
|
+
beforeEach ->
|
151
|
+
persistence_manager.server_data.add entry_1
|
152
|
+
|
153
|
+
it 'adds the entry to the client data cache', ->
|
154
|
+
persistence_manager.load_local 1
|
155
|
+
persistence_manager.client_data.length().should.equal 1
|
156
|
+
persistence_manager.client_data.get(1).should.eql entry_1
|
157
|
+
|
158
|
+
it 'returns the entry from the client data cache', ->
|
159
|
+
result = persistence_manager.load_local 1
|
160
|
+
client_cache_entry = persistence_manager.client_data.get 1
|
161
|
+
result.should.equal client_cache_entry
|
162
|
+
|
163
|
+
it 'returns a different hash than the server data, so that the user can make changes to it', ->
|
164
|
+
result = persistence_manager.load_local 1
|
165
|
+
server_cache_entry = persistence_manager.server_data.get 1
|
166
|
+
result.should.not.equal server_cache_entry
|
167
|
+
|
168
|
+
describe "entry doesn't exist in any cache", ->
|
169
|
+
|
170
|
+
it 'returns undefined', ->
|
171
|
+
expect(persistence_manager.load_local(1)).to.be.undefined
|
172
|
+
|
173
|
+
|
174
|
+
describe 'load_many', ->
|
175
|
+
|
176
|
+
describe 'all entries exists in the cache', ->
|
177
|
+
it 'returns the entries immediately', (done) ->
|
178
|
+
persistence_manager.add_all [entry_1, entry_2]
|
179
|
+
persistence_manager.load_many [1,2], (entries) ->
|
180
|
+
entries.length.should.equal 2
|
181
|
+
entries[0].should.eql entry_1
|
182
|
+
entries[1].should.eql entry_2
|
183
|
+
done()
|
184
|
+
|
185
|
+
|
139
186
|
describe 'load', ->
|
140
187
|
|
141
188
|
describe 'entry exists in client data cache', ->
|
@@ -24,6 +24,12 @@ class window.modularity.AjaxLoader
|
|
24
24
|
AJAX_LOADED: 'AJAX_LOADED' # Called when an AJAX request finishes.
|
25
25
|
|
26
26
|
|
27
|
+
# Makes the given AJAX call.
|
28
|
+
# Buffers the call if it's a GET request.
|
29
|
+
# Fires the AJAX events.
|
30
|
+
ajax: (options) ->
|
31
|
+
|
32
|
+
|
27
33
|
get: (url, callback) ->
|
28
34
|
cached_value = @cache.get url
|
29
35
|
|
@@ -63,16 +63,8 @@ class modularity.PersistenceManager
|
|
63
63
|
# Returns the entry with the given key.
|
64
64
|
load: (key, callback) ->
|
65
65
|
|
66
|
-
|
67
|
-
|
68
|
-
return callback(client_obj) if client_obj
|
69
|
-
|
70
|
-
# No data in client cache --> try to use server cache.
|
71
|
-
server_obj = @server_data.get key
|
72
|
-
if server_obj
|
73
|
-
client_obj = modularity.clone_hash server_obj
|
74
|
-
@client_data.add client_obj
|
75
|
-
return callback client_obj
|
66
|
+
entry = @load_local key
|
67
|
+
return callback(entry) if entry
|
76
68
|
|
77
69
|
# No data on client at all --> load data from server.
|
78
70
|
@loader.get "#{@base_url}/#{key}", (server_entry) =>
|
@@ -94,7 +86,38 @@ class modularity.PersistenceManager
|
|
94
86
|
callback()
|
95
87
|
}
|
96
88
|
|
89
|
+
|
90
|
+
# Loads the entry synchronously from the cache.
|
91
|
+
# Doesn't fall back to the server.
|
92
|
+
load_local: (key) ->
|
93
|
+
|
94
|
+
# Try to use client_data cache.
|
95
|
+
client_obj = @client_data.get key
|
96
|
+
return client_obj if client_obj
|
97
|
+
|
98
|
+
# No data in client cache --> try to use server cache.
|
99
|
+
server_obj = @server_data.get key
|
100
|
+
return null unless server_obj
|
101
|
+
client_obj = modularity.clone_hash server_obj
|
102
|
+
@client_data.add client_obj
|
103
|
+
client_obj
|
97
104
|
|
105
|
+
|
106
|
+
# Returns all entries with the given keys.
|
107
|
+
load_many: (keys, callback) ->
|
108
|
+
result = []
|
109
|
+
missing_keys = []
|
110
|
+
for key in keys
|
111
|
+
do (key) =>
|
112
|
+
entry = @load_local key
|
113
|
+
if entry
|
114
|
+
result.push entry
|
115
|
+
else
|
116
|
+
missing_keys.push key
|
117
|
+
alert "modularity.PersistenceManager.load_many(): Missing functionality to load from the server." if missing_keys.length > 0
|
118
|
+
callback result
|
119
|
+
|
120
|
+
|
98
121
|
# Saves the given object.
|
99
122
|
# Does the right thing (create or update) dependent on
|
100
123
|
# whether the object already has a key parameter.
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Indicates that an AJAX request is running.
|
2
|
+
class sn.AjaxIndicator extends modularity.Module
|
3
|
+
|
4
|
+
constructor: ->
|
5
|
+
|
6
|
+
# The number of currently running ajax requests.
|
7
|
+
@ajax_counter = 0
|
8
|
+
|
9
|
+
@searchManager.bind_event sn.SearchManager.events.AJAX_LOADING, @ajax_loading
|
10
|
+
@searchManager.bind_event sn.SearchManager.events.AJAX_LOADED, @ajax_loaded
|
11
|
+
|
12
|
+
|
13
|
+
# Called when an ajax request starts.
|
14
|
+
ajax_loading: =>
|
15
|
+
@container.addClass 'loading' if @ajax_counter == 0
|
16
|
+
@ajax_counter += 1
|
17
|
+
|
18
|
+
|
19
|
+
# Called when the ajax request is done.
|
20
|
+
ajax_loaded: =>
|
21
|
+
@ajax_counter -= 1
|
22
|
+
@ajax_counter = 0 if @ajax_counter <= 0
|
23
|
+
@container.removeClass 'loading'
|
24
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: modularity-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &70181204940740 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.1.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70181204940740
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: capybara-webkit
|
27
|
-
requirement: &
|
27
|
+
requirement: &70181204936980 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70181204936980
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: evergreen
|
38
|
-
requirement: &
|
38
|
+
requirement: &70181204934000 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70181204934000
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rb-fsevent
|
49
|
-
requirement: &
|
49
|
+
requirement: &70181204930600 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70181204930600
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: guard-livereload
|
60
|
-
requirement: &
|
60
|
+
requirement: &70181204926320 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70181204926320
|
69
69
|
description: Description of ModularityRails.
|
70
70
|
email:
|
71
71
|
- kevin.goslar@gmail.com
|
@@ -155,6 +155,7 @@ files:
|
|
155
155
|
- vendor/assets/javascripts/modularity/data/persistence_manager.coffee
|
156
156
|
- vendor/assets/javascripts/modularity/mixins/clickable.coffee
|
157
157
|
- vendor/assets/javascripts/modularity/mixins/closable.coffee
|
158
|
+
- vendor/assets/javascripts/modularity/modules/ajax_indicator.coffee
|
158
159
|
- vendor/assets/javascripts/modularity/modules/autogrow_textarea.coffee
|
159
160
|
- vendor/assets/javascripts/modularity/modules/button.coffee
|
160
161
|
- vendor/assets/javascripts/modularity/modules/counter_button.coffee
|