Skip to content
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-217: Content Publishable #341

Merged
merged 17 commits into from
Sep 26, 2016
Merged
Show file tree
Hide file tree
Changes from 16 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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ gem 'hashie-forbidden_attributes', '~> 0.1.1'
gem 'ranked-model', '~> 0.4.0'
gem 'redis-rails', '~> 5.0'
gem 'pomona', '~> 0.7'
gem "transitions", '~> 1.2', :require => ["transitions", "active_model/transitions"]

# Middleware
gem 'rack-cors', '~> 0.4.0', require: 'rack/cors'
Expand Down
12 changes: 7 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,7 @@ GEM
thread_safe (0.3.5)
tilt (2.0.5)
timecop (0.8.1)
transitions (1.2.0)
trollop (2.1.2)
turbolinks (5.0.1)
turbolinks-source (~> 5)
Expand Down Expand Up @@ -765,11 +766,12 @@ DEPENDENCIES
sidekiq (~> 4.2.1)
sidekiq-failures (~> 0.4.5)
six (~> 0.2.0)
sprockets (= 3.7.0)
sprockets-rails (= 3.2.0)
timecop (~> 0.8)
turbolinks (~> 5.0.1)
uglifier (~> 3.0.2)
sprockets (= 3.6.0)
sprockets-rails (= 3.0.4)
timecop (~> 0.8.0)
transitions (~> 1.2)
turbolinks (~> 5.0.0beta2)
uglifier (~> 2.7.2)
unicorn (~> 5.1.0)
virtus (~> 1.0.5)
yt (~> 0.25.40)
Expand Down
3 changes: 3 additions & 0 deletions app/cells/buttons/edit_button.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
= link_to edit_content_type_content_item_path(content_type.id, content_item.id), class: 'mdl-button mdl-js-button mdl-button--icon' do
%i{ class: 'material-icons' }
create
15 changes: 15 additions & 0 deletions app/cells/buttons_cell.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class ButtonsCell < Cell::ViewModel
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is a good candidate for an entire class.. I'd just nest it in the view, since it's not complex business logic nor does it utilize its own model

def edit_button
render
end

private

def content_item
model
end

def content_type
content_item.content_type
end
end
1 change: 0 additions & 1 deletion app/cells/index/content_item/edit.haml

This file was deleted.

9 changes: 1 addition & 8 deletions app/cells/index/content_item_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,7 @@ def edit
end

private

def render_edit
content_type = @options[:content_item].content_type
content_item = @options[:content_item]

link_to "<i class='material-icons'>create</i>".html_safe, edit_content_type_content_item_path(content_type.id, content_item.id), class: 'mdl-button mdl-js-button mdl-button--icon'
end


def render_table_data(field)
if field.has_key?(:id)
@options[:content_item].field_items.find { |fi| fi.field_id == field[:id].to_i }.data.values[0]
Expand Down
2 changes: 1 addition & 1 deletion app/cells/index/table_body.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
%td{ class: 'mdl-data-table__cell--non-numeric' }
= cell('index/content_item', nil, { cells: column[:cells], content_item: content_item }).(:column)
%td{ class: 'mdl-data-table__cell--non-numeric' }
= cell('index/content_item', nil, content_item: content_item).(:edit)
= cell('buttons', content_item).(:edit_button)
6 changes: 6 additions & 0 deletions app/cells/wizard/field/show.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@
= cell(FieldTypes::Core::TextCell, field_item, form: field_item_form, input_options: input, label_options: label).(render_method)
- else
= cell(FieldTypes::Core::TextCell, field_item, form: field_item_form, input_options: input, label_options: label).(:input)

- if field_item.field.field_type_instance.class == BooleanFieldType
= cell(FieldTypes::Core::BooleanCell, field_item, form: field_item_form, field_name: field_item.field.name, default_value: false, input_options: input, label_options: label).(:checkbox)

- if field_item.field.field_type_instance.class == TreeFieldType
= cell(FieldTypes::Core::TreeCell, field_item, form: field_item_form, metadata: field_item.field.metadata["allowed_values"], field: field, input_options: input, label_options: label).(render_method)

- if field_item.field.field_type_instance.class == DateTimeFieldType
= cell(FieldTypes::Core::DateTimeCell, field_item, form: field_item_form, default_value: '', input_options: input, label_options: label).(:datepicker)

- if field_item.field.field_type_instance.class == TagFieldType
= cell(FieldTypes::Core::TagCell, field_item, form: field_item_form, default_value: [], input_options: input, label_options: label).(:tag_picker)

- if field_item.field.field_type_instance.class == UserFieldType
= cell(FieldTypes::Core::UserCell, field_item, form: field_item_form, default_value: User.all.first.id, user_data: User.all, input_options: input, label_options: label).(:dropdown)

- if field_item.field.field_type_instance.class == AssetFieldType
= cell(FieldTypes::Core::AssetCell, field_item, form: field_item_form, input_options: input, label_options: label).(:input)
3 changes: 2 additions & 1 deletion app/helpers/content_item_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ def content_item_params
params.require(:content_item).permit(
:creator_id,
:content_type_id,
field_items_attributes: field_items_attributes_params
:state,
field_items_attributes: field_items_attributes_params,
)
end

Expand Down
18 changes: 14 additions & 4 deletions app/models/content_item.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
class ContentItem < ActiveRecord::Base
include ActiveModel::Transitions
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks

state_machine :initial => :default do
state :draft
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 :published, :timestamp => true do
transitions :to => :published, :from => [:draft]
end
end

acts_as_paranoid

belongs_to :creator, class_name: "User"
Expand All @@ -20,17 +31,16 @@ def self.taggable_fields
taggable_on_array = Field.select { |field| field.field_type_instance.is_a?(TagFieldType) }.map { |field_item| field_item.name.parameterize('_') }
end

# The following two methods (#author_image and #publish_state) are currently faked
# The following method (#author_image) is currently faked
# author_image is faked pending being able to reference the specific User object (ex:
# content_item.author.user_image)
# publish_state is faked pending the story revolving around being able to publish ContentItems

def author_image
"<img src='https://robohash.org/#{rand(1000..10000)}.png' height='100' width='100'/>".html_safe
"<img src='https://robohash.org/#{id}.png' height='100' width='100'/>".html_safe
end

def publish_state
"Published"
state.titleize
end

# The Method self.taggable_fields must always be above the acts_as_taggable_on inclusion for it.
Expand Down
1 change: 1 addition & 0 deletions app/services/content_item_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def create
value.delete("id")
@content_item.field_items << FieldItem.new(value)
end

content_item_params.delete("field_items_attributes")
@content_item.attributes = content_item_params.to_hash
end
Expand Down
10 changes: 9 additions & 1 deletion app/views/content_items/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,13 @@
= cell('wizard', @wizard, context: { content_item: @content_item, form: form }).()
.mdl-grid
.mdl-cell.mdl-cell--12-col
= form.submit 'Submit', class: 'mdl-button mdl-js-button mdl-button--raised mdl-button--colored mdl-js-ripple-effect'
- if @content_type.publishable
- case @content_item.state
- when 'published'
= form.submit "Update #{@content_type.name} Post", class: 'mdl-button mdl-js-button mdl-button--raised mdl-button--colored mdl-js-ripple-effect'
- else
= form.button 'Save as Draft', value: 'draft', name: 'content_item[state]', class: 'mdl-button mdl-js-button mdl-button--raised mdl-button--colored mdl-js-ripple-effect', type: 'submit'
= form.button 'Publish', value: 'published', name: 'content_item[state]', class: 'mdl-button mdl-js-button mdl-button--raised mdl-button--colored mdl-js-ripple-effect', type: 'submit'
- else
= form.submit 'Submit', class: 'mdl-button mdl-js-button mdl-button--raised mdl-button--colored mdl-js-ripple-effect'
= link_to 'Cancel', content_type_content_items_path(@content_type), class: 'mdl-button mdl-js-button mdl-js-ripple-effect'
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddPublishableBooleanToContentType < ActiveRecord::Migration
def change
add_column :content_types, :publishable, :boolean, default: false
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class RemoveUnnecessaryFieldsFromContentType < ActiveRecord::Migration
def change
remove_column :content_types, :taggable_with_tags?, :boolean
remove_column :content_types, :taggable_with_keywords?, :boolean
remove_column :content_types, :is_published, :boolean
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class RemoveOldStateDataFromContentItems < ActiveRecord::Migration
def change
remove_column :content_items, :publish_state, :string
remove_column :content_items, :published_at, :datetime
remove_column :content_items, :expired_at, :datetime
end
end
5 changes: 5 additions & 0 deletions db/migrate/20160926180119_add_state_to_content_items.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddStateToContentItems < ActiveRecord::Migration
def change
add_column :content_items, :state, :string
end
end
19 changes: 7 additions & 12 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20160906210044) do
ActiveRecord::Schema.define(version: 20160919153329) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -78,9 +78,6 @@
end

create_table "content_items", force: :cascade do |t|
t.string "publish_state"
t.datetime "published_at"
t.datetime "expired_at"
t.integer "creator_id"
t.integer "content_type_id"
t.datetime "created_at", null: false
Expand All @@ -93,18 +90,16 @@
add_index "content_items", ["deleted_at"], name: "index_content_items_on_deleted_at", using: :btree

create_table "content_types", force: :cascade do |t|
t.string "name", null: false
t.string "name", null: false
t.text "description"
t.integer "creator_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "creator_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "deleted_at"
t.boolean "taggable_with_tags?", default: false
t.boolean "taggable_with_keywords?", default: false
t.jsonb "tag_data"
t.boolean "is_published"
t.integer "contract_id"
t.string "icon", default: "help", null: false
t.string "icon", default: "help", null: false
t.boolean "publishable", default: false
end

add_index "content_types", ["creator_id"], name: "index_content_types_on_creator_id", using: :btree
Expand Down
3 changes: 2 additions & 1 deletion lib/tasks/employer/blog.rake
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ namespace :employer do
description: "Blog for Employer",
icon: "description",
creator_id: 1,
contract_id: 1
contract_id: 1,
publishable: true
})
blog.save

Expand Down