Skip to content

Commit 86a91e5

Browse files
committed
add new route for default notes configuration
1 parent 84fcf01 commit 86a91e5

File tree

3 files changed

+99
-36
lines changed

3 files changed

+99
-36
lines changed

app/controllers/smash_tags_controller.rb

Lines changed: 93 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class SmashTagsController < ApplicationController
22

33
before_action :find_optional_project_and_authorize
44

5-
accept_api_auth :project_tags, :global_tags
5+
accept_api_auth :project_tags, :global_tags, :default_notes_tags
66

77
def project_tags
88
smash_tags = build_tags
@@ -18,6 +18,13 @@ def global_tags
1818
end
1919
end
2020

21+
def default_notes_tags
22+
smash_tags = build_default_notes_tags
23+
respond_to do |format|
24+
format.api { render json: smash_tags}
25+
end
26+
end
27+
2128
private
2229

2330
def find_optional_project_and_authorize
@@ -118,30 +125,6 @@ def build_tags
118125
# Trackers
119126
tracker_project_ids = valid_tracker_project_ids()
120127

121-
simple_notes = Tracker.where(id: Setting.plugin_redmine_gtt_smash['tracker_simple_notes'])
122-
photo_notes = Tracker.where(id: Setting.plugin_redmine_gtt_smash['tracker_photo_notes'])
123-
gps_logs = Tracker.where(id: Setting.plugin_redmine_gtt_smash['tracker_gps_logs'])
124-
default_subject = Setting.plugin_redmine_gtt_smash['default_subject']
125-
126-
if simple_notes.length() > 0
127-
simple_notes = {
128-
tracker_id: simple_notes[0].id,
129-
tracker_name: simple_notes[0].name
130-
}
131-
end
132-
if photo_notes.length() > 0
133-
photo_notes = {
134-
tracker_id: photo_notes[0].id,
135-
tracker_name: photo_notes[0].name
136-
}
137-
end
138-
if gps_logs.length() > 0
139-
gps_logs = {
140-
tracker_id: gps_logs[0].id,
141-
tracker_name: gps_logs[0].name
142-
}
143-
end
144-
145128
Tracker.where(id: tracker_project_ids.keys).sort.each do |tracker|
146129
# Projects
147130
project_ids = tracker_project_ids[tracker.id]
@@ -160,16 +143,6 @@ def build_tags
160143
sectionname: tracker.name,
161144
sectiondescription: "GTT",
162145
sectionicon: "image",
163-
sectionconfig: {
164-
defaultnotetracker: {
165-
simple_notes: simple_notes,
166-
photo_notes: photo_notes,
167-
gps_logs: gps_logs
168-
},
169-
defaults: {
170-
subject: default_subject
171-
}
172-
},
173146
forms: [{
174147
formname: tracker.name,
175148
formitems: [
@@ -370,4 +343,89 @@ def build_tags
370343
end
371344
return smash_tags
372345
end
346+
347+
def build_default_notes_tags
348+
simple_notes = Tracker.where(id: Setting.plugin_redmine_gtt_smash['tracker_simple_notes'])
349+
photo_notes = Tracker.where(id: Setting.plugin_redmine_gtt_smash['tracker_photo_notes'])
350+
gps_logs = Tracker.where(id: Setting.plugin_redmine_gtt_smash['tracker_gps_logs'])
351+
default_subject = Setting.plugin_redmine_gtt_smash['default_subject']
352+
353+
# Trackers
354+
tracker_project_ids = valid_tracker_project_ids()
355+
356+
simple_notes_projects = []
357+
photo_notes_projects = []
358+
gps_logs_projects = []
359+
360+
if simple_notes.length() > 0
361+
project_ids = tracker_project_ids[simple_notes[0].id]
362+
if @project.blank? and project_ids.present?
363+
Project.where(id: project_ids).sort.each {|project|
364+
simple_notes_projects.append({
365+
id: project.id.to_s,
366+
name: project.name
367+
})
368+
}
369+
end
370+
371+
simple_notes = {
372+
id: simple_notes[0].id.to_s,
373+
name: simple_notes[0].name
374+
}
375+
end
376+
if photo_notes.length() > 0
377+
project_ids = tracker_project_ids[photo_notes[0].id]
378+
if @project.blank? and project_ids.present?
379+
Project.where(id: project_ids).sort.each {|project|
380+
photo_notes_projects.append({
381+
id: project.id.to_s,
382+
name: project.name
383+
})
384+
}
385+
end
386+
387+
photo_notes = {
388+
id: photo_notes[0].id.to_s,
389+
name: photo_notes[0].name
390+
}
391+
end
392+
if gps_logs.length() > 0
393+
project_ids = tracker_project_ids[gps_logs[0].id]
394+
if @project.blank? and project_ids.present?
395+
Project.where(id: project_ids).sort.each {|project|
396+
gps_logs_projects.append({
397+
id: project.id.to_s,
398+
name: project.name
399+
})
400+
}
401+
end
402+
403+
gps_logs = {
404+
id: gps_logs[0].id.to_s,
405+
name: gps_logs[0].name
406+
}
407+
end
408+
409+
section = {
410+
notes: {
411+
simple: {
412+
tracker: simple_notes,
413+
projects: simple_notes_projects
414+
},
415+
photo: {
416+
tracker: photo_notes,
417+
projects: photo_notes_projects
418+
},
419+
gps: {
420+
tracker: gps_logs,
421+
projects: gps_logs_projects
422+
}
423+
},
424+
defaults: {
425+
subject: default_subject
426+
}
427+
}
428+
429+
return section
430+
end
373431
end

config/routes.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33

44
scope 'smash' do
55
get 'tags', to: 'smash_tags#global_tags', as: :smash_tags
6+
get 'settings', to: 'smash_tags#default_notes_tags', as: :default_notes_smash_tags
67
end
78

89
scope 'projects/:project_id' do
910
scope 'smash' do
1011
get 'tags', to: 'smash_tags#project_tags', as: :project_smash_tags
1112
end
1213
end
14+
15+
# scope 'smash' do
16+
# get 'settings', to: 'smash_tags#default_notes_tags', as: :default_notes_smash_tags
17+
# end

init.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
project_module :gtt_smash do
2424
permission :view_gtt_smash, {
25-
smash_tags: %i( project_tags global_tags )
25+
smash_tags: %i( project_tags global_tags default_notes_tags )
2626
}, require: :member, read: true
2727
end
2828

0 commit comments

Comments
 (0)