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
Further improvements to Dashboard API #12609
Conversation
* | ||
* @return array[] | ||
*/ | ||
public function getDashboards() | ||
public function getDashboards($login = '', $returnDefaultIfEmpty = true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method was kind of useless without the additional parameters, as it did not allow to fetch dashboards of a specific user. Also it always returned at least one dashboard, even if there isn't one in the database. Therefor the second param can now be set, to get the real result of the database. We can't simply change this behavior, as it would break Matomo Mobile
@@ -138,7 +138,7 @@ public function saveLayout() | |||
$session->dashboardLayout = $layout; | |||
$session->setExpirationSeconds(1800); | |||
} else { | |||
$this->getModel()->updateLayoutForUser(Piwik::getCurrentUserLogin(), $idDashboard, $layout); | |||
$this->getModel()->createOrUpdateDashboard(Piwik::getCurrentUserLogin(), $idDashboard, $layout); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ensures, that the dashboard is created if it does not yet exists. That is e.g. the case if all dashboards were removed from database. The UI then shows the default dashboard (with id 1), even if it isn't stored in DB. Changing the dashboard in UI will trigger an updateLayout (which failed before, as the dashboard wasn't created).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice solution 👍
if (!empty($layout)) { | ||
$layout = $this->dashboard->removeDisabledPluginFromLayout($layout); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved that block, as it might be possible that the default layout might contain unavailable widgets as well.
👍 looks good |
@sgiehl 👍 nicely done! I'm merging now, but could you please add an entry in the CHANGELOG for the new API feature/behavior? |
* Further improvements to Dashboard API * adds some tests
fixes #12608