Skip to content

Commit

Permalink
#366 refactor, add map configuration section in basic settings and sy…
Browse files Browse the repository at this point in the history
…stem page, remove possibility to override the map configuration in the other conf page
  • Loading branch information
syjer committed Dec 4, 2017
1 parent da3abcd commit 4355706
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,13 @@ public String getTimezone(@RequestParam("lat") double lat, @RequestParam("lng")
@RequestMapping("/location/static-map-image")
public String getMapImage(
@RequestParam("lat") String lat,
@RequestParam("lng") String lng,
@RequestParam(value = "orgId", required = false) Integer orgId,
@RequestParam(value = "eventId", required = false) Integer eventId) {

Function<ConfigurationKeys, Configuration.ConfigurationPathKey> pathKeyBuilder = (key) -> {
if(orgId == null && eventId == null) {
return Configuration.getSystemConfiguration(key);
} else if (eventId == null) {
return Configuration.from(orgId, key);
} else {
return Configuration.from(orgId, eventId, key);
}
};

Map<ConfigurationKeys, Optional<String>> geoInfoConfiguration = getGeoConf(pathKeyBuilder);

@RequestParam("lng") String lng) {
Map<ConfigurationKeys, Optional<String>> geoInfoConfiguration = getGeoConf();
return LocationDescriptor.getMapUrl(lat, lng, geoInfoConfiguration);
}

private Map<ConfigurationKeys, Optional<String>> getGeoConf(Function<ConfigurationKeys, Configuration.ConfigurationPathKey> pathKeyBuilder) {
private Map<ConfigurationKeys, Optional<String>> getGeoConf() {
Function<ConfigurationKeys, Configuration.ConfigurationPathKey> pathKeyBuilder = (key) -> Configuration.getSystemConfiguration(key);
return configurationManager.getStringConfigValueFrom(
pathKeyBuilder.apply(ConfigurationKeys.MAPS_PROVIDER),
pathKeyBuilder.apply(ConfigurationKeys.MAPS_CLIENT_API_KEY),
Expand All @@ -95,19 +82,12 @@ private Map<ConfigurationKeys, Optional<String>> getGeoConf(Function<Configurati

@RequestMapping("/location/map-provider-client-api-key")
public ProviderAndKeys getGeoInfoProviderAndKeys() {

Function<ConfigurationKeys, Configuration.ConfigurationPathKey> pathKeyBuilder = (key) -> Configuration.getSystemConfiguration(key);

Map<ConfigurationKeys, Optional<String>> geoInfoConfiguration = getGeoConf(pathKeyBuilder);

Map<ConfigurationKeys, Optional<String>> geoInfoConfiguration = getGeoConf();
ConfigurationKeys.GeoInfoProvider provider = LocationDescriptor.getProvider(geoInfoConfiguration);

Map<ConfigurationKeys, String> apiKeys = new HashMap<>();

geoInfoConfiguration.forEach((k,v) -> {
v.ifPresent(value -> apiKeys.put(k, value));
});

return new ProviderAndKeys(provider, apiKeys);
}

Expand Down
11 changes: 6 additions & 5 deletions src/main/java/alfio/model/system/ConfigurationKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public enum ConfigurationKeys {

BASE_URL("Base application url", false, SettingCategory.GENERAL, ComponentType.TEXT, true, EnumSet.of(SYSTEM), true),

MAPS_PROVIDER("Select the maps provider (Google, Here)", false, SettingCategory.GENERAL, ComponentType.TEXT, false, EnumSet.of(SYSTEM), true),
MAPS_CLIENT_API_KEY("Google maps' client api key", false, SettingCategory.GENERAL, ComponentType.TEXT, false, EnumSet.of(SYSTEM), true),
MAPS_HERE_APP_ID("HERE map App ID", false, SettingCategory.GENERAL, ComponentType.TEXT, false, EnumSet.of(SYSTEM), true),
MAPS_HERE_APP_CODE("HERE map App Code", false, SettingCategory.GENERAL, ComponentType.TEXT, false, EnumSet.of(SYSTEM), true),
MAPS_PROVIDER("Select the maps provider (Google, Here)", false, SettingCategory.MAP, ComponentType.TEXT, false, EnumSet.of(SYSTEM), true),
MAPS_CLIENT_API_KEY("Google maps' client api key", false, SettingCategory.MAP, ComponentType.TEXT, false, EnumSet.of(SYSTEM), true),
MAPS_HERE_APP_ID("HERE map App ID", false, SettingCategory.MAP, ComponentType.TEXT, false, EnumSet.of(SYSTEM), true),
MAPS_HERE_APP_CODE("HERE map App Code", false, SettingCategory.MAP, ComponentType.TEXT, false, EnumSet.of(SYSTEM), true),


RECAPTCHA_API_KEY("Recaptcha api key", false, SettingCategory.GENERAL, ComponentType.TEXT, false, EnumSet.of(SYSTEM), true),
Expand Down Expand Up @@ -165,7 +165,8 @@ public enum SettingCategory {
INVOICE("Invoice settings"),
INVOICE_EU("Invoice settings for EU"),
MAIL("E-Mail settings"),
ALFIO_PI("Offline check-in and badge printing");
ALFIO_PI("Offline check-in and badge printing"),
MAP("Maps settings");

private final String description;
SettingCategory(String description) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,35 @@ <h2>E-Mail</h2>
</div>
</div>


<div class="page-header">
<h2>Map</h2>
<span>Map settings</span>
</div>
<div>
<p class="radio-inline">
<label>
<input type="radio" name="map.mapsProvider" data-ng-model="ctrl.map['MAPS_PROVIDER'].value" data-ng-value="'GOOGLE'">
Google maps
</label>
</p>
<p class="radio-inline">
<label>
<input type="radio" name="map.mapsProvider" data-ng-model="ctrl.map['MAPS_PROVIDER'].value" data-ng-value="'HERE'">
Here maps
</label>
</p>
<div>
<setting data-obj="ctrl.map['MAPS_CLIENT_API_KEY']" data-display-delete-if-needed="true" data-delete-handler="systemConf.delete(config)" ></setting>
</div>
<div>
<setting data-obj="ctrl.map['MAPS_HERE_APP_ID']" data-display-delete-if-needed="true" data-delete-handler="systemConf.delete(config)" ></setting>
</div>
<div>
<setting data-obj="ctrl.map['MAPS_HERE_APP_CODE']" data-display-delete-if-needed="true" data-delete-handler="systemConf.delete(config)" ></setting>
</div>
</div>

<div class="page-header" data-ng-if="ctrl.payment && ctrl.payment.settings.length > 0">
<h2>Payment</h2>
<span>Payment provider settings</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,34 @@ <h2>E-Mail</h2>
</div>
</div>

<div class="page-header">
<h2>Map</h2>
<span>Map settings</span>
</div>
<div>
<p class="radio-inline">
<label>
<input type="radio" name="map.mapsProvider" data-ng-model="systemConf.map['MAPS_PROVIDER'].value" data-ng-value="'GOOGLE'">
Google maps
</label>
</p>
<p class="radio-inline">
<label>
<input type="radio" name="map.mapsProvider" data-ng-model="systemConf.map['MAPS_PROVIDER'].value" data-ng-value="'HERE'">
Here maps
</label>
</p>
<div>
<setting data-obj="systemConf.map['MAPS_CLIENT_API_KEY']" data-display-delete-if-needed="true" data-delete-handler="systemConf.delete(config)" ></setting>
</div>
<div>
<setting data-obj="systemConf.map['MAPS_HERE_APP_ID']" data-display-delete-if-needed="true" data-delete-handler="systemConf.delete(config)" ></setting>
</div>
<div>
<setting data-obj="systemConf.map['MAPS_HERE_APP_CODE']" data-display-delete-if-needed="true" data-delete-handler="systemConf.delete(config)" ></setting>
</div>
</div>


<div class="page-header">
<h2>Invoice settings</h2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,17 @@
mailReplyTo: _.find(original['MAIL'], function(e) {return e.configurationKey === 'MAIL_REPLY_TO';}),
mailAttemptsCount: _.find(original['MAIL'], function(e) {return e.configurationKey === 'MAIL_ATTEMPTS_COUNT';})
};
};

if(angular.isDefined(original['MAP']) && original['MAP'].length > 0) {
transformed.map = {
MAPS_PROVIDER: _.find(original['MAP'], function(e) {return e.key === 'MAPS_PROVIDER';}),
MAPS_CLIENT_API_KEY: _.find(original['MAP'], function(e) {return e.key === 'MAPS_CLIENT_API_KEY';}),
MAPS_HERE_APP_ID: _.find(original['MAP'], function(e) {return e.key === 'MAPS_HERE_APP_ID';}),
MAPS_HERE_APP_CODE: _.find(original['MAP'], function(e) {return e.key === 'MAPS_HERE_APP_CODE';})
}
}

_.forEach(['PAYMENT', 'PAYMENT_STRIPE', 'PAYMENT_PAYPAL', /*'PAYMENT_MOLLIE',*/ 'PAYMENT_OFFLINE', 'INVOICE_EU', 'ALFIO_PI'], function(group) {
if(angular.isDefined(original[group]) && original[group].length > 0) {
transformed[_.camelCase(group)] = {
Expand Down Expand Up @@ -443,6 +453,12 @@
ctrl.payment = {
settings: onlyBasic(settings['PAYMENT'])
};
ctrl.map = {
MAPS_PROVIDER: _.find(settings['MAP'], function(e) {return e.key === 'MAPS_PROVIDER';}),
MAPS_CLIENT_API_KEY: _.find(settings['MAP'], function(e) {return e.key === 'MAPS_CLIENT_API_KEY';}),
MAPS_HERE_APP_ID: _.find(settings['MAP'], function(e) {return e.key === 'MAPS_HERE_APP_ID';}),
MAPS_HERE_APP_CODE: _.find(settings['MAP'], function(e) {return e.key === 'MAPS_HERE_APP_CODE';})
};
});
ctrl.saveSettings = function(frm, settings, pluginSettings) {
if(!frm.$valid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@

$scope.loading = false;
$scope.loadingMap = true;
LocationService.getMapUrl(result.event.latitude, result.event.longitude, result.event.organizationId, result.event.id).then(function(mapUrl) {
LocationService.getMapUrl(result.event.latitude, result.event.longitude).then(function(mapUrl) {
$scope.event.geolocation = {
latitude: result.event.latitude,
longitude: result.event.longitude,
Expand Down
4 changes: 2 additions & 2 deletions src/main/webapp/resources/js/admin/service/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@

var reqCounter = 0;

function getMapUrl(latitude, longitude, orgId, eventId) {
return $http.get('/admin/api/location/static-map-image', {params: {lat: latitude, lng: longitude, orgId : orgId, eventId: eventId}}).then(function(res) {
function getMapUrl(latitude, longitude) {
return $http.get('/admin/api/location/static-map-image', {params: {lat: latitude, lng: longitude}}).then(function(res) {
return res.data;
});
}
Expand Down

0 comments on commit 4355706

Please sign in to comment.