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