typus 3.0.4 → 3.0.5
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/Gemfile +36 -18
- data/Gemfile.lock +17 -16
- data/README.md +26 -4
- data/Rakefile +3 -0
- data/app/controllers/admin/resources_controller.rb +27 -18
- data/app/helpers/admin/file_preview_helper.rb +4 -4
- data/app/helpers/admin/filters_helper.rb +16 -19
- data/app/helpers/admin/list_helper.rb +20 -0
- data/app/helpers/admin/resources_helper.rb +1 -0
- data/app/helpers/admin/search_helper.rb +7 -5
- data/app/helpers/admin/table_helper.rb +9 -9
- data/app/views/admin/helpers/filters/_filters.html.erb +5 -1
- data/app/views/admin/helpers/search/_search.html.erb +6 -3
- data/app/views/admin/resources/edit.html.erb +2 -5
- data/app/views/admin/resources/index.html.erb +3 -2
- data/app/views/admin/resources/new.html.erb +2 -5
- data/app/views/admin/resources/show.html.erb +12 -8
- data/app/views/admin/templates/_has_n.html.erb +2 -2
- data/app/views/layouts/admin/base.html.erb +1 -1
- data/app/views/layouts/admin/session.html.erb +1 -1
- data/lib/support/active_record.rb +4 -14
- data/lib/support/hash.rb +10 -0
- data/lib/typus.rb +0 -1
- data/lib/typus/actions.rb +26 -12
- data/lib/typus/orm/active_record.rb +2 -2
- data/lib/typus/version.rb +1 -1
- metadata +7 -8
- data/lib/support/array.rb +0 -13
data/Gemfile
CHANGED
|
@@ -2,30 +2,48 @@ source 'http://rubygems.org'
|
|
|
2
2
|
|
|
3
3
|
gemspec
|
|
4
4
|
|
|
5
|
-
gem
|
|
6
|
-
gem
|
|
7
|
-
gem
|
|
8
|
-
gem
|
|
5
|
+
gem 'acts_as_list'
|
|
6
|
+
gem 'acts_as_tree'
|
|
7
|
+
gem 'dragonfly', '~>0.8.1'
|
|
8
|
+
gem 'factory_girl'
|
|
9
|
+
gem 'paperclip'
|
|
10
|
+
gem 'rack-cache', :require => 'rack/cache'
|
|
11
|
+
gem 'rails', '~> 3.0'
|
|
9
12
|
|
|
10
13
|
group :test do
|
|
11
|
-
gem
|
|
12
|
-
gem
|
|
14
|
+
gem 'shoulda'
|
|
15
|
+
gem 'tartare', :git => 'https://github.com/fesplugas/rails-tartare.git', :require => false
|
|
16
|
+
|
|
17
|
+
gem 'mocha'
|
|
13
18
|
end
|
|
14
19
|
|
|
15
|
-
|
|
20
|
+
group :development, :test do
|
|
16
21
|
|
|
17
|
-
|
|
18
|
-
gem
|
|
22
|
+
platforms :jruby do
|
|
23
|
+
gem 'activerecord-jdbc-adapter', :require => false
|
|
24
|
+
# gem 'activerecord-jdbcpostgresql-adapter'
|
|
25
|
+
gem 'jdbc-mysql'
|
|
26
|
+
gem 'jdbc-postgres'
|
|
27
|
+
gem 'jdbc-sqlite3'
|
|
28
|
+
end
|
|
19
29
|
|
|
20
|
-
|
|
30
|
+
platforms :ruby do
|
|
31
|
+
gem 'mysql2'
|
|
32
|
+
gem 'pg'
|
|
33
|
+
gem 'sqlite3'
|
|
34
|
+
end
|
|
21
35
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
group :production do
|
|
39
|
+
|
|
40
|
+
platforms :jruby do
|
|
41
|
+
gem 'activerecord-jdbc-adapter'
|
|
42
|
+
gem 'jdbc-sqlite3'
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
platforms :ruby do
|
|
46
|
+
gem 'sqlite3'
|
|
47
|
+
end
|
|
26
48
|
|
|
27
|
-
group :test do
|
|
28
|
-
gem "shoulda"
|
|
29
|
-
gem "tartare", :git => "https://github.com/fesplugas/rails-tartare.git", :require => false
|
|
30
|
-
gem "mocha"
|
|
31
49
|
end
|
data/Gemfile.lock
CHANGED
|
@@ -9,8 +9,8 @@ GIT
|
|
|
9
9
|
PATH
|
|
10
10
|
remote: .
|
|
11
11
|
specs:
|
|
12
|
-
typus (3.0.
|
|
13
|
-
fastercsv (
|
|
12
|
+
typus (3.0.4)
|
|
13
|
+
fastercsv (~> 1.5)
|
|
14
14
|
render_inheritable
|
|
15
15
|
will_paginate (~> 3.0.pre2)
|
|
16
16
|
|
|
@@ -48,7 +48,7 @@ GEM
|
|
|
48
48
|
acts_as_tree (0.1.1)
|
|
49
49
|
arel (2.0.7)
|
|
50
50
|
builder (2.1.2)
|
|
51
|
-
capybara (0.4.
|
|
51
|
+
capybara (0.4.1.1)
|
|
52
52
|
celerity (>= 0.7.9)
|
|
53
53
|
culerity (>= 0.2.4)
|
|
54
54
|
mime-types (>= 1.16)
|
|
@@ -56,22 +56,22 @@ GEM
|
|
|
56
56
|
rack (>= 1.0.0)
|
|
57
57
|
rack-test (>= 0.5.4)
|
|
58
58
|
selenium-webdriver (>= 0.0.27)
|
|
59
|
-
xpath (~> 0.1.
|
|
59
|
+
xpath (~> 0.1.3)
|
|
60
60
|
celerity (0.8.7)
|
|
61
61
|
childprocess (0.1.6)
|
|
62
62
|
ffi (~> 0.6.3)
|
|
63
|
-
culerity (0.2.
|
|
63
|
+
culerity (0.2.15)
|
|
64
64
|
dragonfly (0.8.2)
|
|
65
65
|
rack
|
|
66
66
|
erubis (2.6.6)
|
|
67
67
|
abstract (>= 1.0.0)
|
|
68
68
|
factory_girl (1.3.3)
|
|
69
|
-
fastercsv (1.5.
|
|
69
|
+
fastercsv (1.5.4)
|
|
70
70
|
ffi (0.6.3)
|
|
71
71
|
rake (>= 0.8.7)
|
|
72
72
|
i18n (0.5.0)
|
|
73
|
-
json_pure (1.
|
|
74
|
-
mail (2.2.
|
|
73
|
+
json_pure (1.5.1)
|
|
74
|
+
mail (2.2.15)
|
|
75
75
|
activesupport (>= 2.3.6)
|
|
76
76
|
i18n (>= 0.4.0)
|
|
77
77
|
mime-types (~> 1.16)
|
|
@@ -79,12 +79,12 @@ GEM
|
|
|
79
79
|
mime-types (1.16)
|
|
80
80
|
mocha (0.9.10)
|
|
81
81
|
rake
|
|
82
|
-
|
|
82
|
+
mysql2 (0.2.6)
|
|
83
83
|
nokogiri (1.4.4)
|
|
84
84
|
paperclip (2.3.8)
|
|
85
85
|
activerecord
|
|
86
86
|
activesupport
|
|
87
|
-
pg (0.10.
|
|
87
|
+
pg (0.10.1)
|
|
88
88
|
polyglot (0.3.1)
|
|
89
89
|
rack (1.2.1)
|
|
90
90
|
rack-cache (1.0)
|
|
@@ -116,7 +116,7 @@ GEM
|
|
|
116
116
|
json_pure
|
|
117
117
|
rubyzip
|
|
118
118
|
shoulda (2.11.3)
|
|
119
|
-
sqlite3
|
|
119
|
+
sqlite3 (1.3.3)
|
|
120
120
|
thor (0.14.6)
|
|
121
121
|
treetop (1.4.9)
|
|
122
122
|
polyglot (>= 0.3.1)
|
|
@@ -129,20 +129,21 @@ PLATFORMS
|
|
|
129
129
|
ruby
|
|
130
130
|
|
|
131
131
|
DEPENDENCIES
|
|
132
|
+
activerecord-jdbc-adapter
|
|
132
133
|
acts_as_list
|
|
133
134
|
acts_as_tree
|
|
134
135
|
dragonfly (~> 0.8.1)
|
|
135
136
|
factory_girl
|
|
136
|
-
|
|
137
|
+
jdbc-mysql
|
|
138
|
+
jdbc-postgres
|
|
139
|
+
jdbc-sqlite3
|
|
137
140
|
mocha
|
|
138
|
-
|
|
141
|
+
mysql2
|
|
139
142
|
paperclip
|
|
140
143
|
pg
|
|
141
144
|
rack-cache
|
|
142
145
|
rails (~> 3.0)
|
|
143
|
-
render_inheritable
|
|
144
146
|
shoulda
|
|
145
|
-
sqlite3
|
|
147
|
+
sqlite3
|
|
146
148
|
tartare!
|
|
147
149
|
typus!
|
|
148
|
-
will_paginate (~> 3.0.pre2)
|
data/README.md
CHANGED
|
@@ -18,8 +18,8 @@ Français, Magyar, Italiano, Portuguese, Russian, 中文)
|
|
|
18
18
|
- Integrated [paperclip][1] and [dragonfly][2] attachments viewer.
|
|
19
19
|
- Low memory footprint.
|
|
20
20
|
- Works with `Rails 3.0`.
|
|
21
|
-
- Tested with `Ruby 1.8.7-p300` and `Ruby 1.9.2-p136`.
|
|
22
|
-
- Tested with SQLite
|
|
21
|
+
- Tested with `Ruby 1.8.7-p300` and `Ruby 1.9.2-p136` and `JRuby 1.5.6`.
|
|
22
|
+
- Tested with `SQLite`, `MySQL` and `PostgreSQL`.
|
|
23
23
|
- MIT License, the same as Rails.
|
|
24
24
|
|
|
25
25
|
## Links
|
|
@@ -38,6 +38,9 @@ Add **Typus** to your `Gemfile`
|
|
|
38
38
|
|
|
39
39
|
gem 'typus', :git => 'https://github.com/fesplugas/typus.git'
|
|
40
40
|
|
|
41
|
+
# If you have problems with "Smart HTTP" use the "Git Transfer Protocol".
|
|
42
|
+
# gem 'typus', :git => 'git://github.com/fesplugas/typus.git'
|
|
43
|
+
|
|
41
44
|
Update your bundle
|
|
42
45
|
|
|
43
46
|
$ bundle install
|
|
@@ -52,9 +55,28 @@ Start the application server
|
|
|
52
55
|
|
|
53
56
|
and go to <http://0.0.0.0:3000/admin>.
|
|
54
57
|
|
|
55
|
-
## License
|
|
58
|
+
## MIT License
|
|
59
|
+
|
|
60
|
+
Copyright (c) 2007-2011 Francesc Esplugas Marti
|
|
61
|
+
|
|
62
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
63
|
+
a copy of this software and associated documentation files (the
|
|
64
|
+
"Software"), to deal in the Software without restriction, including
|
|
65
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
66
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
67
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
68
|
+
the following conditions:
|
|
69
|
+
|
|
70
|
+
The above copyright notice and this permission notice shall be
|
|
71
|
+
included in all copies or substantial portions of the Software.
|
|
56
72
|
|
|
57
|
-
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
74
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
75
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
76
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
77
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
78
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
79
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
58
80
|
|
|
59
81
|
[1]: http://rubygems.org/gems/paperclip
|
|
60
82
|
[2]: http://rubygems.org/gems/dragonfly
|
data/Rakefile
CHANGED
|
@@ -38,6 +38,9 @@ task :release => :build do
|
|
|
38
38
|
system "git push && git push --tags"
|
|
39
39
|
system "gem push typus-#{Typus::VERSION}.gem"
|
|
40
40
|
system "git clean -fd && rm -f typus-#{Typus::VERSION}.gem"
|
|
41
|
+
system "git branch -D 3-0-stable"
|
|
42
|
+
system "git checkout -b 3-0-stable && git push -f"
|
|
43
|
+
system "git checkout master"
|
|
41
44
|
end
|
|
42
45
|
|
|
43
46
|
desc 'Deploy'
|
|
@@ -21,8 +21,8 @@ class Admin::ResourcesController < Admin::BaseController
|
|
|
21
21
|
# your formats.
|
|
22
22
|
#
|
|
23
23
|
def index
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
add_resource_action(default_action.titleize, {:action => default_action}, {})
|
|
25
|
+
add_resource_action("Trash", {:action => "destroy"}, {:confirm => "#{Typus::I18n.t("Trash")}?", :method => 'delete'})
|
|
26
26
|
|
|
27
27
|
get_objects
|
|
28
28
|
|
|
@@ -34,8 +34,7 @@ class Admin::ResourcesController < Admin::BaseController
|
|
|
34
34
|
|
|
35
35
|
def new
|
|
36
36
|
item_params = params.dup
|
|
37
|
-
|
|
38
|
-
item_params.delete_if { |k, v| rejections.include?(k) }
|
|
37
|
+
item_params.delete_if { |k, v| !@resource.columns.map(&:name).include?(k) }
|
|
39
38
|
@item = @resource.new(item_params)
|
|
40
39
|
end
|
|
41
40
|
|
|
@@ -57,8 +56,8 @@ class Admin::ResourcesController < Admin::BaseController
|
|
|
57
56
|
end
|
|
58
57
|
|
|
59
58
|
def edit
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
add_resource_action(default_action.titleize, {:action => default_action}, {})
|
|
60
|
+
add_resource_action("Unrelate", {:action => "unrelate", :resource => @resource.model_name, :resource_id => @item.id}, {:confirm => "#{Typus::I18n.t("Unrelate")}?"})
|
|
62
61
|
end
|
|
63
62
|
|
|
64
63
|
def show
|
|
@@ -81,7 +80,8 @@ class Admin::ResourcesController < Admin::BaseController
|
|
|
81
80
|
|
|
82
81
|
def detach
|
|
83
82
|
if @item.update_attributes(params[:attribute] => nil)
|
|
84
|
-
|
|
83
|
+
notice = Typus::I18n.t("%{model} successfully updated.", :model => @resource.model_name.human)
|
|
84
|
+
redirect_to :back, :notice => notice
|
|
85
85
|
else
|
|
86
86
|
render :edit
|
|
87
87
|
end
|
|
@@ -184,7 +184,7 @@ class Admin::ResourcesController < Admin::BaseController
|
|
|
184
184
|
|
|
185
185
|
case item_class.relationship_with(@resource)
|
|
186
186
|
when :has_one
|
|
187
|
-
association_name = @resource.model_name.
|
|
187
|
+
association_name = @resource.model_name.underscore.to_sym
|
|
188
188
|
worked = item.send(association_name).delete
|
|
189
189
|
else
|
|
190
190
|
association_name ||= @resource.model_name.tableize.to_sym
|
|
@@ -249,19 +249,24 @@ class Admin::ResourcesController < Admin::BaseController
|
|
|
249
249
|
|
|
250
250
|
def redirect_on_success
|
|
251
251
|
action = @resource.typus_options_for(:action_after_save)
|
|
252
|
+
path = params.dup.cleanup
|
|
253
|
+
path.merge!(:action => action)
|
|
252
254
|
|
|
253
255
|
case params[:action]
|
|
254
256
|
when "create"
|
|
255
|
-
path = { :action => action }
|
|
256
257
|
path.merge!(:id => @item.id) unless action.eql?("index")
|
|
257
258
|
notice = Typus::I18n.t("%{model} successfully created.", :model => @resource.model_name.human)
|
|
258
259
|
when "update", "detach"
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
260
|
+
case action
|
|
261
|
+
when "index"
|
|
262
|
+
if params[:back_to]
|
|
263
|
+
path = "#{params[:back_to]}##{@resource.to_resource}"
|
|
264
|
+
else
|
|
265
|
+
path.delete_if { |k, v| %w(action id).include?(k) }
|
|
266
|
+
end
|
|
267
|
+
else
|
|
268
|
+
path.merge!(:action => action) #, :id => @item.id)
|
|
269
|
+
end
|
|
265
270
|
notice = Typus::I18n.t("%{model} successfully updated.", :model => @resource.model_name.human)
|
|
266
271
|
end
|
|
267
272
|
|
|
@@ -339,7 +344,7 @@ class Admin::ResourcesController < Admin::BaseController
|
|
|
339
344
|
case item_class.relationship_with(@resource)
|
|
340
345
|
when :has_one
|
|
341
346
|
# Order#invoice = @item
|
|
342
|
-
association_name = @resource.model_name.
|
|
347
|
+
association_name = @resource.model_name.underscore.to_sym
|
|
343
348
|
item.send("#{association_name}=", @item)
|
|
344
349
|
worked = true
|
|
345
350
|
when :has_and_belongs_to_many
|
|
@@ -352,6 +357,10 @@ class Admin::ResourcesController < Admin::BaseController
|
|
|
352
357
|
if item
|
|
353
358
|
worked = @item.send(association_name).push(item)
|
|
354
359
|
end
|
|
360
|
+
when :has_many
|
|
361
|
+
# Dog#image_holders
|
|
362
|
+
association_name = @resource.model_name.tableize.to_sym
|
|
363
|
+
worked = item.send(association_name).push(@item)
|
|
355
364
|
end
|
|
356
365
|
|
|
357
366
|
association = @resource.reflect_on_association(association_name)
|
|
@@ -375,7 +384,7 @@ class Admin::ResourcesController < Admin::BaseController
|
|
|
375
384
|
if worked
|
|
376
385
|
notice = Typus::I18n.t("%{model} successfully updated.", :model => item_class.model_name.human)
|
|
377
386
|
else
|
|
378
|
-
alert = @item.
|
|
387
|
+
alert = @item.errors.full_messages
|
|
379
388
|
end
|
|
380
389
|
end
|
|
381
390
|
|
|
@@ -405,7 +414,7 @@ class Admin::ResourcesController < Admin::BaseController
|
|
|
405
414
|
item = item_class.find(params[:resource_id]) if params[:resource_id]
|
|
406
415
|
|
|
407
416
|
if item_class.relationship_with(@resource) == :has_one
|
|
408
|
-
association_name = @resource.model_name.
|
|
417
|
+
association_name = @resource.model_name.underscore.to_sym
|
|
409
418
|
if item.send(association_name)
|
|
410
419
|
render :text => "Not allowed!", :status => :unprocessable_entity
|
|
411
420
|
end
|
|
@@ -11,14 +11,14 @@ module Admin
|
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def link_to_detach_attribute(attribute)
|
|
14
|
-
validators = @item.class.validators.delete_if { |i| i.class != ActiveModel::Validations::PresenceValidator }.map { |i| i.attributes.to_s }
|
|
14
|
+
validators = @item.class.validators.delete_if { |i| i.class != ActiveModel::Validations::PresenceValidator }.map { |i| i.attributes }.flatten.map { |i| i.to_s }
|
|
15
15
|
|
|
16
16
|
attachment = @item.send(attribute)
|
|
17
17
|
|
|
18
18
|
field = case get_type_of_attachment(attachment)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
when :dragonfly then attribute
|
|
20
|
+
when :paperclip then "#{attribute}_file_name"
|
|
21
|
+
end
|
|
22
22
|
|
|
23
23
|
if !validators.include?(field) && attachment
|
|
24
24
|
attribute_i18n = @item.class.human_attribute_name(attribute)
|
|
@@ -2,7 +2,7 @@ module Admin
|
|
|
2
2
|
|
|
3
3
|
module FiltersHelper
|
|
4
4
|
|
|
5
|
-
def build_filters(resource = @resource)
|
|
5
|
+
def build_filters(resource = @resource, params = params)
|
|
6
6
|
typus_filters = resource.typus_filters
|
|
7
7
|
|
|
8
8
|
return if typus_filters.empty?
|
|
@@ -24,7 +24,17 @@ module Admin
|
|
|
24
24
|
{ :filter => filter, :items => items }
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
hidden_filters = params.dup
|
|
28
|
+
|
|
29
|
+
# Remove default params.
|
|
30
|
+
rejections = %w(controller action locale utf8 sort_order order_by)
|
|
31
|
+
hidden_filters.delete_if { |k, v| rejections.include?(k) }
|
|
32
|
+
|
|
33
|
+
# Remove also custom params.
|
|
34
|
+
rejections = filters.map { |i| i[:filter] }
|
|
35
|
+
hidden_filters.delete_if { |k, v| rejections.include?(k) }
|
|
36
|
+
|
|
37
|
+
render "admin/helpers/filters/filters", :filters => filters, :hidden_filters => hidden_filters
|
|
28
38
|
end
|
|
29
39
|
|
|
30
40
|
def set_filter(key, value)
|
|
@@ -44,7 +54,7 @@ module Admin
|
|
|
44
54
|
class_name = att_assoc.options[:class_name] || filter.capitalize.camelize
|
|
45
55
|
resource = class_name.typus_constantize
|
|
46
56
|
|
|
47
|
-
items = [[Typus::I18n.t("View
|
|
57
|
+
items = [[Typus::I18n.t("View all %{attribute}", :attribute => @resource.human_attribute_name(filter).downcase.pluralize), ""]]
|
|
48
58
|
items += resource.order(resource.typus_order_by).map { |v| [v.to_label, v.id] }
|
|
49
59
|
end
|
|
50
60
|
|
|
@@ -70,23 +80,10 @@ module Admin
|
|
|
70
80
|
end
|
|
71
81
|
|
|
72
82
|
def string_filter(filter)
|
|
73
|
-
values = @resource::const_get(filter.to_s.upcase)
|
|
74
|
-
|
|
83
|
+
values = @resource::const_get(filter.to_s.upcase).to_a
|
|
75
84
|
items = [[Typus::I18n.t("Show by %{attribute}", :attribute => @resource.human_attribute_name(filter).downcase), ""]]
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
when Hash
|
|
79
|
-
values
|
|
80
|
-
when Array
|
|
81
|
-
if values.first.is_a?(Array)
|
|
82
|
-
keys, values = values.map { |i| i.first }, values.map { |i| i.last }
|
|
83
|
-
keys.to_hash_with(values)
|
|
84
|
-
else
|
|
85
|
-
values.to_hash_with(values)
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
items += array.to_a
|
|
85
|
+
array = values.first.is_a?(Array) ? values : values.map { |i| [i, i] }
|
|
86
|
+
items += array
|
|
90
87
|
end
|
|
91
88
|
|
|
92
89
|
def predefined_filters
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module Admin
|
|
2
|
+
|
|
3
|
+
module ListHelper
|
|
4
|
+
|
|
5
|
+
def resources_actions
|
|
6
|
+
@resources_actions ||= []
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def list_actions
|
|
10
|
+
resources_actions.map do |body, url, options|
|
|
11
|
+
if admin_user.can?(url[:action], @resource.name)
|
|
12
|
+
path = params.dup.merge!(url)
|
|
13
|
+
link_to Typus::I18n.t(body), path.cleanup, options # .merge(:target => "_parent")
|
|
14
|
+
end
|
|
15
|
+
end.compact.join(" / ").html_safe
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
@@ -2,12 +2,14 @@ module Admin
|
|
|
2
2
|
|
|
3
3
|
module SearchHelper
|
|
4
4
|
|
|
5
|
-
def search(resource = @resource)
|
|
5
|
+
def search(resource = @resource, params = params)
|
|
6
6
|
if (typus_search = resource.typus_defaults_for(:search)) && typus_search.any?
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
|
|
8
|
+
hidden_filters = params.dup
|
|
9
|
+
rejections = %w(controller action locale utf8 sort_order order_by search)
|
|
10
|
+
hidden_filters.delete_if { |k, v| rejections.include?(k) }
|
|
11
|
+
|
|
12
|
+
render "admin/helpers/search/search", :hidden_filters => hidden_filters
|
|
11
13
|
end
|
|
12
14
|
end
|
|
13
15
|
|
|
@@ -47,16 +47,16 @@ module Admin
|
|
|
47
47
|
fields.map { |k, v| send("table_#{v}_field", k, item) }
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
-
def
|
|
51
|
-
@
|
|
50
|
+
def resource_actions
|
|
51
|
+
@resource_actions ||= []
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
def table_actions(model, item, association_name = nil)
|
|
55
|
-
|
|
56
|
-
if admin_user.can?(
|
|
57
|
-
link_to Typus::I18n.t(
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
resource_actions.map do |body, url, options|
|
|
56
|
+
if admin_user.can?(url[:action], model.name)
|
|
57
|
+
link_to Typus::I18n.t(body),
|
|
58
|
+
params.dup.cleanup.merge(url).merge(:controller => model.to_resource, :id => item.id),
|
|
59
|
+
options.merge(:target => "_parent")
|
|
60
60
|
end
|
|
61
61
|
end.compact.join(" / ").html_safe
|
|
62
62
|
end
|
|
@@ -137,8 +137,8 @@ module Admin
|
|
|
137
137
|
|
|
138
138
|
def table_boolean_field(attribute, item)
|
|
139
139
|
status = item.send(attribute)
|
|
140
|
-
|
|
141
|
-
human_boolean = status ?
|
|
140
|
+
boolean_assoc = item.class.typus_boolean(attribute)
|
|
141
|
+
human_boolean = (status ? boolean_assoc.rassoc("true") : boolean_assoc.rassoc("false")).first
|
|
142
142
|
|
|
143
143
|
options = { :controller => "/admin/#{item.class.to_resource}",
|
|
144
144
|
:action => "toggle",
|
|
@@ -5,7 +5,11 @@
|
|
|
5
5
|
<% filters.each do |filter| %>
|
|
6
6
|
<li><%= select_tag filter[:filter], options_for_select(filter[:items], params[filter[:filter]]) %></li>
|
|
7
7
|
<% end %>
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
<% hidden_filters.each do |key, value| %>
|
|
10
|
+
<%= hidden_field_tag key, value %>
|
|
11
|
+
<% end %>
|
|
12
|
+
|
|
9
13
|
<li><%= submit_tag Typus::I18n.t("Filter"), :name => nil %></li>
|
|
10
14
|
</ul>
|
|
11
15
|
</div>
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
<div id="search">
|
|
2
2
|
|
|
3
|
-
<%= form_tag
|
|
3
|
+
<%= form_tag nil, :method => :get do %>
|
|
4
|
+
|
|
4
5
|
<ul>
|
|
5
6
|
<li><%= search_field_tag "search", nil, :id => "quicksearch", :title => (params[:search] || Typus::I18n.t("Search")) %></li>
|
|
6
7
|
</ul>
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
<% hidden_filters.each do |key, value| %>
|
|
10
|
+
<%= hidden_field_tag key, value %>
|
|
9
11
|
<% end %>
|
|
12
|
+
|
|
10
13
|
<% end %>
|
|
11
14
|
|
|
12
15
|
</div>
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
<h2>
|
|
11
11
|
<%= page_title %>
|
|
12
|
+
<small><%= list_actions %></small>
|
|
12
13
|
</h2>
|
|
13
14
|
|
|
14
15
|
<%= display_link_to_previous %>
|
|
@@ -16,11 +17,7 @@
|
|
|
16
17
|
<%= render 'edit' %>
|
|
17
18
|
|
|
18
19
|
<%
|
|
19
|
-
options =
|
|
20
|
-
:id => @item.id ,
|
|
21
|
-
:back_to => params[:back_to],
|
|
22
|
-
:resource => params[:resource],
|
|
23
|
-
:resource_id => params[:resource_id] }
|
|
20
|
+
options = params.dup.cleanup.merge!(:action => 'update')
|
|
24
21
|
button = Typus::I18n.t("Save %{resource}", :resource => @resource.model_name.human)
|
|
25
22
|
%>
|
|
26
23
|
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
<h2>
|
|
9
9
|
<%= page_title %>
|
|
10
|
+
<small><%= list_actions %></small>
|
|
10
11
|
</h2>
|
|
11
12
|
|
|
12
13
|
<%= display_flash_message %>
|
|
@@ -15,7 +16,7 @@
|
|
|
15
16
|
|
|
16
17
|
<ul class="predefined_filters">
|
|
17
18
|
<% predefined_filters.each do |filter, action, scope| %>
|
|
18
|
-
<li><%= link_to Typus::I18n.t(filter), :action => action %> (<%= @resource.send(scope).count %>)</li>
|
|
19
|
+
<li><%= link_to Typus::I18n.t(filter), params.dup.cleanup.merge(:action => action) %> (<%= @resource.send(scope).count %>)</li>
|
|
19
20
|
<% end %>
|
|
20
21
|
</ul>
|
|
21
22
|
|
|
@@ -30,5 +31,5 @@
|
|
|
30
31
|
<%= raw build_list(@resource, @fields, @items) %>
|
|
31
32
|
<%= will_paginate(@items, Typus.pagination) %>
|
|
32
33
|
<% else %>
|
|
33
|
-
<p><%= Typus::I18n.t("No %{resources} found.", :resources => @resource.model_name.human.pluralize
|
|
34
|
+
<p><%= Typus::I18n.t("No %{resources} found.", :resources => @resource.model_name.human.downcase.pluralize) %></p>
|
|
34
35
|
<% end %>
|
|
@@ -7,17 +7,14 @@
|
|
|
7
7
|
|
|
8
8
|
<h2>
|
|
9
9
|
<%= page_title %>
|
|
10
|
+
<small><%= list_actions %></small>
|
|
10
11
|
</h2>
|
|
11
12
|
|
|
12
13
|
<%= display_link_to_previous %>
|
|
13
14
|
<%= render 'new' %>
|
|
14
15
|
|
|
15
16
|
<%
|
|
16
|
-
options =
|
|
17
|
-
:back_to => params[:back_to],
|
|
18
|
-
:selected => params[:selected],
|
|
19
|
-
:resource => params[:resource],
|
|
20
|
-
:resource_id => params[:resource_id] }
|
|
17
|
+
options = params.dup.cleanup.merge(:action => 'create')
|
|
21
18
|
button = Typus::I18n.t("Create %{resource}", :resource => @resource.model_name.human)
|
|
22
19
|
%>
|
|
23
20
|
|
|
@@ -7,20 +7,20 @@
|
|
|
7
7
|
|
|
8
8
|
<h2>
|
|
9
9
|
<%= page_title %>
|
|
10
|
+
<small><%= list_actions %></small>
|
|
10
11
|
</h2>
|
|
11
12
|
|
|
12
13
|
<%= display_flash_message %>
|
|
13
14
|
<%= render 'show' %>
|
|
14
15
|
|
|
15
16
|
<dl>
|
|
16
|
-
<%- @fields.each do |
|
|
17
|
-
<dt><%=h @resource.human_attribute_name(
|
|
17
|
+
<%- @fields.each do |key, value| -%>
|
|
18
|
+
<dt><%=h @resource.human_attribute_name(key) %></dt>
|
|
18
19
|
<%-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
data = case data_type
|
|
20
|
+
raw_data = @item.send(key)
|
|
21
|
+
data = case value
|
|
22
22
|
when :boolean
|
|
23
|
-
@resource.typus_boolean(
|
|
23
|
+
@resource.typus_boolean(key).invert[raw_data.to_s]
|
|
24
24
|
when :belongs_to
|
|
25
25
|
if raw_data
|
|
26
26
|
link_to raw_data.to_label, { :controller => raw_data.class.to_resource,
|
|
@@ -28,9 +28,13 @@
|
|
|
28
28
|
:id => raw_data }
|
|
29
29
|
end
|
|
30
30
|
when :file
|
|
31
|
-
typus_file_preview(@item,
|
|
31
|
+
typus_file_preview(@item, key)
|
|
32
32
|
when :selector
|
|
33
|
-
@item.mapping(
|
|
33
|
+
@item.mapping(key)
|
|
34
|
+
when :datetime
|
|
35
|
+
if raw_data
|
|
36
|
+
I18n.localize(raw_data, :format => @resource.typus_date_format(key))
|
|
37
|
+
end
|
|
34
38
|
else
|
|
35
39
|
raw_data
|
|
36
40
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<div class="box_relationships" id="<%= association_name %>">
|
|
2
2
|
|
|
3
3
|
<h2>
|
|
4
|
-
<%= association_name.
|
|
4
|
+
<%= association_name.humanize.pluralize %>
|
|
5
5
|
<small><%= add_new %></small>
|
|
6
6
|
</h2>
|
|
7
7
|
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
<%= table %>
|
|
12
12
|
<%= will_paginate(@items, Typus.pagination.merge(:anchor => association_name)) %>
|
|
13
13
|
<% else %>
|
|
14
|
-
<p><%= Typus::I18n.t("No %{resources} found.", :resources => association_name.
|
|
14
|
+
<p><%= Typus::I18n.t("No %{resources} found.", :resources => association_name.humanize.downcase.pluralize) %></p>
|
|
15
15
|
<% end %>
|
|
16
16
|
|
|
17
17
|
</div>
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
<meta name="apple-mobile-web-app-capable" content="yes" />
|
|
9
9
|
<meta name="generator" content="Typus <%= Typus::VERSION %>" />
|
|
10
10
|
|
|
11
|
-
<title><%= yield :title %></title>
|
|
11
|
+
<title><%= Typus.admin_title %> — <%= yield :title %></title>
|
|
12
12
|
|
|
13
13
|
<%= stylesheet_link_tag "/admin/stylesheets/screen",
|
|
14
14
|
"/admin/stylesheets/application",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
<meta name="apple-mobile-web-app-capable" content="yes" />
|
|
9
9
|
<meta name="generator" content="Typus <%= Typus::VERSION %>" />
|
|
10
10
|
|
|
11
|
-
<title><%= yield :title %></title>
|
|
11
|
+
<title><%= Typus.admin_title %> — <%= yield :title %></title>
|
|
12
12
|
|
|
13
13
|
<%= stylesheet_link_tag "/admin/stylesheets/screen",
|
|
14
14
|
"/admin/stylesheets/application" %>
|
|
@@ -2,7 +2,7 @@ class ActiveRecord::Base
|
|
|
2
2
|
|
|
3
3
|
def self.relationship_with(model)
|
|
4
4
|
association = reflect_on_association(model.table_name.to_sym) ||
|
|
5
|
-
reflect_on_association(model.model_name.
|
|
5
|
+
reflect_on_association(model.model_name.underscore.to_sym)
|
|
6
6
|
association.macro
|
|
7
7
|
end
|
|
8
8
|
|
|
@@ -35,19 +35,9 @@ class ActiveRecord::Base
|
|
|
35
35
|
# => "Publicado"
|
|
36
36
|
#++
|
|
37
37
|
def mapping(attribute)
|
|
38
|
-
values = self.class::const_get(attribute.to_s.upcase)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
case values.first
|
|
42
|
-
when Array
|
|
43
|
-
array_keys, array_values = values.transpose
|
|
44
|
-
else
|
|
45
|
-
array_keys = array_values = values
|
|
46
|
-
end
|
|
47
|
-
values = array_keys.to_hash_with(array_values)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
values.invert[send(attribute)]
|
|
38
|
+
values = self.class::const_get(attribute.to_s.upcase).to_a
|
|
39
|
+
array = values.first.is_a?(Array) ? values : values.map { |i| [i, i] }
|
|
40
|
+
array.rassoc(send(attribute)).first
|
|
51
41
|
end
|
|
52
42
|
|
|
53
43
|
def to_label
|
data/lib/support/hash.rb
CHANGED
|
@@ -4,4 +4,14 @@ class Hash
|
|
|
4
4
|
delete_if { |k, v| v.blank? }
|
|
5
5
|
end
|
|
6
6
|
|
|
7
|
+
def cleanup
|
|
8
|
+
whitelist = %w(controller action id
|
|
9
|
+
CKEditor CKEditorFuncNum langCode
|
|
10
|
+
layout
|
|
11
|
+
resource resource_id resource_action
|
|
12
|
+
selected
|
|
13
|
+
back_to)
|
|
14
|
+
delete_if { |k, v| !whitelist.include?(k) }
|
|
15
|
+
end
|
|
16
|
+
|
|
7
17
|
end
|
data/lib/typus.rb
CHANGED
data/lib/typus/actions.rb
CHANGED
|
@@ -4,22 +4,36 @@ module Typus
|
|
|
4
4
|
|
|
5
5
|
protected
|
|
6
6
|
|
|
7
|
-
def
|
|
8
|
-
|
|
9
|
-
@
|
|
10
|
-
@actions << options
|
|
7
|
+
def add_resource_action(*args)
|
|
8
|
+
@resource_actions ||= []
|
|
9
|
+
@resource_actions << args
|
|
11
10
|
end
|
|
12
11
|
|
|
13
|
-
def
|
|
14
|
-
|
|
15
|
-
@
|
|
16
|
-
@actions = @actions.unshift(options)
|
|
12
|
+
def prepend_resource_action(*args)
|
|
13
|
+
@resource_actions ||= []
|
|
14
|
+
@resource_actions = @resource_actions.unshift(args)
|
|
17
15
|
end
|
|
18
16
|
|
|
19
|
-
def
|
|
20
|
-
|
|
21
|
-
@
|
|
22
|
-
|
|
17
|
+
def append_resource_action(*args)
|
|
18
|
+
@resource_actions ||= []
|
|
19
|
+
@resource_actions = @resource_actions.concat([args])
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# FIXME: I know this is ugly but first of all I want to see it working.
|
|
23
|
+
|
|
24
|
+
def add_resources_action(*args)
|
|
25
|
+
@resources_actions ||= []
|
|
26
|
+
@resources_actions << args
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def prepend_resources_action(*args)
|
|
30
|
+
@resources_actions ||= []
|
|
31
|
+
@resources_actions = @resources_actions.unshift(args)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def append_resources_action(*args)
|
|
35
|
+
@resources_actions ||= []
|
|
36
|
+
@resources_actions = @resources_actions.concat([args])
|
|
23
37
|
end
|
|
24
38
|
|
|
25
39
|
end
|
|
@@ -29,7 +29,7 @@ module Typus
|
|
|
29
29
|
data = read_model_config['fields']
|
|
30
30
|
fields = data[filter.to_s] || data['default'] || ""
|
|
31
31
|
|
|
32
|
-
virtual_fields = instance_methods - model_fields.keys.map { |i| i.to_s }
|
|
32
|
+
virtual_fields = instance_methods.map { |i| i.to_s } - model_fields.keys.map { |i| i.to_s }
|
|
33
33
|
|
|
34
34
|
fields.extract_settings.map { |f| f.to_sym }.each do |field|
|
|
35
35
|
if reflect_on_association(field)
|
|
@@ -176,7 +176,7 @@ module Typus
|
|
|
176
176
|
["True", "False"]
|
|
177
177
|
end
|
|
178
178
|
|
|
179
|
-
|
|
179
|
+
[[boolean.first, "true"], [boolean.last, "false"]]
|
|
180
180
|
end
|
|
181
181
|
|
|
182
182
|
#--
|
data/lib/typus/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: typus
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 13
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 3
|
|
8
8
|
- 0
|
|
9
|
-
-
|
|
10
|
-
version: 3.0.
|
|
9
|
+
- 5
|
|
10
|
+
version: 3.0.5
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Francesc Esplugas
|
|
@@ -15,7 +15,7 @@ autorequire:
|
|
|
15
15
|
bindir: bin
|
|
16
16
|
cert_chain: []
|
|
17
17
|
|
|
18
|
-
date: 2011-01-
|
|
18
|
+
date: 2011-01-28 00:00:00 +01:00
|
|
19
19
|
default_executable:
|
|
20
20
|
dependencies:
|
|
21
21
|
- !ruby/object:Gem::Dependency
|
|
@@ -24,14 +24,13 @@ dependencies:
|
|
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
|
25
25
|
none: false
|
|
26
26
|
requirements:
|
|
27
|
-
- -
|
|
27
|
+
- - ~>
|
|
28
28
|
- !ruby/object:Gem::Version
|
|
29
29
|
hash: 5
|
|
30
30
|
segments:
|
|
31
31
|
- 1
|
|
32
32
|
- 5
|
|
33
|
-
|
|
34
|
-
version: 1.5.3
|
|
33
|
+
version: "1.5"
|
|
35
34
|
type: :runtime
|
|
36
35
|
version_requirements: *id001
|
|
37
36
|
- !ruby/object:Gem::Dependency
|
|
@@ -85,6 +84,7 @@ files:
|
|
|
85
84
|
- app/helpers/admin/file_preview_helper.rb
|
|
86
85
|
- app/helpers/admin/filters_helper.rb
|
|
87
86
|
- app/helpers/admin/form_helper.rb
|
|
87
|
+
- app/helpers/admin/list_helper.rb
|
|
88
88
|
- app/helpers/admin/relationships_helper.rb
|
|
89
89
|
- app/helpers/admin/resources_helper.rb
|
|
90
90
|
- app/helpers/admin/search_helper.rb
|
|
@@ -212,7 +212,6 @@ files:
|
|
|
212
212
|
- lib/generators/typus/typus_generator.rb
|
|
213
213
|
- lib/generators/typus/views_generator.rb
|
|
214
214
|
- lib/support/active_record.rb
|
|
215
|
-
- lib/support/array.rb
|
|
216
215
|
- lib/support/fake_user.rb
|
|
217
216
|
- lib/support/hash.rb
|
|
218
217
|
- lib/support/object.rb
|
data/lib/support/array.rb
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
class Array
|
|
2
|
-
|
|
3
|
-
#--
|
|
4
|
-
# Taken from http://snippets.dzone.com/posts/show/302
|
|
5
|
-
#
|
|
6
|
-
# >> %W{ a b c }.to_hash_with( %W{ 1 2 3 } )
|
|
7
|
-
# => {"a"=>"1", "b"=>"2", "c"=>"3"}
|
|
8
|
-
#++
|
|
9
|
-
def to_hash_with(other)
|
|
10
|
-
Hash[ *(0...self.size()).inject([]) { |arr, ix| arr.push(self[ix], other[ix]) } ]
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
end
|