lore 0.4.7 → 0.4.8
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/custom_models.rb +0 -153
- data/lib/lore/behaviours/lockable.rb +27 -13
- data/lib/lore/behaviours/movable.rb +31 -13
- data/lib/lore/behaviours/paginated.rb +31 -0
- data/lib/lore/behaviours/versioned.rb +15 -3
- data/lib/lore/gui/form_generator.rb +72 -104
- data/lib/lore/gui/lore_model_select_field.rb +59 -0
- data/lore.gemspec +4 -3
- metadata +13 -27
- data/lib/lore/gui/erb_template.rb +0 -79
- data/lib/lore/gui/erb_template_helpers.rhtml +0 -19
- data/lib/lore/gui/form.rb +0 -314
- data/lib/lore/gui/form_element.rb +0 -676
- data/lib/lore/gui/templates/button.rhtml +0 -2
- data/lib/lore/gui/templates/checkbox.rhtml +0 -3
- data/lib/lore/gui/templates/checkbox_row.rhtml +0 -1
- data/lib/lore/gui/templates/file.rhtml +0 -2
- data/lib/lore/gui/templates/file_readonly.rhtml +0 -3
- data/lib/lore/gui/templates/form_element.rhtml +0 -5
- data/lib/lore/gui/templates/form_element_horizontal.rhtml +0 -3
- data/lib/lore/gui/templates/form_element_listed.rhtml +0 -8
- data/lib/lore/gui/templates/form_table.rhtml +0 -3
- data/lib/lore/gui/templates/form_table_blank.rhtml +0 -3
- data/lib/lore/gui/templates/form_table_horizontal.rhtml +0 -8
- data/lib/lore/gui/templates/password.rhtml +0 -2
- data/lib/lore/gui/templates/password_readonly.rhtml +0 -3
- data/lib/lore/gui/templates/radio.rhtml +0 -1
- data/lib/lore/gui/templates/radio_row.rhtml +0 -1
- data/lib/lore/gui/templates/select.rhtml +0 -23
- data/lib/lore/gui/templates/text.rhtml +0 -2
- data/lib/lore/gui/templates/text_readonly.rhtml +0 -3
- data/lib/lore/gui/templates/textarea.rhtml +0 -3
- data/lib/lore/gui/templates/textarea_readonly.rhtml +0 -4
data/History.txt
CHANGED
data/custom_models.rb
CHANGED
@@ -1,153 +0,0 @@
|
|
1
|
-
|
2
|
-
require('lore/model')
|
3
|
-
|
4
|
-
module Some
|
5
|
-
module App
|
6
|
-
|
7
|
-
class New_Model < Lore::Model
|
8
|
-
table :new_model, :public
|
9
|
-
primary_key :model_id, :model_id_seq
|
10
|
-
has_attribute :name, Lore::Type.integer
|
11
|
-
has_attribute :created, Lore::Type.timestamp
|
12
|
-
has_attribute :model_id, Lore::Type.integer
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
module Some
|
20
|
-
module App
|
21
|
-
|
22
|
-
class New_Model < Lore::Model
|
23
|
-
table :new_model, :public
|
24
|
-
primary_key :model_id, :model_id_seq
|
25
|
-
has_attribute :name, Lore::Type.integer
|
26
|
-
has_attribute :created, Lore::Type.timestamp
|
27
|
-
has_attribute :model_id, Lore::Type.integer
|
28
|
-
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
module Some
|
35
|
-
module App
|
36
|
-
|
37
|
-
class New_Model < Lore::Model
|
38
|
-
table :new_model, :public
|
39
|
-
primary_key :model_id, :model_id_seq
|
40
|
-
has_attribute :name, Lore::Type.integer
|
41
|
-
has_attribute :created, Lore::Type.timestamp
|
42
|
-
has_attribute :model_id, Lore::Type.integer
|
43
|
-
|
44
|
-
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
module Some
|
50
|
-
module App
|
51
|
-
|
52
|
-
class New_Model < Lore::Model
|
53
|
-
table :new_model, :public
|
54
|
-
primary_key :model_id, :model_id_seq
|
55
|
-
has_attribute :name, Lore::Type.integer
|
56
|
-
has_attribute :created, Lore::Type.timestamp
|
57
|
-
has_attribute :model_id, Lore::Type.integer
|
58
|
-
|
59
|
-
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
module Some
|
65
|
-
module App
|
66
|
-
|
67
|
-
class New_Model < Lore::Model
|
68
|
-
table :new_model, :public
|
69
|
-
primary_key :model_id, :model_id_seq
|
70
|
-
has_attribute :name, Lore::Type.integer
|
71
|
-
has_attribute :created, Lore::Type.timestamp
|
72
|
-
has_attribute :model_id, Lore::Type.integer
|
73
|
-
|
74
|
-
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
module Some
|
80
|
-
module App
|
81
|
-
|
82
|
-
class New_Model < Lore::Model
|
83
|
-
table :new_model, :public
|
84
|
-
primary_key :model_id, :model_id_seq
|
85
|
-
has_attribute :name, Lore::Type.integer
|
86
|
-
has_attribute :created, Lore::Type.timestamp
|
87
|
-
has_attribute :model_id, Lore::Type.integer
|
88
|
-
|
89
|
-
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
module Some
|
95
|
-
module App
|
96
|
-
|
97
|
-
class New_Model < Lore::Model
|
98
|
-
table :new_model, :public
|
99
|
-
primary_key :model_id, :model_id_seq
|
100
|
-
has_attribute :name, Lore::Type.integer
|
101
|
-
has_attribute :created, Lore::Type.timestamp
|
102
|
-
has_attribute :model_id, Lore::Type.integer
|
103
|
-
|
104
|
-
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
module Some
|
110
|
-
module App
|
111
|
-
|
112
|
-
class New_Model < Lore::Model
|
113
|
-
table :new_model, :public
|
114
|
-
primary_key :model_id, :model_id_seq
|
115
|
-
has_attribute :name, Lore::Type.integer
|
116
|
-
has_attribute :created, Lore::Type.timestamp
|
117
|
-
has_attribute :model_id, Lore::Type.integer
|
118
|
-
|
119
|
-
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
module Some
|
125
|
-
module App
|
126
|
-
|
127
|
-
class New_Model < Lore::Model
|
128
|
-
table :new_model, :public
|
129
|
-
primary_key :model_id, :model_id_seq
|
130
|
-
has_attribute :name, Lore::Type.integer
|
131
|
-
has_attribute :created, Lore::Type.timestamp
|
132
|
-
has_attribute :model_id, Lore::Type.integer
|
133
|
-
|
134
|
-
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
module Some
|
140
|
-
module App
|
141
|
-
|
142
|
-
class New_Model < Lore::Model
|
143
|
-
table :new_model, :public
|
144
|
-
primary_key :model_id, :model_id_seq
|
145
|
-
has_attribute :name, Lore::Type.integer
|
146
|
-
has_attribute :created, Lore::Type.timestamp
|
147
|
-
has_attribute :model_id, Lore::Type.integer
|
148
|
-
|
149
|
-
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
@@ -5,37 +5,51 @@ module Behaviours
|
|
5
5
|
module Lockable
|
6
6
|
|
7
7
|
# Defines which attribute to use for locking.
|
8
|
-
# Default is 'lock'.
|
9
8
|
# Usage:
|
10
9
|
#
|
11
|
-
#
|
12
|
-
#
|
10
|
+
# class My_Model < Lore::Model
|
11
|
+
# extend Lockable
|
12
|
+
# include Lockable_Entity
|
13
|
+
#
|
14
|
+
# # ...
|
15
|
+
# lock_by(:lock_field)
|
13
16
|
#
|
14
|
-
#
|
15
|
-
# me.user_id != $user.user_id
|
16
|
-
# }
|
17
|
+
# end
|
17
18
|
#
|
18
|
-
|
19
|
-
|
19
|
+
# my_model_entity.lock!
|
20
|
+
# # same as
|
21
|
+
# My_Model.lock!(my_model_entity)
|
22
|
+
#
|
23
|
+
def lock_by(attrib)
|
20
24
|
@lock_attr = attrib
|
21
25
|
@lock_attr_name = attrib.to_s.split('.')[-1].intern
|
22
26
|
end
|
23
27
|
|
24
28
|
def lock!(inst)
|
25
|
-
inst[@lock_attr] = true
|
29
|
+
inst.attr[@lock_attr] = true
|
26
30
|
commit
|
27
31
|
end # def
|
28
|
-
|
29
32
|
def release!(inst)
|
30
|
-
inst[@lock_attr] = false
|
33
|
+
inst.attr[@lock_attr] = false
|
31
34
|
commit
|
32
35
|
end # def
|
33
|
-
|
34
36
|
def locked?(inst)
|
35
|
-
(inst[@lock_attr] == true) || (inst[@lock_attr] == 't')
|
37
|
+
(inst.attr[@lock_attr] == true) || (inst.attr[@lock_attr] == 't')
|
36
38
|
end # def
|
37
39
|
|
38
40
|
end # module
|
39
41
|
|
42
|
+
module Lockable_Entity
|
43
|
+
def lock!
|
44
|
+
self.class.lock!(self)
|
45
|
+
end
|
46
|
+
def release!
|
47
|
+
self.class.release!(self)
|
48
|
+
end
|
49
|
+
def locked?
|
50
|
+
self.class.locked?(self)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
40
54
|
end # module
|
41
55
|
end # module
|
@@ -2,23 +2,40 @@
|
|
2
2
|
module Lore
|
3
3
|
module Behaviours
|
4
4
|
|
5
|
+
# Move an entity within a given criteria range,
|
6
|
+
# e.g. within nodes of a tree.
|
7
|
+
#
|
8
|
+
# Usage:
|
9
|
+
#
|
10
|
+
# class My_Model < Lore::Model
|
11
|
+
# extend Lore::Behaviours::Movable
|
12
|
+
# include Lore::Behaviours::Movable_Entity
|
13
|
+
# # ...
|
14
|
+
# ordered_by(:position)
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# # Will move entity to position 12 within child entries
|
18
|
+
# # of node with id 2:
|
19
|
+
# my_model_entity.move_to(12, (My_Model.parent_id == 2))
|
20
|
+
# # Same as
|
21
|
+
# My_Model.move(my_model_entity, 12, (My_Model.parent_id == 2))
|
22
|
+
#
|
5
23
|
module Movable
|
6
24
|
|
7
|
-
def ordered_by(
|
8
|
-
@order_attr =
|
9
|
-
@order_attr_name =
|
25
|
+
def ordered_by(attrib)
|
26
|
+
@order_attr = attrib
|
27
|
+
@order_attr_name = attrib.to_s.split('.')[-1].intern
|
10
28
|
end
|
11
29
|
|
12
30
|
def move(inst, sortpos, criteria)
|
13
|
-
|
14
31
|
sortpos = sortpos.to_i
|
15
32
|
return if sortpos < 1
|
16
|
-
|
33
|
+
|
34
|
+
criteria ||= Lore::Clause.new()
|
17
35
|
sortpos_old = inst.attr[@order_attr_name].to_i
|
18
36
|
|
19
37
|
# move down:
|
20
38
|
if sortpos.to_i > sortpos_old then
|
21
|
-
|
22
39
|
self.update { |na|
|
23
40
|
na.set({@order_attr_name => @order_attr-1}).where(
|
24
41
|
(criteria) &
|
@@ -26,9 +43,8 @@ module Behaviours
|
|
26
43
|
(@order_attr > sortpos_old)
|
27
44
|
)
|
28
45
|
}
|
29
|
-
|
46
|
+
# move up:
|
30
47
|
elsif sortpos.to_i < sortpos_old then
|
31
|
-
|
32
48
|
self.update { |na|
|
33
49
|
na.set({@order_attr_name => @order_attr+1}).where(
|
34
50
|
(criteria) &
|
@@ -36,19 +52,21 @@ module Behaviours
|
|
36
52
|
(@order_attr < sortpos_old)
|
37
53
|
)
|
38
54
|
}
|
39
|
-
|
40
55
|
end
|
41
|
-
|
56
|
+
# In case we actually had to move the entity:
|
42
57
|
if sortpos != sortpos_old then
|
43
|
-
|
44
58
|
inst.set_attribute_value(@order_attr_name, sortpos)
|
45
59
|
inst.commit()
|
46
|
-
|
47
60
|
end
|
48
|
-
|
49
61
|
end # def
|
50
62
|
|
51
63
|
end # module
|
52
64
|
|
65
|
+
module Movable_Entity
|
66
|
+
def move_to(position, criteria=nil)
|
67
|
+
self.class.move(self, position, criteria)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
53
71
|
end # module
|
54
72
|
end # module
|
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
module Lore
|
3
|
+
module Behaviours
|
4
|
+
|
5
|
+
|
6
|
+
# Usage:
|
7
|
+
#
|
8
|
+
# class My_Model < Lore::Model
|
9
|
+
# extend Lore::Behaviours::Paginated
|
10
|
+
#
|
11
|
+
# def self.search(search, page)
|
12
|
+
# paginate(:per_page => 10,
|
13
|
+
# :page => page,
|
14
|
+
# :filter => all_with(search).order_by(:name, :desc))
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# first_page_entities => My_Model.search((My_Model.attribute == 'foo'), 1)
|
20
|
+
#
|
21
|
+
module Paginated
|
22
|
+
|
23
|
+
def paginate(params)
|
24
|
+
entities = params[:filter].limit(params[:per_page], params[:page]).entities
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
@@ -2,20 +2,32 @@
|
|
2
2
|
module Lore
|
3
3
|
module Behaviours
|
4
4
|
|
5
|
+
# Usage:
|
6
|
+
#
|
7
|
+
# class My_Model < Lore::Model
|
8
|
+
# extend Lore::Behaviours::Versioned
|
9
|
+
# # ...
|
10
|
+
# version_by :version_number
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# my_model_entity.foo = 'bar'
|
14
|
+
# my_model_entity.commit # Will create a new version
|
15
|
+
#
|
5
16
|
module Versioned
|
6
17
|
|
7
18
|
# Defines attribute the version number is stored in.
|
8
19
|
# Default is 'version'.
|
9
|
-
def version_by(attrib)
|
20
|
+
def version_by(attrib=:version)
|
10
21
|
@version_attr = attrib
|
11
22
|
@version_attr_name = attrib.to_s.split('.')[-1].intern
|
12
23
|
end
|
13
24
|
|
14
25
|
# Overloads commit so it increments the version attribute
|
15
|
-
# before saving instance to database
|
26
|
+
# before saving instance to database and creates a new
|
27
|
+
# entity with incremented version instead.
|
16
28
|
def commit()
|
17
29
|
set_attribute_value(@version_attr, self.attr[@version_attr].to_i + 1)
|
18
|
-
|
30
|
+
create(self.attr)
|
19
31
|
end
|
20
32
|
|
21
33
|
end # module
|
@@ -1,151 +1,119 @@
|
|
1
1
|
|
2
|
-
require('
|
3
|
-
|
2
|
+
require('aurita')
|
3
|
+
Aurita.import_module :gui, :module
|
4
|
+
Aurita.import_module :gui, :model_select_field
|
4
5
|
|
5
6
|
module Lore
|
6
7
|
module GUI
|
7
8
|
|
9
|
+
# A factory rendering Aurita::GUI:Form instances for
|
10
|
+
# Aurita::Model classes.
|
11
|
+
#
|
8
12
|
# Usage:
|
9
|
-
#
|
10
|
-
# generator =
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
13
|
+
#
|
14
|
+
# generator = Lore_Form_Generator.new(Some_Lore_Model)
|
15
|
+
# generator.params = { :action => '/aurita/dispatch', :onsubmit => "alert('submitting'); " }
|
16
|
+
# generator.generate
|
17
|
+
# puts generator.form
|
14
18
|
#
|
15
|
-
class Form_Generator
|
19
|
+
class Form_Generator
|
16
20
|
|
17
|
-
|
18
|
-
|
19
|
-
@logger = Lore.logger
|
20
|
-
@form = Form.new()
|
21
|
-
@labels = labels
|
22
|
-
@klass = klass
|
23
|
-
@custom_elements = custom_elements
|
21
|
+
attr_reader :form, :klass
|
22
|
+
attr_accessor :custom_elements, :labels, :params
|
24
23
|
|
25
|
-
|
24
|
+
def initialize(klass=nil)
|
25
|
+
@klass = klass
|
26
|
+
@labels = {}
|
27
|
+
@params = {}
|
28
|
+
@custom_elements = {}
|
29
|
+
@form = false
|
30
|
+
end
|
26
31
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
@logger.debug('GET_ATTRIBUTES: ' << @klass.get_attributes.inspect)
|
32
|
-
@klass.get_attributes.each_pair { |table, attributes|
|
32
|
+
def form
|
33
|
+
generate() unless @form
|
34
|
+
@form
|
35
|
+
end
|
33
36
|
|
34
|
-
|
35
|
-
|
36
|
-
attributes.each { |attrib|
|
37
|
+
def generate
|
38
|
+
@form = Aurita::GUI::Form.new(@params)
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
@klass.get_attributes.each_pair { |table, attributes|
|
41
|
+
attributes.each { |attribute|
|
42
|
+
label_tag = table.gsub('.','--') << '--' << attribute
|
43
|
+
label = @labels[label_tag]
|
44
|
+
label ||= label_tag
|
45
|
+
full_attrib = table + '.' << attribute
|
46
|
+
field_name = full_attrib.gsub('.','_')
|
47
|
+
form_element = false
|
44
48
|
|
45
49
|
# @custom_elements is a hash mapping attribute names to
|
46
50
|
# Custom_Element instances.
|
47
51
|
if ((@custom_elements[table]) and
|
48
|
-
(@custom_elements[table][
|
52
|
+
(@custom_elements[table][attribute])) then
|
49
53
|
|
50
|
-
form_element = @custom_elements[table][
|
51
|
-
form_element.mode = mode
|
52
|
-
@form.add(form_element)
|
54
|
+
form_element = @custom_elements[table][attribute].new(table, attribute, label)
|
53
55
|
|
54
|
-
elsif (@klass.get_primary_keys[table].nil? or
|
55
|
-
!@klass.get_primary_keys[table].include?
|
56
|
-
(@klass.get_implicit_attributes[table].nil? or
|
57
|
-
!@klass.get_implicit_attributes[table].include?
|
58
|
-
(@klass.get_has_a_klasses.nil? or
|
59
|
-
@klass.get_has_a_klasses[table+'.'+
|
60
|
-
(@klass.get_hidden_attributes[table].nil? or
|
61
|
-
!@klass.get_hidden_attributes[table].include?
|
56
|
+
elsif (@klass.get_primary_keys[table].nil? or # Ignore primary key attributes
|
57
|
+
!@klass.get_primary_keys[table].include? attribute) and
|
58
|
+
(@klass.get_implicit_attributes[table].nil? or # Ignore implicit attributes
|
59
|
+
!@klass.get_implicit_attributes[table].include? attribute) and
|
60
|
+
(@klass.get_has_a_klasses.nil? or # Ignore attributes aggregated via has_a associations (added later)
|
61
|
+
@klass.get_has_a_klasses[table+'.'+attribute].nil?) and
|
62
|
+
(@klass.get_hidden_attributes[table].nil? or # Ignore otherwise hidden attributes
|
63
|
+
!@klass.get_hidden_attributes[table].include? attribute)
|
62
64
|
then
|
63
|
-
|
64
|
-
case @klass.get_attribute_types[table][
|
65
|
-
|
65
|
+
# Attribute has to be added to form, according to data type
|
66
|
+
case @klass.get_attribute_types[table][attribute]
|
66
67
|
when Lore::PG_BOOL
|
67
|
-
form_element =
|
68
|
+
form_element = Radio_Field.new(:label => label,
|
69
|
+
:name => field_name,
|
70
|
+
:options => { 't' => 'yes', 'f' => 'no' } )
|
68
71
|
|
69
72
|
when Lore::PG_SMALLINT || Lore::PG_INT
|
70
|
-
form_element =
|
71
|
-
|
73
|
+
form_element = Input_Field.new(:label => label, :name => field_name)
|
72
74
|
when Lore::PG_VARCHAR
|
73
|
-
form_element =
|
74
|
-
if (!@klass.get_maxlength.nil? &&
|
75
|
-
!@klass.get_maxlength[table].nil? &&
|
76
|
-
!@klass.get_maxlength[table][attrib.intern].nil?) then
|
77
|
-
form_element.set_length(@klass.get_maxlength[table][attrib.intern])
|
78
|
-
end
|
79
|
-
|
75
|
+
form_element = Input_Field.new(:label => label, :name => field_name)
|
80
76
|
when Lore::PG_TEXT
|
81
|
-
form_element =
|
82
|
-
if (!@klass.get_maxlength.nil? &&
|
83
|
-
!@klass.get_maxlength[table].nil? &&
|
84
|
-
!@klass.get_maxlength[table][attrib.intern].nil?) then
|
85
|
-
form_element.set_length(@klass.get_maxlength[table][attrib.intern])
|
86
|
-
end
|
87
|
-
|
77
|
+
form_element = Textarea_Field.new(:label => label, :name => field_name)
|
88
78
|
when Lore::PG_TIMESTAMP_TIMEZONE
|
89
|
-
form_element =
|
90
|
-
|
79
|
+
form_element = Datetime_Field.new(:label => label, :name => field_name, :date_format => 'dmy', :time_format => 'hms', :year_range => (2009..2020))
|
91
80
|
when Lore::PG_DATE
|
92
|
-
form_element =
|
93
|
-
|
81
|
+
form_element = Date_Field.new(:label => label, :name => field_name, :date_format => 'dmy', :year_range => (2009..2020))
|
94
82
|
else
|
95
|
-
form_element =
|
83
|
+
form_element = Input_Field.new(:label => label, :name => field_name)
|
96
84
|
end
|
97
|
-
|
98
|
-
form_element.set_mode(mode)
|
99
|
-
@form.add(form_element)
|
100
|
-
|
85
|
+
|
101
86
|
elsif (!@klass.get_has_a_klasses.nil? and
|
102
|
-
!@klass.get_has_a_klasses[
|
87
|
+
!@klass.get_has_a_klasses[full_attrib].nil?)
|
103
88
|
then
|
104
|
-
foreign_klass = @klass.get_has_a_klasses[
|
105
|
-
|
106
|
-
|
107
|
-
form_element = Klass_Select.new(foreign_klass, table, attrib, label)
|
108
|
-
form_element.set_mode(mode)
|
109
|
-
@form.add(form_element)
|
110
|
-
|
89
|
+
foreign_klass = @klass.get_has_a_klasses[full_attrib]
|
90
|
+
form_element = Model_Select_Field.new(foreign_klass, :label => label, :name => field_name)
|
91
|
+
|
111
92
|
elsif (!@klass.get_aggregate_klasses.nil? and
|
112
|
-
!@klass.get_aggregate_klasses[
|
93
|
+
!@klass.get_aggregate_klasses[full_attrib].nil?)
|
113
94
|
then
|
114
|
-
foreign_klass = @klass.get_aggregate_klasses[
|
115
|
-
|
116
|
-
|
117
|
-
form_element = Klass_Select.new(foreign_klass, table, attrib, label)
|
118
|
-
form_element.set_mode(mode)
|
119
|
-
@form.add(form_element)
|
95
|
+
foreign_klass = @klass.get_aggregate_klasses[full_attrib]
|
96
|
+
form_element = Model_Select_Field.new(foreign_klass, :label => label, :name => field_name)
|
120
97
|
|
121
98
|
# Attribute is explixit (expected/required) but not
|
122
99
|
# catched before -> Add attribute as hidden field:
|
123
100
|
elsif (!@klass.get_explicit_attributes[table].nil? and
|
124
|
-
@klass.get_explicit_attributes[table].include?
|
101
|
+
@klass.get_explicit_attributes[table].include? attribute)
|
125
102
|
then
|
126
|
-
form_element =
|
127
|
-
|
128
|
-
|
103
|
+
form_element = Hidden_Field.new(:name => field_name)
|
104
|
+
|
129
105
|
elsif (!@klass.get_implicit_attributes[table].nil? and
|
130
|
-
@klass.get_implicit_attributes[table].include?
|
106
|
+
@klass.get_implicit_attributes[table].include? attribute)
|
131
107
|
then
|
132
|
-
|
133
|
-
|
108
|
+
# Implicit field, ignored
|
134
109
|
end
|
135
|
-
|
110
|
+
|
111
|
+
@form.add(form_element) if form_element
|
136
112
|
}
|
137
113
|
}
|
138
|
-
end
|
114
|
+
end
|
139
115
|
|
140
|
-
# Returns instance of Cuba::GUI::Form configured
|
141
|
-
# for klass passed in constructor:
|
142
|
-
def generate() # {{{
|
143
|
-
return @form
|
144
|
-
end # }}}
|
145
|
-
|
146
116
|
end # class
|
147
117
|
|
148
|
-
|
149
118
|
end # module
|
150
119
|
end # module
|
151
|
-
|
@@ -0,0 +1,59 @@
|
|
1
|
+
|
2
|
+
require('aurita-gui/form/select_field')
|
3
|
+
|
4
|
+
module Aurita
|
5
|
+
module GUI
|
6
|
+
|
7
|
+
class Lore_Model_Select_Field < Select_Field
|
8
|
+
|
9
|
+
def initialize(model, params, &block)
|
10
|
+
@model = model
|
11
|
+
@filter = params[:filter]
|
12
|
+
@filter ||= true
|
13
|
+
if block_given? then
|
14
|
+
@select_block = block
|
15
|
+
else
|
16
|
+
@select_block = Proc.new { |clause| clause.where(@filter) }
|
17
|
+
end
|
18
|
+
params.delete(:filter)
|
19
|
+
super(params)
|
20
|
+
end
|
21
|
+
|
22
|
+
def option_elements
|
23
|
+
elements = []
|
24
|
+
options = []
|
25
|
+
|
26
|
+
foreign_table = @model.table_name
|
27
|
+
selectables = @model.select(&@select_block)
|
28
|
+
selectables.each { |foreign|
|
29
|
+
foreign_label = ''
|
30
|
+
if @model.get_labels.nil? then
|
31
|
+
raise Aurita::GUI::Form_Error.new('Specify a label for has_a - related model klasses (here: ' << @model.to_s + ') via "use_label".')
|
32
|
+
end
|
33
|
+
@model.get_labels.each { |label_attrib|
|
34
|
+
foreign_label << foreign.get_attribute_values[foreign_table][label_attrib.split('.')[-1]].to_s << ' '
|
35
|
+
}
|
36
|
+
|
37
|
+
@model.get_primary_keys[foreign_table].uniq.each { |keys|
|
38
|
+
key_string = ''
|
39
|
+
keys.each { |key|
|
40
|
+
# concatenate combined primary keys like 'id--id2' -> '3--4'
|
41
|
+
if key_string != '' then key_string << '--' end
|
42
|
+
key_string << foreign.get_attribute_values[foreign_table][key]
|
43
|
+
}
|
44
|
+
options << { key_string => foreign_label }
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
options.each { |map|
|
49
|
+
map.each_pair { |k,v|
|
50
|
+
elements << HTML.option(:value => k) { v }
|
51
|
+
}
|
52
|
+
}
|
53
|
+
elements
|
54
|
+
end
|
55
|
+
|
56
|
+
end # class
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
data/lore.gemspec
CHANGED
@@ -16,12 +16,13 @@ spec = Gem::Specification.new { |s|
|
|
16
16
|
high coverage of native SQL functions and features.
|
17
17
|
Lore is currently using PostgreSQL as database backend.
|
18
18
|
EOF
|
19
|
-
s.version = '0.4.
|
19
|
+
s.version = '0.4.8'
|
20
20
|
s.author = 'Tobias Fuchs'
|
21
21
|
s.email = 'fuchs@atomnode.net'
|
22
22
|
s.date = Time.now
|
23
23
|
s.files = '*.rb'
|
24
24
|
s.add_dependency('postgres', '>= 0.1')
|
25
|
+
s.add_dependency('aurita-gui', '>= 0.1')
|
25
26
|
s.files = FileList['*',
|
26
27
|
'lib/*',
|
27
28
|
'lib/lore/*',
|
@@ -36,8 +37,8 @@ spec = Gem::Specification.new { |s|
|
|
36
37
|
|
37
38
|
s.has_rdoc = true
|
38
39
|
s.rdoc_options << '--title' << 'Lore ORM' <<
|
39
|
-
|
40
|
-
|
40
|
+
'--main' << 'Lore::Model' <<
|
41
|
+
'--line-numbers'
|
41
42
|
|
42
43
|
s.homepage = 'http://lore.rubyforge.org'
|
43
44
|
|