nali 0.2.3 → 0.2.4
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.
- data/lib/client/javascripts/nali/collection.js.coffee +3 -3
- data/lib/client/javascripts/nali/controller.js.coffee +1 -1
- data/lib/client/javascripts/nali/model.js.coffee +20 -10
- data/lib/client/javascripts/nali/router.js.coffee +4 -4
- data/lib/client/javascripts/nali/view.js.coffee +5 -2
- data/lib/generator/config/environments/development.rb +1 -1
- data/lib/nali/clients.rb +4 -3
- data/lib/nali/version.rb +1 -1
- metadata +2 -2
@@ -10,6 +10,7 @@ Nali.extend Collection:
|
|
10
10
|
@adaptations = apply: [], cancel: []
|
11
11
|
@ordering = {}
|
12
12
|
@adaptCollection()
|
13
|
+
@model.each ( model ) => @add model if model.isCorrect @filters
|
13
14
|
@
|
14
15
|
|
15
16
|
new: ( model, filters ) ->
|
@@ -102,9 +103,8 @@ Nali.extend Collection:
|
|
102
103
|
@
|
103
104
|
|
104
105
|
where: ( filters ) ->
|
105
|
-
|
106
|
-
|
107
|
-
result
|
106
|
+
filters[ name ] = value for name, value of @filters
|
107
|
+
@model.where filters
|
108
108
|
|
109
109
|
order: ( @ordering ) ->
|
110
110
|
@reorder()
|
@@ -32,10 +32,10 @@ Nali.extend Model:
|
|
32
32
|
for name, view of @View.extensions when name.indexOf( @_name ) >= 0
|
33
33
|
do ( name, view ) =>
|
34
34
|
@views[ short = view._shortName ] = view
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
shortCap = short.capitalize()
|
36
|
+
unless @[ viewMethod = 'view' + shortCap ]? then @[ viewMethod ] = -> @view short
|
37
|
+
unless @[ showMethod = 'show' + shortCap ]? then @[ showMethod ] = ( insertTo ) -> @show short, insertTo
|
38
|
+
unless @[ hideMethod = 'hide' + shortCap ]? then @[ hideMethod ] = -> @hide short
|
39
39
|
@
|
40
40
|
|
41
41
|
notice: ( params ) ->
|
@@ -149,8 +149,8 @@ Nali.extend Model:
|
|
149
149
|
updateAttribute: ( name, value ) ->
|
150
150
|
# обновляет один атрибут модели, проверяя его валидность, генерирует событие update.attributeName
|
151
151
|
value = @normalizeValue value
|
152
|
-
if @
|
153
|
-
@
|
152
|
+
if @[ name ] isnt value and @isValidAttributeValue( name, value )
|
153
|
+
@[ name ] = value
|
154
154
|
@[ 'onUpdate' + name.capitalize() ]?()
|
155
155
|
@trigger "update.#{ name }"
|
156
156
|
true
|
@@ -170,7 +170,6 @@ Nali.extend Model:
|
|
170
170
|
where: ( filters ) ->
|
171
171
|
# возвращает коллекцию моделей соответствующих фильтру
|
172
172
|
collection = @Collection.new @, filters
|
173
|
-
collection.add model for model in @table when model.isCorrect filters
|
174
173
|
if @forced and not collection.length
|
175
174
|
attributes = {}
|
176
175
|
attributes[ key ] = value for key, value of filters when typeof value in [ 'number', 'string' ]
|
@@ -178,8 +177,14 @@ Nali.extend Model:
|
|
178
177
|
collection
|
179
178
|
|
180
179
|
all: ->
|
180
|
+
# возвращает коллекцию всех моделей
|
181
181
|
@where id: /./
|
182
182
|
|
183
|
+
each: ( callback ) ->
|
184
|
+
# применяет колбек ко всем моделям
|
185
|
+
callback.call @, model for model in @table
|
186
|
+
@
|
187
|
+
|
183
188
|
# работа с аттрибутами
|
184
189
|
|
185
190
|
guid: ->
|
@@ -211,7 +216,11 @@ Nali.extend Model:
|
|
211
216
|
# проверяет соответствие аттрибутов модели определенному набору фильтров, возвращает true либо false
|
212
217
|
return filters.call @ if typeof filters is 'function'
|
213
218
|
return false unless Object.keys( filters ).length
|
214
|
-
|
219
|
+
for name, filter of filters
|
220
|
+
result = if name is 'correct' and typeof filter is 'function'
|
221
|
+
filter.call @
|
222
|
+
else @isCorrectAttribute @[ name ], filter
|
223
|
+
return false unless result
|
215
224
|
return true
|
216
225
|
|
217
226
|
isCorrectAttribute: ( attribute, filter ) ->
|
@@ -223,6 +232,8 @@ Nali.extend Model:
|
|
223
232
|
'' + attribute is filter
|
224
233
|
else if typeof filter is 'number'
|
225
234
|
+ attribute is filter
|
235
|
+
else if typeof filter is 'boolean'
|
236
|
+
attribute is filter
|
226
237
|
else if filter instanceof Array
|
227
238
|
'' + attribute in filter or + attribute in filter
|
228
239
|
else false
|
@@ -316,10 +327,9 @@ Nali.extend Model:
|
|
316
327
|
# связанных с текущей через модель through
|
317
328
|
@getter name, =>
|
318
329
|
delete @[ name ]
|
319
|
-
@[ name ] =
|
330
|
+
@[ name ] = model.where correct: ->
|
320
331
|
return true for model in @[ through ] when model[ key ] is @
|
321
332
|
false
|
322
|
-
@[ name ].add @[ through ].pluck key
|
323
333
|
@[ name ].subscribeTo @[ through ], 'update.length.add', ( collection, model ) -> @add model[ key ]
|
324
334
|
@[ name ].subscribeTo @[ through ], 'update.length.remove', ( collection, model ) -> @remove model[ key ]
|
325
335
|
@[ name ]
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Nali.extend Router:
|
2
2
|
|
3
3
|
initialize: ->
|
4
|
-
@::expand redirect: ( args... ) => @
|
4
|
+
@::expand redirect: ( args... ) => @redirect args...
|
5
5
|
@
|
6
6
|
|
7
7
|
routes: {}
|
@@ -12,7 +12,7 @@ Nali.extend Router:
|
|
12
12
|
event.preventDefault()
|
13
13
|
event.stopPropagation()
|
14
14
|
@saveHistory false
|
15
|
-
@
|
15
|
+
@redirect event.target.location.pathname
|
16
16
|
@
|
17
17
|
|
18
18
|
scanRoutes: ->
|
@@ -25,13 +25,13 @@ Nali.extend Router:
|
|
25
25
|
@routes[ route ] = controller
|
26
26
|
@
|
27
27
|
|
28
|
-
|
28
|
+
redirect: ( url = window.location.pathname, options = {} ) ->
|
29
29
|
if found = @findRoute @prepare( url ) or @prepare( @Application.defaultUrl )
|
30
30
|
{ controller, action, filters, params } = found
|
31
31
|
params[ name ] = value for name, value in options
|
32
32
|
controller.run action, filters, params
|
33
33
|
else if @Application.notFoundUrl
|
34
|
-
@
|
34
|
+
@redirect @Application.notFoundUrl
|
35
35
|
else console.warn "Not exists route to the address %s", url
|
36
36
|
@
|
37
37
|
|
@@ -34,9 +34,10 @@ Nali.extend View:
|
|
34
34
|
@
|
35
35
|
|
36
36
|
show: ( insertTo = @insertTo() ) ->
|
37
|
-
@prepareElement()
|
37
|
+
@prepareElement()
|
38
38
|
unless @visible
|
39
39
|
@runModelCallback 'beforeShow'
|
40
|
+
@draw().bindEvents()
|
40
41
|
@runAssistants 'show'
|
41
42
|
@subscribeTo @model, 'update', @onSourceUpdated
|
42
43
|
@subscribeTo @model, 'destroy', @onSourceDestroyed
|
@@ -45,6 +46,8 @@ Nali.extend View:
|
|
45
46
|
setTimeout ( => @onShow() ), 5 if @onShow?
|
46
47
|
@visible = true
|
47
48
|
@runModelCallback 'afterShow'
|
49
|
+
else
|
50
|
+
@draw()
|
48
51
|
@
|
49
52
|
|
50
53
|
hide: ( delay = 0 ) ->
|
@@ -105,7 +108,7 @@ Nali.extend View:
|
|
105
108
|
obj = if match[1].length is 1 then @ else @model
|
106
109
|
if obj[ method ]? and typeof obj[ method ] is 'function' then obj[ method ] params
|
107
110
|
else console.warn "Method %s not exists", method
|
108
|
-
else @
|
111
|
+
else @redirect url, params
|
109
112
|
@
|
110
113
|
|
111
114
|
formToHash: ( form ) ->
|
data/lib/nali/clients.rb
CHANGED
@@ -19,12 +19,13 @@ module Nali
|
|
19
19
|
if message[ :ping ]
|
20
20
|
client.send_json action: :pong
|
21
21
|
else
|
22
|
-
|
22
|
+
name = message[ :controller ].capitalize + 'Controller'
|
23
|
+
if Math.const_defined?( name ) and controller = Object.const_get( name )
|
23
24
|
controller = controller.new( client, message )
|
24
25
|
if controller.respond_to?( action = message[ :action ].to_sym )
|
25
26
|
controller.runAction action
|
26
27
|
else puts "Action #{ action } not exists in #{ controller }" end
|
27
|
-
else puts "Controller #{
|
28
|
+
else puts "Controller #{ name } not exists" end
|
28
29
|
on_message( client, message ) if respond_to?( :on_message )
|
29
30
|
end
|
30
31
|
end
|
@@ -36,4 +37,4 @@ module Nali
|
|
36
37
|
|
37
38
|
end
|
38
39
|
|
39
|
-
end
|
40
|
+
end
|
data/lib/nali/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nali
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-11-
|
12
|
+
date: 2014-11-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thin
|