upmin 0.0.34
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Rakefile +34 -0
- data/app/assets/images/upmin/logo_large.png +0 -0
- data/app/assets/images/upmin/logo_small.png +0 -0
- data/app/assets/javascripts/upmin/application.js +38 -0
- data/app/assets/javascripts/upmin/jquery-clockpicker.js +729 -0
- data/app/assets/javascripts/upmin/models.js +23 -0
- data/app/assets/javascripts/upmin/pikaday.js +997 -0
- data/app/assets/stylesheets/upmin/application.css +16 -0
- data/app/assets/stylesheets/upmin/base.css.scss +24 -0
- data/app/assets/stylesheets/upmin/button_mixins.scss +37 -0
- data/app/assets/stylesheets/upmin/colors.scss +20 -0
- data/app/assets/stylesheets/upmin/instances.css.scss +91 -0
- data/app/assets/stylesheets/upmin/jquery-clockpicker.css +370 -0
- data/app/assets/stylesheets/upmin/models.css.scss +207 -0
- data/app/assets/stylesheets/upmin/pikaday.css +196 -0
- data/app/controllers/upmin/application_controller.rb +4 -0
- data/app/controllers/upmin/models_controller.rb +94 -0
- data/app/helpers/upmin/application_helper.rb +17 -0
- data/app/helpers/upmin/instances_helper.rb +13 -0
- data/app/helpers/upmin/models_helper.rb +4 -0
- data/app/views/layouts/upmin/_navbar.html.haml +15 -0
- data/app/views/layouts/upmin/application.html.haml +24 -0
- data/app/views/upmin/models/_search_result.html.haml +25 -0
- data/app/views/upmin/models/dashboard.html.haml +9 -0
- data/app/views/upmin/models/search.html.haml +20 -0
- data/app/views/upmin/models/show.html.haml +21 -0
- data/app/views/upmin/search_boxes/_unknown.html.haml +31 -0
- data/app/views/upmin/search_fields/_string.html.haml +3 -0
- data/app/views/upmin/types/_datetime.html.haml +95 -0
- data/app/views/upmin/types/_integer.html.haml +6 -0
- data/app/views/upmin/types/_string.html.haml +7 -0
- data/app/views/upmin/types/_unknown.html.haml +2 -0
- data/app/views/upmin/types/_unknown_collection.html.haml +18 -0
- data/app/views/upmin/types/_unknown_model.html.haml +57 -0
- data/app/views/upmin/types/_unknown_model_badge.html.haml +3 -0
- data/app/views/upmin/types/_unknown_model_nested.html.haml +24 -0
- data/app/views/upmin/types/_unknown_model_search_result.html.haml +31 -0
- data/config/routes.rb +19 -0
- data/lib/tasks/accordive_rails_tasks.rake +4 -0
- data/lib/tasks/upmin_tasks.rake +4 -0
- data/lib/upmin.rb +44 -0
- data/lib/upmin/engine.rb +7 -0
- data/lib/upmin/graph/collection_node.rb +72 -0
- data/lib/upmin/graph/data_node.rb +69 -0
- data/lib/upmin/graph/model_node.rb +151 -0
- data/lib/upmin/graph/node.rb +98 -0
- data/lib/upmin/model.rb +131 -0
- data/lib/upmin/railtie.rb +19 -0
- data/lib/upmin/railties/active_record.rb +156 -0
- data/lib/upmin/railties/render.rb +56 -0
- data/lib/upmin/railties/render_helpers.rb +57 -0
- data/lib/upmin/version.rb +3 -0
- data/test/controllers/upmin/model_controller_test.rb +11 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +83 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/helpers/upmin/model_helper_test.rb +6 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/test_helper.rb +15 -0
- data/test/upmin_test.rb +7 -0
- metadata +253 -0
data/lib/upmin/model.rb
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
module Upmin
|
2
|
+
class Model
|
3
|
+
|
4
|
+
attr_accessor :rails_model
|
5
|
+
attr_accessor :color
|
6
|
+
|
7
|
+
def initialize(rails_model, options = {})
|
8
|
+
self.rails_model = rails_model
|
9
|
+
|
10
|
+
if options[:color]
|
11
|
+
self.color = options[:color]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
return rails_model.to_s
|
17
|
+
end
|
18
|
+
|
19
|
+
def name
|
20
|
+
return rails_model.name
|
21
|
+
end
|
22
|
+
|
23
|
+
def u_name
|
24
|
+
return rails_model.upmin_name
|
25
|
+
end
|
26
|
+
|
27
|
+
def form_name
|
28
|
+
return rails_model.name.underscore
|
29
|
+
end
|
30
|
+
alias_method :partial_name, :form_name
|
31
|
+
|
32
|
+
# Wrapper methods that the normal model would have access to
|
33
|
+
def find(id)
|
34
|
+
return rails_model.find(id)
|
35
|
+
end
|
36
|
+
|
37
|
+
def search(*args)
|
38
|
+
return self.rails_model.ransack(*args)
|
39
|
+
end
|
40
|
+
alias_method :ransack, :search
|
41
|
+
|
42
|
+
def upmin_methods
|
43
|
+
return self.rails_model.upmin_methods
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
# Methods that perform actions on an instance but require some prep and logic ahead of time that shouldn't be injected into the active record.
|
48
|
+
def perform_action(instance, method, arguments)
|
49
|
+
raise "Invalid method: #{method}" unless upmin_methods.include?(method.to_sym)
|
50
|
+
|
51
|
+
params = instance.method(method).parameters
|
52
|
+
args_to_send = []
|
53
|
+
params.each do |type, name|
|
54
|
+
if type == :req
|
55
|
+
raise "Missing argument: #{name}" unless arguments[name]
|
56
|
+
args_to_send << arguments[name]
|
57
|
+
puts "Added: #{arguments[name].inspect}"
|
58
|
+
elsif type == :opt
|
59
|
+
puts arguments.inspect
|
60
|
+
args_to_send << arguments[name] if arguments[name]
|
61
|
+
puts "Added: #{arguments[name].inspect}"
|
62
|
+
else # :block or ??
|
63
|
+
next
|
64
|
+
end
|
65
|
+
end
|
66
|
+
return instance.send(method, *args_to_send)
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
# Methods for determinining attributes, and their types.
|
71
|
+
def attributes
|
72
|
+
return @attributes if defined?(@attributes)
|
73
|
+
|
74
|
+
attributes = {}
|
75
|
+
rails_model.upmin_attributes.each do |u_attr|
|
76
|
+
attributes[u_attr] = {}
|
77
|
+
attributes[u_attr][:type] = get_attr_type(u_attr)
|
78
|
+
end
|
79
|
+
|
80
|
+
return @attributes = attributes
|
81
|
+
end
|
82
|
+
|
83
|
+
def get_attr_type(attr_name)
|
84
|
+
if uc = rails_model.columns_hash[attr_name.to_s]
|
85
|
+
return uc.type
|
86
|
+
else
|
87
|
+
return :unknown
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
## Generic Class Methods
|
93
|
+
def Model.find(name)
|
94
|
+
return all.select{|a| a.to_s == name.to_s}.first
|
95
|
+
end
|
96
|
+
|
97
|
+
# TODO(jon): Store this in the future so it doesn't have to be looked up every call.
|
98
|
+
def Model.all
|
99
|
+
return @models_array if defined?(@models_array)
|
100
|
+
models_array = []
|
101
|
+
colors = [
|
102
|
+
:light_blue,
|
103
|
+
:blue_green,
|
104
|
+
:red,
|
105
|
+
:yellow,
|
106
|
+
:orange,
|
107
|
+
:purple,
|
108
|
+
:dark_blue,
|
109
|
+
:dark_red,
|
110
|
+
:green
|
111
|
+
]
|
112
|
+
|
113
|
+
rails_models.each_with_index do |rails_model, i|
|
114
|
+
ac_model = Model.new(rails_model, color: colors[i % colors.length])
|
115
|
+
models_array << ac_model
|
116
|
+
end
|
117
|
+
|
118
|
+
return @models_array = models_array
|
119
|
+
end
|
120
|
+
|
121
|
+
def Model.rails_models
|
122
|
+
::Rails.application.eager_load!
|
123
|
+
rails_models = ::ActiveRecord::Base.descendants.select do |m|
|
124
|
+
m.to_s != "ActiveRecord::SchemaMigration"
|
125
|
+
end
|
126
|
+
|
127
|
+
return rails_models
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Upmin
|
2
|
+
require 'rails'
|
3
|
+
class Railtie < Rails::Railtie
|
4
|
+
initializer('upmin.insert_into_active_record') do
|
5
|
+
ActiveSupport.on_load(:active_record) do
|
6
|
+
::ActiveRecord::Base.send(:include, Upmin::Railties::ActiveRecord)
|
7
|
+
# ::ActiveRecord::Relation.send(:include, Upmin::ActiveRecordRelation)
|
8
|
+
end
|
9
|
+
|
10
|
+
ActiveSupport.on_load(:action_controller) do
|
11
|
+
::ActionController::Base.send(:include, Upmin::Railties::Render)
|
12
|
+
end
|
13
|
+
|
14
|
+
ActiveSupport.on_load(:action_view) do
|
15
|
+
::ActionView::Base.send(:include, Upmin::Railties::Render)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module Upmin::Railties
|
4
|
+
module ActiveRecord
|
5
|
+
extend ::ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
after_save :notify_upmin_of_save
|
9
|
+
end
|
10
|
+
|
11
|
+
def notify_upmin_of_save
|
12
|
+
# TODO(jon): Add after_save notifications.
|
13
|
+
end
|
14
|
+
|
15
|
+
def upmin_attributes
|
16
|
+
return self.class.upmin_attributes
|
17
|
+
end
|
18
|
+
|
19
|
+
def upmin_associations
|
20
|
+
return self.class.upmin_associations
|
21
|
+
end
|
22
|
+
|
23
|
+
def upmin_collection_reflections
|
24
|
+
return self.class.upmin_collection_reflections
|
25
|
+
end
|
26
|
+
|
27
|
+
def upmin_name(type = :plural)
|
28
|
+
return self.class.upmin_name(type)
|
29
|
+
end
|
30
|
+
|
31
|
+
def upmin_color
|
32
|
+
return self.class.upmin_color
|
33
|
+
end
|
34
|
+
|
35
|
+
def upmin_attr_editable?(attr_name)
|
36
|
+
return false if attr_name.to_sym == :id
|
37
|
+
return false if attr_name.to_sym == :created_at
|
38
|
+
return false if attr_name.to_sym == :updated_at
|
39
|
+
# TODO(jon): Add a way to lock this later
|
40
|
+
return self.respond_to?("#{attr_name}=")
|
41
|
+
end
|
42
|
+
|
43
|
+
def upmin_attr_type(attr_name)
|
44
|
+
if uc = self.class.columns_hash[attr_name.to_s]
|
45
|
+
return uc.type
|
46
|
+
else
|
47
|
+
return :unknown
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def upmin_get_attr(attr_name)
|
52
|
+
return send(attr_name)
|
53
|
+
end
|
54
|
+
|
55
|
+
def upmin_get_assoc(assoc_name)
|
56
|
+
assoc_name = assoc_name.to_sym
|
57
|
+
if upmin_collection_reflections.include?(assoc_name)
|
58
|
+
return send(assoc_name).limit(5)
|
59
|
+
else
|
60
|
+
return send(assoc_name)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
module ClassMethods
|
65
|
+
|
66
|
+
def upmin_attributes(*attributes)
|
67
|
+
if attributes.any?
|
68
|
+
@upmin_attributes = attributes.map{|a| a.to_sym}
|
69
|
+
end
|
70
|
+
@upmin_attributes ||= attribute_names.map{|a| a.to_sym}
|
71
|
+
return @upmin_attributes
|
72
|
+
end
|
73
|
+
|
74
|
+
def upmin_actions(*actions)
|
75
|
+
if actions.any?
|
76
|
+
@upmin_actions = actions.map{|a| a.to_sym}
|
77
|
+
end
|
78
|
+
return @upmin_actions
|
79
|
+
end
|
80
|
+
|
81
|
+
# Alias for upmin_actions
|
82
|
+
def upmin_methods(*methods)
|
83
|
+
return upmin_actions(*methods)
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
def upmin_associations(*associations)
|
88
|
+
if associations.any?
|
89
|
+
@upmin_associations = associations.map{|a| a.to_sym}
|
90
|
+
end
|
91
|
+
return @upmin_associations if defined?(@upmin_associations)
|
92
|
+
|
93
|
+
# TODO(jon): Make this handle through relationships and ignore those.
|
94
|
+
upmin_associations = []
|
95
|
+
ignored_associations = []
|
96
|
+
self.reflect_on_all_associations.each do |reflection|
|
97
|
+
upmin_associations << reflection.name.to_sym
|
98
|
+
if reflection.is_a?(::ActiveRecord::Reflection::ThroughReflection)
|
99
|
+
ignored_associations << reflection.options[:through]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
return @upmin_associations = upmin_associations - ignored_associations
|
103
|
+
end
|
104
|
+
|
105
|
+
def upmin_collection_reflections
|
106
|
+
return @upmin_collection_reflections if defined?(@upmin_collection_reflections)
|
107
|
+
collections = self.reflect_on_all_associations.select do |r|
|
108
|
+
r.collection?
|
109
|
+
end.map do |r|
|
110
|
+
r.name
|
111
|
+
end
|
112
|
+
return @upmin_collection_reflections = collections
|
113
|
+
end
|
114
|
+
|
115
|
+
# def upmin_collections(*collections)
|
116
|
+
# if collections.any?
|
117
|
+
# @upmin_collections = collections.map{|a| a.to_sym}
|
118
|
+
# end
|
119
|
+
# return @upmin_collections if defined?(@upmin_collections)
|
120
|
+
|
121
|
+
# @upmin_collections = []
|
122
|
+
# ignored_collections
|
123
|
+
# self.reflect_on_all_associations.each do |reflection|
|
124
|
+
# @upmin_collections.name.to_sym << if reflection.collection?
|
125
|
+
# if reflection.is_a?(ActiveRecord::Reflection::ThroughReflection)
|
126
|
+
# # We need to figure out what collection to ignore.
|
127
|
+
# @upmin_collections.name.to_sym
|
128
|
+
# end
|
129
|
+
# end
|
130
|
+
# return @upmin_collections
|
131
|
+
# end
|
132
|
+
|
133
|
+
def upmin_actions(*actions)
|
134
|
+
if actions.any?
|
135
|
+
@upmin_actions = actions.map{|a| a.to_sym}
|
136
|
+
end
|
137
|
+
@upmin_actions ||= []
|
138
|
+
return @upmin_actions
|
139
|
+
end
|
140
|
+
|
141
|
+
def upmin_name(type = :plural)
|
142
|
+
names = name.split(/(?=[A-Z])/)
|
143
|
+
if type == :plural
|
144
|
+
names[names.length-1] = names.last.pluralize
|
145
|
+
end
|
146
|
+
return names.join(" ")
|
147
|
+
end
|
148
|
+
|
149
|
+
def upmin_color
|
150
|
+
return @upmin_color if defined?(@upmin_color)
|
151
|
+
return @upmin_color = Upmin::Model.find(self.name).color
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
|
2
|
+
module Upmin::Railties
|
3
|
+
module Render
|
4
|
+
def upmin_render(model_or_node, options = {})
|
5
|
+
if model_or_node.is_a?(::ActiveRecord::Base)
|
6
|
+
upmin_render_node(Upmin::Graph::ModelNode.new(model_or_node), options)
|
7
|
+
|
8
|
+
else # is a node
|
9
|
+
upmin_render_node(model_or_node, options)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def upmin_render_search_box(upmin_model, options = {})
|
14
|
+
partials = RenderHelpers.partials_for_search_box(upmin_model, options)
|
15
|
+
|
16
|
+
partials.each do |partial|
|
17
|
+
begin
|
18
|
+
return render(
|
19
|
+
partial: partial,
|
20
|
+
object: upmin_model, # this doesn't work with nil
|
21
|
+
locals: {
|
22
|
+
upmin_model: upmin_model,
|
23
|
+
options: options
|
24
|
+
}
|
25
|
+
)
|
26
|
+
rescue ActionView::MissingTemplate => e
|
27
|
+
end
|
28
|
+
end
|
29
|
+
raise "Failed to find a matching partial, even with fallback :unknown partials"
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
def upmin_render_node(node, options = {})
|
35
|
+
partials = RenderHelpers.partials_for(node, options)
|
36
|
+
|
37
|
+
# TODO(jon): Update this to use something like https://coderwall.com/p/ftbmsa instead of a rescue
|
38
|
+
partials.each do |partial|
|
39
|
+
puts "Trying #{partial}"
|
40
|
+
begin
|
41
|
+
return render(
|
42
|
+
partial: partial,
|
43
|
+
object: node.object, # this doesn't work with nil
|
44
|
+
locals: {
|
45
|
+
node: node,
|
46
|
+
options: options,
|
47
|
+
RenderHelpers.object_name(partial) => node.object
|
48
|
+
}
|
49
|
+
)
|
50
|
+
rescue ActionView::MissingTemplate => e
|
51
|
+
end
|
52
|
+
end
|
53
|
+
raise "Failed to find a matching partial, even with fallback :unknown partials"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
|
2
|
+
module Upmin::Railties
|
3
|
+
module RenderHelpers
|
4
|
+
def RenderHelpers.partials_for(node, options)
|
5
|
+
partials = []
|
6
|
+
partials << options[:partial] if options[:partial]
|
7
|
+
partials << build_path(options[:as]) if options[:as]
|
8
|
+
partials << build_path(node.type)
|
9
|
+
|
10
|
+
if node.is_a?(Upmin::Graph::ModelNode)
|
11
|
+
partials << build_path("unknown#{node.type_suffix}")
|
12
|
+
elsif node.is_a?(Upmin::Graph::CollectionNode)
|
13
|
+
# TODO(jon): Maybe add in support for method_name later
|
14
|
+
if node.type != :unknown_collection
|
15
|
+
partials << build_path(:unknown_collection)
|
16
|
+
end
|
17
|
+
elsif node.is_a?(Upmin::Graph::DataNode)
|
18
|
+
# TODO(jon): Maybe add in support for method_name later
|
19
|
+
if node.type != :unknown
|
20
|
+
partials << build_path(:unknown)
|
21
|
+
end
|
22
|
+
else
|
23
|
+
# WTF? Add unknown as a backup, but this likely isn't even a node.
|
24
|
+
partials << build_path(:unknown)
|
25
|
+
end
|
26
|
+
|
27
|
+
return partials
|
28
|
+
end
|
29
|
+
|
30
|
+
def RenderHelpers.partials_for_search_box(upmin_model, options)
|
31
|
+
partials = []
|
32
|
+
partials << options[:partial] if options[:partial]
|
33
|
+
partials << build_search_box_path(options[:as]) if options[:as]
|
34
|
+
partials << build_search_box_path(upmin_model.partial_name)
|
35
|
+
partials << build_search_box_path(:unknown)
|
36
|
+
return partials
|
37
|
+
end
|
38
|
+
|
39
|
+
def RenderHelpers.build_path(partial)
|
40
|
+
return "upmin/types/#{partial}"
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
def RenderHelpers.build_search_box_path(partial)
|
45
|
+
return "upmin/search_boxes/#{partial}"
|
46
|
+
end
|
47
|
+
|
48
|
+
def RenderHelpers.object_name(partial)
|
49
|
+
if match = partial.match(/.*\/(.*)/)
|
50
|
+
return match.captures.first
|
51
|
+
else
|
52
|
+
raise "Unable to match object name for the partial #{partial}."
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|