Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
eddie-ruva committed Feb 19, 2014
2 parents c280cdf + a227a9b commit e454b3e
Show file tree
Hide file tree
Showing 29 changed files with 278 additions and 67 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@
.ruby-version
.rspec
Guardfile
coverage
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ gem 'figaro'
gem 'active_model_serializers'
gem 'coveralls', require: false

# Async backgroun job handling
gem 'sidekiq'

group :test do
gem 'ffaker'
gem 'database_cleaner'
gem 'launchy'
gem 'capybara'
gem 'selenium-webdriver'
gem 'selenium-webdriver', "~> 2.38.0"
end

group :development,:test do
Expand Down
24 changes: 19 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ GEM
activemodel (>= 3.2.0)
activesupport (>= 3.2.0)
json (>= 1.7)
childprocess (0.3.9)
celluloid (0.15.2)
timers (~> 1.1.0)
childprocess (0.5.1)
ffi (~> 1.0, >= 1.0.11)
chunky_png (1.2.8)
coderay (1.1.0)
Expand All @@ -73,6 +75,7 @@ GEM
sass (~> 3.1)
compass-rails (1.0.3)
compass (>= 0.12.2, < 0.14)
connection_pool (1.2.0)
coveralls (0.7.0)
multi_json (~> 1.3)
rest-client
Expand Down Expand Up @@ -255,6 +258,9 @@ GEM
ffi (>= 0.5.0)
rdoc (3.12.2)
json (~> 1.4)
redis (3.0.7)
redis-namespace (1.4.1)
redis (~> 3.0.4)
rest-client (1.6.7)
mime-types (>= 1.16)
rspec-core (2.14.5)
Expand All @@ -269,24 +275,30 @@ GEM
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
ruby-hmac (0.4.0)
rubyzip (0.9.9)
rubyzip (1.1.0)
sass (3.2.10)
sass-rails (3.2.6)
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
sassy-math (1.5)
compass (~> 0.11)
selenium-webdriver (2.35.1)
selenium-webdriver (2.38.0)
childprocess (>= 0.2.5)
multi_json (~> 1.0)
rubyzip (< 1.0.0)
rubyzip (~> 1.0)
websocket (~> 1.0.4)
sendgrid (1.2.0)
json
json
shoulda-matchers (2.3.0)
activesupport (>= 3.0.0)
sidekiq (2.17.5)
celluloid (>= 0.15.2)
connection_pool (>= 1.0.0)
json
redis (>= 3.0.6)
redis-namespace (>= 1.3.1)
simple_oauth (0.2.0)
simplecov (0.8.2)
docile (~> 1.1.0)
Expand All @@ -311,6 +323,7 @@ GEM
activerecord
statistics2
tilt (1.4.1)
timers (1.1.0)
tins (0.13.1)
treetop (1.4.15)
polyglot
Expand Down Expand Up @@ -381,9 +394,10 @@ DEPENDENCIES
ransack
rspec-rails
sass-rails (~> 3.2.3)
selenium-webdriver
selenium-webdriver (~> 2.38.0)
sendgrid
shoulda-matchers
sidekiq
thin
thumbs_up
twitter
Expand Down
1 change: 0 additions & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb

1 change: 1 addition & 0 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ based on the [Open 311](http://open311.org) standard.
- Rails 3.2
- Bootstrap 3.0
- Rspec 2.14
- Redis 2.8.6

### Questions?

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ de la comunicación con la ciudadanía y los reportes de cuestiones en sus servi
- Rails 3.2
- Bootstrap 3.0
- Rspec 2.14
- Redis 2.8.6

### ¿Dudas?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class window.GeolocateMap
@jq_address_field.on 'change', =>
@map.validates_address_text @jq_address_field.val(), (result, is_valid) =>
if is_valid
@map.marker.setPosition(result.geometry.location)
@map.update_marker_position(result.geometry.location)
@_update_lat_and_lng_from_marker()
else
@_rollback_to_last_valid_address()
Expand Down
10 changes: 10 additions & 0 deletions app/assets/javascripts/geolocate_map/map.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ class GeolocateMap.Map
else
cb(undefined, false)

update_marker_position: (position) ->
@marker.setPosition(position)
@_zoom_on_marker()

_zoom_on_marker: ->
@g_map.setZoom(17);
@g_map.panTo(@marker.getPosition());

_add_listener_for_map_drag_end: ->
google.maps.event.addListener @g_map, 'dragend', =>
@reset_to_center unless @validates_position(@g_map.getCenter())
Expand All @@ -48,6 +56,7 @@ class GeolocateMap.Map
mapTypeId: google.maps.MapTypeId.ROADMAP
scaleControl: true
html5: false
zoom: 15
}, @_options)

_build_marker_on_center: ->
Expand All @@ -65,6 +74,7 @@ class GeolocateMap.Map
if @validates_position(latLng)
@marker.setPosition(latLng)
@g_map.setCenter(latLng)
@_zoom_on_marker()
$(window).trigger('first_location')
),
((msg) ->
Expand Down
12 changes: 12 additions & 0 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class UserMailer < ActionMailer::Base
default from: ENV['MAILER_FROM'] || 'Urbem <no-responder@urbem.org>'

def notify_service_request_status_change(service_request_id, previous_status_id)
@service_request = ServiceRequest.find(service_request_id)
@user = @service_request.requester
@previous_status = Status.find(previous_status_id)
mail(subject: I18n.t('mailer.subject.status_change_notification'), to: @user.email)
end

end

12 changes: 12 additions & 0 deletions app/models/service_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class ServiceRequest < ActiveRecord::Base
validate :service_extra_fields

before_validation :assign_default_status, on: :create
after_update :send_notification_for_status_update

belongs_to :service
belongs_to :requester, polymorphic: true
Expand Down Expand Up @@ -106,6 +107,11 @@ def service_fields_hash
end
end

def requested_by_user?
self.requester_type == 'User'
end


ransacker :date do |parent|
Arel::Nodes::InfixOperation.new('||',
Arel::Nodes::InfixOperation.new('||', parent.table[:created_at], ' '), parent.table[:created_at])
Expand All @@ -123,4 +129,10 @@ def assign_default_status
self.status = Status.where(is_default: true).first
end

def send_notification_for_status_update
if self.requested_by_user? && self.status_id_changed?
UserMailer.delay.notify_service_request_status_change(self.id, self.status_id_was)
end
end

end
21 changes: 8 additions & 13 deletions app/views/service_requests/_form.html.haml
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
= form_for @service_request, html: {class: "form-horizontal", role: 'form'} do |f|

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

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

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

.form-group
= f.label :service_id, t('form.labels.service'), class: 'col-lg-3 control-label'
= f.label :media, t('form.labels.image'), class: 'col-lg-3 control-label'
.col-lg-9
= f.select :service_id, Service.all.collect {|p| [ p.name, p.id ] }, { include_blank: true }, { class: 'js-load_service_fields form-control' }
= errors_on_resource_for_field(@service_request, :service_id)

%div#service_fields_container
= render @service_request.service.service_fields if @service_request.service?
= f.file_field :media, class: 'js-image-preview'
.image_preview

.form-group
.col-lg-offset-3.col-lg-9
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_header.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
%li
= link_to t('public_nav_bar.service_requests'), service_requests_path, class: "reports index"
%li
= link_to t('public_nav_bar.new_service_request'), new_service_request_path, class: "reports new"
= button_to t('public_nav_bar.new_service_request'), new_service_request_path, method: :get, class: "reports new btn btn-primary navbar-btn"
%ul.nav.navbar-nav.navbar-right
- if current_user
%li.dropdown
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<p>Hola <b><%= @user.name || @user.email %></b>, </p>

<p>Tu reporte con folio <b>#<%= @service_request.id %></b> ha cambiado de estatus <%= @previous_status.name %> a <%= @service_request.status.name %></p>

<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>

<p>Saludos</p>
36 changes: 36 additions & 0 deletions config/application.yml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# More info at https://github.com/laserlemon/figaro


# Facebook credentials
FACEBOOK_SECRET: ''
FACEBOOK_KEY: ''

# Twitter credentials
TWITTER_KEY: ''
TWITTER_SECRET: ''
TWITTER_OAUTH_TOKEN: ''
TWITTER_OAUTH_TOKEN_SECRET: ''

# Sendgrid credentials
SENDGRID_USERNAME: ''
SENDGRID_PASSWORD: ''

# Coverall creadentials
COVERALLS_TOKEN: ''

# From whom do I send the emails from
MAILER_FROM: ''

# Who's my host?
HOST: ''

# Redis server URL
REDISCLOUD_URL: ''

# S3 credentials
S3_BUCKET: ''
AWS_SECRET: ''
AWS_KEY: ''

# Google Maps credentials
GOOGLE_KEY: ''
21 changes: 21 additions & 0 deletions config/database.yml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
development:
adapter: postgresql
encoding: unicode
host: localhost
database: reporte_ciudadano_development
pool: 5
password:

test:
adapter: postgresql
encoding: unicode
database: reporte_ciudadano_test
pool: 5
password:

production:
adapter: postgresql
encoding: unicode
database: reporte_ciudadano_production
pool: 5
password:
10 changes: 3 additions & 7 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,10 @@
# Expands the lines which load the assets
config.assets.debug = true

# Action Mailer
config.action_mailer.default_url_options = { :host => 'localhost:3000' }

config.action_mailer.delivery_method = :letter_opener
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true

#Fallback for development as it uses open letter
SENDGRID = {
username: '',
password: '',
domain: ''
}
end
16 changes: 15 additions & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@
# with SQLite, MySQL, and PostgreSQL)
# config.active_record.auto_explain_threshold_in_seconds = 0.5
#
config.action_mailer.default_url_options = { :host => ENV['ACTION_MAILER_DEFAULT_URL'] }

# Action mailer
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default_url_options = { :host => ENV['HOST'] }
config.action_mailer.smtp_settings = {
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'heroku.com',
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:enable_starttls_auto => true
}



end
1 change: 1 addition & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
config.action_mailer.default_url_options = { :host => 'localhost:3000' }

# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
Expand Down
9 changes: 0 additions & 9 deletions config/initializers/setup_mail.rb

This file was deleted.

16 changes: 16 additions & 0 deletions config/initializers/sidekiq.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
if Rails.env.production?
Sidekiq.configure_server do |config|
config.redis = { url: ENV["REDISCLOUD_URL"], size: 3 }

database_url = ENV['DATABASE_URL']
if database_url
ENV['DATABASE_URL'] = "#{database_url}?pool=20"
ActiveRecord::Base.establish_connection
end
end

Sidekiq.configure_client do |config|
config.redis = {size: 1}
end
end

Loading

0 comments on commit e454b3e

Please sign in to comment.