-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Blair Anderson
committed
Feb 18, 2015
1 parent
f4598ae
commit bdd77e9
Showing
62 changed files
with
1,009 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// This is a manifest file that'll be compiled into application.js, which will include all the files | ||
// listed below. | ||
// | ||
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, | ||
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path. | ||
// | ||
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the | ||
// compiled file. | ||
// | ||
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details | ||
// about supported directives. | ||
// | ||
//= require jquery | ||
//= require jquery_ujs | ||
//= require turbolinks | ||
//= require_tree . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Place all the behaviors and hooks related to the matching controller here. | ||
// All this logic will automatically be available in application.js. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Place all the behaviors and hooks related to the matching controller here. | ||
// All this logic will automatically be available in application.js. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Place all the behaviors and hooks related to the matching controller here. | ||
// All this logic will automatically be available in application.js. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Place all the behaviors and hooks related to the matching controller here. | ||
// All this logic will automatically be available in application.js. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* This is a manifest file that'll be compiled into application.css, which will include all the files | ||
* listed below. | ||
* | ||
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, | ||
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path. | ||
* | ||
* You're free to add application-wide styles to this file and they'll appear at the bottom of the | ||
* compiled file so the styles you add here take precedence over styles defined in any styles | ||
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new | ||
* file per style scope. | ||
* | ||
*= require_tree . | ||
*= require_self | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place all the styles related to the item_comments controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place all the styles related to the items controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
body { | ||
background-color: #fff; | ||
color: #333; | ||
font-family: verdana, arial, helvetica, sans-serif; | ||
font-size: 13px; | ||
line-height: 18px; | ||
} | ||
|
||
p, ol, ul, td { | ||
font-family: verdana, arial, helvetica, sans-serif; | ||
font-size: 13px; | ||
line-height: 18px; | ||
} | ||
|
||
pre { | ||
background-color: #eee; | ||
padding: 10px; | ||
font-size: 11px; | ||
} | ||
|
||
a { | ||
color: #000; | ||
&:visited { | ||
color: #666; | ||
} | ||
&:hover { | ||
color: #fff; | ||
background-color: #000; | ||
} | ||
} | ||
|
||
div { | ||
&.field, &.actions { | ||
margin-bottom: 10px; | ||
} | ||
} | ||
|
||
#notice { | ||
color: green; | ||
} | ||
|
||
.field_with_errors { | ||
padding: 2px; | ||
background-color: red; | ||
display: table; | ||
} | ||
|
||
#error_explanation { | ||
width: 450px; | ||
border: 2px solid red; | ||
padding: 7px; | ||
padding-bottom: 0; | ||
margin-bottom: 20px; | ||
background-color: #f0f0f0; | ||
h2 { | ||
text-align: left; | ||
font-weight: bold; | ||
padding: 5px 5px 5px 15px; | ||
font-size: 12px; | ||
margin: -7px; | ||
margin-bottom: 0px; | ||
background-color: #c00; | ||
color: #fff; | ||
} | ||
ul li { | ||
font-size: 12px; | ||
list-style: square; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place all the styles related to the UserSessions controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place all the styles related to the users controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class ApplicationController < ActionController::Base | ||
# Prevent CSRF attacks by raising an exception. | ||
# For APIs, you may want to use :null_session instead. | ||
protect_from_forgery with: :exception | ||
|
||
private | ||
def not_authenticated | ||
redirect_to login_path, alert: "Please login first" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
class ItemCommentsController < ApplicationController | ||
before_action :set_item | ||
|
||
def index | ||
@comments = @item.comments.order(created_at: :asc) | ||
end | ||
|
||
def create | ||
@comment = current_user.item_comments.build(comment_params) | ||
if @comment.save | ||
redirect_back_or_to item_path(@item), notice: "Success." | ||
else | ||
redirect_back_or_to item_path(@item), notice: @comment.errors.full_messages.join(". ") | ||
end | ||
end | ||
|
||
def update | ||
end | ||
|
||
def destroy | ||
end | ||
|
||
private | ||
|
||
def set_item | ||
@item = Item.find(params[:item_id]) | ||
return redirect_back_or_to root_path, notice: 'could not find item' unless @item | ||
end | ||
|
||
def comment_params | ||
params.require(:item_comment).permit(:content).merge({item_id: params[:item_id]}) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
class ItemsController < ApplicationController | ||
before_action :require_login, only: [:new, :create, :edit, :update, :toggle] | ||
before_action :set_item, only: [:show] | ||
before_action :set_user_item, only: [:edit, :update, :toggle] | ||
|
||
swagger_controller :items, "Item Management" | ||
|
||
swagger_api :index do | ||
summary "Fetches all Current items" | ||
notes "This lists items" | ||
# param :query, :page, :integer, :optional, "Page number" | ||
# param :path, :nested_id, :integer, :optional, "Team Id" | ||
# response :unauthorized | ||
# response :not_acceptable, "The request you made is not acceptable" | ||
# response :requested_range_not_satisfiable | ||
end | ||
def index | ||
@items = Item.order(score: :desc).includes(:user) | ||
end | ||
|
||
def show | ||
@comments = @item.comments.includes(:user).order(created_at: :asc) | ||
end | ||
|
||
# GET /items/new | ||
def new | ||
@item = Item.new | ||
end | ||
|
||
def edit | ||
end | ||
|
||
def create | ||
@item = current_user.items.build(item_params) | ||
|
||
if @item.save | ||
redirect_to @item, notice: 'Item was successfully created.' | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
def update | ||
if @item.update(item_params) | ||
redirect_to @item, notice: 'Item was successfully updated.' | ||
else | ||
render :edit | ||
end | ||
end | ||
|
||
def toggle | ||
@item.update(:disabled, @item.disabled?) | ||
message = item.disabled? ? 'disabled' : 'enabled' | ||
redirect_to @item, notice: "Item #{message}." | ||
end | ||
|
||
private | ||
def set_item | ||
@item = Item.find(params[:id]) | ||
end | ||
|
||
def set_user_item | ||
@item = current_user.items.find(params[:id]) | ||
return redirect_to :back, notice: 'Unauthorized' unless @item | ||
end | ||
|
||
def item_params | ||
params.require(:item).permit( | ||
:title, | ||
:url | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
class UserItemVotesController < ApplicationController | ||
before_action :set_item | ||
|
||
def create | ||
vote = current_user.votes.build(vote_params) | ||
byebug | ||
if vote.save | ||
redirect_to :back, notice: "Upvoted." | ||
else | ||
redirect_to :back, notice: "Already Upvoted." | ||
end | ||
end | ||
|
||
def destroy | ||
vote = current_user.votes.where(vote_params).first | ||
if vote | ||
vote.destroy | ||
message = 'Removed Vote.' | ||
else | ||
message = 'No vote to remove.' | ||
end | ||
redirect_to :back, notice: message | ||
end | ||
|
||
private | ||
def set_item | ||
@item = Item.find(params[:id]) | ||
unless @item | ||
return redirect_to :back, notice: "Could not find item with #{params[:id]}" | ||
end | ||
end | ||
|
||
def vote_params | ||
{ | ||
votable_id: @item.id, | ||
votable_type: @item.class.to_s | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class UserSessionsController < ApplicationController | ||
before_action :require_login, only: [:destroy] | ||
def new | ||
@user = User.new | ||
end | ||
|
||
def create | ||
if @user = login(login_params[:username], login_params[:password]) | ||
redirect_back_or_to(:users, notice: 'Login successful') | ||
else | ||
flash.now[:alert] = 'Login failed' | ||
render action: 'new' | ||
end | ||
end | ||
|
||
def destroy | ||
logout | ||
redirect_to(:users, notice: 'Logged out!') | ||
end | ||
|
||
private | ||
def login_params | ||
params.require(:login).permit(:username, :password) | ||
end | ||
end |
Oops, something went wrong.