Mercurial > prosody-modules
comparison mod_incidents_handling/incidents_handling/mod_incidents_handling.lua @ 1343:7dbde05b48a9
all the things: Remove trailing whitespace
author | Florian Zeitz <florob@babelmonkeys.de> |
---|---|
date | Tue, 11 Mar 2014 18:44:01 +0100 |
parents | c4995b56c358 |
children |
comparison
equal
deleted
inserted
replaced
1342:0ae065453dc9 | 1343:7dbde05b48a9 |
---|---|
25 -- Incidents Table Methods | 25 -- Incidents Table Methods |
26 | 26 |
27 local _inc_mt = {} ; _inc_mt.__index = _inc_mt | 27 local _inc_mt = {} ; _inc_mt.__index = _inc_mt |
28 | 28 |
29 function _inc_mt:init() | 29 function _inc_mt:init() |
30 self:clean() ; self:save() | 30 self:clean() ; self:save() |
31 end | 31 end |
32 | 32 |
33 function _inc_mt:clean() | 33 function _inc_mt:clean() |
34 if expire_time > 0 then | 34 if expire_time > 0 then |
35 for id, incident in pairs(self) do | 35 for id, incident in pairs(self) do |
66 | 66 |
67 local _lang, _dtext = _desc:match("^(%a%a)%s(.*)$") | 67 local _lang, _dtext = _desc:match("^(%a%a)%s(.*)$") |
68 if not _lang or not _dtext then return false end | 68 if not _lang or not _dtext then return false end |
69 local desc = { text = _dtext, lang = _lang } | 69 local desc = { text = _dtext, lang = _lang } |
70 | 70 |
71 local contacts = {} | 71 local contacts = {} |
72 for contact in _contacts:gmatch("[%w%p]+%s[%w%p]+%s[%w%p]+") do | 72 for contact in _contacts:gmatch("[%w%p]+%s[%w%p]+%s[%w%p]+") do |
73 local address, atype, role = contact:match("^([%w%p]+)%s([%w%p]+)%s([%w%p]+)$") | 73 local address, atype, role = contact:match("^([%w%p]+)%s([%w%p]+)%s([%w%p]+)$") |
74 if not address or not atype or not role then fail = true ; break end | 74 if not address or not atype or not role then fail = true ; break end |
75 contacts[#contacts + 1] = { | 75 contacts[#contacts + 1] = { |
76 role = role, | 76 role = role, |
115 if not address or not cat or not noderole then fail = true ; break end | 115 if not address or not cat or not noderole then fail = true ; break end |
116 cat, cat_ext = ih_lib.get_type(cat, "category") | 116 cat, cat_ext = ih_lib.get_type(cat, "category") |
117 noderole_ext = ih_lib.get_type(cat, "noderole") | 117 noderole_ext = ih_lib.get_type(cat, "noderole") |
118 | 118 |
119 if not _preprocess[noderole] then _preprocess[noderole] = { addresses = {}, ext = noderole_ext } end | 119 if not _preprocess[noderole] then _preprocess[noderole] = { addresses = {}, ext = noderole_ext } end |
120 | 120 |
121 _preprocess[noderole].addresses[#_preprocess[noderole].addresses + 1] = { | 121 _preprocess[noderole].addresses[#_preprocess[noderole].addresses + 1] = { |
122 text = address, cat = cat, ext = cat_ext | 122 text = address, cat = cat, ext = cat_ext |
123 } | 123 } |
124 end | 124 end |
125 for noderole, data in pairs(_preprocess) do | 125 for noderole, data in pairs(_preprocess) do |
142 contacts = contacts, | 142 contacts = contacts, |
143 related = related, | 143 related = related, |
144 assessment = assessment, | 144 assessment = assessment, |
145 event_data = { sources = sources, targets = targets } | 145 event_data = { sources = sources, targets = targets } |
146 } | 146 } |
147 | 147 |
148 self[new_object.data.id.text] = new_object | 148 self[new_object.data.id.text] = new_object |
149 self:clean() ; self:save() | 149 self:clean() ; self:save() |
150 return new_object.data.id.text | 150 return new_object.data.id.text |
151 else return false end | 151 else return false end |
152 end | 152 end |
175 origin.send(report_iq) | 175 origin.send(report_iq) |
176 return true | 176 return true |
177 else | 177 else |
178 module:log("error", "Server %s queried for incident %s but we don't know about it", stanza.attr.from, inc_id) | 178 module:log("error", "Server %s queried for incident %s but we don't know about it", stanza.attr.from, inc_id) |
179 origin.send(st.error_reply(stanza, "cancel", "item-not-found")) ; return true | 179 origin.send(st.error_reply(stanza, "cancel", "item-not-found")) ; return true |
180 end | 180 end |
181 end | 181 end |
182 | 182 |
183 local function request_handler(event) | 183 local function request_handler(event) |
184 local origin, stanza = event.origin, event.stanza | 184 local origin, stanza = event.origin, event.stanza |
185 | 185 |
211 local function list_incidents_command_handler(self, data, state) | 211 local function list_incidents_command_handler(self, data, state) |
212 local list_incidents_layout = ih_lib.render_list(incidents) | 212 local list_incidents_layout = ih_lib.render_list(incidents) |
213 | 213 |
214 if state then | 214 if state then |
215 if state.step == 1 then | 215 if state.step == 1 then |
216 if data.action == "cancel" then | 216 if data.action == "cancel" then |
217 return { status = "canceled" } | 217 return { status = "canceled" } |
218 elseif data.action == "prev" then | 218 elseif data.action == "prev" then |
219 return { status = "executing", actions = { "next", default = "next" }, form = list_incidents_layout }, {} | 219 return { status = "executing", actions = { "next", default = "next" }, form = list_incidents_layout }, {} |
220 end | 220 end |
221 | 221 |
285 local err_proc = { status = "completed", error = { message = "There was an error processing your request, check out the syntax" } } | 285 local err_proc = { status = "completed", error = { message = "There was an error processing your request, check out the syntax" } } |
286 | 286 |
287 if state then | 287 if state then |
288 if data.action == "cancel" then return { status = "canceled" } end | 288 if data.action == "cancel" then return { status = "canceled" } end |
289 local fields = send_layout:data(data.form) | 289 local fields = send_layout:data(data.form) |
290 | 290 |
291 if fields.started and fields.ended and fields.reported and fields.description and fields.contacts and | 291 if fields.started and fields.ended and fields.reported and fields.description and fields.contacts and |
292 fields.impact and fields.sources and fields.targets and fields.entity then | 292 fields.impact and fields.sources and fields.targets and fields.entity then |
293 if formtype == "request" and not fields.expectation then return err_no_fields end | 293 if formtype == "request" and not fields.expectation then return err_no_fields end |
294 local id = incidents:new_object(fields, formtype) | 294 local id = incidents:new_object(fields, formtype) |
295 if not id then return err_proc end | 295 if not id then return err_proc end |
301 module:send(stanza) | 301 module:send(stanza) |
302 | 302 |
303 return { status = "completed", info = string.format("Incident %s sent to %s.", formtype, fields.entity) } | 303 return { status = "completed", info = string.format("Incident %s sent to %s.", formtype, fields.entity) } |
304 else | 304 else |
305 return err_no_fields | 305 return err_no_fields |
306 end | 306 end |
307 else | 307 else |
308 return { status = "executing", form = send_layout }, "executing" | 308 return { status = "executing", form = send_layout }, "executing" |
309 end | 309 end |
310 end | 310 end |
311 | 311 |
346 return { incidents = incidents } | 346 return { incidents = incidents } |
347 end | 347 end |
348 | 348 |
349 module.restore = function(data) | 349 module.restore = function(data) |
350 incidents = data.incidents or {} | 350 incidents = data.incidents or {} |
351 setmetatable(incidents, _inc_mt) ; incidents:init() | 351 setmetatable(incidents, _inc_mt) ; incidents:init() |
352 end | 352 end |