Commits

Daniel Poelzleithner  committed 5d797c6

implement quorum display

show the initiative quorum as a small 1px line in bargraph
allow to update your support on the diff page
better linked title in diff page
show absolute quorum numbers in detail pages of issue and initiative

  • Participants
  • Parent commits 39d49cf

Comments (0)

Files changed (5)

File app/main/draft/diff.lua

-slot.put_into("title", _"Diff")
-
 local old_draft_id = param.get("old_draft_id", atom.integer)
 local new_draft_id = param.get("new_draft_id", atom.integer)
 
 local old_draft = Draft:by_id(old_draft_id)
 local new_draft = Draft:by_id(new_draft_id)
 
+local initiative = new_draft.initiative
+local issue = initiative.issue
+
+slot.select("title", function()
+  ui.link{
+    content = issue.area.name,
+    module = "area",
+    view = "show",
+    id = issue.area.id
+  }
+  slot.put(" · ")
+  ui.link{
+    content = _("Issue ##{id}", { id = issue.id }),
+    module = "issue",
+    view = "show",
+    id = issue.id
+  }
+  slot.put(" · ")
+  ui.link{
+    content = _("Initiative: ")..initiative.name,
+    module = "initiative",
+    view = "show",
+    id = initiative.id
+  }
+  slot.put(" · ")
+  slot.put_into("title", _"Diff")
+
+end)
+
+if app.session.member_id and not new_draft.initiative.revoked then
+  local supporter = Supporter:new_selector():add_where{"member_id = ?", app.session.member_id}:count()
+  if supporter then
+    ui.container{
+      attr = { class = "draft_updated_info" },
+      content = function()
+        slot.put(_"The draft of this initiative has been updated!")
+        slot.put(" ")
+        ui.link{
+          text   = _"Refresh support to current draft",
+          module = "initiative",
+          action = "add_support",
+          id     = new_draft.initiative.id,
+          routing = {
+            default = {
+              mode = "redirect",
+              module = "initiative",
+              view = "show",
+              id = new_draft.initiative.id
+            }
+          }
+        }
+      end
+    }
+  end
+end
+
 local old_draft_content = string.gsub(string.gsub(old_draft.content, "\n", " ###ENTER###\n"), " ", "\n")
 local new_draft_content = string.gsub(string.gsub(new_draft.content, "\n", " ###ENTER###\n"), " ", "\n")
 

File app/main/initiative/_details.lua

   record = initiative,
   readonly = true,
   content = function()
+    local policy = initiative.issue.policy
     ui.field.text{ label = _"Issue policy", value = initiative.issue.policy.name }
     ui.field.text{
       label = _"Created at",
       value = tostring(initiative.created)
     }
+    if initiative.revoked then
+      ui.field.text{
+         label = _"Revoked at",
+         value = format.timestamp(initiative.revoked)
+       }
+    end
     ui.field.text{
-      label = _"Created at",
-      value = format.timestamp(initiative.created)
+      label   = _"Initiative quorum",
+      value = format.percentage(policy.initiative_quorum_num / policy.initiative_quorum_den)
+    }
+    ui.field.text{
+      label   = _"Currently required",
+      value = math.ceil(initiative.issue.population * (policy.initiative_quorum_num / policy.initiative_quorum_den)),
     }
   -- ui.field.date{ label = _"Revoked at", name = "revoked" }
     ui.field.boolean{ label = _"Admitted", name = "admitted" }

File app/main/initiative/_list_element.lua

                   ui.bargraph{
                     max_value = max_value,
                     width = 100,
+                    quorum = max_value * (initiative.issue.policy.initiative_quorum_num / initiative.issue.policy.initiative_quorum_den),
+                    quorum_color = "#00F",
                     bars = {
                       { color = "#0a0", value = (initiative.satisfied_supporter_count or 0) },
                       { color = "#bbb", value = (initiative.supporter_count or 0) - (initiative.satisfied_supporter_count or 0) },

File app/main/issue/_details.lua

       label = _"Issue quorum",
       value = format.percentage(policy.issue_quorum_num / policy.issue_quorum_den)
     }
+    ui.field.text{
+      label = _"Currently required",
+      value = math.ceil(issue.population * policy.issue_quorum_num / policy.issue_quorum_den)
+    }
     ui.field.timestamp{  label = _"Accepted at",           name = "accepted" }
     ui.field.text{       label = _"Discussion time",       value = issue.discussion_time }
     ui.field.vote_now{   label = _"Vote now",              name = "vote_now" }
       label   = _"Initiative quorum",
       value = format.percentage(policy.initiative_quorum_num / policy.initiative_quorum_den)
     }
+    ui.field.text{
+      label   = _"Currently required",
+      value = math.ceil(issue.population * (issue.policy.initiative_quorum_num / issue.policy.initiative_quorum_den)),
+    }
     ui.field.timestamp{  label = _"Fully frozen at",       name = "fully_frozen" }
     ui.field.text{       label = _"Voting time",           value = issue.voting_time }
     ui.field.timestamp{  label = _"Closed",                name = "closed" }

File env/ui/bargraph.lua

     },
     content = function()
       local at_least_one_bar = false
+      local quorum = args.quorum and args.quorum * args.width / args.max_value or nil
+      local length = 0
       for i, bar in ipairs(args.bars) do
         if bar.value > 0 then
           at_least_one_bar = true
           local value = bar.value * args.width / args.max_value
+          if quorum and quorum < length + value then
+            local dlength = math.max(quorum - length - 1, 0)
+            if dlength > 0 then
+              ui.container{
+                attr = {
+                  style = "width: " .. tostring(dlength) .. "px; background-color: " .. bar.color .. ";",
+                },
+                content = function() slot.put("&nbsp;") end
+              }
+            end
+            ui.container{
+              attr = {
+                style = "width: 1px; background-color: " .. (args.quorum_color or "blue") ..";",
+              },
+              content = function() slot.put("&nbsp;") end
+            }
+            length = dlength + 1
+            value = value - dlength
+            quorum = nil
+          end
+          length = length + value
           ui.container{
             attr = {
               style = "width: " .. tostring(value) .. "px; background-color: " .. bar.color .. ";",