liquid_feedback_frontend
view app/main/initiative/show_tab.lua @ 118:93f4e465b50d
add initiator support in delegation
if a delegation is issued from the initiative view, the initiators
from that one are added to the delegation target list. this makes it easier to delegate to the author without the need to add him to the contact list.
if a delegation is issued from the initiative view, the initiators
from that one are added to the delegation target list. this makes it easier to delegate to the author without the need to add him to the contact list.
| author | Daniel Poelzleithner <poelzi@poelzi.org> | 
|---|---|
| date | Mon Sep 20 20:32:04 2010 +0200 (2010-09-20) | 
| parents | 0849be391140 | 
| children | 65a1f7a01e7b | 
 line source
     1 local initiative = param.get("initiative", "table")
     2 local initiator = param.get("initiator", "table")
     4 if not initiative then
     5   initiative = Initiative:by_id(param.get("initiative_id", atom.number))
     6 end
     8 if not initiator and app.session.member_id then
     9   initiator = Initiator:by_pk(initiative.id, app.session.member.id)
    10 end
    12 local current_draft_name = _"Current draft"
    13 if initiative.issue.half_frozen then
    14   current_draft_name = _"Voting proposal"
    15 end
    17 if initiative.issue.state == "finished" then
    18   current_draft_name = _"Voted proposal"
    19 end
    21 local tabs = {
    22   {
    23     name = "current_draft",
    24     label = current_draft_name,
    25     icon = { static = "icons/16/script.png" },
    26     module = "initiative",
    27     view = "_current_draft",
    28     params = {
    29       initiative = initiative,
    30       initiator = initiator
    31     }
    32   }
    33 }
    35 if app.session.member_id then
    36   if initiative.issue.ranks_available then
    37     tabs[#tabs+1] = {
    38       name = "voting",
    39       label = _"Voting details",
    40       icon = { static = "icons/16/email_open.png" },
    41       module = "initiative",
    42       view = "_show_voting",
    43       params = {
    44         initiative = initiative
    45       }
    46     }
    47   end
    48 end
    50 local suggestion_count = initiative:get_reference_selector("suggestions"):count()
    52 tabs[#tabs+1] = {
    53   name = "suggestions",
    54   label = _"Suggestions" .. " (" .. tostring(suggestion_count) .. ")",
    55   icon = { static = "icons/16/comments.png" },
    56   module = "initiative",
    57   view = "_suggestions",
    58   params = {
    59     initiative = initiative
    60   }
    61 }
    63 if app.session.member_id then
    64   local members_selector = initiative:get_reference_selector("supporting_members_snapshot")
    65             :join("issue", nil, "issue.id = direct_supporter_snapshot.issue_id")
    66             :join("direct_interest_snapshot", nil, "direct_interest_snapshot.event = issue.latest_snapshot_event AND direct_interest_snapshot.issue_id = issue.id AND direct_interest_snapshot.member_id = member.id")
    67             :add_field("direct_interest_snapshot.weight")
    68             :add_where("direct_supporter_snapshot.event = issue.latest_snapshot_event")
    69             :add_where("direct_supporter_snapshot.satisfied")
    70             :add_field("direct_supporter_snapshot.informed", "is_informed")
    72   local tmp = db:query("SELECT count(1) AS count, sum(weight) AS weight FROM (" .. tostring(members_selector) .. ") as subquery", "object")
    73   local direct_satisfied_supporter_count = tmp.count
    74   local indirect_satisfied_supporter_count = (tmp.weight or 0) - tmp.count
    76   local count_string
    77   if indirect_satisfied_supporter_count > 0 then
    78     count_string = "(" .. tostring(direct_satisfied_supporter_count) .. "+" .. tostring(indirect_satisfied_supporter_count) .. ")"
    79   else
    80     count_string = "(" .. tostring(direct_satisfied_supporter_count) .. ")"
    81   end
    83   tabs[#tabs+1] = {
    84     name = "satisfied_supporter",
    85     label = _"Supporter" .. " " .. count_string,
    86     icon = { static = "icons/16/thumb_up_green.png" },
    87     module = "member",
    88     view = "_list",
    89     params = {
    90       initiative = initiative,
    91       members_selector = members_selector
    92     }
    93   }
    95   local members_selector = initiative:get_reference_selector("supporting_members_snapshot")
    96             :join("issue", nil, "issue.id = direct_supporter_snapshot.issue_id")
    97             :join("direct_interest_snapshot", nil, "direct_interest_snapshot.event = issue.latest_snapshot_event AND direct_interest_snapshot.issue_id = issue.id AND direct_interest_snapshot.member_id = member.id")
    98             :add_field("direct_interest_snapshot.weight")
    99             :add_where("direct_supporter_snapshot.event = issue.latest_snapshot_event")
   100             :add_where("NOT direct_supporter_snapshot.satisfied")
   101             :add_field("direct_supporter_snapshot.informed", "is_informed")
   103   local tmp = db:query("SELECT count(1) AS count, sum(weight) AS weight FROM (" .. tostring(members_selector) .. ") as subquery", "object")
   104   local direct_potential_supporter_count = tmp.count
   105   local indirect_potential_supporter_count = (tmp.weight or 0) - tmp.count
   107   local count_string
   108   if indirect_potential_supporter_count > 0 then
   109     count_string = "(" .. tostring(direct_potential_supporter_count) .. "+" .. tostring(indirect_potential_supporter_count) .. ")"
   110   else
   111     count_string = "(" .. tostring(direct_potential_supporter_count) .. ")"
   112   end
   114   tabs[#tabs+1] = {
   115     name = "supporter",
   116     label = _"Potential supporter" .. " " .. count_string,
   117     icon = { static = "icons/16/thumb_up.png" },
   118     module = "member",
   119     view = "_list",
   120     params = {
   121       initiative = initiative,
   122       members_selector = members_selector
   123     }
   124   }
   126   local initiators_members_selector = initiative:get_reference_selector("initiating_members")
   127     :add_field("initiator.accepted", "accepted")
   129   if not (initiator and initiator.accepted) then
   130     initiators_members_selector:add_where("initiator.accepted")
   131   end
   133   local initiator_count = initiators_members_selector:count()
   135   tabs[#tabs+1] = {
   136     name = "initiators",
   137     label = _"Initiators" .. " (" .. tostring(initiator_count) .. ")",
   138     icon = { static = "icons/16/user_edit.png" },
   139     module = "initiative",
   140     view = "_initiators",
   141     params = {
   142       initiative = initiative,
   143       initiator = initiator,
   144       initiators_members_selector = initiators_members_selector
   145     }
   146   }
   147 end
   149 local drafts_count = initiative:get_reference_selector("drafts"):count()
   151 tabs[#tabs+1] = {
   152   name = "drafts",
   153   label = _"Draft history" .. " (" .. tostring(drafts_count) .. ")",
   154   icon = { static = "icons/16/script.png" },
   155   module = "draft",
   156   view = "_list",
   157   params = { drafts = initiative.drafts }
   158 }
   160 tabs[#tabs+1] = {
   161   name = "details",
   162   label = _"Details",
   163   icon = { static = "icons/16/magnifier.png" },
   164   module = "initiative",
   165   view = "_details",
   166   params = {
   167     initiative = initiative,
   168     members_selector = members_selector
   169   }
   170 }
   172 tabs.module = "initiative"
   173 tabs.view = "show_tab"
   174 tabs.static_params = {
   175   initiative_id = initiative.id
   176 }
   178 ui.tabs(tabs)
