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

Introducing reusable way to display KPIs blocks in Back Office modern pages #9242

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

.kpi-refresh {
position: absolute;
z-index: 1;
top: 0;
right: 0;
}
Expand Down
4 changes: 4 additions & 0 deletions js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,10 @@ $(document).ready(function()
if ($('.kpi-container').length) {
refresh_kpis();
}

$('.kpi-refresh').on('click', '.refresh-kpis', function () {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to add this code to legacy js for the legacy refresh code to pick up the new refresh button, otherwise I would have to create all the javascript for refreshing KPIs, which I want to avoid doing in this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sense :)

refresh_kpis(true);
});
});

function bindSwapSave(context)
Expand Down
21 changes: 21 additions & 0 deletions src/Core/Kpi/Row/KpiRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
*/
final class KpiRow implements KpiRowInterface
{
/**
* @var bool
*/
private $allowRefresh = true;

/**
* @var array[KpiInterface]
*/
Expand All @@ -53,4 +58,20 @@ public function getKpis()
{
return $this->kpis;
}

/**
* @param bool $allowRefresh
*/
public function setAllowRefresh($allowRefresh)
{
$this->allowRefresh = $allowRefresh;
}

/**
* @return bool
*/
public function getAllowRefresh()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe use a isser (isRefreshAllowed()) or an hasser here (hasRefreshAllowed) ?

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, why not :)

{
return $this->allowRefresh;
}
}
10 changes: 10 additions & 0 deletions src/Core/Kpi/Row/KpiRowInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,14 @@ public function addKpi(KpiInterface $kpi);
* @return array[KpiInterface]
*/
public function getKpis();

/**
* @param bool $allowRefresh
*/
public function setAllowRefresh($allowRefresh);

/**
* @return bool
*/
public function getAllowRefresh();
}
1 change: 1 addition & 0 deletions src/Core/Kpi/Row/KpiRowPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function present(KpiRowInterface $kpiRow)

return [
'kpis' => $renderedKpis,
'allowRefresh' => $kpiRow->getAllowRefresh(),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
{% block kpi_row %}
<div class="container-fluid">
<div class="kpi-container">
{% if kpiRow.allowRefresh %}
<div class="kpi-refresh">
<button class="refresh-kpis btn btn-primary" type="button">
<i class="material-icons">refresh</i>
</button>
</div>
{% endif %}

<div class="row">
{% for kpi in kpiRow.kpis %}
<div class="col">
Expand Down