Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dashboard class undefined #18617

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 57 additions & 55 deletions src/Glpi/Dashboard/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,64 +421,66 @@ public function show(bool $mini = false, ?string $token = null)
TWIG, $params);
}

// display the grid
$html = <<<HTML
<div class="dashboard {$embed_class} {$mini_class}" id="dashboard-{$rand}">
<span class='glpi_logo'></span>
$toolbars
$filters
$grid_guide
<div class="grid-stack grid-stack-{$this->grid_cols}"
id="grid-stack-$rand"
gs-column="{$this->grid_cols}"
gs-min-row="{$this->grid_rows}"
style="width: 100%">
$gridstack_items
</div>
</div>
HTML;

if ($mini) {
$html = "<div class='card mb-4 d-none d-md-block dashboard-card'>
<div class='card-body p-2'>
$html
</div>
</div>";
}

$ajax_cards = GLPI_AJAX_DASHBOARD;
$cache_key = sha1($_SESSION['glpiactiveentities_string'] ?? "");

$js_params = json_encode([
'current' => $this->current,
'cols' => $this->grid_cols,
'rows' => $this->grid_rows,
'cell_margin' => $this->cell_margin,
'rand' => $rand,
'ajax_cards' => $ajax_cards,
'all_cards' => $cards,
'all_widgets' => $all_widgets,
'context' => $this->context,
'cache_key' => $cache_key,
'embed' => self::$embed,
'token' => $token,
'entities_id' => $_SESSION['glpiactive_entity'],
'is_recursive' => $_SESSION['glpiactive_entity_recursive'] ? 1 : 0
]);
$js = <<<JAVASCRIPT
$(function () {
// Sometimes GLPIDashboard is undefined and it messes with e2e tests
// by throwing a blocking error
// TODO: investigate why this happens
if (typeof GLPIDashboard === 'undefined') {
return;
}
new GLPIDashboard({$js_params})
});
JAVASCRIPT;
$js = Html::scriptBlock($js);

echo $html . $js;
$twig_params = [
'mini' => $mini,
'embed_class' => $embed_class,
'mini_class' => $mini_class,
'toolbars' => $toolbars,
'filters' => $filters,
'grid_guide' => $grid_guide,
'gridstack_items' => $gridstack_items,
'rand' => $rand,
'grid_cols' => $this->grid_cols,
'grid_rows' => $this->grid_rows,
'js_params' => [
'current' => $this->current,
'cols' => $this->grid_cols,
'rows' => $this->grid_rows,
'cell_margin' => $this->cell_margin,
'rand' => $rand,
'ajax_cards' => $ajax_cards,
'all_cards' => $cards,
'all_widgets' => $all_widgets,
'context' => $this->context,
'cache_key' => $cache_key,
'embed' => self::$embed,
'token' => $token,
'entities_id' => $_SESSION['glpiactive_entity'],
'is_recursive' => $_SESSION['glpiactive_entity_recursive'] ? 1 : 0
]
];
// language=Twig
echo TemplateRenderer::getInstance()->renderFromStringTemplate(<<<TWIG
{% if mini %}
<div class='card mb-4 d-none d-md-block dashboard-card'>
<div class='card-body p-2'>
{% endif %}
<div class="dashboard {{ embed_class }} {{ mini_class }}" id="dashboard-{{ rand }}">
<span class='glpi_logo'></span>
{{ toolbars|raw }}
{{ filters|raw }}
{{ grid_guide|raw }}
<div class="grid-stack grid-stack-{{ grid_cols }}"
id="grid-stack-{{ rand }}"
gs-column="{{ grid_cols }}"
gs-min-row="{{ grid_rows }}"
style="width: 100%">
{{ gridstack_items|raw }}
</div>
</div>
{% if mini %}
</div>
</div>
{% endif %}
<script type="module">
import('{{ js_path('js/modules/Dashboard/Dashboard.js') }}').then((m) => {
new m.GLPIDashboard({{ js_params|json_encode|raw }});
});
</script>
TWIG, $twig_params);
}


Expand Down
4 changes: 0 additions & 4 deletions src/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,6 @@ public static function includeHeader(

if (in_array('dashboard', $jslibs)) {
$tpl_vars['css_files'][] = ['path' => 'css/standalone/dashboard.scss'];
Html::requireJs('dashboard');
}

if (in_array('marketplace', $jslibs)) {
Expand Down Expand Up @@ -5949,9 +5948,6 @@ public static function requireJs($name)
case 'fuzzy':
$_SESSION['glpi_js_toload'][$name][] = 'lib/fuzzy.js';
break;
case 'dashboard':
$_SESSION['glpi_js_toload'][$name][] = 'js/dashboard.js';
break;
case 'marketplace':
$_SESSION['glpi_js_toload'][$name][] = 'js/marketplace.js';
break;
Expand Down
55 changes: 55 additions & 0 deletions tests/cypress/e2e/dashboards.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* ---------------------------------------------------------------------
*
* GLPI - Gestionnaire Libre de Parc Informatique
*
* http://glpi-project.org
*
* @copyright 2015-2024 Teclib' and contributors.
* @copyright 2003-2014 by the INDEPNET Development Team.
* @licence https://www.gnu.org/licenses/gpl-3.0.html
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GLPI.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ---------------------------------------------------------------------
*/
describe('Entities selector', () => {
beforeEach(() => {
cy.login();
});

const dashboards = new Map([
['Asset', '/front/dashboard_assets.php'],
['Assistance', '/front/dashboard_helpdesk.php'],
['Central', '/front/central.php'],
['Tickets Mini', '/front/ticket.php'],
]);

dashboards.forEach((value, key) => {
it(`${key} Dashboard Loads`, () => {
cy.visit(value);
cy.get('.grid-stack-item .g-chart, .grid-stack-item .big-number').should('be.visible');
// grid-stack-items should have reasonable height
cy.get('.grid-stack-item:not(.lock-bottom)').each(($el) => {
cy.get($el).invoke('height').should('be.gt', 30);
});
});
});
});
Loading