populate-me 0.5.2 → 0.6.0

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: be331bffcdd0d674766bfe0d30608203595c6de1
4
- data.tar.gz: 6c2ff9be2717ca69dd6567bc9953f02a1d9cb0d2
3
+ metadata.gz: c5c79dfa650ecfc5df94c3ab28ddbed5f9d491a7
4
+ data.tar.gz: acfd309da2a2ac7f738f4fee4fe60085dc79961c
5
5
  SHA512:
6
- metadata.gz: f95230cfbc50e885b8b47c9104b4887c72b9d60bce892e186d404e569aa5994a4b81d0958f39646707c18c25c78a261fe5b3e6601d21bdc81bc7c2b34ac3eed4
7
- data.tar.gz: 4e3f90dbd5c3b8174ac8b11b85b2edcf58050d0c6e1ff8cff3aff813227e29c31a0c88b3d80a97e4cd02839ca52e2a6927662c3d6a6a641ba5c0d06f422d1074
6
+ metadata.gz: 4343d3b53dfa62f0624adcb7e268813192224fc33fc323a2192d2d36efa8ad7092f81baa32743d561469b1db7ee1e2412da210a45cc12937ed8f40f15a197535
7
+ data.tar.gz: 3e14be4dc566b04247fdf25a0ee6866a99adf29688d6e830090d0863ecd4bd7a226ef93e200a52fc47fd793a7ddd4ee4994886e70017534ba3f7c4e60894f5e9
@@ -40,6 +40,7 @@ class BlogPost < PopulateMe::Document
40
40
  def validate
41
41
  error_on(:content,'Cannot be blank') if WebUtils.blank?(self.content)
42
42
  end
43
+
43
44
  end
44
45
  class BlogPost::Author < PopulateMe::Document
45
46
  # nested
@@ -7,6 +7,9 @@
7
7
  <link rel="stylesheet" href="<%= request.script_name %>/__assets__/css/jquery-ui.min.css" type="text/css" media='screen' />
8
8
  <link rel="stylesheet" href="<%= request.script_name %>/__assets__/css/asmselect.css" type="text/css" media='screen' />
9
9
  <link rel="stylesheet" href="<%= request.script_name %>/__assets__/css/main.css" type="text/css" media='screen' />
10
+ <% if settings.respond_to? :custom_css_url %>
11
+ <link rel="stylesheet" href="<%= settings.custom_css_url %>" type="text/css" media='screen' />
12
+ <% end %>
10
13
  </head>
11
14
  <body>
12
15
 
@@ -54,7 +57,7 @@
54
57
  </a>
55
58
  <ol class='local-menu'>
56
59
  {{#local_menu}}
57
- <li>&rarr; <a href="{{href}}" class='column-push' title='Open'>{{title}}</a></li>
60
+ <li>&rarr; <a href="{{href}}" {{#new_page}}target='_blank'{{/new_page}}{{^new_page}}class='column-push'{{/new_page}} title='Open'>{{title}}</a></li>
58
61
  {{/local_menu}}
59
62
  </ol>
60
63
  </li>
@@ -150,6 +153,10 @@
150
153
  </fieldset>
151
154
  </script>
152
155
 
156
+ <% if settings.respond_to? :custom_templates_view %>
157
+ <%= erb settings.custom_templates_view, layout: false %>
158
+ <% end %>
159
+
153
160
  <!-- JS -->
154
161
  <script src="//code.jquery.com/jquery-1.10.2.min.js" type="text/javascript" charset="utf-8"></script>
155
162
  <script src="<%= request.script_name %>/__assets__/js/jquery-ui.min.js" type="text/javascript" charset="utf-8"></script>
@@ -162,6 +169,9 @@
162
169
  window.index_path = "<%= settings.index_path %>";
163
170
  </script>
164
171
  <script src="<%= request.script_name %>/__assets__/js/main.js" type="text/javascript" charset="utf-8"></script>
172
+ <% if settings.respond_to? :custom_js_url %>
173
+ <script src="<%= settings.custom_js_url %>" type="text/javascript" charset="utf-8"></script>
174
+ <% end %>
165
175
  </body>
166
176
  </html>
167
177
 
@@ -23,7 +23,8 @@ module PopulateMe
23
23
  unless v[:hidden]
24
24
  out << {
25
25
  title: "#{v[:label]}",
26
- href: "#{o[:request].script_name}/list/#{WebUtils.dasherize_class_name(v[:class_name])}?filter[#{v[:foreign_key]}]=#{self.id}"
26
+ href: "#{o[:request].script_name}/list/#{WebUtils.dasherize_class_name(v[:class_name])}?filter[#{v[:foreign_key]}]=#{self.id}",
27
+ new_page: false
27
28
  }
28
29
  out
29
30
  end
@@ -70,6 +70,9 @@ module PopulateMe
70
70
  end
71
71
 
72
72
  def set_indexes f, ids=[]
73
+ if self.fields[f.to_sym][:direction]==:desc
74
+ ids = ids.dup.reverse
75
+ end
73
76
  ids.each_with_index do |id,i|
74
77
  self.documents.each do |d|
75
78
  d[f.to_s] = i if d[self.id_string_key]==id
@@ -59,7 +59,7 @@ module PopulateMe
59
59
  name = o[:name]||:position
60
60
  o[:type] = :position
61
61
  field name, o
62
- sort_by name
62
+ sort_by name, direction: (o[:direction]||:asc)
63
63
  end
64
64
 
65
65
  def label sym # sets the label_field
@@ -46,6 +46,9 @@ module PopulateMe
46
46
  end
47
47
 
48
48
  def set_indexes f, ids=[]
49
+ if self.fields[f.to_sym][:direction]==:desc
50
+ ids = ids.dup.reverse
51
+ end
49
52
  requests = ids.each_with_index.inject([]) do |list, (id, i)|
50
53
  list << {update_one:
51
54
  {
@@ -1,4 +1,4 @@
1
1
  module PopulateMe
2
- VERSION = '0.5.2'
2
+ VERSION = '0.6.0'
3
3
  end
4
4
 
@@ -3,6 +3,8 @@ require 'populate_me/document'
3
3
 
4
4
  class Stuborn < PopulateMe::Document
5
5
  attr_accessor :age
6
+ field :position
7
+ field :reversed, direction: :desc
6
8
  end
7
9
 
8
10
  describe PopulateMe::Document, 'Persistence' do
@@ -52,5 +54,30 @@ describe PopulateMe::Document, 'Persistence' do
52
54
  end
53
55
  end
54
56
 
57
+ describe '::set_indexes' do
58
+
59
+ before do
60
+ Stuborn.documents = []
61
+ Stuborn.new('id' => 'a').save
62
+ Stuborn.new('id' => 'b').save
63
+ Stuborn.new('id' => 'c').save
64
+ end
65
+
66
+ it 'Sets the indexes on the provided field' do
67
+ Stuborn.set_indexes(:position,['b','a','c'])
68
+ assert_equal 1, Stuborn.admin_get('a').position
69
+ assert_equal 0, Stuborn.admin_get('b').position
70
+ assert_equal 2, Stuborn.admin_get('c').position
71
+ end
72
+
73
+ it 'Sets the indexes taking direction into account' do
74
+ Stuborn.set_indexes(:reversed,['b','a','c'])
75
+ assert_equal 1, Stuborn.admin_get('a').reversed
76
+ assert_equal 2, Stuborn.admin_get('b').reversed
77
+ assert_equal 0, Stuborn.admin_get('c').reversed
78
+ end
79
+
80
+ end
81
+
55
82
  end
56
83
 
@@ -222,6 +222,7 @@ describe 'PopulateMe::Mongo' do
222
222
 
223
223
  class MongoChampion < PopulateMe::Mongo
224
224
  field :position
225
+ field :reversed, direction: :desc
225
226
  end
226
227
 
227
228
  before do
@@ -238,6 +239,12 @@ describe 'PopulateMe::Mongo' do
238
239
  assert_equal 2, MongoChampion.admin_get('c').position
239
240
  end
240
241
 
242
+ it 'Sets the indexes taking direction into account' do
243
+ MongoChampion.set_indexes(:reversed,['b','a','c'])
244
+ assert_equal 1, MongoChampion.admin_get('a').reversed
245
+ assert_equal 2, MongoChampion.admin_get('b').reversed
246
+ assert_equal 0, MongoChampion.admin_get('c').reversed
247
+ end
241
248
  end
242
249
 
243
250
  describe '::admin_distinct' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: populate-me
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mickael Riga
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-04 00:00:00.000000000 Z
11
+ date: 2018-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: web-utils