Permalink
Browse files

Show the content author that they have unpublished changes.

  • Loading branch information...
1 parent a870bba commit 746c8cc26f932b017f7510d3a399cb8685468042 @gvarela gvarela committed May 10, 2012
@@ -27,6 +27,11 @@ class CMSimple.Editor extends Spine.Controller
@routeToPath('/')
@bind 'pathLoaded', @proxy @ensureProperState
+ @bind 'pathLoaded', =>
+ console?.log 'pathLoaded'
+ @checkPublishedState()
+
+ CMSimple.Page.bind 'refresh', @proxy @checkPublishedState
@initialLoad ->
Spine.Route.setup(history: true)
@@ -58,8 +63,12 @@ class CMSimple.Editor extends Spine.Controller
initializeMercury: ->
@mercury = new Mercury.PageEditor(null, saveStyle: 'form')
+
Mercury.on 'saved', =>
- CMSimple.Page.fetch(@current_page.id)
+ CMSimple.Page.fetch(id: @current_page.id)
+ Mercury.one 'ready', =>
+ @checkPublishedState()
+
@loadCurrentSnippets()
loadCurrentSnippets: ->
@@ -97,4 +106,11 @@ class CMSimple.Editor extends Spine.Controller
else
$('.mercury-button').not('.mercury-historyPanel-button').removeClass('disabled')
+ checkPublishedState: (record)->
+ publishButton = $('.mercury-publish-button')
+ console?.log @current_page.reinflate().unpublished_changes, publishButton
+ if @current_page.reinflate().unpublished_changes
+ publishButton.addClass('unpublished')
+ else
+ publishButton.removeClass('unpublished')
@@ -91,7 +91,7 @@ window.Mercury = {
primary: {
save: ['Save', 'Save this page'],
preview: ['Preview', 'Preview this page', { toggle: true, mode: true }],
- publish: ['Publish', 'Publish this page'],
+ publish: ['Publishing', 'Manage the publishing of this page'],
sep1: ' ',
undoredo: {
undo: ['Undo', 'Undo your last action'],
@@ -104,7 +104,7 @@ window.Mercury = {
insertCharacter: ['Character', 'Special Characters', { modal: '/mercury/modals/character.html', regions: ['editable', 'markupable'] }],
snippetPanel: ['Snippet', 'Snippet Panel', { panel: '/cmsimple/snippets' }],
sep2: ' ',
- editMetadata: ['Page Metadata', 'Edit Page Metadata'],
+ editMetadata: ['Page Info', 'Edit Page Metadata'],
historyPanel: ['History', 'Page Version History', {toggle: true}],
sep4: ' ',
sitemap: ['Site Map', 'List of pages in the site', {toggle: true}],
@@ -1,5 +1,5 @@
class CMSimple.Page extends Spine.Model
- @configure 'Page', 'template', 'title', 'parent_id', 'position', 'slug', 'is_root', 'browser_title', 'keywords', 'description', 'published'
+ @configure 'Page', 'template', 'title', 'parent_id', 'position', 'slug', 'is_root', 'browser_title', 'keywords', 'description', 'published', 'unpublished_changes'
@extend Spine.Model.Ajax
@belongsTo 'parent', 'CMSimple.Page', 'parent_id'
@@ -35,9 +35,12 @@ class CMSimple.Page extends Spine.Model
values.parent_id = parseInt(values.parent_id, 0) if values.parent_id
@load(values)
+ reinflate: @::reload
+
reload: ->
- @ajax().reload()
- @trigger 'reload'
+ @constructor.fetch
+ id: @id
+ success: => @trigger 'reload'
editPath: ->
"/editor#{@path()}"
@@ -11,6 +11,10 @@
background-image: url(/assets/toolbar/publish.png);
}
+.mercury-publish-button.unpublished em {
+ background-image: url(/assets/toolbar/unpublished.png);
+}
+
.mercury-redirects-button em {
background-image: url(/assets/toolbar/redirect.png);
}
@@ -104,6 +104,12 @@ def unpublish!
def published?
self.published_at.present? && self.published_at <= Time.zone.now
end
+ alias :published :published?
+
+ def unpublished_changes?
+ self.published_at.blank? || (self.updated_at - self.published_at).abs > 1.second
+ end
+ alias :unpublished_changes :unpublished_changes?
#TODO: refactor me, this smells
def published=(val)
@@ -143,6 +149,10 @@ def revert_to!(version_id)
save!
end
+ def as_json(options={})
+ super(options.merge({:methods => [:unpublished_changes, :published]}))
+ end
+
protected
def escape(string)
@@ -18,3 +18,14 @@ Feature: As a user I should be able to create pages on the site
When I make changes to the current page
Then the current page should only show published content
+ Scenario: A user should see an indication of having unpublished changes
+ Given I open the sitemap
+ When I add a new page
+ Then there should be an indication of unpublished changes
+
+ When I publish the current page
+ Then there should not be an indication of unpublished changes
+
+ When I make changes to the current page
+ Then there should be an indication of unpublished changes
+
@@ -78,7 +78,10 @@
end
When "I view the old version" do
- step %{I press "ul.versions button.view"}
+ within '.mercury-panel' do
+ link = all('ul.versions .view').last
+ link.click
+ end
end
When "I add a new page" do
@@ -118,12 +121,16 @@
step %{I click on the "save" button}
step %{I click on the "publish" button}
step %{the modal window should be visible}
- click_button 'Publish'
+ wait_for_client_page_refresh do
+ click_button 'Publish'
+ end
end
When "I make changes to the current page" do
step %{I change the contents of editable1 to "This is changed content"}
- step %{I click on the "save" button}
+ wait_for_client_page_refresh do
+ step %{I click on the "save" button}
+ end
end
When "I publish a new version of the current page" do
@@ -218,10 +225,6 @@
step %(the current page should be publicly available)
end
-Then "the current page should only show published content" do
- step %(the current page should be publicly available)
-end
-
Then "I there should be one version in the history panel" do
within '.mercury-panel' do
page.should have_selector 'ul.versions li', count: 1
@@ -235,3 +238,16 @@
end
end
end
+
+Then "there should be an indication of unpublished changes" do
+ step %{I wait for ajax requests to complete}
+ within '.mercury-toolbar' do
+ page.should have_selector '.mercury-publish-button.unpublished'
+ end
+end
+
+Then "there should not be an indication of unpublished changes" do
+ within '.mercury-toolbar' do
+ page.should_not have_selector '.mercury-publish-button.unpublished'
+ end
+end
@@ -239,3 +239,9 @@ def with_scope(locator)
Then /^show me the page$/ do
save_and_open_page
end
+
+When /^(?:|I )wait for ajax requests to complete/ do
+ wait_until do
+ page.evaluate_script('$.active') == 0
+ end
+end
View
@@ -0,0 +1,10 @@
+module StepUtils
+ def wait_for_client_page_refresh
+ page.driver.execute_script("window.page_refreshed = false; CMSimple.Page.one('refresh', function(){ window.page_refreshed = true; });")
+ yield
+ wait_until do
+ page.evaluate_script('window.page_refreshed') == true
+ end
+ end
+end
+World(StepUtils)
View
@@ -137,6 +137,18 @@
end
end
+ describe '#unpublished_changes?' do
+ it 'has unpublished changes if it was never published' do
+ page.published_at.should be_nil
+ page.unpublished_changes?.should be_true
+ end
+
+ it 'does not have unpublished changes once it is published' do
+ page.publish!
+ page.unpublished_changes?.should be_false
+ end
+ end
+
describe '#unpublish!' do
before do
page.publish!
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 746c8cc

Please sign in to comment.