Skip to content

Commit 043ef7f

Browse files
committed
Refactor asset handling to support Redmine 6
1 parent 826ba5f commit 043ef7f

File tree

7 files changed

+81
-62
lines changed

7 files changed

+81
-62
lines changed

init.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
# Global Hooks
2-
require File.expand_path('../lib/redmine_gtt/hooks/view_layouts_base_html_head_hook', __FILE__)
3-
require File.expand_path('../lib/redmine_gtt/view_hooks', __FILE__)
1+
require_relative 'lib/redmine_gtt/view_hooks'
42

53
Redmine::Plugin.register :redmine_gtt do
64
name 'Redmine GTT plugin'
75
author 'Georepublic'
86
author_url 'https://github.com/georepublic'
97
url 'https://github.com/gtt-project/redmine_gtt'
108
description 'Adds location-based task management and maps'
11-
version '5.1.2'
9+
version '6.0.0'
1210

1311
requires_redmine :version_or_higher => '5.0.0'
1412

lib/redmine_gtt/hooks/view_layouts_base_html_head_hook.rb

Lines changed: 0 additions & 45 deletions
This file was deleted.

lib/redmine_gtt/view_hooks.rb

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
# frozen_string_literal: true
2-
31
module RedmineGtt
42
class ViewHooks < Redmine::Hook::ViewListener
3+
4+
include ActionView::Context
5+
6+
# Render partials in various views
57
render_on :view_account_left_bottom,
6-
partial: 'redmine_gtt/hooks/view_account_left_bottom'
8+
partial: 'redmine_gtt/hooks/view_account_left_bottom'
79

810
render_on :view_my_account,
911
partial: 'redmine_gtt/hooks/view_my_account'
@@ -17,5 +19,45 @@ class ViewHooks < Redmine::Hook::ViewListener
1719
render_on :view_layouts_base_body_bottom,
1820
partial: 'redmine_gtt/hooks/view_layouts_base_body_bottom'
1921

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
2062
end
2163
end

src/styles/icons/custom/custom-icons-def.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,27 @@ const iconMappings: { [key: string]: any } = {
88
'waste': '\uf104'
99
};
1010

11+
// Read the meta tag for custom-icons
12+
const customIconsMeta = document.querySelector('meta[name="gtt-font-custom-icons"]');
13+
const customIconsUrl = customIconsMeta ? customIconsMeta.getAttribute('content') : 'data:application/font-woff2;base64,'; // Provide a data URL for an empty font
14+
15+
// Dynamically create the @font-face rule
16+
const style = document.createElement('style');
17+
style.type = 'text/css';
18+
style.innerHTML = `
19+
@font-face {
20+
font-family: 'custom-icons';
21+
font-style: normal;
22+
font-weight: 400;
23+
font-display: block;
24+
src: url(${customIconsUrl}) format('woff2');
25+
}
26+
`;
27+
document.head.appendChild(style);
28+
1129
// Define the font face
12-
let customFont = new FontFace('custom-icons', 'url(/plugin_assets/redmine_gtt/custom-icons.woff2)');
30+
let customFont: FontFace;
31+
customFont = new FontFace('custom-icons', `url(${customIconsUrl})`);
1332

1433
// Load the font
1534
const fontPromise = customFont.load().then((font) => {

src/styles/icons/custom/custom-icons.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
@font-face {
1+
/* @font-face {
22
font-family: "custom-icons";
33
font-style: normal;
44
font-weight: 400;
55
font-display: block;
66
src: url("./custom-icons.woff2") format("woff2");
7-
}
7+
} */
88

99
.custom-icons {
1010
font-weight: normal;

src/styles/icons/material-design/material-design-def.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7300,11 +7300,16 @@ const iconMappings: { [key: string]: any } = {
73007300
"zodiac-virgo": "\u{F0A88}",
73017301
};
73027302

7303+
// Read the meta tag for MDI webfont
7304+
const mdiWebfontMeta = document.querySelector('meta[name="gtt-font-mdi-webfont"]');
7305+
const mdiWebfontUrl = mdiWebfontMeta ? mdiWebfontMeta.getAttribute('content') : 'data:application/font-woff2;base64,'; // Provide a data URL for an empty font
7306+
73037307
// Define the font face
7304-
let customFont = new FontFace('materialdesignicons', 'url(/plugin_assets/redmine_gtt/materialdesignicons-webfont.woff2)');
7308+
let mdiFont: FontFace;
7309+
mdiFont = new FontFace('materialdesignicons', `url(${mdiWebfontUrl})`);
73057310

73067311
// Load the font
7307-
const fontPromise = customFont.load().then((font) => {
7312+
const fontPromise = mdiFont.load().then((font) => {
73087313
// Add the loaded font to the document
73097314
document.fonts.add(font);
73107315

@@ -7314,13 +7319,13 @@ const fontPromise = customFont.load().then((font) => {
73147319
font: 'Material Design Icons',
73157320
name: 'Material Design Icons',
73167321
copyright: 'Apache-2.0',
7317-
prefix: 'mdi'
7322+
prefix: 'mdi',
73187323
},
73197324
iconMappings
73207325
);
73217326

73227327
// Create a FontFaceObserver instance
7323-
const observer = new FontFaceObserver('custom-icons');
7328+
const observer = new FontFaceObserver('materialdesignicons');
73247329

73257330
// Use the observer to wait for the font to be loaded
73267331
return observer.load();

webpack.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const imageLoaders = {
1616
test: /\.(png|svg|jpg|jpeg|gif)$/i,
1717
type: 'asset/resource',
1818
generator: {
19-
filename: '[name][ext]', // Keep the original file name and extension
19+
filename: '../images/[name][ext]', // Keep the original file name and extension
2020
},
2121
};
2222

@@ -25,7 +25,7 @@ const fontLoaders = {
2525
test: /\.(woff|woff2|eot|ttf|otf)$/i,
2626
type: 'asset/resource',
2727
generator: {
28-
filename: '[name][ext]', // Keep the original file name and extension
28+
filename: '../fonts/[name][ext]', // Keep the original file name and extension
2929
},
3030
};
3131

@@ -55,7 +55,7 @@ module.exports = {
5555
},
5656
output: {
5757
filename: 'main.js',
58-
path: path.resolve(__dirname, 'assets'),
58+
path: path.resolve(__dirname, 'assets/javascripts'),
5959
assetModuleFilename: '[name].[ext]',
6060
},
6161
};

0 commit comments

Comments
 (0)