pinkman 1.3.7 → 1.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/pinkman_base/collection.coffee +36 -15
- data/app/assets/javascripts/pinkman_base/controller.coffee +16 -2
- data/app/assets/javascripts/pinkman_base/pinkman.coffee +6 -0
- data/app/assets/javascripts/pinkman_base/router.coffee +1 -1
- data/lib/pinkman/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 291782b4b04a02a359d5cecaccf2c67b3c4d2c3f2b269e6bb607d949e6ecd180
|
4
|
+
data.tar.gz: 58a64ecaf2dab1df27e8d1d3d07563efcec47cd7e318fc38b2b9c52302cdecc4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 609f4254349dbcc6b21a164d7cfd4c998d92daa64df054ea20318f977feaa759bb0a128627c1f2eb6070a7dea2d4eb837e5d6a368ec43135185e2e416203a3ee
|
7
|
+
data.tar.gz: 3715ca1976c898dc5bd8151dc954ab9bb453ff99e224fd7b158ebdbad99ebda66238a3251b8f58145a29ec9e5af88192be2c953e1067b669fbb2878cfa6bd3c6
|
@@ -94,6 +94,18 @@ class window.PinkmanCollection extends window.PinkmanCommon
|
|
94
94
|
transformation(o)
|
95
95
|
callback(this) if (i == @count()) and typeof callback == 'function'
|
96
96
|
return this
|
97
|
+
|
98
|
+
# rails/ruby equivalent: map
|
99
|
+
# Desc: receive a function and apply it to all members and returns an array of values
|
100
|
+
map: (transformation='',callback) ->
|
101
|
+
array = []
|
102
|
+
if transformation? and typeof transformation=='function'
|
103
|
+
i = 0
|
104
|
+
for o in @collection
|
105
|
+
i = i+1
|
106
|
+
array.push(transformation(o))
|
107
|
+
callback(array) if (i == @count()) and typeof callback == 'function'
|
108
|
+
return array
|
97
109
|
|
98
110
|
# rails/ruby equivalent: where/select
|
99
111
|
# Desc: returns a new collection of all members that satisfies a criteria (criteria(obj) returns true)
|
@@ -519,10 +531,23 @@ class window.PinkmanCollection extends window.PinkmanCommon
|
|
519
531
|
|
520
532
|
# --- Cache Related --- #
|
521
533
|
|
534
|
+
@mangleKey: (key) ->
|
535
|
+
@startCaching() unless @_name_md5
|
536
|
+
@_name_md5 + key
|
537
|
+
|
538
|
+
@cache: (key, value) ->
|
539
|
+
$c.cache(@mangleKey(key), value)
|
540
|
+
|
541
|
+
@hasCache: (key) ->
|
542
|
+
$c.has(@mangleKey(key))
|
543
|
+
|
544
|
+
@getCache: (key, callback) ->
|
545
|
+
$c.get(@mangleKey(key), callback)
|
546
|
+
|
522
547
|
@startCaching: () ->
|
523
548
|
# cache structure
|
524
549
|
@_name_md5 = md5(if @name then @name else @toString()) unless @_name_md5?
|
525
|
-
$c.cache(@_name_md5, new this) unless $c.has(@_name_md5)
|
550
|
+
# $c.cache(@_name_md5, new this) unless $c.has(@_name_md5)
|
526
551
|
|
527
552
|
# --- Ajax related --- #
|
528
553
|
|
@@ -542,25 +567,23 @@ class window.PinkmanCollection extends window.PinkmanCommon
|
|
542
567
|
|
543
568
|
@get: (options) ->
|
544
569
|
if $p.isObject(options) and (options.query? or options.params?) and $p.isFunction(options.callback)
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
if options.cache and $c.has(query_md5)
|
550
|
-
$c.get(query_md5, options.callback)
|
570
|
+
options.cache = false unless options.cache?
|
571
|
+
query_md5 = $p.objHash(options)
|
572
|
+
if options.cache and @hasCache(query_md5)
|
573
|
+
@getCache(query_md5, options.callback)
|
551
574
|
else
|
552
575
|
col = new this
|
553
576
|
obj = new col.config.memberClass
|
554
577
|
params = new Object
|
555
578
|
params.scope = options.scope || Pinkman.scope(obj)
|
556
579
|
params.query = options.query
|
557
|
-
params =
|
558
|
-
|
580
|
+
params = $p.mergeObjects(params, options.params)
|
581
|
+
$p.ajax.get
|
559
582
|
url: options.url || obj.api('get')
|
560
583
|
data: params
|
561
584
|
complete: (response) =>
|
562
585
|
col.fetchFromArray(response)
|
563
|
-
|
586
|
+
@cache(query_md5, col)
|
564
587
|
options.callback(col)
|
565
588
|
else
|
566
589
|
throw "Pinkman Error: collection.get invalid options #{options.toString()}"
|
@@ -622,7 +645,6 @@ class window.PinkmanCollection extends window.PinkmanCommon
|
|
622
645
|
if options? and typeof options == 'object' and options.url?
|
623
646
|
options_md5 = md5(JSON.stringify(options) + @className())
|
624
647
|
options.params = new Object unless options.params?
|
625
|
-
options.cache = yes unless options.cache?
|
626
648
|
if options.scope?
|
627
649
|
options.params.scope = options.scope
|
628
650
|
else
|
@@ -633,12 +655,11 @@ class window.PinkmanCollection extends window.PinkmanCommon
|
|
633
655
|
Pinkman.ajax.get
|
634
656
|
url: Pinkman.json2url(options.url, options.params)
|
635
657
|
complete: (response) =>
|
636
|
-
$c.cache(options_md5, response) if options.cache
|
637
658
|
@handleFetchResponse(response, options)
|
638
659
|
return(this)
|
639
660
|
|
640
|
-
handleFetchResponse: (response,options) ->
|
641
|
-
@constructor.startCaching()
|
661
|
+
handleFetchResponse: (response, options) ->
|
662
|
+
# @constructor.startCaching()
|
642
663
|
if response?
|
643
664
|
[@errors, @error] = [response.errors, response.error] if response.errors? or response.error?
|
644
665
|
|
@@ -652,7 +673,7 @@ class window.PinkmanCollection extends window.PinkmanCommon
|
|
652
673
|
|
653
674
|
if response.length > 0
|
654
675
|
# CACHING INSTANCES
|
655
|
-
$c.get(@constructor._name_md5).fetchFromArray(response)
|
676
|
+
# $c.get(@constructor._name_md5).fetchFromArray(response)
|
656
677
|
|
657
678
|
@_recent.fetchFromArray(response)
|
658
679
|
@fetchFromArray(response)
|
@@ -72,13 +72,14 @@ class window.PinkmanController extends window.PinkmanObject
|
|
72
72
|
if args.length == 1
|
73
73
|
@actions.getBy('name',args[0])
|
74
74
|
else
|
75
|
-
[name, eventName,callback,unknown...] = args
|
75
|
+
[name, eventName, callback, preventDefault, unknown...] = args
|
76
76
|
PinkmanAction.define
|
77
77
|
id: "#{@pinkey}-#{name}-#{eventName}"
|
78
78
|
name: name
|
79
79
|
eventName: eventName
|
80
80
|
callback: callback
|
81
81
|
controller: this
|
82
|
+
preventDefault: if preventDefault? then preventDefault else true
|
82
83
|
selector: "##{this.id} [data-action='#{name}']"
|
83
84
|
|
84
85
|
|
@@ -406,6 +407,11 @@ class window.PinkmanAction extends window.PinkmanObject
|
|
406
407
|
a.set 'controller', options.controller
|
407
408
|
a.set 'selector', options.selector
|
408
409
|
a.set 'eventName', options.eventName
|
410
|
+
|
411
|
+
# default value for preventDefault: yes
|
412
|
+
# console.log options.preventDefault
|
413
|
+
a.set 'preventDefault', options.preventDefault
|
414
|
+
|
409
415
|
# a.log 'eventName'
|
410
416
|
a.set 'call', options.callback if options.callback
|
411
417
|
Pinkman.actions.push(a)
|
@@ -455,7 +461,15 @@ class window.PinkmanAction extends window.PinkmanObject
|
|
455
461
|
$('body').on eventName, action.selector, (ev) ->
|
456
462
|
# debugger
|
457
463
|
# console.log "#{action.id}: called - #{action.name}"
|
458
|
-
|
464
|
+
|
465
|
+
ev.preventDefault() if (eventName != 'keypress' and eventName != 'mousedown') and action.preventDefault
|
466
|
+
# debug mode
|
467
|
+
# if (eventName != 'keypress' and eventName != 'mousedown') and action.preventDefault
|
468
|
+
# console.log 'chamou prevent default'
|
469
|
+
# ev.preventDefault()
|
470
|
+
# else
|
471
|
+
# console.log 'não chamou prevent default'
|
472
|
+
|
459
473
|
obj = window.Pinkman.closest($(this))
|
460
474
|
action.call(obj,$(this),ev)
|
461
475
|
|
data/lib/pinkman/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pinkman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3
|
4
|
+
version: 1.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Agilso Oliveira
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -322,7 +322,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
322
322
|
- !ruby/object:Gem::Version
|
323
323
|
version: '0'
|
324
324
|
requirements: []
|
325
|
-
rubygems_version: 3.0.
|
325
|
+
rubygems_version: 3.0.6
|
326
326
|
signing_key:
|
327
327
|
specification_version: 4
|
328
328
|
summary: Small Rails-js framework.
|