Skip to content

Commit a2ff604

Browse files
authored
Supporting dynamic tags.json output (#13)
* Supporting dynamic tags.json output Signed-off-by: Ko Nagase <[email protected]> * Changed integer value to string Signed-off-by: Ko Nagase <[email protected]> * Supported dynamic tags.json output Signed-off-by: Ko Nagase <[email protected]>
1 parent a6db440 commit a2ff604

File tree

1 file changed

+125
-13
lines changed

1 file changed

+125
-13
lines changed

app/controllers/smash_tags_controller.rb

Lines changed: 125 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,140 @@ class SmashTagsController < ApplicationController
66
accept_api_auth :index
77

88
def index
9-
example = [{
10-
sectionname: "[GTT] Task note",
11-
sectiondescription: "GTT task with image",
12-
sectionnicon: "image",
13-
forms: [
14-
{
15-
formname: "Take a photo",
9+
smash_tags = []
10+
priorities = []
11+
default_priority = nil
12+
# SMASH (Geopaparazzi) form spec: https://www.geopaparazzi.org/geopaparazzi/index.html#_using_form_based_notes
13+
IssuePriority.active.each do |priority|
14+
priorities.append({
15+
item: priority.name
16+
})
17+
if priority.is_default
18+
default_priority = priority.name
19+
end
20+
end
21+
@project.trackers.sort.each do |tracker|
22+
section = {
23+
sectionname: tracker.name,
24+
sectiondescription: "",
25+
sectionicon: "image",
26+
forms: [{
27+
formname: tracker.name,
1628
formitems: [
29+
# Default fields
30+
{
31+
key: "project_id",
32+
value: @project.id.to_s,
33+
type: "hidden",
34+
mandatory: "yes"
35+
},
36+
{
37+
key: "tracker_id",
38+
value: tracker.id.to_s,
39+
type: "hidden",
40+
mandatory: "yes"
41+
},
1742
{
18-
key: "title",
19-
islabel: "true",
43+
key: "subject",
44+
label: l(:field_subject),
2045
value: "",
21-
icon: "infoCircle",
2246
type: "string",
2347
mandatory: "yes"
48+
},
49+
{
50+
key: "priority_id",
51+
label: l(:field_priority),
52+
values: {
53+
items: priorities
54+
},
55+
value: default_priority,
56+
type: "stringcombo",
57+
mandatory: "yes"
58+
},
59+
{
60+
key: "is_private",
61+
label: l(:field_is_private),
62+
type: "boolean",
63+
mandatory: "yes"
64+
},
65+
# TODO: Need to check
66+
# assigned_to_id, category_id, fixed_version_id, parent_issue_id,
67+
# start_date, due_date, estimated_hours, done_ratio
68+
{
69+
key: "description",
70+
label: l(:field_description),
71+
value: "",
72+
type: "string"
2473
}
2574
]
75+
}]
76+
}
77+
# Attachments
78+
section[:forms][0][:formitems].append({
79+
key: "attachments",
80+
value: "",
81+
type: "pictures"
82+
})
83+
# IssueCustomField mapping
84+
# Redmine: https://github.com/redmine/redmine/blob/master/lib/redmine/field_format.rb
85+
IssueCustomField.where(is_for_all: true).sort.each do |icf|
86+
type = "string"
87+
values = []
88+
case icf.field_format
89+
when "string", "text", "link"
90+
type = "string"
91+
when "int"
92+
type = "integer"
93+
when "float"
94+
type = "double"
95+
when "date"
96+
type = "date"
97+
when "bool"
98+
type = "boolean"
99+
when "list"
100+
type = (icf.multiple ? "multistringcombo" : "stringcombo")
101+
icf.possible_values.each do |v|
102+
values.append({
103+
item: v
104+
})
105+
end
106+
when "enumeration"
107+
type = (icf.multiple ? "multistringcombo" : "stringcombo")
108+
icf.enumerations.where(active: true).sort.each do |e|
109+
values.append({
110+
item: e.name
111+
})
112+
end
113+
when "user", "version", "attachment"
114+
# Can't map SMASH object
115+
type = "hidden"
116+
end
117+
if !icf.visible
118+
type = "hidden"
119+
end
120+
value = (icf.default_value ? icf.default_value : "")
121+
mandatory = (icf.is_required ? "true" : "false")
122+
123+
formitem = {
124+
key: "cf_#{icf.id}",
125+
label: icf.name,
126+
value: value,
127+
type: type,
128+
mandatory: mandatory
26129
}
27-
]
28-
}]
130+
131+
if type.end_with?("stringcombo")
132+
formitem[:values] = {
133+
items: values
134+
}
135+
end
136+
137+
section[:forms][0][:formitems].append(formitem)
138+
end
139+
smash_tags.append(section)
140+
end
29141
respond_to do |format|
30-
format.api { render json: example }
142+
format.api { render json: smash_tags }
31143
end
32144
end
33145
end

0 commit comments

Comments
 (0)