liquid_feedback_frontend
view app/main/draft/diff.lua @ 159:5d797c6706d5
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
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
author | Daniel Poelzleithner <poelzi@poelzi.org> |
---|---|
date | Sat Oct 09 03:42:48 2010 +0200 (2010-10-09) |
parents | 6a12fb7e4963 |
children | cc7650c7053f |
line source
1 local old_draft_id = param.get("old_draft_id", atom.integer)
2 local new_draft_id = param.get("new_draft_id", atom.integer)
4 if not old_draft_id or not new_draft_id then
5 slot.put( _"Please choose two versions of the draft to compare")
6 return
7 end
9 if old_draft_id == new_draft_id then
10 slot.put( _"Please choose two different versions of the draft to compare")
11 return
12 end
14 if old_draft_id > new_draft_id then
15 local tmp = old_draft_id
16 old_draft_id = new_draft_id
17 new_draft_id = tmp
18 end
20 local old_draft = Draft:by_id(old_draft_id)
21 local new_draft = Draft:by_id(new_draft_id)
23 local initiative = new_draft.initiative
24 local issue = initiative.issue
26 slot.select("title", function()
27 ui.link{
28 content = issue.area.name,
29 module = "area",
30 view = "show",
31 id = issue.area.id
32 }
33 slot.put(" · ")
34 ui.link{
35 content = _("Issue ##{id}", { id = issue.id }),
36 module = "issue",
37 view = "show",
38 id = issue.id
39 }
40 slot.put(" · ")
41 ui.link{
42 content = _("Initiative: ")..initiative.name,
43 module = "initiative",
44 view = "show",
45 id = initiative.id
46 }
47 slot.put(" · ")
48 slot.put_into("title", _"Diff")
50 end)
52 if app.session.member_id and not new_draft.initiative.revoked then
53 local supporter = Supporter:new_selector():add_where{"member_id = ?", app.session.member_id}:count()
54 if supporter then
55 ui.container{
56 attr = { class = "draft_updated_info" },
57 content = function()
58 slot.put(_"The draft of this initiative has been updated!")
59 slot.put(" ")
60 ui.link{
61 text = _"Refresh support to current draft",
62 module = "initiative",
63 action = "add_support",
64 id = new_draft.initiative.id,
65 routing = {
66 default = {
67 mode = "redirect",
68 module = "initiative",
69 view = "show",
70 id = new_draft.initiative.id
71 }
72 }
73 }
74 end
75 }
76 end
77 end
79 local old_draft_content = string.gsub(string.gsub(old_draft.content, "\n", " ###ENTER###\n"), " ", "\n")
80 local new_draft_content = string.gsub(string.gsub(new_draft.content, "\n", " ###ENTER###\n"), " ", "\n")
82 local key = multirand.string(26, "123456789bcdfghjklmnpqrstvwxyz");
84 local old_draft_filename = encode.file_path(request.get_app_basepath(), 'tmp', "diff-" .. key .. "-old.tmp")
85 local new_draft_filename = encode.file_path(request.get_app_basepath(), 'tmp', "diff-" .. key .. "-new.tmp")
87 local old_draft_file = assert(io.open(old_draft_filename, "w"))
88 old_draft_file:write(old_draft_content)
89 old_draft_file:write("\n")
90 old_draft_file:close()
92 local new_draft_file = assert(io.open(new_draft_filename, "w"))
93 new_draft_file:write(new_draft_content)
94 new_draft_file:write("\n")
95 new_draft_file:close()
97 local output, err, status = os.pfilter(nil, "sh", "-c", "diff -U 1000000000 '" .. old_draft_filename .. "' '" .. new_draft_filename .. "' | grep -v ^--- | grep -v ^+++ | grep -v ^@")
99 os.remove(old_draft_filename)
100 os.remove(new_draft_filename)
102 local last_state = "first_run"
104 local function process_line(line)
105 local state_char = string.sub(line, 1, 1)
106 local state
107 if state_char == "+" then
108 state = "added"
109 elseif state_char == "-" then
110 state = "removed"
111 elseif state_char == " " then
112 state = "unchanged"
113 end
114 local state_changed = false
115 if state ~= last_state then
116 if last_state ~= "first_run" then
117 slot.put("</span> ")
118 end
119 last_state = state
120 state_changed = true
121 slot.put("<span class=\"diff_" .. tostring(state) .. "\">")
122 end
124 line = string.sub(line, 2, #line)
125 if line ~= "###ENTER###" then
126 if not state_changed then
127 slot.put(" ")
128 end
129 slot.put(line)
130 else
131 slot.put("<br />")
132 end
133 end
135 if not status then
136 ui.field.text{ value = _"The drafts do not differ" }
137 else
138 ui.container{
139 tag = "div",
140 attr = { class = "diff" },
141 content = function()
142 output = output:gsub("[^\n\r]+", function(line)
143 process_line(line)
144 end)
145 end
146 }
147 end