Skip to content

Commit e454b3e

Browse files
committed
Merge branch 'develop'
2 parents c280cdf + a227a9b commit e454b3e

29 files changed

+278
-67
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@
2525
.ruby-version
2626
.rspec
2727
Guardfile
28+
coverage

Gemfile

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@ gem 'figaro'
3030
gem 'active_model_serializers'
3131
gem 'coveralls', require: false
3232

33+
# Async backgroun job handling
34+
gem 'sidekiq'
35+
3336
group :test do
3437
gem 'ffaker'
3538
gem 'database_cleaner'
3639
gem 'launchy'
3740
gem 'capybara'
38-
gem 'selenium-webdriver'
41+
gem 'selenium-webdriver', "~> 2.38.0"
3942
end
4043

4144
group :development,:test do

Gemfile.lock

+19-5
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ GEM
5555
activemodel (>= 3.2.0)
5656
activesupport (>= 3.2.0)
5757
json (>= 1.7)
58-
childprocess (0.3.9)
58+
celluloid (0.15.2)
59+
timers (~> 1.1.0)
60+
childprocess (0.5.1)
5961
ffi (~> 1.0, >= 1.0.11)
6062
chunky_png (1.2.8)
6163
coderay (1.1.0)
@@ -73,6 +75,7 @@ GEM
7375
sass (~> 3.1)
7476
compass-rails (1.0.3)
7577
compass (>= 0.12.2, < 0.14)
78+
connection_pool (1.2.0)
7679
coveralls (0.7.0)
7780
multi_json (~> 1.3)
7881
rest-client
@@ -255,6 +258,9 @@ GEM
255258
ffi (>= 0.5.0)
256259
rdoc (3.12.2)
257260
json (~> 1.4)
261+
redis (3.0.7)
262+
redis-namespace (1.4.1)
263+
redis (~> 3.0.4)
258264
rest-client (1.6.7)
259265
mime-types (>= 1.16)
260266
rspec-core (2.14.5)
@@ -269,24 +275,30 @@ GEM
269275
rspec-expectations (~> 2.14.0)
270276
rspec-mocks (~> 2.14.0)
271277
ruby-hmac (0.4.0)
272-
rubyzip (0.9.9)
278+
rubyzip (1.1.0)
273279
sass (3.2.10)
274280
sass-rails (3.2.6)
275281
railties (~> 3.2.0)
276282
sass (>= 3.1.10)
277283
tilt (~> 1.3)
278284
sassy-math (1.5)
279285
compass (~> 0.11)
280-
selenium-webdriver (2.35.1)
286+
selenium-webdriver (2.38.0)
281287
childprocess (>= 0.2.5)
282288
multi_json (~> 1.0)
283-
rubyzip (< 1.0.0)
289+
rubyzip (~> 1.0)
284290
websocket (~> 1.0.4)
285291
sendgrid (1.2.0)
286292
json
287293
json
288294
shoulda-matchers (2.3.0)
289295
activesupport (>= 3.0.0)
296+
sidekiq (2.17.5)
297+
celluloid (>= 0.15.2)
298+
connection_pool (>= 1.0.0)
299+
json
300+
redis (>= 3.0.6)
301+
redis-namespace (>= 1.3.1)
290302
simple_oauth (0.2.0)
291303
simplecov (0.8.2)
292304
docile (~> 1.1.0)
@@ -311,6 +323,7 @@ GEM
311323
activerecord
312324
statistics2
313325
tilt (1.4.1)
326+
timers (1.1.0)
314327
tins (0.13.1)
315328
treetop (1.4.15)
316329
polyglot
@@ -381,9 +394,10 @@ DEPENDENCIES
381394
ransack
382395
rspec-rails
383396
sass-rails (~> 3.2.3)
384-
selenium-webdriver
397+
selenium-webdriver (~> 2.38.0)
385398
sendgrid
386399
shoulda-matchers
400+
sidekiq
387401
thin
388402
thumbs_up
389403
twitter

Procfile

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
2-

README.en.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ based on the [Open 311](http://open311.org) standard.
1818
- Rails 3.2
1919
- Bootstrap 3.0
2020
- Rspec 2.14
21+
- Redis 2.8.6
2122

2223
### Questions?
2324

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ de la comunicación con la ciudadanía y los reportes de cuestiones en sus servi
2121
- Rails 3.2
2222
- Bootstrap 3.0
2323
- Rspec 2.14
24+
- Redis 2.8.6
2425

2526
### ¿Dudas?
2627

app/assets/javascripts/geolocate_map/geolocateMap.js.coffee

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class window.GeolocateMap
2525
@jq_address_field.on 'change', =>
2626
@map.validates_address_text @jq_address_field.val(), (result, is_valid) =>
2727
if is_valid
28-
@map.marker.setPosition(result.geometry.location)
28+
@map.update_marker_position(result.geometry.location)
2929
@_update_lat_and_lng_from_marker()
3030
else
3131
@_rollback_to_last_valid_address()

app/assets/javascripts/geolocate_map/map.js.coffee

+10
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ class GeolocateMap.Map
3535
else
3636
cb(undefined, false)
3737

38+
update_marker_position: (position) ->
39+
@marker.setPosition(position)
40+
@_zoom_on_marker()
41+
42+
_zoom_on_marker: ->
43+
@g_map.setZoom(17);
44+
@g_map.panTo(@marker.getPosition());
45+
3846
_add_listener_for_map_drag_end: ->
3947
google.maps.event.addListener @g_map, 'dragend', =>
4048
@reset_to_center unless @validates_position(@g_map.getCenter())
@@ -48,6 +56,7 @@ class GeolocateMap.Map
4856
mapTypeId: google.maps.MapTypeId.ROADMAP
4957
scaleControl: true
5058
html5: false
59+
zoom: 15
5160
}, @_options)
5261

5362
_build_marker_on_center: ->
@@ -65,6 +74,7 @@ class GeolocateMap.Map
6574
if @validates_position(latLng)
6675
@marker.setPosition(latLng)
6776
@g_map.setCenter(latLng)
77+
@_zoom_on_marker()
6878
$(window).trigger('first_location')
6979
),
7080
((msg) ->

app/mailers/user_mailer.rb

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class UserMailer < ActionMailer::Base
2+
default from: ENV['MAILER_FROM'] || 'Urbem <no-responder@urbem.org>'
3+
4+
def notify_service_request_status_change(service_request_id, previous_status_id)
5+
@service_request = ServiceRequest.find(service_request_id)
6+
@user = @service_request.requester
7+
@previous_status = Status.find(previous_status_id)
8+
mail(subject: I18n.t('mailer.subject.status_change_notification'), to: @user.email)
9+
end
10+
11+
end
12+

app/models/service_request.rb

+12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class ServiceRequest < ActiveRecord::Base
1010
validate :service_extra_fields
1111

1212
before_validation :assign_default_status, on: :create
13+
after_update :send_notification_for_status_update
1314

1415
belongs_to :service
1516
belongs_to :requester, polymorphic: true
@@ -106,6 +107,11 @@ def service_fields_hash
106107
end
107108
end
108109

110+
def requested_by_user?
111+
self.requester_type == 'User'
112+
end
113+
114+
109115
ransacker :date do |parent|
110116
Arel::Nodes::InfixOperation.new('||',
111117
Arel::Nodes::InfixOperation.new('||', parent.table[:created_at], ' '), parent.table[:created_at])
@@ -123,4 +129,10 @@ def assign_default_status
123129
self.status = Status.where(is_default: true).first
124130
end
125131

132+
def send_notification_for_status_update
133+
if self.requested_by_user? && self.status_id_changed?
134+
UserMailer.delay.notify_service_request_status_change(self.id, self.status_id_was)
135+
end
136+
end
137+
126138
end

app/views/service_requests/_form.html.haml

+8-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
= form_for @service_request, html: {class: "form-horizontal", role: 'form'} do |f|
22

33
.form-group
4-
= f.label :title, t('form.labels.title'), class: 'col-lg-3 control-label'
4+
= f.label :service_id, t('form.labels.service'), class: 'col-lg-3 control-label'
55
.col-lg-9
6-
= f.text_field :title, class: 'form-control'
6+
= f.select :service_id, Service.all.collect {|p| [ p.name, p.id ] }, { include_blank: true }, { class: 'js-load_service_fields form-control' }
7+
= errors_on_resource_for_field(@service_request, :service_id)
78

8-
.form-group
9-
= f.label :media, t('form.labels.image'), class: 'col-lg-3 control-label'
10-
.col-lg-9
11-
= f.file_field :media, class: 'js-image-preview'
12-
.image_preview
9+
%div#service_fields_container
10+
= render @service_request.service.service_fields if @service_request.service?
1311

1412
.form-group
1513
= f.label :address, t('form.labels.address'), class: 'col-lg-3 control-label'
@@ -23,13 +21,10 @@
2321
= errors_on_resource_for_field(@service_request, :description)
2422

2523
.form-group
26-
= f.label :service_id, t('form.labels.service'), class: 'col-lg-3 control-label'
24+
= f.label :media, t('form.labels.image'), class: 'col-lg-3 control-label'
2725
.col-lg-9
28-
= f.select :service_id, Service.all.collect {|p| [ p.name, p.id ] }, { include_blank: true }, { class: 'js-load_service_fields form-control' }
29-
= errors_on_resource_for_field(@service_request, :service_id)
30-
31-
%div#service_fields_container
32-
= render @service_request.service.service_fields if @service_request.service?
26+
= f.file_field :media, class: 'js-image-preview'
27+
.image_preview
3328

3429
.form-group
3530
.col-lg-offset-3.col-lg-9

app/views/shared/_header.html.haml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
%li
1414
= link_to t('public_nav_bar.service_requests'), service_requests_path, class: "reports index"
1515
%li
16-
= link_to t('public_nav_bar.new_service_request'), new_service_request_path, class: "reports new"
16+
= button_to t('public_nav_bar.new_service_request'), new_service_request_path, method: :get, class: "reports new btn btn-primary navbar-btn"
1717
%ul.nav.navbar-nav.navbar-right
1818
- if current_user
1919
%li.dropdown
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<p>Hola <b><%= @user.name || @user.email %></b>, </p>
2+
3+
<p>Tu reporte con folio <b>#<%= @service_request.id %></b> ha cambiado de estatus <%= @previous_status.name %> a <%= @service_request.status.name %></p>
4+
5+
<p>Puedes ver más sobre este reporte y el mensaje dejado por el administrador ingresando a la siguiente página: <%= link_to nil, service_request_url(@service_request) %></p>
6+
7+
<p>Saludos</p>

config/application.yml.example

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# More info at https://github.com/laserlemon/figaro
2+
3+
4+
# Facebook credentials
5+
FACEBOOK_SECRET: ''
6+
FACEBOOK_KEY: ''
7+
8+
# Twitter credentials
9+
TWITTER_KEY: ''
10+
TWITTER_SECRET: ''
11+
TWITTER_OAUTH_TOKEN: ''
12+
TWITTER_OAUTH_TOKEN_SECRET: ''
13+
14+
# Sendgrid credentials
15+
SENDGRID_USERNAME: ''
16+
SENDGRID_PASSWORD: ''
17+
18+
# Coverall creadentials
19+
COVERALLS_TOKEN: ''
20+
21+
# From whom do I send the emails from
22+
MAILER_FROM: ''
23+
24+
# Who's my host?
25+
HOST: ''
26+
27+
# Redis server URL
28+
REDISCLOUD_URL: ''
29+
30+
# S3 credentials
31+
S3_BUCKET: ''
32+
AWS_SECRET: ''
33+
AWS_KEY: ''
34+
35+
# Google Maps credentials
36+
GOOGLE_KEY: ''

config/database.yml.example

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
development:
2+
adapter: postgresql
3+
encoding: unicode
4+
host: localhost
5+
database: reporte_ciudadano_development
6+
pool: 5
7+
password:
8+
9+
test:
10+
adapter: postgresql
11+
encoding: unicode
12+
database: reporte_ciudadano_test
13+
pool: 5
14+
password:
15+
16+
production:
17+
adapter: postgresql
18+
encoding: unicode
19+
database: reporte_ciudadano_production
20+
pool: 5
21+
password:

config/environments/development.rb

+3-7
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,10 @@
3535
# Expands the lines which load the assets
3636
config.assets.debug = true
3737

38+
# Action Mailer
3839
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
39-
4040
config.action_mailer.delivery_method = :letter_opener
41+
config.action_mailer.perform_deliveries = true
42+
config.action_mailer.raise_delivery_errors = true
4143

42-
#Fallback for development as it uses open letter
43-
SENDGRID = {
44-
username: '',
45-
password: '',
46-
domain: ''
47-
}
4844
end

config/environments/production.rb

+15-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,20 @@
6666
# with SQLite, MySQL, and PostgreSQL)
6767
# config.active_record.auto_explain_threshold_in_seconds = 0.5
6868
#
69-
config.action_mailer.default_url_options = { :host => ENV['ACTION_MAILER_DEFAULT_URL'] }
69+
70+
# Action mailer
71+
config.action_mailer.raise_delivery_errors = false
72+
config.action_mailer.default_url_options = { :host => ENV['HOST'] }
73+
config.action_mailer.smtp_settings = {
74+
:user_name => ENV['SENDGRID_USERNAME'],
75+
:password => ENV['SENDGRID_PASSWORD'],
76+
:domain => 'heroku.com',
77+
:address => 'smtp.sendgrid.net',
78+
:port => '587',
79+
:authentication => :plain,
80+
:enable_starttls_auto => true
81+
}
82+
83+
7084

7185
end

config/environments/test.rb

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
# The :test delivery method accumulates sent emails in the
2929
# ActionMailer::Base.deliveries array.
3030
config.action_mailer.delivery_method = :test
31+
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
3132

3233
# Raise exception on mass assignment protection for Active Record models
3334
config.active_record.mass_assignment_sanitizer = :strict

config/initializers/setup_mail.rb

-9
This file was deleted.

config/initializers/sidekiq.rb

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
if Rails.env.production?
2+
Sidekiq.configure_server do |config|
3+
config.redis = { url: ENV["REDISCLOUD_URL"], size: 3 }
4+
5+
database_url = ENV['DATABASE_URL']
6+
if database_url
7+
ENV['DATABASE_URL'] = "#{database_url}?pool=20"
8+
ActiveRecord::Base.establish_connection
9+
end
10+
end
11+
12+
Sidekiq.configure_client do |config|
13+
config.redis = {size: 1}
14+
end
15+
end
16+

0 commit comments

Comments
 (0)