Skip to content

Commit

Permalink
No panel can be added after install Intropage (#157)
Browse files Browse the repository at this point in the history
Reorganised javascript that is static into separate intropage.js file
because then the hooks remain even when the main content changes.

Closes #157
  • Loading branch information
netniV committed Jun 11, 2021
1 parent 6746123 commit e73e60c
Show file tree
Hide file tree
Showing 4 changed files with 346 additions and 353 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

--- 4.0.0 ---

* issue#143: Swapping out c3 for billboard
* Attempt to cleanup more memory leaks
* Properly keep panels that have plugin requirements from being selectable
* Dont run the polling functions for the panel if the required plugins are not enabled
* Trend function in panellib analyze requires thold but was not indicated
* feature#161: Add busiest panels (DS Stats)

* issue#143: Swapping out c3 for billboard
* issue#157: No panel can be added after install Intropage
* issue#159: Fix missing fav_graph permission
* issue#162: When user is not logged in, wrong panel data key can cause errors to appear
* issue#165: Fix PHP warning division by zero
* feature#161: Add busiest panels (DS Stats)
* feature#164: Line graph add zoom, pie graph add tooltip percentage

--- 3.0.3 ---
Expand Down
17 changes: 0 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,6 @@ in the file and how they gather their data.
If you find a problem, let me know via github or
https://forums.cacti.net/viewtopic.php?f=5&t=51920

## Changelog

-- develop --

* More minor fixups

* Minor update for 1.2.17 compatibility

* Merge pull request #129 from xmacan/bugfixes

* Minor tweaks for Midwinter theme

* issue#134: Impossible to remove Maintenance widget

* issue#132: get_login_opts missing causing plugin to crash


## Thanks

Tomas Macek, Peter Michael Calum, Trevor Leadley, Earendil
342 changes: 8 additions & 334 deletions display.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,344 +414,18 @@ function display_information() {
var intropage_drag = true;
var intropage_page = '';
var dashboard_id = <?php print $dashboard_id;?>;
var panels = {};

// display/hide detail
$(function() {
$('.flexchild').css('background-color', $('body').css('background-color'));

$('#intropage_addpanel').unbind().change(function() {
addPanel();
});

$('#intropage_action').unbind().change(function() {
actionPanel();
});

$(window).resize(function() {
resizeCharts();
});

$(window).on('orientationchange', function() {
resizeCharts();
}).trigger('orientationchange');

if (pageName == 'index.php') {
intropage_page = urlPath + pageName;
} else {
intropage_page = urlPath + 'plugins/intropage/intropage.php';
}

initPage();
});

function resizeCharts() {
$('.chart_wrapper:has(svg)').each(function() {
var chart = $(this).attr('id');
var windWidth = $(window).width() - 34;
var panelWidth = $(this).closest('.panel_wrapper').width() - 34;
var width = Math.min(windWidth, panelWidth);
var height = $(this).closest('.panel_wrapper').height() - 34;
//console.log('Chart:'+chart+', Width:'+width+', Height:'+height);

if (panels[chart] != undefined) {
panels[chart].resize({ width: width, height:height });
}
});
}

function setupHidden() {
$('.flexchild').each(function(i) {
var item = $(this);
var item_clone = item.clone();
item.data('clone', item_clone);
var position = item.position();
item_clone.css({ left: position.left, top: position.top, visibility: 'hidden' }).attr('data-pos', i+1);
$('#cloned-slides').append(item_clone);
});
}
var intropage_text_panel_details = '<?php print __('Panel Details', 'intropage');?>';
var intropage_text_panel_disable = '<?php print __esc('Disable panel move/Enable copy text from panel', 'intropage');?>';
var intropage_text_panel_enable = '<?php print __esc('Enable panel move/Disable copy text from panel', 'intropage');?>';
var intropage_text_data_error = '<?php print __('Error reading new data', 'intropage');?>';
var intropage_text_close = '<?php print __('Close', 'intropage');?>';

function addPanel() {
$.post(intropage_page, {
header: 'false',
dashboard_id: dashboard_id,
__csrf_magic: csrfMagicToken,
intropage_addpanel: $('#intropage_addpanel').val()
}).done(function(data) {
$('#main').html(data);
applySkin();
initPage();
});
}

function actionPanel() {
var option = $('#intropage_action').val();

if (option == 'loginopt_tab') {
document.location = urlPath + 'plugins/intropage/intropage.php?dashboard_id='+dashboard_id+'&intropage_action='+option;
} else if (option == 'loginopt_console') {
document.location = urlPath + 'index.php?dashboard_id='+dashboard_id+'&intropage_action='+option;
} else {
$.post(intropage_page, {
header: 'false',
dashboard_id: dashboard_id,
__csrf_magic: csrfMagicToken,
intropage_action: option
}).done(function(data) {
$('#main').html(data);
applySkin();
initPage();
});
}
}

function setPageRefresh() {
clearAllTimeouts();

if (intropage_autorefresh > 0) {
refresh = setInterval(reload_all, intropage_autorefresh*1000);
} else if (intropage_autorefresh == -1) {
pollerRefresh = setTimeout(function() {
refresh = setInterval(testPoller, 10000);
}, 30000);
}
}

function initPage() {
setPageRefresh();

$('.article').hide();

$('#obal').sortable({
tolerance: 'pointer',
forcePlaceholderSize: true,
forceHelperSize: false,
placeholder: '.flexchild',
handle: '.panel_header',
helpler: 'clone',
delay: 500,
revert: 'invalid',
scroll: false,
dropOnEmpty: false,
start: function(e, ui){
var minWidth = Math.min.apply(null,
$('.flexchild').map(function() {
return $(this).width();
}).get()
);

ui.helper.width(minWidth);
$('#obal .flexchild').css({'width': minWidth, 'flex-grow': '0'});

ui.helper.addClass('exclude-me');
ui.helper.data('clone').hide();
$('.cloned-slides .flexchild').css('visibility', 'visible');
},
stop: function(event, ui) {
$('#obal .flexchild.exclude-me').each(function() {
var item = $(this);
var clone = item.data('clone');
var position = item.position();

clone.css('left', position.left);
clone.css('top', position.top);
clone.show();

item.removeClass('exclude-me');
$('.flexchild').css('width', '');
});

$('#obal .flexchild').each(function() {
var item = $(this);
var clone = item.data('clone');

clone.attr('data-pos', item.index());
});

$('#obal .flexchild').css('visibility', 'visible');
$('.cloned-slides .flexchild').css('visibility', 'hidden');
$('#obal .flexchild').css({'width': '', 'flex-grow': '1'});
},
change: function(event, ui) {
$('#obal li:not(.exclude-me, .ui-sortable-placeholder)').each(function() {
var item = $(this);
var clone = item.data('clone');
clone.stop(true, false);
var position = item.position();
clone.animate({ left: position.left, top:position.top}, 500);
});
},
update: function(event, ui) {
// change order
var xdata = new Array();
$('#obal li').each(function() {
xdata.push($(this).attr('id'));
});

$.get(intropage_page, { xdata:xdata, intropage_action:'order' });
}
});

$('.droppanel').click(function(event) {
event.preventDefault();
var panel_div_id = $(this).attr('data-panel');
var page = $(this).attr('href');

$('#'+panel_div_id).remove();

$.get(page, function() {
$.get(page.replace('droppanel', 'addpanelselect&header=false'), function(data) {
$('#intropage_addpanel').selectmenu('destroy').replaceWith(data);
$('#intropage_addpanel').selectmenu().unbind().change(function() {
addPanel();
});

applySkin();
resizeCharts();
});
});
});

// enable/disable move panel/copy text
$('#switch_copytext').off('click').on('click', function() {
if (!intropage_drag) {
$('#obal').sortable('enable');
$('#switch_copytext').attr('title', '<?php print __esc('Disable panel move/Enable copy text from panel', 'intropage');?>');
$('.flexchild').css('cursor','move');
intropage_drag = true;
} else {
$('#obal').sortable('disable');
$('#switch_copytext').attr('title', '<?php print __esc('Enable panel move/Disable copy text from panel', 'intropage');?>');
$('.flexchild').css('cursor','default');
intropage_drag = false;
}
});

// reload single panel function
$('.reload_panel_now').off('click').on('click', function(event) {
if ($(this).data('lastClick') + 1000 > new Date().getTime()) {
event.stopPropagation();
return false;
}

$(this).data('lastClick', new Date().getTime());

var panel_id = $(this).attr('id').split('_').pop();

reload_panel(panel_id, true, false);
Pace.stop();
});

reload_all();
setupHidden();
resizeCharts();
}

function testPoller() {
$.get(urlPath+'plugins/intropage/intropage.php?&action=autoreload')
.done(function(data) {
if (data == 1) {
$('#obal li').each(function() {
var panel_id = $(this).attr('id').split('_').pop();
reload_panel(panel_id, false, false);
Pace.stop();
});

setPageRefresh();
}
});
}

function reload_panel(panel_id, forced_update, refresh) {
if (!refresh) {
$('#panel_'+panel_id).find('.panel_data').css('opacity',0);
$('#panel_'+panel_id).find('.panel_data').fadeIn('slow');
}

$.get(urlPath+'plugins/intropage/intropage.php?action=reload&force='+forced_update+'&panel_id='+panel_id)
.done(function(data) {
if ($('#panel_'+panel_id).find('.chart_wrapper').length) {
chart_id = $('#panel_'+panel_id).find('.chart_wrapper').attr('id');
if (panels[chart_id] != undefined) {
panels[chart_id].destroy();
}
}

$('#panel_'+panel_id).find('.panel_data').empty().html(data);

if (!refresh) {
$('#panel_'+panel_id).find('.panel_data').css('opacity', 1);
}

resizeCharts();
})
.fail(function(data) {
$('#panel_'+panel_id).find('.panel_data').html('<?php print __('Error reading new data', 'intropage');?>');
});
}

function reload_all() {
if ($('#overlay').dialog('instance') === undefined) {
$('#obal li.flexchild').each(function() {
var panel_id = $(this).attr('id').split('_').pop();
reload_panel(panel_id, false, true);
});
} else if (!$('#overlay').dialog('isOpen')) {
$('#obal li.flexchild').each(function() {
var panel_id = $(this).attr('id').split('_').pop();
reload_panel(panel_id, false, true);
});
}

Pace.stop();
setPageRefresh();
}

// detail to the new window
$('.maxim').click(function(event) {
event.preventDefault();
var panel_id = $(this).attr('detail-panel');

$.get(urlPath+'plugins/intropage/intropage.php?action=details&panel_id='+panel_id, function(data) {
$('#overlay_detail').html(data);

var width = $('#overlay_detail').textWidth() + 150;
var windowWidth = $(window).width();

if (width > 1200) {
width = 1200;
}

if (width > windowWidth) {
width = windowWidth - 50;
}
var panels = {};

$('#overlay').dialog({
modal: true,
autoOpen: true,
buttons: [
{
text: '<?php print __('Close', 'intropage');?>',
click: function() {
$(this).dialog('destroy');
$('#overlay_detail').empty();
},
icon: 'ui-icon-heart'
}
],
width: width,
maxHeight: 650,
resizable: true,
title: '<?php print __('Panel Details', 'intropage');?>',
});

$('#block').click(function() {
$('#overlay').dialog('close');
});
});
});
</script>

<?php
print get_md5_include_js($config['base_path'].'/plugins/intropage/include/intropage.js');

return true;
}
Loading

0 comments on commit e73e60c

Please sign in to comment.