liquid_feedback_frontend

annotate app/main/initiative/show.lua @ 1500:71f54c43d7cb

Added API support interface
author bsw
date Tue Mar 24 16:59:32 2020 +0100 (2020-03-24)
parents ed3c40911ae1
children 056bccb61eee
rev   line source
bsw@1045 1 local initiative = Initiative:by_id ( param.get_id() )
bsw@1045 2 local member = app.session.member
bsw@1045 3
bsw@1045 4 if not initiative then
bsw@1045 5 execute.view { module = "index", view = "404" }
bsw@1045 6 request.set_status("404 Not Found")
bsw@1045 7 return
bsw@1045 8 end
bsw@1045 9
bsw/jbe@1309 10 app.current_initiative = initiative
bsw/jbe@1309 11
bsw@1045 12 local issue_info
bsw@1045 13
bsw@1045 14 if member then
bsw@1045 15 initiative:load_everything_for_member_id(member.id)
bsw@1045 16 initiative.issue:load_everything_for_member_id(member.id)
bsw@1045 17 issue_info = initiative.issue.member_info
bsw@1045 18 end
bsw@1045 19
bsw@1145 20 local direct_supporter
bsw@1145 21
bsw@1045 22 if app.session.member_id then
bsw@1045 23 direct_supporter = initiative.issue.member_info.own_participation and initiative.member_info.supported
bsw@1045 24 end
bsw@718 25
bsw/jbe@1309 26 slot.put_into("header", initiative.display_name)
bsw@1045 27
bsw/jbe@1309 28 execute.view{ module = "issue", view = "_head", params = { issue = initiative.issue, link_issue = true } }
bsw@1045 29
bsw/jbe@1309 30 ui.grid{ content = function()
bsw@1045 31
bsw/jbe@1309 32 ui.cell_main{ content = function()
bsw/jbe@1309 33 ui.container{ attr = { class = "mdl-card mdl-card__fullwidth mdl-shadow--2dp" }, content = function()
bsw/jbe@1309 34 execute.view{
bsw/jbe@1309 35 module = "initiative", view = "_head", params = {
bsw/jbe@1309 36 initiative = initiative
bsw@1045 37 }
bsw/jbe@1309 38 }
bsw@1045 39
bsw/jbe@1309 40 if direct_supporter and not initiative.issue.closed then
bsw/jbe@1309 41 local supporter = app.session.member:get_reference_selector("supporters")
bsw/jbe@1309 42 :add_where{ "initiative_id = ?", initiative.id }
bsw/jbe@1309 43 :optional_object_mode()
bsw/jbe@1309 44 :exec()
bsw/jbe@1309 45
bsw/jbe@1309 46 if supporter then
bsw@1045 47
bsw/jbe@1309 48 local old_draft_id = supporter.draft_id
bsw/jbe@1309 49 local new_draft_id = initiative.current_draft.id
bsw/jbe@1309 50
bsw/jbe@1309 51 if old_draft_id ~= new_draft_id then
bsw/jbe@1309 52 ui.container {
bsw/jbe@1309 53 attr = { class = "mdl-card__content mdl-card--no-bottom-pad mdl-card--notice" },
bsw/jbe@1309 54 content = _"The draft of this initiative has been updated!"
bsw/jbe@1309 55 }
bsw/jbe@1309 56 ui.container {
bsw/jbe@1309 57 attr = { class = "mdl-card__actions mdl-card--action-border mdl-card--notice" },
bsw/jbe@1309 58 content = function ()
bsw/jbe@1309 59 if not initiative.revoked then
bsw/jbe@1309 60 ui.link{
bsw/jbe@1309 61 attr = { class = "mdl-button mdl-js-button mdl-button--raised" },
bsw/jbe@1309 62 text = _"refresh my support",
bsw/jbe@1309 63 module = "initiative",
bsw/jbe@1309 64 action = "add_support",
bsw/jbe@1309 65 id = initiative.id,
bsw/jbe@1309 66 params = { draft_id = initiative.current_draft.id },
bsw/jbe@1309 67 routing = {
bsw/jbe@1309 68 default = {
bsw/jbe@1309 69 mode = "redirect",
bsw/jbe@1309 70 module = "initiative",
bsw/jbe@1309 71 view = "show",
bsw/jbe@1309 72 id = initiative.id
bsw/jbe@1309 73 }
bsw/jbe@1309 74 }
bsw/jbe@1309 75 }
bsw/jbe@1309 76 slot.put("   ")
bsw/jbe@1309 77 ui.link{
bsw/jbe@1309 78 attr = { class = "mdl-button mdl-js-button mdl-button--raised" },
bsw/jbe@1309 79 content = _"show differences",
bsw/jbe@1309 80 module = "draft",
bsw/jbe@1309 81 view = "diff",
bsw/jbe@1309 82 params = {
bsw/jbe@1309 83 old_draft_id = old_draft_id,
bsw/jbe@1309 84 new_draft_id = new_draft_id
bsw/jbe@1309 85 }
bsw/jbe@1309 86 }
bsw/jbe@1309 87 slot.put("   ")
bsw@1045 88 end
bsw/jbe@1309 89 ui.link{
bsw/jbe@1309 90 attr = { class = "mdl-button mdl-js-button mdl-button--raised" },
bsw/jbe@1309 91 text = _"remove my support",
bsw/jbe@1309 92 module = "initiative",
bsw/jbe@1309 93 action = "remove_support",
bsw/jbe@1309 94 id = initiative.id,
bsw/jbe@1309 95 routing = {
bsw/jbe@1309 96 default = {
bsw/jbe@1309 97 mode = "redirect",
bsw/jbe@1309 98 module = "initiative",
bsw/jbe@1309 99 view = "show",
bsw/jbe@1309 100 id = initiative.id
bsw@1045 101 }
bsw@1045 102 }
bsw@1061 103 }
bsw@1061 104
bsw/jbe@1309 105 end
bsw/jbe@1309 106 }
bsw/jbe@1309 107 end
bsw/jbe@1309 108 end
bsw/jbe@1309 109 end
bsw/jbe@1309 110
bsw/jbe@1309 111 if config.render_external_reference and config.render_external_reference.initiative then
bsw/jbe@1309 112 config.render_external_reference.initiative(initiative, function (callback)
bsw/jbe@1309 113 ui.sectionRow(callback)
bsw/jbe@1309 114 end)
bsw/jbe@1309 115 end
bsw/jbe@1309 116 local draft_content = initiative.current_draft.content
bsw/jbe@1309 117 if config.initiative_abstract then
bsw/jbe@1309 118 local abstract = string.match(draft_content, "(.+)<!%--END_OF_ABSTRACT%-->")
bsw/jbe@1309 119 if abstract then
bsw/jbe@1309 120 draft_content = string.match(draft_content, "<!%--END_OF_ABSTRACT%-->(.*)")
bsw/jbe@1309 121 end
bsw/jbe@1309 122 end
bsw/jbe@1309 123 ui.container {
bsw/jbe@1309 124 attr = { class = "draft mdl-card__content mdl-card--border" },
bsw/jbe@1309 125 content = function ()
bsw/jbe@1309 126 if initiative.current_draft.formatting_engine == "html" or not initiative.current_draft.formatting_engine then
bsw/jbe@1309 127 if config.draft_filter then
bsw/jbe@1309 128 slot.put(config.draft_filter(draft_content))
bsw/jbe@1309 129 else
bsw/jbe@1309 130 slot.put(draft_content)
bsw@1045 131 end
bsw/jbe@1309 132 else
bsw/jbe@1309 133 slot.put ( initiative.current_draft:get_content ( "html" ) )
bsw/jbe@1309 134 end
bsw/jbe@1309 135 end
bsw/jbe@1309 136 }
bsw@1045 137
bsw@1495 138 if config.attachments then
bsw@1495 139
bsw@1495 140 local files = File:new_selector()
bsw@1495 141 :left_join("draft_attachment", nil, "draft_attachment.file_id = file.id")
bsw@1495 142 :add_where{ "draft_attachment.draft_id = ?", initiative.current_draft.id }
bsw@1495 143 :reset_fields()
bsw@1495 144 :add_field("file.id")
bsw@1495 145 :add_field("draft_attachment.title")
bsw@1495 146 :add_field("draft_attachment.description")
bsw@1495 147 :add_order_by("draft_attachment.id")
bsw@1495 148 :exec()
bsw@1495 149
bsw@1495 150 if #files > 0 then
bsw@1495 151 ui.container {
bsw@1495 152 attr = { class = "mdl-card__content mdl-card--border" },
bsw@1495 153 content = function()
bsw@1495 154 for i, file in ipairs(files) do
bsw@1495 155 ui.link{ module = "file", view = "show.jpg", id = file.id, content = function()
bsw@1495 156 ui.image{ module = "file", view = "show.jpg", id = file.id, params = { preview = true } }
bsw@1495 157 end }
bsw@1496 158 ui.container{ content = function()
bsw@1496 159 ui.tag{ tag = "strong", content = file.title or "" }
bsw@1496 160 end }
bsw@1495 161 ui.container{ content = file.description or "" }
bsw@1495 162 slot.put("<br /><br />")
bsw@1495 163 end
bsw@1495 164 end
bsw@1495 165 }
bsw@1495 166 end
bsw@1495 167 end
bsw@1495 168
bsw/jbe@1309 169 local drafts_count = initiative:get_reference_selector("drafts"):count()
bsw@1045 170
bsw/jbe@1309 171 if not config.voting_only then
bsw/jbe@1309 172 ui.container {
bsw/jbe@1309 173 attr = { class = "mdl-card__actions" },
bsw/jbe@1309 174 content = function()
bsw/jbe@1309 175 ui.link{
bsw/jbe@1309 176 attr = { class = "mdl-button mdl-js-button" },
bsw/jbe@1309 177 module = "initiative", view = "history", id = initiative.id,
bsw/jbe@1309 178 content = _("draft history (#{count})", { count = drafts_count })
bsw/jbe@1309 179 }
bsw/jbe@1309 180 end
bsw/jbe@1309 181 }
bsw@1045 182 end
bsw/jbe@1309 183
bsw/jbe@1309 184 end }
bsw/jbe@1309 185
bsw/jbe@1309 186 execute.view{ module = "initiative", view = "_suggestions", params = { initiative = initiative } }
bsw@1045 187
bsw/jbe@1309 188 end }
bsw/jbe@1309 189
bsw/jbe@1309 190 ui.cell_sidebar{ content = function()
bsw/jbe@1309 191 if config.logo then
bsw/jbe@1309 192 config.logo()
bsw/jbe@1309 193 end
bsw/jbe@1309 194 execute.view {
bsw/jbe@1309 195 module = "issue", view = "_sidebar",
bsw/jbe@1309 196 params = {
bsw/jbe@1309 197 issue = initiative.issue,
bsw/jbe@1309 198 initiative = initiative,
bsw/jbe@1309 199 member = app.session.member
bsw/jbe@1309 200 }
bsw/jbe@1309 201 }
bsw/jbe@1309 202
bsw/jbe@1309 203 execute.view {
bsw/jbe@1309 204 module = "issue", view = "_sidebar_whatcanido",
bsw/jbe@1309 205 params = {
bsw/jbe@1309 206 issue = initiative.issue,
bsw/jbe@1309 207 initiative = initiative,
bsw/jbe@1309 208 member = app.session.member
bsw/jbe@1309 209 }
bsw/jbe@1309 210 }
bsw/jbe@1309 211
bsw/jbe@1309 212 execute.view {
bsw/jbe@1309 213 module = "issue", view = "_sidebar_members", params = {
bsw/jbe@1309 214 issue = initiative.issue, initiative = initiative
bsw/jbe@1309 215 }
bsw/jbe@1309 216 }
bsw/jbe@1309 217
bsw/jbe@1309 218 end }
bsw/jbe@1309 219
bsw/jbe@1309 220 end }

Impressum / About Us