bowtie 0.3 → 0.3.1

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.
data/bowtie.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  Gem::Specification.new do |s|
3
3
  s.name = %q{bowtie}
4
- s.version = "0.3"
4
+ s.version = "0.3.1"
5
5
 
6
6
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
7
7
  s.authors = ["Tomás Pollak"]
data/lib/bowtie/admin.rb CHANGED
@@ -67,7 +67,7 @@ module Bowtie
67
67
  end
68
68
 
69
69
  post "/:model" do
70
- @resource = model.create(params[:resource].normalize)
70
+ @resource = model.create(params[:resource].prepare_for_query(model))
71
71
  if @resource.valid? and @resource.save
72
72
  redirect "/#{model.pluralize}?notice=created"
73
73
  else
@@ -94,11 +94,15 @@ module Bowtie
94
94
  end
95
95
 
96
96
  put "/:model/:id" do
97
- if resource.update(params[:resource].normalize)
98
- request.xhr? ? resource.to_json : redirect("/#{model.pluralize}/#{params[:id]}?notice=saved")
99
- else
100
- if request.xhr?
97
+ if request.xhr? # dont pass through hooks or put the boolean stuff
98
+ if resource.update!(params[:resource].filter_inaccessible_in(model).normalize)
99
+ resource.to_json
100
+ else
101
101
  false
102
+ end
103
+ else # normal request
104
+ if resource.update(params[:resource].prepare_for_query(model))
105
+ redirect("/#{model.pluralize}/#{params[:id]}?notice=updated")
102
106
  else
103
107
  @resource = resource
104
108
  erb :show
@@ -20,6 +20,14 @@ class Class
20
20
  self.to_s.pluralize
21
21
  end
22
22
 
23
+ def field_names
24
+ self.properties.collect{|p| p.name }
25
+ end
26
+
27
+ def boolean_fields
28
+ self.properties.map{|a| a.name if a.class == DataMapper::Property::Boolean}.compact
29
+ end
30
+
23
31
  def searchable_fields
24
32
  self.properties.map{|a| a.name if a.class == DataMapper::Property::String}.compact
25
33
  end
@@ -45,10 +53,29 @@ end
45
53
 
46
54
  class Hash
47
55
 
56
+ def prepare_for_query(model)
57
+ self.filter_inaccessible_in(model).include_missing_booleans_in(model).normalize
58
+ end
59
+
60
+ def filter_inaccessible_in(model)
61
+ fields = model.field_names
62
+ self.delete_if { |key,val| !fields.include?(key.to_sym) }
63
+ end
64
+
65
+ def include_missing_booleans_in(model)
66
+ model.boolean_fields.each do |bool|
67
+ self[bool] = false unless self.has_key?(bool.to_s)
68
+ end
69
+ self
70
+ end
71
+
48
72
  # this is for checkboxes which give us a param of 'on' on the params hash
49
73
  def normalize
74
+ replacements = { 'on' => true, '' => nil}
50
75
  normalized = {}
51
- self.each_pair {|k,v| normalized[k] = v == 'on' ? true : v }
76
+ self.each_pair do |key,val|
77
+ normalized[key] = replacements.has_key?(val) ? replacements[val] : val
78
+ end
52
79
  normalized
53
80
  end
54
81
 
@@ -141,10 +141,6 @@ table{
141
141
  text-align: left;
142
142
  }
143
143
 
144
- table tr:hover{
145
- background: #efefef;
146
- }
147
-
148
144
  table tr td, table tr th {
149
145
  border:1px solid #ccc;
150
146
  padding:6px;
@@ -187,21 +183,35 @@ table .check-column{
187
183
  text-align: center;
188
184
  }
189
185
 
190
- table tr.good{
191
- /* background: green;*/
186
+ table tr.active,
187
+ table tr.enabled{
188
+ border-left: 5px solid #528e00;
189
+ }
190
+
191
+ table tr.active td,
192
+ table tr.enabled td{
193
+ background: #ebf9eb;
192
194
  }
193
195
 
194
- table tr.bad td, table .error{
196
+ table tr.cancelled,
197
+ table tr.disabled,
198
+ table tr.suspended{
199
+ border-left: 5px solid #a00;
200
+ }
201
+
202
+ table tr.cancelled td,
203
+ table tr.disabled td,
204
+ table tr.suspended td{
195
205
  /* background-color: #fbf5dc;*/
196
206
  background-color: #FFEFEF;
197
207
  }
198
208
 
199
209
  table th.rel{
200
210
  background: #999;
201
- color: #fff
211
+ color: #fff;
202
212
  }
203
213
  table td.rel {
204
- background: #fafafa;
214
+ background: #eee;
205
215
  }
206
216
 
207
217
  table .icon{
@@ -211,6 +221,10 @@ table .icon{
211
221
  margin-top: -3px;
212
222
  }
213
223
 
224
+ table tr:hover td{
225
+ background: #ffffed;
226
+ }
227
+
214
228
  /* forms
215
229
  -------------------------------------------------------------*/
216
230
 
@@ -2,7 +2,11 @@
2
2
 
3
3
  html =''
4
4
  name = @p.name.to_s
5
- value = @resource.send(@p.name).to_s
5
+ begin
6
+ value = @resource.send(@p.name)
7
+ rescue NoMethodError
8
+ value = ''
9
+ end
6
10
 
7
11
  case @p.class.to_s.gsub("DataMapper::Property::",'')
8
12
  when "Array", /Class/ # weird how datamapper names enum classes
@@ -13,10 +17,10 @@
13
17
  end
14
18
  html += '</select>'
15
19
  when "TrueClass", "FalseClass", /Boolean/
16
- checked = (value == 'n' || value.blank?) ? '' : 'checked="checked"'
20
+ checked = value == true ? 'checked="checked"' : ''
17
21
  html += '<input name="resource['+name+']" type="checkbox" '+checked+' />'
18
22
  else
19
- html += '<input class="string" type="text" name="resource['+name+']" value="'+value+'" />'
23
+ html += '<input class="string" type="text" name="resource['+name+']" value="'+value.to_s+'" />'
20
24
  end
21
25
  html
22
26
 
@@ -8,7 +8,7 @@
8
8
  <% unless [:created_at, :id].include?(p.name) %>
9
9
  <% @p = p %>
10
10
  <tr>
11
- <td class="left-col"><%= p.name.to_s.titleize %> <small>(<%= p.class.name.to_s.gsub("DataMapper::Property::",'') %>)</small></td>
11
+ <td class="left-col"><%= p.name.to_s.titleize %> <small>(<%= p.class.name.to_s.gsub("DataMapper::Property::",'') || 'Enum' %>)</small></td>
12
12
  <td class="right-col"><%= partial(:field) %></td>
13
13
  </tr>
14
14
  <% end %>
@@ -1,4 +1,4 @@
1
- <tr id="resource-<%= @r.key.first.to_s %>" class="<%= @r.ok? ? 'good' : 'bad' if @r.respond_to?('ok?') %>">
1
+ <tr id="resource-<%= @r.key.first.to_s %>" class="<%= @r.state.to_s if @r.respond_to?(:state) %>">
2
2
  <td class="<%= @model.key.first.name.to_s %>-col"><a href="<%= url_for(@r) %>"><%= @r.key.first.to_s %></a></td>
3
3
  <% @r.attributes.each do |a| %>
4
4
  <% next if a[0] == @model.key.first.name %>
metadata CHANGED
@@ -5,7 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- version: "0.3"
8
+ - 1
9
+ version: 0.3.1
9
10
  platform: ruby
10
11
  authors:
11
12
  - "Tom\xC3\xA1s Pollak"