Skip to content

Commit

Permalink
Better 'debug' mode for PDF. Fixed changing skin_id bug (thanks to Mi…
Browse files Browse the repository at this point in the history
…ro for signaling this).
  • Loading branch information
gaspard committed Feb 11, 2011
1 parent 311ddd1 commit 8b3bd12
Show file tree
Hide file tree
Showing 16 changed files with 201 additions and 29 deletions.
7 changes: 6 additions & 1 deletion app/controllers/nodes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,16 @@ def update
if params[:edit] == 'popup'
redirect_to edit_node_version_path(:node_id => @node[:zip], :id => 0, :close => (params[:validate] ? true : nil))
else
# FIXME: use a redir param......
redirect_to zen_path(@node, :mode => params[:mode])
end
else
begin
route = ActionController::Routing::Routes.recognize_path(request.referer[%r{https?://[^/]+(.*)},1])
if request.referer
route = ActionController::Routing::Routes.recognize_path(request.referer[%r{https?://[^/]+(.*)},1])
else
route = {:action => 'show'}
end
if route[:action] == 'index'
mode = '+index'
elsif route[:action] == 'search'
Expand Down
29 changes: 28 additions & 1 deletion app/models/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1163,14 +1163,23 @@ def get_project_id

# Id to zip mapping for parent_id. Used by zafu and forms.
def parent_zip
@parent_zip || (parent ? parent[:zip] : nil)
@parent_zip || parent.try(:zip)
end

# When setting parent trough controllers, we receive parent_zip=.
def parent_zip=(zip)
@parent_zip = zip
end

# When setting skin trough controllers, we receive skin_zip=.
def skin_zip=(zip)
@skin_zip = zip.to_i
end

def skin_zip
@skin_zip || skin.try(:zip)
end

# Id to zip mapping for section_id. Used by zafu and forms.
def section_zip
section[:zip]
Expand Down Expand Up @@ -1521,6 +1530,19 @@ def node_before_validation
end
end

if @skin_zip
if node = secure(Node) { Node.find_by_zip(@skin_zip) }
if !node.kind_of?(Skin)
@skin_zip_error = _('type mismatch (%{type} is not a Skin)') % {:type => node.klass}
else
self.skin_id = node.id
end
else
@skin_zip_error = _('could not be found')
end
end


self[:kpath] = self.vclass.kpath

# make sure section is the same as the parent
Expand Down Expand Up @@ -1571,6 +1593,11 @@ def validate_node
@parent_zip_error = nil
end

if @skin_zip_error
errors.add('skin_id', @skin_zip_error)
@skin_zip_error = nil
end

# when creating root node, self[:id] and :root_id are both nil, so it works.
if parent_id_changed? && self[:id] == current_site[:root_id]
errors.add("parent_id", "root should not have a parent") unless self[:parent_id].blank?
Expand Down
2 changes: 1 addition & 1 deletion app/views/nodes/_groups.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<li><label><%= _('publishers') %></label><%= select('node', 'dgroup_id', form_groups, { :include_blank => true }, {:disabled=>(@node[:inherit] != 0)}) %></li>
<li><label><%= _('writers') %></label><%= select('node', 'wgroup_id', form_groups, { :include_blank => true }, {:disabled=>(@node[:inherit] != 0)}) %></li>
<li><label><%= _('readers') %></label><%= select('node', 'rgroup_id', form_groups, { :include_blank => true }, {:disabled=>(@node[:inherit] != 0)}) %></li>
<li><label><%= _('skin') %></label><%= select('node', 'skin_id', form_skins, {}, {:disabled=>(@node[:inherit] == 1)}) %></li>
<li><label><%= _('skin') %></label><%= select('node', 'skin_id', form_skins, {:selected => @node.skin_zip}, {:disabled=>(@node[:inherit] == 1)}) %></li>
<li class='submit'><%= submit_tag _('change') %></li>
</form>
<% else %>
Expand Down
9 changes: 8 additions & 1 deletion bricks/pdf/lib/bricks/pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,18 @@ def render_to_pdf(opts)
}
else
# did not work
query_string = request.query_string
if query_string == ''
debug_url = "#{request.path}?debug"
else
debug_url = "#{request.path}?#{query_string}&debug"
end

{
:type => 'text/html',
# Compile html to pdf
:disposition => 'inline',
:data => "Could not render pdf file..."
:data => "Could not render pdf file... <a href='#{debug_url}'>debug</a>"
}
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/zena/info.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Zena
VERSION = '1.0.0.beta5'
VERSION = '1.0.0.rc1'
ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
end
2 changes: 1 addition & 1 deletion lib/zena/site_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_nodes
:conditions => ['site_id = ?', site_id],
:limit => CHUNK_SIZE,
:offset => (page - 1) * CHUNK_SIZE,
:order => 'id ASC'
:order => 'id DESC'
)
secure_result(nodes)
end
Expand Down
5 changes: 5 additions & 0 deletions lib/zena/use/display.rb
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,11 @@ def extract_label(res, params, attribute)
end
end

# ??? <r:h do='foasfa'/> ?
# def r_h
# out "<%= h ??? %>"
# end

# Insert javascript asset tags
def r_javascripts
if @params[:list] == 'all' || @params[:list].nil?
Expand Down
34 changes: 24 additions & 10 deletions lib/zena/use/scope_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,21 @@ def validate_idx_scope
scopes = new_instance.safe_eval self[:idx_scope]
if scopes.kind_of?(Hash)
scopes.each do |keys, query|
unless keys.kind_of?(String) && query.kind_of?(String)
errors.add('idx_scope', "Invalid entry: keys and query should be of type String (#{keys.inspect} => #{query.inspect})")
unless keys.kind_of?(String) &&
(
query.kind_of?(String) ||
(query.kind_of?(Array) && query.inject(true){|s,k| s && k.kind_of?(String)}))
errors.add('idx_scope', "Invalid entry: keys should be a String and query should be a String or an Array of strings (#{keys.inspect} => #{query.inspect})")
next
end
begin
real_class.build_query(:all, query,
:node_name => 'self',
:main_class => self,
:rubyless_helper => self
)
Array(query).each do |q|
real_class.build_query(:all, q,
:node_name => 'self',
:main_class => self,
:rubyless_helper => self
)
end
rescue ::QueryBuilder::Error => err
errors.add('idx_scope', "Invalid query: #{err.message}")
end
Expand Down Expand Up @@ -181,8 +186,17 @@ def update_scope_indices_on_prop_change
if virtual_class && scopes = virtual_class.idx_scope
scopes = safe_eval(scopes)
return unless scopes.kind_of?(Hash)
scopes.each do |keys, query|
next unless query.kind_of?(String) && keys.kind_of?(String)
mapped_scopes = []
scopes.each do |keys, queries|
# Change key ('project,contract') to an array
keys = keys.split(',').map(&:strip) if keys.kind_of?(String)
Array(queries).each do |query|
mapped_scopes << [keys, query]
end
end

mapped_scopes.each do |keys, query|
next unless query.kind_of?(String) && keys.kind_of?(Array) && keys.inject(true) {|s,k| s && k.kind_of?(String) }
if query.strip == 'self'
models_to_update = [self]
else
Expand All @@ -192,7 +206,7 @@ def update_scope_indices_on_prop_change
models_to_update.each do |m|
if idx_model = m.scope_index
# force creation of index record
idx_model.update_with(self, keys.split(',').map(&:strip), true)
idx_model.update_with(self, keys, true)
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/zena/use/zafu_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ def filter_prefix
end # filter_prefix

def filter_status
# Do not filter or we cannot set any 'status' attribute in <r:new>.
return if %w{new link}.include?(@method)
status = @params.delete(:status)
if status == 'true' || (@params[:actions] && status != 'false')
node = (@method == 'each' && self.node.list_context?) ? self.node.move_to(var, self.node.single_class) : self.node
Expand Down
4 changes: 4 additions & 0 deletions lib/zena/use/zafu_safe_definitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ def self.join_proc
safe_method_for String, [:limit, Number] => {:class => String, :pre_processor => true}
safe_method_for String, [:limit, Number, String] => {:class => String, :pre_processor => true}
safe_method_for Number, :to_s => {:class => String, :pre_processor => true}
safe_method_for Number, :to_f => {:class => Number, :pre_processor => true}
safe_method_for Number, :to_i => {:class => Number, :pre_processor => true}
safe_method_for NilClass, :to_f => {:class => Number, :pre_processor => true}
safe_method_for NilClass, :to_i => {:class => Number, :pre_processor => true}
safe_method_for Object, :blank? => Boolean

safe_method_for Node, [:kind_of?, VirtualClass] =>
Expand Down
38 changes: 33 additions & 5 deletions public/javascripts/zena.js
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ Zena.Div_editor.prototype = {
}

Zena.draggable = function(dom_id, drag_handle, revert) {
revert = revert == undefined ? true : revert
revert = revert == undefined ? true : revert;
if (drag_handle) {
if ($(dom_id).select('.' + drag_handle) == []) {
// insert span
Expand Down Expand Up @@ -800,10 +800,7 @@ Zena.put = function(tag) {
f.appendChild(m);
f.submit();
}
function test()
{
alert("test!");
}

Zena.set_toggle = function(dom_id, definition) {
var elem = $(dom_id);
var id = dom_id.replace(/^.*_/,'') * 1;
Expand Down Expand Up @@ -861,4 +858,35 @@ Zena.toggle = function(elem, definition, id) {
}
});
}
}

Zena.m_toggle = function(id) {
var txt_id = 'txt_' + id;
$('off_'+id, 'on_'+id, txt_id).invoke('toggle');
if ($(txt_id).style.display != 'none') {
$$('#' + txt_id + ' iframe').each(function(s) {
s.src = s.src;
});
}
fleXenv.updateScrollBars();
}

var pm_counter = 1;
Zena.plus_minus = function(elem, start, plus, minus) {
plus = plus == undefined ? '[+]' : plus;
minus = minus == undefined ? '[-]' : minus;

var tag = elem.tagName;
pm_counter = pm_counter + 1;
var id = "m_" + pm_counter;
var show = start == 'on' ? 'display:none;' : '';
var hide = start == 'on' ? '' : 'display:none;';
var trigger_tag = " <a id='off_"+id+"' style='"+show+"' onclick='Zena.m_toggle(\"" + id +"\")' class='plus_btn'>"+plus+"</a><a id='on_"+id+"' style='"+hide+"' onclick='Zena.m_toggle(\"" + id +"\")' class='minus_btn'>"+minus+"</a>";
var new_tag = "<"+tag+" style='"+hide+"' id='txt_"+id+"' class='txt'>" + elem.innerHTML + "</"+tag+">";
if (tag.toUpperCase() == 'SPAN' || !elem.previous()) {
Element.replace(elem, trigger_tag + ' ' + new_tag);
} else {
Element.insert(elem.previous(), {bottom:trigger_tag});
Element.replace(elem, new_tag);
}
}
31 changes: 28 additions & 3 deletions test/functional/nodes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,12 @@ class NodesControllerTest < Zena::Controller::TestCase
end # creating a node

context 'updating a node' do

context 'that she owns' do
setup do
@node = secure(Page) { Page.create(:parent_id => nodes_id(:zena), :title => 'hop', :v_status => Zena::Status[:pub]) }
end

context 'in redit time' do
subject do
{:action => 'update', :controller => 'nodes', :id => @node.zip, :node => {:title => 'hip'}}
Expand All @@ -229,8 +229,33 @@ class NodesControllerTest < Zena::Controller::TestCase
end
end # in redit time
end # that she owns

context 'by changing skin' do
subject do
{:action => 'update', :controller => 'nodes', :id => nodes_zip(:people), :node => {:skin_zip => nodes_zip(:wikiSkin), :inherit => 0}}
end

should 'update skin_id' do
put_subject
assert_equal nodes_id(:wikiSkin), nodes(:people).skin_id
end

context 'with a bad value' do
subject do
{:action => 'update', :controller => 'nodes', :id => nodes_zip(:people), :node => {:skin_zip => nodes_zip(:status), :inherit => 0}}
end

should 'set error message on skin_id' do
put_subject
assert_response :success
assert_equal 'type mismatch (Page is not a Skin)', assigns(:node).errors[:skin_id]
end
end # with a bad value

end # by changing skin

end # updating a node

context 'using xml' do
context 'without being in the api_group' do
setup do
Expand Down
5 changes: 5 additions & 0 deletions test/integration/zafu_compiler/relations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -461,3 +461,8 @@ count:
src: "<p do='nodes in site order by id' find='count'/>"
tem: "<p><%= Node.do_find(:count, %Q{SELECT COUNT(*) FROM nodes WHERE #{secure_scope('nodes')}}) %></p>"
res: "<p>42</p>"

nodes_main_class:
src: "<r:nodes do='each' do='Document?' do='title'/>"
tem: "xx"

2 changes: 1 addition & 1 deletion test/sites/zena/roles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Tracker:
Tag:
kpath: NPT
real_class: Page
idx_scope: "{'tag' => 'project'}"
idx_scope: "{'tag' => %w{project self}}"

Task:
kpath: N
Expand Down

0 comments on commit 8b3bd12

Please sign in to comment.