-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
List portlets find and return content blocks. The following can be configured: * Find all of a given content type and display as a list. * Can limit results * Can order results (uses AJAX) * Can sort/reverse sort results * Can chose list or table views * Provide a way to custom the view for a given list portlet via creating an application specific version. * Only works for html.erb files. Format is: app/views/portlets/list/#{name_of_portlet}/_#{view_as}.html.erb * Name links if content is addressable. Other Fixes: * Fix portlet generator so it generates SimpleForm fields. * New portlets have a prompt for developers to add a suitable description.
- Loading branch information
Showing
25 changed files
with
246 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Adds AJAX behavior primarily for List Portlet | ||
|
||
jQuery(function($){ | ||
var select_tag = $('*[data-role="content_type_selector"]'); | ||
var order_field = $('*[data-role="order-fields"]'); | ||
if(select_tag.exists()){ | ||
select_tag.on('change', function(){ | ||
var selected_option = $( this ).val(); | ||
console.log("Changed to", selected_option ); | ||
order_field.load( '/cms/content_types.js .load > .select', { "content_type": selected_option } ) | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require_dependency "cms/application_controller" | ||
|
||
module Cms | ||
class ContentTypesController < ApplicationController | ||
|
||
def index | ||
content_type = ContentType.named(params[:content_type]).first | ||
@attributes = content_type.orderable_attributes.sort() | ||
respond_to do |format| | ||
format.js { render :layout => false } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module Cms | ||
module ContentTypesHelper | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## | ||
# All methods from this helper will be available in the render.html.erb for ListPortlet | ||
module ListPortletHelper | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
class ListPortlet < Cms::Portlet | ||
|
||
description "Find and display content blocks." | ||
enable_template_editor false | ||
|
||
def render | ||
query = current_content_type.model_class | ||
limit = self.limit | ||
unless limit.blank? | ||
query = query.limit(limit.to_i) | ||
end | ||
direction = self.reverse_order.blank? || self.reverse_order == "0" ? 'asc' : 'desc' | ||
unless self.order.blank? | ||
query = query.order("#{self.order} #{direction}") | ||
end | ||
@content_blocks = query.all.to_a | ||
end | ||
|
||
|
||
# This is far less flexible than prepending additional view paths, but it suffices for now. | ||
def view_as_full_path | ||
if File.exists?(expected_view_path()) | ||
"portlets/list/#{self.name.parameterize('_')}/_#{self.view_as}" | ||
else | ||
"portlets/list/_#{self.view_as}" | ||
end | ||
end | ||
|
||
def expected_view_path | ||
File.join(Rails.root, 'app', 'views', 'portlets', 'list', self.name.parameterize('_'), "_#{self.view_as}.html.erb") | ||
end | ||
|
||
def view_as_path | ||
"portlets/list/#{self.name.parameterize('_')}/_#{self.view_as}.html.erb" | ||
end | ||
|
||
def current_content_type | ||
Cms::ContentType.named(self.content_type).first | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<%= f.input :order, | ||
collection: collection, | ||
label_method: :humanize, | ||
include_blank: false, | ||
wrapper_html: {'data-role' => "order-fields", class: 'load'} %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<%= simple_form_for ListPortlet.new(order: "name") do |f| %> | ||
<%= render partial: 'cms/content_types/order_field', locals: { f: f, collection: @attributes} %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<% | ||
# Setup that would otherwise be done in Controller#new / #edit | ||
if @block.content_type.blank? | ||
@block.content_type = Cms::HtmlBlock.name | ||
end | ||
@orderable_attributes = @block.current_content_type.orderable_attributes | ||
|
||
views = { | ||
list: "List", | ||
table: "Table", | ||
} | ||
%> | ||
<% if @block.persisted? %> | ||
<% content_for :sidebar_after do %> | ||
<div class='sidebar-block'> | ||
<h4 class="gray">Custom View</h4> | ||
|
||
<p>Create/edit the following file: app/views/<%= @block.view_as_path %></p> | ||
</div> | ||
<% end %> | ||
<% end %> | ||
<%= f.input :name, placeholder: 'Name', label: false, input_html: {class: 'input-block-level input-xxlarge'} %> | ||
<%= f.input :content_type, | ||
collection: Cms::ContentType.available, | ||
label_method: :display_name, | ||
value_method: :name, | ||
include_blank: false, | ||
input_html: {'data-role' => "content_type_selector"} %> | ||
<%= f.input :limit, hint: 'Show at most this many items.', placeholder: 'Displays all items if left blank.' %> | ||
<%= render partial: 'cms/content_types/order_field', locals: {f: f, collection: @orderable_attributes} %> | ||
<%= f.input :reverse_order, as: :boolean %> | ||
<%= f.input :view_as, collection: views.invert, include_blank: false %> | ||
<%= f.input :template, as: :template_editor %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h1 class="cms-list-portlet"><%= @portlet.name %></h1> | ||
<ul class="cms-list-portlet" data-view-as="list"> | ||
<% collection.each do |content| %> | ||
<li><%= link_to_addressable_content(content.name, content) %></li> | ||
<% end %> | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<h1 class="cms-list-portlet"><%= @portlet.name %></h1> | ||
<table class="cms-list-portlet" data-view-as="table"> | ||
<thead> | ||
<tr> | ||
<th>Name</th> | ||
</tr> | ||
</thead> | ||
<% collection.each do |content| %> | ||
<tr> | ||
<td><%= link_to_addressable_content(content.name, content) %></td> | ||
</tr> | ||
<% end %> | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= render file: @portlet.view_as_full_path, locals: {collection: @content_blocks} %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
@cli | ||
Feature: | ||
Developers working in BrowserCMS projects should be able to generate portlets. | ||
|
||
Background: | ||
Given a BrowserCMS project named "petstore" exists | ||
And I cd into the project "petstore" | ||
|
||
Scenario: Generate a portlet | ||
When I run `rails g cms:portlet Events body` | ||
Then the file "app/portlets/events_portlet.rb" should contain: | ||
""" | ||
description "TODO: Provide a suitable description for this portlet." | ||
""" | ||
And the file "app/views/portlets/events/_form.html.erb" should contain: | ||
""" | ||
<%= f.input :name %> | ||
<%= f.input :body %> | ||
<%= f.input :template, as: :template_editor %> | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<%%= f.cms_text_field :name %> | ||
<%%= f.input :name %> | ||
<% for attribute in attributes -%> | ||
<%%= f.cms_text_field :<%= attribute.name %> %> | ||
<%%= f.input :<%= attribute.name %> %> | ||
<% end -%> | ||
<%%= f.cms_template_editor :template %> | ||
<%%= f.input :template, as: :template_editor %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require "test_helper" | ||
|
||
describe ContentTypesController do | ||
# it "must be a real test" do | ||
# flunk "Need real tests" | ||
# end | ||
end |
6 changes: 6 additions & 0 deletions
6
test/dummy/app/views/portlets/list/all_products/_list.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h1 call>My special list:</h1> | ||
<ul class="cms-list-portlet" data-view-as="list"> | ||
<% collection.each do |content| %> | ||
<li><%= content.name %></li> | ||
<% end %> | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require "test_helper" | ||
|
||
describe ContentTypesHelper do | ||
|
||
it "must be a real test" do | ||
flunk "Need real tests" | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require File.join(File.dirname(__FILE__), '/../../test_helper') | ||
|
||
class ListTest < ActiveSupport::TestCase | ||
|
||
test "Should be able to create new instance of a portlet" do | ||
assert ListPortlet.create!(:name => "New Portlet") | ||
end | ||
|
||
end |