opensteam 0.9.1 → 0.9.2

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.
Files changed (40) hide show
  1. data/CHANGELOG +12 -1
  2. data/generators/opensteam/opensteam_generator.rb +5 -0
  3. data/generators/opensteam/templates/app/controllers/admin/invoices_controller.rb +31 -25
  4. data/generators/opensteam/templates/app/controllers/admin/orders_controller.rb +22 -69
  5. data/generators/opensteam/templates/app/controllers/admin/shipments_controller.rb +29 -26
  6. data/generators/opensteam/templates/app/controllers/admin/users_controller.rb +28 -13
  7. data/generators/opensteam/templates/app/controllers/admin_controller.rb +39 -1
  8. data/generators/opensteam/templates/app/controllers/profile/orders_controller.rb +20 -59
  9. data/generators/opensteam/templates/app/helpers/webshop_helper.rb +3 -0
  10. data/generators/opensteam/templates/app/models/filter_entry.rb +17 -0
  11. data/generators/opensteam/templates/app/views/admin/filters/_filter.html.erb +14 -0
  12. data/generators/opensteam/templates/app/views/admin/filters/_filter_entry.html.erb +6 -0
  13. data/generators/opensteam/templates/app/views/admin/filters/_filter_fields.html.erb +8 -0
  14. data/generators/opensteam/templates/app/views/admin/invoices/_invoices.html.erb +9 -9
  15. data/generators/opensteam/templates/app/views/admin/invoices/index.html.erb +5 -1
  16. data/generators/opensteam/templates/app/views/admin/orders/_orders.html.erb +15 -16
  17. data/generators/opensteam/templates/app/views/admin/orders/show.html.erb +9 -8
  18. data/generators/opensteam/templates/app/views/admin/shipments/_shipments.html.erb +11 -11
  19. data/generators/opensteam/templates/app/views/admin/shipments/index.html.erb +3 -0
  20. data/generators/opensteam/templates/app/views/admin/users/edit.html.erb +3 -1
  21. data/generators/opensteam/templates/app/views/admin/users/index.html.erb +18 -6
  22. data/generators/opensteam/templates/app/views/admin/users/new.html.erb +2 -0
  23. data/generators/opensteam/templates/app/views/layouts/admin.html.erb +4 -0
  24. data/generators/opensteam/templates/app/views/profile/orders/_orders.html.erb +9 -19
  25. data/generators/opensteam/templates/config/initializers/opensteam_model_tables.rb +80 -41
  26. data/generators/opensteam/templates/db/migrate/20080609095728_create_order_items.rb +1 -0
  27. data/generators/opensteam/templates/db/migrate/20080609095729_create_orders.rb +2 -2
  28. data/generators/opensteam/templates/db/migrate/20080804152615_create_filter_entries.rb +16 -0
  29. data/generators/opensteam/templates/public/stylesheets/opensteam_white.css +25 -25
  30. data/generators/opensteam_product/templates/controllers/product_controller.rb +1 -1
  31. data/lib/opensteam/extension_base.rb +1 -0
  32. data/lib/opensteam/helpers/config_table_helper.rb +139 -0
  33. data/lib/opensteam/initializer.rb +3 -3
  34. data/lib/opensteam/invoice_base.rb +4 -0
  35. data/lib/opensteam/order_base.rb +5 -3
  36. data/lib/opensteam/shipment_base.rb +6 -0
  37. data/lib/opensteam/user_base.rb +1 -0
  38. data/lib/opensteam/version.rb +1 -1
  39. metadata +8 -3
  40. data/lib/opensteam/helper/configurable_table.rb +0 -228
@@ -0,0 +1,16 @@
1
+ class CreateFilterEntries < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :filter_entries do |t|
4
+ t.string :model, :null => false
5
+ t.string :key, :null => false
6
+ t.string :val, :null => false
7
+ t.string :op, :default => "LIKE"
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+
13
+ def self.down
14
+ drop_table :filter_entries
15
+ end
16
+ end
@@ -9,33 +9,32 @@ body {
9
9
  }
10
10
 
11
11
  #menu {
12
- float:right;
12
+ float:right;
13
13
  }
14
14
 
15
15
  #page {
16
- margin-top:30px;
17
- margin-left:50px;
18
- margin-right:50px;
16
+ margin-top:30px;
17
+ margin-left:50px;
18
+ margin-right:50px;
19
19
  }
20
20
 
21
21
 
22
22
  #header {
23
- padding-left:30px;
24
- padding-top:30px;
25
- padding-bottom:10px;
26
-
23
+ padding-left:30px;
24
+ padding-top:30px;
25
+ padding-bottom:10px;
26
+
27
27
  border-bottom:1px solid black;
28
28
  }
29
29
 
30
30
  #content_box {
31
- clear:both;
31
+ clear:both;
32
32
  }
33
33
 
34
34
  #content_box div {
35
- border-left: 1px solid #aaa;
36
- padding:10px;
37
- float:left
38
- ;
35
+ padding:10px;
36
+ float:left
37
+ ;
39
38
  }
40
39
 
41
40
  #content_box div * {
@@ -49,20 +48,21 @@ body {
49
48
 
50
49
 
51
50
  #content_box div div {
52
- border:none;
53
- padding:10px;
54
- clear:both;
51
+ border:none;
52
+ padding:10px;
53
+ clear:both;
55
54
  }
56
55
 
57
56
  #sidebar {
58
57
  }
59
58
 
60
59
  #content {
60
+ border-left: 1px solid #aaa ;
61
61
  }
62
62
 
63
63
  #footer {
64
- border-top: 1px solid black;
65
- clear:both;
64
+ border-top: 1px solid black;
65
+ clear:both;
66
66
  }
67
67
 
68
68
  #cart {
@@ -79,19 +79,19 @@ body {
79
79
  }
80
80
 
81
81
  .configured_table table {
82
- border-collapse: collapse ;
83
- border-spacing: 1px;
84
- font-size:8pt;
82
+ border-collapse: collapse ;
83
+ border-spacing: 1px;
84
+ font-size:8pt;
85
85
  }
86
86
 
87
87
  .configured_table table th a {
88
- width:100%;
89
- color:black;
90
- text-decoration:none;
88
+ width:100%;
89
+ color:black;
90
+ text-decoration:none;
91
91
  }
92
92
 
93
93
  .configured_table table th a:hover {
94
- background-color:#eee;
94
+ background-color:#eee;
95
95
  }
96
96
 
97
97
  .configured_table table td {
@@ -1,5 +1,5 @@
1
1
  ## TEMPLATE ##
2
- class Admin<%= class_name.pluralize %>Controller < AdminController
2
+ class Admin::<%= class_name.pluralize %>Controller < AdminController
3
3
  include Opensteam::Finder
4
4
 
5
5
  # GET /<%= table_name %>
@@ -41,6 +41,7 @@ module Opensteam
41
41
 
42
42
 
43
43
 
44
+
44
45
  def active? ; active == 0 ? false : true ; end
45
46
 
46
47
  # activate the extension
@@ -0,0 +1,139 @@
1
+ module Opensteam::Helpers
2
+
3
+
4
+ module ConfigTableHelper
5
+
6
+ def self.included(base)
7
+ base.extend(ClassMethods)
8
+ base.class_eval do
9
+ include InstanceMethods
10
+
11
+
12
+
13
+
14
+
15
+ end
16
+
17
+ end
18
+
19
+ module ClassMethods
20
+
21
+ def opensteam_filter(name, *args, &block )
22
+ @osteam_configtable = Opensteam::Helpers::ConfigTableHelper::Base.new( name, *args )
23
+ @osteam_configtable.instance_eval(&block) if block_given?
24
+
25
+ class << self ; attr_accessor :osteam_configtable ; end
26
+
27
+ end
28
+
29
+ end
30
+
31
+ module InstanceMethods
32
+ end
33
+
34
+
35
+
36
+ class Base < ActionView::Base
37
+
38
+ include ActionView::Helpers::TagHelper
39
+ include ActionView::Helpers::FormTagHelper
40
+
41
+ attr_accessor :name, :default_include, :columns, :order_column
42
+
43
+ def initialize( name, *args )
44
+ # args = args.first if args.is_a?(Array)
45
+ @name = name
46
+ @default_include = [] #args[:default_include] || []
47
+ @columns = []
48
+ end
49
+
50
+ def include_associations(arr)
51
+ @default_include = arr
52
+ end
53
+
54
+ def column(id, *args)
55
+ @columns << Column.new( id, *args )
56
+ end
57
+
58
+ def default_order_column(id)
59
+ @order_column = id
60
+ end
61
+
62
+ def [](id)
63
+ @columns.find { |s| s.id.to_s == id.to_s }
64
+ end
65
+
66
+ def table_header( &block )
67
+ html_options = {}
68
+ content_tag( :thead, {} ) do
69
+ content_tag( :tr, html_options ) do
70
+ @columns.collect do |c|
71
+ content_tag( :th, {} ) do
72
+ block.call( c )
73
+ end
74
+
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+
81
+
82
+
83
+
84
+ end
85
+
86
+ class Column
87
+ attr_accessor :name, :order, :sql, :id
88
+ def initialize(id, *args )
89
+ @args = args.is_a?( Array ) ? args.first : args
90
+ @id = id
91
+ @order = @args[:order] || @args[:sql]
92
+ @sql = @args[:sql] || @args[:order]
93
+ @name = @args[:name]
94
+ @method = @args[:method]
95
+ end
96
+
97
+ def sort
98
+ if @method
99
+ return Proc.new { |a,b| a.__send__( @id ).__send__(@method) <=> b.__send__( @id ).__send__( @method ) }
100
+ end
101
+ return @order
102
+ end
103
+
104
+
105
+
106
+ end
107
+
108
+
109
+ module HelperMethods
110
+
111
+ def osteam_sort_table( mdl, opts = {}, &block )
112
+ mdl = mdl.to_s.classify.constantize unless mdl.is_a?( Class )
113
+ config_table = mdl.osteam_configtable
114
+
115
+ content = capture( config_table, &block )
116
+
117
+ html_options = opts[:html] || {}
118
+
119
+ concat(
120
+ content_tag( :div, { :class => 'configured_table_containter' } ) do
121
+ content_tag( :table, html_options ) do
122
+ content
123
+ end
124
+ end, block.binding )
125
+
126
+ end
127
+
128
+ end
129
+
130
+ end
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+
139
+ end
@@ -35,6 +35,8 @@ module Opensteam
35
35
 
36
36
  def require_opensteam_after_initialize
37
37
  require 'opensteam/user_base' ## AuthenticatedMethods include !!!
38
+
39
+ require 'opensteam/helpers/config_table_helper'
38
40
 
39
41
  _logger "loaded!"
40
42
  end
@@ -97,9 +99,7 @@ module Opensteam
97
99
  require 'opensteam/cart_base'
98
100
  require 'opensteam/checkout'
99
101
  require 'opensteam/inventory_base'
100
-
101
-
102
- require 'opensteam/helper/configurable_table'
102
+
103
103
 
104
104
 
105
105
  end
@@ -41,6 +41,10 @@ module Opensteam
41
41
  has_many :order_items, :class_name => 'Opensteam::OrderBase::OrderItem'
42
42
 
43
43
 
44
+ named_scope :by_order, lambda { |order_id| { :include => :order, :conditions => { :order_id => order_id } } }
45
+ named_scope :order_by, lambda { |by| { :include => Invoice.osteam_configtable.default_include, :order => Array(by).join(",") , :conditions => "orders.id = orders.id" } }
46
+
47
+
44
48
  def initialize(*args)
45
49
  super(*args)
46
50
  if order
@@ -46,9 +46,11 @@ module Opensteam
46
46
  # Order Model
47
47
  class Order < ActiveRecord::Base
48
48
  include Opensteam::StateMachine
49
-
50
- include Opensteam::UUIDHelper
51
-
49
+ # include Opensteam::UUIDHelper
50
+
51
+ named_scope :order_by, lambda { |by| { :include => Order.osteam_configtable.default_include, :order => Array(by).join(",") , :conditions => "users.id = users.id" } }
52
+ named_scope :by_user, lambda { |user_id| { :include => [:customer ], :conditions => { :customer_id => user_id } } }
53
+
52
54
  # associations
53
55
 
54
56
  has_many :order_items, :class_name => 'Opensteam::OrderBase::OrderItem', :extend => OrderItemsExtension
@@ -38,6 +38,12 @@ module Opensteam
38
38
 
39
39
  has_many :order_items, :class_name => 'Opensteam::OrderBase::OrderItem'
40
40
 
41
+
42
+ named_scope :by_order, lambda { |order_id| { :include => :order, :conditions => { :order_id => order_id } } }
43
+ named_scope :order_by, lambda { |by| { :include => Shipment.osteam_configtable.default_include, :order => Array(by).join(",") , :conditions => "orders.id = orders.id" } }
44
+
45
+
46
+
41
47
  def initialize(*args)
42
48
  super(*args)
43
49
 
@@ -101,6 +101,7 @@ module Opensteam
101
101
 
102
102
 
103
103
  named_scope :by_profile, lambda { |p| { :include => :profile, :conditions => "profiles.name = '#{p.to_s.classify}'" } }
104
+ named_scope :order_by, lambda { |by| { :include => Opensteam::UserBase::User.osteam_configtable.default_include, :order => by, :conditions => "profiles.id = profiles.id" } }
104
105
 
105
106
 
106
107
 
@@ -18,7 +18,7 @@ module Opensteam #:nodoc:
18
18
  module VERSION #:nodoc:
19
19
  MAJOR = 0
20
20
  MINOR = 9
21
- TINY = 1
21
+ TINY = 2
22
22
 
23
23
  STRING = [MAJOR, MINOR, TINY].join('.')
24
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opensteam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Schaerfer
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-01 00:00:00 +02:00
12
+ date: 2008-08-07 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -43,7 +43,7 @@ files:
43
43
  - lib/opensteam/inventory_base.rb
44
44
  - lib/opensteam/initializer.rb
45
45
  - lib/opensteam/history.rb
46
- - lib/opensteam/helper/configurable_table.rb
46
+ - lib/opensteam/helpers/config_table_helper.rb
47
47
  - lib/opensteam/finder.rb
48
48
  - lib/opensteam/extension_base.rb
49
49
  - lib/opensteam/config.rb
@@ -122,6 +122,7 @@ files:
122
122
  - generators/opensteam/templates/lib/authentication/by_password.rb
123
123
  - generators/opensteam/templates/lib/authentication/by_cookie_token.rb
124
124
  - generators/opensteam/templates/lib/authenticated_system.rb
125
+ - generators/opensteam/templates/db/migrate/20080804152615_create_filter_entries.rb
125
126
  - generators/opensteam/templates/db/migrate/20080714131650_create_shipments.rb
126
127
  - generators/opensteam/templates/db/migrate/20080714131513_create_invoices.rb
127
128
  - generators/opensteam/templates/db/migrate/20080630114155_create_state_histories.rb
@@ -228,10 +229,14 @@ files:
228
229
  - generators/opensteam/templates/app/views/admin/inventories/index.html.erb
229
230
  - generators/opensteam/templates/app/views/admin/inventories/edit.html.erb
230
231
  - generators/opensteam/templates/app/views/admin/index.html.erb
232
+ - generators/opensteam/templates/app/views/admin/filters/_filter_fields.html.erb
233
+ - generators/opensteam/templates/app/views/admin/filters/_filter_entry.html.erb
234
+ - generators/opensteam/templates/app/views/admin/filters/_filter.html.erb
231
235
  - generators/opensteam/templates/app/views/admin/catalog.html.erb
232
236
  - generators/opensteam/templates/app/views/admin/_nav.html.erb
233
237
  - generators/opensteam/templates/app/views/admin/_address.html.erb
234
238
  - generators/opensteam/templates/app/models/search.rb
239
+ - generators/opensteam/templates/app/models/filter_entry.rb
235
240
  - generators/opensteam/templates/app/helpers/webshop_helper.rb
236
241
  - generators/opensteam/templates/app/helpers/users_helper.rb
237
242
  - generators/opensteam/templates/app/helpers/admin_helper.rb
@@ -1,228 +0,0 @@
1
- module Opensteam
2
-
3
- module Helper
4
-
5
-
6
- # ConfigurableTable
7
- #
8
- # Module to Configure, Search and Sort a table, depending on a model-collection
9
- #
10
- module ConfigurableTableController
11
-
12
- def self.included(base)
13
- # base.extend( ClassMethods )
14
-
15
- base.class_eval do
16
- include InstanceMethods
17
- before_filter :set_sort_column
18
- private :sort_model, :set_sort_column
19
- end
20
- end
21
-
22
-
23
- module InstanceMethods
24
-
25
- # before_filter:
26
- # if params[:sort] is set, it gets the current sort-column from the
27
- # configured_table class variable
28
- #
29
- def set_sort_column
30
- if params[:sort]
31
- model = params[:model].demodulize.classify.constantize rescue nil
32
- @sort_column = model.configured_table.get_column( params[:sort] ) || model.configured_table.default_sort
33
- end
34
- end
35
-
36
- def sort
37
- if params[:sort]
38
- self.class.to_s =~ /^(.+)Controller/
39
- model = $1.demodulize.classify.constantize rescue nil
40
- @result = sort_model( model, @sort_column )
41
- end
42
- render :action => :sort
43
-
44
- end
45
-
46
- # sort the current model by column
47
- # finds all entries for current model (including all associations)
48
- # sort entries either by "ORDER" SQL or by a ruby sort-block (depending on
49
- # the configuration or wether the column is an association)
50
- #
51
- def sort_model( model, column, conditions = nil, includes = nil )
52
- finder_args = {}
53
- finder_args[:conditions] = conditions if conditions
54
- finder_args[:include] = includes if includes
55
-
56
- if column.order_ruby?
57
- result = model.find( :all, finder_args )
58
- result.sort!(&column.order)
59
- else
60
- finder_args[:order] = column.order
61
- result = model.find(:all, finder_args )
62
- end
63
- toggle_sorted( model.to_s.demodulize )
64
- result.reverse! if sorted?( model.to_s.demodulize )
65
- result
66
- end
67
-
68
- # if model is currently sorted ascending
69
- def sorted?(model)
70
- session["#{model}_sorted".to_sym] ? true : false ;
71
- end
72
-
73
-
74
- # toggle the sorted-sesssion variable for the given model
75
- def toggle_sorted(model)
76
- session["#{model}_sorted".to_sym] = session["#{model}_sorted".to_sym] ? false : true
77
- end
78
- end
79
- end
80
-
81
-
82
-
83
-
84
- module ConfigurableTable
85
-
86
- def self.included(base)
87
- base.extend(ClassMethods)
88
-
89
- end
90
-
91
-
92
- module ClassMethods
93
- # configure a table
94
- # takes a block, like:
95
- # configure_table :order do
96
- # column :id, :name => "ID"
97
- # end
98
- #
99
- def configure_table( mdl, &block )
100
- mdl = mdl.to_s.classify.constantize unless mdl.is_a?( Class )
101
-
102
-
103
- mdl.class_eval do
104
- @configured_table = ConfigTable.new( self )
105
- @configured_table.instance_eval( &block )
106
-
107
- class << self ; attr_accessor :configured_table ; end
108
- end
109
-
110
- end
111
- end
112
-
113
-
114
-
115
-
116
-
117
- # ConfigTable
118
- # Holds all the Columns defined fot the Configurable-Table
119
- #
120
- class ConfigTable
121
-
122
- attr_accessor :columns, :model, :assocs, :assoc_names, :table_id
123
-
124
- def initialize(mdl)
125
- @columns = []
126
- @model = mdl
127
- @table_id = "#{@model.table_name}_configured_table"
128
- @assocs = mdl.reflect_on_all_associations
129
- @assoc_names = @assocs.collect(&:name)
130
- end
131
-
132
-
133
- def default_sort_col( id )
134
- @default_sort = id.to_sym
135
- end
136
-
137
- def column( id, *args )
138
- @columns << Column.new( id.to_sym, self, *args )
139
- end
140
-
141
- def get_column(id)
142
- @columns.find { |s| s.id.to_sym == id.to_sym }
143
- end
144
-
145
- def default_sort ; get_column( @default_sort ) ; end
146
-
147
- end
148
-
149
- class Column
150
- attr_accessor :id, :name, :opts, :order, :config_table, :method, :table_name, :sql_query
151
-
152
-
153
- # initialize a column
154
- # if column is an association of the current model, the entries
155
- # are sorted either by a ruby-block (if a :method is defined to call on the
156
- # association-object), by :size (ruby-block, if its a _has_many_ association) or
157
- # simply by the id (ORDER-SQL statement)
158
- # if columns is not an association, the entries are sorted by an ORDER-SQL statement.
159
- #
160
- def initialize( id, config_table, *args )
161
- @id = id
162
- @opts = *args || Hash.new(nil)
163
- @method = @opts[:method]
164
- @name = @opts[:name] || @id.to_s
165
- @config_table = config_table
166
-
167
- @assoc = @config_table.assocs.find { |s| s.name.to_sym == @id.to_sym }
168
-
169
- @order = @opts[:sort]
170
-
171
-
172
-
173
- unless @order
174
- if is_assoc?
175
- if @method
176
- @order = Proc.new { |a,b|
177
- a.__send__( @id ).__send__( @method ).to_s <=> b.__send__( @id ).__send__( @method ).to_s
178
- }
179
- # @order = "`#{assoc_table_name}`.`#{@method}`"
180
- else
181
- @order = is_has_many_assoc? ? Proc.new { |a,b| a.__send__(@method).size <=> b.__send__(@method).size } :
182
- "`#{assoc_table_name}`.`id`"
183
- end
184
- else
185
- @order = "`#{@config_table.model.table_name}`.`#{@id}`"
186
- end
187
- end
188
-
189
- end
190
-
191
- def sql_query
192
- is_assoc? ? "`#{table_name}`.`#{@method =~ /size/ ? 'id' : @method}`" :
193
- "`#{table_name}`.`#{@id}`" ;
194
- end
195
-
196
- def table_name
197
- is_assoc? ? assoc_table_name : @config_table.model.table_name ;
198
- end
199
-
200
- def is_assoc? #:nodoc:
201
- @assoc ? true : false
202
- end
203
-
204
- def is_has_many_assoc? #:nodoc:
205
- @assoc.macro =~ /has_many/
206
- end
207
-
208
- def assoc_table_name #:nodoc:
209
- @assoc.options.include?( :class_name ) ?
210
- @assoc.options[:class_name].constantize.table_name :
211
- @id.to_s.tableize
212
- end
213
-
214
-
215
- def order_ruby? #:nodoc:
216
- @order.is_a?( Proc )
217
- end
218
- end
219
-
220
- end
221
-
222
- end
223
-
224
-
225
-
226
-
227
-
228
- end