ui_bibz 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +44 -0
- data/.travis.yml +13 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +171 -0
- data/MIT-LICENSE +20 -0
- data/README.md +728 -0
- data/README.rdoc +0 -0
- data/Rakefile +34 -0
- data/config/locales/en.yml +14 -0
- data/config/locales/fr.yml +14 -0
- data/doc/images/alert.png +0 -0
- data/doc/images/breadcrumb.png +0 -0
- data/doc/images/button.png +0 -0
- data/doc/images/button_dropdown.png +0 -0
- data/doc/images/button_group.png +0 -0
- data/doc/images/button_link.png +0 -0
- data/doc/images/button_split_dropdown.png +0 -0
- data/doc/images/glyph.png +0 -0
- data/doc/images/list.png +0 -0
- data/doc/images/nav.png +0 -0
- data/doc/images/panel.png +0 -0
- data/doc/images/table.png +0 -0
- data/doc/images/table_pagination_per_page.png +0 -0
- data/doc/images/table_panel.png +0 -0
- data/doc/images/table_search_field.png +0 -0
- data/doc/images/ui-bibz-logo-without-border.gif +0 -0
- data/doc/images/ui-bibz-logo.gif +0 -0
- data/lib/tasks/ui_bibz_tasks.rake +4 -0
- data/lib/ui_bibz/concerns/models/searchable.rb +93 -0
- data/lib/ui_bibz/helpers/meta_helper.rb +27 -0
- data/lib/ui_bibz/helpers/ui_helper.rb +108 -0
- data/lib/ui_bibz/helpers/utils_helper.rb +9 -0
- data/lib/ui_bibz/rails/engine.rb +39 -0
- data/lib/ui_bibz/ui/alert.rb +67 -0
- data/lib/ui_bibz/ui/breadcrumb/breadcrumb.rb +54 -0
- data/lib/ui_bibz/ui/breadcrumb/components/breadcrumb_link.rb +62 -0
- data/lib/ui_bibz/ui/button/button.rb +65 -0
- data/lib/ui_bibz/ui/button/button_dropdown.rb +56 -0
- data/lib/ui_bibz/ui/button/button_group.rb +62 -0
- data/lib/ui_bibz/ui/button/button_link.rb +66 -0
- data/lib/ui_bibz/ui/button/button_split_dropdown.rb +80 -0
- data/lib/ui_bibz/ui/component.rb +137 -0
- data/lib/ui_bibz/ui/dropdown/components/dropdown_list.rb +73 -0
- data/lib/ui_bibz/ui/dropdown/dropdown.rb +101 -0
- data/lib/ui_bibz/ui/glyph.rb +92 -0
- data/lib/ui_bibz/ui/grid/components/col.rb +74 -0
- data/lib/ui_bibz/ui/grid/components/row.rb +32 -0
- data/lib/ui_bibz/ui/grid/grid.rb +108 -0
- data/lib/ui_bibz/ui/jumbotron.rb +58 -0
- data/lib/ui_bibz/ui/label.rb +58 -0
- data/lib/ui_bibz/ui/list/components/list.rb +105 -0
- data/lib/ui_bibz/ui/list/list_group.rb +78 -0
- data/lib/ui_bibz/ui/nav/components/nav_link.rb +68 -0
- data/lib/ui_bibz/ui/nav/nav.rb +65 -0
- data/lib/ui_bibz/ui/panel.rb +101 -0
- data/lib/ui_bibz/ui/table/components/actions.rb +44 -0
- data/lib/ui_bibz/ui/table/components/column.rb +34 -0
- data/lib/ui_bibz/ui/table/components/columns.rb +16 -0
- data/lib/ui_bibz/ui/table/components/store.rb +67 -0
- data/lib/ui_bibz/ui/table/components/table_action.rb +21 -0
- data/lib/ui_bibz/ui/table/table.rb +146 -0
- data/lib/ui_bibz/ui/table/table_pagination.rb +29 -0
- data/lib/ui_bibz/ui/table/table_pagination_per_page.rb +53 -0
- data/lib/ui_bibz/ui/table/table_panel.rb +66 -0
- data/lib/ui_bibz/ui/table/table_search_field.rb +62 -0
- data/lib/ui_bibz/ui/table/ux/actionable.rb +59 -0
- data/lib/ui_bibz/ui/table/ux/paginable.rb +35 -0
- data/lib/ui_bibz/ui/table/ux/searchable.rb +47 -0
- data/lib/ui_bibz/ui/table/ux/sortable.rb +93 -0
- data/lib/ui_bibz/ui/ui.rb +14 -0
- data/lib/ui_bibz/utils/internationalization.rb +30 -0
- data/lib/ui_bibz/version.rb +3 -0
- data/lib/ui_bibz.rb +60 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/mailers/.keep +0 -0
- data/test/dummy/app/models/.keep +0 -0
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/models/user.rb +5 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +29 -0
- data/test/dummy/config/application.rb +26 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +41 -0
- data/test/dummy/config/environments/production.rb +79 -0
- data/test/dummy/config/environments/test.rb +42 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +57 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/migrate/20150123191721_user.rb +4 -0
- data/test/dummy/db/migrate/20150123191805_create_users.rb +12 -0
- data/test/dummy/db/schema.rb +25 -0
- data/test/dummy/lib/assets/.keep +0 -0
- data/test/dummy/log/.keep +0 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/test/fixtures/users.yml +13 -0
- data/test/dummy/test/models/user_test.rb +7 -0
- data/test/factories/user.rb +8 -0
- data/test/store_test.rb +46 -0
- data/test/support/factory_girl.rb +6 -0
- data/test/test_helper.rb +23 -0
- data/test/ui/button_test.rb +56 -0
- data/test/ui/component_test.rb +21 -0
- data/test/ui/dropdown_test.rb +18 -0
- data/test/ui/glyph_test.rb +23 -0
- data/test/ui/grid_test.rb +46 -0
- data/test/ui/list_group_test.rb +28 -0
- data/test/ui/nav_test.rb +27 -0
- data/test/ui/panel_test.rb +52 -0
- data/test/ui/table_test.rb +178 -0
- data/test/ui_bibz_test.rb +13 -0
- data/test/ui_helper_test.rb +44 -0
- data/ui_bibz.gemspec +36 -0
- data/vendor/assets/javascripts/ui_bibz.js.coffee +24 -0
- data/vendor/assets/stylesheets/ui_bibz.sass +46 -0
- metadata +398 -0
data/README.md
ADDED
@@ -0,0 +1,728 @@
|
|
1
|
+
![Ui Bibz logo](doc/images/ui-bibz-logo-without-border.gif)
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/thooams/Ui-Bibz.svg)](https://travis-ci.org/thooams/Ui-Bibz)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/thooams/Ui-Bibz/badges/gpa.svg)](https://codeclimate.com/github/thooams/Ui-Bibz)
|
5
|
+
[![Test Coverage](https://codeclimate.com/github/thooams/Ui-Bibz/badges/coverage.svg)](https://codeclimate.com/github/thooams/Ui-Bibz)
|
6
|
+
|
7
|
+
This project rocks and uses MIT-LICENSE.
|
8
|
+
|
9
|
+
# UiBibz
|
10
|
+
> Ui Bibz est un [framework d'interface](http://fr.wikipedia.org/wiki/Framework_d%27interface)
|
11
|
+
> permettant de construire une interface très rapidement et simplement
|
12
|
+
> à l'aide de Ruby on Rails 4 et de Boostrap 3.
|
13
|
+
|
14
|
+
Ui Bibz charge la librairie [boostrap](http://getbootstrap.com/) et
|
15
|
+
[awesomefont](http://fontawesome.io/).
|
16
|
+
|
17
|
+
**NB** : [HAML](http://haml.info/) est utilisé pour présenter les exemples de chaque élément.
|
18
|
+
Vous pouvez bien entendu utiliser l'interpréteur ERB dans votre application Rails.
|
19
|
+
|
20
|
+
Tous les composants du framework Ui Bibz comportent des *options* et des *html_options*.
|
21
|
+
Ces éléments sont basés sur l'élément ```Component```.
|
22
|
+
Un ```component``` accepte un contenu par variable ou par block.
|
23
|
+
ex :
|
24
|
+
|
25
|
+
### Component
|
26
|
+
|
27
|
+
|
28
|
+
L'élément ```component``` accepte dans content et block :
|
29
|
+
|
30
|
+
* le contenu
|
31
|
+
|
32
|
+
L'élément ```component``` accepte en option les arguments :
|
33
|
+
|
34
|
+
* [state](#state-values)
|
35
|
+
* [glyph](#glyph-arguments)
|
36
|
+
* [status](#status-values)
|
37
|
+
* class
|
38
|
+
|
39
|
+
|
40
|
+
L'élément ```component``` accepte en html_option les arguments :
|
41
|
+
|
42
|
+
* class
|
43
|
+
* data
|
44
|
+
* ...
|
45
|
+
|
46
|
+
Ex :
|
47
|
+
```ruby
|
48
|
+
Component.new 'Exemple', { state: :success }, { class: 'exemple' }
|
49
|
+
# ou
|
50
|
+
Component.new { state: :success }, { class: 'exemple' } do
|
51
|
+
'Exemple'
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
Signature :
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
Component.new content = nil, options = nil, html_options = nil, &block
|
59
|
+
```
|
60
|
+
|
61
|
+
**NB** : Pour des raisons de simplicité d'écriture, l'argument ```class``` est présent
|
62
|
+
dans ```options``` et ```html_options```.
|
63
|
+
|
64
|
+
|
65
|
+
## Installation
|
66
|
+
|
67
|
+
Ajouter la gem dans Rails :
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
gem "ui_bibz", '~> 0.9.0'
|
71
|
+
```
|
72
|
+
|
73
|
+
Lancer la command suivante :
|
74
|
+
|
75
|
+
```console
|
76
|
+
bundle install
|
77
|
+
```
|
78
|
+
|
79
|
+
Placer la ligne suivante dans ```/app/views/layouts/application.rb```
|
80
|
+
```ruby
|
81
|
+
= ui_bibz_meta_links
|
82
|
+
```
|
83
|
+
|
84
|
+
Exemple :
|
85
|
+
```ruby
|
86
|
+
!!!
|
87
|
+
%html
|
88
|
+
%head
|
89
|
+
...
|
90
|
+
= ui_bibz_meta_links
|
91
|
+
...
|
92
|
+
%body
|
93
|
+
```
|
94
|
+
|
95
|
+
|
96
|
+
## Utilisation
|
97
|
+
|
98
|
+
### Alert
|
99
|
+
|
100
|
+
![alert](doc/images/alert.png)
|
101
|
+
|
102
|
+
L'élément ```notify``` accepte en option les arguments :
|
103
|
+
|
104
|
+
* [state](#state-values)
|
105
|
+
* [glyph](#glyph-arguments)
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
= notify 'toto', state: :info, glyph: 'eye'
|
109
|
+
```
|
110
|
+
|
111
|
+
### Breadcrumb (fil d'ariane)
|
112
|
+
|
113
|
+
![breadcrumb](doc/images/breadcrumb.png)
|
114
|
+
|
115
|
+
L'élément ```breadcrumb``` accepte en option les arguments :
|
116
|
+
|
117
|
+
* [status](#status-values)
|
118
|
+
* [glyph](#glyph-arguments)
|
119
|
+
* url
|
120
|
+
|
121
|
+
L'élément ```link``` est un [component](#component).
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
= breadcrumb do |b|
|
125
|
+
- b.link 'toto', url: '#toto', glyph: 'home'
|
126
|
+
- b.link 'momo', url: '#momo'
|
127
|
+
- b.link 'nono', status: :active
|
128
|
+
```
|
129
|
+
|
130
|
+
### Buttons (Boutons)
|
131
|
+
|
132
|
+
#### Button
|
133
|
+
|
134
|
+
![button](doc/images/button.png)
|
135
|
+
|
136
|
+
L'élément ```button``` accepte en option les arguments :
|
137
|
+
|
138
|
+
* [state](#state-values)
|
139
|
+
* [status](#status-values)
|
140
|
+
* [glyph](#glyph-arguments)
|
141
|
+
* [size](#size-values)
|
142
|
+
|
143
|
+
```ruby
|
144
|
+
= button 'Button', { state: :danger, size: :xs, glyph: 'star' } , { class: 'my-button' }
|
145
|
+
```
|
146
|
+
|
147
|
+
#### Button Dropdown
|
148
|
+
|
149
|
+
L'élément ```button_dropdown``` accepte pour options les mêmes arguments que l'élément
|
150
|
+
[dropdown](#dropdown).
|
151
|
+
|
152
|
+
![button_link](doc/images/button_dropdown.png)
|
153
|
+
```ruby
|
154
|
+
= button_dropdown 'Button Dropdown' do |bd|
|
155
|
+
- bd.list link_to 'toto', '#'
|
156
|
+
- bd.list 'header', type: :header
|
157
|
+
- bd.list link_to 'momo', '#'
|
158
|
+
- bd.list '---'
|
159
|
+
- bd.list link_to 'lolo', '#'
|
160
|
+
```
|
161
|
+
|
162
|
+
#### Button group
|
163
|
+
|
164
|
+
![button_group](doc/images/button_group.png)
|
165
|
+
|
166
|
+
L'élément ```button_group``` accepte pour options les arguments :
|
167
|
+
|
168
|
+
* position (:vertical, :horizontal)
|
169
|
+
* [size](#size-values)
|
170
|
+
|
171
|
+
L'élément ```list```accepte pour options les arguments :
|
172
|
+
|
173
|
+
* [status](#status-values)
|
174
|
+
* [state](#state-values)
|
175
|
+
|
176
|
+
```ruby
|
177
|
+
= button_group position: :vertical, size: :xs do
|
178
|
+
= button 'toto', status: :active
|
179
|
+
= button 'momo'
|
180
|
+
= button 'lolo'
|
181
|
+
|
182
|
+
= button_group do
|
183
|
+
= button 'toto', status: :active
|
184
|
+
= button 'momo'
|
185
|
+
= button 'lolo'
|
186
|
+
= button_dropdown 'Button Dropdown' do |bd|
|
187
|
+
- bd.list 'header', type: :header
|
188
|
+
- bd.list link_to 'momo', '#'
|
189
|
+
- bd.list '---'
|
190
|
+
- bd.list link_to 'lolo', '#'
|
191
|
+
```
|
192
|
+
|
193
|
+
#### Button Link (Lien Bouton)
|
194
|
+
|
195
|
+
L'élément ```button_link```accepte pour options les arguments :
|
196
|
+
|
197
|
+
![button_link](doc/images/button_link.png)
|
198
|
+
```ruby
|
199
|
+
= button_link 'Button', { url: '#button', state: :primary, glyph: 'star' }, { class: 'my-button' }
|
200
|
+
```
|
201
|
+
|
202
|
+
#### Button Split Dropdown
|
203
|
+
|
204
|
+
L'élément ```button_split_dropdown```accepte pour options les mêmes arguments
|
205
|
+
que l'élément [dropdown](#dropdown).
|
206
|
+
|
207
|
+
|
208
|
+
![button_group](doc/images/button_split_dropdown.png)
|
209
|
+
```ruby
|
210
|
+
= button_split_dropdown 'Dropdown', state: :primary do |d|
|
211
|
+
- d.list do
|
212
|
+
= link_to 'toto', "#"
|
213
|
+
- d.list 'header', type: :header
|
214
|
+
- d.list link_to 'momo', '#'
|
215
|
+
- d.list '---'
|
216
|
+
- d.list link_to 'lolo', '#'
|
217
|
+
```
|
218
|
+
|
219
|
+
### Dropdown
|
220
|
+
|
221
|
+
L'élément ```dropdown```accepte pour options les arguments :
|
222
|
+
|
223
|
+
* [state](#state-values)
|
224
|
+
* [status](#status-values)
|
225
|
+
* position (:left, :right)
|
226
|
+
|
227
|
+
L'élément ```list``` est un [component](#component) qui accepte pour options les arguments :
|
228
|
+
|
229
|
+
* type (:header)
|
230
|
+
* [glyph](#glyph-arguments)
|
231
|
+
|
232
|
+
```ruby
|
233
|
+
= dropdown 'Dropdown', state: :success do |d|
|
234
|
+
- d.list do
|
235
|
+
= link_to 'toto', "#"
|
236
|
+
- d.list 'header', type: :header
|
237
|
+
- d.list link_to 'momo', '#'
|
238
|
+
- d.list '---'
|
239
|
+
- d.list link_to 'lolo', '#'
|
240
|
+
```
|
241
|
+
|
242
|
+
Pour ajouter une ligne séparatrice, il suffit d'insérer 3 "-" à la suite
|
243
|
+
ex :
|
244
|
+
```
|
245
|
+
...
|
246
|
+
d.list '--'
|
247
|
+
...
|
248
|
+
```
|
249
|
+
|
250
|
+
### Glyph
|
251
|
+
|
252
|
+
![glyph](doc/images/glyph.png)
|
253
|
+
|
254
|
+
Les glyphs utilisés proviennent de [Font Awesome](http://fontawesome.io/).
|
255
|
+
L'élément ```glyph``` accepte pour options les arguments :
|
256
|
+
|
257
|
+
* size
|
258
|
+
* type
|
259
|
+
|
260
|
+
```ruby
|
261
|
+
= glyph 'star', { size: 3, type: 'fw' }, class: 'star-exemple'
|
262
|
+
ou
|
263
|
+
= glyph { name: 'star', size: 3, type: 'fw' }
|
264
|
+
```
|
265
|
+
|
266
|
+
### Panel
|
267
|
+
|
268
|
+
![panel](doc/images/panel.png)
|
269
|
+
|
270
|
+
L'élément ```panel``` accepte pour options les arguments :
|
271
|
+
|
272
|
+
* [state](#state)
|
273
|
+
* tap (true) : permet de créer un header, body et footer
|
274
|
+
|
275
|
+
Les éléments ```header```, ```body```,```footer``` sont des éléments [component](#component).
|
276
|
+
Exemple :
|
277
|
+
|
278
|
+
```ruby
|
279
|
+
= panel 'danger'
|
280
|
+
# ou
|
281
|
+
= panel state: :danger do
|
282
|
+
= 'toto'
|
283
|
+
# ou
|
284
|
+
= panel({ tap: true, state: :danger }, { class: 'exemple' }) |p|
|
285
|
+
- p.header 'toto', glyph: 'eye'
|
286
|
+
- p.body class: 'my-body' do
|
287
|
+
= 'toto'
|
288
|
+
- p.footer 'toto'
|
289
|
+
```
|
290
|
+
|
291
|
+
### Table
|
292
|
+
|
293
|
+
![table](doc/images/table.png)
|
294
|
+
|
295
|
+
L'élément ```table``` est un tableau composé d'une recherche, une pagination et un trie de colonnes intégré.
|
296
|
+
Le tableau est compatible [I18n](http://guides.rubyonrails.org/i18n.html).
|
297
|
+
Le tableau contient pour chaque ligne un bouton dropdown action avec par défaut
|
298
|
+
ces 3 actions : voir, éditer, supprimer. Toute les colonnes sont présentent et
|
299
|
+
affichées par défaut.
|
300
|
+
|
301
|
+
La table doit contenir un store. Ce store est créé dans le controlleur avec la
|
302
|
+
méthode ```table_search_pagination```.
|
303
|
+
La méthode ```table_search_pagination``` contient 3 arguments :
|
304
|
+
|
305
|
+
* params
|
306
|
+
* session
|
307
|
+
* args (optionel)
|
308
|
+
|
309
|
+
Exemple :
|
310
|
+
```ruby
|
311
|
+
# app/controllers/document_controller.rb
|
312
|
+
@documents = Document.table_search_pagination(params, session)
|
313
|
+
```
|
314
|
+
|
315
|
+
Dans le model, insérer la méthode ```searchable_attributes``` afin de pouvoir
|
316
|
+
faire une recherche sur les attributs souhaités.
|
317
|
+
|
318
|
+
Exemple :
|
319
|
+
```ruby
|
320
|
+
# app/models/document.rb
|
321
|
+
searchable_attributes :name_fr, :name_en
|
322
|
+
```
|
323
|
+
|
324
|
+
Un champ recherche est disponible dans la vue :
|
325
|
+
![table_search_field](doc/images/table_search_field.png)
|
326
|
+
|
327
|
+
```ruby
|
328
|
+
= table_search_field store: @documents
|
329
|
+
```
|
330
|
+
|
331
|
+
Une pagination est disponible dans la vue :
|
332
|
+
|
333
|
+
```ruby
|
334
|
+
= table_pagination store: @documents
|
335
|
+
```
|
336
|
+
|
337
|
+
Un champs select par page est disponible dans la vue :
|
338
|
+
|
339
|
+
![table_search_field](doc/images/table_pagination_per_page.png)
|
340
|
+
|
341
|
+
```ruby
|
342
|
+
= table_pagination_per_page store: @documents
|
343
|
+
```
|
344
|
+
|
345
|
+
#### Simple Example table
|
346
|
+
|
347
|
+
Dans le **controlleur**, insérer la méthode ```table_search_pagination```.
|
348
|
+
La méthode ```table_search_pagination``` contient 3 arguments :
|
349
|
+
|
350
|
+
* params
|
351
|
+
* session
|
352
|
+
* args
|
353
|
+
|
354
|
+
Exemple :
|
355
|
+
```ruby
|
356
|
+
# app/controllers/document_controller.rb
|
357
|
+
@documents = Document.table_search_pagination(params, session)
|
358
|
+
```
|
359
|
+
|
360
|
+
Dans le **model**, insérer la méthode ```searchable_attributes``` afin de pouvoir
|
361
|
+
faire une recherche pour les attributs souhaités.
|
362
|
+
|
363
|
+
Exemple :
|
364
|
+
```ruby
|
365
|
+
# app/models/document.rb
|
366
|
+
searchable_attributes :name_fr, :name_en
|
367
|
+
```
|
368
|
+
|
369
|
+
Dans la **vue**, insérer la méthode ```table``` qui peut contenir plusieurs arguments :
|
370
|
+
|
371
|
+
* store (ex: @documents)
|
372
|
+
* paginable (true, false)
|
373
|
+
* sortable (true, false)
|
374
|
+
|
375
|
+
Une table comporte des **colonnes** et des **actions**.
|
376
|
+
|
377
|
+
Exemple :
|
378
|
+
```ruby
|
379
|
+
# app/views/documents/index.html.haml
|
380
|
+
= table store: @documents
|
381
|
+
```
|
382
|
+
|
383
|
+
Les actions par défauts peuvent être modifiées (voir exemple complexe) :
|
384
|
+
|
385
|
+
* edit
|
386
|
+
* view
|
387
|
+
* delete
|
388
|
+
|
389
|
+
Elles sont intégrées à l'intérieur d'un bouton [dropdown](#dropdown).
|
390
|
+
|
391
|
+
Exemple :
|
392
|
+
```ruby
|
393
|
+
# app/views/documents/index.html.haml
|
394
|
+
= table store: @documents do |g|
|
395
|
+
- g.actions do
|
396
|
+
= link_action 'Show', documents_path(:id), glyph: 'eye'
|
397
|
+
= link_action 'Edit', edit_document_path(:id), glyph: 'pencil'
|
398
|
+
= link_action 'Delete', documents_path(:id), method: :delete, glyph: 'trash', data: { confirm: 'Are you sure?' }
|
399
|
+
= link_action "---"
|
400
|
+
= link_action 'Duplicate', duplicate_document_path(:id), glyph: 'files-o'
|
401
|
+
= link_action 'Alert', alert_document_path(:id), glyph: 'bell'
|
402
|
+
```
|
403
|
+
|
404
|
+
L'ajout de colonnes à travers la méthode ```add``` contient plusieurs arguments :
|
405
|
+
|
406
|
+
* name (nom de la colonne)
|
407
|
+
* data_index (le nom de l'attribut)
|
408
|
+
* count (utilise la méthode count sur l'élément)
|
409
|
+
* date_format (formate l'affichage de la date en utilisant la méthode ```strftime``` ex: '%Y/%M/%D')
|
410
|
+
* format (formate les élements de la colone en utilisant **lambda**)
|
411
|
+
* link (ajoute un lien où l'expression ```:id``` est parsé et remplacé par l'entier correspondant)
|
412
|
+
* sort (permet de trier sur des champs )
|
413
|
+
* custom_sort (indique que le tableau sera triéé d'une manière personnalisée)
|
414
|
+
|
415
|
+
```ruby
|
416
|
+
# app/views/documents/index.html.haml
|
417
|
+
= table store: @documents do |g|
|
418
|
+
- g.columns do |c|
|
419
|
+
- c.add { name: '#', data_index: 'id' }
|
420
|
+
- c.add { name: 'Name fr', data_index: 'name_fr', link: edit_document_path(:id)}
|
421
|
+
- c.add { data_index: 'name_en' }
|
422
|
+
- c.add { name: 'Hotline', data_index: 'hotline_access', format: lambda{ |records, record| glyph(record.icon) }}
|
423
|
+
- c.add { name: 'Updated at', data_index: 'updated_at', date_format: '%Y' }
|
424
|
+
```
|
425
|
+
|
426
|
+
#### Complex Example table
|
427
|
+
|
428
|
+
Si on souhaite voir apparaître des liasions avec d'autres tables il faut pour
|
429
|
+
cela :
|
430
|
+
|
431
|
+
Dans le controlleur, insérer la méthode ```table_search_pagination``` en ajoutant
|
432
|
+
un ```includes``` juste avant.
|
433
|
+
|
434
|
+
Exemple :
|
435
|
+
```ruby
|
436
|
+
# app/controllers/document_controller.rb
|
437
|
+
@documents = Document.includes(:users).table_search_pagination(params, session)
|
438
|
+
```
|
439
|
+
|
440
|
+
Dans la vue, insérer la méthod ```table```.
|
441
|
+
NB: On peut créer ces propres méthodes comme ```user_name``` dans notre model "Document" et
|
442
|
+
l'utiliser dans le data_index.
|
443
|
+
|
444
|
+
```ruby
|
445
|
+
# app/views/documents/index.html.haml
|
446
|
+
= table store: @documents do |g|
|
447
|
+
- g.columns do |c|
|
448
|
+
- c.add { name: 'Users', data_index: 'user_name', sort: "user.name" }
|
449
|
+
```
|
450
|
+
|
451
|
+
|
452
|
+
#### Ultra Complex Example table
|
453
|
+
|
454
|
+
Si l'on souhaite, par exemple, dénombrer des utilisateurs qui ont un lien non
|
455
|
+
direct avec les documents.
|
456
|
+
Imaginons par exemple qu'un utilisateur à des produits et que
|
457
|
+
ces produits contiennent plusieurs documents. On souhaite compter le nombre
|
458
|
+
d'utilisateurs par document.
|
459
|
+
|
460
|
+
On peut ajouter des arguments dans la méthode ```table_search_pagination```
|
461
|
+
qui vont permettre de faire des jointures.
|
462
|
+
|
463
|
+
Exemple :
|
464
|
+
```ruby
|
465
|
+
# app/controllers/document_controller.rb
|
466
|
+
arguments = { sortable: {
|
467
|
+
column: 'users',
|
468
|
+
count: true,
|
469
|
+
joins: "LEFT OUTER JOIN documents_products ON documents_products.document_id = documents.id
|
470
|
+
LEFT OUTER JOIN products ON products.id = documents_products.product_id
|
471
|
+
LEFT OUTER JOIN products_users ON products_users.product_id = products.id
|
472
|
+
LEFT OUTER JOIN users ON users.id = products_users.user_id"
|
473
|
+
} }
|
474
|
+
|
475
|
+
@documents = Document.includes(:users).table_search_pagination(params, session,
|
476
|
+
arguments)
|
477
|
+
```
|
478
|
+
|
479
|
+
Ici l'argument sortable signifie que l'on souhaite s'interresser à la
|
480
|
+
fonctionnalité de trie.
|
481
|
+
Pour celà il faut :
|
482
|
+
|
483
|
+
* définir le nom de la colonne triéé à travers l'argument ```column:``` (string)
|
484
|
+
* définir si le traitement se fait sur le comptage avec l'argument ```count:```
|
485
|
+
(boolean)
|
486
|
+
* définir la jointure avec l'argument ```joins:``` (string, array, hash)
|
487
|
+
|
488
|
+
Dans la vue :
|
489
|
+
|
490
|
+
```ruby
|
491
|
+
# app/views/documents/index.html.haml
|
492
|
+
= table store: @documents do |g|
|
493
|
+
- g.columns do |c|
|
494
|
+
- c.add({ name: 'Users', data_index: 'users', count: true, custom_sort: true })
|
495
|
+
```
|
496
|
+
|
497
|
+
#### table I18n
|
498
|
+
|
499
|
+
La table est utilisable avec I18n. Les traductions
|
500
|
+
s'executent par ordre d'importance dans cet ordre précis pour la colonne "name_fr" par exemple.
|
501
|
+
|
502
|
+
1. ui_biz.table.headers.document.name_fr
|
503
|
+
2. ui_biz.table.headers.defaults.name_fr
|
504
|
+
3. activerecord.attributes.document.name_fr
|
505
|
+
4. activerecord.attributes.defaults.name_fr
|
506
|
+
|
507
|
+
Le placeholder du champ recherche est utilisable et traduisible avec les attributs activerecord dans le fichier locale.
|
508
|
+
|
509
|
+
Exemple :
|
510
|
+
|
511
|
+
```ruby
|
512
|
+
# config/locales/fr.yml
|
513
|
+
...
|
514
|
+
activerecord:
|
515
|
+
models:
|
516
|
+
user: 'Utilisateur'
|
517
|
+
attributes:
|
518
|
+
defaults:
|
519
|
+
name_fr: 'Nom fr'
|
520
|
+
...
|
521
|
+
```
|
522
|
+
|
523
|
+
### Table Panel
|
524
|
+
|
525
|
+
![table_panel](doc/images/table_panel.png)
|
526
|
+
|
527
|
+
Le composant ```table_panel``` est un tableau dans un panel.
|
528
|
+
|
529
|
+
```ruby
|
530
|
+
= table_panel store: @users
|
531
|
+
#ou
|
532
|
+
= table_panel({ store: @users, tap: true, glyph: 'home', state: :danger }) do |g|
|
533
|
+
- g.columns do |cls|
|
534
|
+
- cls.column name: '#', data_index: 'id'
|
535
|
+
- cls.column name: 'Username', data_index: 'username', link: edit_user_path(:id)
|
536
|
+
- cls.column name: 'Name', data_index: 'name'
|
537
|
+
- cls.column name: 'Email', data_index: 'email'
|
538
|
+
- cls.column name: 'Role', data_index: 'role_name', sort: 'roles.name'
|
539
|
+
- g.actions do |acs|
|
540
|
+
- acs.action 'Toto', url: edit_user_path(:id), glyph: 'pencil'
|
541
|
+
- acs.action "---"
|
542
|
+
- acs.action 'momo', url: user_path(:id), glyph: 'eye'
|
543
|
+
|
544
|
+
```
|
545
|
+
|
546
|
+
### List
|
547
|
+
|
548
|
+
![list](doc/images/list.png)
|
549
|
+
|
550
|
+
Par défaut une liste à pour tag ```<li>```. Mais elle peut se transformer en lien ```<a>```
|
551
|
+
à travers l'option ```type:```. Par défaut le tag ```<li>``` est présent.
|
552
|
+
|
553
|
+
```ruby
|
554
|
+
= list_group type: :link do |lg|
|
555
|
+
- lg.list 'Momo', { state: :success, glyph: 'home' }, { href: '#Momo' }
|
556
|
+
- lg.list({ tap: true, status: :active }, { href: '#Toto' }) do |l|
|
557
|
+
- l.header 'My title'
|
558
|
+
- l.body 'My title'
|
559
|
+
# ou
|
560
|
+
= list_group do |lg|
|
561
|
+
- lg.list 'Momo', glyph: 'home', badge: 2
|
562
|
+
- lg.list 'Toto'
|
563
|
+
```
|
564
|
+
|
565
|
+
### Nav
|
566
|
+
|
567
|
+
![nav](doc/images/nav.png)
|
568
|
+
|
569
|
+
Par défaut la navigation comporte des onglets "tab".
|
570
|
+
L'élément ```nav``` accepte en option les arguments :
|
571
|
+
|
572
|
+
* type (:pills, :tabs)
|
573
|
+
* position (:justified, :stacked)
|
574
|
+
* tap (true)
|
575
|
+
|
576
|
+
L'élement link est un [component](#component).
|
577
|
+
|
578
|
+
```ruby
|
579
|
+
= nav(type: :pills, position: :justified, tap: true) do |d|
|
580
|
+
d.link 'Test', url: '#test', badge: 6
|
581
|
+
d.link 'Test2', url: '#test2', status: :active
|
582
|
+
```
|
583
|
+
|
584
|
+
### Label
|
585
|
+
|
586
|
+
### Row
|
587
|
+
|
588
|
+
Le composant row génére une div avec la class row.
|
589
|
+
|
590
|
+
```ruby
|
591
|
+
= row class: 'toto' do
|
592
|
+
= content
|
593
|
+
# => <div class='row toto'>content</div>
|
594
|
+
```
|
595
|
+
|
596
|
+
### Col
|
597
|
+
|
598
|
+
L'élément ```col``` est un [composant](#composant) qui accèpte en arguments :
|
599
|
+
|
600
|
+
* num
|
601
|
+
* offset
|
602
|
+
* size
|
603
|
+
|
604
|
+
ou
|
605
|
+
|
606
|
+
* un tableau de hashes avec les arguments ```num```, ```offset``` et ```size``` à l'intérieur.
|
607
|
+
|
608
|
+
Ces paramètres génèrent les classes qui seront insérées dans la div avec la classe
|
609
|
+
col.
|
610
|
+
|
611
|
+
|
612
|
+
```ruby
|
613
|
+
= col({num: 2, size: :lg}, class: 'test') do
|
614
|
+
= content
|
615
|
+
|
616
|
+
# => <div class='col-lg-2 test'>content</div>
|
617
|
+
|
618
|
+
# ou
|
619
|
+
= col([{ offset: 1, size: :xs}, { num: 3}], class: 'test') do
|
620
|
+
= content
|
621
|
+
|
622
|
+
# => <div class='col-xs-offset-1 col-md-3 test'>content</div>
|
623
|
+
```
|
624
|
+
|
625
|
+
### Grid
|
626
|
+
|
627
|
+
Une grid est un composant qui est composé de 5 vues :
|
628
|
+
|
629
|
+
* top
|
630
|
+
* right
|
631
|
+
* bottom
|
632
|
+
* left
|
633
|
+
* center
|
634
|
+
|
635
|
+
La vue **center** est obligatoire.
|
636
|
+
Une vue à pour arguments :
|
637
|
+
|
638
|
+
* position (:top, :left, :bottom, :right, :center)
|
639
|
+
* num (1..12) 12 étant le nombre limite de colonnes utilisable dans boostrap.
|
640
|
+
|
641
|
+
L'argument ```position``` détermine la position de la vue et l'argument ```num``` determine
|
642
|
+
le nombre de colonnes occupées par la vue.
|
643
|
+
|
644
|
+
```ruby
|
645
|
+
= grid do |g|
|
646
|
+
- g.view num: 3, position: :left do
|
647
|
+
= list_group(type: :link) do |lg|
|
648
|
+
- lg.list 'Link 1', { url: '#link1' }
|
649
|
+
- lg.list 'Link 2', { url: '#link1', status: :active }
|
650
|
+
- lg.list 'Link 1', { url: '#link1' }
|
651
|
+
- lg.list 'Link 3', { url: '#link1' }
|
652
|
+
- lg.list 'Link 4', { url: '#link1' }
|
653
|
+
- g.view({ position: :top}) do
|
654
|
+
= button_group(type: :toolbar) do
|
655
|
+
= button 'option 1'
|
656
|
+
= button 'option 2'
|
657
|
+
= button 'option 3'
|
658
|
+
- g.view position: :center do
|
659
|
+
= table store: @users, type: :bordered
|
660
|
+
- g.view position: :bottom do
|
661
|
+
= 'bottom'
|
662
|
+
|
663
|
+
= grid do |g|
|
664
|
+
- g.view num: 5, position: :left do
|
665
|
+
= 'left'
|
666
|
+
- g.view position: :right do
|
667
|
+
= 'right'
|
668
|
+
- g.view({ position: :top}, { class: 'success'}) do
|
669
|
+
= 'top'
|
670
|
+
- g.view position: :center do
|
671
|
+
= 'center'
|
672
|
+
- g.view position: :bottom do
|
673
|
+
= 'bottom'
|
674
|
+
```
|
675
|
+
|
676
|
+
### Arguments and Values
|
677
|
+
|
678
|
+
#### Status values
|
679
|
+
* :active
|
680
|
+
* :disable
|
681
|
+
|
682
|
+
#### Size values
|
683
|
+
* :xs
|
684
|
+
* :sm
|
685
|
+
* :lg
|
686
|
+
|
687
|
+
#### State values
|
688
|
+
* :default
|
689
|
+
* :primary
|
690
|
+
* :info
|
691
|
+
* :success
|
692
|
+
* :warning
|
693
|
+
* :danger
|
694
|
+
|
695
|
+
#### Glyph arguments
|
696
|
+
* name
|
697
|
+
* size
|
698
|
+
* type
|
699
|
+
|
700
|
+
# Plus de détails
|
701
|
+
|
702
|
+
Pour plus d'informations, vous pouvez accéder à la documentation rdoc en
|
703
|
+
générant cette dernière :
|
704
|
+
|
705
|
+
```
|
706
|
+
rake rdoc
|
707
|
+
```
|
708
|
+
|
709
|
+
# Conflits
|
710
|
+
|
711
|
+
Certaines méthodes dans le helper peuvent être en conflit avec d'autres
|
712
|
+
librairies. Le cas échéant, vous pouvez utiliser directement la librairie UiBibz
|
713
|
+
comme ci-dessous.
|
714
|
+
|
715
|
+
Exemple :
|
716
|
+
|
717
|
+
```ruby
|
718
|
+
UiBibz::Ui::Panel.new('Exemple', { state: :success }, { class: 'exemple'}).render
|
719
|
+
# au lieu de
|
720
|
+
panel 'Exemple', { state: :success }, { class: 'exemple' }
|
721
|
+
```
|
722
|
+
|
723
|
+
# A faire :
|
724
|
+
|
725
|
+
* progress bar
|
726
|
+
* media
|
727
|
+
...
|
728
|
+
|
data/README.rdoc
ADDED
File without changes
|