@tsteur opened this Issue on April 23rd 2013 Owner

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 commented on April 23rd 2013 Owner

Attachment:
dashboard.patch

@tsteur commented on April 23rd 2013 Owner

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 commented on April 24th 2013 Owner

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 commented on April 24th 2013 Owner

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 commented on April 25th 2013 Owner

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

@mattab commented on April 25th 2013 Owner

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

refs #3913 provide a simple API for dashboards

@mattab commented on April 25th 2013 Owner

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

@mattab commented on May 6th 2013 Owner

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)

@tsteur commented on May 6th 2013 Owner

@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 commented on May 7th 2013 Owner

In 096f8904eba39dd35e29dacea6f103576580f807: Fixing build

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

@mattab commented on May 23rd 2013 Owner

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

This Issue was closed on May 27th 2013
Powered by GitHub Issue Mirror