Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heroku #3

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,19 @@
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
logfile

.DS_Store

# Ignore all photos previously added.
/public/cinemagraph_storage/*
/public/system/*

coverage
ngrok

/coverage/.resultset.json
/coverage/.last_run.json

*.rvmrc*
/.rvmrc.*
.ruby-version
6 changes: 4 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ gem 'rails', '3.2.11'
gem 'pg'
gem 'jquery-rails'
gem 'bcrypt-ruby', '~> 3.0.0'
gem 'mini_magick'
gem 'paperclip'
gem 'aws-sdk'
gem 'pry'

group :assets do
gem 'sass-rails', '~> 3.2.3'
Expand All @@ -13,7 +15,7 @@ group :assets do
end

group :test, :development do
gem "rspec-rails", "~> 2.0"
gem 'rspec-rails', '~> 2.0'
gem 'shoulda'
gem 'capybara'
gem 'factory_girl_rails'
Expand Down
28 changes: 24 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ GEM
i18n (~> 0.6)
multi_json (~> 1.0)
arel (3.0.2)
aws-sdk (1.11.1)
json (~> 1.4)
nokogiri (>= 1.4.4)
uuidtools (~> 2.1)
bcrypt-ruby (3.0.1)
builder (3.0.4)
capybara (2.1.0)
Expand All @@ -48,6 +52,11 @@ GEM
xpath (~> 2.0)
childprocess (0.3.9)
ffi (~> 1.0, >= 1.0.11)
climate_control (0.0.3)
activesupport (>= 3.0)
cocaine (0.5.3)
climate_control (>= 0.0.3, < 1.0)
coderay (1.0.9)
database_cleaner (1.1.1)
diff-lcs (1.2.4)
erubis (2.7.0)
Expand All @@ -71,15 +80,23 @@ GEM
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
method_source (0.8.2)
mime-types (1.25)
mini_magick (3.6.0)
subexec (~> 0.2.1)
mini_portile (0.5.1)
multi_json (1.8.0)
nokogiri (1.6.0)
mini_portile (~> 0.5.0)
paperclip (3.5.2)
activemodel (>= 3.0.0)
activesupport (>= 3.0.0)
cocaine (~> 0.5.3)
mime-types
pg (0.17.0)
polyglot (0.3.3)
pry (0.9.12.2)
coderay (~> 1.0.5)
method_source (~> 0.8)
slop (~> 3.4)
rack (1.4.5)
rack-cache (1.2)
rack (>= 0.4)
Expand Down Expand Up @@ -137,12 +154,12 @@ GEM
multi_json (~> 1.0)
simplecov-html (~> 0.7.1)
simplecov-html (0.7.1)
slop (3.4.6)
sprockets (2.2.2)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
subexec (0.2.3)
thor (0.18.1)
tilt (1.4.1)
treetop (1.4.15)
Expand All @@ -152,6 +169,7 @@ GEM
uglifier (2.2.1)
execjs (>= 0.3.0)
multi_json (~> 1.0, >= 1.0.2)
uuidtools (2.1.4)
websocket (1.0.7)
xpath (2.0.0)
nokogiri (~> 1.3)
Expand All @@ -161,14 +179,16 @@ PLATFORMS

DEPENDENCIES
anjlab-bootstrap-rails!
aws-sdk
bcrypt-ruby (~> 3.0.0)
capybara
database_cleaner
factory_girl_rails
faker
jquery-rails
mini_magick
paperclip
pg
pry
rails (= 3.2.11)
rspec-rails (~> 2.0)
sass-rails (~> 3.2.3)
Expand Down
33 changes: 3 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,5 @@
#CineHerd
team: Dan, Lloyd, Luisa, Chae
#[CineHerd](http://calm-meadow-5876.herokuapp.com/)

Our [trello board](https://trello.com/b/1ObtqHqL/stackexchange) is hosted at: https://trello.com/b/1ObtqHqL/stackexchange

Please take a second to look over all of our cards and comments—

We'd like to add response functionality for our posts. There's a small catch—our schema is such that responses and posts are designed to be the same object. The main post for any given thread should have a parent_id and a root_id attribute that are set to nil.

Any direct responses to that post (say, the post with post_id of 1) should have a root_id and parent_id set to reference that post (1). (Let's assume our response has a post_id of 2)

Any comments to THAT response should have a parent_id set to reference the response's post_id (2) and a root_id set to the post_id of the root post (1).

POST 1 (ROOT)
post_id: 1
root_id: nil
parent_id: nil

POST 2 (DIRECT RESPONSE)
post_id: 2
root_id: 1
parent_id: 1

POST 3 (COMMENT TO DIRECT RESPONSE)
post_id: 3
root_id: 1
parent_id: 2

User signup page exists, but it isn't currently linked to from the root or navbar. Navigate directly there with:

localhost:3000/users/new
[http://calm-meadow-5876.herokuapp.com/](http://calm-meadow-5876.herokuapp.com/)

Weekend DBC project created by [Dan](https://github.com/danapczynski), [Chae](https://github.com/ChaeOkay), [Luisa](https://github.com/LBeck), and [Lloyd](https://github.com/llnimetz)
34 changes: 28 additions & 6 deletions app/assets/javascripts/post.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
$(document).ready(function(){

var SubmitPost = function() {
}

SubmitPost.prototype.afterSubmit = function() {
$("#new_post_form").on('ajax:success', function(xhr, settings){
displayLoadingAnimation()
}).on('ajax:complete', function(e, data, status, xhr){
console.log(data)
})
})
}

var Arrows = function(images){
this.arrowImages = images
this.dissableButton = $('#sign_in')
}

function displayLoadingAnimation() {
$("#new_post_button").removeClass('btn-primary').addClass('btn-danger')
$("#new_post_button").val('Uploading Cinemagraph...')
}
Arrows.prototype.disable = function(){
if (this.dissableButton.length > 0)
{
$.each(this.arrowImages, function(index, value){
$(value).attr('onClick', 'return false')
})
}
}


$(document).ready(function(){
newPost = new SubmitPost()
newPost.afterSubmit()

arrowImages = new Arrows($('i'))
arrowImages.disable()
})
1 change: 0 additions & 1 deletion app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
class PostsController < ApplicationController

def index
#@vote = Vote.index
@posts = Post.all
end

Expand Down
67 changes: 5 additions & 62 deletions app/models/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,11 @@ class Post < ActiveRecord::Base
belongs_to :user
has_many :votes, :as => :votable
has_many :comments
attr_accessible :content, :title, :user, :cinemagraph, :extension
validates_presence_of :content, :title, :user, :extension
validates_uniqueness_of :title

after_save :store_cinemagraph

include MiniMagick

def cinemagraph=(file_data)
unless file_data.blank?
@file_data = file_data
self.extension = file_data.original_filename.split('.').last.downcase
end
end

def cinemagraph_filename
File.join(CINEMAGRAPH_STORAGE, "#{self.id}.#{self.extension}")
end

def cinemagraph_still_filename
File.join(CINEMAGRAPH_STORAGE, "#{self.id}_still.#{self.extension}")
end

def cinemagraph_path
"/cinemagraph_storage/#{self.id}.#{self.extension}"
end

def cinemagraph_still_path
"/cinemagraph_storage/#{self.id}_still.#{self.extension}"
end
attr_accessible :content, :title, :user, :cinemagraph
has_attached_file :cinemagraph, :styles => { :medium => "600x400>"}

def has_cinemagraph?
File.exists?(cinemagraph_filename)
end

CINEMAGRAPH_STORAGE = File.join(Rails.root, 'public', 'cinemagraph_storage')

private

def store_cinemagraph
if @file_data
FileUtils.mkdir_p CINEMAGRAPH_STORAGE
File.open(cinemagraph_filename, 'wb') do |f|
f.write(@file_data.read)
end
resize_cinemagraph(cinemagraph_filename)
create_still(cinemagraph_filename)
@file_data = nil
end
end

def resize_cinemagraph(cinemagraph_filename)
image = MiniMagick::Image.open(cinemagraph_filename)
image.coalesce
image.resize("600x400")
image.write(cinemagraph_filename)
end

def create_still(cinemagraph_filename)
image = MiniMagick::Image.open(cinemagraph_filename)
image.collapse!
image.colorspace("Gray")
image.write(cinemagraph_still_filename)
end
#add paperclip validations for content type, size, attachment presence
validates_presence_of :content, :title, :user
validates_uniqueness_of :title
end
12 changes: 6 additions & 6 deletions app/views/pages/about.html.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<h2>CineHerd <span class="about_text1" >(pronounced <en>"seen-heard"</en>)</span>
</h2>
<h4>...the easiest way to share & find the world's best Cinemagraphs.
</h4>
</h2>

<h4>...the easiest way to share & find the world's best Cinemagraphs.</h4>
<hr>
<div class="about_body">
<p class="about_h4">The Cinemagraph is the photograph of the future. It captures one single moment in time but with some extra, subtle flare that brings that moment alive more than a photograph ever could!
<p class="about_h4">The Cinemagraph is the photograph of the future. It captures one single moment in time but with some extra, subtle flare that brings that moment alive more than a photograph ever could!
</p>

<p class="about_h4">Dan, Lloyd, Chae and Luisa were searching for cinemagraphs online one day and realized that there wasn't yet a site that made them it easy to find. So we decided to build our own, tapping into the power of crowdsourcing and the social wed (a.k.a. 'herds') to do so.</p>
<p class="about_h4"><%= link_to "Dan", "https://github.com/danapczynski" %>, <%= link_to "Chae", "https://github.com/ChaeOkay" %>, <%= link_to "Lloyd", "https://github.com/llnimetz" %>, and <%= link_to "Luisa", "https://github.com/LBeck" %> were searching for cinemagraphs online one day and realized that there wasn't yet a site that made them it easy to find. So we decided to build our own, tapping into the power of crowdsourcing and the social wed (a.k.a. 'herds') to do so.</p>

<p>We built this app in just a few days and plan to add features so stay tuned for updates.
<p>We built this app in just a few days and plan to add features so stay tuned for updates.
</p>
</div>
4 changes: 1 addition & 3 deletions app/views/posts/_formroot.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<div class ="col-md-5 col-md-offset-3" >


<h1 class = "form-heading"> Contribute to the Herd: </h1>
<%= form_for @post, :remote => true, :html => { :id => 'new_post_form', :class => "form-group" } do |f| %>

<%= form_for @post, :remote => true, :html => { :multipart => true } do |f| %>
<%= f.text_field :title, :placeholder => "Title", :class => "form-control" %><br>
<%= f.text_field :content, :placeholder => "Description", :class => "form-control" %><br>
<%= f.file_field :cinemagraph, :placeholder => "Cinemagraph", :class => "form-control", :id => "file_uploader" %><br>
Expand Down
2 changes: 1 addition & 1 deletion app/views/posts/_show2.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<ul>
<div class="cinemagraph-comment">
<% if @post.has_cinemagraph? %>
<%= image_tag @post.cinemagraph_path %>
<%= image_tag @post.cinemagraph.url(:medium) %>
<% else %>
<p>No cinemagraph found. Boo.</p>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/posts/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<% @posts.each do |post| %>

<div class="cinemagraph">
<%= image_tag post.cinemagraph_still_path, :class => "still_photo" %>
<%= image_tag post.cinemagraph.url(:medium), :class => "still_photo" %>
<div class='post-description'>

<h2><%= link_to post.title, post_path(post) %></h2>
Expand Down
4 changes: 2 additions & 2 deletions app/views/posts/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<ul>
<div class="cinemagraph-comment">
<% if @post.has_cinemagraph? %>
<%= image_tag @post.cinemagraph_path %>
<% if @post.cinemagraph %>
<%= image_tag @post.cinemagraph.url(:medium) %>
<% else %>
<p>No cinemagraph found. Boo.</p>
<% end %>
Expand Down
10 changes: 10 additions & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,14 @@
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
# config.active_record.auto_explain_threshold_in_seconds = 0.5

# Paperclip
config.paperclip_defaults = {
:storage => :s3,
:s3_credentials => {
:bucket => ENV['AWS_BUCKET_NAME'],
:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
}
}
end
9 changes: 9 additions & 0 deletions db/migrate/20131026150129_remove_extension_to_posts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class RemoveExtensionToPosts < ActiveRecord::Migration
def up
remove_column :posts, :extension
end

def down
add_column :posts, :extension, :string
end
end
11 changes: 11 additions & 0 deletions db/migrate/20131026192026_add_attachment_cinemagraph_to_posts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class AddAttachmentCinemagraphToPosts < ActiveRecord::Migration
def self.up
change_table :posts do |t|
t.attachment :cinemagraph
end
end

def self.down
drop_attached_file :posts, :cinemagraph
end
end
Loading