tablets 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +42 -13
- data/Rakefile +1 -0
- data/app/assets/javascripts/tablets/details.js.coffee +3 -0
- data/app/assets/javascripts/tablets/navigation.js.coffee +5 -0
- data/app/assets/javascripts/tablets/store.js.coffee +5 -0
- data/app/assets/javascripts/tablets/tablet.js.coffee +14 -17
- data/app/views/tablets/_tablet.html.erb +1 -1
- data/lib/tablets/data/processing/base.rb +1 -1
- data/lib/tablets/data/processing/order.rb +2 -2
- data/lib/tablets/renderer.rb +2 -1
- data/lib/tablets/tablet.rb +10 -0
- data/lib/tablets/utils/config.rb +5 -0
- data/lib/tablets/version.rb +1 -1
- data/spec/lib/tablets/renderer_spec.rb +4 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 073682f3e75df008250ab8ec39352ed307eb797e
|
4
|
+
data.tar.gz: e811d153b45b6bce4396f9711aa45e2c039b6fea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0603710b65211af597d17c3015e6b175871f44c3d5d417f9560fe810c0c6c172e1bfe90d4472beb85e31d81d2e67902274a151a34210bbbd16a6362a429f511
|
7
|
+
data.tar.gz: 086fe45cd22de329a6fc4da74dcc5f273cccdd4e724380d15ff3e4c24e3d8457b0e59c848288f4dd7db1d38747fd31e99f0f38b445d0f8aafb214ff2fd2e0d50
|
data/README.md
CHANGED
@@ -1,33 +1,39 @@
|
|
1
1
|
# Tablets
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/tablets.svg)](http://badge.fury.io/rb/tablets)
|
4
|
+
|
3
5
|
## Installation
|
4
6
|
|
5
7
|
Add this line to your application's `Gemfile`:
|
6
8
|
|
7
|
-
```ruby
|
9
|
+
``` ruby
|
8
10
|
gem 'tablets'
|
9
11
|
```
|
10
12
|
|
11
13
|
Include tablets and jquery datatables scripts in your `app/assets/application.js`:
|
12
|
-
|
14
|
+
|
15
|
+
``` javascript
|
13
16
|
//= require dataTables/jquery.dataTables
|
14
17
|
//= require tablets
|
15
18
|
```
|
16
19
|
|
17
20
|
Include jquery datatables styles in your `app/assets/application.css`:
|
21
|
+
|
18
22
|
```
|
19
23
|
*= require dataTables/jquery.dataTables
|
20
24
|
```
|
21
25
|
|
22
26
|
Mount engine in `config/routes.rb`:
|
23
|
-
|
27
|
+
|
28
|
+
``` ruby
|
24
29
|
mount Tablets::Engine, at: '/tablets'
|
25
30
|
```
|
26
31
|
|
27
32
|
## Examples
|
28
33
|
|
29
34
|
In `app/tablets/posts.rb`:
|
30
|
-
|
35
|
+
|
36
|
+
``` ruby
|
31
37
|
Tablets.register :posts do
|
32
38
|
# Authorization logic.
|
33
39
|
authorize do |controller|
|
@@ -43,13 +49,14 @@ Tablets.register :posts do
|
|
43
49
|
columns do
|
44
50
|
[{
|
45
51
|
title: 'Title',
|
46
|
-
order: 'posts.title',
|
47
52
|
data: :title,
|
53
|
+
order: 'posts.title',
|
54
|
+
search: 'posts.title',
|
48
55
|
options: { className: 'post-title' }
|
49
56
|
}, {
|
50
57
|
title: 'User',
|
51
|
-
order: ['users.first_name', 'users.last_name'],
|
52
58
|
data: ->(user) { [user.first_name, user.last_name].compact.join(' ') },
|
59
|
+
order: ['users.first_name', 'users.last_name'],
|
53
60
|
search: ['users.first_name', 'users.last_name']
|
54
61
|
}]
|
55
62
|
end
|
@@ -72,19 +79,41 @@ Tablets.register :posts do
|
|
72
79
|
end
|
73
80
|
```
|
74
81
|
|
75
|
-
In `app/views/posts/index.html.erb
|
76
|
-
|
82
|
+
In `app/views/posts/index.html.erb`:
|
83
|
+
|
84
|
+
``` erb
|
77
85
|
<%= render_tablet :posts, user_id: current_user.id %>
|
78
86
|
```
|
79
87
|
|
80
|
-
|
88
|
+
In `app/assets/javascripts/posts.js`:
|
89
|
+
|
90
|
+
``` javascript
|
91
|
+
$('.tablet[name="posts"]').on('click', 'tbody > tr[role=row]', function() {
|
92
|
+
Tablets.toggleDetails($(this).closest('tr'));
|
93
|
+
});
|
94
|
+
|
95
|
+
```
|
96
|
+
|
97
|
+
Use `'.tablet.has-details'` for all tablets that has details.
|
98
|
+
|
99
|
+
## JavaScript callbacks
|
81
100
|
|
82
101
|
Called just before datatable initialization.
|
83
|
-
|
84
|
-
|
102
|
+
|
103
|
+
``` javascript
|
104
|
+
Tablets.Callbacks.beforeInit = function(element, options) {};
|
85
105
|
```
|
86
106
|
|
87
107
|
Called after datatable initialization.
|
88
|
-
|
89
|
-
|
108
|
+
|
109
|
+
``` javascript
|
110
|
+
Tablets.Callbacks.afterInit = function(table) {};
|
111
|
+
```
|
112
|
+
|
113
|
+
## JavaScript API
|
114
|
+
|
115
|
+
Open details for row.
|
116
|
+
|
117
|
+
``` javascript
|
118
|
+
Tablets.toggleDetails($tr);
|
90
119
|
```
|
data/Rakefile
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
class Tablets.Tablet
|
2
2
|
constructor: (@element, @options, @params) ->
|
3
3
|
@initTable()
|
4
|
-
|
4
|
+
|
5
|
+
Tablets.set(@element.attr('id'), this)
|
5
6
|
|
6
7
|
dataTableOptions: ->
|
7
8
|
$.extend {}, @options,
|
@@ -17,19 +18,15 @@ class Tablets.Tablet
|
|
17
18
|
|
18
19
|
Tablets.Callbacks.afterInit(@table)
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
row
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
if data
|
33
|
-
row.child("<span>#{data}</span>").show()
|
34
|
-
tr.addClass 'expanded'
|
35
|
-
tr.addClass 'shown'
|
21
|
+
toggleDetails: (tr) ->
|
22
|
+
row = @table.row tr
|
23
|
+
|
24
|
+
if row.child.isShown()
|
25
|
+
row.child.hide()
|
26
|
+
tr.removeClass 'expanded'
|
27
|
+
tr.removeClass 'shown'
|
28
|
+
else
|
29
|
+
data = row.data().details
|
30
|
+
row.child("<span>#{data}</span>").show()
|
31
|
+
tr.addClass 'expanded'
|
32
|
+
tr.addClass 'shown'
|
@@ -7,8 +7,8 @@ module Tablets
|
|
7
7
|
class Order < Tablets::Data::Processing::Base
|
8
8
|
# Applies order processing on relation.
|
9
9
|
def apply(relation)
|
10
|
-
params[:order].values.inject(relation) do |
|
11
|
-
|
10
|
+
params[:order].values.inject(relation) do |rel, item|
|
11
|
+
rel.order("#{column(item)} #{direction(item)}")
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
data/lib/tablets/renderer.rb
CHANGED
data/lib/tablets/tablet.rb
CHANGED
@@ -35,6 +35,11 @@ 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
|
+
|
38
43
|
# Returns columns definitions.
|
39
44
|
# Required.
|
40
45
|
def columns
|
@@ -49,6 +54,11 @@ module Tablets
|
|
49
54
|
|
50
55
|
private
|
51
56
|
|
57
|
+
# Checks if config has callback with specified name.
|
58
|
+
def has?(name)
|
59
|
+
@config.has?(name)
|
60
|
+
end
|
61
|
+
|
52
62
|
# Calls callback.
|
53
63
|
# Clarifies error message on error.
|
54
64
|
def call(callback, *params, &block)
|
data/lib/tablets/utils/config.rb
CHANGED
@@ -32,6 +32,11 @@ module Tablets
|
|
32
32
|
instance_eval(&block)
|
33
33
|
end
|
34
34
|
|
35
|
+
# Checks if value or callback is defined with specified name.
|
36
|
+
def has?(name)
|
37
|
+
@hash[name].present?
|
38
|
+
end
|
39
|
+
|
35
40
|
# Returns value.
|
36
41
|
# If no value defined, returns default.
|
37
42
|
# If no default raises ArgumentError.
|
data/lib/tablets/version.rb
CHANGED
@@ -49,7 +49,10 @@ RSpec.describe Tablets::Renderer do
|
|
49
49
|
|
50
50
|
before do
|
51
51
|
allow(tablet).to receive_messages(
|
52
|
-
name: tablet_name,
|
52
|
+
name: tablet_name,
|
53
|
+
columns: tablet_columns,
|
54
|
+
options: tablet_options,
|
55
|
+
details?: false
|
53
56
|
)
|
54
57
|
|
55
58
|
allow(Tablets::Engine).to receive_message_chain(
|
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.
|
4
|
+
version: 0.2.0
|
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-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -106,6 +106,9 @@ files:
|
|
106
106
|
- Rakefile
|
107
107
|
- app/assets/javascripts/tablets.js.coffee
|
108
108
|
- app/assets/javascripts/tablets/callbacks.js.coffee
|
109
|
+
- app/assets/javascripts/tablets/details.js.coffee
|
110
|
+
- app/assets/javascripts/tablets/navigation.js.coffee
|
111
|
+
- app/assets/javascripts/tablets/store.js.coffee
|
109
112
|
- app/assets/javascripts/tablets/tablet.js.coffee
|
110
113
|
- app/controllers/tablets/ajax_controller.rb
|
111
114
|
- app/views/tablets/_tablet.html.erb
|