liquid_feedback_frontend
changeset 136:166fd10c7e81
fixes bug #234
test if the constructed selector first before adding a paginator
test if the constructed selector first before adding a paginator
author | Daniel Poelzleithner <poelzi@poelzi.org> |
---|---|
date | Tue Oct 05 21:51:59 2010 +0200 (2010-10-05) |
parents | 02e24b4dd21c |
children | 43ac94c7575b |
files | app/main/timeline/_list.lua |
line diff
1.1 --- a/app/main/timeline/_list.lua Tue Oct 05 21:14:54 2010 +0200 1.2 +++ b/app/main/timeline/_list.lua Tue Oct 05 21:51:59 2010 +0200 1.3 @@ -2,130 +2,143 @@ 1.4 local event_names = param.get("event_names", "table") 1.5 local initiatives_per_page = param.get("initiatives_per_page", atom.number) or 3 1.6 1.7 -ui.paginate{ 1.8 - per_page = param.get("per_page", atom.number) or 25, 1.9 - selector = timeline_selector, 1.10 - content = function() 1.11 - local timelines = timeline_selector:exec() 1.12 - timelines:load("issue") 1.13 - timelines:load("initiative") 1.14 - timelines:load("member") 1.15 - ui.list{ 1.16 - attr = { class = "nohover" }, 1.17 - records = timelines, 1.18 - columns = { 1.19 - { 1.20 - field_attr = { style = "width: 10em;" }, 1.21 - content = function(timeline) 1.22 - ui.field.text{ 1.23 - attr = { style = "font-size: 75%; font-weight: bold; background-color: #ccc; display: block; margin-bottom: 1ex;"}, 1.24 - value = format.time(timeline.occurrence) 1.25 - } 1.26 + 1.27 +-- test if selector is valid 1.28 +local test_selector = timeline_selector:get_db_conn():new_selector() 1.29 +test_selector:add_field('count(1)') 1.30 +test_selector:add_from(timeline_selector) 1.31 +test_selector:single_object_mode() 1.32 + 1.33 +err, x = test_selector:try_exec() 1.34 1.35 - ui.field.text{ 1.36 - attr = { style = "font-size: 75%; font-weight: bold;"}, 1.37 - value = event_names[timeline.event] or timeline.event 1.38 - } 1.39 - if timeline.event == "draft_created" and timeline.count > 1 then 1.40 +if err then 1.41 + slot.put_into("error", _"Invalid query") 1.42 +else 1.43 + ui.paginate{ 1.44 + per_page = param.get("per_page", atom.number) or 25, 1.45 + selector = timeline_selector, 1.46 + content = function() 1.47 + local timelines = timeline_selector:exec() 1.48 + timelines:load("issue") 1.49 + timelines:load("initiative") 1.50 + timelines:load("member") 1.51 + ui.list{ 1.52 + attr = { class = "nohover" }, 1.53 + records = timelines, 1.54 + columns = { 1.55 + { 1.56 + field_attr = { style = "width: 10em;" }, 1.57 + content = function(timeline) 1.58 ui.field.text{ 1.59 - attr = { style = "font-size: 75%;"}, 1.60 - value = _("(#{more_count} duplicates removed)", { more_count = timeline.count - 1 }) 1.61 + attr = { style = "font-size: 75%; font-weight: bold; background-color: #ccc; display: block; margin-bottom: 1ex;"}, 1.62 + value = format.time(timeline.occurrence) 1.63 } 1.64 - end 1.65 - end 1.66 - }, 1.67 - { 1.68 - content = function(timeline) 1.69 - local issue 1.70 - local initiative 1.71 - if timeline.issue then 1.72 - issue = timeline.issue 1.73 - elseif timeline.initiative then 1.74 - initiative = timeline.initiative 1.75 - issue = initiative.issue 1.76 - elseif timeline.draft then 1.77 - initiative = timeline.draft.initiative 1.78 - issue = initiative.issue 1.79 - elseif timeline.suggestion then 1.80 - initiative = timeline.suggestion.initiative 1.81 - issue = initiative.issue 1.82 - end 1.83 - if issue then 1.84 - if timeline.is_interested then 1.85 - local label = _"You are interested in this issue", 1.86 - ui.image{ 1.87 - attr = { alt = label, title = label, style = "float: left; margin-right: 0.5em;" }, 1.88 - static = "icons/16/eye.png" 1.89 + 1.90 + ui.field.text{ 1.91 + attr = { style = "font-size: 75%; font-weight: bold;"}, 1.92 + value = event_names[timeline.event] or timeline.event 1.93 + } 1.94 + if timeline.event == "draft_created" and timeline.count > 1 then 1.95 + ui.field.text{ 1.96 + attr = { style = "font-size: 75%;"}, 1.97 + value = _("(#{more_count} duplicates removed)", { more_count = timeline.count - 1 }) 1.98 } 1.99 end 1.100 - slot.put(" ") 1.101 - ui.tag{ 1.102 - tag = "span", 1.103 - attr = { style = "font-size: 75%; font-weight: bold; background-color: #ccc; display: block; margin-bottom: 1ex;"}, 1.104 - content = issue.area.name .. ", " .. _("Issue ##{id}", { id = issue.id }) 1.105 - } 1.106 - else 1.107 - ui.tag{ 1.108 - tag = "span", 1.109 - attr = { style = "font-size: 75%; background-color: #ccc; display: block; margin-bottom: 1ex;"}, 1.110 - content = function() slot.put(" ") end 1.111 - } 1.112 - end 1.113 - 1.114 - if timeline.member then 1.115 - execute.view{ 1.116 - module = "member_image", 1.117 - view = "_show", 1.118 - params = { 1.119 - member = timeline.member, 1.120 - image_type = "avatar", 1.121 - show_dummy = true 1.122 - } 1.123 - } 1.124 - ui.link{ 1.125 - content = timeline.member.name, 1.126 - module = "member", 1.127 - view = "show", 1.128 - id = timeline.member.id 1.129 - } 1.130 end 1.131 - if timeline.issue then 1.132 - local initiatives_selector = timeline.issue 1.133 - :get_reference_selector("initiatives") 1.134 - execute.view{ 1.135 - module = "initiative", 1.136 - view = "_list", 1.137 - params = { 1.138 - issue = timeline.issue, 1.139 - initiatives_selector = initiatives_selector, 1.140 - per_page = initiatives_per_page, 1.141 - no_sort = true, 1.142 - limit = initiatives_per_page 1.143 + }, 1.144 + { 1.145 + content = function(timeline) 1.146 + local issue 1.147 + local initiative 1.148 + if timeline.issue then 1.149 + issue = timeline.issue 1.150 + elseif timeline.initiative then 1.151 + initiative = timeline.initiative 1.152 + issue = initiative.issue 1.153 + elseif timeline.draft then 1.154 + initiative = timeline.draft.initiative 1.155 + issue = initiative.issue 1.156 + elseif timeline.suggestion then 1.157 + initiative = timeline.suggestion.initiative 1.158 + issue = initiative.issue 1.159 + end 1.160 + if issue then 1.161 + if timeline.is_interested then 1.162 + local label = _"You are interested in this issue", 1.163 + ui.image{ 1.164 + attr = { alt = label, title = label, style = "float: left; margin-right: 0.5em;" }, 1.165 + static = "icons/16/eye.png" 1.166 + } 1.167 + end 1.168 + slot.put(" ") 1.169 + ui.tag{ 1.170 + tag = "span", 1.171 + attr = { style = "font-size: 75%; font-weight: bold; background-color: #ccc; display: block; margin-bottom: 1ex;"}, 1.172 + content = issue.area.name .. ", " .. _("Issue ##{id}", { id = issue.id }) 1.173 + } 1.174 + else 1.175 + ui.tag{ 1.176 + tag = "span", 1.177 + attr = { style = "font-size: 75%; background-color: #ccc; display: block; margin-bottom: 1ex;"}, 1.178 + content = function() slot.put(" ") end 1.179 + } 1.180 + end 1.181 + 1.182 + if timeline.member then 1.183 + execute.view{ 1.184 + module = "member_image", 1.185 + view = "_show", 1.186 + params = { 1.187 + member = timeline.member, 1.188 + image_type = "avatar", 1.189 + show_dummy = true 1.190 + } 1.191 } 1.192 - } 1.193 - elseif initiative then 1.194 - execute.view{ 1.195 - module = "initiative", 1.196 - view = "_list", 1.197 - params = { 1.198 - issue = initiative.issue, 1.199 - initiatives_selector = Initiative:new_selector():add_where{ "initiative.id = ?", initiative.id }, 1.200 - per_page = initiatives_per_page, 1.201 - no_sort = true 1.202 + ui.link{ 1.203 + content = timeline.member.name, 1.204 + module = "member", 1.205 + view = "show", 1.206 + id = timeline.member.id 1.207 + } 1.208 + end 1.209 + if timeline.issue then 1.210 + local initiatives_selector = timeline.issue 1.211 + :get_reference_selector("initiatives") 1.212 + execute.view{ 1.213 + module = "initiative", 1.214 + view = "_list", 1.215 + params = { 1.216 + issue = timeline.issue, 1.217 + initiatives_selector = initiatives_selector, 1.218 + per_page = initiatives_per_page, 1.219 + no_sort = true, 1.220 + limit = initiatives_per_page 1.221 + } 1.222 } 1.223 - } 1.224 + elseif initiative then 1.225 + execute.view{ 1.226 + module = "initiative", 1.227 + view = "_list", 1.228 + params = { 1.229 + issue = initiative.issue, 1.230 + initiatives_selector = Initiative:new_selector():add_where{ "initiative.id = ?", initiative.id }, 1.231 + per_page = initiatives_per_page, 1.232 + no_sort = true 1.233 + } 1.234 + } 1.235 + end 1.236 + if timeline.suggestion then 1.237 + ui.link{ 1.238 + module = "suggestion", 1.239 + view = "show", 1.240 + id = timeline.suggestion.id, 1.241 + content = timeline.suggestion.name 1.242 + } 1.243 + end 1.244 end 1.245 - if timeline.suggestion then 1.246 - ui.link{ 1.247 - module = "suggestion", 1.248 - view = "show", 1.249 - id = timeline.suggestion.id, 1.250 - content = timeline.suggestion.name 1.251 - } 1.252 - end 1.253 - end 1.254 - }, 1.255 + }, 1.256 + } 1.257 } 1.258 - } 1.259 - end 1.260 -} 1.261 \ No newline at end of file 1.262 + end 1.263 + } 1.264 +end