Skip to content

Commit

Permalink
Merge pull request #455 from bmlt-enabled:fixes-to-3.18
Browse files Browse the repository at this point in the history
bug fixes mostly regarding centering the map
  • Loading branch information
otrok7 committed Jan 12, 2024
2 parents e58afae + 941b6eb commit 9c674f2
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 107 deletions.
39 changes: 23 additions & 16 deletions crouton.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Description: A tabbed based display for showing meeting information.
Author: bmlt-enabled
Author URI: https://bmlt.app
Version: 3.18.0
Version: 3.18.1
*/
/* Disallow direct access to the plugin file */
if (basename($_SERVER['PHP_SELF']) == basename(__FILE__)) {
Expand Down Expand Up @@ -126,6 +126,7 @@ class Crouton
"has_venues",
"has_common_needs"
];
private $waitMsg = '<div class="bootstrap-bmlt" id="please-wait"><button class="btn btn-lg btn-info"><span class="glyphicon glyphicon-repeat glyphicon-repeat-animate"></span>Fetching...</button></div>';
private MeetingMap\Controller $meetingMapController;
public function __construct()
{
Expand Down Expand Up @@ -290,14 +291,6 @@ private function testRootServer($root_server)
return '';
}

public function doQuit($message = '')
{
ob_flush();
flush();
$message .= '<script>document.getElementById("please-wait").style.display = "none";</script>';
return $message;
}

private function sharedRender()
{
$output = "";
Expand All @@ -318,7 +311,7 @@ public function tabbedUi($atts, $content = null)
if (isset($_GET['meeting-id'])) {
return do_shortcode($this->getDefaultMeetingDetailsPageContents());
}
return sprintf('%s<div id="bmlt-tabs" class="bmlt-tabs hide">%s</div><script>document.getElementById("please-wait").style.display = "none";</script>', $this->sharedRender(), $this->renderTable($atts));
return $this->waitMsg.sprintf('%s<div id="bmlt-tabs" class="bmlt-tabs hide">%s</div><script>document.getElementById("please-wait").style.display = "none";</script>', $this->sharedRender(), $this->renderTable($atts));
}
public function bmltHandlebar($atts, $template = null)
{
Expand Down Expand Up @@ -353,6 +346,11 @@ public function meetingMap($atts, $content = null)
if (isset($_GET['meeting-id'])) {
return do_shortcode($this->getDefaultMeetingDetailsPageContents());
}
if (is_array($atts)) {
$atts['has_venues'] = '0';
} else {
$atts = ["has_venues" => "0"];
}
return sprintf('%s<div id="bmlt-tabs" class="bmlt-tabs hide">%s</div>', $this->sharedRender(), $this->renderMap($atts, false));
}
private function getMapInitialization($mapConfig)
Expand Down Expand Up @@ -399,26 +397,35 @@ public function meetingCount($atts)
if (isset($_GET['meeting-id'])) {
return '1';
}
$random_id = rand(10000, 99999);
return $this->getInitializeCroutonBlock("crouton.meetingCount(function(res) { document.getElementById('meeting-count-$random_id').innerHTML = res; });", ...$this->getCroutonJsConfig($atts)) . "<span id='meeting-count-$random_id'></span>";
$live = '';
if (is_array($atts) && isset($atts['live']) && $atts['live']=='1') {
$live = "-live";
}
return "<span id='bmlt_tabs_meeting_count$live'>Fetching...</span>";
}

public function groupCount($atts)
{
if (isset($_GET['meeting-id'])) {
return '1';
}
$random_id = rand(10000, 99999);
return $this->getInitializeCroutonBlock("crouton.groupCount(function(res) { document.getElementById('group-count-$random_id').innerHTML = res; });", ...$this->getCroutonJsConfig($atts)) . "<span id='group-count-$random_id'></span>";
$live = '';
if (is_array($atts) && isset($atts['live']) && $atts['live']=='1') {
$live = "-live";
}
return "<span id='bmlt_tabs_group_count$live'>Fetching...</span>";
}

public function serviceBodyNames($atts)
{
if (isset($_GET['meeting-id'])) {
return '';
}
$random_id = rand(10000, 99999);
return $this->getInitializeCroutonBlock("crouton.serviceBodyNames(function(res) { document.getElementById('service-body-names-$random_id').innerHTML = res; })", ...$this->getCroutonJsConfig($atts)) . "<span id='service-body-names-$random_id'></span>";
$live = '';
if (is_array($atts) && isset($atts['live']) && $atts['live']=='1') {
$live = "-live";
}
return "<span id='bmlt_tabs_service_body_names$live'>Fetching...</span>";
}
public function handlebarFooter()
{
Expand Down
7 changes: 7 additions & 0 deletions croutonjs/meetingMap/css/meeting_map.css
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,13 @@ div.bmlt_map_container_div button {
color: #2d5c88 !important;

}
#map-search-button {
width: fit-content;
height: fit-content;
}
#map-search-button .menu-button-label {
margin: 10px;
}
.menu-button-child {
width: 32px;
height: 32px;
Expand Down
16 changes: 10 additions & 6 deletions croutonjs/meetingMap/js/meeting_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function MeetingMap(inConfig) {
const config = inConfig;
if (!config.maxZoom) config.maxZoom = 17;
if (!config.minZoom) config.minZoom = 6;
if (!config.marker_contents_template) config.marker_contents_template = croutonDefaultTemplates.marker_contents_template;
var gAllMeetings = null;
var gMeetingIdsFromCrouton = null;
var loadedCallbackFunction = null;
Expand All @@ -26,6 +27,7 @@ function MeetingMap(inConfig) {

function loadMap(inDiv, menuContext, handlebarMapOptions=null,cb=null) {
if (inDiv) {
crouton_Handlebars.registerPartial("markerContentsTemplate", config['marker_contents_template']);
gInDiv = inDiv;
createThrobber(inDiv);
if (!config.map_search) showThrobber();
Expand Down Expand Up @@ -159,15 +161,15 @@ function MeetingMap(inConfig) {
return controlDiv;
}

function loadFromCrouton(inDiv_id, meetings_responseObject, menuContext = null, handlebarMapOptions = null, callback) {
function loadFromCrouton(inDiv_id, meetings_responseObject, menuContext = null, handlebarMapOptions = null, fitBounds = true, callback) {
if (!gDelegate.isApiLoaded()) {
preloadApiLoadedCallback(loadFromCrouton, [inDiv_id, meetings_responseObject, menuContext, handlebarMapOptions, callback]);
preloadApiLoadedCallback(loadFromCrouton, [inDiv_id, meetings_responseObject, menuContext, handlebarMapOptions, fitBounds, callback]);
gDelegate.loadApi();
return;
}
let inDiv = document.getElementById(inDiv_id);
loadMap(inDiv, menuContext, handlebarMapOptions,callback);
loadAllMeetings(meetings_responseObject, true);
loadAllMeetings(meetings_responseObject, fitBounds, true);
};
function loadPopupMap(inDiv_id, meeting, handlebarMapOptions = null) {
if (!gDelegate.isApiLoaded()) {
Expand Down Expand Up @@ -248,7 +250,7 @@ function MeetingMap(inConfig) {
showThrobber();
crouton.searchByCoordinates(latlng.lat, latlng.lng, config.map_search.width);
}
function loadAllMeetings(meetings_responseObject, fitAll=false) {
function loadAllMeetings(meetings_responseObject, fitBounds=true, fitAll=false) {
if (meetings_responseObject === null && config.map_search) {
if (config.map_search.auto) nearMeSearch();
else if (config.map_search.coordinates_search) {
Expand All @@ -261,8 +263,10 @@ function MeetingMap(inConfig) {
return;
}
gAllMeetings = meetings_responseObject.filter(m => m.venue_type != 2);
const lat_lngs = gAllMeetings.reduce(function(a,m) {a.push([m.latitude, m.longitude]); return a;},[]);
gDelegate.fitBounds(lat_lngs);
if (fitBounds) {
const lat_lngs = gAllMeetings.reduce(function(a,m) {a.push([m.latitude, m.longitude]); return a;},[]);
gDelegate.fitBounds(lat_lngs);
}
searchResponseCallback();
hideThrobber();
if (config.centerMe) {
Expand Down
12 changes: 11 additions & 1 deletion croutonjs/meetingMap/meeting_map.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class Controller
'map_search_location' => '',
'map_search_coordinate_search' => '',
'map_search_zoom' => '',
'center_me' => '',
'goto' => ''
);
public $options = array();

Expand Down Expand Up @@ -208,13 +210,20 @@ private function createJavascriptConfig($options)
$ret .= 'lat:"'.$options['lat'].'",';
$ret .= 'lng:"'.$options['lng'].'",';
$ret .= 'zoom:"'.$options['zoom'].'",';
if (!empty($options['center_me'])) {
$ret .= 'centerMe:"'.$options['center_me'].'",';
}
if (!empty($options['goto'])) {
$ret .= 'goto:"'.$options['goto'].'",';
}
if (isset($options['map_search'])) {
$ret .= 'map_search: {';
foreach ($options['map_search'] as $key => $value) {
$ret .= $key.':"'.$value.'",';
}
$ret .= '},';
}
$ret .= '"marker_contents_template":'.json_encode($options['marker_contents_template']);
$ret .= '},';
return $ret;
}
Expand Down Expand Up @@ -326,7 +335,8 @@ public function processUpdate(&$options)
{
$options['api_key'] = $_POST['api_key'];
$options['tile_provider'] = $_POST['tile_provider'];
$options['tile_url'] = sanitize_url($_POST['tile_url']);
// cannot sanitize, because string contains {} characters.
$options['tile_url'] = $_POST['tile_url'];
$options['nominatim_url'] = sanitize_url($_POST['nominatim_url']);
$options['tile_attribution'] = wp_kses_post($_POST['tile_attribution']);
$options['lat'] = floatval($_POST['lat']);
Expand Down
Loading

0 comments on commit 9c674f2

Please sign in to comment.