bsw@2: local old_draft_id = param.get("old_draft_id", atom.integer) bsw@2: local new_draft_id = param.get("new_draft_id", atom.integer) bsw@1045: local initiative_id = param.get("initiative_id", atom.number) bsw@2: bsw@1045: if not old_draft_id bsw@1045: or not new_draft_id bsw@1045: or old_draft_id == new_draft_id bsw@1045: then bsw@1045: slot.reset_all() bsw@1045: slot.select("error", function() bsw@1045: ui.tag{ content = _"Please choose two different versions of the draft to compare" } bsw@1045: end ) bsw@1045: request.redirect{ bsw@1045: module = "draft", view = "list", params = { bsw@1045: initiative_id = initiative_id bsw@1045: } bsw@1045: } bsw@10: return bsw@10: end bsw@10: bsw@2: if old_draft_id > new_draft_id then jbe@1226: old_draft_id, new_draft_id = new_draft_id, old_draft_id bsw@2: end bsw@2: bsw@2: local old_draft = Draft:by_id(old_draft_id) bsw@2: local new_draft = Draft:by_id(new_draft_id) bsw@2: bsw@1045: local initiative = new_draft.initiative bsw@1045: bsw@1045: if app.session.member then bsw@1045: initiative:load_everything_for_member_id(app.session.member_id) bsw@1045: initiative.issue:load_everything_for_member_id(app.session.member_id) bsw@1045: end bsw@1045: bsw@1045: bsw@1045: execute.view{ module = "issue", view = "_sidebar_state", params = { bsw@1045: initiative = initiative bsw@1045: } } bsw@1045: bsw@1045: execute.view { bsw@1045: module = "issue", view = "_sidebar_issue", bsw@1045: params = { bsw@1045: issue = initiative.issue, bsw@1045: highlight_initiative_id = initiative.id bsw@1045: } poelzi@160: } poelzi@159: bsw@1045: execute.view { bsw@1045: module = "issue", view = "_sidebar_whatcanido", bsw@1045: params = { initiative = initiative } bsw@1045: } poelzi@159: bsw@1045: execute.view { bsw@1045: module = "issue", view = "_sidebar_members", params = { bsw@1045: issue = initiative.issue, initiative = initiative bsw@1045: } bsw@1045: } bsw@1045: bsw@1045: bsw@1045: bsw@1045: execute.view { bsw@1045: module = "issue", view = "_head", params = { bsw@1045: issue = initiative.issue bsw@1045: } bsw@1045: } bsw@1045: bsw@1045: poelzi@159: bsw@95: local old_draft_content = string.gsub(string.gsub(old_draft.content, "\n", " ###ENTER###\n"), " ", "\n") bsw@95: local new_draft_content = string.gsub(string.gsub(new_draft.content, "\n", " ###ENTER###\n"), " ", "\n") bsw@95: jbe@1226: local key = multirand.string(24, "0123456789abcdefghijklmnopqrstuvwxyz") bsw@2: bsw@1230: local old_draft_filename = encode.file_path(WEBMCP_BASE_PATH, 'tmp', "diff-" .. key .. "-old.tmp") bsw@1230: local new_draft_filename = encode.file_path(WEBMCP_BASE_PATH, 'tmp', "diff-" .. key .. "-new.tmp") bsw@2: bsw@2: local old_draft_file = assert(io.open(old_draft_filename, "w")) bsw@95: old_draft_file:write(old_draft_content) bsw@2: old_draft_file:write("\n") bsw@2: old_draft_file:close() bsw@2: bsw@2: local new_draft_file = assert(io.open(new_draft_filename, "w")) bsw@95: new_draft_file:write(new_draft_content) bsw@2: new_draft_file:write("\n") bsw@2: new_draft_file:close() bsw@2: bsw@728: local output, err, status = extos.pfilter(nil, "sh", "-c", "diff -U 1000000000 '" .. old_draft_filename .. "' '" .. new_draft_filename .. "' | grep -v ^--- | grep -v ^+++ | grep -v ^@") bsw@2: bsw@2: os.remove(old_draft_filename) bsw@2: os.remove(new_draft_filename) bsw@2: bsw@95: local last_state = "first_run" bsw@95: bsw@95: local function process_line(line) bsw@95: local state_char = string.sub(line, 1, 1) bsw@95: local state bsw@95: if state_char == "+" then bsw@95: state = "added" bsw@95: elseif state_char == "-" then bsw@95: state = "removed" bsw@95: elseif state_char == " " then bsw@95: state = "unchanged" bsw@95: end bsw@95: local state_changed = false bsw@95: if state ~= last_state then bsw@95: if last_state ~= "first_run" then bsw@95: slot.put(" ") bsw@95: end bsw@95: last_state = state bsw@95: state_changed = true bsw@95: slot.put("") bsw@95: end bsw@95: bsw@95: line = string.sub(line, 2, #line) bsw@95: if line ~= "###ENTER###" then bsw@95: if not state_changed then bsw@95: slot.put(" ") bsw@95: end bsw@953: slot.put(encode.html(line)) bsw@95: else bsw@95: slot.put("
") bsw@95: end bsw@95: end bsw@95: bsw@1045: ui.section( function() bsw@1045: ui.sectionHead( function() bsw@1045: ui.link{ bsw@1045: module = "initiative", view = "show", id = initiative.id, bsw@1045: content = function () bsw@1045: ui.heading { bsw@1045: level = 1, bsw@1045: content = initiative.display_name bsw@1045: } bsw@1045: end bsw@1045: } bsw@1045: ui.heading{ level = 2, content = _("Comparision of revisions #{id1} and #{id2}", { bsw@1045: id1 = old_draft.id, bsw@1045: id2 = new_draft.id bsw@1045: } ) } bsw@1045: end ) bsw@1045: bsw@1045: if app.session.member_id and not new_draft.initiative.revoked then bsw@1045: local supporter = app.session.member:get_reference_selector("supporters") bsw@1045: :add_where{ "initiative_id = ?", new_draft.initiative_id } bsw@1045: :optional_object_mode() bsw@1045: :exec() bsw@1045: if supporter and supporter.draft_id ~= new_draft.id then bsw@1045: ui.sectionRow("draft_updated_info", function() bsw@1045: ui.container{ bsw@1045: attr = { class = "info" }, bsw@1045: content = _"The draft of this initiative has been updated!" bsw@1045: } bsw@1045: slot.put(" ") bsw@1045: ui.link{ bsw@1045: text = _"refresh my support", bsw@1045: module = "initiative", bsw@1045: action = "add_support", bsw@1045: id = new_draft.initiative.id, bsw@1045: params = { draft_id = new_draft.id }, bsw@1045: routing = { bsw@1045: default = { bsw@1045: mode = "redirect", bsw@1045: module = "initiative", bsw@1045: view = "show", bsw@1045: id = new_draft.initiative.id bsw@1045: } bsw@1045: } bsw@1045: } bsw@1045: bsw@1045: slot.put(" · ") bsw@1045: bsw@1045: ui.link{ bsw@1045: text = _"remove my support", bsw@1045: module = "initiative", bsw@1045: action = "remove_support", bsw@1045: id = new_draft.initiative.id, bsw@1045: routing = { bsw@1045: default = { bsw@1045: mode = "redirect", bsw@1045: module = "initiative", bsw@1045: view = "show", bsw@1045: id = new_draft.initiative.id bsw@1045: } bsw@1045: } bsw@1045: } bsw@1045: bsw@1045: end ) bsw@2: end bsw@1045: end bsw@1045: bsw@1045: ui.sectionRow( function() bsw@2: bsw@1045: if not status then bsw@1045: ui.field.text{ value = _"The drafts do not differ" } bsw@1045: else bsw@1045: ui.container{ bsw@1045: tag = "div", bsw@1045: attr = { class = "diff" }, bsw@1045: content = function() bsw@1045: output = output:gsub("[^\n\r]+", function(line) bsw@1045: process_line(line) bsw@1045: end) bsw@1045: end bsw@1045: } bsw@1045: end bsw@1045: bsw@1045: end ) jbe@1226: end )