tablets 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -0
- data/app/assets/javascripts/tablets/{navigation.js.coffee → api.js.coffee} +5 -0
- data/app/assets/javascripts/tablets/tablet.js.coffee +11 -1
- data/app/views/tablets/_tablet.html.erb +1 -1
- data/lib/tablets/data.rb +7 -2
- data/lib/tablets/renderer.rb +2 -3
- data/lib/tablets/tablet.rb +22 -12
- data/lib/tablets/version.rb +1 -1
- data/spec/lib/tablets/renderer_spec.rb +1 -1
- metadata +3 -4
- data/app/assets/javascripts/tablets/details.js.coffee +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ada28ad84ab6080afca26791721a0cc50a38ddbd
|
4
|
+
data.tar.gz: 545ad23ef11c304211f4095ca35956b9a38c3d44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fac271b7c4b42ef7f2e6098f5c5506da9e49ed275687480f1b7b692478ef28b2dc497b5b05db43096fb709a7267f4ee0a75cd80a81cd0a50e76d230d3bbcd189
|
7
|
+
data.tar.gz: 0096c9645613c4eea418b968a7e6b960ee806d32cad89c61839e8a64a8ea217573da00823a7b02813e7929c85c435b6ba9c251b8b45afdafa6a634405993f07d
|
data/README.md
CHANGED
@@ -29,6 +29,7 @@ Mount engine in `config/routes.rb`:
|
|
29
29
|
mount Tablets::Engine, at: '/tablets'
|
30
30
|
```
|
31
31
|
|
32
|
+
|
32
33
|
## Examples
|
33
34
|
|
34
35
|
In `app/tablets/posts.rb`:
|
@@ -95,6 +96,7 @@ $('.tablet[data-name="posts"]').on('click', 'tbody > tr[role=row]', function() {
|
|
95
96
|
|
96
97
|
Use `'.tablet.has-details'` for all tablets that has details.
|
97
98
|
|
99
|
+
|
98
100
|
## JavaScript API
|
99
101
|
|
100
102
|
Fields:
|
@@ -110,6 +112,11 @@ Open details for row.
|
|
110
112
|
Tablets.toggleDetails($tr);
|
111
113
|
```
|
112
114
|
|
115
|
+
Returns nearest tablet:
|
116
|
+
|
117
|
+
Tablets.tabletForElement($element);
|
118
|
+
|
119
|
+
|
113
120
|
### JavaScript callbacks
|
114
121
|
|
115
122
|
Callbacks called on tablet. You can use `this` to access tablet from callback.
|
@@ -1,5 +1,10 @@
|
|
1
1
|
$.extend Tablets,
|
2
|
+
reload_all: ->
|
3
|
+
for _id, tablet of @store
|
4
|
+
tablet.reload()
|
2
5
|
tabletId: ($element) ->
|
3
6
|
$element.closest('.tablet').attr('id')
|
4
7
|
tabletForElement: ($element) ->
|
5
8
|
Tablets.get(@tabletId($element))
|
9
|
+
toggleDetails: ($tr) ->
|
10
|
+
@tabletForElement($tr).toggleDetails($tr)
|
@@ -1,13 +1,16 @@
|
|
1
1
|
class Tablets.Tablet
|
2
2
|
constructor: (@element, @options, @params) ->
|
3
|
+
@initVars()
|
3
4
|
@initTable()
|
4
5
|
|
5
|
-
Tablets.set(@
|
6
|
+
Tablets.set(@id, this)
|
6
7
|
|
7
8
|
dataTableOptions: ->
|
8
9
|
$.extend {}, @options,
|
9
10
|
fnServerParams: (data) =>
|
10
11
|
data.params = @serverParams()
|
12
|
+
fnRowCallback: (row, data) =>
|
13
|
+
$(row).addClass('has-details') if data.details
|
11
14
|
|
12
15
|
serverParams: ->
|
13
16
|
params = $.extend({}, @params)
|
@@ -16,6 +19,10 @@ class Tablets.Tablet
|
|
16
19
|
|
17
20
|
params
|
18
21
|
|
22
|
+
initVars: ->
|
23
|
+
@id = @element.attr('id')
|
24
|
+
@name = @element.attr('data-name')
|
25
|
+
|
19
26
|
initTable: ->
|
20
27
|
options = @dataTableOptions()
|
21
28
|
|
@@ -25,6 +32,9 @@ class Tablets.Tablet
|
|
25
32
|
|
26
33
|
@trigger('afterInit')
|
27
34
|
|
35
|
+
reload: ->
|
36
|
+
@element.dataTable().fnDraw(false)
|
37
|
+
|
28
38
|
toggleDetails: (tr) ->
|
29
39
|
row = @table.row tr
|
30
40
|
|
data/lib/tablets/data.rb
CHANGED
@@ -41,9 +41,14 @@ module Tablets
|
|
41
41
|
# Also appends details.
|
42
42
|
def data
|
43
43
|
records.map do |record|
|
44
|
-
tablet.columns.map.with_index do |column, index|
|
44
|
+
data = tablet.columns.map.with_index do |column, index|
|
45
45
|
[index, cell(record, column)]
|
46
|
-
end.to_h
|
46
|
+
end.to_h
|
47
|
+
|
48
|
+
details = tablet.details(record)
|
49
|
+
data[:details] = details if details.present?
|
50
|
+
|
51
|
+
data
|
47
52
|
end
|
48
53
|
end
|
49
54
|
|
data/lib/tablets/renderer.rb
CHANGED
@@ -25,8 +25,7 @@ module Tablets
|
|
25
25
|
name: tablet.name,
|
26
26
|
columns: tablet.columns,
|
27
27
|
options: options,
|
28
|
-
params: params
|
29
|
-
has_details: tablet.details?
|
28
|
+
params: params
|
30
29
|
}
|
31
30
|
end
|
32
31
|
|
@@ -36,7 +35,7 @@ module Tablets
|
|
36
35
|
# renderer.id #=> 'posts_user_id_1'
|
37
36
|
#
|
38
37
|
def id
|
39
|
-
[tablet.name, params.to_a].flatten.map(&:to_s).join('_')
|
38
|
+
[tablet.name, params.to_a, 'tablet'].flatten.map(&:to_s).join('_')
|
40
39
|
end
|
41
40
|
|
42
41
|
# Calculates resulting options.
|
data/lib/tablets/tablet.rb
CHANGED
@@ -35,30 +35,40 @@ module Tablets
|
|
35
35
|
call(:details, record) { nil }
|
36
36
|
end
|
37
37
|
|
38
|
-
# Checks if details is defined.
|
39
|
-
def details?
|
40
|
-
has?(:details)
|
41
|
-
end
|
42
|
-
|
43
38
|
# Returns columns definitions.
|
44
|
-
#
|
39
|
+
# By default deduct columns from relation.
|
45
40
|
def columns
|
46
|
-
call(:columns)
|
41
|
+
call(:columns) { deduct_columns_from_relation }
|
47
42
|
end
|
48
43
|
|
49
44
|
# Returns database relation to fetch data.
|
50
|
-
#
|
51
|
-
def relation(params)
|
52
|
-
|
45
|
+
# By default tries to deduct class from tablet name.
|
46
|
+
def relation(params = {})
|
47
|
+
if defined? @name.camelize.constantize
|
48
|
+
call(:relation, params) { @name.camelize.constantize.where(nil) }
|
49
|
+
else
|
50
|
+
call(:relation, params)
|
51
|
+
end
|
53
52
|
end
|
54
53
|
|
55
|
-
private
|
56
|
-
|
57
54
|
# Checks if config has callback with specified name.
|
58
55
|
def has?(name)
|
59
56
|
@config.has?(name)
|
60
57
|
end
|
61
58
|
|
59
|
+
private
|
60
|
+
|
61
|
+
# Returns default columns definititions, deducted from relation.
|
62
|
+
def deduct_columns_from_relation
|
63
|
+
relation.columns.map(&:name).map do |name|
|
64
|
+
{
|
65
|
+
title: name.humanize.capitalize,
|
66
|
+
data: name.to_sym,
|
67
|
+
order: name
|
68
|
+
}
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
62
72
|
# Calls callback.
|
63
73
|
# Clarifies error message on error.
|
64
74
|
def call(callback, *params, &block)
|
data/lib/tablets/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tablets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yevhen Shemet
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -105,9 +105,8 @@ files:
|
|
105
105
|
- README.md
|
106
106
|
- Rakefile
|
107
107
|
- app/assets/javascripts/tablets.js.coffee
|
108
|
+
- app/assets/javascripts/tablets/api.js.coffee
|
108
109
|
- app/assets/javascripts/tablets/callbacks.js.coffee
|
109
|
-
- app/assets/javascripts/tablets/details.js.coffee
|
110
|
-
- app/assets/javascripts/tablets/navigation.js.coffee
|
111
110
|
- app/assets/javascripts/tablets/store.js.coffee
|
112
111
|
- app/assets/javascripts/tablets/tablet.js.coffee
|
113
112
|
- app/controllers/tablets/ajax_controller.rb
|