Skip to content

Commit

Permalink
Merge pull request #19 from it3s/user-location
Browse files Browse the repository at this point in the history
User location
  • Loading branch information
LuizArmesto committed May 1, 2014
2 parents 9e92ae6 + 1c94632 commit a1db780
Show file tree
Hide file tree
Showing 23 changed files with 257 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
# Ignore bundler config.
/.bundle

# Ignore vagrant link
/vagrant

# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ before_script:
- "psql -c 'create database test;' -U postgres"
- "cp config/database.yml.sample config/database.yml"
- "cp config/secrets.yml.sample config/secrets.yml"
- "rake db:create db:migrate db:test:prepare"
- "bundle exec rake db:create db:migrate db:test:prepare"

script:
- bundle exec rake
Expand Down
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ gem 'rails', '4.0.2'
gem 'puma' # faster app server
gem 'foreman' # process supervision
gem 'pg' # postgresql
gem 'rgeo' # geometry abstraction
gem 'rgeo-geojson' # geojson encode/decode
gem 'activerecord-postgis-adapter' # postgis

gem 'coffee-rails', '~> 4.0.0' # coffeescript
gem 'uglifier', '>= 1.3.0' # minify
Expand All @@ -19,6 +22,7 @@ gem 'font-awesome-sass' # font with svg icons
gem 'tinymce-rails' # tinymce wysiwyg editor
gem 'tinymce-rails-langs' # tinymce language pack
gem "jquery-fileupload-rails" # jquery-fielupload plugin
gem 'meppit-map-rails', :github => 'it3s/meppit-map-rails' # our beloved map

# gem 'turbolinks' # speed page loading

Expand Down
19 changes: 19 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
GIT
remote: git://github.com/it3s/meppit-map-rails.git
revision: efcf7e32fa2e2a990b3705826eba5e94dca60961
specs:
meppit-map-rails (0.0.1)

GEM
remote: https://rubygems.org/
specs:
Expand All @@ -19,6 +25,8 @@ GEM
activesupport (= 4.0.2)
arel (~> 4.0.0)
activerecord-deprecated_finders (1.0.3)
activerecord-postgis-adapter (0.6.5)
rgeo-activerecord (~> 0.5.0)
activesupport (4.0.2)
i18n (~> 0.6, >= 0.6.4)
minitest (~> 4.2)
Expand Down Expand Up @@ -239,6 +247,13 @@ GEM
remotipart (1.2.1)
rest-client (1.6.7)
mime-types (>= 1.16)
rgeo (0.3.20)
rgeo-activerecord (0.5.0)
activerecord (>= 3.0.3)
arel (>= 2.0.6)
rgeo (>= 0.3.20)
rgeo-geojson (0.2.3)
rgeo (>= 0.3.7)
rspec (2.14.1)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
Expand Down Expand Up @@ -324,6 +339,7 @@ PLATFORMS
ruby

DEPENDENCIES
activerecord-postgis-adapter
better_errors
binding_of_caller (= 0.7.1)
bourbon
Expand All @@ -348,6 +364,7 @@ DEPENDENCIES
konacha
letter_opener
letter_opener_web
meppit-map-rails!
mini_magick
oily_png
pg
Expand All @@ -357,6 +374,8 @@ DEPENDENCIES
puma
rails (= 4.0.2)
remotipart
rgeo
rgeo-geojson
rspec-rails (~> 2.0)
sass-rails (~> 4.0.0)
sdoc
Expand Down
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#= require components/alert
#= require components/editor
#= require components/overlay
#= require components/map

onReady = ->
App.mediator.publish('components:start')
Expand Down
21 changes: 21 additions & 0 deletions app/assets/javascripts/components/map.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#= require meppit-map

App.components.map = (container) ->
{
container: container

init: ->
L.Icon.Default.imagePath = '/assets' # FIXME: should not be done here.
@geojson = @container.data('geojson')
@startMap()

startMap: ->
el = @container[0]
@map = new Meppit.Map
element: el,
enableGeoJsonTile: false

@map.load(@geojson)
@map.panTo(@geojson.features[0])

}
22 changes: 21 additions & 1 deletion app/assets/javascripts/components/overlay.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,29 @@ App.components.overlay = (container) ->
container: container

overlayElement: """<div class="overlay"></div>"""
overlayMessage: """<div class="overlay-message"></div>"""

init: ->
data = @container.data('overlay')
overlay = @createOverlay(data)
@inject overlay

createOverlay: (data) ->
overlay = $(@overlayElement)

# toggle dark/light
overlay.addClass(data.style) if data?.style

overlay.append(@createMessage data) if data?.message
overlay

createMessage: (data)->
message = $(@overlayMessage)
message.text(data.message)
message

inject: (overlay) ->
@container.css 'position', 'relative'
@container.prepend @overlayElement
@container.prepend overlay

}
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// vendor
@import "jquery.modal";
@import "flexslider";
@import "meppit-map";

// app common
@import "shared/header";
Expand Down
11 changes: 11 additions & 0 deletions app/assets/stylesheets/core/_base.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,15 @@ h3 {
width: 100%;
height: 100%;
background-color: rgba(255, 255, 255,0.5);

.overlay-message {
color: #000;
text-align: center;
margin-top: 35%;
}

&.dark {
background-color: rgba(35, 35, 35, 0.7);
.overlay-message { color: #fff; }
}
}
7 changes: 5 additions & 2 deletions app/assets/stylesheets/users/_profile.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
// margin-bottom: 20px;
}

.user-location img{
.user-location {

width: 100%;
max-height: 200px;
margin: 20px 0;

.map { height: 250px; }
.placeholder { max-height: 200px; width: 240px; }
}

.user-projects {
Expand Down
19 changes: 19 additions & 0 deletions app/models/concerns/geometry.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Geometry
extend ActiveSupport::Concern

module ClassMethods
def geofactory
RGeo::Geographic.spherical_factory :srid => 4326
end

def geojson_field(*fields)
fields.each do |field|
set_rgeo_factory_for_column field, geofactory.projection_factory
define_method "#{field}_geojson" do
::GeoJSON::encode(send(field), id, geojson_properties).to_json
end
end
end
end

end
7 changes: 7 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class User < ActiveRecord::Base
include Contacts
include Geometry

authenticates_with_sorcery! do |config|
config.authentications_class = Authentication
Expand All @@ -11,6 +12,8 @@ class User < ActiveRecord::Base
has_many :authentications, :dependent => :destroy
accepts_nested_attributes_for :authentications

geojson_field :location

attr_reader :license_aggrement

validates :email, :name, :presence => true
Expand All @@ -29,4 +32,8 @@ def send_reset_password_email!
# override sorcery reset password to user sidekiq
UserMailer.delay.reset_password_email(id, I18n.locale)
end

def geojson_properties
{:name => name, :id => id}
end
end
1 change: 1 addition & 0 deletions app/views/users/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
</div>

<div class="user-location">
<!-- TODO: add map editor -->
<%= image_tag "imgs/map-placeholder.png", :alt => 'user location' %>
</div>

Expand Down
8 changes: 7 additions & 1 deletion app/views/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
</div>

<div class="user-location">
<%= image_tag "imgs/map-placeholder.png", :alt => 'user location' %>
<% if @user.location %>
<div class="map" data-components="map" data-geojson='<%= raw @user.location_geojson %>'></div>
<% else %>
<div data-components='overlay' data-overlay='<%= {style: "dark", message: t("users.profile.location.empty")}.to_json %>'>
<%= image_tag "imgs/map-placeholder.png", :alt => 'user location', :class => 'placeholder' %>
</div>
<% end %>
</div>

<div class="user-projects">
Expand Down
8 changes: 4 additions & 4 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ then
fi

# Setup
bundle
sudo -u vagrant rake db:create db:migrate
sudo -u vagrant rake db:create db:migrate RAILS_ENV=test
sudo -u vagrant rspec
sudo -u vagrant bundle
sudo -u vagrant bundle exec rake db:create db:migrate
sudo -u vagrant bundle exec rake db:create db:migrate RAILS_ENV=test
sudo -u vagrant bundle exec rspec

touch ~/runonce
fi
2 changes: 2 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require File.expand_path('../boot', __FILE__)

require 'rails/all'
require 'active_record/connection_adapters/postgis_adapter/railtie'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Expand All @@ -11,6 +12,7 @@ class Application < Rails::Application
# Set Time.zone default and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Brasilia'
config.autoload_paths += Dir["#{config.root}/lib/**/"]

config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**/*.{rb,yml}').to_s]
# config.i18n.default_locale = :'pt-BR'
Expand Down
16 changes: 12 additions & 4 deletions config/database.yml.sample
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
development:
adapter: postgresql
adapter: postgis
schema_search_path: '"$user",public,postgis'
postgis_extension: true
encoding: unicode
database: meppit_development
pool: 5
username: postgres
password:

test:
adapter: postgresql
adapter: postgis
schema_search_path: '"$user",public,postgis'
postgis_extension: true
encoding: unicode
database: meppit_test
pool: 5
username: postgres
password:

production:
adapter: postgresql
adapter: postgis
schema_search_path: '"$user",public,postgis'
postgis_extension: true
encoding: unicode
database: meppit_production
pool: 5
username: postgres
password:

staging:
adapter: postgresql
adapter: postgis
schema_search_path: '"$user",public,postgis'
postgis_extension: true
encoding: unicode
database: meppit_staging
pool: 5
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en/users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ en:
title: 'About me'
empty: "%{name} hasn't written anything yet."
last_contributions: 'Last Contributions'
location:
empty: 'Location not provided yet'

2 changes: 2 additions & 0 deletions config/locales/pt-BR/users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ pt-BR:
title: 'Sobre mim'
empty: "%{name} não escreveu nada ainda."
last_contributions: 'Últimas Contribuições'
location:
empty: 'Localização não fornecida'
9 changes: 9 additions & 0 deletions db/migrate/20140429030856_add_location_to_user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddLocationToUser < ActiveRecord::Migration
def change
change_table :users do |t|
t.geometry :location, :srid => 4326

t.index :location, :spatial => true
end
end
end
15 changes: 9 additions & 6 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20140309174451) do
ActiveRecord::Schema.define(version: 20140429030856) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
enable_extension "postgis"
enable_extension "hstore"

create_table "authentications", force: true do |t|
Expand All @@ -26,8 +27,8 @@
end

create_table "users", force: true do |t|
t.string "name", null: false
t.string "email", null: false
t.string "name", null: false
t.string "email", null: false
t.string "crypted_password"
t.datetime "created_at"
t.datetime "updated_at"
Expand All @@ -41,10 +42,12 @@
t.text "about_me"
t.hstore "contacts"
t.string "avatar"
t.spatial "location", limit: {:srid=>4326, :type=>"geometry"}
end

add_index "users", ["activation_token"], name: "index_users_on_activation_token", using: :btree
add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", using: :btree
add_index "users", ["activation_token"], :name => "index_users_on_activation_token"
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
add_index "users", ["location"], :name => "index_users_on_location", :spatial => true
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token"

end
Loading

0 comments on commit a1db780

Please sign in to comment.