Skip to content
This repository was archived by the owner on Jul 22, 2022. It is now read-only.

Commit bb7946b

Browse files
committed
functional simplest_photo
1 parent 6ef53a8 commit bb7946b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+596
-4371
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727

2828
# Compiled assets
2929
/public/assets
30+
/public/uploads
31+
32+
.DS_Store
3033

3134
# JS Dependencies
3235
node_modules

Gemfile

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ gem 'pundit'
3939
# Using Active_Materials skin for ActiveAdmin
4040
gem "active_material", github: "vigetlabs/active_material"
4141

42+
#Using Simplest Photo for photo management
43+
gem 'simplest_photo', github: 'vigetlabs/simplest_photo'
44+
gem 'dragonfly-s3_data_store'
45+
4246
# Javascript build tool for use of Colonel Kurtz
4347
gem "browserify-rails"
4448

Gemfile.lock

+35
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ GIT
2222
specs:
2323
active_material (1.4.1)
2424

25+
GIT
26+
remote: https://github.com/vigetlabs/simplest_photo.git
27+
revision: 20dfe346c7b015afa0134faee0cbfc521c574eb1
28+
specs:
29+
simplest_photo (0.0.1)
30+
dragonfly
31+
rails (>= 4.2.1)
32+
2533
GIT
2634
remote: https://github.com/vigetlabs/viget-deployment.git
2735
revision: 42b48c6707cf703fe69be0544d3c6d4c033a21fa
@@ -138,15 +146,39 @@ GEM
138146
responders
139147
warden (~> 1.2.3)
140148
diff-lcs (1.3)
149+
dragonfly (1.1.3)
150+
addressable (~> 2.3)
151+
multi_json (~> 1.0)
152+
rack (>= 1.3)
153+
dragonfly-s3_data_store (1.3.0)
154+
dragonfly (~> 1.0)
155+
fog-aws
141156
draper (3.0.0)
142157
actionpack (~> 5.0)
143158
activemodel (~> 5.0)
144159
activemodel-serializers-xml (~> 1.0)
145160
activesupport (~> 5.0)
146161
request_store (~> 1.0)
147162
erubi (1.6.1)
163+
excon (0.57.1)
148164
execjs (2.7.0)
149165
ffi (1.9.18)
166+
fog-aws (1.4.0)
167+
fog-core (~> 1.38)
168+
fog-json (~> 1.0)
169+
fog-xml (~> 0.1)
170+
ipaddress (~> 0.8)
171+
fog-core (1.44.3)
172+
builder
173+
excon (~> 0.49)
174+
formatador (~> 0.2)
175+
fog-json (1.0.2)
176+
fog-core (~> 1.0)
177+
multi_json (~> 1.10)
178+
fog-xml (0.1.3)
179+
fog-core
180+
nokogiri (>= 1.5.11, < 2.0.0)
181+
formatador (0.2.5)
150182
formtastic (3.1.5)
151183
actionpack (>= 3.2.13)
152184
formtastic_i18n (0.6.0)
@@ -157,6 +189,7 @@ GEM
157189
activesupport (>= 4.1, < 5.2)
158190
highline (1.7.8)
159191
i18n (0.8.4)
192+
ipaddress (0.8.3)
160193
jbuilder (2.7.0)
161194
activesupport (>= 4.2.0)
162195
multi_json (>= 1.2)
@@ -334,6 +367,7 @@ DEPENDENCIES
334367
capybara (~> 2.13)
335368
coffee-rails (~> 4.2)
336369
devise
370+
dragonfly-s3_data_store
337371
draper
338372
inherited_resources!
339373
jbuilder (~> 2.5)
@@ -348,6 +382,7 @@ DEPENDENCIES
348382
sass-rails (~> 5.0)
349383
selenium-webdriver
350384
shoulda-matchers!
385+
simplest_photo!
351386
spring
352387
spring-watcher-listen (~> 2.0.0)
353388
turbolinks (~> 5)

README.md

+36-12
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,67 @@ coffee drinkers.
66

77
## Development Setup
88

9-
Ensure you have `rbenv` installed on your machine.
9+
1. Clone the repository onto your machine
10+
11+
$ git clone [email protected]:vigetlabs/GroundRules.git
12+
13+
2. Enter into the project directory
14+
15+
$ cd GroundRules
16+
17+
3. Ensure you have `postrgres` installed
18+
19+
$ brew install postgres
20+
21+
4. Ensure the `postgres` server is running
22+
23+
$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
24+
25+
5. Ensure you have `rbenv` installed on your machine
1026

1127
$ brew install rbenv
1228

13-
Ensure you have Ruby `2.4.1` installed on your machine.
29+
6. Ensure you have Ruby `2.4.1` installed on your machine
1430

1531
$ rbenv install 2.4.1
1632

17-
Install Bundler
33+
7. Install Bundler
1834

1935
$ gem install bundler
2036

21-
To get the application running, first install gem dependencies with Bundler:
37+
8. To get the application running, first install gem dependencies with Bundler:
2238

2339
$ bundle install
2440

25-
Copy the example environment dotfile and fill out:
41+
9. Install ImageMagick
42+
43+
$ brew install imagemagick
44+
45+
10. Copy the example environment dotfile and fill out:
46+
47+
$ cp config/secrets.example.yml config/secrets.yml
48+
49+
10a. Keys can be generated by using the following command:
2650

27-
$ cp secrets.example.yml secrets.yml
51+
$ bundle exec rake secret
2852

29-
Copy the sample database configuration file and fill out:
53+
11. Copy the sample database configuration file and fill out:
3054

3155
$ cp config/database.example.yml config/database.yml
3256

33-
Run npm install
57+
12. Run npm install
3458

3559
$ npm install
3660

37-
Create, migrate and seed the database:
61+
13. Create, migrate and seed the database:
3862

3963
$ rake db:create db:migrate db:seed
4064

41-
Start the server:
65+
14. Start the server:
4266

43-
$ rails s
67+
$ rails s
4468

45-
Now the application will be available at `localhost:3000`.
69+
Now the application will be available at `localhost:3000`
4670

4771
## Deploying Changes
4872

app/admin/device.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
config.filters = false
44

55
permit_params :name,
6-
:image_url
6+
:image_id
77

88
action_item :device_problem, only: [:show, :edit] do
99
link_to 'Problems', admin_device_device_problems_path(resource)
@@ -12,15 +12,15 @@
1212
index do
1313
column :name
1414
column "Image" do |device|
15-
image_tag device.image_url, style: 'width: 5rem; height: 5rem'
15+
image_tag device.image.url, style: 'width: 5rem; height: 5rem'
1616
end
1717
actions
1818
end
1919

2020
form do |f|
2121
f.inputs do
2222
f.input :name
23-
f.input :image_url
23+
f.input :image, as: :photo_select
2424
end
2525
f.actions
2626
end

app/admin/inputs/colonel_kurtz_input.rb

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def to_html
3131
end
3232
end
3333

34-
3534
private
3635

3736
def editor_div
+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
class PhotoSelectInput < Formtastic::Inputs::StringInput
2+
3+
include Rails.application.routes.url_helpers
4+
5+
def file
6+
@object.send(method)
7+
end
8+
9+
def file_attachment
10+
@object.send("#{method}_attachment")
11+
end
12+
13+
def association_primary_key
14+
"#{method}_id"
15+
end
16+
17+
def file_class
18+
if file.present?
19+
file.class
20+
else
21+
self.class.name.match(/\A(?<model>\w+)SelectInput/)[:model].constantize
22+
end
23+
end
24+
25+
def file_name
26+
file_class.name
27+
end
28+
29+
def index_url
30+
url_for [:admin, file_class.table_name.to_sym, only_path: true]
31+
end
32+
33+
def file_route_key
34+
file_class.model_name.i18n_key
35+
end
36+
37+
def input_html_options
38+
{
39+
data: {
40+
url: index_url,
41+
resource: file_name
42+
}
43+
}.deep_merge(super)
44+
end
45+
46+
def to_html
47+
input_wrapping do
48+
label_html <<
49+
field_html <<
50+
image_preview_html
51+
end
52+
end
53+
54+
def field_html
55+
builder.text_field(association_primary_key, input_html_options)
56+
end
57+
58+
def image_preview_html
59+
if image_stored?
60+
%Q{
61+
<p class="image-preview">
62+
#{template.image_tag(image.thumb('x100').url)}
63+
<br>
64+
#{template.link_to('Original Image', image.url, target: '_blank')}
65+
</p>
66+
}.html_safe
67+
end
68+
end
69+
70+
def label_html
71+
super.tap do |label|
72+
links = [template.link_to('New', [:new, :admin, file_route_key], target: '_blank', class: 'photo-picker-button')]
73+
74+
if image_stored? && show_remove_link? && file_attachment.present?
75+
links.unshift template.link_to('Remove', [:admin, file_attachment], method: :delete, class: 'photo-picker-button')
76+
end
77+
78+
label.insert -9, links.join
79+
end
80+
end
81+
82+
def image_stored?
83+
file.try(:image_stored?)
84+
end
85+
86+
def image
87+
file.try(:image)
88+
end
89+
90+
def show_remove_link?
91+
@object.persisted? && !required?
92+
end
93+
94+
end

app/admin/photo.rb

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
ActiveAdmin.register Photo do
2+
config.sort_order = 'created_at_desc'
3+
4+
filter :name_contains
5+
6+
permit_params :image,
7+
:name
8+
9+
index do
10+
column :image do |photo|
11+
image_tag photo.url, style: 'width: 5rem; height: 5rem'
12+
end
13+
column :name
14+
actions
15+
end
16+
17+
show title: :name do
18+
attributes_table do
19+
row(:image) { |photo| image_tag photo.url }
20+
row :name
21+
row :created_at
22+
row :updated_at
23+
end
24+
25+
panel 'Attachments' do
26+
table_for resource.photo_attachments do
27+
column 'Item', :attachable
28+
column('Role') { |a| a.attachable_name.titleize }
29+
end
30+
end
31+
end
32+
33+
form do |f|
34+
inputs do
35+
if f.object.new_record?
36+
input :image, as: :file
37+
end
38+
input :name
39+
end
40+
actions
41+
end
42+
43+
end

app/admin/roast.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
permit_params :name,
44
:toggle_text,
55
:description,
6-
:toggle_image_url,
7-
:thumbnail_image_url
6+
:toggle_image_id
87

98
filter :name_contains
109

@@ -15,7 +14,7 @@
1514
index do
1615
column :name
1716
column "Toggle Image" do |roast|
18-
image_tag roast.toggle_image_url, style: 'width: 5rem; height: 5rem'
17+
image_tag roast.toggle_image.url, style: 'width: 5rem; height: 5rem'
1918
end
2019
column :toggle_text
2120
column :description

app/admin/roast_brand.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
permit_params :brand_name,
1010
:roast_name,
11-
:image_url,
11+
:image_id,
1212
:roast_id
1313

1414
index do
1515
column :brand_name
1616
column :roast_name
17-
column "Image" do |device|
18-
image_tag device.image_url, style: 'width: 5rem; height: 5rem'
17+
column "Image" do |roast_brand|
18+
image_tag roast_brand.image.url, style: 'width: 5rem; height: 5rem'
1919
end
2020
column "Roast" do |roast_brand|
2121
roast_brand.roast.name
@@ -27,7 +27,7 @@
2727
f.inputs do
2828
f.input :brand_name
2929
f.input :roast_name
30-
f.input :image_url
30+
f.input :image, as: :photo_select
3131
end
3232
f.actions
3333
end

0 commit comments

Comments
 (0)