populate-me 0.10.1 → 0.11.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.
- checksums.yaml +4 -4
- data/lib/populate_me/admin/__assets__/js/main.js +24 -0
- data/lib/populate_me/admin/views/page.erb +2 -1
- data/lib/populate_me/document_mixins/schema.rb +10 -3
- data/lib/populate_me/version.rb +1 -1
- data/test/test_admin.rb +15 -5
- data/test/test_document_outcasting.rb +16 -0
- data/test/test_document_schema.rb +23 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: faa748585887ab4c87b9a96b0fcbc1cb819933840e5ed916a3455ea677c10ada
|
4
|
+
data.tar.gz: '0548e4f13d04c8f9a5375029fc11e6cfdd00b7759b2a6b5ba171151640ee5159'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3244bbeb680e2d0ffea098719cc228623115666b498330651563672455c2495cfd3955270943f4b0020fc54780e876dd644a9025b0ff7f325eb016586f75cc8f
|
7
|
+
data.tar.gz: 3489e40c4e16e1b75c005d09937c535de3eef8d52edf8de9b1aa54a43d71a7a8304a7e80ebaaec2486da4b344b28752b1451f82e224f2014cc00d74a0e417118
|
@@ -195,6 +195,30 @@ PopulateMe.init_column = function(c) {
|
|
195
195
|
// Init multiple select with asmSelect
|
196
196
|
$('select[multiple]', c).asmSelect({ sortable: true, removeLabel: '×' });
|
197
197
|
|
198
|
+
// Select with preview
|
199
|
+
$('select:not([multiple])', c).change(function() {
|
200
|
+
var $this = $(this);
|
201
|
+
var container;
|
202
|
+
if ($this.data('preview-container')) {
|
203
|
+
container = $($this.data('preview-container'), c);
|
204
|
+
} else {
|
205
|
+
container = $this.next('.preview-container');
|
206
|
+
}
|
207
|
+
if (container.size() == 0) return;
|
208
|
+
var path = $this.find(':selected:first').data('preview');
|
209
|
+
if (path) {
|
210
|
+
var img = container.find('img:first');
|
211
|
+
if (img.size() < 1) {
|
212
|
+
img = $("<img src='' alt='Preview' title='Preview' width='250' />");
|
213
|
+
container.html(img);
|
214
|
+
}
|
215
|
+
img.attr('src', path);
|
216
|
+
} else {
|
217
|
+
container.html('');
|
218
|
+
}
|
219
|
+
});
|
220
|
+
$('option:selected[data-preview]').parent().change();
|
221
|
+
|
198
222
|
// Polymorphic selector
|
199
223
|
$('select.polymorphic_type_values').change(function() {
|
200
224
|
var $this = $(this);
|
@@ -134,9 +134,10 @@
|
|
134
134
|
{{/multiple}}
|
135
135
|
<select name='{{input_name}}' {{#multiple}}multiple title='?'{{/multiple}}{{{build_input_attributes}}}>
|
136
136
|
{{#select_options}}
|
137
|
-
<option value='{{value}}' {{#selected}}selected{{/selected}}>{{description}}</option>
|
137
|
+
<option value='{{value}}' {{#selected}}selected{{/selected}} {{#preview_uri}}data-preview='{{preview_uri}}'{{/preview_uri}}>{{description}}</option>
|
138
138
|
{{/select_options}}
|
139
139
|
</select>
|
140
|
+
<div class='preview-container'></div>
|
140
141
|
</script>
|
141
142
|
|
142
143
|
<script id="template-attachment-field" type="x-tmpl-mustache">
|
@@ -160,13 +160,20 @@ module PopulateMe
|
|
160
160
|
|
161
161
|
def to_select_options o={}
|
162
162
|
proc do
|
163
|
-
items = self.admin_find(
|
163
|
+
items = self.admin_find({
|
164
|
+
query: (o[:query]||{}),
|
165
|
+
fields: [self.id_string_key, self.label_field, self.admin_image_field].compact.uniq
|
166
|
+
})
|
164
167
|
output = items.sort_by do |i|
|
165
168
|
i.to_s.downcase
|
166
169
|
end.map do |i|
|
167
|
-
|
170
|
+
item = { description: i.to_s, value: i.id }
|
171
|
+
unless self.admin_image_field.nil?
|
172
|
+
item.merge! preview_uri: i.admin_image_url
|
173
|
+
end
|
174
|
+
item
|
168
175
|
end
|
169
|
-
output.unshift(
|
176
|
+
output.unshift(description: '?', value: '') if o[:allow_empty]
|
170
177
|
output
|
171
178
|
end
|
172
179
|
end
|
data/lib/populate_me/version.rb
CHANGED
data/test/test_admin.rb
CHANGED
@@ -124,6 +124,10 @@ describe PopulateMe::Admin do
|
|
124
124
|
|
125
125
|
describe 'Handlers' do
|
126
126
|
|
127
|
+
let(:help_item) {
|
128
|
+
{ 'title' => '?', 'href' => '/help', 'new_page' => false }
|
129
|
+
}
|
130
|
+
|
127
131
|
describe '/menu' do
|
128
132
|
|
129
133
|
describe 'when url is root' do
|
@@ -133,18 +137,22 @@ describe PopulateMe::Admin do
|
|
133
137
|
assert_json last_response
|
134
138
|
assert_for_view json, 'template_menu', 'Menu'
|
135
139
|
expected_h = {
|
136
|
-
'title'=> 'Home Details',
|
140
|
+
'title' => 'Home Details',
|
141
|
+
'href' => '/admin/form/home-details/0',
|
142
|
+
'new_page' => false
|
137
143
|
}
|
138
144
|
assert_equal expected_h, json['items'][0]
|
139
145
|
expected_h = {
|
140
|
-
'title'=> 'Project Page',
|
146
|
+
'title' => 'Project Page',
|
147
|
+
'href' => '/menu/project-page',
|
148
|
+
'new_page' => false
|
141
149
|
}
|
142
150
|
assert_equal expected_h, json['items'][1]
|
143
151
|
end
|
144
152
|
it 'Adds help link' do
|
145
153
|
get '/menu'
|
146
154
|
assert_equal 3, json['items'].size
|
147
|
-
assert_equal(
|
155
|
+
assert_equal(help_item, json['items'].last)
|
148
156
|
end
|
149
157
|
end
|
150
158
|
describe 'when url is nested' do
|
@@ -155,13 +163,15 @@ describe PopulateMe::Admin do
|
|
155
163
|
assert_for_view json, 'template_menu', 'Checks'
|
156
164
|
assert_equal 2, json['items'].size
|
157
165
|
expected_h = {
|
158
|
-
'title'=> 'Check 1',
|
166
|
+
'title' => 'Check 1',
|
167
|
+
'href' => '/check/1',
|
168
|
+
'new_page' => false
|
159
169
|
}
|
160
170
|
assert_equal expected_h, json['items'][0]
|
161
171
|
end
|
162
172
|
it 'Does not add help link' do
|
163
173
|
get '/menu/project-page/checks'
|
164
|
-
refute_equal(
|
174
|
+
refute_equal(help_item, json['items'].last)
|
165
175
|
end
|
166
176
|
end
|
167
177
|
|
@@ -11,6 +11,11 @@ class Outcasted < PopulateMe::Document
|
|
11
11
|
{description: 'medium', value: 'm'},
|
12
12
|
{description: 'large', value: 'l'}
|
13
13
|
]
|
14
|
+
field :availability, type: :select, select_options: [
|
15
|
+
{description: 'Available', value: 'yes', preview_uri: 'http://www.example.org/yes.jpg' },
|
16
|
+
{description: 'On offer', value: 'almost', preview_uri: 'http://www.example.org/almost.jpg' },
|
17
|
+
{description: 'Sold', value: 'no', preview_uri: 'http://www.example.org/no.jpg' }
|
18
|
+
]
|
14
19
|
field :tags, type: :select, select_options: ['art','sport','science'], multiple: true
|
15
20
|
field :related_properties, type: :select, select_options: ['prop1','prop2','prop3'], multiple: true
|
16
21
|
field :pdf, type: :attachment
|
@@ -98,6 +103,17 @@ describe PopulateMe::Document, 'Outcasting' do
|
|
98
103
|
formated_options?(original, output)
|
99
104
|
end
|
100
105
|
|
106
|
+
it 'Can have more fields when they are already formated' do
|
107
|
+
# Mainly for adding a preview_uri but also future tweaks
|
108
|
+
original = Outcasted.fields[:availability]
|
109
|
+
output = Outcasted.new.outcast(:availability, original, {input_name_prefix: 'data'})
|
110
|
+
assert(output[:select_options].all?{|o| o.key?(:preview_uri)})
|
111
|
+
last = output[:select_options].last
|
112
|
+
assert_equal 'Sold', last[:description]
|
113
|
+
assert_equal 'no', last[:value]
|
114
|
+
assert_equal 'http://www.example.org/no.jpg', last[:preview_uri]
|
115
|
+
end
|
116
|
+
|
101
117
|
it 'Formats the options when it is a 2 strings array' do
|
102
118
|
original = Outcasted.fields[:size].dup
|
103
119
|
original[:select_options] = [
|
@@ -85,12 +85,22 @@ describe PopulateMe::Document, 'Schema' do
|
|
85
85
|
label :slug
|
86
86
|
end
|
87
87
|
|
88
|
+
class Selectpreviewable < PopulateMe::Document
|
89
|
+
set :default_attachment_class, PopulateMe::Attachment
|
90
|
+
field :name
|
91
|
+
field :img, type: :attachment, variations: [
|
92
|
+
PopulateMe::Variation.default
|
93
|
+
]
|
94
|
+
end
|
95
|
+
|
88
96
|
before do
|
89
97
|
Selectoptionable.documents = []
|
90
98
|
Selectoptionable.new(id: '1', name: 'Joe', slug: 'joe').save
|
91
99
|
Selectoptionable.new(id: '2', name: 'William', slug: 'william').save
|
92
100
|
Selectoptionable.new(id: '3', name: 'Jack', slug: 'jack').save
|
93
101
|
Selectoptionable.new(id: '4', name: 'Averell', slug: 'averell').save
|
102
|
+
Selectpreviewable.documents = []
|
103
|
+
Selectpreviewable.new(id: '1', name: 'Project', img: 'project.jpg').save
|
94
104
|
end
|
95
105
|
|
96
106
|
after do
|
@@ -102,19 +112,27 @@ describe PopulateMe::Document, 'Schema' do
|
|
102
112
|
assert output_proc.is_a?(Proc)
|
103
113
|
output = output_proc.call
|
104
114
|
assert_equal 4, output.size
|
105
|
-
assert output.all?{|o| o.is_a?(
|
106
|
-
assert_equal '1', output.find{|o|o
|
115
|
+
assert output.all?{|o| o.is_a?(Hash) and o.size==2}
|
116
|
+
assert_equal '1', output.find{|o|o.fetch(:description)=='joe'}.fetch(:value)
|
107
117
|
end
|
108
118
|
|
109
119
|
it 'Puts items in alphabetical order of their label' do
|
110
120
|
output= Selectoptionable.to_select_options.call
|
111
|
-
assert_equal
|
121
|
+
assert_equal({description: 'averell', value: '4'}, output[0])
|
112
122
|
end
|
113
123
|
|
114
124
|
it 'Has an option for prepending empty choice' do
|
115
125
|
output= Selectoptionable.to_select_options(allow_empty: true).call
|
116
|
-
assert_equal
|
117
|
-
assert_equal
|
126
|
+
assert_equal({description: '?', value: ''}, output[0])
|
127
|
+
assert_equal({description: 'averell', value: '4'}, output[1])
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'Adds a :preview_uri when there is a thumbnail' do
|
131
|
+
output= Selectpreviewable.to_select_options.call
|
132
|
+
assert output[0].key?(:preview_uri)
|
133
|
+
assert_equal 'Project', output[0][:description]
|
134
|
+
assert_equal '1', output[0][:value]
|
135
|
+
assert_equal '/attachment/selectpreviewable/project.populate_me_thumb.jpg', output[0][:preview_uri]
|
118
136
|
end
|
119
137
|
|
120
138
|
end
|
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.
|
4
|
+
version: 0.11.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: 2020-
|
11
|
+
date: 2020-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: web-utils
|