vidl-toolbox 0.0.3 → 0.0.4

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.
@@ -45,6 +45,7 @@ module Toolbox
45
45
  class ShowConfig
46
46
  attr_reader :fieldsets
47
47
  attr_reader :embedded_lists
48
+ attr_reader :pdf_options
48
49
 
49
50
  def initialize model_name, config
50
51
  @fieldsets = []
@@ -68,6 +69,7 @@ module Toolbox
68
69
  prefixes[c.prefix] = c
69
70
  @embedded_lists << c
70
71
  end
72
+ @pdf_options = config[:pdf_options] || {}
71
73
  end
72
74
  end
73
75
 
@@ -140,7 +142,11 @@ module Toolbox
140
142
  class ActionConfig < Config
141
143
  define_options :label => { :type => [String] },
142
144
  :name => { :required => true, :type => [Symbol] },
143
- :model_name => { :required => true, :type => [String] }
145
+ :model_name => { :required => true, :type => [String] },
146
+ :url => {:type => [String]},
147
+ :direct_link => { :type => [TrueClass, FalseClass], :default => false},
148
+ :css_class => { :type => [String]}
149
+
144
150
  end
145
151
 
146
152
  # Holds the configuration for a from control
@@ -1,4 +1,5 @@
1
1
  require File.expand_path("../dirs", File.dirname(__FILE__))
2
+ require 'fastercsv'
2
3
 
3
4
  module Toolbox
4
5
 
@@ -67,11 +68,23 @@ module Toolbox
67
68
  end
68
69
 
69
70
  def show
70
- obj = model_class.find(params[:id])
71
- set_record obj
71
+ rec = model_class.find(params[:id])
72
+ set_record rec
73
+
74
+ @show_config = show_config rec
75
+ @embedded_list = nil
76
+ if @show_config.embedded_lists.length > 0
77
+ prefix = params[:list] || @show_config.embedded_lists.first.prefix
78
+ @show_config.embedded_lists.each do |embedded_list|
79
+ @embedded_list = embedded_list if embedded_list.prefix == prefix
80
+ end
81
+ end
82
+
72
83
  respond_to do |format|
73
84
  format.html { render :template => 'toolbox/show' }
74
- format.xml { render :xml => obj }
85
+ format.xml { render :xml => rec }
86
+ format.pdf { render @show_config.pdf_options }
87
+ format.csv { stream_csv show_csv(rec) }
75
88
  end
76
89
  end
77
90
 
@@ -240,11 +253,30 @@ module Toolbox
240
253
  controller_name.classify.constantize
241
254
  end
242
255
 
256
+ def embedded_list_collection rec
257
+ options = {}
258
+ options[:order] = Toolbox::Sorting.order_by params, @embedded_list.widget_list.widgets, @embedded_list.prefix
259
+ options[:include] = @embedded_list.include_assoc if @embedded_list.include_assoc
260
+ rec.send(@embedded_list.collection_config.model_method).find(:all, options)
261
+ end
262
+
243
263
  protected
244
264
 
245
- #def load_config
246
- # @config = "#{controller_name.camelcase}ViewConfig".constantize.get_instance unless defined? @config
247
- #end
265
+ def stream_csv options
266
+ field_renderers = options[:widget_list].widgets.map { |f| Toolbox::FieldRenderer.new self, f }
267
+
268
+ csv_string = FasterCSV.generate do |csv|
269
+ # Title
270
+ csv << field_renderers.map { |fr| fr.label }
271
+ options[:collection].each do |rec|
272
+ csv << field_renderers.map { |fr| fr.render_value(rec, false) }
273
+ end
274
+ end
275
+ send_data csv_string, :type => "text/csv",
276
+ :filename=> options[:filename],
277
+ :disposition => 'attachment'
278
+ end
279
+
248
280
 
249
281
  # check the consitency between the visible input-field
250
282
  # and the invisible id field
@@ -280,6 +312,7 @@ module Toolbox
280
312
  def include_assoc
281
313
  self.class.read_inheritable_attribute('include_assoc')
282
314
  end
315
+
283
316
  end
284
317
 
285
318
  end
@@ -258,7 +258,7 @@ module Toolbox
258
258
  model_name = @widget_config.model_name
259
259
  return nil if action == current_action
260
260
  end
261
- css_class = "enabled #{action}"
261
+ css_class = @widget_config.css_class || "enabled #{action}"
262
262
 
263
263
  case action
264
264
  when 'separator'
@@ -297,8 +297,16 @@ module Toolbox
297
297
  @view.link_to label, url
298
298
  end
299
299
  else
300
- url = eval("@view.#{action}_#{model_name}_path(rec)")
301
- @view.link_to_remote label, { :url => url, :method => :get }, {:class => css_class }
300
+ url = @widget_config.url || @view.formatted_polymorphic_path([rec, action]) #eval("@view.#{action}_#{model_name}_path(rec)")
301
+ if context
302
+ if @widget_config.direct_link
303
+ @view.link_to label, url, :class => css_class
304
+ else
305
+ @view.link_to_remote label, { :url => url, :method => :get }, {:class => css_class }
306
+ end
307
+ else
308
+ @view.link_to label, url
309
+ end
302
310
  end # case
303
311
  end
304
312
  end
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Toolbox
3
- VERSION = '0.0.3'
3
+ VERSION = '0.0.4'
4
4
  end
@@ -149,7 +149,7 @@ div.menu a {
149
149
  .menu.desktop a.save {
150
150
  background: #f9f8f7 url(/images/toolbox/page_save.png) 2px 50% no-repeat;
151
151
  }
152
- .menu.desktop a.xsl {
152
+ .menu.desktop a.xls {
153
153
  background: #f9f8f7 url(/images/toolbox/page_excel.png) 2px 50% no-repeat;
154
154
  }
155
155
  .menu.desktop a.doc {
@@ -1,29 +1,24 @@
1
1
  <%
2
2
  rec = get_record
3
- show_config = controller.show_config rec
4
-
5
3
  %>
6
- <%= render :partial => 'toolbox/show', :object => rec, :locals => { :widgetsets => show_config.fieldsets} %>
4
+ <%= render :partial => 'toolbox/show', :object => rec, :locals => { :widgetsets => @show_config.fieldsets} %>
7
5
 
8
- <% if show_config.embedded_lists.length > 0
9
- current_list = nil
10
- prefix = params[:list] || show_config.embedded_lists.first.prefix
6
+ <% if @embedded_list
11
7
  sub_menu = []
12
- show_config.embedded_lists.each do |embedded_list|
13
- sub_menu << link_to_if(embedded_list.prefix != prefix,
8
+ @show_config.embedded_lists.each do |embedded_list|
9
+ sub_menu << link_to_if(embedded_list.prefix != @embedded_list.prefix,
14
10
  "#{embedded_list.label} (#{rec.send(embedded_list.collection_config.model_method).count})",
15
11
  params.merge(:list => embedded_list.prefix))
16
- current_list = embedded_list if embedded_list.prefix == prefix
17
12
  end
18
13
 
19
14
  pag_options = {}
20
- pag_options[:page] = params["#{prefix}-page".to_sym]
21
- pag_options[:order] = Toolbox::Sorting.order_by params, current_list.widget_list.widgets, prefix
22
- pag_options[:include] = current_list.include_assoc if current_list.include_assoc
23
- data = rec.send(current_list.collection_config.model_method).paginate(pag_options)
15
+ pag_options[:page] = params["#{@embedded_list.prefix}-page".to_sym]
16
+ pag_options[:order] = Toolbox::Sorting.order_by params, @embedded_list.widget_list.widgets, @embedded_list.prefix
17
+ pag_options[:include] = @embedded_list.include_assoc if @embedded_list.include_assoc
18
+ data = rec.send(@embedded_list.collection_config.model_method).paginate(pag_options)
24
19
  %>
25
20
  <div style="clear: left; padding-top: 10px"><%= sub_menu.join ' | ' %>
26
- <%= render :partial => "toolbox/list", :object => data, :locals => {:widget_list => current_list.widget_list, :prefix => prefix} %>
21
+ <%= render :partial => "toolbox/list", :object => data, :locals => {:widget_list => @embedded_list.widget_list, :prefix => @embedded_list.prefix} %>
27
22
  </div>
28
23
  <% end %>
29
24
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vidl-toolbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Nyffenegger