Skip to content

Commit

Permalink
Get setting from JSON
Browse files Browse the repository at this point in the history
No inline script
No JavaScript on server side
  • Loading branch information
sbrunner committed Dec 6, 2018
1 parent 75636ff commit 26431be
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 48 deletions.
9 changes: 9 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# 2.4

For the GeoMapFish applications we must not anymore to add the dynamic.js in the application HTML file
and the ng-app, but we needs to add the following metadata:
```
<meta name="dynamicUrl" content="<application_url>/dynamic.json">
<meta name="interface" content="<interface_name>">
```
If you use the one of the abstract controllers the bootstrap will be done by `gmf/controllers/bootstrap.js`.
11 changes: 3 additions & 8 deletions contribs/gmf/apps/desktop/index.html.ejs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<!DOCTYPE html>
<html lang="{{mainCtrl.lang}}" ng-app="Appdesktop" ng-controller="DesktopController as mainCtrl" ng-strict-di>
<html lang="{{mainCtrl.lang}}" ng-controller="DesktopController as mainCtrl" ng-strict-di>
<head>
<title ng-bind-template="{{'Desktop Application'|translate}}">GeoMapFish</title>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<meta name="dynamicUrl" content="https://geomapfish-demo-dc.camptocamp.com/2.4/dynamic.json">
<meta name="interface" content="desktop">
<link rel="shortcut icon" href="<%=require("./image/favicon.ico")%>" />
<% for (var css in htmlWebpackPlugin.files.css) { %>
<link href="<%= htmlWebpackPlugin.files.css[css] %>" rel="stylesheet">
Expand Down Expand Up @@ -314,12 +316,5 @@
<% for (var chunk in htmlWebpackPlugin.files.chunks) { %>
<script src="<%= htmlWebpackPlugin.files.chunks[chunk].entry %>"></script>
<% } %>
<script>
document.write(
'<script src="https://geomapfish-demo-dc.camptocamp.com/2.4/dynamic.js?' +
'interface=desktop&' +
'query=' + encodeURIComponent(document.location.search) +
'"><' + '/script>');
</script>
</body>
</html>
4 changes: 3 additions & 1 deletion contribs/gmf/apps/desktop_alt/index.html.ejs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<!DOCTYPE html>
<html lang="{{mainCtrl.lang}}" ng-app="Appdesktop_alt" ng-controller="AlternativeDesktopController as mainCtrl" ng-strict-di>
<html lang="{{mainCtrl.lang}}" ng-controller="AlternativeDesktopController as mainCtrl" ng-strict-di>
<head>
<title ng-bind-template="{{'Alternative Desktop Application'|translate}}">GeoMapFish</title>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<meta name="dynamicUrl" content="https://geomapfish-demo-dc.camptocamp.com/2.4/dynamic.json">
<meta name="interface" content="desktop_alt">
<link rel="shortcut icon" href="<%=require("./image/favicon.ico")%>" />
<% for (var css in htmlWebpackPlugin.files.css) { %>
<link href="<%= htmlWebpackPlugin.files.css[css] %>" rel="stylesheet">
Expand Down
9 changes: 2 additions & 7 deletions contribs/gmf/apps/iframe_api/index.html.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<title ng-bind-template="{{'Iframe API Application'|translate}}">GeoMapFish</title>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<meta name="dynamicUrl" content="https://geomapfish-demo-dc.camptocamp.com/2.4/dynamic.json">
<meta name="interface" content="iframe_api">
<link rel="shortcut icon" href="<%=require("./image/favicon.ico")%>" />
<% for (var css in htmlWebpackPlugin.files.css) { %>
<link href="<%= htmlWebpackPlugin.files.css[css] %>" rel="stylesheet">
Expand Down Expand Up @@ -95,12 +97,5 @@
<% for (var chunk in htmlWebpackPlugin.files.chunks) { %>
<script src="<%= htmlWebpackPlugin.files.chunks[chunk].entry %>"></script>
<% } %>
<script>
document.write(
'<script src="https://geomapfish-demo-dc.camptocamp.com/2.4/dynamic.js?' +
'interface=iframe_api&' +
'query=' + encodeURIComponent(document.location.search) +
'"><' + '/script>');
</script>
</body>
</html>
11 changes: 3 additions & 8 deletions contribs/gmf/apps/mobile/index.html.ejs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<!DOCTYPE html>
<html lang="{{mainCtrl.lang}}" ng-app="Appmobile" ng-controller="MobileController as mainCtrl" ng-strict-di>
<html lang="{{mainCtrl.lang}}" ng-controller="MobileController as mainCtrl" ng-strict-di>
<head>
<title ng-bind-template="{{'Mobile Application'|translate}}">GeoMapFish</title>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="dynamicUrl" content="https://geomapfish-demo-dc.camptocamp.com/2.4/dynamic.json">
<meta name="interface" content="mobile">
<link rel="shortcut icon" href="<%=require("./image/favicon.ico")%>" />
<% for (var css in htmlWebpackPlugin.files.css) { %>
<link href="<%= htmlWebpackPlugin.files.css[css] %>" rel="stylesheet">
Expand Down Expand Up @@ -183,12 +185,5 @@
<% for (var chunk in htmlWebpackPlugin.files.chunks) { %>
<script src="<%= htmlWebpackPlugin.files.chunks[chunk].entry %>"></script>
<% } %>
<script>
document.write(
'<script src="https://geomapfish-demo-dc.camptocamp.com/2.4/dynamic.js?' +
'interface=mobile&' +
'query=' + encodeURIComponent(document.location.search) +
'"><' + '/script>');
</script>
</body>
</html>
11 changes: 3 additions & 8 deletions contribs/gmf/apps/mobile_alt/index.html.ejs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<!DOCTYPE html>
<html lang="{{mainCtrl.lang}}" ng-app="Appmobile_alt" ng-controller="AlternativeMobileController as mainCtrl" ng-strict-di>
<html lang="{{mainCtrl.lang}}" ng-controller="AlternativeMobileController as mainCtrl" ng-strict-di>
<head>
<title ng-bind-template="{{'Alternative Mobile Application'|translate}}">GeoMapFish</title>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="dynamicUrl" content="https://geomapfish-demo-dc.camptocamp.com/2.4/dynamic.json">
<meta name="interface" content="mobile_alt">
<link rel="shortcut icon" href="<%=require("./image/favicon.ico")%>" />
<% for (var css in htmlWebpackPlugin.files.css) { %>
<link href="<%= htmlWebpackPlugin.files.css[css] %>" rel="stylesheet">
Expand Down Expand Up @@ -192,12 +194,5 @@
<% for (var chunk in htmlWebpackPlugin.files.chunks) { %>
<script src="<%= htmlWebpackPlugin.files.chunks[chunk].entry %>"></script>
<% } %>
<script>
document.write(
'<script src="https://geomapfish-demo-dc.camptocamp.com/2.4/dynamic.js?' +
'interface=mobile_alt&' +
'query=' + encodeURIComponent(document.location.search) +
'"><' + '/script>');
</script>
</body>
</html>
12 changes: 4 additions & 8 deletions contribs/gmf/apps/oeedit/index.html.ejs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<!DOCTYPE html>
<html lang="{{mainCtrl.lang}}" ng-app="Appoeedit" ng-controller="OEEditController as mainCtrl" ng-strict-di>
<html lang="{{mainCtrl.lang}}" ng-controller="OEEditController as mainCtrl" ng-strict-di>
<head>
<title ng-bind-template="{{'ObjectEditing - Edit Application'|translate}}">GeoMapFish</title>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<meta name="dynamicUrl" content="https://geomapfish-demo-dc.camptocamp.com/2.4/dynamic.json">
<meta name="interface" content="oeedit">
<link rel="shortcut icon" href="<%=require("./image/favicon.ico")%>" />
<% for (var css in htmlWebpackPlugin.files.css) { %>
<link href="<%= htmlWebpackPlugin.files.css[css] %>" rel="stylesheet">
Expand Down Expand Up @@ -173,12 +176,5 @@
<% for (var chunk in htmlWebpackPlugin.files.chunks) { %>
<script src="<%= htmlWebpackPlugin.files.chunks[chunk].entry %>"></script>
<% } %>
<script>
document.write(
'<script src="https://geomapfish-demo-dc.camptocamp.com/2.4/dynamic.js?' +
'interface=oeedit&' +
'query=' + encodeURIComponent(document.location.search) +
'"><' + '/script>');
</script>
</body>
</html>
12 changes: 4 additions & 8 deletions contribs/gmf/apps/oeview/index.html.ejs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<!DOCTYPE html>
<html lang="{{mainCtrl.lang}}" ng-app="Appoeview" ng-controller="DesktopController as mainCtrl" ng-strict-di>
<html lang="{{mainCtrl.lang}}" ng-controller="DesktopController as mainCtrl" ng-strict-di>
<head>
<title ng-bind-template="{{'ObjectEditing - Viewer Application'|translate}}">GeoMapFish</title>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<meta name="dynamicUrl" content="https://geomapfish-demo-dc.camptocamp.com/2.4/dynamic.json">
<meta name="interface" content="oeview">
<link rel="shortcut icon" href="<%=require("./image/favicon.ico")%>" />
<% for (var css in htmlWebpackPlugin.files.css) { %>
<link href="<%= htmlWebpackPlugin.files.css[css] %>" rel="stylesheet">
Expand Down Expand Up @@ -130,12 +133,5 @@
<% for (var chunk in htmlWebpackPlugin.files.chunks) { %>
<script src="<%= htmlWebpackPlugin.files.chunks[chunk].entry %>"></script>
<% } %>
<script>
document.write(
'<script src="https://geomapfish-demo-dc.camptocamp.com/2.4/dynamic.js?' +
'interface=oeview&' +
'query=' + encodeURIComponent(document.location.search) +
'"><' + '/script>');
</script>
</body>
</html>
2 changes: 2 additions & 0 deletions contribs/gmf/src/controllers/AbstractAppController.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'jquery';
import 'angular';
import 'angular-gettext';
import 'angular-dynamic-locale';
import bootstrap from 'gmf/controllers/bootstrap.js';
import gmfAuthenticationModule from 'gmf/authentication/module.js';
import gmfBackgroundlayerselectorComponent from 'gmf/backgroundlayerselector/component.js';
import gmfDatasourceModule from 'gmf/datasource/module.js';
Expand Down Expand Up @@ -827,5 +828,6 @@ exports.module.config(['tmhDynamicLocaleProvider', 'angularLocaleScript',
}
]);

bootstrap(exports.module);

export default exports;
34 changes: 34 additions & 0 deletions contribs/gmf/src/controllers/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* global DocumentTouch */

import $ from 'jquery';

function bootstrap(module) {
const interface_ = $('meta[name=interface]')[0].attributes.content.value;
const dynamicUrl_ = $('meta[name=dynamicUrl]')[0].attributes.content.value;
const dynamicUrl = `?${dynamicUrl_}interface=${interface_}&query=${encodeURIComponent(document.location.search)}`;
const request = $.ajax(dynamicUrl, {
'dataType': 'json',
'xhrFields': {
withCredentials: false
}
});
request.fail((jqXHR, textStatus) => {
window.alert(`Failed to get the dynamic: ${textStatus}`);
});
request.done((dynamic) => {
if (dynamic['doRedirect']) {
const small_screen = window.matchMedia ? window.matchMedia('(max-width: 1024px)') : false;
if (small_screen && (('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch)) {
window.location = dynamic['redirectUrl'];
}
}

for (const name in dynamic['constants']) {
module.constant(name, dynamic['constants'][name]);
}

angular.bootstrap(document, [`App${interface_}`]);
});
}

export default bootstrap;

0 comments on commit 26431be

Please sign in to comment.