Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
50 changes: 37 additions & 13 deletions admins/pageflow/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,58 @@ module Pageflow
menu :priority => 1

config.batch_actions = false
config.clear_sidebar_sections!

index do
column :title, :sortable => 'title' do |entry|
link_to entry.title, admin_entry_path(entry)
column class: 'publication_state' do |entry|
entry_publication_state_indicator(entry)
end
column I18n.t('pageflow.admin.entries.members'), :class => 'members' do |entry|
column :title, sortable: 'title' do |entry|
link_to(entry.title, admin_entry_path(entry))
end
column I18n.t('pageflow.admin.entries.members'), class: 'members' do |entry|
entry_user_badge_list(entry)
end
if authorized?(:read, Account)
column :account, :sortable => 'account_id' do |entry|
link_to(entry.account.name, admin_account_path(entry.account), :data => {:id => entry.account.id})
column :account, sortable: 'account_id' do |entry|
link_to(entry.account.name,
admin_account_path(entry.account),
data: {id: entry.account.id})
end
end
column :created_at
column :updated_at
column :class => 'buttons' do |entry|
column :edited_at
column :published_at, sortable: 'pageflow_revisions.published_at'

column class: 'buttons' do |entry|
if authorized?(:edit, Entry)
span(link_to(I18n.t('pageflow.admin.entries.editor'), pageflow.edit_entry_path(entry), :class => 'editor button'))
icon_link_to(pageflow.edit_entry_path(entry),
tooltip: I18n.t('pageflow.admin.entries.editor_hint'),
class: 'editor')
end
span(link_to(I18n.t('pageflow.admin.entries.preview'), preview_admin_entry_path(entry), :class => 'preview button'))

icon_link_to(preview_admin_entry_path(entry),
tooltip: I18n.t('pageflow.admin.entries.preview'),
class: 'preview')

if entry.published?
span(link_to(I18n.t('pageflow.admin.entries.show_public'), pretty_entry_url(entry), :class => 'show_public button'))
icon_link_to(pretty_entry_url(entry),
tooltip: I18n.t('pageflow.admin.entries.show_public_hint'),
class: 'show_public')
end
end
end

filter :title
filter :account
filter :created_at
filter :edited_at
filter :first_published_at
filter :published_revision_published_at, as: :date_range
filter :with_publication_state, as: :select, collection: -> { collection_for_entry_publication_states }

Choose a reason for hiding this comment

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

Line is too long. [107/100]

Choose a reason for hiding this comment

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

Line is too long. [107/100]


sidebar :folders, :only => :index do
text_node(link_to(I18n.t('pageflow.admin.entries.add_folder'), new_admin_folder_path, :class => 'new'))
grouped_folder_list(Folder.accessible_by(Ability.new(current_user), :read),
grouped_folder_list(Folder.includes(:account).accessible_by(Ability.new(current_user), :read),
:class => authorized?(:manage, Folder) ? 'editable' : nil,
:active_id => params[:folder_id],
:grouped_by_accounts => authorized?(:read, Account))
Expand Down Expand Up @@ -114,6 +136,7 @@ module Pageflow
controller do
helper FoldersHelper
helper EntriesHelper
helper Pageflow::Admin::EntriesHelper
helper Pageflow::Admin::FeaturesHelper
helper Pageflow::Admin::RevisionsHelper
helper Pageflow::Admin::FormHelper
Expand All @@ -130,7 +153,8 @@ def update
end

def scoped_collection
params.key?(:folder_id) ? super.where(:folder_id => params[:folder_id]) : super
result = super.includes(:theming, :account, :users, :published_revision).references(:published_revision)

Choose a reason for hiding this comment

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

Line is too long. [112/100]

Choose a reason for hiding this comment

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

Line is too long. [112/100]

params.key?(:folder_id) ? result.where(folder_id: params[:folder_id]) : result
end

def permitted_params
Expand Down
5 changes: 5 additions & 0 deletions app/assets/stylesheets/pageflow/admin.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
@import "pageflow/admin/entries";
@import "pageflow/admin/forms";
@import "pageflow/admin/features";
@import "pageflow/admin/filters";
@import "pageflow/admin/quotas";
@import "pageflow/admin/tabs_view";
@import "pageflow/admin/tooltip_bubble";
@import "pageflow/admin/icon_link";
@import "pageflow/admin/icon_button";
@import "pageflow/admin/publication_state_indicator";

#wrapper {
overflow: hidden;
Expand Down
13 changes: 3 additions & 10 deletions app/assets/stylesheets/pageflow/admin/entries.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,7 @@
clear: both;
}

td.buttons {
padding: 5px;
}

td.members {
max-width: 130px;
}

@import './entries/folders';
@import './entries/user_badge_list';
@import "./entries/index_table";
@import "./entries/folders";
@import "./entries/user_badge_list";
}
15 changes: 15 additions & 0 deletions app/assets/stylesheets/pageflow/admin/entries/index_table.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.index_table {
.publication_state {
width: 16px;
padding: 5px;
}

.buttons {
width: 85px;
padding: 5px;
}

.members {
max-width: 130px;
}
}
3 changes: 3 additions & 0 deletions app/assets/stylesheets/pageflow/admin/filters.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#filter_sidebar_section {

Choose a reason for hiding this comment

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

Avoid using id selectors

Choose a reason for hiding this comment

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

Avoid using id selectors

display: none;
}
25 changes: 25 additions & 0 deletions app/assets/stylesheets/pageflow/admin/icon_button.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
$icon-button-color: #fff;

a.icon_button:link {
@include background-icon-left($font-size: 15px,
$color: $icon-button-color,
$left: 9px,
$top: 50%);
padding-left: 30px;

&:before {
font-weight: normal;
}

&.editor {
@include fa-pencil-icon;
}

&.preview {
@include fa-eye-icon;
}

&.show_public {
@include fa-external-link-icon;
}
}
31 changes: 31 additions & 0 deletions app/assets/stylesheets/pageflow/admin/icon_link.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
$icon-link-color: #555;

$icon-link-acitve-color: #000;

.icon_link_to {
a {
@include background-icon-center($font-size: 16px, $color: $icon-link-color);
position: relative;
display: inline-block;
width: 25px;
height: 25px;
vertical-align: bottom;

&:focus,
&:hover {
@include background-icon-color($icon-link-acitve-color);
}

&.editor {
@include fa-pencil-icon;
}

&.preview {
@include fa-eye-icon;
}

&.show_public {
@include fa-external-link-icon;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
$publication-state-indicator-color: #5d5d5d;

.publication_state_indicator {
@include background-icon-center($font-size: 16px, $color: $publication-state-indicator-color);
display: inline-block;
width: 25px;
height: 25px;
vertical-align: bottom;
border-bottom: none;

&.published_without_password_protection {
@include fa-globe-icon;
}

&.published_with_password_protection {
@include fa-lock-icon;
}
}
30 changes: 30 additions & 0 deletions app/assets/stylesheets/pageflow/admin/tooltip_bubble.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
$tooltip-bubble-background-color: rgba(0, 0, 0, 0.7);

$tooltip-bubble-text-color: #fff;

.tooltip_bubble {
position: absolute;
display: none;
background-color: $tooltip-bubble-background-color;
color: $tooltip-bubble-text-color;
padding: 5px 10px;
top: -30px;
white-space: nowrap;
border-radius: 2px;
pointer-events: none;

&:before {
content: "";
position: absolute;
top: 100%;
left: 8px;
@include triangle(10px, $tooltip-bubble-background-color, down);
}
}

:focus,
:hover {
> .tooltip_bubble {
display: block;
}
}
15 changes: 15 additions & 0 deletions app/helpers/pageflow/admin/entries_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Pageflow
module Admin
module EntriesHelper
def collection_for_entry_publication_states
[
'published_without_password_protection',
'published_with_password_protection',
'not_published'
].index_by do |state|
I18n.t(state, scope: 'activerecord.values.pageflow/entry.publication_states')
end
end
end
end
end
63 changes: 63 additions & 0 deletions app/models/concerns/pageflow/entry_publication_states.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
module Pageflow
module EntryPublicationStates
extend ActiveSupport::Concern

included do
scope(:published, -> { joins(:published_revision) })

scope(:published_without_password_protection,
-> { published.merge(Revision.without_password_protection) })

scope(:published_with_password_protection,
-> { published.merge(Revision.with_password_protection) })

scope(:not_published,
lambda do
includes(:published_revision)
.references(:pageflow_revisions)
.where(pageflow_revisions: {id: nil})
end)
end

def publication_state
if published_with_password_protection?
'published_with_password_protection'
elsif published?
'published_without_password_protection'
else
'not_published'
end
end

def published_with_password_protection?
published? && published_revision.password_protected?
end

def published?
published_revision.present?
end

def published_at
published? ? published_revision.published_at : nil
end

def published_until
published? ? published_revision.published_until : nil
end

module ClassMethods
def with_publication_state(state)
case state
when 'published_with_password_protection'
published_with_password_protection
when 'published_without_password_protection'
published_without_password_protection
when 'not_published'
not_published
else
fail(ArgumentError, "Unknown publication state #{state}")
end
end
end
end
end
14 changes: 5 additions & 9 deletions app/models/pageflow/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class PasswordMissingError < StandardError
end

include FeatureTarget
include EntryPublicationStates

extend FriendlyId
friendly_id :slug_candidates, :use => [:finders, :slugged]
Expand Down Expand Up @@ -34,7 +35,6 @@ class PasswordMissingError < StandardError
validates :account, :theming, :presence => true
validate :folder_belongs_to_same_account

scope :published, -> { joins(:published_revision) }
scope :editing, -> { joins(:edit_lock).merge(Pageflow::EditLock.active) }

attr_accessor :skip_draft_creation
Expand Down Expand Up @@ -96,14 +96,6 @@ def duplicate
EntryDuplicate.of(self).create!
end

def published?
published_revision.present?
end

def published_until
published? ? published_revision.published_until : nil
end

def should_generate_new_friendly_id?
slug.blank? || title_changed?
end
Expand All @@ -112,6 +104,10 @@ def slug_candidates
[:title, [:title, :id]]
end

def self.ransackable_scopes(_)
[:with_publication_state, :published]
end

private

def folder_belongs_to_same_account
Expand Down
5 changes: 4 additions & 1 deletion app/models/pageflow/revision.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Revision < ActiveRecord::Base
'pageflow_pages.position ASC'
].join(',')

belongs_to :entry, :touch => true
belongs_to :entry, touch: :edited_at
belongs_to :creator, :class_name => 'User'
belongs_to :restored_from, :class_name => 'Pageflow::Revision'

Expand All @@ -29,6 +29,9 @@ class Revision < ActiveRecord::Base
{:now => Time.now}])
end

scope(:with_password_protection, -> { where('password_protected IS TRUE') })
scope(:without_password_protection, -> { where('password_protected IS NOT TRUE') })

scope :editable, -> { where('frozen_at IS NULL') }
scope :frozen, -> { where('frozen_at IS NOT NULL') }

Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/entries/_attributes_table.html.arb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ attributes_table_for entry do
row :account, :class => 'account'
end
row :created_at
row :updated_at
row :edited_at
row :published?, :class => 'published' do
span :'data-published' => entry.published? do
if entry.published?
Expand Down
Loading