merb-admin 0.5.4 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +1 -1
- data/Rakefile +1 -1
- data/app/helpers/main_helper.rb +8 -4
- data/app/views/main/_belongs_to.html.erb +4 -3
- data/app/views/main/_has_many.html.erb +1 -1
- data/app/views/main/_has_one.html.erb +4 -3
- data/app/views/main/_properties.html.erb +3 -2
- data/app/views/main/_string.html.erb +3 -0
- data/app/views/main/delete.html.erb +19 -2
- data/app/views/main/list.html.erb +5 -2
- data/lib/merb-admin/slicetasks.rb +46 -28
- data/lib/merb-admin.rb +1 -1
- data/schema/migrations/005_create_teams_migration.rb +1 -1
- data/spec/models/datamapper/team.rb +1 -1
- metadata +2 -2
data/README.markdown
CHANGED
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ AUTHOR = "Erik Michaels-Ober"
|
|
9
9
|
EMAIL = "sferik@gmail.com"
|
10
10
|
HOMEPAGE = "http://github.com/sferik/merb-admin"
|
11
11
|
SUMMARY = "MerbAdmin is a Merb plugin that provides an easy-to-use interface for managing your data."
|
12
|
-
GEM_VERSION = "0.5.
|
12
|
+
GEM_VERSION = "0.5.5"
|
13
13
|
|
14
14
|
spec = Gem::Specification.new do |s|
|
15
15
|
s.rubyforge_project = "merb"
|
data/app/helpers/main_helper.rb
CHANGED
@@ -2,7 +2,7 @@ require 'builder'
|
|
2
2
|
module Merb
|
3
3
|
module MerbAdmin
|
4
4
|
module MainHelper
|
5
|
-
def
|
5
|
+
def object_name(object)
|
6
6
|
if object.nil?
|
7
7
|
nil
|
8
8
|
elsif object.respond_to?(:name)
|
@@ -24,7 +24,7 @@ module Merb
|
|
24
24
|
else
|
25
25
|
Builder::XmlMarkup.new.img(:src => image_path("icon-no.gif"), :alt => "False")
|
26
26
|
end
|
27
|
-
when :
|
27
|
+
when :datetime
|
28
28
|
value = object.send(property_name)
|
29
29
|
value.respond_to?(:strftime) ? value.strftime("%b. %d, %Y, %I:%M%p") : nil
|
30
30
|
when :date
|
@@ -34,13 +34,17 @@ module Merb
|
|
34
34
|
value = object.send(property_name)
|
35
35
|
value.respond_to?(:strftime) ? value.strftime("%I:%M%p") : nil
|
36
36
|
when :string
|
37
|
-
|
37
|
+
if property_name.to_s =~ /(image|logo|photo|photograph|picture|thumb|thumbnail)_ur(i|l)/i
|
38
|
+
Builder::XmlMarkup.new.img(:src => object.send(property_name), :width => 10, :height => 10)
|
39
|
+
else
|
40
|
+
object.send(property_name).to_s.truncate(50)
|
41
|
+
end
|
38
42
|
when :text
|
39
43
|
object.send(property_name).to_s.truncate(50)
|
40
44
|
when :integer
|
41
45
|
association = @abstract_model.belongs_to_associations.select{|a| a[:child_key].first == property_name}.first
|
42
46
|
if association
|
43
|
-
|
47
|
+
object_name(object.send(association[:name]))
|
44
48
|
else
|
45
49
|
object.send(property_name)
|
46
50
|
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
<%
|
2
2
|
child_key = association[:child_key].first
|
3
|
-
collection = MerbAdmin::AbstractModel.new(association[:parent_model]).all.map{|o| [o.id,
|
3
|
+
collection = MerbAdmin::AbstractModel.new(association[:parent_model]).all.map{|o| [o.id, object_name(o)]}.sort_by{|o| o[1]}
|
4
4
|
selected = @object.send(child_key)
|
5
5
|
label = association[:pretty_name]
|
6
6
|
required = false
|
7
|
+
errors_exist = !(@object.errors[child_key].nil? || @object.errors[child_key].empty?)
|
7
8
|
@properties.each do |property|
|
8
9
|
next unless property[:name] == child_key
|
9
10
|
required = true unless property[:nullable?]
|
@@ -11,8 +12,8 @@
|
|
11
12
|
%>
|
12
13
|
<fieldset class="module aligned">
|
13
14
|
<h2><%= label %></h2>
|
14
|
-
<div class="<%=
|
15
|
-
<% if
|
15
|
+
<div class="<%= errors_exist ? "form-row errors" : "form-row"%>">
|
16
|
+
<% if errors_exist %>
|
16
17
|
<ul class="errorlist">
|
17
18
|
<% @object.errors[child_key].each do |error| %>
|
18
19
|
<li><%= error %></li>
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<%
|
2
2
|
association_name = association[:name]
|
3
|
-
collection = MerbAdmin::AbstractModel.new(association[:child_model]).all.map{|o| [o.id,
|
3
|
+
collection = MerbAdmin::AbstractModel.new(association[:child_model]).all.map{|o| [o.id, object_name(o)]}.sort_by{|o| o[1]}
|
4
4
|
selected = @object.send(association_name)
|
5
5
|
label = association[:pretty_name]
|
6
6
|
%>
|
@@ -1,10 +1,11 @@
|
|
1
1
|
<%
|
2
2
|
child_key = association[:child_key].first
|
3
3
|
association_name = association[:name]
|
4
|
-
collection = MerbAdmin::AbstractModel.new(association[:child_model]).all.map{|o| [o.id,
|
4
|
+
collection = MerbAdmin::AbstractModel.new(association[:child_model]).all.map{|o| [o.id, object_name(o)]}.sort_by{|o| o[1]}
|
5
5
|
selected = @object.send(association_name)
|
6
6
|
label = association[:pretty_name]
|
7
7
|
required = false
|
8
|
+
errors_exist = !(@object.errors[child_key].nil? || @object.errors[child_key].empty?)
|
8
9
|
@properties.each do |property|
|
9
10
|
next unless property[:name] == child_key
|
10
11
|
required = true unless property[:nullable?]
|
@@ -12,8 +13,8 @@
|
|
12
13
|
%>
|
13
14
|
<fieldset class="module aligned">
|
14
15
|
<h2><%= label %></h2>
|
15
|
-
<div class="<%=
|
16
|
-
<% if
|
16
|
+
<div class="<%= errors_exist ? "form-row errors" : "form-row" %>">
|
17
|
+
<% if errors_exist %>
|
17
18
|
<ul class="errorlist">
|
18
19
|
<% @object.errors[child_key].each do |error| %>
|
19
20
|
<li><%= error %></li>
|
@@ -3,10 +3,11 @@
|
|
3
3
|
<% properties.each do |property| %>
|
4
4
|
<% property_name = property[:name] %>
|
5
5
|
<% property_type = property[:type] %>
|
6
|
+
<% errors_exist = !(@object.errors[property_name].nil? || @object.errors[property_name].empty?) %>
|
6
7
|
<% next if [:id, :created_at, :created_on, :deleted_at, :updated_at, :updated_on, :deleted_on].include?(property_name) %>
|
7
8
|
<% next if belongs_to_keys.include?(property_name) %>
|
8
|
-
<div class="<%=
|
9
|
-
<% if
|
9
|
+
<div class="<%= errors_exist ? "form-row errors" : "form-row" %>">
|
10
|
+
<% if errors_exist %>
|
10
11
|
<ul class="errorlist">
|
11
12
|
<% @object.errors[property_name].each do |error| %>
|
12
13
|
<li><%= error %></li>
|
@@ -6,6 +6,9 @@
|
|
6
6
|
%>
|
7
7
|
<div>
|
8
8
|
<%= text_field(property_name, :size => [50, length].min, :maxlength => length, :label => label) %>
|
9
|
+
<% if property_name.to_s =~ /(image|logo|photo|photograph|picture|thumb|thumbnail)_ur(i|l)/i %>
|
10
|
+
<img src="<%= @object.send(property_name) %>" width="10" height"10" />
|
11
|
+
<% end %>
|
9
12
|
<p class="help">
|
10
13
|
<%= required ? "Required." : "Optional." %> <%= length %> <%= length == 1 ? "character." : "characters or fewer." %>
|
11
14
|
</p>
|
@@ -1,7 +1,24 @@
|
|
1
|
-
<p>Are you sure you want to delete the <%= @abstract_model.pretty_name.downcase
|
1
|
+
<p>Are you sure you want to delete the <%= @abstract_model.pretty_name.downcase %> “<%= object_name(@object) %>”? All of the following related items will be deleted:</p>
|
2
2
|
<ul>
|
3
3
|
<li>
|
4
|
-
<%= link_to(@
|
4
|
+
<%= @abstract_model.pretty_name %>: <%= link_to(object_name(@object), url(:merb_admin_edit, :model_name => @abstract_model.singular_name, :id => @object.id)) %>
|
5
|
+
<ul>
|
6
|
+
<% @abstract_model.has_many_associations.each do |association| %>
|
7
|
+
<% @object.send(association[:name]).each do |child| %>
|
8
|
+
<% next if child.nil? %>
|
9
|
+
<li>
|
10
|
+
One or more <%= @abstract_model.pretty_name.pluralize.downcase %> in <%= association[:pretty_name].downcase %>: <%= link_to(object_name(child), url(:merb_admin_edit, :model_name => association[:name].to_s.singularize.to_sym, :id => child.id)) %>
|
11
|
+
</li>
|
12
|
+
<% end %>
|
13
|
+
<% end %>
|
14
|
+
<% @abstract_model.has_one_associations.each do |association| %>
|
15
|
+
<% child = @object.send(association[:name]) %>
|
16
|
+
<% next if child.nil? %>
|
17
|
+
<li>
|
18
|
+
A <%= @abstract_model.pretty_name.downcase %> in <%= association[:pretty_name].downcase %>: <%= link_to(object_name(child), url(:merb_admin_edit, :model_name => association[:name], :id => child.id)) %>
|
19
|
+
</li>
|
20
|
+
<% end %>
|
21
|
+
</ul>
|
5
22
|
</li>
|
6
23
|
</ul>
|
7
24
|
<%= form_for(@object, :action => url(:merb_admin_destroy, :model_name => @abstract_model.singular_name, :id => @object.id), :method => :delete) do %>
|
@@ -4,6 +4,7 @@
|
|
4
4
|
filter = params[:filter]
|
5
5
|
sort = params[:sort]
|
6
6
|
sort_reverse = params[:sort_reverse]
|
7
|
+
filters_exist = !@properties.select{|property| property[:type] == :boolean}.empty?
|
7
8
|
%>
|
8
9
|
<div id="content-main">
|
9
10
|
<ul class="object-tools">
|
@@ -11,7 +12,7 @@
|
|
11
12
|
<%= link_to("Add #{@abstract_model.pretty_name.downcase}", url(:merb_admin_new, :model_name => @abstract_model.singular_name), :class => "addlink") %>
|
12
13
|
</li>
|
13
14
|
</ul>
|
14
|
-
<div class="module filtered" id="changelist">
|
15
|
+
<div class="<%= filters_exist ? "module filtered" : "module" %>" id="changelist">
|
15
16
|
<div id="toolbar">
|
16
17
|
<form id="changelist-search" action="" method="get">
|
17
18
|
<div>
|
@@ -30,6 +31,7 @@
|
|
30
31
|
</form>
|
31
32
|
</div>
|
32
33
|
<script type="text/javascript">document.getElementById("searchbar").focus();</script>
|
34
|
+
<% if filters_exist %>
|
33
35
|
<div id="changelist-filter">
|
34
36
|
<h2>Filter</h2>
|
35
37
|
<% @properties.each do |property| %>
|
@@ -52,13 +54,14 @@
|
|
52
54
|
<% end %>
|
53
55
|
<% end %>
|
54
56
|
</div>
|
57
|
+
<% end %>
|
55
58
|
<table cellspacing="0">
|
56
59
|
<thead>
|
57
60
|
<tr>
|
58
61
|
<% @properties.each do |property| %>
|
59
62
|
<% property_name = property[:name] %>
|
60
63
|
<% property_pretty_name = property[:pretty_name] %>
|
61
|
-
<th class="<%= sort == property_name.to_s ? sort_reverse ?
|
64
|
+
<th class="<%= sort == property_name.to_s ? sort_reverse ? "sorted descending" : "sorted ascending" : nil %>">
|
62
65
|
<%= link_to(property_pretty_name, "?" + Merb::Parse.params_to_query_string(params.merge(:sort => property_name).reject{|key, value| key.to_sym == :sort_reverse}.merge(sort == property_name.to_s && sort_reverse != "true" ? {:sort_reverse => "true"} : {}))) %>
|
63
66
|
</th>
|
64
67
|
<% end %>
|
@@ -4,32 +4,6 @@ require 'mlb'
|
|
4
4
|
namespace :slices do
|
5
5
|
namespace :"merb-admin" do
|
6
6
|
|
7
|
-
desc "Loads sample DataMapper models and data"
|
8
|
-
task :load_sample => ["load_sample:datamapper"]
|
9
|
-
|
10
|
-
namespace :load_sample do
|
11
|
-
|
12
|
-
desc "Loads sample ActiveRecord models"
|
13
|
-
task :activerecord do
|
14
|
-
puts "Copying sample ActiveRecord models into host application - resolves any collisions"
|
15
|
-
copy_models(:activerecord)
|
16
|
-
puts "Copying sample ActiveRecord migrations into host application - resolves any collisions"
|
17
|
-
copy_migrations
|
18
|
-
Rake::Task["db:migrate"].reenable
|
19
|
-
Rake::Task["db:migrate"].invoke
|
20
|
-
load_data
|
21
|
-
end
|
22
|
-
|
23
|
-
desc "Loads sample DataMapper models"
|
24
|
-
task :datamapper do
|
25
|
-
puts "Copying sample DataMapper models into host application - resolves any collisions"
|
26
|
-
copy_models(:datamapper)
|
27
|
-
Rake::Task["db:automigrate"].reenable
|
28
|
-
Rake::Task["db:automigrate"].invoke
|
29
|
-
load_data
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
7
|
# add your own merb-admin tasks here
|
34
8
|
|
35
9
|
# # Uncomment the following lines and edit the pre defined tasks
|
@@ -45,6 +19,47 @@ namespace :slices do
|
|
45
19
|
# task :migrate do
|
46
20
|
# end
|
47
21
|
|
22
|
+
namespace :activerecord do
|
23
|
+
|
24
|
+
desc "Loads sample ActiveRecord models and data"
|
25
|
+
task :load_sample => ["load_sample:activerecord:models", "load_sample:activerecord:data"]
|
26
|
+
namespace :load_sample do
|
27
|
+
desc "Loads sample ActiveRecord models"
|
28
|
+
task :models do
|
29
|
+
copy_models(:activerecord)
|
30
|
+
copy_migrations(:activerecord)
|
31
|
+
end
|
32
|
+
|
33
|
+
desc "Loads sample ActiveRecord data"
|
34
|
+
task :data do
|
35
|
+
Rake::Task["db:migrate"].reenable
|
36
|
+
Rake::Task["db:migrate"].invoke
|
37
|
+
load_data
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
namespace :datamapper do
|
44
|
+
|
45
|
+
desc "Loads sample DataMapper models and data"
|
46
|
+
task :load_sample => ["load_sample:datamapper:models", "load_sample:datamapper:data"]
|
47
|
+
namespace :load_sample do
|
48
|
+
desc "Loads sample DataMapper models"
|
49
|
+
task :models do
|
50
|
+
copy_models(:datamapper)
|
51
|
+
end
|
52
|
+
|
53
|
+
desc "Loads sample DataMapper data"
|
54
|
+
task :data do
|
55
|
+
Rake::Task["db:automigrate"].reenable
|
56
|
+
Rake::Task["db:automigrate"].invoke
|
57
|
+
load_data
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
48
63
|
end
|
49
64
|
end
|
50
65
|
|
@@ -60,7 +75,7 @@ def load_data
|
|
60
75
|
division = MerbAdmin::AbstractModel.new("Division").create(:name => mlb_team.division, :league => league)
|
61
76
|
end
|
62
77
|
unless team = MerbAdmin::AbstractModel.new("Team").first(:conditions => ["name = ?", mlb_team.name])
|
63
|
-
team = MerbAdmin::AbstractModel.new("Team").create(:name => mlb_team.name, :
|
78
|
+
team = MerbAdmin::AbstractModel.new("Team").create(:name => mlb_team.name, :logo_url => mlb_team.logo_url, :manager => mlb_team.manager, :ballpark => mlb_team.ballpark, :mascot => mlb_team.mascot, :founded => mlb_team.founded, :wins => mlb_team.wins, :losses => mlb_team.losses, :win_percentage => ("%.3f" % (mlb_team.wins.to_f / (mlb_team.wins + mlb_team.losses))).to_f, :division => division, :league => league)
|
64
79
|
end
|
65
80
|
mlb_team.players.each do |player|
|
66
81
|
MerbAdmin::AbstractModel.new("Player").create(:name => player.name, :number => player.number, :position => player.position, :team => team)
|
@@ -70,6 +85,7 @@ end
|
|
70
85
|
|
71
86
|
def copy_models(orm = nil)
|
72
87
|
orm ||= set_orm
|
88
|
+
puts "Copying sample #{orm} models into host application - resolves any collisions"
|
73
89
|
seen, copied, duplicated = [], [], []
|
74
90
|
Dir.glob(File.dirname(__FILE__) / ".." / ".." / "spec" / "models" / orm.to_s.downcase / MerbAdmin.glob_for(:model)).each do |source_filename|
|
75
91
|
destination_filename = Merb.dir_for(:model) / File.basename(source_filename)
|
@@ -81,7 +97,9 @@ def copy_models(orm = nil)
|
|
81
97
|
duplicated.each { |f| puts "! duplicated override as #{f}" }
|
82
98
|
end
|
83
99
|
|
84
|
-
def copy_migrations
|
100
|
+
def copy_migrations(orm = nil)
|
101
|
+
orm ||= set_orm
|
102
|
+
puts "Copying sample #{orm} migrations into host application - resolves any collisions"
|
85
103
|
seen, copied, duplicated = [], [], []
|
86
104
|
Dir.glob(File.dirname(__FILE__) / ".." / ".." / "schema" / "migrations" / "*.rb").each do |source_filename|
|
87
105
|
destination_filename = Merb.root / "schema" / "migrations" / File.basename(source_filename)
|
data/lib/merb-admin.rb
CHANGED
@@ -23,7 +23,7 @@ if defined?(Merb::Plugins)
|
|
23
23
|
|
24
24
|
# Slice metadata
|
25
25
|
self.description = "MerbAdmin is a Merb plugin that provides an easy-to-use interface for managing your data."
|
26
|
-
self.version = "0.5.
|
26
|
+
self.version = "0.5.5"
|
27
27
|
self.author = "Erik Michaels-Ober"
|
28
28
|
|
29
29
|
# Stub classes loaded hook - runs before LoadClasses BootLoader
|
@@ -5,7 +5,7 @@ class CreateTeamsMigration < ActiveRecord::Migration
|
|
5
5
|
t.integer :league_id
|
6
6
|
t.integer :division_id
|
7
7
|
t.string :name, :limit => 50, :null => false
|
8
|
-
t.string :
|
8
|
+
t.string :logo_url, :limit => 255
|
9
9
|
t.string :manager, :limit => 100, :null => false
|
10
10
|
t.string :ballpark, :limit => 100
|
11
11
|
t.string :mascot, :limit => 100
|
@@ -7,7 +7,7 @@ class Team
|
|
7
7
|
property :league_id, Integer, :nullable => false, :index => true
|
8
8
|
property :division_id, Integer, :nullable => false, :index => true
|
9
9
|
property :name, String, :nullable => false, :index => true
|
10
|
-
property :
|
10
|
+
property :logo_url, String, :length => 255
|
11
11
|
property :manager, String, :length => 100, :nullable => false, :index => true
|
12
12
|
property :ballpark, String, :length => 100, :index => true
|
13
13
|
property :mascot, String, :length => 100, :index => true
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: merb-admin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erik Michaels-Ober
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-15 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|