upmin-admin 0.0.39 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +25 -14
  3. data/Rakefile +24 -15
  4. data/app/assets/javascripts/upmin/application.js +0 -1
  5. data/app/assets/stylesheets/upmin/base.css.scss +4 -0
  6. data/app/assets/stylesheets/upmin/instances.css.scss +11 -1
  7. data/app/controllers/upmin/models_controller.rb +52 -42
  8. data/app/views/layouts/upmin/_navbar.html.haml +3 -3
  9. data/app/views/layouts/upmin/application.html.haml +2 -1
  10. data/app/views/upmin/models/new.html.haml +3 -3
  11. data/app/views/upmin/models/search.html.haml +5 -4
  12. data/app/views/upmin/models/show.html.haml +3 -3
  13. data/app/views/upmin/partials/actions/_action.html.haml +6 -21
  14. data/app/views/upmin/partials/associations/_associations.html.haml +8 -10
  15. data/app/views/upmin/partials/attributes/_boolean.html.haml +8 -6
  16. data/app/views/upmin/partials/attributes/_datetime.html.haml +38 -36
  17. data/app/views/upmin/partials/attributes/_decimal.html.haml +10 -0
  18. data/app/views/upmin/partials/attributes/_float.html.haml +10 -6
  19. data/app/views/upmin/partials/attributes/_integer.html.haml +10 -6
  20. data/app/views/upmin/partials/attributes/_progress_bar.html.haml +1 -0
  21. data/app/views/upmin/partials/attributes/_string.html.haml +17 -6
  22. data/app/views/upmin/partials/attributes/_text.html.haml +8 -6
  23. data/app/views/upmin/partials/attributes/_unknown.html.haml +5 -3
  24. data/app/views/upmin/partials/models/_model.html.haml +18 -46
  25. data/app/views/upmin/partials/models/_new_model.html.haml +9 -31
  26. data/app/views/upmin/partials/parameters/_block_parameter.haml +0 -0
  27. data/app/views/upmin/partials/parameters/_opt_parameter.html.haml +14 -0
  28. data/app/views/upmin/partials/parameters/_req_parameter.html.haml +4 -0
  29. data/app/views/upmin/partials/search_boxes/_ransack_search_box.html.haml +2 -3
  30. data/app/views/upmin/partials/search_results/_results.html.haml +9 -2
  31. data/lib/upmin/action.rb +50 -0
  32. data/lib/upmin/active_record/association.rb +47 -0
  33. data/lib/upmin/active_record/model.rb +54 -0
  34. data/lib/upmin/active_record/query.rb +12 -0
  35. data/lib/upmin/admin.rb +24 -2
  36. data/lib/upmin/association.rb +73 -0
  37. data/lib/upmin/attribute.rb +87 -0
  38. data/lib/upmin/automatic_delegation.rb +76 -0
  39. data/lib/upmin/configuration.rb +103 -0
  40. data/lib/upmin/data_mapper/association.rb +57 -0
  41. data/lib/upmin/data_mapper/model.rb +62 -0
  42. data/lib/upmin/data_mapper/query.rb +57 -0
  43. data/lib/upmin/engine.rb +2 -0
  44. data/lib/upmin/errors.rb +43 -0
  45. data/lib/upmin/model.rb +267 -98
  46. data/lib/upmin/parameter.rb +43 -0
  47. data/lib/upmin/query.rb +51 -0
  48. data/lib/upmin/railtie.rb +11 -1
  49. data/lib/upmin/railties/active_record.rb +5 -50
  50. data/lib/upmin/railties/data_mapper.rb +18 -0
  51. data/lib/upmin/railties/render.rb +34 -98
  52. data/lib/upmin/railties/render_helpers.rb +119 -53
  53. data/lib/upmin/version.rb +1 -1
  54. data/spec/factories/factories.rb +6 -0
  55. data/spec/features/action_spec.rb +39 -46
  56. data/spec/features/edit_model_spec.rb +4 -2
  57. data/spec/features/navbar_spec.rb +48 -0
  58. data/spec/features/new_model_spec.rb +1 -0
  59. data/spec/features/search_spec.rb +7 -4
  60. data/spec/lib/configuration_spec.rb +60 -0
  61. data/spec/spec_helper.rb +14 -8
  62. metadata +25 -7
  63. data/app/assets/javascripts/upmin/moment.js +0 -2856
  64. data/app/helpers/upmin/instances_helper.rb +0 -13
  65. data/app/views/upmin/partials/attributes/_nilable.html.haml +0 -14
  66. data/app/views/upmin/partials/search_results/_result.html.haml +0 -8
  67. data/lib/upmin/klass.rb +0 -170
@@ -1,13 +0,0 @@
1
- module Upmin
2
- module InstancesHelper
3
-
4
- def models_path
5
- return "#{root_path}models/"
6
- end
7
-
8
- def instance_path(instance)
9
- return "#{models_path}#{instance.class.name}/#{instance.id}"
10
- end
11
-
12
- end
13
- end
@@ -1,14 +0,0 @@
1
- - if editable && f = form_builder
2
- -# TODO(jon): Find a better place for code like this. Kinda sucks to have it in the view.
3
- - is_nil = upmin_model.attribute(attr_name).nil? && !upmin_model.instance.new_record?
4
- .input-group
5
- = up_attribute(upmin_model.instance, attr_name, locals: { form_builder: form_builder })
6
- .input-group-addon.nilable-addon
7
- .form-group
8
- %label{for: "#{upmin_model.klass.name.underscore}_#{attr_name}_is_nil"}
9
- Make This Nil
10
- = check_box(upmin_model.klass.name.underscore, "#{attr_name}_is_nil", class: "boolean", checked: is_nil, value: is_nil)
11
-
12
- - else
13
- %p.well
14
- = nilable
@@ -1,8 +0,0 @@
1
- %a.search-result-link{href: upmin_model_path(upmin_model.path_hash)}
2
- .upmin-model{class: upmin_model.color}
3
- %dl.dl-horizontal
4
- - @klass.attributes.each do |attribute|
5
- %dt
6
- = upmin_model.attribute_label_name(attribute)
7
- %dd
8
- = upmin_model.attribute(attribute)
@@ -1,170 +0,0 @@
1
- module Upmin
2
- class Klass
3
-
4
- attr_accessor :model
5
- attr_accessor :color
6
-
7
- def initialize(model, options = {})
8
- self.model = model
9
-
10
- if options[:color]
11
- self.color = options[:color]
12
- end
13
- end
14
-
15
- def new(*args)
16
- m = model.new(*args)
17
- return Upmin::Model.new(m)
18
- end
19
-
20
- # Exposing a model method, but wrapping the result in
21
- # an Upmin::Model
22
- def find(*args)
23
- return Upmin::Model.new(model.find(*args))
24
- end
25
-
26
- def ransack(*args)
27
- return model.ransack(*args)
28
- end
29
-
30
-
31
- # Returns all of the upmin attributes for the ActiveRecord model
32
- # referenced by this Klass object.
33
- def attributes
34
- return model.upmin_attributes
35
- end
36
-
37
- # Returns the type for an attribute by checking the columns
38
- # hash. If no match can be found, :unknown is returned.
39
- # NOTE - the Upmin::Model version of this will look at the
40
- # actual contents of the attr_name if :unknown is returned,
41
- # so this version is more accurate if you can use it.
42
- def attribute_type(attr_name)
43
- if connection_adapter = model.columns_hash[attr_name.to_s]
44
- return connection_adapter.type
45
- else
46
- return :unknown
47
- end
48
- end
49
-
50
-
51
- # Returns all of the upmin actions for the ActiveRecord model
52
- # referenced by this Klass object.
53
- def actions
54
- return model.upmin_actions
55
- end
56
-
57
- # Returns all associations that are not used in through associations
58
- # eg - an Order's products, but not an order's product_orders that link the two.
59
- def associations
60
- return @associations if defined?(@associations)
61
-
62
- all = []
63
- ignored = []
64
- model.reflect_on_all_associations.each do |reflection|
65
- all << reflection.name.to_sym
66
-
67
- # We need to remove the ignored later because we don't know the order they come in.
68
- if reflection.is_a?(::ActiveRecord::Reflection::ThroughReflection)
69
- ignored << reflection.options[:through]
70
- end
71
- end
72
-
73
- return @associations = all - ignored
74
- end
75
-
76
- # Tries to find an association type based on the reflection
77
- def association_type(assoc_name)
78
- reflection = reflections.select { |r| r.name == assoc_name.to_sym }.first
79
-
80
- if reflection
81
- return reflection.foreign_type.to_s.gsub(/_type$/, "").pluralize.to_sym
82
- else
83
- return :unknown
84
- end
85
- end
86
-
87
- def plural_associations
88
- return model.reflect_on_all_associations
89
- .select{ |r| r.collection? }
90
- .map{ |r| r.name.to_sym }
91
- end
92
-
93
- def reflections
94
- return model.reflect_on_all_associations
95
- end
96
-
97
-
98
-
99
- ## Methods for prettying up things to display them in views etc.
100
-
101
- # Returns the class name, split at camelCase,
102
- # with the last word pluralized if it is plural.
103
- def humanized_name(type = :plural)
104
- names = model.name.split(/(?=[A-Z])/)
105
- if type == :plural
106
- names[names.length-1] = names.last.pluralize
107
- end
108
- return names.join(" ")
109
- end
110
-
111
- # Returns the class name, capitalized as it would be with User.name or OrderShipment.name - "User", or "OrderShipment"
112
- def name
113
- return model.name
114
- end
115
-
116
- def path_hash
117
- return {
118
- klass: klass.name
119
- }
120
- end
121
-
122
-
123
-
124
- ## Class Methods
125
-
126
- # Takes a Rails ActiveRecord or the name of one and returns an
127
- # Upmin::Klass instance of the model.
128
- def Klass.find(model)
129
- return all.select{|k| k.name == model.to_s}.first
130
- end
131
-
132
- # Returns an array of all Klass instances
133
- def Klass.all
134
- return @all if defined?(@all)
135
- all = []
136
-
137
- models.each_with_index do |model, i|
138
- klass = Klass.new(model, color: colors[i % colors.length])
139
- all << klass
140
- end
141
-
142
- return @all = all
143
- end
144
-
145
- def Klass.colors
146
- return [
147
- :light_blue,
148
- :blue_green,
149
- :red,
150
- :yellow,
151
- :orange,
152
- :purple,
153
- :dark_blue,
154
- :dark_red,
155
- :green
156
- ]
157
- end
158
-
159
- def Klass.models
160
- # If Rails
161
- ::Rails.application.eager_load!
162
- rails_models = ::ActiveRecord::Base.descendants.select do |m|
163
- m.to_s != "ActiveRecord::SchemaMigration"
164
- end
165
-
166
- return rails_models
167
- end
168
-
169
- end
170
- end