diff --git a/.gitignore b/.gitignore index 27f1273..e78ed47 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ !/log/.keep !/tmp/.keep /public/uploads/ +coverage # Ignore Byebug command history file. .byebug_history diff --git a/.rspec b/.rspec index 43ae203..c99d2e7 100644 --- a/.rspec +++ b/.rspec @@ -1,3 +1 @@ ---color --require spec_helper ---format documentation diff --git a/.rubocop.yml b/.rubocop.yml index 9cad052..3982e55 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -9,12 +9,8 @@ AllCops: - 'spec/rails_helper.rb' - 'test/test_helper.rb' - 'config/puma.rb' - - 'config/initializers/devise.rb' - - 'config/initializers/bower_rails.rb' - - 'config/initializers/wrap_parameters.rb' - - 'config/initializers/backtrace_silencers.rb' - - 'config/initializers/assets.rb' - - 'config/initializers/new_framework_defaults.rb' + - 'config/spring.rb' + - 'config/initializers/*' - 'app/helpers/application_helper.rb' - 'db/**/*' - 'bin/*' @@ -26,4 +22,39 @@ Metrics/AbcSize: Max: 20 Metrics/MethodLength: CountComments: false - Max: 15 + Max: 20 +Metrics/ModuleLength: + Exclude: + - "**/*_spec.rb" + - "app/helpers/users_helper.rb" +Metrics/AbcSize: + Enabled: false +Metrics/BlockLength: + Enabled: false +Style/SymbolArray: + Enabled: false +Style/ClassAndModuleChildren: + Enabled: false +Date: + Enabled: false +ParenthesesAsGroupedExpression: + Enabled: false +Metrics/ClassLength: + Enabled: false +Lint/HandleExceptions: + Enabled: false +Rails/FindEach: + Enabled: false +Style/FrozenStringLiteralComment: + Enabled: false +Documentation: + Enabled: false +CyclomaticComplexity: + Enabled: false +Rails/Delegate: + Description: 'Prefer delegate method for delegations.' + Enabled: false +Rails/HasAndBelongsToMany: + Description: 'Prefer has_many :through to has_and_belongs_to_many.' + StyleGuide: 'https://github.com/bbatsov/rails-style-guide#has-many-through' + Enabled: false diff --git a/.ruby-version b/.ruby-version index 4805492..01f9bd9 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.3.1@aindia +ruby-2.4.0@aindia diff --git a/Gemfile b/Gemfile index a8d9cc9..67bad24 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,9 @@ +# frozen_string_literal: true. + source 'https://rubygems.org' git_source(:github) do |repo_name| - repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") + repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?('/') "https://github.com/#{repo_name}.git" end @@ -20,6 +22,8 @@ gem 'omniauth' gem 'omniauth-facebook' gem 'rails', '~> 5.0.2' gem 'sass-rails', '~> 5.0' +gem 'turbolinks' +gem 'tzinfo-data' gem 'uglifier', '>= 1.3.0' gem 'will_paginate', '3.1.0' @@ -37,3 +41,8 @@ group :development do gem 'spring-watcher-listen' gem 'web-console' end + +group :test do + gem 'factory_girl_rails' + gem 'faker' +end diff --git a/Gemfile.lock b/Gemfile.lock index 9ebde6e..f92252a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -67,6 +67,13 @@ GEM erubis (2.7.0) excon (0.55.0) execjs (2.7.0) + factory_girl (4.8.0) + activesupport (>= 3.0.0) + factory_girl_rails (4.8.0) + factory_girl (~> 4.8.0) + railties (>= 3.0.0) + faker (1.7.3) + i18n (~> 0.5) faraday (0.11.0) multipart-post (>= 1.2, < 3) ffi (1.9.18) @@ -348,8 +355,13 @@ GEM thread_safe (0.3.6) tilt (2.0.7) trollop (2.1.2) + turbolinks (5.0.1) + turbolinks-source (~> 5) + turbolinks-source (5.0.3) tzinfo (1.2.3) thread_safe (~> 0.1) + tzinfo-data (1.2017.2) + tzinfo (>= 1.0.0) uglifier (3.2.0) execjs (>= 0.3.0, < 3) unicode-display_width (1.2.1) @@ -373,6 +385,8 @@ DEPENDENCIES byebug carrierwave (= 0.11.2) dotenv-rails + factory_girl_rails + faker fog (= 1.38.0) haml jbuilder (~> 2.5) @@ -390,6 +404,8 @@ DEPENDENCIES simplecov spring spring-watcher-listen + turbolinks + tzinfo-data uglifier (>= 1.3.0) web-console will_paginate (= 3.1.0) diff --git a/README.md b/README.md index 9b945f9..ed2faaa 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,31 @@ ## About -“Adopt India” is to connect people who are socially responsible and to support and encourage civic participation in solving social issues. http://adoptindia.org/ +Social Quora is to connect people who are socially responsible and to support and encourage civic participation in solving social issues. http://adoptindia.org/ ## Developer Notes -Ruby Version - 2.4.0 -Rails Version - 5.1.0 +## How to run the app locally? +Install the right ruby and rails versions - 2.4.0 (ruby) with rvm +`rvm install 2.4.0` + +`gem install bundler` to install the bundler gem. +`bundle install` to install the gems for the project. +`bundle exec rake db:create` to create the local database +`bundle exec rake db:migrate` to migrate +`bundle exec rake db:seed` to populate an initial list of social interests. + +`bundle exec rails s` to start the server on port 3000 + + ## Deployment Steps * Run "bundle install" to install the dependencies. * Run "rails s" to install the app on local host. -* Run "rails db:migrate" +* Run "rails db:migrate" * Run "rails db:seed" -## Test Steps +## Test Steps * TODO - diff --git a/app/.DS_Store b/app/.DS_Store new file mode 100644 index 0000000..4e15090 Binary files /dev/null and b/app/.DS_Store differ diff --git a/app/assets/stylesheets/custom.scss b/app/assets/stylesheets/custom.scss index 823f59c..212192c 100644 --- a/app/assets/stylesheets/custom.scss +++ b/app/assets/stylesheets/custom.scss @@ -29,7 +29,8 @@ $navbar-inverse-bg: $theme-color; } body { - padding-top: 80px + padding-top: 80px; + background-color: #EEE; } .app { @@ -73,7 +74,7 @@ h3 { font-size: 1.2em; text-align: left; font-weight: bold; - margin-bottom: -15px + // margin-bottom: -15px } // button @@ -83,27 +84,97 @@ button { opacity: 1.0 } -material-icons { - font-family: 'Material Icons'; +/* issues */ + +.issues { + list-style: none; + padding: 0; + li { + padding: 10px; + border-top: 1px solid #e8e8e8; + } + .user { + margin-top: 5em; + padding-top: 0; + } + .content { + display: block; + margin-left: 2px; + margin-top: 35px; + margin-bottom: 10px; + img { + display: block; + padding: 5px 0; + } + } + .timestamp { + color: $gray-light; + display: block; + margin-left: 2px; + } + .gravatar { + float: left; + margin-right: 10px; + margin-top: 5px; + } +} + +.card { + margin-top: 10px; + padding: 20px; + border: 0.1px solid #ddd; + border-radius: 5px; + background-color: #ffffff; +} + +aside { + textarea { + height: 100px; + margin-bottom: 5px; + } +} + +span.picture { + margin-top: 10px; + input { + border: 0; + } +} + +.chip { + display: inline-block; + padding: 0 25px; + height: 26px; + font-size: 12px; + line-height: 26px; + border-radius: 10px; + background-color: #f1f1f1; + border-width: thick; +} + +.edit-icon { + font-size: 20px; + color: gray; + margin-left: 20px; +} + +.edit-icon:hover { + text-decoration: none; +} + +.support-button { + font-size: 15px; + color: gray; + margin: 5px; +} + +.supported-button { + font-size: 15px; + color: blue; font-weight: bold; - font-style: normal; - font-size: 24px; /* Preferred icon size */ - display: inline-block; - line-height: 1; - text-transform: none; - letter-spacing: normal; - word-wrap: normal; - white-space: nowrap; - direction: ltr; - - /* Support for all WebKit browsers. */ - -webkit-font-smoothing: antialiased; - /* Support for Safari and Chrome. */ - text-rendering: optimizeLegibility; - - /* Support for Firefox. */ - -moz-osx-font-smoothing: grayscale; - - /* Support for IE. */ - font-feature-settings: 'liga'; + margin: 5px; +} + +.button_to { + display: inline; } diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb index d672697..9aec230 100644 --- a/app/channels/application_cable/channel.rb +++ b/app/channels/application_cable/channel.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ApplicationCable class Channel < ActionCable::Channel::Base end diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb index 0ff5442..8d6c2a1 100644 --- a/app/channels/application_cable/connection.rb +++ b/app/channels/application_cable/connection.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ApplicationCable class Connection < ActionCable::Connection::Base end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ab1e4be..e17fe21 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,30 +1,16 @@ +# frozen_string_literal: true + class ApplicationController < ActionController::Base protect_from_forgery with: :exception + before_action :current_user, :verify_user_has_logged_in include SessionsHelper - protected - def current_user - @current_user ||= User.find_by_id(session[:user_id]) - end - - def signed_in? - !!current_user - end + private - helper_method :current_user, :signed_in? - def current_user=(user) - @current_user = user - session[:user_id] = user.id - end - -private # Confirms a logged-in user. - def logged_in_user - unless logged_in? - store_location - flash[:danger] = "Please log in." - redirect_to root_url - end + def verify_user_has_logged_in + return if logged_in? + flash[:danger] = 'Please log in.' + redirect_to root_url end - end diff --git a/app/controllers/concerns/support_issue.rb b/app/controllers/concerns/support_issue.rb new file mode 100644 index 0000000..1893de0 --- /dev/null +++ b/app/controllers/concerns/support_issue.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module SupportIssue + extend ActiveSupport::Concern + + def update_support_issue + issue = Issue.find(params[:issue_id]) + @current_user.update_support_issue(issue) + redirect_to :back + end +end diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 418190e..624d122 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -1,32 +1,62 @@ -class IssuesController < ApplicationController - before_action :logged_in_user, only: [:create, :destroy] - before_action :correct_user, only: :destroy +# frozen_string_literal: true +class IssuesController < ApplicationController + before_action :verify_current_user_is_owner, only: %i[destroy edit update] def new @issue = Issue.new end def create - byebug @issue = current_user.issues.build(issue_params) + @issue.attributes = { + 'social_interest_ids' => [] + }.merge(params[:issue] || {}) + if @issue.save - flash[:success] = "Issue created!" - redirect_to root_url + flash[:success] = 'Issue created!' + redirect_to user_path(@issue.user) else - @feed_items = [] + render 'new' end end + def destroy + return unless @issue.destroy + flash[:success] = 'Issue deleted' + redirect_to @current_user + end + + def edit; end + + def update + update_attributes + end + private - def issue_params - params.require(:issue).permit(:content, :imageurl, :user_id, :title) - end + def issue_params + params.require(:issue).permit( + %i[content imageurl title impact cost socialinterest_ids] + ) + end - def correct_user - @issue = current_user.issues.find_by(id: params[:id]) - redirect_to root_url if @issue.nil? + def update_attributes + @issue.attributes = { + 'social_interest_ids' => [] + }.merge(params[:issue] || {}) + + if @issue.save + flash[:success] = 'Issue saved!' + redirect_to user_path(@issue.user) + else + render 'edit' end + end + # verifying that the current user is the owner of the issue + def verify_current_user_is_owner + @issue = current_user.issues.find(params[:id]) + redirect_to root_url if @issue.nil? + end end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 44eb8b6..0f1c039 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,24 +1,17 @@ +# frozen_string_literal: true + class SessionsController < ApplicationController + skip_before_action :verify_user_has_logged_in, except: [:destroy] + skip_before_action :current_user, except: [:destroy] + def create - user = User.from_omniauth(request.env["omniauth.auth"]) + user = User.from_omniauth(request.env['omniauth.auth']) log_in(user) - #session[:user_id] = user.id - #redirect_to root_path - redirect_to user + redirect_to root_path end def destroy log_out if logged_in? redirect_to root_url end - end - -# auth = request.env['omniauth.auth'] -# unless @auth = Authorization.find_from_hash(auth) -# # Create a new user or add an auth to existing user, depending on -# # whether there is already a user signed in. -# @auth = Authorization.create_from_hash(auth, current_user) -# end -# # Log the authorizing user in. -# self.current_user = @auth.user diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb new file mode 100644 index 0000000..b812b54 --- /dev/null +++ b/app/controllers/static_pages_controller.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class StaticPagesController < ApplicationController + include SupportIssue + skip_before_action :verify_user_has_logged_in + + def home + @feed_items = @current_user.issues_based_on_my_interests if logged_in? + end + + def help; end + + def contact; end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 40c9226..10e9ecc 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,25 +1,26 @@ +# frozen_string_literal: true + class UsersController < ApplicationController - before_action :redirect_if_logged_in, only: [:new, :create] + include SupportIssue - include UsersHelper + before_action :redirect_if_logged_in, only: %i[new create] + skip_before_action :verify_user_has_logged_in, except: [:show] + before_action :set_user, only: [:show] + # TODO + # before_action :verify_correct_user, except: [:interests] def new - if logged_in? - redirect_to user - end + redirect_to user if logged_in? end def show - @user = User.find(params[:id]) + @issues = @user.issues.paginate(page: params[:page]) end - def edit - @user = User.find(params[:id]) - end + def edit; end def update - @user = User.find(params[:id]) - if @user.update_attributes(user_params) + if @current_user.update_attributes(user_params) # Handle a successful update. else render 'edit' @@ -31,21 +32,35 @@ def update def destroy user = User.find(params[:id]) user.destroy - flash[:success] = "User deleted" + flash[:success] = 'User deleted' + redirect_to users_url end - def interests - @user = User.find(params[:id]) + def interests; end + + def update_follow_interests + interest = SocialInterest.find(params[:interest_id]) + @current_user.update_follow_interests(interest) + redirect_to :back end -private -def user_params - params.require(:user).permit(:name, :uid, :provider, :oauth_token, :oauth_expires_at, :email, :image_url, :dob, :gender) -end + private -def redirect_if_logged_in - redirect_to @current_user if logged_in? -end + def set_user + @user = User.find(params[:id]) + end + + def user_params + params.require(:user).permit( + %i[ + name uid provider oauth_token oauth_expires_at email + image_url dob gender + ] + ) + end + def redirect_if_logged_in + redirect_to @current_user if logged_in? + end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 08c59fa..c2bbb8e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + module ApplicationHelper -def full_title(page_title = '') - base_title = "Adopt India" - if page_title.empty? - base_title - else - page_title + " | " + base_title + def full_title(page_title = '') + base_title = "Social Quora" + if page_title.empty? + base_title + else + page_title + " | " + base_title + end end end -end diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index bfb9d25..fd90767 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + module IssuesHelper end diff --git a/app/helpers/sessions_helper.rb b/app/helpers/sessions_helper.rb index 05c1616..b3a4d65 100644 --- a/app/helpers/sessions_helper.rb +++ b/app/helpers/sessions_helper.rb @@ -1,60 +1,30 @@ -module SessionsHelper - -def log_in(user) - session[:user_id] = user.id -end +# frozen_string_literal: true -# Remembers a user in a persistent session. -def remember(user) - user.remember - cookies.permanent.signed[:user_id] = user.id - cookies.permanent[:remember_token] = user.remember_token -end +module SessionsHelper + def log_in(user) + session[:user_id] = user.id + current_user + end -# Forgets a persistent session. -def forget(user) - user.forget - cookies.delete(:user_id) - cookies.delete(:remember_token) -end + # Returns true if the user is logged in, false otherwise. + def logged_in? + @current_user.present? + end -# Returns true if the given user is the current user. -def current_user?(user) - user == current_user -end + # Returns true if the given user is the current user. + def current_user?(user) + user == current_user + end -def current_user - if (user_id = session[:user_id]) + def current_user + return if session[:user_id].nil? + user_id = session[:user_id] @current_user ||= User.find_by(id: user_id) - elsif (user_id = cookies.signed[:user_id]) - user = User.find_by(id: user_id) - if user && user.authenticated?(:remember, cookies[:remember_token]) - log_in user - @current_user = user - end end -end - -# Returns true if the user is logged in, false otherwise. -def logged_in? - !current_user.nil? -end - -def log_out -# forget(current_user) - session.delete(:user_id) - @current_user = nil -end - -# Redirects to stored location (or to the default). -def redirect_back_or(default) - redirect_to(session[:forwarding_url] || default) - session.delete(:forwarding_url) -end - -# Stores the URL trying to be accessed. -def store_location - session[:forwarding_url] = request.original_url if request.get? -end + def log_out + # forget(current_user) + session.delete(:user_id) + @current_user = nil + end end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index cd56871..366cb96 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -1,22 +1,10 @@ +# frozen_string_literal: true + require 'yaml' module UsersHelper - def image_for(user, size: 60) - if user.image_url - imageurl = "https://sports.ndtv.com/cricket/teams/6-india-teamprofile?s=#{size}" - image_tag(imageurl, alt: user.name, class: "gravatar") - end - end - - def parse_yaml_file - ret = [] - byebug - data = YAML.load_file 'config/socialinterests.yml' - puts(data) - data['socialinterests'].each do |hash| - ret << SocialInterest.new(hash) - end - puts("Social interests count: #{ret.count}") - ret + def image_for(user) + image_tag(user.image_url, alt: user.name, class: 'gravatar') if + user.image_url end end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index a009ace..d92ffdd 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class ApplicationJob < ActiveJob::Base end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 286b223..d84cb6e 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationMailer < ActionMailer::Base default from: 'from@example.com' layout 'mailer' diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 10a4cba..71fbba5 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationRecord < ActiveRecord::Base self.abstract_class = true end diff --git a/app/models/authorization.rb b/app/models/authorization.rb deleted file mode 100644 index 39da442..0000000 --- a/app/models/authorization.rb +++ /dev/null @@ -1,14 +0,0 @@ -class Authorization < ApplicationRecord - belongs_to :user - validates :user_id, :uid, :provider, presence: true - validates_uniqueness_of :uid, :scope => :provider -end - -def self.find_from_hash(hash) - find_by_provider_and_uid(hash['provider'], hash['uid']) -end - -def self.create_from_hash(hash, user = nil) - user ||= User.create_from_hash!(hash) - Authorization.create(user: user, uid: hash['uid'], provider: hash['provider']) -end diff --git a/app/models/issue.rb b/app/models/issue.rb index 5bf087f..78878a1 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -1,8 +1,27 @@ +# frozen_string_literal: true + class Issue < ApplicationRecord belongs_to :user + # TODO: belongs_to :leader, :class_name => "User" + default_scope -> { order(created_at: :desc) } mount_uploader :imageurl, PictureUploader + validates :user_id, presence: true validates :title, presence: true, length: { maximum: 140 } - validates :content, presence: true, length: { maximum: 140 } + validates :content, presence: true, length: { maximum: 20_000 } + + has_and_belongs_to_many :social_interests, class_name: 'SocialInterest' + has_and_belongs_to_many :supported_users, class_name: 'User' + + def supported_by_user?(suser) + supported_users.include?(suser) + end + + def supported_users_count + supported_users.count + end end + + + diff --git a/app/models/social_interest.rb b/app/models/social_interest.rb index 0565cf6..c8b5f43 100644 --- a/app/models/social_interest.rb +++ b/app/models/social_interest.rb @@ -1,12 +1,7 @@ +# frozen_string_literal: true + class SocialInterest < ApplicationRecord - attr_accessor :title, :description, :image_url validates :title, presence: true - - def initialize(hash) - hash.each do |k,v| - self.instance_variable_set("@#{k}", v.is_a?(Hash) ? Hashit.new(v) : v) - self.class.send(:define_method, k, proc{self.instance_variable_get("@#{k}")}) - self.class.send(:define_method, "#{k}=", proc{|v| self.instance_variable_set("@#{k}", v)}) - end - end + has_and_belongs_to_many :users + has_and_belongs_to_many :issues end diff --git a/app/models/user.rb b/app/models/user.rb index 40e8331..a905a0a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,20 +1,126 @@ +# frozen_string_literal: true + class User < ApplicationRecord - has_many :issues, dependent: :destroy + has_many :issues, dependent: :destroy # created issues + has_and_belongs_to_many :social_interests, class_name: 'SocialInterest' + validates :name, presence: true + validates :email, presence: true + validates :oauth_token, presence: true + # TODO: validates :name, :email, :oauth_token, presence: true + has_and_belongs_to_many :supported_issues, class_name: 'Issue' + # supported issues -def self.from_omniauth(auth) - #where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user| - where(provider: auth.provider, uid: auth.uid).first_or_initialize do |user| + def self.from_omniauth(auth) + # where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user| + where(provider: auth.provider, uid: auth.uid).first_or_initialize do |user| + user.save_from_auth(auth) + user.save! + end + end - user.provider = auth.provider - user.uid = auth.uid - user.name = auth.info.name - user.oauth_token = auth.credentials.token - user.oauth_expires_at = Time.at(auth.credentials.expires_at) - user.image_url = auth.info.image - user.email = auth.info.email - user.save! + def save_from_auth(auth) + self.provider = auth.provider + self.uid = auth.uid + self.name = auth.info.name + self.oauth_token = auth.credentials.token + self.oauth_expires_at = Time.zone.at(auth.credentials.expires_at) + self.image_url = auth.info.image + self.email = auth.info.email + end + + # Following Interests methods + def following?(social_interest) + social_interests.include?(social_interest) + end + + def update_follow_interests(social_interest) + if following?(social_interest) + unfollow_interest(social_interest) + else + follow_interest(social_interest) + end + # TODO: following?(social_interest) ? unfollow_interest(social_interest) : follow_interest(social_interest) + end + + def follow_interest(social_interest) + social_interests << social_interest + end + + def unfollow_interest(social_interest) + social_interests.delete(social_interest) + end + + # Support Issue methods + + def supporting?(issue) + supported_issues.include?(issue) + end + + def update_support_issue(issue) + if supporting?(issue) + unsupport_issue(issue) + else + support_issue(issue) + end + # TODO: Convert to a tertiary + end + + def support_issue(issue) + supported_issues << issue + end + + def unsupport_issue(issue) + supported_issues.delete(issue) + end + + # TODO: Make this code work +=begin + def ordered_relevant_issues + social_interests.collect {|si| si.issues}.flatten.uniq.order_by(:created_at) + end +=end + + def issues_based_on_my_interests + if social_interests.count.positive? + Issue.includes(:social_interests).where(social_interests: + { + id: social_interests.pluck(:id) + }) + else + Issue.all + end end -end end + + +=begin +Where to put the methods? +@user.relevant_issues +Issue.relevent_issues(user) + +TDD +Describe user + 'I should see my relevant issues' do + @user = User.find(...) + @user.si = 'Cleanliness' + + @issue = Issue.create(tag: 'Cleanliness', ...) + + @user.relevant_issues.should include(@issue) + + @user.relevant_issues.should include(@issue) + + + + end + +Issue.relevant_issues(user, location_of_user, ...) +1) look at si +2) look at the radius of hte user. + +ReleventIssues.compute(user, + + +=end diff --git a/app/uploaders/picture_uploader.rb b/app/uploaders/picture_uploader.rb index 217f662..59a4464 100644 --- a/app/uploaders/picture_uploader.rb +++ b/app/uploaders/picture_uploader.rb @@ -1,14 +1,19 @@ +# frozen_string_literal: true + # encoding: utf-8 class PictureUploader < CarrierWave::Uploader::Base - # Include RMagick or MiniMagick support: # include CarrierWave::RMagick - # include CarrierWave::MiniMagick + include CarrierWave::MiniMagick + process resize_to_limit: [400, 400] # Choose what kind of storage to use for this uploader: - storage :file - # storage :fog + if Rails.env.production? + storage :fog + else + storage :file + end # Override the directory where uploaded files will be stored. # This is a sensible default for uploaders that are meant to be mounted: @@ -19,7 +24,8 @@ def store_dir # Provide a default URL as a default if there hasn't been a file uploaded: # def default_url # # For Rails 3.1+ asset pipeline compatibility: - # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) + # # ActionController::Base.helpers.asset_path("fallback/" + + # [version_name, "default.png"].compact.join('_')) # # "/images/fallback/" + [version_name, "default.png"].compact.join('_') # end @@ -38,14 +44,14 @@ def store_dir # Add a white list of extensions which are allowed to be uploaded. # For images you might use something like this: - # def extension_white_list - # %w(jpg jpeg gif png) - # end + def extension_white_list + %w[jpg jpeg gif png] + end # Override the filename of the uploaded files: - # Avoid using model.id or version_name here, see uploader/store.rb for details. + # Avoid using model.id or version_name here, + # see uploader/store.rb for details. # def filename # "something.jpg" if original_filename # end - end diff --git a/app/views/.DS_Store b/app/views/.DS_Store new file mode 100644 index 0000000..4cc6e3a Binary files /dev/null and b/app/views/.DS_Store differ diff --git a/app/views/issues/_newform.html.haml b/app/views/issues/_newform.html.haml index c9b5135..497e9cb 100644 --- a/app/views/issues/_newform.html.haml +++ b/app/views/issues/_newform.html.haml @@ -1,20 +1,26 @@ = form_for(issue) do |f| - - if issue.errors.any? - #error_explanation - %h2 - = pluralize(issue.errors.count, "error") - prohibited this issue from being saved: - %ul - - issue.errors.full_messages.each do |message| - %li= message .form-group - = f.label :title - = f.text_field :title, class: 'form-control' + = render 'shared/error_messages', object: f.object + .form-group - = f.label :content - = f.text_area :content, class: 'form-control' + - SocialInterest.all.each do |sinterest| + %label.checkbox-inline + = check_box_tag :social_interest_ids, sinterest.id, @issue.social_interests.include?(sinterest), :name => "issue[social_interest_ids][]" + = sinterest.title + .form-group + = f.label :title + = f.text_field :title, maxlength: 80, class: 'form-control' .form-group %span.picture = f.file_field :imageurl .form-group - = submit_tag 'Create Issue', class: "btn btn-primary" + = f.label :content + = f.text_area :content, maxlength: 20000, :rows => 8, style: 'width:100%;', class: 'form-control' + .form-group + = f.label :impact + = f.text_field :impact, class: 'form-control' + .form-group + - if @issue.id.nil? + = submit_tag 'Post', class: "btn btn-primary pull-right" + - else + = submit_tag 'Update', class: "btn btn-primary pull-right" diff --git a/app/views/issues/edit.html.haml b/app/views/issues/edit.html.haml new file mode 100644 index 0000000..ade43da --- /dev/null +++ b/app/views/issues/edit.html.haml @@ -0,0 +1,3 @@ +.col-md-8.col-md-offset-1 + %h1 Edit Cause + = render 'newform', issue: @issue diff --git a/app/views/issues/new.html.haml b/app/views/issues/new.html.haml index 2bf2b25..1642a1b 100644 --- a/app/views/issues/new.html.haml +++ b/app/views/issues/new.html.haml @@ -1,3 +1,3 @@ -%h1 New Issue -= render 'newform', issue: @issue -= link_to 'Back', root_path +.col-md-8.col-md-offset-1 + %h1 New Cause + = render 'newform', issue: @issue diff --git a/test/controllers/.keep b/app/views/issues/show.html.haml similarity index 100% rename from test/controllers/.keep rename to app/views/issues/show.html.haml diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 6004942..2254eff 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -4,12 +4,15 @@