diff --git a/Gemfile b/Gemfile index 65988ca4..f5358f47 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,5 @@ source 'https://rubygems.org' +ruby '1.9.3' gem 'rails', '3.2.17' @@ -14,6 +15,10 @@ gem 'formtastic' gem 'json' gem 'rails3-jquery-autocomplete' gem 'best_in_place' + +gem 'paperclip' +gem 'aws-sdk' + #gem 'therubyracer' #optional #gem 'rb-readline' @@ -29,6 +34,10 @@ group :assets do gem 'uglifier', '>= 1.0.3' end +group :production do #this is used on heroku + gem 'rmagick' +end + gem 'jquery-rails', '2.1.2' # To use ActiveModel has_secure_password diff --git a/Gemfile.lock b/Gemfile.lock index 3346fa26..e4bbb146 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -29,6 +29,9 @@ GEM i18n (~> 0.6, >= 0.6.4) multi_json (~> 1.0) arel (3.0.3) + aws-sdk (1.44.0) + json (~> 1.4) + nokogiri (>= 1.4.4) bcrypt (3.1.7) bcrypt (3.1.7-x86-mingw32) best_in_place (2.1.0) @@ -36,6 +39,10 @@ GEM rails (~> 3.1) builder (3.0.4) cancan (1.6.10) + climate_control (0.0.3) + activesupport (>= 3.0) + cocaine (0.5.4) + climate_control (>= 0.0.3, < 1.0) coffee-rails (3.2.2) coffee-script (>= 2.2.0) railties (~> 3.2.0) @@ -68,8 +75,18 @@ GEM mime-types (~> 1.16) treetop (~> 1.4.8) mime-types (1.25.1) + mini_portile (0.6.0) multi_json (1.10.0) + nokogiri (1.6.2.1) + mini_portile (= 0.6.0) + nokogiri (1.6.2.1-x86-mingw32) + mini_portile (= 0.6.0) orm_adapter (0.5.0) + paperclip (4.1.1) + activemodel (>= 3.0.0) + activesupport (>= 3.0.0) + cocaine (~> 0.5.3) + mime-types pg (0.17.1) pg (0.17.1-x86-mingw32) polyglot (0.3.4) @@ -129,6 +146,7 @@ PLATFORMS x86-mingw32 DEPENDENCIES + aws-sdk best_in_place cancan coffee-rails (~> 3.2.1) @@ -138,6 +156,7 @@ DEPENDENCIES jbuilder (= 0.8.2) jquery-rails (= 2.1.2) json + paperclip pg rails (= 3.2.17) rails3-jquery-autocomplete diff --git a/app/controllers/maps_controller.rb b/app/controllers/maps_controller.rb index a5ef3c6b..40107e72 100644 --- a/app/controllers/maps_controller.rb +++ b/app/controllers/maps_controller.rb @@ -62,8 +62,8 @@ class MapsController < ApplicationController # GET maps/:id def show - - @current = current_user + + @current = current_user @map = Map.find(params[:id]).authorize_to_show(@current) if not @map diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index d16a8f80..d824b72b 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -69,7 +69,7 @@ class TopicsController < ApplicationController @topic.permission = 'commons' @topic.metacode = Metacode.find_by_name(params[:topic][:metacode]) @topic.user = @user - + #if being created on a map, set topic by default to whatever permissions the map is if params[:topic][:map] @map = Map.find(params[:topic][:map]) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index ac97d22e..bfbc1ffc 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -16,9 +16,6 @@ class UsersController < ApplicationController @user = current_user @user.attributes = params[:user] - #@m = params[:metacodes][:value] - #@user.settings.metacodes=@m.split(',') - @user.save sign_in(@user, :bypass => true) diff --git a/app/models/topic.rb b/app/models/topic.rb index 149321c9..668c94fe 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -11,7 +11,24 @@ has_many :topics2, :through => :synapses1, :source => :topic2 has_many :mappings has_many :maps, :through => :mappings + + # This method associates the attribute ":image" with a file attachment + has_attached_file :image + + #, styles: { + # thumb: '100x100>', + # square: '200x200#', + # medium: '300x300>' + #} + + # Validate the attached image is image/jpg, image/png, etc + validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/ + # This method associates the attribute ":image" with a file attachment + has_attached_file :audio + # Validate the attached audio is audio/wav, audio/mp3, etc + validates_attachment_content_type :audio, :content_type => /\Aaudio\/.*\Z/ + def synapses synapses1 + synapses2 end diff --git a/app/models/user.rb b/app/models/user.rb index ae03c659..1be8144a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -11,13 +11,32 @@ has_many :mappings devise :database_authenticatable, :recoverable, :rememberable, :trackable, :registerable - attr_accessible :name, :email, :password, :password_confirmation, :code, :joinedwithcode, :remember_me + attr_accessible :name, :email, :image, :password, :password_confirmation, :code, :joinedwithcode, :remember_me serialize :settings, UserPreference validates_uniqueness_of :name # done by devise validates_uniqueness_of :email # done by devise + # This method associates the attribute ":image" with a file attachment + has_attached_file :image, :styles => { + :thumb => ['100x100>', :png], + :square => ['200x200#', :png], + :round => ['200x200#', :png] + }, :convert_options => {:round => Proc.new{self.convert_options}} + + # Validate the attached image is image/jpg, image/png, etc + validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/ + + def self.convert_options + trans = '' + trans << ' ( +clone -alpha extract ' + trans << '-draw "fill black polygon 0,0 0,100 100,0 fill white circle 100,100 100,0" ' + trans << '( +clone -flip ) -compose multiply -composite ' + trans << '( +clone -flop ) -compose multiply -composite ' + trans << ') -alpha off -compose copy_opacity -composite ' + end + if ActiveRecord::Base.connection.table_exists? 'users' codes = ActiveRecord::Base.connection.execute("SELECT code FROM users").map {|user| user["code"] } else diff --git a/app/views/maps/show.html.erb b/app/views/maps/show.html.erb index 474a6c1a..8a325a73 100644 --- a/app/views/maps/show.html.erb +++ b/app/views/maps/show.html.erb @@ -116,13 +116,13 @@ if (json.length > 0) { <% if authenticated? && (@map.permission == "commons" || @map.user == user) %> // this is for the heroku staging environment -window.realtime.socket = io.connect('http://gentle-savannah-1303.herokuapp.com'); +//window.realtime.socket = io.connect('http://gentle-savannah-1303.herokuapp.com'); // this is for metamaps.cc //window.realtime.socket = io.connect('http://metamaps.cc:5001'); // this is for localhost development -//window.realtime.socket = io.connect('http://localhost:5001'); +window.realtime.socket = io.connect('http://localhost:5001'); window.realtime.socket.on('connect', function () { console.log('socket connected'); diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index 732b0f03..1bb64d46 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -8,6 +8,9 @@

Your Settings

<%= formula_form_for @user, url: user_url do |form| %>

Edit Account

+ + <% if @user.image %><%= image_tag @user.image.url(:round), :size => "48x48" %><% end %> + <%= form.file_field :image %> <%= form.input :name, label: "Name", class: "name" %> <%= form.input :email, label: "Email", class: "email" %> <%= form.input :password, label: "Password", class: "password", :autocomplete => :off %> diff --git a/config/environments/development.rb b/config/environments/development.rb index 7f1b0375..d3a8b0b7 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -13,7 +13,16 @@ ISSAD::Application.configure do config.consider_all_requests_local = true config.action_controller.perform_caching = false - + # S3 file storage + config.paperclip_defaults = { + :storage => :s3, + :s3_credentials => { + :bucket => ENV['S3_BUCKET_NAME'], + :access_key_id => ENV['AWS_ACCESS_KEY_ID'], + :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'] + } + } + config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { address: 'mail.metamaps.cc', diff --git a/config/environments/production.rb b/config/environments/production.rb index 8b1bf0f9..962b0dd2 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -13,6 +13,17 @@ ISSAD::Application.configure do # Compress JavaScripts and CSS config.assets.compress = true + + + # S3 file storage + config.paperclip_defaults = { + :storage => :s3, + :s3_credentials => { + :bucket => ENV['S3_BUCKET_NAME'], + :access_key_id => ENV['AWS_ACCESS_KEY_ID'], + :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'] + } + } config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { diff --git a/config/initializers/paperclip.rb b/config/initializers/paperclip.rb new file mode 100644 index 00000000..1447988b --- /dev/null +++ b/config/initializers/paperclip.rb @@ -0,0 +1,2 @@ +Paperclip::Attachment.default_options[:url] = ':s3_domain_url' +Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename' \ No newline at end of file diff --git a/db/migrate/20140625212637_add_image_and_audio_to_topics.rb b/db/migrate/20140625212637_add_image_and_audio_to_topics.rb new file mode 100644 index 00000000..46bead64 --- /dev/null +++ b/db/migrate/20140625212637_add_image_and_audio_to_topics.rb @@ -0,0 +1,11 @@ +class AddImageAndAudioToTopics < ActiveRecord::Migration + def self.up + add_attachment :topics, :image + add_attachment :topics, :audio + end + + def self.down + remove_attachment :topics, :image + remove_attachment :topics, :audio + end +end diff --git a/db/migrate/20140707161810_add_image_to_users.rb b/db/migrate/20140707161810_add_image_to_users.rb new file mode 100644 index 00000000..0a479fda --- /dev/null +++ b/db/migrate/20140707161810_add_image_to_users.rb @@ -0,0 +1,9 @@ +class AddImageToUsers < ActiveRecord::Migration + def self.up + add_attachment :users, :image + end + + def self.down + remove_attachment :users, :image + end +end diff --git a/db/schema.rb b/db/schema.rb index 0a8292d7..c3fce2b2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140517115841) do +ActiveRecord::Schema.define(:version => 20140707161810) do create_table "in_metacode_sets", :force => true do |t| t.integer "metacode_id" @@ -83,8 +83,16 @@ ActiveRecord::Schema.define(:version => 20140517115841) do t.text "permission" t.integer "user_id" t.integer "metacode_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.string "image_file_name" + t.string "image_content_type" + t.integer "image_file_size" + t.datetime "image_updated_at" + t.string "audio_file_name" + t.string "audio_content_type" + t.integer "audio_file_size" + t.datetime "audio_updated_at" end create_table "users", :force => true do |t| @@ -110,6 +118,10 @@ ActiveRecord::Schema.define(:version => 20140517115841) do t.string "current_sign_in_ip" t.datetime "reset_password_sent_at" t.boolean "admin" + t.string "image_file_name" + t.string "image_content_type" + t.integer "image_file_size" + t.datetime "image_updated_at" end add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true