rich_table_component 0.0.1
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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +470 -0
- data/Rakefile +1 -0
- data/lib/rich_table_component/version.rb +3 -0
- data/lib/rich_table_component.rb +622 -0
- data/rich_table_component.gemspec +36 -0
- metadata +294 -0
@@ -0,0 +1,622 @@
|
|
1
|
+
require "rich_table_component/version"
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
require 'sass-rails'
|
5
|
+
require 'less-rails'
|
6
|
+
require 'haml-rails'
|
7
|
+
require 'cancan'
|
8
|
+
require 'paperclip'
|
9
|
+
require 'ckeditor'
|
10
|
+
require 'ransack'
|
11
|
+
require 'squeel'
|
12
|
+
require 'simple_form'
|
13
|
+
require 'redis'
|
14
|
+
require 'will_paginate'
|
15
|
+
require 'wicked_pdf'
|
16
|
+
require 'simple_form'
|
17
|
+
require 'compass-rails'
|
18
|
+
require 'twitter-bootstrap-rails'
|
19
|
+
|
20
|
+
require 'will_paginate/view_helpers/link_renderer'
|
21
|
+
require 'will_paginate/view_helpers/action_view'
|
22
|
+
require 'pagination_list_link_renderer'
|
23
|
+
|
24
|
+
module RichTableComponent
|
25
|
+
def self.ipsum
|
26
|
+
"Lorem ipsum dolor sit amet, consectetur adipisicing vicerus luctum ...."
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.included(base)
|
30
|
+
base.extend(ClassMethods)
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
## Define ControllerMethods
|
37
|
+
module Controller
|
38
|
+
## this one manages the usual self.included, klass_eval stuff
|
39
|
+
extend ActiveSupport::Concern
|
40
|
+
|
41
|
+
included do
|
42
|
+
helper_method :sort_column, :sort_direction
|
43
|
+
end
|
44
|
+
|
45
|
+
module InstanceMethods
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
# Removes leading and trailing whitespace from ransack search params
|
55
|
+
def strip_search_param
|
56
|
+
case params[:q]
|
57
|
+
when String
|
58
|
+
params[:q].strip!
|
59
|
+
when Hash
|
60
|
+
params[:q].each_pair{|k, v| params[:q][k] = v.strip}
|
61
|
+
else
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Define default order by column
|
66
|
+
# ralibi
|
67
|
+
def default_sort
|
68
|
+
@default_sort ||= "created_at"
|
69
|
+
end
|
70
|
+
|
71
|
+
# Set sorting direction for table grid
|
72
|
+
# ralibi
|
73
|
+
def sort_direction
|
74
|
+
%w[asc desc].include?(params[:direction]) ? params[:direction] : (@sort_direction ||= "desc")
|
75
|
+
end
|
76
|
+
|
77
|
+
# Set table relation for table grid
|
78
|
+
# ralibi
|
79
|
+
def sort_relation
|
80
|
+
params[:relation] || nil
|
81
|
+
end
|
82
|
+
|
83
|
+
# Formulate order by column string. Also handling column from related table
|
84
|
+
# ralibi
|
85
|
+
def sort_column(mdl = nil)
|
86
|
+
if mdl.nil?
|
87
|
+
params[:sort] || default_sort
|
88
|
+
else
|
89
|
+
sort_relation ? (params[:sort] || default_sort) : (mdl.column_names.include?(params[:sort]) ? params[:sort] : default_sort)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# The result from Rich Table Component manipulation
|
94
|
+
def rich_table_component(relation = {}, _sort_column = {}, _sort_direction = nil, pagination = true)
|
95
|
+
case relation
|
96
|
+
when Hash
|
97
|
+
_sort_column = relation[:sort_column]
|
98
|
+
_sort_direction = relation[:sort_direction]
|
99
|
+
pagination = relation[:pagination] == false ? false : true
|
100
|
+
relation = relation[:relation]
|
101
|
+
_association_records_count = [relation[:association_records_count]].compact.flatten.collect(&:to_s)
|
102
|
+
else
|
103
|
+
_association_records_count = nil
|
104
|
+
case _sort_column
|
105
|
+
when Hash
|
106
|
+
_sort_direction = _sort_column[:sort_direction]
|
107
|
+
pagination = _sort_column[:pagination] == false ? false : true
|
108
|
+
_association_records_count = [_sort_column[:association_records_count]].compact.flatten.collect(&:to_s)
|
109
|
+
_sort_column = _sort_column[:sort_column]
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
pagination = false if ['application/pdf', 'application/xls'].include? request.format.to_s
|
114
|
+
|
115
|
+
@default_sort = _sort_column.presence || nil
|
116
|
+
@sort_direction = _sort_direction
|
117
|
+
sort = sort_column
|
118
|
+
direction = sort_direction
|
119
|
+
_relation_table_name = relation.respond_to?('klass') ? relation.klass.name.tableize : relation.name.tableize
|
120
|
+
@default_sort = nil
|
121
|
+
@sort_direction = nil
|
122
|
+
|
123
|
+
order_table_name = _relation_table_name
|
124
|
+
|
125
|
+
if params[:sort_relation].present?
|
126
|
+
splitter = params[:sort_relation].index('__').present? ? params[:sort_relation].split('__') : params[:sort_relation].split('.')
|
127
|
+
order_table_name = splitter.last.try(:tableize).presence || _relation_table_name
|
128
|
+
relation = relation.joins{splitter.inject((splitter.present? ? self : nil), :__send__).outer}
|
129
|
+
elsif sort.index('.').present?
|
130
|
+
splitter = sort.split('.')
|
131
|
+
sort = splitter.pop
|
132
|
+
order_table_name = splitter.last.try(:tableize).presence || _relation_table_name
|
133
|
+
relation = relation.joins{splitter.inject((splitter.present? ? self : nil), :__send__).outer}
|
134
|
+
end
|
135
|
+
|
136
|
+
if _association_records_count.present? && _association_records_count.map{|m| "number_of_" + m}.include?(sort)
|
137
|
+
index_arc = _association_records_count.map{|m| "number_of_" + m}.index(sort)
|
138
|
+
relation = relation.joins{[_association_records_count[index_arc]].inject(([_association_records_count[index_arc]].present? ? self : nil), :__send__).outer}.select("#{_relation_table_name}.*, COUNT(#{_association_records_count[index_arc]}.id) number_of_#{_association_records_count[index_arc]}")
|
139
|
+
relation = relation.order("#{sort} #{direction}")
|
140
|
+
else
|
141
|
+
relation = relation.order("#{order_table_name}.#{sort} #{direction}")
|
142
|
+
end
|
143
|
+
|
144
|
+
if pagination
|
145
|
+
params[:page] ||= 1
|
146
|
+
params[:per_page] ||= WillPaginate.per_page
|
147
|
+
relation = relation.page(params[:page].to_i).per_page(params[:per_page].to_i)
|
148
|
+
end
|
149
|
+
|
150
|
+
relation = relation.group("#{_relation_table_name}.id")
|
151
|
+
relation
|
152
|
+
end
|
153
|
+
|
154
|
+
# Saving object with document by Jquery File Upload
|
155
|
+
# document assigned with id from att_from_obj
|
156
|
+
def save_documents_with_attached_from(doc_ids, att_from_obj)
|
157
|
+
if doc_ids.present?
|
158
|
+
doc_ids.collect(&:to_i).each do |document_id|
|
159
|
+
document = Document.find(document_id)
|
160
|
+
document.attached_from_id = att_from_obj.id
|
161
|
+
document.document_type = att_from_obj.class.name.tableize.singularize
|
162
|
+
document.save
|
163
|
+
end
|
164
|
+
end
|
165
|
+
@document = Document.new
|
166
|
+
end
|
167
|
+
|
168
|
+
# Just providing object document
|
169
|
+
# call this method in object that has many documents
|
170
|
+
def init_document_upload
|
171
|
+
@document = Document.new
|
172
|
+
end
|
173
|
+
|
174
|
+
|
175
|
+
# Group methods for recapitulation
|
176
|
+
# -------------------------------
|
177
|
+
def get_group_db(splitter, splitter_attr, splitter_time, group_attr, join_model, recapitulation_model)
|
178
|
+
group_db = [splitter.last.try('tableize'), group_attr].compact.join('.')
|
179
|
+
group_db = (group_db.split('.').length > 1) ? group_db : [recapitulation_model.to_s.tableize, group_db].join('.')
|
180
|
+
|
181
|
+
if splitter_time.present?
|
182
|
+
case join_model.columns_hash[group_attr].type
|
183
|
+
when :date
|
184
|
+
old_since = splitter_time[2].eql?('old') ? "#{splitter_time[1]}(curdate()) - " : ""
|
185
|
+
group_db = "(#{old_since}#{splitter_time[1]}(#{group_attr}))"
|
186
|
+
if splitter_time[3].presence
|
187
|
+
group_db = "(floor((#{group_db}) / #{splitter_time[3].to_i}))"
|
188
|
+
end
|
189
|
+
when :datetime
|
190
|
+
old_since = splitter_time[2].eql?('old') ? "{splitter_time[1]}(curdate()) - " : ""
|
191
|
+
group_db = "(#{old_since}#{splitter_time[1]}(#{group_attr}))"
|
192
|
+
else
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
group_db
|
197
|
+
end
|
198
|
+
|
199
|
+
def get_as_group_db(group_db)
|
200
|
+
as_group_db = "#{group_db.to_s.gsub('.', '__')}"
|
201
|
+
as_group_db = 'datetime_calculation' if as_group_db.index('curdate').present? || as_group_db.index('year(').present?
|
202
|
+
as_group_db
|
203
|
+
end
|
204
|
+
|
205
|
+
def on_operation?
|
206
|
+
params[:operation_value].present? && params[:operation_type].present?
|
207
|
+
end
|
208
|
+
|
209
|
+
def two_dimension?
|
210
|
+
params[:group_row].present? && params[:group_col].present?
|
211
|
+
end
|
212
|
+
|
213
|
+
def get_group_data(str_param, recapitulation_model)
|
214
|
+
splitter_attr = str_param.split('__')
|
215
|
+
|
216
|
+
splitter = splitter_attr.first.split('.')
|
217
|
+
splitter_time = splitter_attr.find{|f| f.first(5).eql?('time.')}.try('split', '.')
|
218
|
+
group = splitter.pop
|
219
|
+
join_model = splitter.present? ? splitter.last.classify.constantize : recapitulation_model
|
220
|
+
group_attr = join_model.columns_hash[group].present? ? group : group + '_id'
|
221
|
+
group_db = get_group_db(splitter, splitter_attr, splitter_time, group_attr, join_model, recapitulation_model)
|
222
|
+
splitter_mapping = splitter_attr.find{|f| f.first(8).eql?('mapping.')}.try('split', '.')
|
223
|
+
|
224
|
+
{
|
225
|
+
splitter_attr: splitter_attr,
|
226
|
+
splitter: splitter,
|
227
|
+
splitter_time: splitter_time,
|
228
|
+
group: group,
|
229
|
+
join_model: join_model,
|
230
|
+
group_attr: group_attr,
|
231
|
+
group_db: group_db,
|
232
|
+
splitter_mapping: splitter_mapping,
|
233
|
+
is_id: group_attr.last(3).eql?('_id')
|
234
|
+
}
|
235
|
+
end
|
236
|
+
|
237
|
+
def get_label_record(group_data, join_table, as_group_db)
|
238
|
+
group_data[:is_id] ? group_data[:group].tableize.classify.constantize.where{id.in(join_table.select(group_data[:group_db]).order(group_data[:group_db].to_s + ' ASC').uniq.to_a.collect(&(group_data[:group_attr]).to_sym))} : join_table.select(group_data[:group_db] + ' AS ' + as_group_db).order(as_group_db + ' ASC').uniq
|
239
|
+
end
|
240
|
+
|
241
|
+
def get_label_range(group_data, labels)
|
242
|
+
if group_data[:splitter_time].present? && group_data[:splitter_time].try('fourth').present?
|
243
|
+
lri = labels.to_i
|
244
|
+
spli = group_data[:splitter_time][3].to_i
|
245
|
+
"#{lri * spli} - #{(lri * spli) + spli - 1}"
|
246
|
+
else
|
247
|
+
labels
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
def get_label_item(group_data, record, as_group_db)
|
252
|
+
label_item = ((group_data[:is_id] ? record.to_s : record.try(as_group_db)).to_s.presence || t('unknown'))
|
253
|
+
|
254
|
+
# label row for range value like age old or date since
|
255
|
+
label_item = get_label_range(group_data, label_item)
|
256
|
+
|
257
|
+
# row mapping
|
258
|
+
if group_data[:splitter_mapping].present?
|
259
|
+
idx = group_data[:splitter_mapping].index(label_item)
|
260
|
+
label_item = group_data[:splitter_mapping][idx + 1].presence || label_item if idx.present?
|
261
|
+
end
|
262
|
+
|
263
|
+
label_item
|
264
|
+
end
|
265
|
+
|
266
|
+
|
267
|
+
def generate_recapitulation
|
268
|
+
if params[:group_row].present? || params[:group_col].present?
|
269
|
+
generate_recapitulation_start
|
270
|
+
else
|
271
|
+
@recapitulation_error = {message: 'Pilih baris atau kolom terlebih dahulu'}
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
def generate_recapitulation_start
|
276
|
+
recapitulation_model = (params[:rtc_controller_name].presence || controller_name).classify.constantize
|
277
|
+
|
278
|
+
|
279
|
+
# DATA FETCHING
|
280
|
+
# ----------------------------------------------------------------------------------------------------
|
281
|
+
# ----------------------------------------------------------------------------------------------------
|
282
|
+
|
283
|
+
# ROW section
|
284
|
+
gd_row = get_group_data(params[:group_row].presence || params[:group_col], recapitulation_model)
|
285
|
+
|
286
|
+
|
287
|
+
if two_dimension?
|
288
|
+
# COL section
|
289
|
+
gd_col = get_group_data(params[:group_col], recapitulation_model)
|
290
|
+
else
|
291
|
+
gd_col = {splitter: []}
|
292
|
+
end
|
293
|
+
|
294
|
+
|
295
|
+
q_join_table = recapitulation_model
|
296
|
+
.joins{gd_row[:splitter].inject((gd_row[:splitter].present? ? self : nil), :__send__)}
|
297
|
+
.joins{gd_col[:splitter].inject((gd_col[:splitter].present? ? self : nil), :__send__)}
|
298
|
+
|
299
|
+
|
300
|
+
@q = q_join_table.search(params[:q])
|
301
|
+
join_table = @q.result
|
302
|
+
|
303
|
+
# executing query for counting record
|
304
|
+
recapitulations = join_table.count(group: [gd_row[:group_db], gd_col[:group_db]].compact)
|
305
|
+
|
306
|
+
|
307
|
+
# executing query for value
|
308
|
+
if on_operation?
|
309
|
+
recapitulations_operation = nil
|
310
|
+
|
311
|
+
# contruct operation_value
|
312
|
+
gd_ov = get_group_data(params[:operation_value], recapitulation_model)
|
313
|
+
|
314
|
+
recapitulations_operation = join_table.sum(gd_ov[:group_db], group: [gd_row[:group_db], gd_col[:group_db]].compact)
|
315
|
+
end
|
316
|
+
|
317
|
+
# END DATA FETCHING
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
# in between
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
|
328
|
+
@label_col = []
|
329
|
+
@label_row = []
|
330
|
+
|
331
|
+
@recapitulation_matrix_data = []
|
332
|
+
@total_each_col = []
|
333
|
+
@total_each_row = []
|
334
|
+
|
335
|
+
# executing query for value
|
336
|
+
if on_operation?
|
337
|
+
@recapitulation_matrix_data_operation = []
|
338
|
+
@total_each_col_operation = []
|
339
|
+
@total_each_row_operation = []
|
340
|
+
end
|
341
|
+
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
# just make sure the attribute name won't conflict
|
346
|
+
as_group_row_db = get_as_group_db(gd_row[:group_db])
|
347
|
+
as_group_col_db = get_as_group_db(gd_col[:group_db])
|
348
|
+
|
349
|
+
# executing query for row label, this also let us know the total rows
|
350
|
+
rows = get_label_record(gd_row, join_table, as_group_row_db)
|
351
|
+
|
352
|
+
# process column if 2 dimension. (row or column position doesn't important. their order, can be transposed, what matters only 1-D or 2-D)
|
353
|
+
if two_dimension?
|
354
|
+
cols = get_label_record(gd_col, join_table, as_group_col_db)
|
355
|
+
|
356
|
+
# iterate through cols and asign label only, not including value
|
357
|
+
cols.each_with_index do |col, j|
|
358
|
+
@total_each_col << 0
|
359
|
+
@total_each_col_operation << 0 if on_operation?
|
360
|
+
|
361
|
+
@label_col << get_label_item(gd_col, col, as_group_col_db)
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
# DATA PROCESS
|
372
|
+
# ----------------------------------------------------------------------------------------------------
|
373
|
+
# ----------------------------------------------------------------------------------------------------
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
# iterate through rows and summing up matrix value simultanously
|
378
|
+
# rows -> label top-bottom
|
379
|
+
rows.each_with_index do |row, i|
|
380
|
+
|
381
|
+
# assign label for each row
|
382
|
+
@label_row << get_label_item(gd_row, row, as_group_row_db)
|
383
|
+
|
384
|
+
# hash key in result set, eg. [{a: 5}, {c: 8}] or [{[a, b]: 5}, {[c, d]: 9}]. hash key are a, b, c, and d
|
385
|
+
key_row = (row.id.present? ? row.id : row.try(as_group_row_db))
|
386
|
+
if two_dimension?
|
387
|
+
# 2-dimension
|
388
|
+
@recapitulation_matrix_data << []
|
389
|
+
@total_each_row << 0
|
390
|
+
if on_operation?
|
391
|
+
@recapitulation_matrix_data_operation << []
|
392
|
+
@total_each_row_operation << 0
|
393
|
+
end
|
394
|
+
cols.each_with_index do |col, j|
|
395
|
+
key_col = (col.id.present? ? col.id : col.try(as_group_col_db))
|
396
|
+
cell = recapitulations[[key_row, key_col]].presence || 0
|
397
|
+
@recapitulation_matrix_data[i] << cell
|
398
|
+
@total_each_row[i] += cell
|
399
|
+
@total_each_col[j] += cell
|
400
|
+
|
401
|
+
if on_operation?
|
402
|
+
cell_operation = (recapitulations_operation[[key_row, key_col]].presence || 0).to_f
|
403
|
+
@recapitulation_matrix_data_operation[i] << cell_operation
|
404
|
+
@total_each_row_operation[i] += cell_operation
|
405
|
+
@total_each_col_operation[j] += cell_operation
|
406
|
+
end
|
407
|
+
end
|
408
|
+
else
|
409
|
+
# 1-dimension
|
410
|
+
cell = recapitulations[key_row].presence || 0
|
411
|
+
@recapitulation_matrix_data << [cell]
|
412
|
+
@total_each_row << cell
|
413
|
+
|
414
|
+
@total_each_col = [@total_each_row.inject(0, :+)]
|
415
|
+
@label_col = [t('subtotal')]
|
416
|
+
|
417
|
+
if on_operation?
|
418
|
+
cell_operation = (recapitulations_operation[key_row].presence || 0).to_f
|
419
|
+
@recapitulation_matrix_data_operation << [cell_operation]
|
420
|
+
@total_each_row_operation << cell_operation
|
421
|
+
@total_each_col_operation = [@total_each_row_operation.inject(0, :+)]
|
422
|
+
end
|
423
|
+
|
424
|
+
end
|
425
|
+
|
426
|
+
#
|
427
|
+
@recapitulation_matrix = []
|
428
|
+
@recapitulation_matrix_data.each do |rm|
|
429
|
+
@recapitulation_matrix << (Array.new(rm))
|
430
|
+
end
|
431
|
+
@recapitulation_matrix << (Array.new(@total_each_col))
|
432
|
+
@recapitulation_matrix.each_with_index do |rmwt, index|
|
433
|
+
rmwt << (rmwt.inject(0, :+))
|
434
|
+
rmwt.unshift(@label_row[index].presence || t('total'))
|
435
|
+
end
|
436
|
+
@recapitulation_matrix.unshift([''] + Array.new(@label_col + [t('total')]))
|
437
|
+
|
438
|
+
if on_operation?
|
439
|
+
@recapitulation_matrix_operation = []
|
440
|
+
@recapitulation_matrix_data_operation.each do |rm|
|
441
|
+
@recapitulation_matrix_operation << (Array.new(rm))
|
442
|
+
end
|
443
|
+
@recapitulation_matrix_operation << (Array.new(@total_each_col_operation))
|
444
|
+
@recapitulation_matrix_operation.each_with_index do |rmwt, index|
|
445
|
+
rmwt << (rmwt.inject(0, :+))
|
446
|
+
end
|
447
|
+
|
448
|
+
|
449
|
+
# calculate matrix data content
|
450
|
+
if params[:operation_type] == 'sum'
|
451
|
+
@recapitulation_matrix_operation.each_with_index do |rmoi, i|
|
452
|
+
rmoi.each_with_index do |rmoj, j|
|
453
|
+
@recapitulation_matrix[i + 1][j + 1] = @recapitulation_matrix_operation[i][j]
|
454
|
+
end
|
455
|
+
end
|
456
|
+
else # 'average'
|
457
|
+
@recapitulation_matrix_operation.each_with_index do |rmoi, i|
|
458
|
+
rmoi.each_with_index do |rmoj, j|
|
459
|
+
unless @recapitulation_matrix[i + 1][j + 1] == 0
|
460
|
+
@recapitulation_matrix[i + 1][j + 1] = ((@recapitulation_matrix_operation[i][j].round(2).to_f / @recapitulation_matrix[i + 1][j + 1]).to_f * 100).round / 100.0
|
461
|
+
end
|
462
|
+
end
|
463
|
+
end
|
464
|
+
end
|
465
|
+
|
466
|
+
end
|
467
|
+
|
468
|
+
|
469
|
+
end # end rows iteration
|
470
|
+
|
471
|
+
# Execute if 1-dimension
|
472
|
+
unless two_dimension?
|
473
|
+
@recapitulation_matrix = @recapitulation_matrix.transpose
|
474
|
+
recap_shift = @recapitulation_matrix.shift
|
475
|
+
@recapitulation_matrix.shift
|
476
|
+
@recapitulation_matrix = Array.new([recap_shift] + @recapitulation_matrix)
|
477
|
+
|
478
|
+
# Transpose if needed, depend on row coulumn position
|
479
|
+
@recapitulation_matrix = @recapitulation_matrix.transpose if params[:group_row].present?
|
480
|
+
end
|
481
|
+
end
|
482
|
+
|
483
|
+
# EOF group methods for recapitulation
|
484
|
+
|
485
|
+
|
486
|
+
|
487
|
+
def respond_to_remote(act = action_name, obj = instance_variable_get("@#{controller_name}"))
|
488
|
+
respond_to do |format|
|
489
|
+
case act
|
490
|
+
when :create
|
491
|
+
flash[:notice] = "#{obj.class.name.tableize} was successfully created."
|
492
|
+
format.html { redirect_to controller: obj.class.name.tableize, action: :edit, id: obj.id }
|
493
|
+
when :update
|
494
|
+
flash[:notice] = "#{obj.class.name.tableize} was successfully updated."
|
495
|
+
format.html { redirect_to controller: obj.class.name.tableize, action: :edit, id: obj.id }
|
496
|
+
when :destroy
|
497
|
+
flash[:notice] = "#{obj.class.name.tableize} was successfully deleted."
|
498
|
+
format.html { redirect_to controller: obj.class.name.tableize, action: :index }
|
499
|
+
else
|
500
|
+
format.html # index.html.erb
|
501
|
+
end
|
502
|
+
if params[:pgos].eql?('true')
|
503
|
+
format.js { render 'index', formats: [:js] }
|
504
|
+
format.xls { render 'index' }
|
505
|
+
elsif params[:recapitulation].eql?('true')
|
506
|
+
if params[:group_row].present? || params[:group_col].present?
|
507
|
+
generate_recapitulation
|
508
|
+
format.pdf {
|
509
|
+
render pdf: "#{controller_name}",
|
510
|
+
template: "application/recapitulation",
|
511
|
+
layout: 'print/recapitulation.html', # for pdf.html.erb
|
512
|
+
disposition: 'attachment'
|
513
|
+
}
|
514
|
+
headers["Content-Disposition"] = "attachment; filename=\"#{controller_name}.xls\""
|
515
|
+
format.xls { render 'recapitulation' }
|
516
|
+
end
|
517
|
+
format.js { render 'recapitulation', formats: [:js] }
|
518
|
+
else
|
519
|
+
format.js { render act, formats: [:js] }
|
520
|
+
format.xls
|
521
|
+
format.pdf {
|
522
|
+
render pdf: "#{controller_name}",
|
523
|
+
template: lookup_context.exists?("#{controller_path}/index") ? "#{controller_path}/index" : "application/index",
|
524
|
+
layout: 'print/pdf.html', # for pdf.html.erb
|
525
|
+
disposition: 'attachment'
|
526
|
+
}
|
527
|
+
end
|
528
|
+
format.json { render json: obj }
|
529
|
+
end
|
530
|
+
end
|
531
|
+
|
532
|
+
def format_remote(format, act = action_name, obj = instance_variable_get("@#{controller_name}"))
|
533
|
+
case act
|
534
|
+
when :create
|
535
|
+
flash[:notice] = "#{obj.class.name.tableize} was successfully created."
|
536
|
+
format.html { redirect_to controller: obj.class.name.tableize, action: :edit, id: obj.id }
|
537
|
+
when :update
|
538
|
+
flash[:notice] = "#{obj.class.name.tableize} was successfully updated."
|
539
|
+
format.html { redirect_to controller: obj.class.name.tableize, action: :edit, id: obj.id }
|
540
|
+
else
|
541
|
+
format.html { render action: act }
|
542
|
+
end
|
543
|
+
format.js { render act, formats: [:js] }
|
544
|
+
format.json { render json: obj }
|
545
|
+
end
|
546
|
+
|
547
|
+
|
548
|
+
|
549
|
+
def notification_meta record, opts={}
|
550
|
+
(record.notification_meta ||= {current_user: current_user}).merge! opts if record.respond_to? :notification_meta
|
551
|
+
end
|
552
|
+
|
553
|
+
# Set parent resource of the current resource
|
554
|
+
# Used in breadcrumbs
|
555
|
+
def set_parent_resources(*args)
|
556
|
+
args.each_with_index do |pr, i|
|
557
|
+
pr_singular = pr.singularize
|
558
|
+
pr_id = params["#{pr_singular}_id"]
|
559
|
+
|
560
|
+
if pr_id.blank? && i == 0
|
561
|
+
controller_object = controller_name.classify.constantize.where{id.eq(my{params[:id]})}.first
|
562
|
+
if controller_object.present? && controller_object.respond_to?(pr_singular.to_sym)
|
563
|
+
pr_id = controller_object.send("#{pr_singular}_id")
|
564
|
+
end
|
565
|
+
end
|
566
|
+
|
567
|
+
if pr_id.present?
|
568
|
+
@parent_resources ||= []
|
569
|
+
@parent_resources << pr
|
570
|
+
pr_object = pr.classify.constantize.find(pr_id)
|
571
|
+
instance_variable_set("@#{pr_singular}", pr_object)
|
572
|
+
elsif i > 0
|
573
|
+
prev_pr = args[i - 1]
|
574
|
+
prev_pr_singular = prev_pr.singularize
|
575
|
+
prev_pr_id = params["#{prev_pr_singular}_id"].presence || instance_variable_get("@#{prev_pr_singular}").try(:id)
|
576
|
+
if prev_pr_id.present?
|
577
|
+
prev_pr_object = prev_pr.classify.constantize.find(prev_pr_id)
|
578
|
+
if prev_pr_object.respond_to? pr_singular.to_sym
|
579
|
+
pr_id = prev_pr_object.send("#{pr_singular}_id")
|
580
|
+
if pr_id.present?
|
581
|
+
@parent_resources ||= []
|
582
|
+
@parent_resources << pr
|
583
|
+
pr_object = pr.classify.constantize.find(pr_id)
|
584
|
+
instance_variable_set("@#{pr_singular}", pr_object)
|
585
|
+
end
|
586
|
+
end
|
587
|
+
end
|
588
|
+
end
|
589
|
+
end
|
590
|
+
end
|
591
|
+
|
592
|
+
|
593
|
+
|
594
|
+
|
595
|
+
|
596
|
+
end
|
597
|
+
|
598
|
+
end
|
599
|
+
|
600
|
+
|
601
|
+
class Engine < ::Rails::Engine
|
602
|
+
|
603
|
+
initializer 'rich_table_compoenent.setup_helpers' do |app|
|
604
|
+
app.config.to_prepare do
|
605
|
+
ActionController::Base.send :helper, ComponentHelper
|
606
|
+
ActionController::Base.send :helper, ParagraphHelper
|
607
|
+
ActionController::Base.send :helper, TranslationsHelper
|
608
|
+
ActionController::Base.send :helper, MenusHelper
|
609
|
+
ActionController::Base.send :helper, DocumentsHelper
|
610
|
+
end
|
611
|
+
end
|
612
|
+
|
613
|
+
end
|
614
|
+
|
615
|
+
|
616
|
+
|
617
|
+
|
618
|
+
end
|
619
|
+
|
620
|
+
|
621
|
+
::ActionController::Base.send :include, RichTableComponent::Controller
|
622
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rich_table_component/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "rich_table_component"
|
8
|
+
gem.version = RichTableComponent::VERSION
|
9
|
+
gem.authors = ["ralibi"]
|
10
|
+
gem.email = ["ralibi@starqle.com"]
|
11
|
+
gem.description = %q{Rich Table Component with advanced search, export file, and generate recapitulation}
|
12
|
+
gem.summary = %q{Just what the description said}
|
13
|
+
gem.homepage = "http://starqle.com/"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency 'sass-rails'
|
21
|
+
gem.add_dependency 'less-rails'
|
22
|
+
gem.add_dependency 'haml-rails'
|
23
|
+
gem.add_dependency 'cancan'
|
24
|
+
gem.add_dependency 'paperclip'
|
25
|
+
gem.add_dependency 'ckeditor'
|
26
|
+
gem.add_dependency 'ransack'
|
27
|
+
gem.add_dependency 'squeel'
|
28
|
+
gem.add_dependency 'simple_form'
|
29
|
+
gem.add_dependency 'redis'
|
30
|
+
gem.add_dependency 'will_paginate'
|
31
|
+
gem.add_dependency 'wicked_pdf'
|
32
|
+
|
33
|
+
gem.add_dependency 'simple_form'
|
34
|
+
gem.add_dependency 'compass-rails'
|
35
|
+
gem.add_dependency 'twitter-bootstrap-rails'
|
36
|
+
end
|