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

Various Api Improvements #10665

Merged
merged 8 commits into from Oct 5, 2016
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -96,6 +96,7 @@ Read more about migrating a plugin from Piwik 2.X to Piwik 3 on our [Migration g
* `PluginManager.pluginInstalled` triggered after a plugin was installed
* `PluginManager.pluginUninstalled` triggered after a plugin was uninstalled
* New HTTP Tracking API parameter `pv_id` which accepts a six character unique ID that identifies which actions were performed on a specific page view. Read more about it in the [HTTP Tracking API](https://developer.piwik.org/api-reference/tracking-api);
* New event `Segment.addSegments` that lets you add segments.

### New features
* New "Sparklines" visualization that lets you create a widget showing multiple sparklines
Expand Down
1 change: 0 additions & 1 deletion core/Report/ReportWidgetConfig.php
Expand Up @@ -7,7 +7,6 @@
*
*/
namespace Piwik\Report;
use Piwik\ViewDataTable\Factory;
use Piwik\Widget\WidgetConfig;

/**
Expand Down
20 changes: 20 additions & 0 deletions core/Widget/WidgetConfig.php
Expand Up @@ -29,6 +29,7 @@ class WidgetConfig
protected $order = 99;
protected $isEnabled = true;
protected $isWidgetizable = true;
protected $isWide = false;

/**
* Set the id of the category the widget belongs to.
Expand Down Expand Up @@ -345,5 +346,24 @@ public function getMiddlewareParameters()
return $this->middlewareParameters;
}

/**
* Marks this widget as a "wide" widget that requires the full width.
*
* @return $this
*/
public function setIsWide()
{
$this->isWide = true;
return $this;
}

/**
* Detect whether the widget should be shown wide or not.
* @return bool
*/
public function isWide()
{
return $this->isWide;
}

}
36 changes: 32 additions & 4 deletions plugins/API/SegmentMetadata.php
Expand Up @@ -10,21 +10,49 @@

use Piwik\Columns\Dimension;
use Piwik\Piwik;
use Piwik\Plugin\Segment;

class SegmentMetadata
{
public function getSegmentsMetadata($idSites = array(), $_hideImplementationData = true, $isAuthenticatedWithViewAccess)
{
$segments = array();

/**
* Triggered to add custom segment definitions.
*
* **Example**
*
* public function addSegments(&$segments)
* {
* $segment = new Segment();
* $segment->setSegment('my_segment_name');
* $segment->setType(Segment::TYPE_DIMENSION);
* $segment->setName('My Segment Name');
* $segment->setSqlSegment('log_table.my_segment_name');
* $segments[] = $segment;
* }
*
* @param array &$segments An array containing a list of segment entries.
*/
Piwik::postEvent('Segment.addSegments', array(&$segments));

foreach (Dimension::getAllDimensions() as $dimension) {
foreach ($dimension->getSegments() as $segment) {
if ($segment->isRequiresAtLeastViewAccess()) {
$segment->setPermission($isAuthenticatedWithViewAccess);
}
$segments[] = $segment;
}
}

$segments[] = $segment->toArray();
/** @var Segment[] $dimensionSegments */
$dimensionSegments = $segments;
$segments = array();

foreach ($dimensionSegments as $segment) {
if ($segment->isRequiresAtLeastViewAccess()) {
$segment->setPermission($isAuthenticatedWithViewAccess);
}

$segments[] = $segment->toArray();
}

foreach ($segments as &$segment) {
Expand Down
1 change: 1 addition & 0 deletions plugins/API/WidgetMetadata.php
Expand Up @@ -82,6 +82,7 @@ public function buildWidgetMetadata(WidgetConfig $widget, $categoryList = null)
$item['order'] = $widget->getOrder();
$item['parameters'] = $widget->getParameters();
$item['uniqueId'] = $widget->getUniqueId();
$item['isWide'] = $widget->isWide();

$middleware = $widget->getMiddlewareParameters();

Expand Down
13 changes: 9 additions & 4 deletions plugins/API/tests/Unit/WidgetMetadataTest.php
Expand Up @@ -63,7 +63,8 @@ public function test_buildWidgetMetadata_ShouldGenerateMetadata()
'module' => 'CoreHome',
'action' => 'render'
),
'uniqueId' => 'widgetCoreHomerender'
'uniqueId' => 'widgetCoreHomerender',
'isWide' => false
), $metadata);
}

Expand Down Expand Up @@ -154,7 +155,8 @@ public function test_buildWidgetMetadata_ShouldAddContainerInformtion_IfWidgetCo
'module' => 'CoreHome',
'action' => 'render',
),
'uniqueId' => 'widgetCoreHomerender'
'uniqueId' => 'widgetCoreHomerender',
'isWide' => false
), $widget1);
$this->assertSame(array(
'name' => 'NestedName2',
Expand All @@ -176,7 +178,8 @@ public function test_buildWidgetMetadata_ShouldAddContainerInformtion_IfWidgetCo
'module' => 'CoreHome',
'action' => 'render',
),
'uniqueId' => 'widgetCoreHomerender'
'uniqueId' => 'widgetCoreHomerender',
'isWide' => false
), $widget2);
}

Expand Down Expand Up @@ -219,6 +222,7 @@ public function test_buildPageMetadata_ShouldAddContainerInformtion_IfWidgetCont
'action' => 'render',
),
'uniqueId' => 'widgetCoreHomerender',
'isWide' => false
), array (
'name' => 'NestedName2',
'module' => 'CoreHome',
Expand All @@ -228,7 +232,8 @@ public function test_buildPageMetadata_ShouldAddContainerInformtion_IfWidgetCont
'module' => 'CoreHome',
'action' => 'render',
),
'uniqueId' => 'widgetCoreHomerender'
'uniqueId' => 'widgetCoreHomerender',
'isWide' => false
)
)
), $metadata);
Expand Down
20 changes: 5 additions & 15 deletions plugins/CoreAdminHome/templates/home.twig
Expand Up @@ -19,14 +19,10 @@
{% if isSuperUser %}
<div class="row">
<div class="col s12 {% if isFeedbackEnabled %}m4{% else %}m6{% endif %}">
<div piwik-content-block content-title="{{ 'CoreHome_SystemSummaryWidget'|translate }}">
<div piwik-widget-loader='{"module":"CoreHome","action":"getSystemSummary"}'></div>
</div>
<div piwik-widget-loader='{"module":"CoreHome","action":"getSystemSummary"}'></div>
</div>
<div class="col s12 {% if isFeedbackEnabled %}m4{% else %}m6{% endif %}">
<div piwik-content-block content-title="{{ 'Installation_SystemCheck'|translate }}">
<div piwik-widget-loader='{"module":"Installation","action":"getSystemCheck"}'></div>
</div>
<div piwik-widget-loader='{"module":"Installation","action":"getSystemCheck"}'></div>
</div>
{% if isFeedbackEnabled %}
<div class="col s12 m4">
Expand All @@ -39,9 +35,7 @@
{% endif %}

{% if isMarketplaceEnabled %}
<div piwik-content-block content-title="Latest Marketplace Updates">
<div piwik-widget-loader='{"module":"CorePluginsAdmin","action":"getNewPlugins", "isAdminPage": "1"}'></div>
</div>
<div piwik-widget-loader='{"module":"CorePluginsAdmin","action":"getNewPlugins", "isAdminPage": "1"}'></div>
{% endif %}

{{ postEvent('Template.adminHome') }}
Expand All @@ -61,16 +55,12 @@
<div class="row">
{% if hasDonateForm %}
<div class="col s12 {% if hasPiwikBlog %}m6{% endif %}">
<div piwik-content-block content-title="{{ 'CoreHome_SupportPiwik'|translate }}">
<div piwik-widget-loader='{"module":"CoreHome","action":"getDonateForm","widget": "0"}'></div>
</div>
<div piwik-widget-loader='{"module":"CoreHome","action":"getDonateForm","widget": "0"}'></div>
</div>
{% endif %}
{% if hasPiwikBlog %}
<div class="col s12 {% if hasDonateForm %}m6{% endif %}">
<div piwik-content-block content-title="Piwik.org Blog">
<div piwik-widget-loader='{"module":"RssWidget","action":"rssPiwik"}'></div>
</div>
<div piwik-widget-loader='{"module":"RssWidget","action":"rssPiwik"}'></div>
Copy link
Member Author

Choose a reason for hiding this comment

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

Here we can see the benefit of rendering widget headlines automatically now, we do not have to define the title twice, we automatically use the widget title defined in the widget

</div>
{% endif %}
</div>
Expand Down
30 changes: 28 additions & 2 deletions plugins/CoreHome/Controller.php
Expand Up @@ -11,7 +11,6 @@
use Exception;
use Piwik\API\Request;
use Piwik\Common;
use Piwik\DataTable\Renderer\Json;
use Piwik\Date;
use Piwik\FrontController;
use Piwik\Notification\Manager as NotificationManager;
Expand All @@ -29,6 +28,7 @@
use Piwik\Url;
use Piwik\View;
use Piwik\ViewDataTable\Manager as ViewDataTableManager;
use Piwik\Widget\WidgetConfig;

class Controller extends \Piwik\Plugin\Controller
{
Expand Down Expand Up @@ -86,7 +86,33 @@ public function renderWidget($widget)
{
Piwik::checkUserHasSomeViewAccess();

return $widget->render();
$config = new WidgetConfig();
$widget::configure($config);

$content = $widget->render();

if ($config->getName() && Common::getRequestVar('showtitle', '', 'string') === '1') {
if (strpos($content, '<h2') !== false
|| strpos($content, ' content-title=') !== false
|| strpos($content, ' piwik-enriched-headline') !== false
|| strpos($content, '<h1') !== false ) {
// already includes title
return $content;
}

if (strpos($content, 'piwik-content-block') === false
&& strpos($content, 'class="card"') === false
Copy link
Member Author

Choose a reason for hiding this comment

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

We might not detect in all cases whether someone is using the card css class manually but developers should not do this anyway, they should use piwik-content-block. So it's fine if someone was using class=" card test"

&& strpos($content, "class='card'") === false
&& strpos($content, 'class="card-content"') === false
&& strpos($content, "class='card-content'") === false) {
$view = new View('@CoreHome/_singleWidget');
$view->title = $config->getName();
$view->content = $content;
return $view->render();
}
}

return $content;
}

function redirectToCoreHomeIndex()
Expand Down
14 changes: 6 additions & 8 deletions plugins/CoreHome/angularjs/reporting-page/reportingpage-model.js
Expand Up @@ -47,7 +47,11 @@
return true;
}

return widget.viewDataTable && widget.viewDataTable === 'tableAllColumns';
if ('undefined' !== typeof widget.isWide && widget.isWide) {
return true;
}

return widget.viewDataTable && (widget.viewDataTable === 'tableAllColumns' || widget.viewDataTable === 'sparklines' || widget.viewDataTable === 'graphEvolution');
Copy link
Member Author

@tsteur tsteur Oct 4, 2016

Choose a reason for hiding this comment

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

we always display them full width

}

function buildPage(page)
Expand All @@ -69,13 +73,7 @@

reportsToIgnore = reportsToIgnore.concat(getRelatedReports(widget));

if (widget.viewDataTable && widget.viewDataTable === 'graphEvolution') {
evolutionReports.push(widget);
} else if (widget.viewDataTable && widget.viewDataTable === 'sparklines') {
sparklineReports.push(widget);
} else {
widgets.push(widget);
}
widgets.push(widget);
});

widgets = sortWidgets(widgets);
Expand Down
Expand Up @@ -4,14 +4,6 @@

<div ng-show="hasNoPage">{{ 'CoreHome_NoSuchPage'|translate }}</div>

<div class="row" ng-repeat="evolutionReport in pageModel.evolutionReports">
<div class="col s12 fullWidgetColumn" piwik-widget="evolutionReport"></div>
</div>

<div class="row" ng-repeat="sparklineReport in pageModel.sparklineReports">
<div class="col s12 fullWidgetColumn" piwik-widget="sparklineReport"></div>
</div>

<div class="row" ng-repeat="widget in pageModel.widgets">
<div class="col s12 fullWidgetColumn" ng-if="!widget.group" piwik-widget="widget"></div>

Expand Down
Expand Up @@ -13,52 +13,52 @@
max-width: 380px;
}
}
}

.entityList {
.entityList {

ul {
li {
margin: 4px 0;
padding: 0 0 0 16px;
line-height: 22px;
border-left: 2px solid @theme-color-background-base;
ul {
li {
margin: 4px 0;
padding: 0 0 0 16px;
line-height: 22px;
border-left: 2px solid @theme-color-background-base;

:hover {
opacity: 0.8;
}
&:hover:not(.activeDimension) {
border-color: @theme-color-header-background;
border-left-width: 1px;
padding-left: 17px;
}

&.activeDimension {
border-color: @theme-color-header-background;
:hover {
opacity: 0.8;
}
&:hover:not(.activeDimension) {
border-color: @theme-color-header-background;
border-left-width: 1px;
padding-left: 17px;
}

.dimension {
font-weight: bold;
}
}
&.activeDimension {
border-color: @theme-color-header-background;

.dimension {
cursor: pointer;
border-bottom: 1px solid #d0d0d0;
color: @theme-color-text-contrast;
border: 0;
font-weight: bold;
}
}

&.listCircle {
font-weight: normal;
list-style: none;
padding: 4px 0;
margin-top: 8px;
}
&.listCircle li a {
color: #000;
.dimension {
cursor: pointer;
border-bottom: 1px solid #d0d0d0;
color: @theme-color-text-contrast;
border: 0;
}
}

&.listCircle {
font-weight: normal;
list-style: none;
padding: 4px 0;
margin-top: 8px;
}
&.listCircle li a {
color: #000;
}

}

}
2 changes: 1 addition & 1 deletion plugins/CoreHome/stylesheets/zen-mode.less
Expand Up @@ -64,7 +64,7 @@
}

.goalEntry {
border-bottom: 0px;
border-bottom: 0;
}

.relatedReferrerReports {
Expand Down