server_status_advisor.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* vim: set expandtab sw=4 ts=4 sts=4: */
  2. /**
  3. * Server Status Advisor
  4. *
  5. * @package PhpMyAdmin
  6. */
  7. /**
  8. * Unbind all event handlers before tearing down a page
  9. */
  10. AJAX.registerTeardown('server_status_advisor.js', function () {
  11. $('a[href="#openAdvisorInstructions"]').off('click');
  12. $('#statustabs_advisor').html('');
  13. $('#advisorDialog').remove();
  14. $('#instructionsDialog').remove();
  15. });
  16. AJAX.registerOnload('server_status_advisor.js', function () {
  17. // if no advisor is loaded
  18. if ($('#advisorData').length === 0) {
  19. return;
  20. }
  21. /** ** Server config advisor ****/
  22. var $dialog = $('<div />').attr('id', 'advisorDialog');
  23. var $instructionsDialog = $('<div />')
  24. .attr('id', 'instructionsDialog')
  25. .html($('#advisorInstructionsDialog').html());
  26. $('a[href="#openAdvisorInstructions"]').click(function () {
  27. var dlgBtns = {};
  28. dlgBtns[PMA_messages.strClose] = function () {
  29. $(this).dialog('close');
  30. };
  31. $instructionsDialog.dialog({
  32. title: PMA_messages.strAdvisorSystem,
  33. width: '60%',
  34. buttons: dlgBtns
  35. });
  36. });
  37. var $cnt = $('#statustabs_advisor');
  38. var $tbody;
  39. var $tr;
  40. var str;
  41. var even = true;
  42. data = JSON.parse($('#advisorData').text());
  43. $cnt.html('');
  44. if (data.parse.errors.length > 0) {
  45. $cnt.append('<b>Rules file not well formed, following errors were found:</b><br />- ');
  46. $cnt.append(data.parse.errors.join('<br/>- '));
  47. $cnt.append('<p></p>');
  48. }
  49. if (data.run.errors.length > 0) {
  50. $cnt.append('<b>Errors occurred while executing rule expressions:</b><br />- ');
  51. $cnt.append(data.run.errors.join('<br/>- '));
  52. $cnt.append('<p></p>');
  53. }
  54. if (data.run.fired.length > 0) {
  55. $cnt.append('<p><b>' + PMA_messages.strPerformanceIssues + '</b></p>');
  56. $cnt.append('<table class="data" id="rulesFired" border="0"><thead><tr>' +
  57. '<th>' + PMA_messages.strIssuse + '</th><th>' + PMA_messages.strRecommendation +
  58. '</th></tr></thead><tbody></tbody></table>');
  59. $tbody = $cnt.find('table#rulesFired');
  60. var rc_stripped;
  61. $.each(data.run.fired, function (key, value) {
  62. // recommendation may contain links, don't show those in overview table (clicking on them redirects the user)
  63. rc_stripped = $.trim($('<div>').html(value.recommendation).text());
  64. $tbody.append($tr = $('<tr class="linkElem noclick"><td>' +
  65. value.issue + '</td><td>' + rc_stripped + ' </td></tr>'));
  66. even = !even;
  67. $tr.data('rule', value);
  68. $tr.click(function () {
  69. var rule = $(this).data('rule');
  70. $dialog
  71. .dialog({ title: PMA_messages.strRuleDetails })
  72. .html(
  73. '<p><b>' + PMA_messages.strIssuse + ':</b><br />' + rule.issue + '</p>' +
  74. '<p><b>' + PMA_messages.strRecommendation + ':</b><br />' + rule.recommendation + '</p>' +
  75. '<p><b>' + PMA_messages.strJustification + ':</b><br />' + rule.justification + '</p>' +
  76. '<p><b>' + PMA_messages.strFormula + ':</b><br />' + rule.formula + '</p>' +
  77. '<p><b>' + PMA_messages.strTest + ':</b><br />' + rule.test + '</p>'
  78. );
  79. var dlgBtns = {};
  80. dlgBtns[PMA_messages.strClose] = function () {
  81. $(this).dialog('close');
  82. };
  83. $dialog.dialog({ width: 600, buttons: dlgBtns });
  84. });
  85. });
  86. }
  87. });