-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
COR-710: Publish System Rebuild #487
Changes from 10 commits
5f9d299
1e0dd41
506d8ca
ae224f0
49f221b
cfac6ca
4856669
0eb39aa
6d8f066
5f64af6
dbd7f93
b32cd67
ea21a4f
7900600
ae62c0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,23 +3,8 @@ class ContentItem < ApplicationRecord | |
include Elasticsearch::Model | ||
include Elasticsearch::Model::Callbacks | ||
|
||
state_machine :initial => :default do | ||
state_machine do | ||
state :draft | ||
state :scheduled, :enter => lambda { |content_item| content_item.schedule_publish } | ||
state :published | ||
state :default #the default state that is given to an object - this should only ever exist on ContentItems where the ContentType is not publishable | ||
|
||
event :publish do | ||
transitions :to => :published, :from => [:default, :draft, :scheduled] | ||
end | ||
|
||
event :schedule do | ||
transitions :to => :scheduled, :from => [:default, :draft] | ||
end | ||
|
||
event :draft do | ||
transitions :to => :draft, :from => [:default, :published, :scheduled] | ||
end | ||
end | ||
|
||
acts_as_paranoid | ||
|
@@ -47,12 +32,8 @@ def author_email | |
end | ||
|
||
def publish_state | ||
state.titleize | ||
end | ||
|
||
def schedule_publish | ||
timestamp = field_items.find { |field_item| field_item.field.name == "Publish Date" }.data["timestamp"] | ||
PublishContentItemJob.set(wait_until: DateTime.parse(timestamp)).perform_later(self) | ||
sorted_field_items = field_items.select { |fi| fi.field.field_type_instance.is_a?(DateTimeFieldType) && !fi.field.metadata["state"].nil? }.sort_by{ |a| a.data["timestamp"] }.reverse | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have some thoughts about this system (which is pretty neat!), but we may end up rebuilding some of this anyway - so we can discuss later. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's move this logic to the Service layer - consumers of this abstraction ideally shouldn't have to know how to groom the data being passed in. This issue of 'leaky abstractions' is something that I'm trying to correct across the application - it's hard to stay ontop of, and it's something we've all been guilty of. Thanks! |
||
PublishStateService.new.perform(sorted_field_items, self) | ||
end | ||
|
||
def rss_url(base_url, slug_field_id) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class PublishStateService < ApplicationController | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's not inherit from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whoops - that's a typo, good catch |
||
def perform(sorted_field_items, content_item) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm guessing this returns the publish status of a |
||
@sorted_field_items = sorted_field_items | ||
@content_item = content_item | ||
|
||
Rails.cache.fetch("PublishStateService/#{content_item.id}", expires_in: 10.minutes) do | ||
active_state | ||
end | ||
end | ||
|
||
def self.clear(content_item) | ||
Rails.cache.delete("PublishStateService/#{content_item.id}") | ||
end | ||
|
||
private | ||
|
||
def active_state | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since our terminology is 'published', should this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Our terminology is only published for this specific |
||
@sorted_field_items.each do |field_item| | ||
if DateTime.now > DateTime.parse(field_item.data["timestamp"]) | ||
return field_item.field.metadata["state"] | ||
break | ||
end | ||
end | ||
|
||
return @content_item.state.titleize | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,18 +4,5 @@ | |
= cell('wizard', @wizard, context: { content_item: @content_item, form: form }).() | ||
%footer.mdl-grid | ||
.mdl-cell.mdl-cell--12-col | ||
- if @content_type.publishable | ||
- case @content_item.state | ||
- when 'published' | ||
= form.submit "Update Post", class: 'mdl-button mdl-js-button mdl-button--raised mdl-button--success mdl-js-ripple-effect' | ||
= form.button 'Save as Draft', value: 'draft', name: 'content_item[state]', class: 'mdl-button mdl-js-button mdl-button--cb mdl-js-ripple-effect', type: 'submit' | ||
- when 'scheduled' | ||
= form.button 'Schedule Post', value: 'schedule', name: 'content_item[state]', class: 'mdl-button mdl-js-button mdl-button--cb mdl-js-ripple-effect', type: 'submit' | ||
= form.button 'Publish Now', value: 'publish', name: 'content_item[state]', class: 'mdl-button mdl-js-button mdl-button--raised mdl-button--success mdl-js-ripple-effect', type: 'submit' | ||
= form.button 'Save as Draft', value: 'draft', name: 'content_item[state]', class: 'mdl-button mdl-js-button mdl-button--cb mdl-js-ripple-effect', type: 'submit' | ||
- else | ||
= form.button 'Publish Now', value: 'publish', name: 'content_item[state]', class: 'mdl-button mdl-js-button mdl-button--raised mdl-button--success mdl-js-ripple-effect new_publish_state_button', type: 'submit' | ||
= form.button 'Save as Draft', value: 'draft', name: 'content_item[state]', class: 'mdl-button mdl-js-button mdl-button--cb mdl-js-ripple-effect', type: 'submit' | ||
- else | ||
= form.submit 'Submit', class: 'mdl-button mdl-js-button mdl-button--raised mdl-button--success mdl-js-ripple-effect' | ||
= form.submit 'Save Now', class: 'mdl-button mdl-js-button mdl-button--raised mdl-button--success mdl-js-ripple-effect' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe we'll still need to reflect the state in the button's text, per Justin's previous AC There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I talked with him about this, since the buttons wouldn't actually move the state along he preferred if it just said "Save Now" until we figure out how best to implement the triggered state changes |
||
= link_to 'Cancel', content_type_content_items_path(@content_type), class: 'mdl-button mdl-js-button mdl-button--cb mdl-js-ripple-effect' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still need to reflect the latest state as the user changes publish/expiration dates, as per Justin's previous AC
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I talked with him about this, since the buttons wouldn't actually move the state along he preferred if it just said "Save Now" until we figure out how best to implement the triggered state changes