upmin-admin 0.1.0 → 0.1.01

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d17a5316e3ae23cb3bfe9e66d531798356f02ad4
4
- data.tar.gz: ad0e64565f7304bec6f762db4ea7549dd42cf87b
3
+ metadata.gz: 910d8396eb70b53feb5a498af6acc41edb1e3d1e
4
+ data.tar.gz: 6e2d7366490c0dfb137a503a02fd6784111714c4
5
5
  SHA512:
6
- metadata.gz: 0605a9cd8ef301ec6ce36a51f0ce5d2349f084bab91b878b14f58fca4cf52975db25db4f38235a8aeed95e7b10ad8dd407c557b936a38bce2d5b34bdf1180b24
7
- data.tar.gz: 6a9d6a9607628fad7263dd7513e5fd193725c4048b8e5d90dc53fb0fa728631eee4ced49c9ef2404b4439d6bfcadbb7ae42ffd43607a6fb073a09ba305d3bd42
6
+ metadata.gz: 4aea3404252228d686ed20f0a480e7d32898c70ef6edc895b387272bc14cfdb82bf6e06f8044fa15360fcf3ddc3dea147b6429c3cd6997460dff5d785e153e01
7
+ data.tar.gz: bdb283f1c155465a8f94be4b5d290d21ff0c2883c9536323850b809a5e3a0223df65c2d3212f44bb073c89bd587c3b192e1d49f9ded56fe327a6dbdafc815df8
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # Upmin Admin
2
2
 
3
- Upmin Admin is a framework for creating powerful admin backends with minimal effort.
3
+ [![Gem Version](https://badge.fury.io/rb/upmin-admin.svg)](http://badge.fury.io/rb/upmin-admin)
4
+
5
+ Upmin Admin is a framework for creating powerful Ruby on Rails admin backends with minimal effort.
6
+ Upmin currently supports Rails 3.2, 4.0, 4.1 & 4.2.
4
7
 
5
8
 
6
9
  ## Demo Videos
@@ -59,7 +62,7 @@ For further documentation, please visit our [Wiki](https://github.com/upmin/upmi
59
62
 
60
63
  ## Going Forward
61
64
 
62
- Upmin Admin is new. It has been live for less than a few months, so there are going to be things missing. If you want to make it better, get involved and [create issues](https://github.com/upmin/upmin-admin-ruby/issues) when you find bugs or want new features, and contribute with pull requests.
65
+ Upmin Admin is new. It has been live for less than a few months, so there are going to be things missing. If you want to make it better, get involved and [create issues](https://github.com/upmin/upmin-admin-ruby/issues) when you find bugs or want new features, and [contribute](https://github.com/upmin/upmin-admin-ruby/blob/master/CONTRIBUTING.md) with pull requests.
63
66
 
64
67
  The major features that are being worked on now are:
65
68
 
data/Rakefile CHANGED
@@ -13,12 +13,17 @@ end
13
13
 
14
14
  task :default => "spec:all"
15
15
 
16
- def update_files
17
- # Drop and reload spec files
16
+ def update_files(gemfile = nil)
17
+ # Drop and reload spec files
18
18
  sh "rm -rf spec/"
19
19
  sh "cp -R ../../spec spec"
20
20
  sh "cp ../../.rspec .rspec"
21
21
 
22
+ # Copy gemfile specific specs if they exist
23
+ if Dir.exists?("../../spec_#{gemfile}")
24
+ sh "cp -R ../../spec_#{gemfile} spec/#{gemfile}"
25
+ end
26
+
22
27
  # Drop and reload Upmin::Model files
23
28
  sh "rm -rf app/upmin/"
24
29
  sh "cp -R ../../test_app_upmin app/upmin"
@@ -69,16 +74,47 @@ namespace :spec do
69
74
  end
70
75
  end
71
76
 
77
+ desc "Run Tests with namespaced models"
78
+ task :namespaced_model do
79
+ Dir.chdir("test_apps/namespaced_model")
80
+ puts "Testing in #{`pwd`}"
81
+ sh "bundle install --quiet"
82
+ sh "bundle update --quiet"
83
+
84
+ # Drop migrations and recreate
85
+ sh "rm -rf db/migrate/*.test_models.rb"
86
+ sh "bundle exec rake railties:install:migrations > /dev/null"
87
+
88
+ sh "RAILS_ENV=test bundle exec rake db:drop db:create db:migrate db:seed --quiet > /dev/null"
89
+
90
+ update_files("namespaced_model")
91
+
92
+ # Run tests
93
+ sh "bundle exec rake"
94
+ end
95
+
96
+
97
+ desc "Run Tests with namespaced models quickly (no bundle install etc)"
98
+ task :namespaced_model_quick do
99
+ Dir.chdir("test_apps/namespaced_model")
100
+ puts "Re-Testing in #{`pwd`}. Bundle install and migration updates will NOT happen!"
101
+
102
+ update_files("namespaced_model")
103
+
104
+ # Run tests
105
+ sh "bundle exec rake"
106
+ end
107
+
72
108
  desc "Run Tests against all ORMs"
73
109
  task :all do
74
- %w(active_record_32 active_record_40 active_record_41 active_record_42 will_paginate data_mapper).each do |gemfile|
110
+ %w(active_record_32 active_record_40 active_record_41 active_record_42 will_paginate data_mapper namespaced_model).each do |gemfile|
75
111
  sh "rake spec:#{gemfile}"
76
112
  end
77
113
  end
78
114
 
79
115
  desc "Run Tests against all ORMs"
80
116
  task :all_quick do
81
- %w(active_record_32 active_record_40 active_record_41 active_record_42 will_paginate data_mapper).each do |gemfile|
117
+ %w(active_record_32 active_record_40 active_record_41 active_record_42 will_paginate data_mapper namespaced_model).each do |gemfile|
82
118
  sh "rake spec:#{gemfile}_quick"
83
119
  end
84
120
  end
@@ -117,7 +117,7 @@ module Upmin
117
117
  end
118
118
 
119
119
  def set_query
120
- @query = Upmin::Query.new(@klass, params[:q], page: @page, per_page: 30)
120
+ @query = Upmin::Query.new(@klass, params[:q], page: @page, per_page: @klass.items_per_page)
121
121
  end
122
122
 
123
123
  def set_model
@@ -0,0 +1,3 @@
1
+ - unless current_page.first?
2
+ %li.first
3
+ = link_to_unless current_page.first?, raw(t 'views.pagination.first'), url, :remote => remote
@@ -0,0 +1,2 @@
1
+ %li.page.gap.disabled
2
+ %a{:href => "#", :onclick => "return false;"}= raw(t 'views.pagination.truncate')
@@ -0,0 +1,3 @@
1
+ - unless current_page.last?
2
+ %li.last.next
3
+ = link_to_unless current_page.last?, raw(t 'views.pagination.last'), url, {:remote => remote}
@@ -0,0 +1,3 @@
1
+ - unless current_page.last?
2
+ %li.next_page
3
+ = link_to_unless current_page.last?, raw(t 'views.pagination.next'), url, :rel => 'next', :remote => remote
@@ -0,0 +1,2 @@
1
+ %li{:class => "page#{' active' if page.current?}"}
2
+ = link_to page, url, opts = {:remote => remote, :rel => page.next? ? 'next' : page.prev? ? 'prev' : nil}
@@ -0,0 +1,11 @@
1
+ = paginator.render do
2
+ %ul.pagination
3
+ = first_page_tag unless current_page.first?
4
+ = prev_page_tag unless current_page.first?
5
+ - each_page do |page|
6
+ - if page.left_outer? || page.right_outer? || page.inside_window?
7
+ = page_tag page
8
+ - elsif !page.was_truncated?
9
+ = gap_tag
10
+ = next_page_tag unless current_page.last?
11
+ = last_page_tag unless current_page.last?
@@ -0,0 +1,3 @@
1
+ - unless current_page.first?
2
+ %li.prev
3
+ = link_to_unless current_page.first?, raw(t 'views.pagination.previous'), url, :rel => 'prev', :remote => remote
@@ -45,6 +45,19 @@ module Upmin
45
45
  end
46
46
  end
47
47
 
48
+ def items_per_page=(items)
49
+ @custom_items_per_page = true
50
+ @items_per_page = items
51
+ end
52
+
53
+ def items_per_page
54
+ if defined?(@custom_items_per_page)
55
+ return @items_per_page
56
+ else
57
+ return 30
58
+ end
59
+ end
60
+
48
61
  private
49
62
 
50
63
  def default_models
@@ -1,4 +1,6 @@
1
1
  # require 'haml-rails'
2
+ # require kaminari here to affect load order so that custom kaminari views load from upmin
3
+ require 'kaminari'
2
4
 
3
5
  module Upmin
4
6
  class Engine < ::Rails::Engine
@@ -96,8 +96,6 @@ module Upmin
96
96
  end
97
97
 
98
98
 
99
-
100
-
101
99
  ###########################################################
102
100
  ### Class methods
103
101
  ###########################################################
@@ -112,10 +110,23 @@ module Upmin
112
110
 
113
111
  def Model.find_or_create_class(model_name)
114
112
  ::Rails.application.eager_load!
115
- return "Admin#{model_name}".constantize
113
+
114
+ create_name = model_name.gsub(":", "")
115
+ return "Admin#{create_name}".constantize
116
116
  rescue NameError
117
- eval("class ::Admin#{model_name} < Upmin::Model; end")
118
- return "Admin#{model_name}".constantize
117
+ if model_name.match(/::/)
118
+ class_str = <<-class_string
119
+ class ::Admin#{create_name} < Upmin::Model
120
+ def self.model_class
121
+ return #{model_name}
122
+ end
123
+ end
124
+ class_string
125
+ eval(class_str)
126
+ else
127
+ eval("class ::Admin#{create_name} < Upmin::Model; end")
128
+ end
129
+ return "Admin#{create_name}".constantize
119
130
  end
120
131
 
121
132
  # Returns all upmin models.
@@ -127,10 +138,6 @@ module Upmin
127
138
  return all
128
139
  end
129
140
 
130
- def Model.model_class
131
- @model_class ||= inferred_model_class
132
- end
133
-
134
141
  def Model.model_class?
135
142
  return model_class
136
143
  rescue Upmin::UninferrableSourceError
@@ -142,24 +149,28 @@ module Upmin
142
149
  end
143
150
 
144
151
  def Model.inferred_model_class
145
- name = model_class_name
152
+ name = inferred_model_class_name
146
153
  return name.constantize
147
154
  rescue NameError => error
148
155
  raise if name && !error.missing_name?(name)
149
156
  raise Upmin::UninferrableSourceError.new(self)
150
157
  end
151
158
 
152
- def Model.model_class_name
159
+ def Model.inferred_model_class_name
153
160
  raise NameError if name.nil? || name.demodulize !~ /Admin.+$/
154
161
  return name.demodulize[5..-1]
155
162
  end
156
163
 
164
+ def Model.model_class_name
165
+ return model_class.name
166
+ end
167
+
157
168
  def Model.model_name
158
169
  return ActiveModel::Name.new(model_class)
159
170
  end
160
171
 
161
172
  def Model.humanized_name(type = :plural)
162
- names = model_class_name.split(/(?=[A-Z])/)
173
+ names = model_class_name.split(/(?=[A-Z])/).map{|n| n.gsub(":", "")}
163
174
  if type == :plural
164
175
  names[names.length-1] = names.last.pluralize
165
176
  end
@@ -202,10 +213,9 @@ module Upmin
202
213
  return @color_index
203
214
  end
204
215
 
205
-
206
216
  def Model.active_record?
207
217
  if defined?(ActiveRecord)
208
- return model_class.superclass == ::ActiveRecord::Base
218
+ return (model_class < ::ActiveRecord::Base) == true
209
219
  else
210
220
  return false
211
221
  end
@@ -220,7 +230,6 @@ module Upmin
220
230
  end
221
231
 
222
232
 
223
-
224
233
  ###########################################################
225
234
  ### Customization methods for Admin<Model> classes
226
235
  ###########################################################
@@ -273,6 +282,9 @@ module Upmin
273
282
  return @actions
274
283
  end
275
284
 
285
+ def Model.items_per_page(items = Upmin.configuration.items_per_page)
286
+ return @items_per_page ||= items
287
+ end
276
288
 
277
289
 
278
290
  ###########################################################
@@ -4,6 +4,7 @@ module Upmin::Railties
4
4
 
5
5
  def up_paginate(scope, options = {}, &block)
6
6
  if defined?(WillPaginate)
7
+ options[:renderer] = BootstrapPagination::Rails if defined?(BootstrapPagination::Rails)
7
8
  return will_paginate(scope, options)
8
9
  else # Use Kaminari
9
10
  return paginate(scope, options, &block)
@@ -180,9 +180,12 @@ module Upmin::Railties
180
180
  def RenderHelpers.search_box_partials(klass, options = {})
181
181
  partials = []
182
182
  # <options[:as]>
183
+ # <model_name>_search_box, eg: order_search_box
183
184
  # ransack_search_box
185
+ model_name = klass.underscore_name
184
186
 
185
187
  partials << build_search_box_path(options[:as]) if options[:as]
188
+ partials << build_search_box_path("#{model_name}_search_box")
186
189
  partials << build_search_box_path(:ransack_search_box)
187
190
  return partials
188
191
  end
@@ -1,3 +1,3 @@
1
1
  module Upmin
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.01"
3
3
  end
@@ -15,7 +15,7 @@ feature("Search Views") do
15
15
 
16
16
  # Make sure some basic pagination exits
17
17
  within(".pagination:first-of-type") do
18
- within(".current") do
18
+ within(".active, .current") do
19
19
  expect(page).to(have_content("1"))
20
20
  end
21
21
 
@@ -24,7 +24,7 @@ feature("Search Views") do
24
24
  end
25
25
 
26
26
  within(".pagination:nth-of-type(2)") do
27
- within(".current") do
27
+ within(".active, .current") do
28
28
  expect(page).to(have_content("2"))
29
29
  end
30
30
 
@@ -35,14 +35,14 @@ feature("Search Views") do
35
35
  end
36
36
 
37
37
  within(".pagination:last-of-type") do
38
- within(".current") do
38
+ within(".active, .current") do
39
39
  expect(page).to(have_content("3"))
40
40
  end
41
41
  end
42
42
  end
43
43
 
44
44
  scenario("Search via integer") do
45
- visit("/upmin/m/Order")
45
+ visit("/upmin/m/User")
46
46
 
47
47
  expect(page).to(have_selector("a.search-result-link", count: 30))
48
48
 
@@ -77,4 +77,28 @@ feature("Search Views") do
77
77
  expect(page).to(have_content(expected_user.name))
78
78
  end
79
79
 
80
+ scenario("config.items_per_page") do
81
+ Upmin.configuration.items_per_page = 25
82
+
83
+ visit("/upmin/m/Order")
84
+
85
+ # Global config of 25 should override default of 30
86
+ expect(page).to(have_selector("a.search-result-link", count: 25))
87
+
88
+ # Reset this.
89
+ Upmin.configuration = Upmin::Configuration.new
90
+ end
91
+
92
+ scenario("Model items_per_page with config.items_per_page") do
93
+ Upmin.configuration.items_per_page = 25
94
+
95
+ visit("/upmin/m/Shipment")
96
+
97
+ # `items_per_page 20` in the model should override global config of 25
98
+ expect(page).to(have_selector("a.search-result-link", count: 20))
99
+
100
+ # Reset this.
101
+ Upmin.configuration = Upmin::Configuration.new
102
+ end
103
+
80
104
  end
@@ -57,4 +57,17 @@ describe Upmin::Configuration do
57
57
 
58
58
  end
59
59
 
60
+ describe "#items_per_page" do
61
+
62
+ context "default items_per_page" do
63
+ it { expect(@config.items_per_page).to(eq(30)) }
64
+ end
65
+
66
+ context "custom items_per_page" do
67
+ before(:each) { @config.items_per_page = 10 }
68
+ it { expect(@config.items_per_page).to(eq(10)) }
69
+ end
70
+
71
+ end
72
+
60
73
  end
@@ -46,11 +46,11 @@ RSpec.configure do |config|
46
46
  end
47
47
 
48
48
  # Uncomment this if you want to the page to be saved and opened after any test failure.
49
- config.after do |example|
50
- if example.metadata[:type] == :feature && example.exception.present?
51
- save_and_open_page
52
- end
53
- end
49
+ # config.after do |example|
50
+ # if example.metadata[:type] == :feature && example.exception.present?
51
+ # save_and_open_page
52
+ # end
53
+ # end
54
54
 
55
55
  config.include(FactoryGirl::Syntax::Methods)
56
56
  config.include(ActionView::Helpers::NumberHelper, type: :view)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: upmin-admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.01
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Calhoun
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-09-28 00:00:00.000000000 Z
12
+ date: 2014-10-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -174,8 +174,6 @@ extra_rdoc_files: []
174
174
  files:
175
175
  - README.md
176
176
  - Rakefile
177
- - app/assets/images/upmin/logo_large.png
178
- - app/assets/images/upmin/logo_small.png
179
177
  - app/assets/javascripts/upmin/application.js
180
178
  - app/assets/javascripts/upmin/attributes/datetime.js
181
179
  - app/assets/javascripts/upmin/helpers.js
@@ -196,6 +194,13 @@ files:
196
194
  - app/controllers/upmin/models_controller.rb
197
195
  - app/helpers/upmin/application_helper.rb
198
196
  - app/helpers/upmin/models_helper.rb
197
+ - app/views/kaminari/_first_page.html.haml
198
+ - app/views/kaminari/_gap.html.haml
199
+ - app/views/kaminari/_last_page.html.haml
200
+ - app/views/kaminari/_next_page.html.haml
201
+ - app/views/kaminari/_page.html.haml
202
+ - app/views/kaminari/_paginator.html.haml
203
+ - app/views/kaminari/_prev_page.html.haml
199
204
  - app/views/layouts/upmin/_navbar.html.haml
200
205
  - app/views/layouts/upmin/application.html.haml
201
206
  - app/views/upmin/models/dashboard.html.haml
@@ -221,7 +226,6 @@ files:
221
226
  - app/views/upmin/partials/search_boxes/_ransack_search_box.html.haml
222
227
  - app/views/upmin/partials/search_results/_results.html.haml
223
228
  - config/routes.rb
224
- - lib/tasks/accordive_rails_tasks.rake
225
229
  - lib/tasks/upmin_tasks.rake
226
230
  - lib/upmin.rb
227
231
  - lib/upmin/action.rb
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :accordive_rails do
3
- # # Task goes here
4
- # end