Opened 12 months ago

Closed 11 months ago

Last modified 11 months ago

#3913 closed New feature (fixed)

New Dashboard API to return list of all configured dashboard for a given user

Reported by: tsteur Owned by:
Priority: major Milestone: 1.12 - The Great 1.x Backlog
Component: Core Keywords:
Cc: Sensitive: no


I need an API to get configured dashboards for Piwik Mobile 2.

It's already implemented and will attach a diff soon. I'm not sure if I broke something because there are no tests. I think I've also fixed some issues in getAllDashboards. Just do a quick review please and I will send a pull request then. The diff will add three API methods getDashboards, getUserDashboards and getDefaultDashboard.

Structure will look like this (one entry per dashboard).

    "name": "Dashboard",
    "widgets": [
        "module": "VisitsSummary",
        "action": "getEvolutionGraph"
        "module": "Live",
        "action": "widget"
        "module": "VisitorInterest",
        "action": "getNumberOfVisitsPerVisitDuration"
        "module": "CoreHome",
        "action": "getPromoVideo"
        "module": "Referers",
        "action": "getKeywords"
        "module": "Referers",
        "action": "getWebsites"
        "module": "UserCountryMap",
        "action": "visitorMap"
        "module": "UserSettings",
        "action": "getBrowser"
        "module": "Referers",
        "action": "getSearchEngines"
        "module": "VisitTime",
        "action": "getVisitInformationPerServerTime"
        "module": "ExampleRssWidget",
        "action": "rssPiwik"

The structure is simple because I don't need more yet but we can still extend it later and add for example things like "layout": "33-33-33"

Attachments (1)

dashboard.patch (17.4 KB) - added by tsteur 12 months ago.

Download all attachments as: .zip

Change History (12)

Changed 12 months ago by tsteur

comment:1 Changed 12 months ago by tsteur

Attached the code. Kept it simple... Would make sense to extract some things to a Dashboard_Layout class but didn't want to refactor too much.

comment:2 Changed 12 months ago by matt (mattab)

  • Milestone set to 1.12 - The Great 1.x Backlog

Nice improvements!


  • Piwik Mobile is based on "metadata" reports. Here you will get "widgets". It will work OK to match Widgets->Metadata for most reports since they are called the same, but I wanted to point this out.
  • (!property_exists($widget, 'isHidden') || !$widget->isHidden); could be: !empty($widget->isHidden)
  • in getLayout($idDashboard) the block
            if (empty($layout)) {
                $layout = $this->getDefaultLayout();

should be last (because it's possible that the call to removeDisabledPluginFromLayout() will remove all widgets from existing layout, in which case we'd rather display default layout than empty.

  • the call to removeDisabledPluginFromLayout() could be done at the end of: getDefaultLayout() before the return statement, rather than done by the caller (in getLayout($idDashboard))
  • I agree it would be nice to refactor in Dashboard_Layout class (in 2.0 branch I'd like to refactor all plugins with big _Plugin classes and split up in new classes, so this is relevant!)

Do you want/need to get this in 1.12 or can we wait for 2.0 beta? It looks OK to be included in 1.12 so up to you.

comment:3 Changed 12 months ago by tsteur

thx! Will change some things and send pull request. You're right regarding removeDisabledPluginFromLayout. Will change that although it is a bit confusing that getDefaultLayout automatically removes disabled plugins and for instance getLayoutForUser does not and so on. But when cleaning this up I'd have to refactor the whole plugin because for instance removeDisabledPluginFromLayout is doing multiple things (removing plugins, adding columns if not present, encode/decode, ...).

Would be good to have it in 1.12 if possible. If we release an alpha version of Piwik Mobile 2 in a few weeks users can already see the dashboard feature.

In the beginning I will only display widgets in Piwik Mobile that are reports/metadata. Later I want to implement similar widgets for mobile app. And even later users should be able to write their own widgets :)

Will send a pull request once done.

comment:4 Changed 12 months ago by tsteur

In 9b5f738f578137389fb3572d9654e2eb6a57af15:

refs #3913 provide a simple API for dashboards

comment:5 Changed 12 months ago by matt (mattab)

In 4affef74d5f132fb8ba6695ce23e60661b6fdcea:

Merge pull request #64 from tsteur/dashboardapi

refs #3913 provide a simple API for dashboards

comment:6 Changed 12 months ago by matt (mattab)

In cdd10f9083c531d14c6bd2972846c4db48215630:

Refs #3913 missing <?php + license block

comment:7 Changed 12 months ago by matt (mattab)

In fa4b7c4aad5f6e715f922f3528560139ecf462ef:

Refs #3913 adding XML files so the build passes, but tests output is empty for now. Also moving to private unused methods (lets delete any unused method)

comment:8 Changed 12 months ago by tsteur

@Matt I need API method "getDashboards", not "getUserDashboards" :) I want to display the default dashboard in Piwik Mobile if a user hasn't created his own dashboard to be consistent with Piwik.

comment:9 Changed 12 months ago by matt (mattab)

In 096f8904eba39dd35e29dacea6f103576580f807:

Fixing build

refs #3913 Fixes API for dashboards + disabling Dashboard API tests for now

comment:10 Changed 11 months ago by matt (mattab)

  • Resolution set to fixed
  • Status changed from new to closed

Thomas please reopen if anything is left on this for 1.12. Nice work!

comment:11 Changed 11 months ago by matt (mattab)

  • Priority changed from normal to major
  • Summary changed from Dashboard API to New Dashboard API to return list of all configured dashboard for a given user
Note: See TracTickets for help on using tickets.