# HG changeset patch # User Daniel Poelzleithner # Date 1286308319 -7200 # Node ID 166fd10c7e81e4e8b13889f0e7e447f3236b8cda # Parent 02e24b4dd21c089cdae914a7db0f6a829779fc05 fixes bug #234 test if the constructed selector first before adding a paginator diff -r 02e24b4dd21c -r 166fd10c7e81 app/main/timeline/_list.lua --- a/app/main/timeline/_list.lua Tue Oct 05 21:14:54 2010 +0200 +++ b/app/main/timeline/_list.lua Tue Oct 05 21:51:59 2010 +0200 @@ -2,130 +2,143 @@ local event_names = param.get("event_names", "table") local initiatives_per_page = param.get("initiatives_per_page", atom.number) or 3 -ui.paginate{ - per_page = param.get("per_page", atom.number) or 25, - selector = timeline_selector, - content = function() - local timelines = timeline_selector:exec() - timelines:load("issue") - timelines:load("initiative") - timelines:load("member") - ui.list{ - attr = { class = "nohover" }, - records = timelines, - columns = { - { - field_attr = { style = "width: 10em;" }, - content = function(timeline) - ui.field.text{ - attr = { style = "font-size: 75%; font-weight: bold; background-color: #ccc; display: block; margin-bottom: 1ex;"}, - value = format.time(timeline.occurrence) - } + +-- test if selector is valid +local test_selector = timeline_selector:get_db_conn():new_selector() +test_selector:add_field('count(1)') +test_selector:add_from(timeline_selector) +test_selector:single_object_mode() + +err, x = test_selector:try_exec() - ui.field.text{ - attr = { style = "font-size: 75%; font-weight: bold;"}, - value = event_names[timeline.event] or timeline.event - } - if timeline.event == "draft_created" and timeline.count > 1 then +if err then + slot.put_into("error", _"Invalid query") +else + ui.paginate{ + per_page = param.get("per_page", atom.number) or 25, + selector = timeline_selector, + content = function() + local timelines = timeline_selector:exec() + timelines:load("issue") + timelines:load("initiative") + timelines:load("member") + ui.list{ + attr = { class = "nohover" }, + records = timelines, + columns = { + { + field_attr = { style = "width: 10em;" }, + content = function(timeline) ui.field.text{ - attr = { style = "font-size: 75%;"}, - value = _("(#{more_count} duplicates removed)", { more_count = timeline.count - 1 }) + attr = { style = "font-size: 75%; font-weight: bold; background-color: #ccc; display: block; margin-bottom: 1ex;"}, + value = format.time(timeline.occurrence) } - end - end - }, - { - content = function(timeline) - local issue - local initiative - if timeline.issue then - issue = timeline.issue - elseif timeline.initiative then - initiative = timeline.initiative - issue = initiative.issue - elseif timeline.draft then - initiative = timeline.draft.initiative - issue = initiative.issue - elseif timeline.suggestion then - initiative = timeline.suggestion.initiative - issue = initiative.issue - end - if issue then - if timeline.is_interested then - local label = _"You are interested in this issue", - ui.image{ - attr = { alt = label, title = label, style = "float: left; margin-right: 0.5em;" }, - static = "icons/16/eye.png" + + ui.field.text{ + attr = { style = "font-size: 75%; font-weight: bold;"}, + value = event_names[timeline.event] or timeline.event + } + if timeline.event == "draft_created" and timeline.count > 1 then + ui.field.text{ + attr = { style = "font-size: 75%;"}, + value = _("(#{more_count} duplicates removed)", { more_count = timeline.count - 1 }) } end - slot.put(" ") - ui.tag{ - tag = "span", - attr = { style = "font-size: 75%; font-weight: bold; background-color: #ccc; display: block; margin-bottom: 1ex;"}, - content = issue.area.name .. ", " .. _("Issue ##{id}", { id = issue.id }) - } - else - ui.tag{ - tag = "span", - attr = { style = "font-size: 75%; background-color: #ccc; display: block; margin-bottom: 1ex;"}, - content = function() slot.put(" ") end - } - end - - if timeline.member then - execute.view{ - module = "member_image", - view = "_show", - params = { - member = timeline.member, - image_type = "avatar", - show_dummy = true - } - } - ui.link{ - content = timeline.member.name, - module = "member", - view = "show", - id = timeline.member.id - } end - if timeline.issue then - local initiatives_selector = timeline.issue - :get_reference_selector("initiatives") - execute.view{ - module = "initiative", - view = "_list", - params = { - issue = timeline.issue, - initiatives_selector = initiatives_selector, - per_page = initiatives_per_page, - no_sort = true, - limit = initiatives_per_page + }, + { + content = function(timeline) + local issue + local initiative + if timeline.issue then + issue = timeline.issue + elseif timeline.initiative then + initiative = timeline.initiative + issue = initiative.issue + elseif timeline.draft then + initiative = timeline.draft.initiative + issue = initiative.issue + elseif timeline.suggestion then + initiative = timeline.suggestion.initiative + issue = initiative.issue + end + if issue then + if timeline.is_interested then + local label = _"You are interested in this issue", + ui.image{ + attr = { alt = label, title = label, style = "float: left; margin-right: 0.5em;" }, + static = "icons/16/eye.png" + } + end + slot.put(" ") + ui.tag{ + tag = "span", + attr = { style = "font-size: 75%; font-weight: bold; background-color: #ccc; display: block; margin-bottom: 1ex;"}, + content = issue.area.name .. ", " .. _("Issue ##{id}", { id = issue.id }) + } + else + ui.tag{ + tag = "span", + attr = { style = "font-size: 75%; background-color: #ccc; display: block; margin-bottom: 1ex;"}, + content = function() slot.put(" ") end + } + end + + if timeline.member then + execute.view{ + module = "member_image", + view = "_show", + params = { + member = timeline.member, + image_type = "avatar", + show_dummy = true + } } - } - elseif initiative then - execute.view{ - module = "initiative", - view = "_list", - params = { - issue = initiative.issue, - initiatives_selector = Initiative:new_selector():add_where{ "initiative.id = ?", initiative.id }, - per_page = initiatives_per_page, - no_sort = true + ui.link{ + content = timeline.member.name, + module = "member", + view = "show", + id = timeline.member.id + } + end + if timeline.issue then + local initiatives_selector = timeline.issue + :get_reference_selector("initiatives") + execute.view{ + module = "initiative", + view = "_list", + params = { + issue = timeline.issue, + initiatives_selector = initiatives_selector, + per_page = initiatives_per_page, + no_sort = true, + limit = initiatives_per_page + } } - } + elseif initiative then + execute.view{ + module = "initiative", + view = "_list", + params = { + issue = initiative.issue, + initiatives_selector = Initiative:new_selector():add_where{ "initiative.id = ?", initiative.id }, + per_page = initiatives_per_page, + no_sort = true + } + } + end + if timeline.suggestion then + ui.link{ + module = "suggestion", + view = "show", + id = timeline.suggestion.id, + content = timeline.suggestion.name + } + end end - if timeline.suggestion then - ui.link{ - module = "suggestion", - view = "show", - id = timeline.suggestion.id, - content = timeline.suggestion.name - } - end - end - }, + }, + } } - } - end -} \ No newline at end of file + end + } +end