1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
|
module(..., package.seeall)
-- Load libraries
require("controllerfunctions")
require("format")
-- Set variables
local newrecordtxt = "[New]"
local anytxt = "Any"
local bugreportreceiver = "bugs@alpinelinux.org"
local descr = {
labels = {
['category'] = "Category",
['severity'] = "Severity",
['priority'] = "Priority",
['class'] = "Class",
['state'] = "State",
['skipclosed'] = "Skip/Hide closed",
['text'] = "Text in single-line fields",
['multitext'] = "Text in multi-line fields",
['responsible'] = "Responsible",
['originator'] = "Originator",
['release'] = "Alpine release",
['environment']="Environment",
['description']="Description",
['howtorepeat']="How-to-repeat this bug",
['fix']="Fix",
['synopsis']="One-line description*",
['from']="Your e-mail address*",
['reporter_name']="Your full name",
['reporter_id']="Your ID (Submitter ID)",
['reporter_org']="Your organization name",
header = {
['received'] = "Received",
['to'] = "To",
['from'] = "From",
['date'] = "Date",
['message_id'] = "Message ID",
['subject'] = "Subject",
['return_path'] = "Return path",
},
sfields = {
['number'] = "Number",
['class'] = "Class",
['responsible'] = "Responsible",
['category'] = "Category",
['priority'] = "Priority",
['confidential'] = "Confidential",
['originator'] = "Originator",
['severity'] = "Severity",
['keywords'] = "Keywords",
['arrival_date'] = "Arrival date",
['quarter'] = "Quarter",
['synopsis'] = "Synopsis",
['notify_list'] = "Notify list",
['submitter_id'] = "Submitter id",
['date_required'] = "Date required",
['release'] = "Release",
['last_modified'] = "Last modified",
['closed_date'] = "Closed date",
['state'] = "State",
},
mfields = {
['environment'] = "Environment",
['release_note'] = "Release note",
['audit_trail'] = "Audit trail",
['howtorepeat'] = "How to repeat",
['organization'] = "Organization",
['fix'] = "Fix",
['unformatted'] = "Unformatted",
},
},
audit_trail = {
['Responsible-Changed-From-To'] = "Responsible Changed",
['State-Changed-From-To'] = "State Changed",
['From'] = "Reply via E-mail",
},
maildescriptions = {
['from'] = "From: ",
['reporter_id'] = ">Submitter-Id: ",
['xxx'] = ">Notify-List: ",
['originator'] = ">Originator: ",
['reporter_org'] = ">Organization: ",
['synopsis'] = ">Synopsis: ",
['xxx'] = ">Confidential: ",
['severity'] = ">Severity: ",
['priority'] = ">Priority: ",
['category'] = ">Category: ",
['class'] = ">Class: ",
['release'] = ">Release: ",
['environment'] = ">Environment: ",
['description'] = ">Description: ",
['howtorepeat'] = ">How-To-Repeat:",
['fix'] = ">Fix: ",
},
}
-- ################################################################################
-- PUBLIC FUNCTIONS
default_action = "status"
function status(self)
return self.model.getstatus()
end
function listdatabases(self)
return self.model.list_databases()
end
function listdatabasefiles(self)
return self.model.list_database_files(self.clientdata.database)
end
function editdatabsefile(self)
return controllerfunctions.handle_form(self, function() return self.model.read_database_file(self.clientdata.filename) end, self.model.update_database_file, self.clientdata, "Save", "Edit File", "File Saved")
end
function listconfigfiles(self)
return self.model.list_config_files()
end
function editconfigfile(self)
return controllerfunctions.handle_form(self, function() return self.model.read_config_file(self.clientdata.filename) end, self.model.update_config_file, self.clientdata, "Save", "Edit File", "File Saved")
end
function expert(self)
local url = self.conf.script .. self.conf.prefix .. self.conf.controller
local status=self.model.getstatus()
local filedetailsresult, file = self.model:get_filedetails()
-- Add buttons
file.cmdsave = cfe ({
name="cmdsave",
label="Apply settings",
value="Apply",
type="submit",
})
return ( {
option={ script=self.conf.script,
prefix=self.conf.prefix,
controller = self.conf.controller,
action = "update",
extra = "" },
status = status,
file = file,
modifications = modifications,
url = url, } )
end
function edit(self)
-- Save changes
local modifications = self.clientdata.filecontent or ""
local cmdresult, cmdresultmsg
if ( self.clientdata.cmdsave ) then
cmdresult, cmdresultmsg = self.model:update_filecontent(modifications,self.clientdata.name)
end
local status = self.model:getstatus(self)
local filedetailsresult, file = self.model:get_filedetails(self.clientdata.name)
if not (filedetailsresult) then
redirect(self, "status")
end
-- Add a cmd button to the view
file.cmdsave = cfe({ name="cmdsave",
label="Save/Apply above settings",
value="Save",
type="submit",
})
if (cmdresult) then
file.cmdsave.descr="* Changes has been saved!"
end
return {
option={ script=self.conf.script,
prefix=self.conf.prefix,
controller = self.conf.controller,
action = "edit",
extra = "",
},
modifications = modifications,
file = file,
status = status,
}
end
--]]
function query(self)
local query = {}
query.pr = cfe({
name="pr",
label="Search string",
})
query.pr_cmd = cfe({
name="pr_cmd",
label=" ",
type="submit",
value="Submit",
})
local tags = { "category", "severity", "priority", "class", "state", }
for k,val in pairs(tags) do
query[val] = cfe({
name=val,
label=(descr.labels[val] or val),
value=anytxt,
type="select",
option=self.model:get_select_opt(val),
})
table.insert(query[val].option, 1, anytxt)
-- If there is only a limited amount records, then present as radio buttons.
if (#query[val].option < 6) then query[val].type="radio" end
end
local val = "responsible"
query[val] = cfe({
name=val,
label=(descr.labels[val] or val),
value=anytxt,
type="select",
option=self.model:list_responsible(),
})
table.insert(query[val].option, 1, anytxt)
local tags = { "skipclosed", "text", "multitext", }
for k,val in pairs(tags) do
query[val] = cfe({
name=val,
label=(descr.labels[val] or val),
option=self.model:get_select_opt(val),
})
end
-- Show 'skipclosed' as a checkbox instead
query.skipclosed.type="checkbox"
query.skipclosed.checked="Yes"
query.advanced_cmd = cfe({
name="advanced_cmd",
label=" ",
type="submit",
value="Submit advanced query",
})
-- Assume connection is down if you get no reply from it (disable buttons)
if not (query['severity']['option']) or (#query['severity']['option'] < 2) then
query.advanced_cmd.disabled="yes"
query.advanced_cmd.errtxt="Lost connection to the server!"
query.pr_cmd.disabled=query.advanced_cmd.disabled
query.pr_cmd.errtxt=query.advanced_cmd.errtxt
end
return {
option={ script=self.conf.script,
prefix=self.conf.prefix,
controller = self.conf.controller,
action = "edit",
extra = "",
},
query = query,
}
end
---------------------------------------------------------------------------
function summary(self)
-- parse the search criterias - select boxes
local action = "Query"
local s = {}
local invalid = nil
if self.clientdata.pr then
s["synopsis"] = self.model.validate_textfield(self.clientdata.pr)
else
for i, f in ipairs({"class", "category", "severity", "priority", "state", "responsible"}) do
s[f] = self.model:validate_field(self.clientdata[f], f)
end
-- parse the search criterias - input boxes
for i,f in ipairs({"text", "multitext", "originator"}) do
s[f] = self.model.validate_textfield(self.clientdata[f] or "")
-- replace this with ajax stuff?
if action == "Query" and s[f] == nil then
self.model:set_invalid_field(f)
invalid = true
end
-- if field is blank, then ignore it
if action == "Query" and s[f] == "" then
s[f] = nil
end
end
end
-- we have found atleast one invalid field. reset the action
if invalid then
action = nil
end
if (self.clientdata.skipclosed) then
s["skip-closed"] = ""
else
s["skip-closed"] = nil
end
-- Set the search criterias
self.model:set_search_criteria(s)
local summary = self.model:summary()
--[[ -- Hide unwanted records
local modsummary = {}
for k,v in pairs(orgsummary) do
if not ((orgsummary[k]['state'] == "closed") and ((orgsummary[k]['category'] == "test") or (orgsummary[k]['category'] == "spam"))) then
table.insert(modsummary, v)
end
end
summary = modsummary
--]]
return {
option={ script=self.conf.script,
prefix=self.conf.prefix,
controller = self.conf.controller,
action = "edit",
extra = "",
},
summary = summary,
}
end
-----------------------------------------------------------------------
function queryresult(self)
local query = {}
local pr_id = self.clientdata.pr
if (tonumber(pr_id)) then
query.header, query.sfields, query.mfields = self.model:read_pr(pr_id)
else
return summary(self)
end
local myform = query.header
for k,v in pairs(myform) do
myform[k] = cfe({
name=k,
label=descr.labels.header[k] or k,
value=string.gsub(myform[k], "\"", ""),
})
end
local myform = query.sfields
for k,v in pairs(myform) do
myform[k] = cfe({
name=k,
label=descr.labels.sfields[k] or k,
value=string.gsub(myform[k], "\"", ""),
})
end
local myform = query.mfields
for k,v in pairs(myform) do
myform[k] = cfe({
name=k,
label=descr.labels.mfields[k] or k,
value=string.gsub(myform[k], "\"", ""),
})
end
local audit_trail_table = {}
local checkstring = ""
local checkstring2 = 0
table.insert(audit_trail_table, cfe({class="", label=""}))
local tags = { "organization", "environment", "description", "how_to_repeat", "fix", "release_note", }
for k,val in pairs(tags) do
query.mfields[val].type="longtext"
end
local tags = { "category", "severity", "priority", "class", "state", }
for k,val in pairs(tags) do
query.sfields[val] = cfe({
name=val,
label=(descr.labels[val] or val),
value=query.sfields[val].value,
type="select",
option=self.model:get_select_opt(val),
})
-- If there is only a limited amount records, then present as radio buttons.
if (#query.sfields[val].option < 6) then query.sfields[val].type="radio" end
end
for k,v in pairs(format.string_to_table(query.mfields.audit_trail.value, "\n")) do
if (v == "") then
checkstring2 = checkstring2 + 1
end
if (checkstring2 == 99) then
table.insert(audit_trail_table, cfe({class="Unknown", label=""}))
checkstring = ""
checkstring2 = 0
end
for k1, v1 in pairs(descr.audit_trail) do
if (string.match(v, "^".. string.gsub(k1, "-", "%%-"))) then
table.insert(audit_trail_table, cfe({class=k1, label=v1}))
checkstring = k1
checkstring2 = 0
break
end
end
if (#audit_trail_table > 0) then
table.insert(audit_trail_table[#audit_trail_table], string.match(v, "^.+")) --Strips empty lines
end
end
query.mfields.audit_trail.option=audit_trail_table
return {
option={ script=self.conf.script,
prefix=self.conf.prefix,
controller = self.conf.controller,
action = "edit",
extra = "",
},
query = query,
}
end
--------------------------------------------------------------------------
function report(self)
local reportform = {}
local status = self.model:getstatus(self)
local alltags = { "reporter_name", "from", "reporter_id", "reporter_org",
"synopsis","severity","priority","category","class","release","environment",
"description", "howtorepeat", "fix", }
self.clientdata.reporter_id = "web-users"
for k,val in pairs(alltags) do
reportform[val] = cfe({
name=val,
label=(descr.labels[val] or val),
value=(self.clientdata[val] or ""),
})
end
local tags = { "category", "priority","severity","class" }
for k,val in pairs(tags) do
reportform[val] = cfe({
name=val,
label=(descr.labels[val] or val),
value=(self.clientdata[val] or ""),
type="select",
option=self.model:get_select_opt(val),
})
-- If there is only a limited amount records, then present as radio buttons.
if (#reportform[val].option < 6) then
reportform[val].type="radio"
else
table.insert(reportform[val].option, 1, "")
end
end
reportform.description.type="longtext"
reportform.howtorepeat.type="longtext"
reportform.fix.type="longtext"
reportform.environment.type="longtext"
reportform.release.value=status.alpinerelease.value or ""
-- Add buttons
reportform.submit = cfe ({
name="submit",
label=" ", -- hack
value="Submit",
type="submit",
})
-- Assume connection is down if you get no reply from it (disable buttons)
if not (reportform['severity']['option']) or (#reportform['severity']['option'] == 0) then
reportform.submit.disabled = "yes"
reportform.submit.errtxt = "Lost connection to the server!"
end
if (self.clientdata.submit) then
if not (self.clientdata.from) or (#self.clientdata.from == 0) then
reportform.from.errtxt = "You need to enter a valid e-mail address"
end
if not (self.clientdata.synopsis) or (#self.clientdata.synopsis == 0) then
reportform.synopsis.errtxt = "You need to enter a valid online-description"
end
if not (self.clientdata.severity) or (#self.clientdata.severity == 0) then
reportform.severity.errtxt = "You need to choose one of these options"
end
if not (self.clientdata.priority) or (#self.clientdata.priority == 0) then
reportform.priority.errtxt = "You need to choose one of these options"
end
if not (self.clientdata.category) or (#self.clientdata.category == 0) then
reportform.category.errtxt = "You need to choose one of these options"
end
if not (self.clientdata.class) or (#self.clientdata.class == 0) then
reportform.class.errtxt = "You need to choose one of these options"
end
local noerrorsexists
for k,v in pairs(alltags) do
noerrorsexists = false
if (reportform[v]['errtxt']) then break end
noerrorsexists = true
end
-- If we had no errors, then we proceed with creating/sending the bugreport
if (noerrorsexists) then
local bugreport = {}
table.insert(bugreport, "To: " .. (bugreportreceiver or ""))
if not (self.clientdata.reporter_name) or (#self.clientdata.reporter_name == 0) then
self.clientdata.reporter_name = "unknown"
end
table.insert(bugreport, "From: " .. self.clientdata.reporter_name .. " <" .. (self.clientdata.from or "") .. ">")
table.insert(bugreport, "Reply-To: " .. (self.clientdata.from or ""))
table.insert(bugreport, "")
for k,v in pairs({"reporter_id", "notify_list", "originator", "synopsis", "confidential", "severity",
"priority", "category", "class", "release", }) do
if (v) and (descr.maildescriptions[v]) and (self.clientdata[v]) then
table.insert(bugreport, descr.maildescriptions[v] .. self.clientdata[v] )
end
end
table.insert(bugreport, descr.maildescriptions.environment .. "\n" .. (self.clientdata.environment or "") .."\n" )
table.insert(bugreport, descr.maildescriptions.howtorepeat .. "\n" .. (self.clientdata.howtorepeat or "") .."\n" )
table.insert(bugreport, descr.maildescriptions.fix .. "\n" .. (self.clientdata.fix or "") .."\n" )
local bugreportsuccess, bugreport = self.model:sendbug(bugreport)
if (bugreportsuccess) then
redirect(self, "reportsuccess")
end
reportform.submit.errtxt = "Something went wrong because the report could not be sent.\n" .. bugreport
end
end
return {
option={ script=self.conf.script,
prefix=self.conf.prefix,
controller = self.conf.controller,
action = "edit",
extra = "",
},
reportform = reportform,
}
end
function reportsuccess()
-- Just show that the report was successfully sent.
end
function queryeditpr(self)
local query = {}
query.pr = cfe({
name="pr",
label="Query a specific PR number:",
})
query.pr_cmd = cfe({
name="pr_cmd",
label="Submit the query",
type="submit",
value="Submit",
})
return {
option={ script=self.conf.script,
prefix=self.conf.prefix,
controller = self.conf.controller,
action = "edit",
extra = "",
},
query = query,
}
end
function editpr(self)
local queryresult = queryresult(self)
local query = queryresult.query
query.cmdsave = cfe({
name="cmdsave",
label="Save above changes",
type="submit",
disabled="yes",
errtxt="This button doesn't work. Still don't know howto send this edited information into gnats.",
value="Submit",
})
return {
option={ script=self.conf.script,
prefix=self.conf.prefix,
controller = self.conf.controller,
action = "edit",
extra = "",
},
query = query,
}
end
|