revisions system is done
Oleg
committed May 10, 2011
commit 69fe788b8252e013d98e83b178fa3e8f24f584ab
Showing 11
changed files with
113 additions
and 12 deletions
Gemfile
+1
-1
| @@ | @@ -1,7 +1,7 @@ |
| source 'http://rubygems.org' | |
| gem 'rails', '>=3.0.0' | |
| - | gem 'active_link_to', '>=0.0.6' |
| + | gem 'active_link_to', '>=0.0.7' |
| gem 'paperclip', '>=2.3.8' | |
| group :development do | |
Gemfile.lock
+2
-2
| @@ | @@ -15,7 +15,7 @@ GEM |
| rack-mount (~> 0.6.13) | |
| rack-test (~> 0.5.6) | |
| tzinfo (~> 0.3.23) | |
| - | active_link_to (0.0.6) |
| + | active_link_to (0.0.7) |
| activemodel (3.0.3) | |
| activesupport (= 3.0.3) | |
| builder (~> 2.1.2) | |
| @@ | @@ -78,7 +78,7 @@ PLATFORMS |
| ruby | |
| DEPENDENCIES | |
| - | active_link_to (>= 0.0.6) |
| + | active_link_to (>= 0.0.7) |
| jeweler (>= 1.4.0) | |
| paperclip (>= 2.3.8) | |
| rails (>= 3.0.0) | |
app/controllers/cms_admin/revisions_controller.rb
+8
-1
| @@ | @@ -8,7 +8,14 @@ class CmsAdmin::RevisionsController < CmsAdmin::BaseController |
| end | |
| def show | |
| - | render |
| + | case @record |
| + | when Cms::Page |
| + | @current_content = @record.blocks.inject({}){|c, b| c[b.label] = b.content; c } |
| + | @versioned_content = @record.blocks.inject({}){|c, b| c[b.label] = @revision.data['blocks_attributes'].detect{|r| r[:label] == b.label}.try(:[], :content); c } |
| + | else |
| + | @current_content = @record.revision_fields.inject({}){|c, f| c[f] = @record.send(f); c } |
| + | @versioned_content = @record.revision_fields.inject({}){|c, f| c[f] = @revision.data[f]; c } |
| + | end |
| end | |
| def revert | |
app/views/cms_admin/layouts/edit.html.erb
+1
-0
| @@ | @@ -1,3 +1,4 @@ |
| + | <%= link_to span_tag(pluralize(@cms_layout.revisions.count, 'revision')), cms_admin_layout_revisions_path(@cms_layout), :class => 'big button' %> |
| <h1> Editing Layout </h1> | |
| <%= cms_form_for @cms_layout, :url => {:action => :update} do |form| %> | |
app/views/cms_admin/pages/edit.html.erb
+1
-0
| @@ | @@ -1,3 +1,4 @@ |
| + | <%= link_to span_tag(pluralize(@cms_page.revisions.count, 'revision')), cms_admin_page_revisions_path(@cms_page), :class => 'big button' %> |
| <h1> Editing Page </h1> | |
| <%= cms_form_for @cms_page, :url => {:action => :update} do |form| %> | |
app/views/cms_admin/revisions/show.html.erb
+36
-2
| @@ | @@ -1,2 +1,36 @@ |
| - | <%= debug @record %> |
| - | <%= debug @revision %> |
| \ No newline at end of file | |
| + | <h1> Revisions for <%= @record.class.to_s.demodulize %></h1> |
| + | <h2> <%= @record.is_a?(Cms::Page) ? "Full Path: #{@record.full_path}" : "Slug: #{@record.slug}" %> </h2> |
| + | |
| + | <% content_for :right_column do %> |
| + | <h2><%= pluralize(@record.revisions.count, 'Revision') %></h2> |
| + | <div class='revisions box'> |
| + | <% @record.revisions.each do |revision| %> |
| + | <%= active_link_to revision.created_at, :id => revision.id %> |
| + | <% end %> |
| + | </div> |
| + | <% end %> |
| + | |
| + | <%= cms_form_for @revision, :url => {:action => :revert} do |form| %> |
| + | <%= form.simple_field do %> |
| + | <div class='current'> |
| + | <div class='title'>Current</div> |
| + | </div> |
| + | <div class='versioned'> |
| + | <div class='title'><%= @revision.created_at %></div> |
| + | </div> |
| + | <% end %> |
| + | |
| + | <% @current_content.each do |label, content| %> |
| + | |
| + | <%= form.simple_field label do %> |
| + | <div class='current'> |
| + | <div class='content'><%= content %></div> |
| + | </div> |
| + | <div class='versioned'> |
| + | <div class='content'><%= @versioned_content[label] %></div> |
| + | </div> |
| + | <% end %> |
| + | <% end %> |
| + | |
| + | <%= form.submit 'Update to this Revision' %> |
| + | <% end %> |
| \ No newline at end of file | |
config/routes.rb
+3
-3
| @@ | @@ -11,19 +11,19 @@ Rails.application.routes.draw do |
| match :reorder | |
| end | |
| resources :revisions, :only => [:index, :show, :revert] do | |
| - | post :revert, :on => :member |
| + | put :revert, :on => :member |
| end | |
| end | |
| resources :sites | |
| resources :uploads, :only => [:create, :destroy] | |
| resources :layouts do | |
| resources :revisions, :only => [:index, :show, :revert] do | |
| - | post :revert, :on => :member |
| + | put :revert, :on => :member |
| end | |
| end | |
| resources :snippets do | |
| resources :revisions, :only => [:index, :show, :revert] do | |
| - | post :revert, :on => :member |
| + | put :revert, :on => :member |
| end | |
| end | |
| end | |
public/stylesheets/comfortable_mexican_sofa/content.css
+42
-0
| @@ | @@ -182,4 +182,46 @@ form.search { |
| } | |
| .c_cms_admin_snippets.a_index ul.list li .item .icon { | |
| background-image: url(/images/comfortable_mexican_sofa/icon_snippet.gif); | |
| + | } |
| + | |
| + | /* -- Revisions ---------------------------------------------------------- */ |
| + | .c_cms_admin_revisions.a_show .form_element.submit_element .value { |
| + | margin-left: 0px; |
| + | } |
| + | .c_cms_admin_revisions.a_show .current { |
| + | width: 50%; |
| + | float: left; |
| + | } |
| + | .c_cms_admin_revisions.a_show .versioned { |
| + | width: 50%; |
| + | float: right; |
| + | } |
| + | .c_cms_admin_revisions.a_show .title, |
| + | .c_cms_admin_revisions.a_show .content { |
| + | padding: 2px 5px; |
| + | margin: 0px 3px; |
| + | } |
| + | .c_cms_admin_revisions.a_show .title { |
| + | background: #f1f1f1; |
| + | border-bottom: 2px solid #bbb; |
| + | } |
| + | .c_cms_admin_revisions.a_show .content { |
| + | min-height: 16px; |
| + | border: 1px dashed #f1f1f1; |
| + | } |
| + | .c_cms_admin_revisions.a_show .revisions a { |
| + | display: block; |
| + | background-color: #252525; |
| + | border-radius: 2px; |
| + | padding: 0px 3px; |
| + | opacity: 0.5; |
| + | margin-bottom: 2px; |
| + | color: #fff; |
| + | } |
| + | .c_cms_admin_revisions.a_show .revisions a:hover, |
| + | .c_cms_admin_revisions.a_show .revisions a.active { |
| + | opacity: 1; |
| + | } |
| + | .c_cms_admin_revisions.a_show .revisions a:last-child { |
| + | margin-bottom: 0px; |
| } | |
| \ No newline at end of file | |
public/stylesheets/comfortable_mexican_sofa/structure.css
+5
-0
| @@ | @@ -55,6 +55,11 @@ html, body { |
| color: #fff; | |
| opacity: 1; | |
| } | |
| + | .right_column_content h2 { |
| + | color: #d8d8d8; |
| + | text-shadow: #000 1px 1px; |
| + | margin-bottom: 5px; |
| + | } |
| .right_column_content .box { | |
| background-color: #484848; | |
| padding: 5px; | |
public/stylesheets/comfortable_mexican_sofa/typography.css
+8
-0
| @@ | @@ -10,6 +10,14 @@ h1 { |
| text-shadow: #fff 1px 1px; | |
| border-bottom: 2px solid #9f9f9f; | |
| } | |
| + | h2 { |
| + | font: bold 16px/16px 'Lucida Grande', 'Tahoma', serif; |
| + | text-shadow: #fff 1px 1px; |
| + | margin-bottom: 15px; |
| + | } |
| + | h1 + h2 { |
| + | margin-top: -15px; |
| + | } |
| a { | |
| text-decoration: none; | |
| color: #384E66; | |
test/functional/cms_admin/revisions_controller_test.rb
+6
-3
| @@ | @@ -33,6 +33,7 @@ class CmsAdmin::RevisionsControllerTest < ActionController::TestCase |
| assert assigns(:record) | |
| assert assigns(:revision) | |
| assert assigns(:record).is_a?(Cms::Layout) | |
| + | assert_equal 'Layout (default)', assigns(:record_title) |
| assert_template :show | |
| end | |
| @@ | @@ -42,6 +43,7 @@ class CmsAdmin::RevisionsControllerTest < ActionController::TestCase |
| assert assigns(:record) | |
| assert assigns(:revision) | |
| assert assigns(:record).is_a?(Cms::Page) | |
| + | assert_equal 'Page (/)', assigns(:record_title) |
| assert_template :show | |
| end | |
| @@ | @@ -51,6 +53,7 @@ class CmsAdmin::RevisionsControllerTest < ActionController::TestCase |
| assert assigns(:record) | |
| assert assigns(:revision) | |
| assert assigns(:record).is_a?(Cms::Snippet) | |
| + | assert_equal 'Snippet (default)', assigns(:record_title) |
| assert_template :show | |
| end | |
| @@ | @@ -89,7 +92,7 @@ class CmsAdmin::RevisionsControllerTest < ActionController::TestCase |
| layout = cms_layouts(:default) | |
| assert_difference 'layout.revisions.count' do | |
| - | post :revert, :layout_id => layout, :id => cms_revisions(:layout) |
| + | put :revert, :layout_id => layout, :id => cms_revisions(:layout) |
| assert_response :redirect | |
| assert_redirected_to edit_cms_admin_layout_path(layout) | |
| assert_equal 'Content Reverted', flash[:notice] | |
| @@ | @@ -105,7 +108,7 @@ class CmsAdmin::RevisionsControllerTest < ActionController::TestCase |
| page = cms_pages(:default) | |
| assert_difference 'page.revisions.count' do | |
| - | post :revert, :page_id => page, :id => cms_revisions(:page) |
| + | put :revert, :page_id => page, :id => cms_revisions(:page) |
| assert_response :redirect | |
| assert_redirected_to edit_cms_admin_page_path(page) | |
| assert_equal 'Content Reverted', flash[:notice] | |
| @@ | @@ -122,7 +125,7 @@ class CmsAdmin::RevisionsControllerTest < ActionController::TestCase |
| snippet = cms_snippets(:default) | |
| assert_difference 'snippet.revisions.count' do | |
| - | post :revert, :snippet_id => snippet, :id => cms_revisions(:snippet) |
| + | put :revert, :snippet_id => snippet, :id => cms_revisions(:snippet) |
| assert_response :redirect | |
| assert_redirected_to edit_cms_admin_snippet_path(snippet) | |
| assert_equal 'Content Reverted', flash[:notice] | |