liquid_feedback_frontend
view app/main/initiative/show_tab.lua @ 381:b155ca3744c5
Rearanged delegatee icons in area list to make everything fit better
| author | bsw | 
|---|---|
| date | Mon Mar 05 11:31:27 2012 +0100 (2012-03-05) | 
| parents | 808269b7f41c | 
| children | 63d6549cc00b | 
 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 = "draft",
    27     view = "_show",
    28     params = {
    29       draft = initiative.current_draft
    30     }
    31   }
    32 }
    34 if app.session.member_id then
    35   if initiative.issue.ranks_available then
    36     tabs[#tabs+1] = {
    37       name = "voting",
    38       label = _"Voting details",
    39       icon = { static = "icons/16/email_open.png" },
    40       module = "initiative",
    41       view = "_show_voting",
    42       params = {
    43         initiative = initiative
    44       }
    45     }
    46   end
    47 end
    49 local suggestion_count = initiative:get_reference_selector("suggestions"):count()
    51 tabs[#tabs+1] = {
    52   name = "suggestions",
    53   label = _"Suggestions" .. " (" .. tostring(suggestion_count) .. ")",
    54   icon = { static = "icons/16/comments.png" },
    55   module = "initiative",
    56   view = "_suggestions",
    57   params = {
    58     initiative = initiative
    59   }
    60 }
    62 if app.session.member_id then
    63   local members_selector = initiative:get_reference_selector("supporting_members_snapshot")
    64             :join("issue", nil, "issue.id = direct_supporter_snapshot.issue_id")
    65             :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")
    66             :add_field("direct_interest_snapshot.weight")
    67             :add_where("direct_supporter_snapshot.event = issue.latest_snapshot_event")
    68             :add_where("direct_supporter_snapshot.satisfied")
    69             :add_field("direct_supporter_snapshot.informed", "is_informed")
    71   local tmp = db:query("SELECT count(1) AS count, sum(weight) AS weight FROM (" .. tostring(members_selector) .. ") as subquery", "object")
    72   local direct_satisfied_supporter_count = tmp.count
    73   local indirect_satisfied_supporter_count = (tmp.weight or 0) - tmp.count
    75   local count_string
    76   if indirect_satisfied_supporter_count > 0 then
    77     count_string = "(" .. tostring(direct_satisfied_supporter_count) .. "+" .. tostring(indirect_satisfied_supporter_count) .. ")"
    78   else
    79     count_string = "(" .. tostring(direct_satisfied_supporter_count) .. ")"
    80   end
    82   tabs[#tabs+1] = {
    83     name = "satisfied_supporter",
    84     label = _"Supporter" .. " " .. count_string,
    85     icon = { static = "icons/16/thumb_up_green.png" },
    86     module = "member",
    87     view = "_list",
    88     params = {
    89       initiative = initiative,
    90       members_selector = members_selector
    91     }
    92   }
    94   local members_selector = initiative:get_reference_selector("supporting_members_snapshot")
    95             :join("issue", nil, "issue.id = direct_supporter_snapshot.issue_id")
    96             :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")
    97             :add_field("direct_interest_snapshot.weight")
    98             :add_where("direct_supporter_snapshot.event = issue.latest_snapshot_event")
    99             :add_where("NOT direct_supporter_snapshot.satisfied")
   100             :add_field("direct_supporter_snapshot.informed", "is_informed")
   102   local tmp = db:query("SELECT count(1) AS count, sum(weight) AS weight FROM (" .. tostring(members_selector) .. ") as subquery", "object")
   103   local direct_potential_supporter_count = tmp.count
   104   local indirect_potential_supporter_count = (tmp.weight or 0) - tmp.count
   106   local count_string
   107   if indirect_potential_supporter_count > 0 then
   108     count_string = "(" .. tostring(direct_potential_supporter_count) .. "+" .. tostring(indirect_potential_supporter_count) .. ")"
   109   else
   110     count_string = "(" .. tostring(direct_potential_supporter_count) .. ")"
   111   end
   113   tabs[#tabs+1] = {
   114     name = "supporter",
   115     label = _"Potential supporter" .. " " .. count_string,
   116     icon = { static = "icons/16/thumb_up.png" },
   117     module = "member",
   118     view = "_list",
   119     params = {
   120       initiative = initiative,
   121       members_selector = members_selector
   122     }
   123   }
   125 end
   127 local drafts_count = initiative:get_reference_selector("drafts"):count()
   129 tabs[#tabs+1] = {
   130   name = "drafts",
   131   label = _"Draft history" .. " (" .. tostring(drafts_count) .. ")",
   132   icon = { static = "icons/16/script.png" },
   133   module = "draft",
   134   view = "_list",
   135   params = { drafts = initiative.drafts }
   136 }
   138 tabs[#tabs+1] = {
   139   name = "details",
   140   label = _"Details",
   141   icon = { static = "icons/16/magnifier.png" },
   142   module = "initiative",
   143   view = "_details",
   144   params = {
   145     initiative = initiative,
   146     members_selector = members_selector
   147   }
   148 }
   150 tabs.module = "initiative"
   151 tabs.view = "show_tab"
   152 tabs.static_params = {
   153   initiative_id = initiative.id
   154 }
   156 ui.tabs(tabs)
