upmin 0.0.34

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +34 -0
  3. data/app/assets/images/upmin/logo_large.png +0 -0
  4. data/app/assets/images/upmin/logo_small.png +0 -0
  5. data/app/assets/javascripts/upmin/application.js +38 -0
  6. data/app/assets/javascripts/upmin/jquery-clockpicker.js +729 -0
  7. data/app/assets/javascripts/upmin/models.js +23 -0
  8. data/app/assets/javascripts/upmin/pikaday.js +997 -0
  9. data/app/assets/stylesheets/upmin/application.css +16 -0
  10. data/app/assets/stylesheets/upmin/base.css.scss +24 -0
  11. data/app/assets/stylesheets/upmin/button_mixins.scss +37 -0
  12. data/app/assets/stylesheets/upmin/colors.scss +20 -0
  13. data/app/assets/stylesheets/upmin/instances.css.scss +91 -0
  14. data/app/assets/stylesheets/upmin/jquery-clockpicker.css +370 -0
  15. data/app/assets/stylesheets/upmin/models.css.scss +207 -0
  16. data/app/assets/stylesheets/upmin/pikaday.css +196 -0
  17. data/app/controllers/upmin/application_controller.rb +4 -0
  18. data/app/controllers/upmin/models_controller.rb +94 -0
  19. data/app/helpers/upmin/application_helper.rb +17 -0
  20. data/app/helpers/upmin/instances_helper.rb +13 -0
  21. data/app/helpers/upmin/models_helper.rb +4 -0
  22. data/app/views/layouts/upmin/_navbar.html.haml +15 -0
  23. data/app/views/layouts/upmin/application.html.haml +24 -0
  24. data/app/views/upmin/models/_search_result.html.haml +25 -0
  25. data/app/views/upmin/models/dashboard.html.haml +9 -0
  26. data/app/views/upmin/models/search.html.haml +20 -0
  27. data/app/views/upmin/models/show.html.haml +21 -0
  28. data/app/views/upmin/search_boxes/_unknown.html.haml +31 -0
  29. data/app/views/upmin/search_fields/_string.html.haml +3 -0
  30. data/app/views/upmin/types/_datetime.html.haml +95 -0
  31. data/app/views/upmin/types/_integer.html.haml +6 -0
  32. data/app/views/upmin/types/_string.html.haml +7 -0
  33. data/app/views/upmin/types/_unknown.html.haml +2 -0
  34. data/app/views/upmin/types/_unknown_collection.html.haml +18 -0
  35. data/app/views/upmin/types/_unknown_model.html.haml +57 -0
  36. data/app/views/upmin/types/_unknown_model_badge.html.haml +3 -0
  37. data/app/views/upmin/types/_unknown_model_nested.html.haml +24 -0
  38. data/app/views/upmin/types/_unknown_model_search_result.html.haml +31 -0
  39. data/config/routes.rb +19 -0
  40. data/lib/tasks/accordive_rails_tasks.rake +4 -0
  41. data/lib/tasks/upmin_tasks.rake +4 -0
  42. data/lib/upmin.rb +44 -0
  43. data/lib/upmin/engine.rb +7 -0
  44. data/lib/upmin/graph/collection_node.rb +72 -0
  45. data/lib/upmin/graph/data_node.rb +69 -0
  46. data/lib/upmin/graph/model_node.rb +151 -0
  47. data/lib/upmin/graph/node.rb +98 -0
  48. data/lib/upmin/model.rb +131 -0
  49. data/lib/upmin/railtie.rb +19 -0
  50. data/lib/upmin/railties/active_record.rb +156 -0
  51. data/lib/upmin/railties/render.rb +56 -0
  52. data/lib/upmin/railties/render_helpers.rb +57 -0
  53. data/lib/upmin/version.rb +3 -0
  54. data/test/controllers/upmin/model_controller_test.rb +11 -0
  55. data/test/dummy/README.rdoc +28 -0
  56. data/test/dummy/Rakefile +6 -0
  57. data/test/dummy/app/assets/javascripts/application.js +13 -0
  58. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  59. data/test/dummy/app/controllers/application_controller.rb +5 -0
  60. data/test/dummy/app/helpers/application_helper.rb +2 -0
  61. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  62. data/test/dummy/bin/bundle +3 -0
  63. data/test/dummy/bin/rails +4 -0
  64. data/test/dummy/bin/rake +4 -0
  65. data/test/dummy/config.ru +4 -0
  66. data/test/dummy/config/application.rb +23 -0
  67. data/test/dummy/config/boot.rb +5 -0
  68. data/test/dummy/config/database.yml +25 -0
  69. data/test/dummy/config/environment.rb +5 -0
  70. data/test/dummy/config/environments/development.rb +37 -0
  71. data/test/dummy/config/environments/production.rb +83 -0
  72. data/test/dummy/config/environments/test.rb +39 -0
  73. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  74. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  75. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  76. data/test/dummy/config/initializers/inflections.rb +16 -0
  77. data/test/dummy/config/initializers/mime_types.rb +4 -0
  78. data/test/dummy/config/initializers/session_store.rb +3 -0
  79. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  80. data/test/dummy/config/locales/en.yml +23 -0
  81. data/test/dummy/config/routes.rb +4 -0
  82. data/test/dummy/config/secrets.yml +22 -0
  83. data/test/dummy/public/404.html +67 -0
  84. data/test/dummy/public/422.html +67 -0
  85. data/test/dummy/public/500.html +66 -0
  86. data/test/dummy/public/favicon.ico +0 -0
  87. data/test/helpers/upmin/model_helper_test.rb +6 -0
  88. data/test/integration/navigation_test.rb +10 -0
  89. data/test/test_helper.rb +15 -0
  90. data/test/upmin_test.rb +7 -0
  91. metadata +253 -0
@@ -0,0 +1,19 @@
1
+ Upmin::Engine.routes.draw do
2
+ root to: "models#dashboard"
3
+
4
+ scope :models do
5
+ # TODO(jon): Put dashboards elsewhere prob.. whatever for now.
6
+ get "/", as: :upmin_dashboard, controller: :models, action: :dashboard
7
+
8
+ scope "/:model_name" do
9
+ match "/", as: :upmin_search, controller: :models, action: :search, via: [:get, :post]
10
+
11
+ scope "/:id" do
12
+ get "/", as: :upmin_model, controller: :models, action: :show
13
+ put "/", controller: :models, action: :update
14
+
15
+ post "/:method", as: :upmin_action, controller: :models, action: :action
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :accordive_rails do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :upmin do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,44 @@
1
+ require "upmin/engine"
2
+
3
+ require "upmin/model"
4
+
5
+ # For displaying views and finding children
6
+ require "upmin/graph/collection_node"
7
+ require "upmin/graph/data_node"
8
+ require "upmin/graph/model_node"
9
+
10
+ # Monkey patch code into rails
11
+ require "upmin/railties/active_record"
12
+ # require "upmin/active_record_relation"
13
+ require "upmin/railties/render"
14
+ require "upmin/railties/render_helpers"
15
+ require "upmin/railtie"
16
+
17
+ # gems and stuff we use
18
+ require "ransack"
19
+ require "typhoeus"
20
+ require "haml"
21
+ require "sass-rails"
22
+
23
+ module Upmin
24
+
25
+ def Upmin.api_key=(api_key)
26
+ @@api_key = api_key
27
+ # Upmin.notify_upmin
28
+ end
29
+
30
+ def Upmin.api_key
31
+ if (defined? @@api_key)
32
+ return @@api_key
33
+ else
34
+ raise "Upmin API key is not set."
35
+ end
36
+ end
37
+
38
+ # def Upmin.notify_upmin
39
+ # # TODO(jon): Add if prod check here (and maybe other spots?)
40
+ # resp = Typhoeus.get(init_url, followlocation: true, params: { api_key: Upmin.api_key })
41
+ # puts JSON.parse(resp.body)
42
+ # end
43
+
44
+ end
@@ -0,0 +1,7 @@
1
+ # require 'haml-rails'
2
+
3
+ module Upmin
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace Upmin
6
+ end
7
+ end
@@ -0,0 +1,72 @@
1
+ module Upmin::Graph
2
+ class CollectionNode
3
+ def initialize(collection, options = {})
4
+ @collection = collection
5
+ @options = options
6
+ end
7
+
8
+ def collection
9
+ return @collection
10
+ end
11
+ alias_method :object, :collection
12
+
13
+ def options
14
+ return @options
15
+ end
16
+
17
+ def depth
18
+ return options[:depth] ||= 0
19
+ end
20
+
21
+ def editable?
22
+ return options[:editable] if options[:editable]
23
+ return options[:editable] = false
24
+ end
25
+
26
+ def type
27
+ return options[:type] ||= determine_type
28
+ end
29
+
30
+ def method_name
31
+ return options[:method_name] || nil
32
+ end
33
+
34
+ def nodes
35
+ return @nodes ||= create_nodes
36
+ end
37
+
38
+ private
39
+ def determine_type
40
+ # TODO(jon): Maybe optimize multi-type collections? Prob don't need this much work to figure them out.
41
+ if collection.any?
42
+ klasses = collection.map{|c| c.class.to_s.underscore.to_sym}
43
+ if klasses.uniq.length == 1
44
+ return "#{klasses.first}_collection".to_sym
45
+ end
46
+ end
47
+
48
+ if method_name
49
+ return "#{method_name.to_s.singularize}_collection"
50
+ else
51
+ return :unknown_collection
52
+ end
53
+ end
54
+
55
+ def create_nodes
56
+ nodes = []
57
+ node_options = {
58
+ depth: depth,
59
+ editable: editable?
60
+ }
61
+ collection.each do |collection_item|
62
+ if collection_item.is_a?(ActiveRecord::Base)
63
+ nodes << ModelNode.new(collection_item, node_options)
64
+ else
65
+ nodes << DataNode.new(collection_item, node_options)
66
+ end
67
+ end
68
+ return nodes
69
+ end
70
+
71
+ end
72
+ end
@@ -0,0 +1,69 @@
1
+ module Upmin::Graph
2
+ class Upmin::Graph::DataNode
3
+ def initialize(data, options = {})
4
+ @data = data
5
+ @options = options
6
+ end
7
+
8
+ def data
9
+ return @data
10
+ end
11
+ alias_method :object, :data
12
+
13
+ def options
14
+ return @options
15
+ end
16
+
17
+ def depth
18
+ return options[:depth] ||= 0
19
+ end
20
+
21
+ def editable?
22
+ return options[:editable] unless options[:editable].nil?
23
+ return options[:editable] = false
24
+ end
25
+
26
+ def type
27
+ return options[:type] ||= determine_type
28
+ end
29
+
30
+ def method_name
31
+ return options[:method_name] || nil
32
+ end
33
+
34
+ def parent_name
35
+ return options[:parent_name] || nil
36
+ end
37
+
38
+ def form_name
39
+ return "#{parent_name}[#{method_name}]"
40
+ end
41
+
42
+ def form_id
43
+ return "#{parent_name}_#{method_name}"
44
+ end
45
+
46
+
47
+
48
+ private
49
+
50
+ def determine_type
51
+ # Preferably this gets set by the model, but in the case that it isn't we try to determine it with the data
52
+ class_name = data.class.to_s.underscore.to_sym
53
+ if class_name == :false_class || class_name == :true_class
54
+ return :boolean
55
+ elsif class_name == :nil_class
56
+ return :unknown
57
+ elsif class_name == :fixnum
58
+ return :integer
59
+ elsif class_name == :big_decimal
60
+ return :decimal
61
+ elsif class_name == :"active_support/time_with_zone"
62
+ return :datetime
63
+ else
64
+ # TODO(jon): Determine if we need more for things like binary, date, timestamp, etc.
65
+ return class_name
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,151 @@
1
+ module Upmin::Graph
2
+ class ModelNode
3
+ def initialize(model, options = {})
4
+ @model = model
5
+ @options = options
6
+ end
7
+
8
+ def model
9
+ return @model
10
+ end
11
+ alias_method :object, :model
12
+
13
+ def options
14
+ return @options
15
+ end
16
+
17
+ def depth
18
+ return options[:depth] ||= 0
19
+ end
20
+
21
+ def editable?
22
+ return options[:editable] if options[:editable]
23
+ return options[:editable] = true
24
+ end
25
+
26
+ def type
27
+ return options[:type] ||= determine_type
28
+ end
29
+
30
+ def method_name
31
+ return options[:method_name] || nil
32
+ end
33
+
34
+ def name
35
+ return model.upmin_name(:singular)
36
+ end
37
+
38
+ def title
39
+ # TODO(jon): Add block option for custom defined titles
40
+ return "#{name} # #{model.id}"
41
+ end
42
+
43
+ def color
44
+ return model.upmin_color
45
+ end
46
+
47
+ def path_hash
48
+ return {
49
+ model_name: model.class.to_s,
50
+ id: model.id
51
+ }
52
+ end
53
+
54
+ # TODO(jon): Add the following methods:
55
+
56
+
57
+ def attributes
58
+ return @attributes ||= create_attributes
59
+ end
60
+
61
+ def children
62
+ if depth >= 1
63
+ return [] # nothing beyond a depth of 2
64
+ else
65
+ return @children ||= create_children
66
+ end
67
+ end
68
+
69
+ def singletons
70
+ return @singletons if @singletons
71
+ create_children # backfill this if not defined
72
+ return @singletons
73
+ end
74
+
75
+ def collections
76
+ return @collections if @collections
77
+ create_children # backfill this if not defined
78
+ return @collections
79
+ end
80
+
81
+ def type_prefix
82
+ name = model.class.to_s.underscore
83
+ return name
84
+ end
85
+
86
+ def type_suffix
87
+ if depth == 0
88
+ return "_model"
89
+ elsif depth >= 1
90
+ return "_model_nested"
91
+ # else
92
+ # return "_model_badge"
93
+ end
94
+ end
95
+
96
+ private
97
+ def determine_type
98
+ return "#{type_prefix}#{type_suffix}".to_sym
99
+ end
100
+
101
+ def create_attributes
102
+ attributes = {}
103
+ editable = (depth == 0)
104
+
105
+ model.upmin_attributes.each do |u_attr|
106
+ attributes[u_attr] = DataNode.new(
107
+ model.upmin_get_attr(u_attr), {
108
+ depth: depth + 1,
109
+ editable: editable && model.upmin_attr_editable?(u_attr),
110
+ type: model.upmin_attr_type(u_attr),
111
+ method_name: u_attr,
112
+ parent_name: model.class.to_s.underscore
113
+ })
114
+ end
115
+ return attributes
116
+ end
117
+
118
+ def create_children
119
+ singletons = {}
120
+ collections = {}
121
+
122
+ model.upmin_associations.each do |association|
123
+ puts "Association=#{association}"
124
+ v = model.upmin_get_assoc(association)
125
+ puts "Value for assoc is: #{v} #{v.inspect}"
126
+ options = {
127
+ depth: depth + 1,
128
+ editable: (depth == 0),
129
+ method_name: association.to_sym
130
+ }
131
+ puts options.inspect
132
+ puts options.inspect
133
+ puts options.inspect
134
+ puts options.inspect
135
+
136
+ if v.nil?
137
+ singletons[association] = DataNode.new(nil, options.merge(type: :unknown))
138
+ elsif v.is_a?(ActiveRecord::Base)
139
+ singletons[association] = ModelNode.new(v, options)
140
+ else
141
+ collections[association] = CollectionNode.new(v, options)
142
+ end
143
+ end
144
+
145
+ @singletons = singletons
146
+ @collections = collections
147
+ return @singletons.merge(@collections)
148
+ end
149
+
150
+ end
151
+ end
@@ -0,0 +1,98 @@
1
+ # module Upmin
2
+ # module Graph
3
+ # end
4
+ # end
5
+
6
+ # class Upmin::Graph::Node
7
+ # def initialize(model, depth = 0)
8
+ # @model = model
9
+ # @depth = depth
10
+ # end
11
+
12
+ # def model
13
+ # return @model
14
+ # end
15
+
16
+ # def depth
17
+ # return @depth
18
+ # end
19
+
20
+ # def attributes
21
+ # return @attributes ||= create_attributes
22
+ # end
23
+
24
+ # def children
25
+ # if @depth >= 2
26
+ # return [] # nothing beyond a depth of 2
27
+ # else
28
+ # return @children ||= create_children
29
+ # end
30
+ # end
31
+
32
+ # private
33
+ # def create_attributes
34
+ # attributes = []
35
+ # model.upmin_attributes.each do |u_attr|
36
+ # attributes << {
37
+ # name: u_attr.to_sym,
38
+ # value: model.upmin_get(u_attr),
39
+ # editable: depth == 0 && model.upmin_attr_editable?(u_attr),
40
+ # type: model.upmin_attr_type(u_attr)
41
+ # }
42
+ # end
43
+ # return attributes
44
+ # end
45
+
46
+ # def create_children
47
+ # @singletons = []
48
+ # @collections = []
49
+ # model.upmin_associations.each do |association|
50
+ # puts "Association=#{association}"
51
+ # v = model.upmin_get_assoc(association)
52
+ # puts "Value for assoc is: #{v} #{v.inspect}"
53
+ # options = {
54
+ # depth: depth + 1,
55
+ # editable: false
56
+ # }
57
+
58
+ # if v.nil?
59
+ # @singletons << DataNode.new(nil, depth: depth + 1)
60
+ # elsif true
61
+
62
+ # else
63
+
64
+ # end
65
+
66
+ # hash = {
67
+ # name: association.to_sym,
68
+ # }
69
+ # if v.nil?
70
+ # # TODO(jon): Make this work better
71
+ # @singletons << hash.merge({
72
+ # value: nil,
73
+ # editable: false,
74
+ # type: :nil
75
+ # })
76
+ # elsif v.is_a?(ActiveRecord::Base)
77
+ # @singletons << hash.merge({
78
+ # value: Node.new(v, depth + 1),
79
+ # editable: false,
80
+ # type: v.class.to_s.underscore.to_sym
81
+ # })
82
+ # else # Assume it is a collection or nil
83
+ # type = :nil
84
+ # type = v.first.class.to_s.underscore if v.any?
85
+ # type = "#{type}_collection".to_sym
86
+
87
+ # @collections << hash.merge({
88
+ # value: "",
89
+ # editable: false,
90
+ # type: type
91
+ # })
92
+ # end
93
+ # end
94
+
95
+ # return @singletons + @collections
96
+ # end
97
+
98
+ # end