liquid_feedback_frontend

view app/main/draft/diff.lua @ 75:733f65c0c0a0

Bugfixes, feature enhancements, code-cleanup, and major work on API

Details:
- API
-- Allow relation name to be passed to helper function util.autoapi{...}
-- Added area API
-- Bugfixes in API
--- Correctly return initiatives (bug #162)
--- Correctly process "id" parameter for initiative API
--- Bugfix related to "state" parameter (bug #165)
--- Changed constant "discussion" to "accepted" (in model/issue.lua, used by API)
--- Fixed JSON encoding in auto_api (bug #181)
--- Ignore list filter "voted" in case of public access
--- Enable access to API without session
- Work on RSS feed (incomplete yet)
- Other bugfixes
-- Handle empty browser identification string
-- Handle invalid date in member/update.lua (bugs #24 #109 #115 #136)
-- Better handle errors while converting uploaded images. (bug #79 +5 duplicates)
-- Don't display revoked initiatives in list of new drafts (bug #134)
-- Fixed syntax error in app/main/member/_action/update_name.lua throwing unexpected error, when new name was too short
-- Do not display refresh support button for revoked initiatives
-- Repaired issue search (bug #150)
-- Fixed typos in german translation files
--- "initi(i)erte"
--- "Er(g)eignisse" (bug #161)
- Code cleanup
-- Removed deprecated motd files locale/motd/de.txt and locale/motd/de_public.txt
-- Removed redundant code in app/main/index/_updated_drafts.lua
- New features and (optical) enhancements
-- Support change of notify email; notification of not approved address added to start page
-- Settings dialog splitted into single pages
-- Mark deactivated members
-- Calendar for birthday selection in profile
-- Policy list public readable when public access is enabled
author bsw
date Thu Jul 08 18:44:02 2010 +0200 (2010-07-08)
parents ca3a0552927f
children 6a12fb7e4963
line source
1 slot.put_into("title", _"Diff")
3 local old_draft_id = param.get("old_draft_id", atom.integer)
4 local new_draft_id = param.get("new_draft_id", atom.integer)
6 if not old_draft_id or not new_draft_id then
7 slot.put( _"Please choose two versions of the draft to compare")
8 return
9 end
11 if old_draft_id == new_draft_id then
12 slot.put( _"Please choose two different versions of the draft to compare")
13 return
14 end
16 if old_draft_id > new_draft_id then
17 local tmp = old_draft_id
18 old_draft_id = new_draft_id
19 new_draft_id = tmp
20 end
22 local old_draft = Draft:by_id(old_draft_id)
23 local new_draft = Draft:by_id(new_draft_id)
25 local key = multirand.string(26, "123456789bcdfghjklmnpqrstvwxyz");
27 local old_draft_filename = encode.file_path(request.get_app_basepath(), 'tmp', "diff-" .. key .. "-old.tmp")
28 local new_draft_filename = encode.file_path(request.get_app_basepath(), 'tmp', "diff-" .. key .. "-new.tmp")
30 local old_draft_file = assert(io.open(old_draft_filename, "w"))
31 old_draft_file:write(old_draft.content)
32 old_draft_file:write("\n")
33 old_draft_file:close()
35 local new_draft_file = assert(io.open(new_draft_filename, "w"))
36 new_draft_file:write(new_draft.content)
37 new_draft_file:write("\n")
38 new_draft_file:close()
40 local output, err, status = os.pfilter(nil, "sh", "-c", "diff -U 100000 '" .. old_draft_filename .. "' '" .. new_draft_filename .. "' | grep -v ^--- | grep -v ^+++ | grep -v ^@")
42 os.remove(old_draft_filename)
43 os.remove(new_draft_filename)
45 if not status then
46 ui.field.text{ value = _"The drafts do not differ" }
47 else
48 slot.put('<table class="diff">')
49 slot.put('<tr><th width="50%">' .. _"Old draft revision" .. '</th><th width="50%">' .. _"New draft revision" .. '</th></tr>')
51 local last_state = "unchanged"
52 local lines = {}
53 local removed_lines = nil
55 local function process_line(line)
56 local state = "unchanged"
57 local char = line:sub(1,1)
58 line = line:sub(2)
59 state = "unchanged"
60 if char == "-" then
61 state = "-"
62 elseif char == "+" then
63 state = "+"
64 elseif char == "!" then
65 state = "eof"
66 end
67 if last_state == "unchanged" then
68 if state == "unchanged" then
69 lines[#lines+1] = line
70 elseif (state == "-") or (state == "+") or (state == "eof") then
71 local text = table.concat(lines, "\n")
72 slot.put("<tr><td>", encode.html_newlines(encode.html(text)), "</td><td>", encode.html_newlines(encode.html(text)), "</td></tr>")
73 lines = { line }
74 end
75 elseif last_state == "-" then
76 if state == "-" then
77 lines[#lines+1] = line
78 elseif state == "+" then
79 removed_lines = lines
80 lines = { line }
81 elseif (state == "unchanged") or (state == "eof") then
82 local text = table.concat(lines,"\n")
83 slot.put('<tr><td class="removed">', encode.html_newlines(encode.html(text)), "</td><td></td></tr>")
84 lines = { line }
85 end
86 elseif last_state == "+" then
87 if state == "+" then
88 lines[#lines+1] = line
89 elseif (state == "-") or (state == "unchanged") or (state == "eof") then
90 if removed_lines then
91 local text = table.concat(lines, "\n")
92 local removed_text = table.concat(removed_lines, "\n")
93 slot.put('<tr><td class="removed">', encode.html_newlines(encode.html(removed_text)), '</td><td class="added">', encode.html_newlines(encode.html(text)), "</td></tr>")
94 else
95 local text = table.concat(lines, "\n")
96 slot.put('<tr><td></td><td class="added">', encode.html_newlines(encode.html(text)), "</td></tr>")
97 end
98 removed_lines = nil
99 lines = { line }
100 end
101 end
102 last_state = state
103 end
105 output = output .. " "
106 output = output:gsub("[^\n\r]+", function(line)
107 process_line(line)
108 end)
109 process_line("!")
111 slot.put("</table>")
112 end

Impressum / About Us