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

Closed
tsteur opened this Issue Apr 23, 2013 · 11 comments

2 participants

@tsteur
Piwik Open Source Analytics member

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"

@tsteur
Piwik Open Source Analytics member

Attachment:
dashboard.patch

@tsteur
Piwik Open Source Analytics member

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.

@mattab
Piwik Open Source Analytics member

Nice improvements!

Review:

  • 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.

@tsteur
Piwik Open Source Analytics member

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.

@tsteur
Piwik Open Source Analytics member

In 9b5f738: refs #3913 provide a simple API for dashboards

@mattab
Piwik Open Source Analytics member

In 4affef7: Merge pull request #64 from tsteur/dashboardapi

refs #3913 provide a simple API for dashboards

@mattab
Piwik Open Source Analytics member

In cdd10f9: Refs #3913 missing <?php + license block

@mattab
Piwik Open Source Analytics member

In fa4b7c4: 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)

@tsteur
Piwik Open Source Analytics member

@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.

@mattab
Piwik Open Source Analytics member

In 096f890: Fixing build

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

@mattab
Piwik Open Source Analytics member

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

@tsteur tsteur added this to the 1.12 - The Great 1.x Backlog milestone Jul 8, 2014
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment