Permalink
Browse files

viewing and editing attribtues works. the attribtue type needs set co…

…rrectly and associaiotns needed added, then finally search
  • Loading branch information...
joncalhoun committed Sep 26, 2014
1 parent ec13802 commit 02b2459c1da3ec7e6931beeb87d890d87e3dcc98
Showing with 1,062 additions and 48 deletions.
  1. +23 −23 app/views/upmin/partials/models/_model.html.haml
  2. +1 −1 app/views/upmin/partials/models/_new_model.html.haml
  3. +22 −0 lib/upmin/active_record_query.rb
  4. +3 −0 lib/upmin/admin.rb
  5. +20 −8 lib/upmin/configuration.rb
  6. +30 −0 lib/upmin/data_mapper_query.rb
  7. +59 −6 lib/upmin/model.rb
  8. +21 −9 lib/upmin/query.rb
  9. +1 −1 lib/upmin/version.rb
  10. +5 −0 spec/spec_helper.rb
  11. +16 −0 test_apps/data_mapper/.gitignore
  12. +3 −0 test_apps/data_mapper/.rspec
  13. +18 −0 test_apps/data_mapper/Gemfile
  14. +28 −0 test_apps/data_mapper/README.rdoc
  15. +6 −0 test_apps/data_mapper/Rakefile
  16. 0 test_apps/data_mapper/app/assets/images/.keep
  17. +16 −0 test_apps/data_mapper/app/assets/javascripts/application.js
  18. +15 −0 test_apps/data_mapper/app/assets/stylesheets/application.css
  19. +5 −0 test_apps/data_mapper/app/controllers/application_controller.rb
  20. 0 test_apps/data_mapper/app/controllers/concerns/.keep
  21. +2 −0 test_apps/data_mapper/app/helpers/application_helper.rb
  22. 0 test_apps/data_mapper/app/mailers/.keep
  23. 0 test_apps/data_mapper/app/models/.keep
  24. 0 test_apps/data_mapper/app/models/concerns/.keep
  25. +17 −0 test_apps/data_mapper/app/models/order.rb
  26. +23 −0 test_apps/data_mapper/app/models/product.rb
  27. +16 −0 test_apps/data_mapper/app/models/product_order.rb
  28. +17 −0 test_apps/data_mapper/app/models/shipment.rb
  29. +15 −0 test_apps/data_mapper/app/models/user.rb
  30. +14 −0 test_apps/data_mapper/app/views/layouts/application.html.erb
  31. +3 −0 test_apps/data_mapper/bin/bundle
  32. +4 −0 test_apps/data_mapper/bin/rails
  33. +4 −0 test_apps/data_mapper/bin/rake
  34. +4 −0 test_apps/data_mapper/config.ru
  35. +30 −0 test_apps/data_mapper/config/application.rb
  36. +4 −0 test_apps/data_mapper/config/boot.rb
  37. +25 −0 test_apps/data_mapper/config/database.yml
  38. +5 −0 test_apps/data_mapper/config/environment.rb
  39. +37 −0 test_apps/data_mapper/config/environments/development.rb
  40. +78 −0 test_apps/data_mapper/config/environments/production.rb
  41. +39 −0 test_apps/data_mapper/config/environments/test.rb
  42. +8 −0 test_apps/data_mapper/config/initializers/assets.rb
  43. +7 −0 test_apps/data_mapper/config/initializers/backtrace_silencers.rb
  44. +3 −0 test_apps/data_mapper/config/initializers/cookies_serializer.rb
  45. +8 −0 test_apps/data_mapper/config/initializers/data_mapper.rb
  46. +4 −0 test_apps/data_mapper/config/initializers/filter_parameter_logging.rb
  47. +16 −0 test_apps/data_mapper/config/initializers/inflections.rb
  48. +4 −0 test_apps/data_mapper/config/initializers/mime_types.rb
  49. +3 −0 test_apps/data_mapper/config/initializers/session_store.rb
  50. +14 −0 test_apps/data_mapper/config/initializers/wrap_parameters.rb
  51. +23 −0 test_apps/data_mapper/config/locales/en.yml
  52. +3 −0 test_apps/data_mapper/config/routes.rb
  53. +22 −0 test_apps/data_mapper/config/secrets.yml
  54. 0 test_apps/data_mapper/lib/assets/.keep
  55. 0 test_apps/data_mapper/lib/tasks/.keep
  56. 0 test_apps/data_mapper/log/.keep
  57. +67 −0 test_apps/data_mapper/public/404.html
  58. +67 −0 test_apps/data_mapper/public/422.html
  59. +66 −0 test_apps/data_mapper/public/500.html
  60. 0 test_apps/data_mapper/public/favicon.ico
  61. +5 −0 test_apps/data_mapper/public/robots.txt
  62. 0 test_apps/data_mapper/vendor/assets/javascripts/.keep
  63. 0 test_apps/data_mapper/vendor/assets/stylesheets/.keep
  64. +41 −0 test_seeders/data_mapper/order_seeder.rb
  65. +26 −0 test_seeders/data_mapper/product_seeder.rb
  66. +9 −0 test_seeders/data_mapper/seeder.rb
  67. +37 −0 test_seeders/data_mapper/user_seeder.rb
  68. 0 upmin-rails.sublime-project → upmin-admin.sublime-project
@@ -10,7 +10,7 @@
.attributes
-# Yes this is meant to be model.model - this is the raw rails model instance.
= form_for(model.model, url: model.path, html: { method: :put }) do |f|
= form_for(model, url: model.path, html: { method: :put }) do |f|
-# Render each attribute
- model.attributes.each do |attribute|
@@ -19,26 +19,26 @@
= f.submit("Save", class: "btn btn-primary")
- if model.associations.any?
%br
%br
%br
%h3{style: "color: #333;"}
Associations
%hr
.associations
- model.associations.each do |association|
= up_render(association)
- if model.actions.any?
%br
%br
%br
%h3{style: "color: #333;"}
Actions
%hr
.actions
- model.actions.each do |action|
= up_render(action)
-# - if model.associations.any?
-# %br
-# %br
-# %br
-# %h3{style: "color: #333;"}
-# Associations
-# %hr
-# .associations
-# - model.associations.each do |association|
-# = up_render(association)
-# - if model.actions.any?
-# %br
-# %br
-# %br
-# %h3{style: "color: #333;"}
-# Actions
-# %hr
-# .actions
-# - model.actions.each do |action|
-# = up_render(action)
@@ -12,7 +12,7 @@
.attributes
-# Yes this is meant to be model.model - this is the raw rails model instance.
= form_for(model.model, url: model.create_path, html: { method: :post }) do |f|
= form_for(model, url: model.create_path, html: { method: :post }) do |f|
-# Render each attribute
- model.attributes.each do |attribute|
@@ -0,0 +1,22 @@
module Upmin
class ActiveRecordQuery < Query
def results
return klass.ransack(search_options).result(distinct: true)
end
def paginated_results
return @paginated_results if defined?(@paginated_results)
if page && per_page
pr = Upmin::Paginator.paginate(results, page, per_page)
else
pr = Upmin::Paginator.paginate(results)
end
@paginated_results = pr
return @paginated_results
end
private
end
end
View
@@ -11,7 +11,10 @@
require "upmin/association"
require "upmin/action"
require "upmin/parameter"
require "upmin/query"
require "upmin/active_record_query"
require "upmin/data_mapper_query"
# Monkey patch code into rails
View
@@ -17,10 +17,7 @@ class Configuration
attr_writer :colors
def initialize
if defined?(ActiveRecord)
# Eager load on init so even if models are set custom an eager load has happened.
::Rails.application.eager_load!
end
::Rails.application.eager_load!
end
def colors
@@ -34,19 +31,34 @@ def models
private
def default_models
def_models = []
orm_found = false
if defined?(ActiveRecord)
# If Rails
orm_found = true
::Rails.application.eager_load!
rails_models = ::ActiveRecord::Base.descendants
def_models += ::ActiveRecord::Base.descendants
.map(&:to_s)
.select{ |m| m != "ActiveRecord::SchemaMigration" }
.sort
.map(&:underscore)
.map(&:to_sym)
return rails_models
else
end
if defined?(DataMapper)
orm_found = true
def_models += DataMapper::Model.descendants.entries
.map(&:to_s)
.sort
.map(&:underscore)
.map(&:to_sym)
end
unless orm_found
raise UnsupportedObjectMapper.new
end
return def_models
end
def default_colors
@@ -0,0 +1,30 @@
module Upmin
class DataMapperQuery < Query
attr_reader :klass
attr_reader :search_options
attr_reader :page
attr_reader :per_page
delegate(:underscore_name, to: :klass)
def initialize(klass, search_options = {}, options = {})
@klass = klass
@search_options = search_options
@page = options[:page]
@per_page = options[:per_page]
end
def results
# TODO(jon): Implement this.
end
def paginated_results
# TODO(jon): Implement this.
end
private
end
end
View
@@ -11,7 +11,7 @@ def initialize(model = nil, options = {})
unless model.has_key?(:id)
raise ":id or model instance is required."
end
@model = self.model_class.find(model[:id])
@model = self.class.find(model[:id])
elsif model.nil?
@model = self.model_class.new
else
@@ -64,6 +64,30 @@ def actions
###########################################################
### Rails methods that may need mapped to something ###
### else with other ORMs ###
###########################################################
def new_record?
if self.class.active_record?
return model.new_record?
elsif self.class.data_mapper?
return model.new?
end
end
def to_key
if self.class.active_record?
return model.to_key
elsif self.class.data_mapper?
# TODO(jon): Make this better, but this may work for now.
return [model.id]
end
end
###########################################################
### Delegated instance methods ###
###########################################################
@@ -114,6 +138,15 @@ def Model.associations
return @associations = all - ignored
end
def Model.find(*args)
if data_mapper?
model_class.get(*args)
elsif active_record?
model_class.find(*args)
end
end
def Model.find_class(model)
return find_or_create_class(model.to_s)
end
@@ -163,6 +196,10 @@ def Model.model_class_name
return name.demodulize[5..-1]
end
def Model.model_name
return ActiveModel::Name.new(model_class)
end
def Model.humanized_name(type = :plural)
names = model_class_name.split(/(?=[A-Z])/)
if type == :plural
@@ -210,6 +247,14 @@ def Model.color_index
return @color_index
end
def Model.active_record?
return model_class.superclass == ActiveRecord::Base
end
def Model.data_mapper?
return model_class.is_a?(DataMapper::Model)
end
###########################################################
### Customization methods for Admin<Model> classes ###
@@ -234,17 +279,25 @@ def Model.attributes(*attributes)
if attributes.any?
@attributes = attributes.map{|a| a.to_sym}
end
@attributes ||= default_attributes
@attributes ||= model_class.attribute_names.map{|a| a.to_sym}
return (@attributes + @extra_attrs).uniq
end
def Model.default_attributes
if active_record?
return model_class.attribute_names.map(&:to_sym)
elsif data_mapper?
return model_class.properties.map(&:name)
end
end
def Model.attribute_type(attribute)
if adapter = model_class.columns_hash[attribute.to_s]
return adapter.type
else
return :unknown
if active_record?
adapter = model_class.columns_hash[attribute.to_s]
return adapter.type if adapter
end
return :unknown
end
# Add a single action to upmin actions. If this is called
View
@@ -8,6 +8,24 @@ class Query
delegate(:underscore_name, to: :klass)
def Query.new(*args)
unless args[0]
raise ::ArgumentError.new("wrong number of arguments (#{args.length} for 1..3)")
end
unless args[0].superclass == Upmin::Model
raise ArgumentError.new(args[0])
end
mc = args[0].model_class
if mc.is_a?(DataMapper::Model)
return DataMapperQuery.new(*args)
elsif mc.superclass == ActiveRecord::Base
return ActiveRecordQuery.new(*args)
else
raise ArgumentError.new(args[0])
end
end
def initialize(klass, search_options = {}, options = {})
@klass = klass
@search_options = search_options
@@ -16,18 +34,11 @@ def initialize(klass, search_options = {}, options = {})
end
def results
return klass.ransack(search_options).result(distinct: true)
raise NotImplementedError
end
def paginated_results
return @paginated_results if defined?(@paginated_results)
if page && per_page
pr = Upmin::Paginator.paginate(results, page, per_page)
else
pr = Upmin::Paginator.paginate(results)
end
@paginated_results = pr
return @paginated_results
raise NotImplementedError
end
def upmin_results
@@ -36,6 +47,7 @@ def upmin_results
return @upmin_results
end
private
end
View
@@ -1,3 +1,3 @@
module Upmin
VERSION = "0.0.39dev10000101"
VERSION = "0.0.39dev10000105"
end
View
@@ -28,6 +28,11 @@
end
config.before(:suite) do
if defined?(DataMapper)
DataMapper.finalize
DataMapper.auto_migrate!
end
Seeder.seed
end
@@ -0,0 +1,16 @@
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'
# Ignore bundler config.
/.bundle
# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
@@ -0,0 +1,3 @@
--color
--require spec_helper
--format=d
Oops, something went wrong.

0 comments on commit 02b2459

Please sign in to comment.