Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ source 'https://rubygems.org'
gem 'rails', '3.2.8'
gem 'pg', '~>0.13.2'
gem 'bourbon', '1.3.6'
gem 'devise'

group :assets do
gem 'sass-rails', '~> 3.2.5'
Expand All @@ -11,7 +12,14 @@ group :assets do
end

group :development do
# WHY DO YOU HAVE SQLITE AS A GEM HERE?
gem 'sqlite3', '1.3.5'
gem 'thin'
end

group :test do
gem 'shoulda'
gem 'database_cleaner'
end

gem 'jquery-rails'
Expand Down
32 changes: 32 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ GEM
i18n (~> 0.6)
multi_json (~> 1.0)
arel (3.0.2)
bcrypt-ruby (3.0.1)
bourbon (1.3.6)
sass (>= 3.1)
bourne (1.4.0)
mocha (~> 0.13.2)
builder (3.0.4)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
Expand All @@ -39,7 +42,15 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.4.0)
daemons (1.1.9)
database_cleaner (0.9.1)
devise (2.2.3)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.1)
railties (~> 3.1)
warden (~> 1.2.1)
erubis (2.7.0)
eventmachine (1.0.3)
execjs (1.4.0)
multi_json (~> 1.0)
hike (1.2.1)
Expand All @@ -53,9 +64,13 @@ GEM
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
metaclass (0.0.1)
mime-types (1.19)
mocha (0.13.3)
metaclass (~> 0.0.1)
multi_json (1.4.0)
nokogiri (1.5.6)
orm_adapter (0.4.0)
pg (0.13.2)
polyglot (0.3.3)
rack (1.4.1)
Expand Down Expand Up @@ -88,11 +103,22 @@ GEM
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
shoulda (3.4.0)
shoulda-context (~> 1.0, >= 1.0.1)
shoulda-matchers (~> 1.0, >= 1.4.1)
shoulda-context (1.1.1)
shoulda-matchers (1.5.6)
activesupport (>= 3.0.0)
bourne (~> 1.3)
sprockets (2.1.3)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.5)
thin (1.5.1)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
thor (0.16.0)
tilt (1.3.3)
treetop (1.4.12)
Expand All @@ -102,17 +128,23 @@ GEM
uglifier (1.3.0)
execjs (>= 0.3.0)
multi_json (~> 1.0, >= 1.0.2)
warden (1.2.1)
rack (>= 1.0)

PLATFORMS
ruby

DEPENDENCIES
bourbon (= 1.3.6)
coffee-rails (~> 3.2.1)
database_cleaner
devise
jquery-rails
nokogiri
pg (~> 0.13.2)
rails (= 3.2.8)
sass-rails (~> 3.2.5)
shoulda
sqlite3 (= 1.3.5)
thin
uglifier (>= 1.0.3)
3 changes: 3 additions & 0 deletions app/assets/javascripts/admin/base.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3 changes: 3 additions & 0 deletions app/assets/javascripts/admin/songs.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/admin/base.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the admin/base controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/admin/songs.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the admin/songs controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
6 changes: 6 additions & 0 deletions app/controllers/admin/base_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Admin::BaseController < ApplicationController
layout "admin"

before_filter :authenticate_admin_user!

end
63 changes: 63 additions & 0 deletions app/controllers/admin/songs_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
class Admin::SongsController < Admin::BaseController
before_filter :prepare_artists, :except => :index
before_filter :prepare_albums, :except => :index

def index
@songs = Song.order(sort_column + ' ' + sort_direction)
end

def new
@song = Song.new
end

def edit
@song = Song.find(params[:id])
end

def create
@song = Song.new(params[:song])
if @song.save
redirect_to admin_songs_url, notice: "Successfully created song."
else
render :new
end
end

def update
@song = Song.find(params[:id])
if @song.update_attributes(params[:song])
redirect_to admin_songs_url, notice: "Successfully updated song."
else
render :edit
end
end

def destroy
@song = Song.find(params[:id])
@song.destroy
respond_to do |format|
format.html { redirect_to admin_songs_url }
format.json { head :no_content }
end
end

private

def sort_column
params[:sort] || "title"
end
helper_method :sort_column

def sort_direction
params[:direction] || "asc"
end
helper_method :sort_direction

def prepare_artists
@artists = Artist.all
end

def prepare_albums
@albums = Album.all
end
end
38 changes: 0 additions & 38 deletions app/controllers/songs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,44 +29,6 @@ def show
@recent_songs = Song.where(published: true).all(order: 'created_at DESC', limit: 12)
end

def admin
@songs = Song.order(sort_column + ' ' + sort_direction)
end

def new
@song = Song.new
end

def edit
@song = Song.find(params[:id])
end

def create
@song = Song.new(params[:song])
if @song.save
redirect_to admin_url, notice: "Successfully created song."
else
render :new
end
end

def update
@song = Song.find(params[:id])
if @song.update_attributes(params[:song])
redirect_to admin_url, notice: "Successfully updated song."
else
render :edit
end
end

def destroy
@song = Song.find(params[:id])
@song.destroy
respond_to do |format|
format.html { redirect_to songs_url }
format.json { head :no_content }
end
end

private

Expand Down
2 changes: 2 additions & 0 deletions app/helpers/admin/base_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module Admin::BaseHelper
end
2 changes: 2 additions & 0 deletions app/helpers/admin/songs_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module Admin::SongsHelper
end
11 changes: 11 additions & 0 deletions app/models/admin_user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class AdminUser < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable,
:recoverable, :rememberable, :trackable, :validatable

# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
# attr_accessible :title, :body
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div style="background:white;">
<%= form_for(@song) do |f| %>
<%= form_for [:admin, @song] do |f| %>
<% if @song.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@song.errors.count, "error") %> prohibited this song from being saved:</h2>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<%= render "shared/admin_nav" %>

<div class="admin">

<h1>Editing song</h1>
Expand Down
36 changes: 36 additions & 0 deletions app/views/admin/songs/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<div class="admin">
<% unless notice.blank? %>
<p style="background:yellow; padding: 12px 15px;"><%= notice %></p>
<% end %>

<h1>Songs</h1>
<p style="font-size: 16px;">You have <%= @songs.count %> published songs.</p>
<p style="margin:20px 0"><%= link_to 'Add New Song', new_admin_song_path, :class => 'btn' %></p>

<table>
<tr>
<th><%= sortable "title" %></th>
<th>Artist</th>
<th><%= sortable "year" %></th>
<th>Album</th>
<th><%= sortable "created_at" %></th>
<th><%= sortable "record_label","Record label" %></th>
<th></th>
</tr>

<% @songs.each do |song| %>
<tr>
<td><strong><%= link_to song.title, edit_admin_song_path(song) %></strong></td>
<td><%= song.artist.blank? ? "--" : song.artist.name %></td>
<td><%= song.year %></td>
<td><%= song.album.blank? ? "--" : song.album.name %></td>
<td><%= song.created_at.strftime("%b %e, %Y") %></td>
<td><%= song.record_label? ? song.record_label : "--" %></td>
<td><%= button_to "delete", [:admin, song], :method => :delete, :class => :destroy %></td>
</tr>
<% end %>
</table>

<p style="margin:20px 0"><%= link_to 'Add New Song', new_admin_song_path, :class => 'btn' %></p>

</div>
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<%= render "shared/admin_nav" %>

<div class="admin">

<h1>New song</h1>
Expand Down
18 changes: 18 additions & 0 deletions app/views/layouts/admin.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<title>admin</title>

<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>

<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href='http://fonts.googleapis.com/css?family=Averia+Serif+Libre:300,400,700,300italic,400italic,700italic|Source+Code+Pro:300,400,600,700' rel='stylesheet' type='text/css'>

</head>
<body class="<%= "admin" if ((action_name == "admin") || (action_name == "new") || (action_name == "edit") || (action_name == "details")) %>">
<%= render "shared/admin_nav" %>
<%= yield %>
</body>
</html>
7 changes: 7 additions & 0 deletions app/views/layouts/admin/_admin_nav.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="" style="background: #333; padding: 12px;">
<p style="margin: 0;color:#fff;padding: 0;font-size: 16px;line-height: 24px;">
<%= link_to "Artists", artists_url, :style=>"color:#ffff00;" %>&nbsp;&nbsp;|&nbsp;
<%= link_to "Albums", albums_url, :style=>"color:#ffff00;" %>&nbsp;&nbsp;|&nbsp;
<%= link_to "Songs", admin_url, :style=>"color:#ffff00;" %>
</p>
</div>
2 changes: 1 addition & 1 deletion app/views/shared/_admin_nav.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<p style="margin: 0;color:#fff;padding: 0;font-size: 16px;line-height: 24px;">
<%= link_to "Artists", artists_url, :style=>"color:#ffff00;" %>&nbsp;&nbsp;|&nbsp;
<%= link_to "Albums", albums_url, :style=>"color:#ffff00;" %>&nbsp;&nbsp;|&nbsp;
<%= link_to "Songs", admin_url, :style=>"color:#ffff00;" %>
<%= link_to "Songs", admin_songs_url, :style=>"color:#ffff00;" %>
</p>
</div>
38 changes: 0 additions & 38 deletions app/views/songs/admin.html.erb

This file was deleted.

Loading