clevic 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/times_models.rb ADDED
@@ -0,0 +1,163 @@
1
+ require 'clevic.rb'
2
+
3
+ # db connection options
4
+ $options ||= {}
5
+ $options[:database] ||= $options[:debug] ? 'times_test' : 'times'
6
+ $options[:adapter] ||= 'postgresql'
7
+ $options[:host] ||= 'localhost'
8
+ $options[:username] ||= 'panic'
9
+ $options[:password] ||= ''
10
+
11
+ # model definitions
12
+ class Entry < ActiveRecord::Base
13
+ include ActiveRecord::Dirty
14
+ belongs_to :invoice
15
+ belongs_to :activity
16
+ belongs_to :project
17
+
18
+ # define how fields are displayed
19
+ def self.ui( parent )
20
+ Clevic::TableView.new( self, parent ).create_model do
21
+ plain :date, :sample => '28-Dec-08'
22
+ relational :project, 'project', :conditions => 'active = true', :order => 'lower(project)'
23
+ relational :invoice, 'invoice_number', :conditions => "status = 'not sent'", :order => 'invoice_number'
24
+ plain :start
25
+ plain :end
26
+ plain :description, :sample => 'This is a long string designed to hold lots of data and description'
27
+ relational :activity, 'activity', :order => 'lower(activity)', :sample => 'Troubleshooting', :conditions => 'active = true'
28
+ distinct :module, :tooltip => 'Module or sub-project'
29
+ plain :charge, :tooltip => 'Is this time billable?'
30
+ distinct :person, :tooltip => 'The person who did the work'
31
+
32
+ records :order => 'date, start, id'
33
+ end
34
+ end
35
+
36
+ # called when a key is pressed in this model's table view
37
+ def self.key_press_event( event, current_index, view )
38
+ case
39
+ # copy almost all of the previous line
40
+ when event.ctrl? && event.quote_dbl?
41
+ if current_index.row > 1
42
+ # fetch previous item
43
+ model = current_index.model
44
+ previous_item = model.collection[current_index.row - 1]
45
+
46
+ # copy the relevant fields
47
+ current_index.entity.start = previous_item.end
48
+ [:date, :project, :invoice, :activity, :module, :charge, :person].each do |attr|
49
+ current_index.entity.send( "#{attr.to_s}=", previous_item.send( attr ) )
50
+ end
51
+
52
+ # tell view to update
53
+ top_left_index = model.create_index( current_index.row, 0 )
54
+ bottom_right_index = model.create_index( current_index.row, current_index.column + view.builder.fields.size )
55
+ view.dataChanged( top_left_index, bottom_right_index )
56
+
57
+ # move to end time field
58
+ view.override_next_index( model.create_index( current_index.row, view.builder.index( :end ) ) )
59
+ end
60
+ # don't let anybody else handle the keypress
61
+ return true
62
+
63
+ when event.ctrl? && event.i?
64
+ invoice_from_project( current_index, view )
65
+ # don't let anybody else handle the keypress
66
+ return true
67
+ end
68
+ end
69
+
70
+ # called when data is changed in this model's table view
71
+ def self.data_changed( top_left, bottom_right, view )
72
+ invoice_from_project( top_left, view ) if ( top_left == bottom_right )
73
+ end
74
+
75
+ def self.invoice_from_project( current_index, view )
76
+ # auto-complete invoice number field from project
77
+ current_field = current_index.attribute
78
+ if current_field == :project && current_index.entity.project != nil
79
+ # most recent entry, ordered in reverse
80
+ invoice = current_index.entity.project.latest_invoice
81
+
82
+ unless invoice.nil?
83
+ # make a reference to the invoice
84
+ current_index.entity.invoice = invoice
85
+
86
+ # update view from top_left to bottom_right
87
+ model = current_index.model
88
+ changed_index = model.create_index( current_index.row, view.builder.index( :invoice ) )
89
+ view.dataChanged( changed_index, changed_index )
90
+
91
+ # move edit cursor to start time field
92
+ view.override_next_index( model.create_index( current_index.row, view.builder.index( :start ) ) )
93
+ end
94
+ end
95
+ end
96
+ end
97
+
98
+ class Project < ActiveRecord::Base
99
+ include ActiveRecord::Dirty
100
+ has_many :entries
101
+
102
+ def self.ui( parent )
103
+ Clevic::TableView.new( Project, parent ).create_model do
104
+ plain :project
105
+ plain :description
106
+ distinct :client
107
+ plain :rate
108
+ plain :active
109
+
110
+ records :order => 'project'
111
+ end
112
+ end
113
+
114
+ # Return the latest invoice for this project
115
+ # Not part of the UI.
116
+ def latest_invoice
117
+ Invoice.find(
118
+ :first,
119
+ :conditions => ["client = ? and status = 'not sent'", self.client],
120
+ :order => 'invoice_number desc'
121
+ )
122
+ end
123
+
124
+ end
125
+
126
+ class Activity < ActiveRecord::Base
127
+ include ActiveRecord::Dirty
128
+ has_many :entries
129
+
130
+ # define how fields are displayed
131
+ def self.ui( parent )
132
+ Clevic::TableView.new( Activity, parent ).create_model do
133
+ plain :activity
134
+ plain :active
135
+
136
+ records :order => 'activity'
137
+ end
138
+ end
139
+ end
140
+
141
+ class Invoice < ActiveRecord::Base
142
+ include ActiveRecord::Dirty
143
+ has_many :entries
144
+
145
+ # define how fields are displayed
146
+ def self.ui( parent )
147
+ Clevic::TableView.new( Invoice, parent ).create_model do
148
+ plain :date
149
+ distinct :client, :frequency => true
150
+ plain :invoice_number
151
+ restricted :status, :set => ['not sent', 'sent', 'paid', 'debt', 'writeoff', 'internal']
152
+ restricted :billing, :set => %w{Hours Quote Internal}
153
+ plain :quote_date
154
+ plain :quote_amount
155
+ plain :description
156
+
157
+ records :order => 'invoice_number'
158
+ end
159
+ end
160
+ end
161
+
162
+ # tab widget order
163
+ $options[:models] = [ Entry, Invoice, Project, Activity ]
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: clevic
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.1
5
+ platform: ruby
6
+ authors:
7
+ - John Anderson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-06-26 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.5.1
23
+ version:
24
+ description: Database framework and Qt Model/View GUI for data capture and editing of tables in a pre-existing relational DBMS. Thanks to ActiveRecord, Postgresql, Mysql and so on are supported. Has only been tested with Postgres. There is a mild focus on reducing keystrokes for repetitive data capture, so it provides nice keyboard shortcuts for all sorts of things. Model (table) objects are extensible to allow for model (table) specific cleverness, like auto-filling-in of fields.
25
+ email: john at semiosix dot com
26
+ executables:
27
+ - clevic
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - History.txt
32
+ - Manifest.txt
33
+ - README.txt
34
+ files:
35
+ - History.txt
36
+ - INSTALL
37
+ - Manifest.txt
38
+ - README.txt
39
+ - Rakefile
40
+ - TODO
41
+ - accounts_models.rb
42
+ - bin/clevic
43
+ - lib/active_record/dirty.rb
44
+ - lib/clevic.rb
45
+ - lib/clevic/browser.rb
46
+ - lib/clevic/cache_table.rb
47
+ - lib/clevic/db_options.rb
48
+ - lib/clevic/delegates.rb
49
+ - lib/clevic/extensions.rb
50
+ - lib/clevic/field.rb
51
+ - lib/clevic/item_delegate.rb
52
+ - lib/clevic/model_builder.rb
53
+ - lib/clevic/model_column.rb
54
+ - lib/clevic/search_dialog.rb
55
+ - lib/clevic/table_model.rb
56
+ - lib/clevic/table_view.rb
57
+ - lib/clevic/ui/browser.ui
58
+ - lib/clevic/ui/browser_ui.rb
59
+ - lib/clevic/ui/icon.png
60
+ - lib/clevic/ui/search_dialog.ui
61
+ - lib/clevic/ui/search_dialog_ui.rb
62
+ - sql/accounts.sql
63
+ - sql/times.sql
64
+ - times_models.rb
65
+ has_rdoc: true
66
+ homepage: http://www.rubyforge.org/clevic
67
+ post_install_message:
68
+ rdoc_options:
69
+ - --main
70
+ - README.txt
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: "0"
84
+ version:
85
+ requirements: []
86
+
87
+ rubyforge_project: clevic
88
+ rubygems_version: 1.1.0
89
+ signing_key:
90
+ specification_version: 2
91
+ summary: Database framework and Qt Model/View GUI for data capture and editing of tables in a pre-existing relational DBMS
92
+ test_files: []
93
+