Skip to content

Commit a9d2d62

Browse files
committed
Moves Javascript and HTML to partial views
Cleans up hooks Fixes issue with file uploader
1 parent 3008bb5 commit a9d2d62

File tree

4 files changed

+36
-43
lines changed

4 files changed

+36
-43
lines changed

app/views/redmine_gtt/hooks/_view_layouts_base_body_bottom.html.erb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,27 @@
22
<textarea name="<%= l(:title_geojson_upload) %>" placeholder="<%= l(:placeholder_geojson_upload) %>" class="ui-widget ui-state-default ui-corner-all"></textarea>
33
<input type="file" id="file-selector" accept=".json,.geojson">
44
</div>
5+
6+
<%= javascript_include_tag 'main', plugin: 'redmine_gtt' %>
7+
8+
<% geocoder = { enabled: false } %>
9+
10+
<% if Setting.plugin_redmine_gtt['enable_geocoding_on_map'] == 'true' %>
11+
<% geocoder = {
12+
enabled: true,
13+
provider: Setting.plugin_redmine_gtt['default_geocoder_provider'],
14+
options: (JSON.parse(Setting.plugin_redmine_gtt['default_geocoder_options']) rescue {})
15+
} %>
16+
<% end %>
17+
18+
<%= tag.div data: {
19+
lon: Setting.plugin_redmine_gtt['default_map_center_longitude'],
20+
lat: Setting.plugin_redmine_gtt['default_map_center_latitude'],
21+
zoom: Setting.plugin_redmine_gtt['default_map_zoom_level'],
22+
maxzoom: Setting.plugin_redmine_gtt['default_map_maxzoom_level'],
23+
vector_minzoom: Setting.plugin_redmine_gtt['vector_minzoom_level'],
24+
fit_maxzoom: Setting.plugin_redmine_gtt['default_map_fit_maxzoom_level'],
25+
geocoder: geocoder,
26+
plugin_settings: Setting.plugin_redmine_gtt.select { |key, value| key.to_s.match(/^(?!default).+/) },
27+
i18n: l(:gtt_js).to_json.html_safe
28+
}, id: 'gtt-defaults', style: 'display:none' %>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<%= tag.meta(
2+
name: 'gtt-font-custom-icons',
3+
content: asset_path('plugin_assets/redmine_gtt/custom-icons.woff2')) %>
4+
5+
<%= tag.meta(
6+
name: 'gtt-font-mdi-webfont',
7+
content: asset_path('plugin_assets/redmine_gtt/materialdesignicons-webfont.woff2')) %>

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
to: 'projects#update_gtt_configuration',
77
as: :update_gtt_configuration
88

9+
# Todo: check if this route should start with "/assets" for consistency
910
get '/plugin_assets/redmine_gtt/javascripts/index.js.map', to: 'gtt#map'
1011

1112
scope 'gtt' do

lib/redmine_gtt/view_hooks.rb

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
module RedmineGtt
22
class ViewHooks < Redmine::Hook::ViewListener
3-
43
include ActionView::Context
54

65
# Render partials in various views
76
render_on :view_account_left_bottom,
8-
partial: 'redmine_gtt/hooks/view_account_left_bottom'
7+
partial: 'redmine_gtt/hooks/view_account_left_bottom'
98

109
render_on :view_my_account,
1110
partial: 'redmine_gtt/hooks/view_my_account'
@@ -16,48 +15,10 @@ class ViewHooks < Redmine::Hook::ViewListener
1615
render_on :view_issues_form_details_top,
1716
partial: 'redmine_gtt/hooks/view_issues_form_details_top'
1817

18+
render_on :view_layouts_base_html_head,
19+
partial: 'redmine_gtt/hooks/view_layouts_base_html_head'
20+
1921
render_on :view_layouts_base_body_bottom,
2022
partial: 'redmine_gtt/hooks/view_layouts_base_body_bottom'
21-
22-
# Add meta tags to the HTML head to inform about available fonts with their URL including the digest
23-
def view_layouts_base_html_head(context={})
24-
tags = []
25-
tags << tag.meta(:name => 'gtt-font-custom-icons', :content => asset_path('plugin_assets/redmine_gtt/custom-icons.woff2'))
26-
tags << tag.meta(:name => 'gtt-font-mdi-webfont', :content => asset_path('plugin_assets/redmine_gtt/materialdesignicons-webfont.woff2'))
27-
return tags.join("\n")
28-
end
29-
30-
# Add JavaScript and data tags to the body bottom
31-
def view_layouts_base_body_bottom(context={})
32-
tags = [];
33-
34-
tags << javascript_include_tag('main', :plugin => 'redmine_gtt')
35-
36-
geocoder = {
37-
enabled: false
38-
}
39-
40-
if Setting.plugin_redmine_gtt['enable_geocoding_on_map'] == 'true'
41-
geocoder = {
42-
enabled: true,
43-
provider: Setting.plugin_redmine_gtt['default_geocoder_provider'],
44-
options: (JSON.parse(Setting.plugin_redmine_gtt['default_geocoder_options']) rescue {})
45-
}
46-
end
47-
48-
tags.push(tag.div :data => {
49-
:lon => Setting.plugin_redmine_gtt['default_map_center_longitude'],
50-
:lat => Setting.plugin_redmine_gtt['default_map_center_latitude'],
51-
:zoom => Setting.plugin_redmine_gtt['default_map_zoom_level'],
52-
:maxzoom => Setting.plugin_redmine_gtt['default_map_maxzoom_level'],
53-
:vector_minzoom => Setting.plugin_redmine_gtt['vector_minzoom_level'],
54-
:fit_maxzoom => Setting.plugin_redmine_gtt['default_map_fit_maxzoom_level'],
55-
:geocoder => geocoder,
56-
:plugin_settings => Setting.plugin_redmine_gtt.select{ |key, value| key.to_s.match(/^(?!default).+/) },
57-
:i18n => l(:gtt_js).to_json.html_safe
58-
}, :id => 'gtt-defaults', :style => 'display:none')
59-
60-
return tags.join("\n")
61-
end
6223
end
6324
end

0 commit comments

Comments
 (0)