upmin-admin 0.0.39 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -9,13 +9,13 @@
9
9
  %button.close{"data-dismiss" => "alert", type: "button"}
10
10
  %span{"aria-hidden" => "true"} ×
11
11
  = alert
12
- - if @model.instance.errors.any?
12
+ - if @model.errors.any?
13
13
  %ul
14
- - @model.instance.errors.each do |field, error|
14
+ - @model.errors.each do |field, error|
15
15
  %li
16
16
  %b
17
17
  = field
18
18
  = error
19
19
  .row
20
20
  .col-sm-12
21
- = up_model(@model.instance)
21
+ = up_render(@model)
@@ -1,24 +1,9 @@
1
+ %h4{style: "color: #333;"}
2
+ = action.title
1
3
  .well.action-well
2
- = form_tag(upmin_action_path(upmin_model.path_hash.merge(method: action_name))) do
3
- - upmin_model.action_parameters(action_name).each do |param_type, param_name|
4
-
5
- - next if param_type == :block # Skip blocks
6
-
7
- .form-group
8
- = label(action_name, param_name, param_name.to_s.capitalize.gsub("_", " "))
9
-
10
- - if param_type == :opt
11
- .input-group
12
- = text_field(action_name, param_name, class: "form-control")
13
- .input-group-addon.nilable-addon
14
- .form-group
15
- %label{for: "#{action_name}_#{param_name}_is_nil"}
16
- Do Not Provide
17
- = check_box(action_name, "#{param_name}_is_nil", class: "boolean")
18
- %small
19
- * Optional
20
- - else
21
- = text_field(action_name, param_name, class: "form-control")
22
-
4
+ = form_tag(action.path, class: action.name) do
5
+ - action.parameters.each do |parameter|
6
+ -# = Upmin::Railties::RenderHelpers.parameter_partials(parameter)
7
+ = up_render(parameter)
23
8
 
24
9
  = submit_tag("Submit", class: "btn btn-primary")
@@ -1,14 +1,12 @@
1
- - if associations.any?
2
- %p
3
- - associations.each do |u|
4
- - nested_upmin_model = Upmin::Model.new(u)
5
- %a.active-tag-link{href: upmin_model_path(nested_upmin_model.path_hash)}
6
- %span.label{class: nested_upmin_model.color}
7
- = nested_upmin_model.title
1
+ %h5
2
+ = association.title
8
3
 
9
- - else
4
+ - if association.empty?
10
5
  %p.well
11
6
  None
12
7
 
13
-
14
-
8
+ - else
9
+ - association.upmin_values.each do |m|
10
+ %a.active-tag-link{href: m.path}
11
+ %span.label{class: m.color}
12
+ = m.title
@@ -1,8 +1,10 @@
1
- - boolean ||= "false"
1
+ .form-group{class: attribute.errors? ? "has-error" : ""}
2
+ %label{for: attribute.form_id}
3
+ = attribute.label_name
2
4
 
3
- - if editable && f = form_builder
4
- = f.check_box(attr_name, value: boolean, class: "boolean")
5
+ - if attribute.editable? && f = form_builder
6
+ = f.check_box(attribute.name, value: boolean, class: "boolean")
5
7
 
6
- - else
7
- %p.well
8
- = f.check_box(attr_name, {value: boolean, class: "boolean", disabled: "disabled"})
8
+ - else
9
+ %p.well
10
+ = attribute.value
@@ -1,36 +1,38 @@
1
- - datetime ||= nil
2
- - datetime_str = datetime.utc.iso8601 if datetime
3
- - if editable && f = form_builder
4
- .row.datetime-attribute{class: form_id}
5
- = f.hidden_field(attr_name, value: datetime_str)
6
- - # TODO(jon): Figure out a better way to do transforms. This works for now though.
7
- = f.hidden_field("transforms[#{attr_name}]", value: "DateTime#parse")
8
-
9
- .col-xs-12.col-md-4
10
- .input-group.pikadate
11
- %input.form-control{type: :text, value: datetime_str, id: "#{form_id}-date"}
12
- %span.input-group-addon
13
- %span.glyphicon.glyphicon-calendar
14
-
15
- .col-xs-12.col-md-4
16
- .input-group.clockpicker{"data-align" => "top", "data-autoclose" => "true", "data-placement" => "right"}
17
- %input.form-control{:type => "text", :value => datetime_str, id: "#{form_id}-time"}
18
- %span.input-group-addon
19
- %span.glyphicon.glyphicon-time
20
-
21
- .col-xs-12.col-md-4
22
- %small
23
- Date & Time are shown in UTC. If not time is provided, the current time in UTC will be used.
24
-
25
-
26
- - content_for(:javascript) do
27
- :javascript
28
- $(document).ready(function() {
29
- window.Upmin.Attributes.DateTime("#{form_id}");
30
- });
31
-
32
-
33
- - else
34
- %p.well
35
- -# TODO(jon): Make this show an uneditable date and time field.
36
- = datetime
1
+ - iso8601 = attribute.value.nil? ? nil : attribute.value.utc.iso8601
2
+
3
+ .form-group{class: attribute.errors? ? "has-error" : ""}
4
+ %label{for: attribute.form_id}
5
+ = attribute.label_name
6
+
7
+ - if attribute.editable? && f = form_builder
8
+ .row.datetime-attribute{class: attribute.form_id}
9
+ = f.hidden_field(attribute.name, value: iso8601)
10
+
11
+ .col-xs-12.col-md-4
12
+ .input-group.pikadate
13
+ %input.form-control{type: :text, value: iso8601, id: "#{attribute.form_id}-date"}
14
+ %span.input-group-addon
15
+ %span.glyphicon.glyphicon-calendar
16
+
17
+ .col-xs-12.col-md-4
18
+ .input-group.clockpicker{"data-align" => "top", "data-autoclose" => "true", "data-placement" => "right"}
19
+ %input.form-control{type: "text", value: iso8601, id: "#{attribute.form_id}-time"}
20
+ %span.input-group-addon
21
+ %span.glyphicon.glyphicon-time
22
+
23
+ .col-xs-12.col-md-4
24
+ %small
25
+ Date & Time are shown in UTC. If no time is provided, the current time in UTC will be used.
26
+
27
+
28
+ - content_for(:javascript) do
29
+ :javascript
30
+ $(document).ready(function() {
31
+ window.Upmin.Attributes.DateTime("#{attribute.form_id}");
32
+ });
33
+
34
+
35
+ - else
36
+ %p.well
37
+ -# TODO(jon): Make this show an uneditable date and time field.
38
+ = iso8601
@@ -0,0 +1,10 @@
1
+ .form-group{class: attribute.errors? ? "has-error" : ""}
2
+ %label{for: attribute.form_id}
3
+ = attribute.label_name
4
+
5
+ - if attribute.editable? && f = form_builder
6
+ = f.text_field(attribute.name, value: attribute.value, class: "form-control")
7
+
8
+ - else
9
+ %p.well
10
+ = attribute.value
@@ -1,7 +1,11 @@
1
- - float ||= nil
2
- - if editable && f = form_builder
3
- = f.text_field(attr_name, value: float, class: "form-control")
4
1
 
5
- - else
6
- %p.well
7
- = float
2
+ .form-group{class: attribute.errors? ? "has-error" : ""}
3
+ %label{for: attribute.form_id}
4
+ = attribute.label_name
5
+
6
+ - if attribute.editable? && f = form_builder
7
+ = f.text_field(attribute.name, value: attribute.value, class: "form-control")
8
+
9
+ - else
10
+ %p.well
11
+ = attribute.value
@@ -1,7 +1,11 @@
1
- - integer ||= nil
2
- - if editable && f = form_builder
3
- = f.number_field(attr_name, value: integer, class: "form-control")
4
1
 
5
- - else
6
- %p.well
7
- = integer
2
+ .form-group{class: attribute.errors? ? "has-error" : ""}
3
+ %label{for: attribute.form_id}
4
+ = attribute.label_name
5
+
6
+ - if attribute.editable? && f = form_builder
7
+ = f.number_field(attribute.name, value: attribute.value, class: "form-control")
8
+
9
+ - else
10
+ %p.well
11
+ = attribute.value
@@ -1,3 +1,4 @@
1
+ -# TODO(jon): Turn this into a widget
1
2
  - state ||= nil
2
3
  - states ||= []
3
4
  %ol.progbar{data: { "progbar-steps" => states.length }}
@@ -1,7 +1,18 @@
1
- - string ||= nil
2
- - if editable && f = form_builder
3
- = f.text_field(attr_name, value: string, class: "form-control")
1
+ - is_nil = model.new_record? ? false : attribute.value.nil?
4
2
 
5
- - else
6
- %p.well
7
- = string
3
+ .form-group{class: attribute.errors? ? "has-error" : ""}
4
+ %label{for: attribute.form_id}
5
+ = attribute.label_name
6
+
7
+ - if attribute.editable? && f = form_builder
8
+ .input-group
9
+ = f.text_field(attribute.name, value: attribute.value, class: "form-control")
10
+ .input-group-addon.nilable-addon
11
+ .form-group
12
+ %label{for: "#{attribute.form_id}_is_nil"}
13
+ Make this Nil
14
+ = check_box(model.underscore_name, "#{attribute.name}_is_nil", class: "boolean", checked: is_nil, value: is_nil)
15
+
16
+ - else
17
+ %p.well
18
+ = attribute.value
@@ -1,7 +1,9 @@
1
- - text ||= nil
2
- - if editable && f = form_builder
3
- = f.text_area(attr_name, value: text, rows: 4, class: "form-control")
1
+ .form-group{class: attribute.errors? ? "has-error" : ""}
2
+ %label{for: attribute.form_id}
3
+ = attribute.label_name
4
+ - if attribute.editable? && f = form_builder
5
+ = f.text_area(attribute.name, value: attribute.value, rows: 4, class: "form-control")
4
6
 
5
- - else
6
- %p.well
7
- = text
7
+ - else
8
+ %p.well
9
+ = attribute.value
@@ -1,3 +1,5 @@
1
- - unknown ||= nil
2
- %p.well
3
- = unknown
1
+ .form-group{class: attribute.errors? ? "has-error" : ""}
2
+ %label{for: attribute.form_id}
3
+ = attribute.label_name
4
+ %p.well
5
+ = attribute.value
@@ -1,72 +1,44 @@
1
- -# The following are all available to you here:
2
- -# unknown - This is the model passed into the up_model method.
3
- -# This attribute is always present in any partial rendered
4
- -# by Upmin, and will always match the name of the partial
5
- -# *UNLESS* nil, true, or false are passed in.
6
- -# upmin_model - This is an Upmin::Model instantiated with unknown
7
- -# and is always present.
8
- -#
9
- -# In general, the upmin_model makes it significantly easier to
10
- -# render a view, so I suggest using it. It is way simpler than
11
- -# trying to find all associations for a model on your own.
12
- -#
13
- -# Just an FYI: upmin_model.instance == unknown
14
-
15
- .upmin-model{class: upmin_model.color}
16
- -# Display the model title as "Model # ID"
1
+ .upmin-model{class: model.color}
17
2
  %h3
18
- = upmin_model.title
3
+ = model.title
19
4
 
20
5
  %br
21
6
  %br
22
7
  %h3{style: "color: #333;"}
23
8
  Attributes
24
9
  %hr
25
- -# Create a form to wrap the attributes in.
26
- -# TODO(jon): Update the URL with a decent helper?
27
- = form_for(upmin_model.instance, url: upmin_model_path(upmin_model.path_hash), html: { method: :put }) do |f|
28
-
29
- -# Render each attribute
30
- - upmin_model.klass.attributes.each do |attribute|
31
- - any_errors = model.errors[attribute].any?
32
- .form-group{class: any_errors ? "has-error" : ""}
33
- -# = f.label(attribute.to_s) # Not using this because it drops _id and this isn't always desirable
34
-
35
- %label{for: upmin_model.attribute_form_id(attribute)}
36
- = upmin_model.attribute_label_name(attribute)
37
- - if upmin_model.attribute_type(attribute) == :string
38
- = up_attribute(upmin_model.instance, attribute, locals: { form_builder: f }, as: :nilable)
39
- - else
40
- = up_attribute(upmin_model.instance, attribute, locals: { form_builder: f })
41
10
 
11
+ .attributes
12
+ -# Yes this is meant to be model.model - this is the raw rails model instance.
13
+ = form_for(model, url: model.path, html: { method: :put }) do |f|
42
14
 
43
- = f.submit("Save", class: "btn btn-primary")
15
+ -# Render each attribute
16
+ - model.attributes.each do |attribute|
17
+ = up_render(attribute, locals: { form_builder: f })
44
18
 
19
+ = f.submit("Save", class: "btn btn-primary")
45
20
 
46
21
 
47
- - if upmin_model.klass.associations.any?
22
+ - if model.associations.any?
48
23
  %br
49
24
  %br
50
25
  %br
51
26
  %h3{style: "color: #333;"}
52
27
  Associations
53
28
  %hr
54
- - upmin_model.klass.associations.each do |association|
55
- %h5
56
- = association.to_s.humanize
57
- = up_association(upmin_model.instance, association, limit: 5)
29
+ .associations
30
+ - model.associations.each do |association|
31
+ = up_render(association)
58
32
 
59
- - if upmin_model.klass.actions.any?
33
+
34
+ - if model.actions.any?
60
35
  %br
61
36
  %br
62
37
  %br
63
38
  %h3{style: "color: #333;"}
64
39
  Actions
65
40
  %hr
66
- - upmin_model.klass.actions.each do |action|
67
- %h4{style: "color: #333;"}
68
- = action.to_s.capitalize.humanize
69
- = up_action(upmin_model.instance, action)
70
-
71
-
41
+ .actions
42
+ - model.actions.each do |action|
43
+ = up_render(action)
72
44
 
@@ -1,44 +1,22 @@
1
- -# The following are all available to you here:
2
- -# unknown - This is the model passed into the up_model method.
3
- -# This attribute is always present in any partial rendered
4
- -# by Upmin, and will always match the name of the partial
5
- -# *UNLESS* nil, true, or false are passed in.
6
- -# upmin_model - This is an Upmin::Model instantiated with unknown
7
- -# and is always present.
8
- -#
9
- -# In general, the upmin_model makes it significantly easier to
10
- -# render a view, so I suggest using it. It is way simpler than
11
- -# trying to find all associations for a model on your own.
12
- -#
13
- -# Just an FYI: upmin_model.instance == unknown
14
1
 
15
- .upmin-model{class: upmin_model.color}
16
- -# Display the model title as "Model # ID"
2
+ .upmin-model{class: model.color}
17
3
  %h3
18
4
  Create a
19
- = upmin_model.klass.humanized_name(:singular)
5
+ = model.humanized_name(:singular)
20
6
 
21
7
  %br
22
8
  %br
23
9
  %h3{style: "color: #333;"}
24
10
  Attributes
25
11
  %hr
26
- -# Create a form to wrap the attributes in.
27
- -# TODO(jon): Update the URL with a decent helper?
28
- = form_for(upmin_model.instance, url: upmin_create_model_path(klass: @klass.name), html: { method: :post }) do |f|
29
12
 
30
- -# Render each attribute
31
- - upmin_model.klass.attributes.each do |attribute|
32
- - any_errors = new_model.errors[attribute].any?
33
- .form-group{class: any_errors ? "has-error" : ""}
34
- -# = f.label(attribute.to_s) # Not using this because it drops _id and this isn't always desirable
13
+ .attributes
14
+ -# Yes this is meant to be model.model - this is the raw rails model instance.
15
+ = form_for(model, url: model.create_path, html: { method: :post }) do |f|
35
16
 
36
- %label{for: upmin_model.attribute_form_id(attribute)}
37
- = upmin_model.attribute_label_name(attribute)
38
- - if upmin_model.attribute_type(attribute) == :string
39
- = up_attribute(upmin_model.instance, attribute, locals: { form_builder: f }, as: :nilable)
40
- - else
41
- = up_attribute(upmin_model.instance, attribute, locals: { form_builder: f })
17
+ -# Render each attribute
18
+ - model.attributes.each do |attribute|
19
+ = up_render(attribute, locals: { form_builder: f })
42
20
 
43
- = f.submit("Create", class: "btn btn-primary")
21
+ = f.submit("Create", class: "btn btn-primary")
44
22
 
@@ -0,0 +1,14 @@
1
+ .form-group
2
+ %label{for: parameter.form_id}
3
+ = parameter.label_name
4
+
5
+ .input-group
6
+ = text_field(action.name, parameter.name, class: "form-control")
7
+ .input-group-addon.nilable-addon
8
+ .form-group
9
+ %label{for: parameter.nil_form_id}
10
+ Do Not Provide
11
+ = check_box(parameter.action.name, "#{parameter.name}_is_nil", class: "boolean")
12
+
13
+ %small
14
+ * Optional
@@ -0,0 +1,4 @@
1
+ .form-group
2
+ %label{for: parameter.form_id}
3
+ = parameter.label_name
4
+ = text_field(action.name, parameter.name, class: "form-control")
@@ -3,11 +3,10 @@
3
3
  = klass.humanized_name
4
4
 
5
5
  -# Upmin default search uses the ransack gem, see: https://github.com/activerecord-hackery/ransack
6
- = form_tag(upmin_search_path(klass: klass.name), method: :get) do
6
+ = form_tag(klass.search_path, method: :get) do
7
7
  - klass.attributes.each do |attr_name|
8
8
  - type = klass.attribute_type(attr_name)
9
9
 
10
- -# TODO(jon): Make sure these retain their data on a search
11
10
  -# TODO(jon): Break these into partials possibly?
12
11
  - if type == :string
13
12
  .form-group
@@ -34,4 +33,4 @@
34
33
  = date_field(:q, "#{attr_name}_lteq", class: "form-control")
35
34
 
36
35
  = submit_tag("Search", class: "btn btn-primary btn-block")
37
- = link_to("Clear All", upmin_search_path(klass: klass.name), class: "btn btn-default btn-block")
36
+ = link_to("Clear All", klass.search_path, class: "btn btn-default btn-block")