diff --git a/Gemfile b/Gemfile index c4330a7..697d7d5 100644 --- a/Gemfile +++ b/Gemfile @@ -45,6 +45,7 @@ gem 'sass-rails', "~> 3.1.0" gem "exception_notification", :git => "git://github.com/rails/exception_notification", :require => 'exception_notifier' gem 'pg' gem 'devise' +gem 'formtastic' gem 'squeel' gem 'mini_exiftool' gem 'will_paginate' @@ -52,3 +53,4 @@ gem 'rdiscount' gem 'paperclip' gem 'acts_as_markup' gem 'yaml_db' +gem 'haml' \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 991fbe6..aad6d95 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -64,6 +64,9 @@ GEM erubis (2.7.0) execjs (1.2.9) multi_json (~> 1.0) + formtastic (2.0.2) + rails (~> 3.0) + haml (3.1.3) hike (1.2.1) hpricot (0.8.4) i18n (0.6.0) @@ -164,6 +167,8 @@ DEPENDENCIES coffee-rails (~> 3.1.0) devise exception_notification! + formtastic + haml hpricot jquery-rails mini_exiftool diff --git a/app/assets/images/admin/logo.png b/app/assets/images/admin/logo.png index fec2fca..ce9b20c 100644 Binary files a/app/assets/images/admin/logo.png and b/app/assets/images/admin/logo.png differ diff --git a/app/assets/javascripts/admin.js b/app/assets/javascripts/admin.js index 7bd1f59..707d3d4 100644 --- a/app/assets/javascripts/admin.js +++ b/app/assets/javascripts/admin.js @@ -6,4 +6,5 @@ // //= require jquery //= require jquery_ujs +//= require fancybox //= require_directory ./admin diff --git a/app/assets/javascripts/admin/photos.js.coffee b/app/assets/javascripts/admin/photos.js.coffee new file mode 100644 index 0000000..bbd3026 --- /dev/null +++ b/app/assets/javascripts/admin/photos.js.coffee @@ -0,0 +1,2 @@ +$ -> + $(".photos .photo a").not(".actions a").fancybox() \ No newline at end of file diff --git a/app/assets/stylesheets/admin.css b/app/assets/stylesheets/admin.css index ab7dfe9..af0241e 100644 --- a/app/assets/stylesheets/admin.css +++ b/app/assets/stylesheets/admin.css @@ -4,5 +4,6 @@ * the top of the compiled file, but it's generally better to create a new file per style scope. *= require_self *= require formtastic + *= require fancybox *= require_directory ./admin */ \ No newline at end of file diff --git a/app/assets/stylesheets/admin/admin.css.sass b/app/assets/stylesheets/admin/admin.css.sass index 9b3261a..1b6bca6 100644 --- a/app/assets/stylesheets/admin/admin.css.sass +++ b/app/assets/stylesheets/admin/admin.css.sass @@ -109,6 +109,9 @@ table background: #ddd !important border-bottom: 0 +.pagination + margin: 0.5em 0 + #error_explanation width: 450px border: 2px solid red diff --git a/app/assets/stylesheets/admin/formtastic.css.sass b/app/assets/stylesheets/admin/formtastic.css.sass index 97bc6b8..0007166 100644 --- a/app/assets/stylesheets/admin/formtastic.css.sass +++ b/app/assets/stylesheets/admin/formtastic.css.sass @@ -50,6 +50,13 @@ form.formtastic -webkit-appearance: none margin: 0 + .fragments + .label label + width: 13em + + .fragments-group + padding-left: 14em + input[type=submit], a.button @include button &[name=commit] @@ -60,6 +67,11 @@ form.formtastic @include box-shadow("0 1px 0 rgba(0, 0, 0, 0.25), inset -1px -1px 0 rgba(255, 255, 255, 0.2), inset 1px 1px 0 rgba(255, 255, 255, 0.3), inset 0 0 6px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.3)") &:hover, &:focus background-color: #8B6 + + .boolean + label + padding-left: 14em + text-align: left .error input border-width: 1px diff --git a/app/assets/stylesheets/admin/photos.css.sass b/app/assets/stylesheets/admin/photos.css.sass new file mode 100644 index 0000000..3a687be --- /dev/null +++ b/app/assets/stylesheets/admin/photos.css.sass @@ -0,0 +1,21 @@ +@import "../includes/round_corners" +@import "../includes/box_shadow" + +.photos + .photo + float: left + margin-right: 1em + margin-top: 1em + &:after + content: "" + display: block + clear: both + +ul.categories + border: 1px solid #ccc + @include round-corners(3px) + @include box-shadow("inset 2px 2px 4px rgba(0, 0, 0, 0.1)") + margin-top: 1em + padding: 1em + width: 25% + float: right diff --git a/app/assets/stylesheets/photos.css.sass b/app/assets/stylesheets/photos.css.sass index 9fc51ce..550c51f 100644 --- a/app/assets/stylesheets/photos.css.sass +++ b/app/assets/stylesheets/photos.css.sass @@ -1,10 +1,13 @@ @import "includes/box_shadow" +html + -webkit-text-size-adjust: 100% + body background: #101010 color: white - font-family: "Helvetica Neue", "Arial", "Helvatica", sans-serif - font-size: 14px + font-family: freight-sans-pro, "Helvetica Neue", "Arial", sans-serif + font-size: 100% overflow: hidden a @@ -151,7 +154,7 @@ p a text-align: right margin: 0 20px font-weight: normal - font-size: 1.1em + font-size: 1em line-height: 1em img @@ -183,9 +186,9 @@ img color: #ccc overflow: auto div - padding: 15px 20px + padding: 2px 12px p - margin-bottom: 0.6em + margin-top: 0.6em line-height: 1.35em /* FORM @@ -206,6 +209,7 @@ form display: block width: 75px float: left + margin-top: 6px &.error float: none display: inline @@ -214,9 +218,9 @@ form textarea height: 150px width: 335px - font-family: "Helvetica Neue","Arial","Helvatica",sans-serif - font-size: 14px - padding: 3px + font-family: freight-sans-pro, "Helvetica Neue", "Arial", sans-serif + font-size: 1em + padding: 5px color: #333 border: 2px solid #999 -moz-border-radius: 3px @@ -224,9 +228,9 @@ form border-radius: 3px input &[type='text'] - font-family: "Helvetica Neue","Arial","Helvatica",sans-serif - font-size: 14px - padding: 3px + font-family: freight-sans-pro, "Helvetica Neue", "Arial", sans-serif + font-size: 1em + padding: 5px color: #333 border: 2px solid #999 -moz-border-radius: 3px @@ -266,9 +270,9 @@ input.error, textarea.error form input[type='submit'] background: #666 - font-family: "Helvetica Neue","Arial","Helvatica",sans-serif - font-size: 14px - padding: 3px + font-family: freight-sans-pro, "Helvetica Neue", "Arial", sans-serif + font-size: 1em + padding: 3px 8px color: white border: 2px solid #333 -moz-border-radius: 3px diff --git a/app/controllers/admin/admin_controller.rb b/app/controllers/admin/admin_controller.rb index 57cf8cf..b66cd2f 100644 --- a/app/controllers/admin/admin_controller.rb +++ b/app/controllers/admin/admin_controller.rb @@ -5,6 +5,9 @@ class Admin::AdminController < ApplicationController def admin_menu @admin_menu = { :dashboard => '', - :admin_users => '' } + :admin_users => '', + :categories => '', + :photos => '', + :pages => '' } end end diff --git a/app/controllers/admin/categories_controller.rb b/app/controllers/admin/categories_controller.rb index 0d4438d..fa5a6d9 100644 --- a/app/controllers/admin/categories_controller.rb +++ b/app/controllers/admin/categories_controller.rb @@ -1,2 +1,53 @@ -class Admin::CategoriesController < Admin::ResourcesController +class Admin::CategoriesController < Admin::AdminController + + def index + @categories = Category.all + end + + def new + @category = Category.new + end + + def edit + @category = Category.find(params[:id]) + end + + def update + @category = Category.find(params[:id]) + + respond_to do |format| + if @category.update_attributes(params[:category]) + format.html { redirect_to(admin_categories_path, :notice => 'Category was successfully updated.') } + format.xml { head :ok } + else + format.html { render :action => "edit" } + format.xml { render :xml => @category.errors, :status => :unprocessable_entity } + end + end + end + + def create + @category = Category.new(params[:category]) + + respond_to do |format| + if @category.save + format.html { redirect_to(admin_categories_path, :notice => 'Category was successfully added.') } + format.xml { head :ok } + else + format.html { render :action => "edit" } + format.xml { render :xml => @category.errors, :status => :unprocessable_entity } + end + end + end + + def destroy + @category = Category.find(params[:id]) + @category.destroy + + respond_to do |format| + format.html { redirect_to(admin_categories_path, :notice => 'Category was deleted.') } + format.xml { head :ok } + end + end + end diff --git a/app/controllers/admin/pages_controller.rb b/app/controllers/admin/pages_controller.rb index df12653..ef63b69 100644 --- a/app/controllers/admin/pages_controller.rb +++ b/app/controllers/admin/pages_controller.rb @@ -1,2 +1,53 @@ -class Admin::PagesController < Admin::ResourcesController +class Admin::PagesController < Admin::AdminController + + def index + @pages = Page.all + end + + def new + @page = Page.new + end + + def edit + @page = Page.find(params[:id]) + end + + def update + @page = Page.find(params[:id]) + + respond_to do |format| + if @page.update_attributes(params[:page]) + format.html { redirect_to(admin_pages_path, :notice => 'Page was successfully updated.') } + format.xml { head :ok } + else + format.html { render :action => "edit" } + format.xml { render :xml => @page.errors, :status => :unprocessable_entity } + end + end + end + + def create + @page = Page.new(params[:page]) + + respond_to do |format| + if @page.save + format.html { redirect_to(admin_pages_path, :notice => 'Page was successfully added.') } + format.xml { head :ok } + else + format.html { render :action => "edit" } + format.xml { render :xml => @page.errors, :status => :unprocessable_entity } + end + end + end + + def destroy + @page = Page.find(params[:id]) + @page.destroy + + respond_to do |format| + format.html { redirect_to(admin_pages_path, :notice => 'Page was deleted.') } + format.xml { head :ok } + end + end + end diff --git a/app/controllers/admin/photos_controller.rb b/app/controllers/admin/photos_controller.rb index 75d2f9a..70ff80a 100644 --- a/app/controllers/admin/photos_controller.rb +++ b/app/controllers/admin/photos_controller.rb @@ -1,2 +1,60 @@ -class Admin::PhotosController < Admin::ResourcesController +class Admin::PhotosController < Admin::AdminController + before_filter :get_categories + + def index + @photos = Photo.paginate(:page => params[:page]) + end + + def new + @photo = Photo.new + end + + def edit + @photo = Photo.find(params[:id]) + end + + def update + @photo = Photo.find(params[:id]) + + respond_to do |format| + if @photo.update_attributes(params[:photo]) + format.html { redirect_to(admin_photos_path, :notice => 'Photo was successfully updated.') } + format.xml { head :ok } + else + format.html { render :action => "edit" } + format.xml { render :xml => @photo.errors, :status => :unprocessable_entity } + end + end + end + + def create + @photo = Photo.new(params[:photo]) + + respond_to do |format| + if @photo.save + format.html { redirect_to(admin_photos_path, :notice => 'Photo was successfully added.') } + format.xml { head :ok } + else + format.html { render :action => "edit" } + format.xml { render :xml => @photo.errors, :status => :unprocessable_entity } + end + end + end + + def destroy + @photo = Photo.find(params[:id]) + @photo.destroy + + respond_to do |format| + format.html { redirect_to(admin_photos_path, :notice => 'Photo was deleted.') } + format.xml { head :ok } + end + end + + private + + def get_categories + @categories = Category.all + end + end diff --git a/app/views/admin/categories/_category.html.haml b/app/views/admin/categories/_category.html.haml new file mode 100644 index 0000000..8809248 --- /dev/null +++ b/app/views/admin/categories/_category.html.haml @@ -0,0 +1,7 @@ +%tr + %td= category.name + %td= category.base_colour + %td{ :class => :actions } + = link_to 'Show', [:admin, category] + = link_to 'Edit', edit_admin_category_path(category) + = link_to 'Destroy', [:admin, category], confirm: 'Are you sure?', method: :delete diff --git a/app/views/admin/categories/_form.html.haml b/app/views/admin/categories/_form.html.haml new file mode 100644 index 0000000..1cc8787 --- /dev/null +++ b/app/views/admin/categories/_form.html.haml @@ -0,0 +1,3 @@ += semantic_form_for [:admin, category] do |f| + = f.inputs :name, :description, :base_colour, :sort + = f.buttons \ No newline at end of file diff --git a/app/views/admin/categories/edit.html.haml b/app/views/admin/categories/edit.html.haml new file mode 100644 index 0000000..ad67433 --- /dev/null +++ b/app/views/admin/categories/edit.html.haml @@ -0,0 +1,2 @@ +%h2 Edit Category += render :partial => "form", :locals => { :category => @category } \ No newline at end of file diff --git a/app/views/admin/categories/index.html.haml b/app/views/admin/categories/index.html.haml new file mode 100644 index 0000000..423bf90 --- /dev/null +++ b/app/views/admin/categories/index.html.haml @@ -0,0 +1,15 @@ +%h2 Categories + +%table + %thead + %tr + %th Name + %th Base Colour + %th + %tbody + = render :partial => "category", :collection => @categories + %tfoot + %tr + %td{:colspan => 4} +%br/ += link_to 'New Category', new_admin_category_path, :class => [:button, :new] diff --git a/app/views/admin/categories/new.html.haml b/app/views/admin/categories/new.html.haml new file mode 100644 index 0000000..d765ae7 --- /dev/null +++ b/app/views/admin/categories/new.html.haml @@ -0,0 +1,2 @@ +%h2 New Category += render :partial => "form", :locals => { :category => @category } \ No newline at end of file diff --git a/app/views/admin/pages/_form.html.haml b/app/views/admin/pages/_form.html.haml new file mode 100644 index 0000000..ed135a0 --- /dev/null +++ b/app/views/admin/pages/_form.html.haml @@ -0,0 +1,3 @@ += semantic_form_for [:admin, page] do |f| + = f.inputs :name, :title, :content + = f.buttons \ No newline at end of file diff --git a/app/views/admin/pages/_page.html.haml b/app/views/admin/pages/_page.html.haml new file mode 100644 index 0000000..949c8d1 --- /dev/null +++ b/app/views/admin/pages/_page.html.haml @@ -0,0 +1,7 @@ +%tr + %td= page.name + %td= page.title + %td{ :class => :actions } + = link_to 'Show', [:admin, page] + = link_to 'Edit', edit_admin_page_path(page) + = link_to 'Destroy', [:admin, page], confirm: 'Are you sure?', method: :delete diff --git a/app/views/admin/pages/edit.html.haml b/app/views/admin/pages/edit.html.haml new file mode 100644 index 0000000..8584005 --- /dev/null +++ b/app/views/admin/pages/edit.html.haml @@ -0,0 +1,2 @@ +%h2 Edit Page += render :partial => "form", :locals => { :page => @page } \ No newline at end of file diff --git a/app/views/admin/pages/index.html.haml b/app/views/admin/pages/index.html.haml new file mode 100644 index 0000000..4d8ca59 --- /dev/null +++ b/app/views/admin/pages/index.html.haml @@ -0,0 +1,15 @@ +%h2 Pages + +%table + %thead + %tr + %th Name + %th Title + %th + %tbody + = render :partial => "page", :collection => @pages + %tfoot + %tr + %td{:colspan => 4} +%br/ += link_to 'New Category', new_admin_page_path, :class => [:button, :new] diff --git a/app/views/admin/pages/new.html.haml b/app/views/admin/pages/new.html.haml new file mode 100644 index 0000000..f3d37f3 --- /dev/null +++ b/app/views/admin/pages/new.html.haml @@ -0,0 +1,2 @@ +%h2 New Page += render :partial => "form", :locals => { :page => @page } \ No newline at end of file diff --git a/app/views/admin/photos/_form.html.haml b/app/views/admin/photos/_form.html.haml new file mode 100644 index 0000000..e3f348c --- /dev/null +++ b/app/views/admin/photos/_form.html.haml @@ -0,0 +1,8 @@ += semantic_form_for [:admin, photo] do |f| + %ul.categories + - @categories.each do |photo_category| + %li + = check_box_tag "photo[category_ids][]", photo_category.id, @photo.categories.include?(photo_category), :id => "photo_category_ids_#{photo_category.id}" + = label_tag "photo_category_ids_#{photo_category.id}", photo_category.name + = f.inputs :photo, :title, :description, :flickr_url, :featured, :enabled, :taken_at + = f.buttons \ No newline at end of file diff --git a/app/views/admin/photos/_photo.html.haml b/app/views/admin/photos/_photo.html.haml new file mode 100644 index 0000000..5e27625 --- /dev/null +++ b/app/views/admin/photos/_photo.html.haml @@ -0,0 +1,6 @@ +.photo + = link_to image_tag(photo.photo.url(:size5), :title => photo.title), photo.photo.url + .actions + = link_to 'Show', [:admin, photo] + = link_to 'Edit', edit_admin_photo_path(photo) + = link_to 'Destroy', [:admin, photo], confirm: 'Are you sure?', method: :delete diff --git a/app/views/admin/photos/edit.html.haml b/app/views/admin/photos/edit.html.haml new file mode 100644 index 0000000..6f956f4 --- /dev/null +++ b/app/views/admin/photos/edit.html.haml @@ -0,0 +1,2 @@ +%h2 Edit Photo += render :partial => "form", :locals => { :photo => @photo } \ No newline at end of file diff --git a/app/views/admin/photos/index.html.haml b/app/views/admin/photos/index.html.haml new file mode 100644 index 0000000..bab4e1f --- /dev/null +++ b/app/views/admin/photos/index.html.haml @@ -0,0 +1,11 @@ +%h2 Photos + += will_paginate @photos, :remote => true + +.photos + = render :partial => "photo", :collection => @photos + += will_paginate @products, :remote => true + +%br/ += link_to 'New Photo', new_admin_photo_path, :class => [:button, :new] diff --git a/app/views/admin/photos/new.html.haml b/app/views/admin/photos/new.html.haml new file mode 100644 index 0000000..3621575 --- /dev/null +++ b/app/views/admin/photos/new.html.haml @@ -0,0 +1,2 @@ +%h2 New Photo += render :partial => "form", :locals => { :photo => @photo } \ No newline at end of file diff --git a/app/views/layouts/photos.html.erb b/app/views/layouts/photos.html.erb index 5823f70..e218229 100644 --- a/app/views/layouts/photos.html.erb +++ b/app/views/layouts/photos.html.erb @@ -12,6 +12,7 @@ <%= stylesheet_link_tag "fancybox", :media => "all" %> <%= stylesheet_link_tag "scrollbars", :media => "screen" %> <%= javascript_include_tag 'application' %> + <%= render :partial => "shared/typekit" %> diff --git a/app/views/shared/_typekit.html.haml b/app/views/shared/_typekit.html.haml new file mode 100644 index 0000000..76914fe --- /dev/null +++ b/app/views/shared/_typekit.html.haml @@ -0,0 +1,3 @@ += javascript_include_tag "http://use.typekit.com/bvi1xdc.js" +:javascript + try{Typekit.load();}catch(e){} diff --git a/config/routes.rb b/config/routes.rb index 8d64a95..7678adf 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -22,6 +22,9 @@ DanBarberPhoto::Application.routes.draw do put :update_password end end + resources :categories + resources :photos + resources :pages end # The priority is based upon order of creation: diff --git a/db/migrate/20111030163656_remove_admin_users.rb b/db/migrate/20111030163656_remove_admin_users.rb new file mode 100644 index 0000000..0b31c69 --- /dev/null +++ b/db/migrate/20111030163656_remove_admin_users.rb @@ -0,0 +1,20 @@ +class RemoveAdminUsers < ActiveRecord::Migration + def self.up + drop_table :admin_users + end + + def self.down + create_table :admin_users do |t| + t.string :first_name, :default => "", :null => false + t.string :last_name, :default => "", :null => false + t.string :role, :null => false + t.string :email, :null => false + t.boolean :status, :default => false + t.string :token, :null => false + t.string :salt, :null => false + t.string :crypted_password, :null => false + t.string :preferences + t.timestamps + end + end +end diff --git a/db/migrate/20111030164012_create_devise_admin_users.rb b/db/migrate/20111030164012_create_devise_admin_users.rb new file mode 100644 index 0000000..af89857 --- /dev/null +++ b/db/migrate/20111030164012_create_devise_admin_users.rb @@ -0,0 +1,27 @@ +class CreateDeviseAdminUsers < ActiveRecord::Migration + def up + create_table(:admin_users) do |t| + t.database_authenticatable :null => false + t.recoverable + t.rememberable + t.trackable + + # t.encryptable + t.confirmable + t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both + # t.token_authenticatable + + t.timestamps + end + + add_index :admin_users, :email, :unique => true + add_index :admin_users, :reset_password_token, :unique => true + add_index :admin_users, :confirmation_token, :unique => true + add_index :admin_users, :unlock_token, :unique => true + # add_index :admin_users, :authentication_token, :unique => true + end + + def down + drop_table :admin_users + end +end diff --git a/db/schema.rb b/db/schema.rb index 4c30654..5ee3352 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 => 20111013085444) do +ActiveRecord::Schema.define(:version => 20111030164012) do create_table "admin_users", :force => true do |t| t.string "email", :default => "", :null => false @@ -34,6 +34,11 @@ ActiveRecord::Schema.define(:version => 20111013085444) do t.datetime "updated_at" end + add_index "admin_users", ["confirmation_token"], :name => "index_admin_users_on_confirmation_token", :unique => true + add_index "admin_users", ["email"], :name => "index_admin_users_on_email", :unique => true + add_index "admin_users", ["reset_password_token"], :name => "index_admin_users_on_reset_password_token", :unique => true + add_index "admin_users", ["unlock_token"], :name => "index_admin_users_on_unlock_token", :unique => true + create_table "categories", :force => true do |t| t.string "name" t.text "description" @@ -74,4 +79,14 @@ ActiveRecord::Schema.define(:version => 20111013085444) do t.integer "views", :default => 0 end + create_table "sessions", :force => true do |t| + t.string "session_id", :null => false + t.text "data" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id" + add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at" + end