clevic 0.7.0 → 0.8.0

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.
@@ -1,7 +1,7 @@
1
1
  module Clevic #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 7
4
+ MINOR = 8
5
5
  TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
@@ -16,21 +16,18 @@ class Entry < Clevic::Record
16
16
  belongs_to :debit, :class_name => 'Account', :foreign_key => 'debit_id'
17
17
  belongs_to :credit, :class_name => 'Account', :foreign_key => 'credit_id'
18
18
 
19
- # define how fields will be displayed
20
- def self.ui( parent )
21
- Clevic::TableView.new( self, parent ).create_model do
22
- plain :date, :sample => '88-WWW-99'
23
- distinct :description, :conditions => "now() - date <= '1 year'", :sample => 'm' * 26
24
- relational :debit, :display => 'name', :conditions => 'active = true', :order => 'lower(name)', :sample => 'Leilani Member Loan'
25
- relational :credit, :display => 'name', :conditions => 'active = true', :order => 'lower(name)', :sample => 'Leilani Member Loan'
26
- plain :amount, :sample => 999999.99
27
- distinct :category
28
- plain :cheque_number
29
- plain :active, :sample => 'WW'
30
- plain :vat, :label => 'VAT', :sample => 'WW', :tooltip => 'Does this include VAT?'
31
-
32
- records :order => 'date, id'
33
- end
19
+ define_ui do
20
+ plain :date, :sample => '88-WWW-99'
21
+ distinct :description, :conditions => "now() - date <= '1 year'", :sample => 'm' * 26
22
+ relational :debit, :display => 'name', :conditions => 'active = true', :order => 'lower(name)', :sample => 'Leilani Member Loan'
23
+ relational :credit, :display => 'name', :conditions => 'active = true', :order => 'lower(name)', :sample => 'Leilani Member Loan'
24
+ plain :amount, :sample => 999999.99
25
+ distinct :category
26
+ plain :cheque_number
27
+ plain :active, :sample => 'WW'
28
+ plain :vat, :label => 'VAT', :sample => 'WW', :tooltip => 'Does this include VAT?'
29
+
30
+ records :order => 'date, id'
34
31
  end
35
32
 
36
33
  # called when data is changed in the UI
@@ -82,16 +79,14 @@ class Account < Clevic::Record
82
79
  has_many :credits, :class_name => 'Entry', :foreign_key => 'credit_id'
83
80
 
84
81
  # define how fields are displayed
85
- def self.ui( parent )
86
- Clevic::TableView.new( self, parent ).create_model do
87
- plain :name
88
- restricted :vat, :label => 'VAT', :set => %w{ yes no all }
89
- plain :account_type
90
- plain :pastel_number, :alignment => Qt::AlignRight, :label => 'Pastel'
91
- plain :fringe, :format => "%.1f"
92
- plain :active
93
-
94
- records :order => 'name,account_type'
95
- end
82
+ define_ui do
83
+ plain :name
84
+ restricted :vat, :label => 'VAT', :set => %w{ yes no all }
85
+ plain :account_type
86
+ plain :pastel_number, :alignment => Qt::AlignRight, :label => 'Pastel'
87
+ plain :fringe, :format => "%.1f"
88
+ plain :active
89
+
90
+ records :order => 'name,account_type'
96
91
  end
97
92
  end
@@ -1,5 +1,7 @@
1
1
  require 'clevic.rb'
2
2
 
3
+ # see sql/accounts.sql for schema
4
+
3
5
  # db connection
4
6
  Clevic::DbOptions.connect do
5
7
  database 'accounts_test'
@@ -14,67 +14,73 @@ class Entry < Clevic::Record
14
14
  belongs_to :activity
15
15
  belongs_to :project
16
16
 
17
- # define how fields are displayed
18
- def self.ui( parent )
19
- Clevic::TableView.new( self, parent ).create_model do
20
- plain :date, :sample => '28-Dec-08'
21
- relational :project, :display => 'project', :conditions => 'active = true', :order => 'lower(project)'
22
- relational :invoice, :display => 'invoice_number', :conditions => "status = 'not sent'", :order => 'invoice_number'
23
- plain :start
24
- plain :end
25
- plain :description, :sample => 'This is a long string designed to hold lots of data and description'
26
- relational :activity, :display => 'activity', :order => 'lower(activity)', :sample => 'Troubleshooting', :conditions => 'active = true'
27
- distinct :module, :tooltip => 'Module or sub-project'
28
- plain :charge, :tooltip => 'Is this time billable?'
29
- distinct :person, :tooltip => 'The person who did the work'
30
-
31
- records :order => 'date, start, id'
17
+ define_ui do
18
+ plain :date, :sample => '28-Dec-08'
19
+ relational :project, :display => 'project', :conditions => 'active = true', :order => 'lower(project)'
20
+ relational :invoice, :display => 'invoice_number', :conditions => "status = 'not sent'", :order => 'invoice_number'
21
+ plain :start
22
+ plain :end
23
+ plain :description, :sample => 'This is a long string designed to hold lots of data and description'
24
+
25
+ relational :activity do
26
+ display 'activity'
27
+ order 'lower(activity)'
28
+ sample 'Troubleshooting'
29
+ conditions 'active = true'
32
30
  end
31
+
32
+ distinct :module, :tooltip => 'Module or sub-project'
33
+ plain :charge, :tooltip => 'Is this time billable?'
34
+ distinct :person, :tooltip => 'The person who did the work'
35
+
36
+ records :order => 'date, start, id'
33
37
  end
34
38
 
35
- # called when a key is pressed in this model's table view
36
- def self.key_press_event( event, current_index, view )
37
- case
38
- # copy almost all of the previous line
39
- when event.ctrl? && event.quote_dbl?
40
- if current_index.row > 1
41
- # fetch previous item
42
- model = current_index.model
43
- previous_item = model.collection[current_index.row - 1]
44
-
45
- # copy the relevant fields
46
- current_index.entity.start = previous_item.end
47
- [:date, :project, :invoice, :activity, :module, :charge, :person].each do |attr|
48
- current_index.entity.send( "#{attr.to_s}=", previous_item.send( attr ) )
49
- end
50
-
51
- # tell view to update
52
- top_left_index = model.create_index( current_index.row, 0 )
53
- bottom_right_index = model.create_index( current_index.row, current_index.column + view.builder.fields.size )
54
- view.dataChanged( top_left_index, bottom_right_index )
55
-
56
- # move to end time field
57
- view.override_next_index( model.create_index( current_index.row, view.builder.index( :end ) ) )
58
- end
59
- # don't let anybody else handle the keypress
60
- return true
61
-
62
- when event.ctrl? && event.i?
63
- invoice_from_project( current_index, view )
64
- # don't let anybody else handle the keypress
65
- return true
39
+ def self.actions( view, action_builder )
40
+ action_builder.action :smart_copy, 'Smart Copy', :shortcut => 'Ctrl+"' do
41
+ smart_copy( view )
42
+ end
43
+
44
+ action_builder.action :invoice_from_project, 'Invoice from Project', :shortcut => 'Ctrl+Shift+I' do
45
+ invoice_from_project( view.current_index, view )
66
46
  end
67
47
  end
68
48
 
49
+ # do a smart copy from the previous line
50
+ def self.smart_copy( view )
51
+ view.sanity_check_read_only
52
+ view.sanity_check_ditto
53
+
54
+ if view.current_index.row > 1
55
+ # fetch previous item
56
+ model = view.model
57
+ previous_item = model.collection[view.current_index.row - 1]
58
+
59
+ # copy the relevant fields
60
+ view.current_index.entity.start = previous_item.end
61
+ [:date, :project, :invoice, :activity, :module, :charge, :person].each do |attr|
62
+ view.current_index.entity.send( "#{attr.to_s}=", previous_item.send( attr ) )
63
+ end
64
+
65
+ # tell view to update
66
+ top_left_index = model.create_index( view.current_index.row, 0 )
67
+ bottom_right_index = model.create_index( view.current_index.row, view.current_index.column + view.builder.fields.size )
68
+ view.dataChanged( top_left_index, bottom_right_index )
69
+
70
+ # move to end time field
71
+ view.override_next_index( model.create_index( view.current_index.row, view.builder.index( :end ) ) )
72
+ end
73
+ end
74
+
69
75
  # called when data is changed in this model's table view
70
76
  def self.data_changed( top_left, bottom_right, view )
71
77
  invoice_from_project( top_left, view ) if ( top_left == bottom_right )
72
78
  end
73
79
 
80
+ # auto-complete invoice number field from project
74
81
  def self.invoice_from_project( current_index, view )
75
- # auto-complete invoice number field from project
76
82
  current_field = current_index.attribute
77
- if current_field == :project && current_index.entity.project != nil
83
+ if [:project,:invoice].include?( current_field ) && current_index.entity.project != nil
78
84
  # most recent entry, ordered in reverse
79
85
  invoice = current_index.entity.project.latest_invoice
80
86
 
@@ -97,36 +103,31 @@ end
97
103
  class Invoice < Clevic::Record
98
104
  has_many :entries
99
105
 
100
- # define how fields are displayed
101
- def self.ui( parent )
102
- Clevic::TableView.new( self, parent ).create_model do
103
- plain :date
104
- distinct :client
105
- plain :invoice_number
106
- restricted :status, :set => ['not sent', 'sent', 'paid', 'debt', 'writeoff', 'internal']
107
- restricted :billing, :set => %w{Hours Quote Internal}
108
- plain :quote_date
109
- plain :quote_amount
110
- plain :description
111
-
112
- records :order => 'invoice_number'
113
- end
106
+ define_ui do
107
+ plain :date
108
+ distinct :client
109
+ plain :invoice_number
110
+ restricted :status, :set => ['not sent', 'sent', 'paid', 'debt', 'writeoff', 'internal']
111
+ restricted :billing, :set => %w{Hours Quote Internal}
112
+ plain :quote_date
113
+ plain :quote_amount
114
+ plain :description
115
+
116
+ records :order => 'invoice_number'
114
117
  end
115
118
  end
116
119
 
117
120
  class Project < Clevic::Record
118
121
  has_many :entries
119
122
 
120
- def self.ui( parent )
121
- Clevic::TableView.new( Project, parent ).create_model do
122
- plain :project
123
- plain :description
124
- distinct :client
125
- plain :rate
126
- plain :active
127
-
128
- records :order => 'project'
129
- end
123
+ define_ui do
124
+ plain :project
125
+ plain :description
126
+ distinct :client
127
+ plain :rate
128
+ plain :active
129
+
130
+ records :order => 'project'
130
131
  end
131
132
 
132
133
  # Return the latest invoice for this project
@@ -145,12 +146,10 @@ class Activity < Clevic::Record
145
146
  has_many :entries
146
147
 
147
148
  # define how fields are displayed
148
- def self.ui( parent )
149
- Clevic::TableView.new( Activity, parent ).create_model do
150
- plain :activity
151
- plain :active
152
-
153
- records :order => 'activity'
154
- end
149
+ define_ui do
150
+ plain :activity
151
+ plain :active
152
+
153
+ records :order => 'activity'
155
154
  end
156
155
  end
@@ -13,8 +13,8 @@ class Entry < Clevic::Record
13
13
  belongs_to :project
14
14
 
15
15
  # define how fields are displayed
16
- def self.ui( parent )
17
- Clevic::TableView.new( self, parent ).create_model do
16
+ def self.build_table_model( model_builder )
17
+ model_builder.instance_exec do
18
18
  plain :date, :sample => '28-Dec-08'
19
19
  relational :project, :display => 'project', :conditions => "active = true", :order => 'lower(project)'
20
20
  relational :invoice, :display => 'invoice_number', :conditions => "status = 'not sent'", :order => 'invoice_number'
@@ -95,8 +95,8 @@ end
95
95
  class Project < Clevic::Record
96
96
  has_many :entries
97
97
 
98
- def self.ui( parent )
99
- Clevic::TableView.new( Project, parent ).create_model do
98
+ def self.build_table_model( model_builder )
99
+ model_builder.instance_exec do
100
100
  plain :project
101
101
  plain :description
102
102
  distinct :client
@@ -123,8 +123,8 @@ class Activity < Clevic::Record
123
123
  has_many :entries
124
124
 
125
125
  # define how fields are displayed
126
- def self.ui( parent )
127
- Clevic::TableView.new( Activity, parent ).create_model do
126
+ def self.build_table_model( model_builder )
127
+ model_builder.instance_exec do
128
128
  plain :activity
129
129
  plain :active
130
130
 
@@ -137,8 +137,8 @@ class Invoice < Clevic::Record
137
137
  has_many :entries
138
138
 
139
139
  # define how fields are displayed
140
- def self.ui( parent )
141
- Clevic::TableView.new( Invoice, parent ).create_model do
140
+ def self.build_table_model( model_builder )
141
+ model_builder.instance_exec do
142
142
  plain :date
143
143
  distinct :client
144
144
  plain :invoice_number
@@ -8,13 +8,14 @@ Clevic::DbOptions.connect( $options ) do
8
8
  end
9
9
 
10
10
  # This is a read-only view, which is currently not implemented
11
- class Values < Clevic::Record
11
+ class Value < Clevic::Record
12
12
  set_table_name 'values'
13
- has_many :debits, :class_name => 'Entry', :foreign_key => 'debit_id'
14
- has_many :credits, :class_name => 'Entry', :foreign_key => 'credit_id'
15
- def self.ui( parent )
16
- Clevic::TableView.new( self, parent ).create_model do
17
- readonly
13
+ #~ has_many :debits, :class_name => 'Entry', :foreign_key => 'debit_id'
14
+ #~ has_many :credits, :class_name => 'Entry', :foreign_key => 'credit_id'
15
+
16
+ def self.build_table_model( model_builder )
17
+ model_builder.instance_exec do
18
+ read_only!
18
19
  plain :date
19
20
  plain :description
20
21
  plain :debit
@@ -31,12 +31,14 @@
31
31
  <p><a href="rdoc">RDoc</a> | <a href="http://rubyforge.org/projects/clevic/">Rubyforge Project</a></p>
32
32
 
33
33
 
34
- <p>Code for inimal UI definition</p>
34
+ <p>Code for minimal UI definition</p>
35
35
 
36
36
 
37
37
  <pre><code>
38
38
  require 'clevic.rb'
39
39
 
40
+ # see sql/accounts.sql for schema
41
+
40
42
  # db connection
41
43
  Clevic::DbOptions.connect do
42
44
  database 'accounts_test'
@@ -85,21 +87,18 @@ class Entry < Clevic::Record
85
87
  belongs_to :debit, :class_name => 'Account', :foreign_key => 'debit_id'
86
88
  belongs_to :credit, :class_name => 'Account', :foreign_key => 'credit_id'
87
89
 
88
- # define how fields will be displayed
89
- def self.ui( parent )
90
- Clevic::TableView.new( self, parent ).create_model do
91
- plain :date, :sample => '88-WWW-99'
92
- distinct :description, :conditions => "now() - date <= '1 year'", :sample => 'm' * 26
93
- relational :debit, :display => 'name', :conditions => 'active = true', :order => 'lower(name)', :sample => 'Leilani Member Loan'
94
- relational :credit, :display => 'name', :conditions => 'active = true', :order => 'lower(name)', :sample => 'Leilani Member Loan'
95
- plain :amount, :sample => 999999.99
96
- distinct :category
97
- plain :cheque_number
98
- plain :active, :sample => 'WW'
99
- plain :vat, :label => 'VAT', :sample => 'WW', :tooltip => 'Does this include VAT?'
100
-
101
- records :order => 'date, id'
102
- end
90
+ define_ui do
91
+ plain :date, :sample => '88-WWW-99'
92
+ distinct :description, :conditions => "now() - date <= '1 year'", :sample => 'm' * 26
93
+ relational :debit, :display => 'name', :conditions => 'active = true', :order => 'lower(name)', :sample => 'Leilani Member Loan'
94
+ relational :credit, :display => 'name', :conditions => 'active = true', :order => 'lower(name)', :sample => 'Leilani Member Loan'
95
+ plain :amount, :sample => 999999.99
96
+ distinct :category
97
+ plain :cheque_number
98
+ plain :active, :sample => 'WW'
99
+ plain :vat, :label => 'VAT', :sample => 'WW', :tooltip => 'Does this include VAT?'
100
+
101
+ records :order => 'date, id'
103
102
  end
104
103
 
105
104
  # called when data is changed in the UI
@@ -151,17 +150,15 @@ class Account < Clevic::Record
151
150
  has_many :credits, :class_name => 'Entry', :foreign_key => 'credit_id'
152
151
 
153
152
  # define how fields are displayed
154
- def self.ui( parent )
155
- Clevic::TableView.new( self, parent ).create_model do
156
- plain :name
157
- restricted :vat, :label => 'VAT', :set => %w{ yes no all }
158
- plain :account_type
159
- plain :pastel_number, :alignment => Qt::AlignRight, :label => 'Pastel'
160
- plain :fringe, :format => "%.1f"
161
- plain :active
162
-
163
- records :order => 'name,account_type'
164
- end
153
+ define_ui do
154
+ plain :name
155
+ restricted :vat, :label => 'VAT', :set => %w{ yes no all }
156
+ plain :account_type
157
+ plain :pastel_number, :alignment => Qt::AlignRight, :label => 'Pastel'
158
+ plain :fringe, :format => "%.1f"
159
+ plain :active
160
+
161
+ records :order => 'name,account_type'
165
162
  end
166
163
  end
167
164
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clevic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Anderson
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-07-25 00:00:00 +02:00
12
+ date: 2008-08-21 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 0.4.1
23
+ version: 0.5.0
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activerecord
@@ -85,6 +85,7 @@ files:
85
85
  - lib/clevic/delegates.rb
86
86
  - lib/clevic/extensions.rb
87
87
  - lib/clevic/field.rb
88
+ - lib/clevic/field_builder.rb
88
89
  - lib/clevic/item_delegate.rb
89
90
  - lib/clevic/model_builder.rb
90
91
  - lib/clevic/model_column.rb