- added persistent map size for non "Chrome" browsers, fixed #585

- added notification to /admin/maps page if there are no maps found
This commit is contained in:
Mark Friedrich
2018-03-30 12:47:55 +02:00
parent 240f2b27cd
commit 5b9f939137
7 changed files with 164 additions and 34 deletions

View File

@@ -421,6 +421,13 @@ class Admin extends Controller{
}
$f3->set('tplMaps', $data);
if( !isset($data->corpMaps) ){
$f3->set('tplNotification', $this->getNotificationObject('No maps found',
'Only corporation maps could get loaded' ,
'info'
));
}
}
/**

View File

@@ -25,6 +25,7 @@ class Controller {
const ERROR_SESSION_SUSPECT = 'id: [%45s], ip: [%45s], User-Agent: [%s]';
const ERROR_TEMP_CHARACTER_ID = 'Invalid temp characterId: %s';
const NOTIFICATION_TYPES = ['danger', 'warning', 'info', 'success'];
/**
* @var \Base
*/
@@ -542,6 +543,20 @@ class Controller {
return $object;
}
/**
* @param string $title
* @param string $message
* @param string $type
* @return \stdClass
*/
protected function getNotificationObject(string $title, $message = '', $type = 'danger') : \stdClass {
$notification = (object) [];
$notification->type = in_array($type, self::NOTIFICATION_TYPES) ? $type : 'danger';
$notification->title = $title;
$notification->message = $message;
return $notification;
}
/**
* get a program URL by alias
* -> if no $alias given -> get "default" route (index.php)

View File

@@ -944,35 +944,70 @@ define([
*/
let setMapWrapperObserver = (mapWrapper, mapConfig) => {
/**
* save current map dimension to local storage
* @param entry
*/
let saveMapSize = (entry) => {
let width = '';
let height = '';
if(entry.constructor.name === 'HTMLDivElement'){
width = entry.style.width;
height = entry.style.height;
}else if (entry.constructor.name === 'ResizeObserverEntry'){
width = entry.target.style.width;
height = entry.target.style.height;
}
width = parseInt(width.substring(0, width.length - 2)) || 0;
height = parseInt(height.substring(0, height.length - 2)) || 0;
let promiseStore = MapUtil.getLocaleData('map', mapConfig.config.id );
promiseStore.then((data) => {
let storeData = true;
if (
data && data.style &&
data.style.width === width &&
data.style.height === height
) {
// no style changes
storeData = false;
}
if (storeData) {
MapUtil.storeLocalData('map', mapConfig.config.id, 'style', {
width: width,
height: height
});
}
});
};
// map resize observer ----------------------------------------------------------------------------------------
if(window.ResizeObserver) {
// ResizeObserver() supported
let resizeTimer;
let wrapperResize = new ResizeObserver(entries => { // jshint ignore:line
/**
* save current map dimension to local storage
* @param entry
*/
let saveMapSize = (entry) => {
return setTimeout(() => {
let width = entry.target.style.width;
let height = entry.target.style.height;
width = parseInt( width.substring(0, width.length - 2) ) || 0;
height = parseInt( height.substring(0, height.length - 2) ) || 0;
MapUtil.storeLocalData('map', mapConfig.config.id, 'style', {
width: width,
height: height
});
}, 100);
let checkMapSize = (entry) => {
return setTimeout(saveMapSize, 100, entry);
};
for (let entry of entries){
// use timeout to "throttle" save actions
clearTimeout(resizeTimer);
resizeTimer = saveMapSize(entry);
resizeTimer = checkMapSize(entry);
}
});
wrapperResize.observe(mapWrapper[0]);
}else if(requestAnimationFrame){
// ResizeObserver() not supported
let checkMapSize = (entry) => {
saveMapSize(entry);
return setTimeout(checkMapSize, 500, entry);
};
checkMapSize(mapWrapper[0]);
}
};

View File

@@ -944,35 +944,70 @@ define([
*/
let setMapWrapperObserver = (mapWrapper, mapConfig) => {
/**
* save current map dimension to local storage
* @param entry
*/
let saveMapSize = (entry) => {
let width = '';
let height = '';
if(entry.constructor.name === 'HTMLDivElement'){
width = entry.style.width;
height = entry.style.height;
}else if (entry.constructor.name === 'ResizeObserverEntry'){
width = entry.target.style.width;
height = entry.target.style.height;
}
width = parseInt(width.substring(0, width.length - 2)) || 0;
height = parseInt(height.substring(0, height.length - 2)) || 0;
let promiseStore = MapUtil.getLocaleData('map', mapConfig.config.id );
promiseStore.then((data) => {
let storeData = true;
if (
data && data.style &&
data.style.width === width &&
data.style.height === height
) {
// no style changes
storeData = false;
}
if (storeData) {
MapUtil.storeLocalData('map', mapConfig.config.id, 'style', {
width: width,
height: height
});
}
});
};
// map resize observer ----------------------------------------------------------------------------------------
if(window.ResizeObserver) {
// ResizeObserver() supported
let resizeTimer;
let wrapperResize = new ResizeObserver(entries => { // jshint ignore:line
/**
* save current map dimension to local storage
* @param entry
*/
let saveMapSize = (entry) => {
return setTimeout(() => {
let width = entry.target.style.width;
let height = entry.target.style.height;
width = parseInt( width.substring(0, width.length - 2) ) || 0;
height = parseInt( height.substring(0, height.length - 2) ) || 0;
MapUtil.storeLocalData('map', mapConfig.config.id, 'style', {
width: width,
height: height
});
}, 100);
let checkMapSize = (entry) => {
return setTimeout(saveMapSize, 100, entry);
};
for (let entry of entries){
// use timeout to "throttle" save actions
clearTimeout(resizeTimer);
resizeTimer = saveMapSize(entry);
resizeTimer = checkMapSize(entry);
}
});
wrapperResize.observe(mapWrapper[0]);
}else if(requestAnimationFrame){
// ResizeObserver() not supported
let checkMapSize = (entry) => {
saveMapSize(entry);
return setTimeout(checkMapSize, 500, entry);
};
checkMapSize(mapWrapper[0]);
}
};

View File

@@ -66,5 +66,7 @@
</div>
</div>
</repeat>
<include href="templates/admin/notification.html" with="notification={{@tplNotification}}" />
</div>
</section>

View File

@@ -0,0 +1,9 @@
<check if="{{ @notification->title }}">
<div class="container-fluid no-padding text-left">
<div class="row">
<div class="col-xs-12 col-md-8 col-md-offset-2">
<include href="templates/modules/notification.html" with="notification={{@notification}}" />
</div>
</div>
</div>
</check>

View File

@@ -0,0 +1,27 @@
<check if="{{ @notification->title }}">
<switch expr="{{ @notification->type }}">
<case value="warning" break="true">
<set notificationTypeClass="alert-warning" />
<set notificationColorClass="txt-color-warning" />
</case>
<case value="info" break="true">
<set notificationTypeClass="alert-info" />
<set notificationColorClass="txt-color-info" />
</case>
<case value="success" break="true">
<set notificationTypeClass="alert-success" />
<set notificationColorClass="txt-color-success" />
</case>
<default>
<set notificationTypeClass="alert-danger" />
<set notificationColorClass="txt-color-danger" />
</default>
</switch>
<div class="alert {{@notificationTypeClass}}">
<span class="txt-color {{@notificationColorClass}}">{{ @notification->title }}</span>
<check if="{{ @notification->message }}">
<small>{{ @notification->message }}</small>
</check>
</div>
</check>