Skip to content

Commit 9b7c1db

Browse files
committed
Always log in the console in case of warnings, display a message for GIS for invalid layers in CFG
1 parent 2561a03 commit 9b7c1db

File tree

3 files changed

+124
-34
lines changed

3 files changed

+124
-34
lines changed

assets/src/modules/ExecuteJSFromServer.js

Lines changed: 110 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
/**
2+
* LizDict
3+
* @typedef {object} lizDict
4+
*/
5+
6+
/**
7+
* Execute JS from server
8+
*/
19
export default function executeJSFromServer() {
210
lizMap.events.on({
311
uicreated: () => {
4-
5-
// skipWarningsDisplay is used in tests, to skip a possible warnings about old QGIS plugin used
6-
if (!document.body.dataset.skipWarningsDisplay){
7-
displayWarningsAdministrator();
8-
}
12+
const withDisplay = !document.body.dataset.skipWarningsDisplay;
13+
displayWarningsAdministrator(withDisplay);
14+
checkInvalidLayersCfgFile(withDisplay);
915

1016
if (document.body.dataset.lizmapHideLegend) {
1117
document.querySelector('li.switcher.active #button-switcher')?.click();
@@ -26,7 +32,9 @@ export default function executeJSFromServer() {
2632
var search = $('#nominatim-search');
2733
if (search.length != 0) {
2834
$('#mapmenu').append(search);
29-
$('#nominatim-search div.dropdown-menu').removeClass('pull-right').addClass('pull-left');
35+
$(
36+
'#nominatim-search div.dropdown-menu'
37+
).removeClass('pull-right').addClass('pull-left');
3038
}
3139

3240
//calculate dock position and size
@@ -46,7 +54,8 @@ export default function executeJSFromServer() {
4654
if ($('#mapmenu li.switcher').hasClass('active'))
4755
$('#button-switcher').click();
4856

49-
$('#mapmenu .nav-list > li.permaLink a').attr('data-original-title', lizDict['embed.open.map']);
57+
$('#mapmenu .nav-list > li.permaLink a').attr(
58+
'data-original-title', lizDict['embed.open.map']);
5059
},
5160
dockopened: () => {
5261
// one tool at a time
@@ -65,7 +74,8 @@ export default function executeJSFromServer() {
6574
// autocompletion items for locatebylayer feature
6675
$('div.locate-layer select').hide();
6776
$('span.custom-combobox').show();
68-
$('#locate div.locate-layer input.custom-combobox-input').autocomplete('option', 'position', { my: 'left top', at: 'left bottom' });
77+
$('#locate div.locate-layer input.custom-combobox-input'
78+
).autocomplete('option', 'position', { my: 'left top', at: 'left bottom' });
6979
}
7080

7181
if (evt.id == 'permaLink') {
@@ -79,30 +89,101 @@ export default function executeJSFromServer() {
7989
}
8090

8191
/**
82-
* Display messages to the user about deprecated features or outdated versions.
92+
* Display a message about invalid layers, detected on the client side.
93+
*
94+
* A message is logged in the console in English.
95+
* Another message is translated and displayed for GIS administrators.
96+
*
97+
* @param {boolean} withDisplay If the message must be displayed in the web interface, only in the console otherwise.
98+
*/
99+
function checkInvalidLayersCfgFile(withDisplay){
100+
const invalidLayers = lizMap.mainLizmap.initialConfig.invalidLayersNotFoundInCfg;
101+
if (invalidLayers.length === 0) {
102+
return;
103+
}
104+
105+
let message = `WMS layers "${invalidLayers.join(', ')}" are not found in the Lizmap configuration. `;
106+
message += `Is the Lizmap configuration file "${lizUrls.params.project}.qgs.cfg" up to date ?`;
107+
console.warn(message);
108+
109+
if (!withDisplay){
110+
return;
111+
}
112+
113+
if (!document.body.dataset.lizmapAdminUser){
114+
return;
115+
}
116+
117+
const layersNotFound = `
118+
${lizDict['project.has.not.found.layers']}<br>
119+
<code>${invalidLayers.join(', ')}</code>`;
120+
121+
lizMap.addMessage(
122+
layersNotFound,
123+
'warning',
124+
true
125+
).attr('id', 'lizmap-warning-message');
126+
}
127+
128+
/**
129+
* Display messages to the administrator about deprecated features or outdated versions.
130+
*
131+
* The message is translated and displayed for GIS administrators.
132+
* A message is logged in the console in English.
133+
*
134+
* @param {boolean} withDisplay If the message must be displayed in the web interface, only in the console otherwise.
83135
*/
84-
function displayWarningsAdministrator() {
85-
if (document.body.dataset.lizmapPluginUpdateWarningUrl) {
86-
var message = lizDict['project.plugin.outdated.warning'];
87-
message += `<br><a href="${document.body.dataset.lizmapPluginUpdateWarningUrl}">`;
88-
message += lizDict['visit.admin.panel.project.page'];
89-
message += '</a>';
90-
message += '<br>';
91-
message += lizDict['project.admin.panel.info'];
92-
// The plugin can be easily updated, the popup can not be closed
93-
lizMap.addMessage(message, 'warning', false).attr('id', 'lizmap-warning-message');
94-
} else if (document.body.dataset.lizmapPluginHasWarningsUrl) {
95-
var message = lizDict['project.has.warnings'];
96-
message += `<br><a href="${document.body.dataset.lizmapPluginHasWarningsUrl}">`;
97-
message += lizDict['visit.admin.panel.project.page'];
98-
message += '</a>';
99-
message += '<br>';
100-
message += lizDict['project.admin.panel.info'];
101-
// It can take times to fix these issues, the popup can be closed
102-
lizMap.addMessage(message, 'warning', true).attr('id', 'lizmap-warning-message');
136+
function displayWarningsAdministrator(withDisplay) {
137+
if (document.body.dataset.lizmapPluginUpdateWarning) {
138+
console.warn('The plugin in QGIS is not up to date.');
139+
140+
if (document.body.dataset.lizmapPluginUpdateWarningUrl && withDisplay) {
141+
let messageOutdatedWarning = lizDict['project.plugin.outdated.warning'];
142+
messageOutdatedWarning += `<br><a href="${document.body.dataset.lizmapPluginUpdateWarningUrl}">`;
143+
messageOutdatedWarning += lizDict['visit.admin.panel.project.page'];
144+
messageOutdatedWarning += '</a>';
145+
messageOutdatedWarning += '<br>';
146+
messageOutdatedWarning += lizDict['project.admin.panel.info'];
147+
148+
// The plugin can be easily updated, the popup can not be closed
149+
lizMap.addMessage(
150+
messageOutdatedWarning,
151+
'warning',
152+
false
153+
).attr('id', 'lizmap-warning-message');
154+
}
155+
156+
} else if (document.body.dataset.lizmapPluginHasWarnings) {
157+
console.warn('The project has some warnings in the Lizmap plugin.');
158+
159+
if (document.body.dataset.lizmapPluginHasWarningsUrl && withDisplay) {
160+
let messageHasWarnings = lizDict['project.has.warnings'];
161+
messageHasWarnings += `<br><a href="${document.body.dataset.lizmapPluginHasWarningsUrl}">`;
162+
messageHasWarnings += lizDict['visit.admin.panel.project.page'];
163+
messageHasWarnings += '</a>';
164+
messageHasWarnings += '<br>';
165+
messageHasWarnings += lizDict['project.admin.panel.info'];
166+
167+
// It can take times to fix these issues, the popup can be closed
168+
lizMap.addMessage(
169+
messageHasWarnings,
170+
'warning',
171+
true
172+
).attr('id', 'lizmap-outdated-plugin');
173+
}
103174
}
104175

105176
if (document.body.dataset.lizmapActionWarningOld) {
106-
lizMap.addMessage(document.body.dataset.lizmapActionWarningOld,'info',true).attr('id','lizmap-action-message');
177+
let message = 'The project uses deprecated Action JSON format. ';
178+
message += 'Read https://docs.lizmap.com/current/en/publish/lizmap_plugin/actions.html for more information';
179+
console.warn(message);
180+
181+
if (document.body.dataset.lizmapAdminUser && withDisplay) {
182+
lizMap.addMessage(
183+
document.body.dataset.lizmapActionWarningOld,
184+
'info',
185+
true
186+
).attr('id','lizmap-action-message');
187+
}
107188
}
108189
}

lizmap/modules/view/controllers/lizMap.classic.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -530,14 +530,22 @@ function f($x)
530530
$assign['googleAnalyticsID'] = $lser->googleAnalyticsID;
531531
}
532532

533-
if (\jAcl2::check('lizmap.admin.access') || \jAcl2::check('lizmap.admin.server.information.view')) {
534-
if ($lproj->qgisLizmapPluginUpdateNeeded()) {
533+
$isAdmin = \jAcl2::check('lizmap.admin.access') || \jAcl2::check('lizmap.admin.server.information.view');
534+
if ($isAdmin) {
535+
// Add body attribute to tell if current user is admin
536+
$rep->setBodyAttributes(array('data-lizmap-admin-user' => true));
537+
}
538+
539+
if ($lproj->qgisLizmapPluginUpdateNeeded()) {
540+
$rep->setBodyAttributes(array('data-lizmap-plugin-update-warning' => true));
541+
if ($isAdmin) {
535542
$rep->setBodyAttributes(array('data-lizmap-plugin-update-warning-url' => jUrl::get('admin~qgis_projects:index')));
536-
} elseif ($lproj->projectCountCfgWarnings() >= 1) {
543+
}
544+
} elseif ($lproj->projectCountCfgWarnings() >= 1) {
545+
$rep->setBodyAttributes(array('data-lizmap-plugin-has-warnings' => true));
546+
if ($isAdmin) {
537547
$rep->setBodyAttributes(array('data-lizmap-plugin-has-warnings-url' => jUrl::get('admin~qgis_projects:index')));
538548
}
539-
// add body attribute to tell if current user is admin
540-
$rep->setBodyAttributes(array('data-lizmap-admin-user' => true));
541549
}
542550

543551
$rep->body->assign($assign);

lizmap/modules/view/locales/en_US/dictionnary.UTF-8.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ startup.goToProject=Home
66
startup.goToRepositoryAdmin=Maps management page
77
startup.projectWithoutJSLink=This map without additional JavaScript
88
9+
project.has.not.found.layers=Some layers are in the WMS capabilities (*.qgs file) but are not found in the Lizmap configuration file (*.qgs.cfg). Is the Lizmap configuration file up to date ?
910
project.has.warnings=The project has some warnings in the QGIS desktop Lizmap plugin which must be fixed.
1011
project.plugin.outdated.warning=The project has been recently updated in QGIS Desktop, but with an outdated version of the Lizmap plugin. You must upgrade your plugin in QGIS Desktop.
1112
project.admin.panel.info=Only administrators or publishers can see this message.

0 commit comments

Comments
 (0)