diff options
author | diosmosis <diosmosis@users.noreply.github.com> | 2019-05-14 02:46:55 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-14 02:46:55 +0300 |
commit | 4b81b3b8eea9d0e361a5219164b08b850a30392d (patch) | |
tree | 79a47fda381fa8fc4db28e0e93e7f991d13e5ab7 /plugins | |
parent | accdec4ab34ece7b4a0aa3c34055fdaafd4fde08 (diff) |
Allow period used to generate scheduled report to be different from email schedule. (#13832)
* Allow period used to generate scheduled report to be different from email schedule.
* Apply review feedback.
* Add quick test.
* Update UI tests, fix for random failure.
* Update expected screenshot.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/ScheduledReports/API.php | 28 | ||||
-rw-r--r-- | plugins/ScheduledReports/Controller.php | 10 | ||||
-rw-r--r-- | plugins/ScheduledReports/Model.php | 1 | ||||
-rw-r--r-- | plugins/ScheduledReports/angularjs/manage-scheduled-report/manage-scheduled-report.controller.js | 10 | ||||
-rw-r--r-- | plugins/ScheduledReports/lang/en.json | 5 | ||||
-rw-r--r-- | plugins/ScheduledReports/templates/_addReport.twig | 17 | ||||
-rw-r--r-- | plugins/ScheduledReports/tests/Integration/ApiTest.php | 7 |
7 files changed, 64 insertions, 14 deletions
diff --git a/plugins/ScheduledReports/API.php b/plugins/ScheduledReports/API.php index c4a61a3c01..ab82b56b7e 100644 --- a/plugins/ScheduledReports/API.php +++ b/plugins/ScheduledReports/API.php @@ -27,6 +27,7 @@ use Piwik\Plugins\LanguagesManager\LanguagesManager; use Piwik\Plugins\SegmentEditor\API as APISegmentEditor; use Piwik\Plugins\SitesManager\API as SitesManagerApi; use Piwik\ReportRenderer; +use Piwik\Scheduler\Schedule\Schedule; use Piwik\Site; use Piwik\Translate; use Piwik\Translation\Translator; @@ -92,11 +93,12 @@ class API extends \Piwik\Plugin\API * @param string $evolutionPeriodFor If set to 'each', the evolution graphs cover each day within the period. If set to 'prev', * evolution graphs cover the previous N periods. * @param int|null $evolutionPeriodN The previous N periods to query in evolution graphs if $evolutionPeriodFor is 'each'. + * @param string $periodParam the period for the report, eg 'day', 'week', 'month', 'year'. * * @return int idReport generated */ - public function addReport($idSite, $description, $period, $hour, $reportType, $reportFormat, $reports, $parameters, $idSegment = false, $evolutionPeriodFor = 'prev', - $evolutionPeriodN = null) + public function addReport($idSite, $description, $period, $hour, $reportType, $reportFormat, $reports, $parameters, $idSegment = false, + $evolutionPeriodFor = 'prev', $evolutionPeriodN = null, $periodParam = null) { Piwik::checkUserIsNotAnonymous(); Piwik::checkUserHasViewAccess($idSite); @@ -118,6 +120,7 @@ class API extends \Piwik\Plugin\API 'description' => $description, 'idsegment' => $idSegment, 'period' => $period, + 'period_param'=> $periodParam, 'hour' => $hour, 'type' => $reportType, 'format' => $reportFormat, @@ -151,8 +154,8 @@ class API extends \Piwik\Plugin\API * * @see addReport() */ - public function updateReport($idReport, $idSite, $description, $period, $hour, $reportType, $reportFormat, $reports, $parameters, $idSegment = false, $evolutionPeriodFor = 'prev', - $evolutionPeriodN = null) + public function updateReport($idReport, $idSite, $description, $period, $hour, $reportType, $reportFormat, $reports, $parameters, $idSegment = false, + $evolutionPeriodFor = 'prev', $evolutionPeriodN = null, $periodParam = null) { Piwik::checkUserIsNotAnonymous(); Piwik::checkUserHasViewAccess($idSite); @@ -176,6 +179,7 @@ class API extends \Piwik\Plugin\API 'description' => $description, 'idsegment' => $idSegment, 'period' => $period, + 'period_param'=> $periodParam, 'hour' => $hour, 'type' => $reportType, 'format' => $reportFormat, @@ -284,6 +288,12 @@ class API extends \Piwik\Plugin\API if (empty($report['evolution_graph_period_n'])) { $report['evolution_graph_period_n'] = ImageGraph::getDefaultGraphEvolutionLastPeriods(); } + + // default the period param to use to the email schedule + if (empty($report['period_param'])) { + $periodParam = $report['period'] == Schedule::PERIOD_NEVER ? Schedule::PERIOD_DAY : $report['period']; + $report['period_param'] = $periodParam; + } } // static cache @@ -332,7 +342,7 @@ class API extends \Piwik\Plugin\API // override report period if (empty($period)) { - $period = $report['period']; + $period = $report['period_param']; } // override report format @@ -571,12 +581,8 @@ class API extends \Piwik\Plugin\API $reports = $this->getReports($idSite = false, false, $idReport); $report = reset($reports); - if ($report['period'] == 'never') { - $report['period'] = 'day'; - } - if (!empty($period)) { - $report['period'] = $period; + $report['period_param'] = $period; } if (empty($date)) { @@ -596,7 +602,7 @@ class API extends \Piwik\Plugin\API $date, $language, self::OUTPUT_SAVE_ON_DISK, - $report['period'] + $report['period_param'] ); } catch (Exception $e) { diff --git a/plugins/ScheduledReports/Controller.php b/plugins/ScheduledReports/Controller.php index f8f57ea107..a204f4a9c1 100644 --- a/plugins/ScheduledReports/Controller.php +++ b/plugins/ScheduledReports/Controller.php @@ -49,6 +49,15 @@ class Controller extends \Piwik\Plugin\Controller $view->defaultEvolutionPeriodN = ImageGraph::getDefaultGraphEvolutionLastPeriods(); $view->displayFormats = ScheduledReports::getDisplayFormats(); + $view->paramPeriods = []; + foreach (Piwik::$idPeriods as $label => $id) { + if ($label === 'range') { + continue; + } + + $view->paramPeriods[$label] = Piwik::translate('Intl_Period' . ucfirst($label)); + } + $reportsByCategoryByType = array(); $reportFormatsByReportTypeOptions = array(); $reportFormatsByReportType = array(); @@ -82,6 +91,7 @@ class Controller extends \Piwik\Plugin\Controller foreach ($reports as &$report) { $report['evolutionPeriodFor'] = $report['evolution_graph_within_period'] ? 'each' : 'prev'; $report['evolutionPeriodN'] = (int) $report['evolution_graph_period_n'] ?: ImageGraph::getDefaultGraphEvolutionLastPeriods(); + $report['periodParam'] = $report['period_param']; $report['recipients'] = API::getReportRecipients($report); $reportsById[$report['idreport']] = $report; diff --git a/plugins/ScheduledReports/Model.php b/plugins/ScheduledReports/Model.php index 27b6fc6433..d1ec94ed9f 100644 --- a/plugins/ScheduledReports/Model.php +++ b/plugins/ScheduledReports/Model.php @@ -87,6 +87,7 @@ class Model `deleted` tinyint(4) NOT NULL default 0, `evolution_graph_within_period` TINYINT(4) NOT NULL DEFAULT 0, `evolution_graph_period_n` INT(11) NOT NULL, + `period_param` VARCHAR(10) NULL, PRIMARY KEY (`idreport`)"; DbHelper::createTable(self::$rawPrefix, $reportTable); diff --git a/plugins/ScheduledReports/angularjs/manage-scheduled-report/manage-scheduled-report.controller.js b/plugins/ScheduledReports/angularjs/manage-scheduled-report/manage-scheduled-report.controller.js index a8135caad4..5070a3fe68 100644 --- a/plugins/ScheduledReports/angularjs/manage-scheduled-report/manage-scheduled-report.controller.js +++ b/plugins/ScheduledReports/angularjs/manage-scheduled-report/manage-scheduled-report.controller.js @@ -65,6 +65,7 @@ 'reports': [], 'evolutionPeriodFor': 'prev', 'evolutionPeriodN': ReportPlugin.defaultEvolutionPeriodN, + 'periodParam': ReportPlugin.defaultPeriod, }; if (idReport > 0) { @@ -139,6 +140,7 @@ apiParameters.idSegment = this.report.idsegment; apiParameters.reportType = this.report.type; apiParameters.reportFormat = this.report['format' + this.report.type]; + apiParameters.periodParam = this.report.periodParam; apiParameters.evolutionPeriodFor = this.report.evolutionPeriodFor; if (apiParameters.evolutionPeriodFor !== 'each') { apiParameters.evolutionPeriodN = this.report.evolutionPeriodN; @@ -231,6 +233,10 @@ }; this.getFrequencyPeriodSingle = function () { + if (!this.report || !this.report.period) { + return ''; + } + var translation = ReportPlugin.periodTranslations[this.report.period]; if (!translation) { translation = ReportPlugin.periodTranslations.day; @@ -238,6 +244,10 @@ return translation.single; }; this.getFrequencyPeriodPlural = function () { + if (!this.report || !this.report.period) { + return ''; + } + var translation = ReportPlugin.periodTranslations[this.report.period]; if (!translation) { translation = ReportPlugin.periodTranslations.day; diff --git a/plugins/ScheduledReports/lang/en.json b/plugins/ScheduledReports/lang/en.json index bfcaadfcf9..42afb27062 100644 --- a/plugins/ScheduledReports/lang/en.json +++ b/plugins/ScheduledReports/lang/en.json @@ -55,6 +55,9 @@ "NoTokenProvided": "No token was provided in the URL", "NoSubscriptionFound": "No subscription found. Maybe the report was already unsubscribed or removed.", "EvolutionGraphsShowForEachInPeriod": "Evolution graphs show the evolution for %1$seach day%2$s in the last %3$s", - "EvolutionGraphsShowForPreviousN": "Evolution graphs show the evolution over the previous N %s" + "EvolutionGraphsShowForPreviousN": "Evolution graphs show the evolution over the previous N %s", + "ReportPeriod": "Report Period", + "ReportPeriodHelp": "The period of data covered by this report. By default this is the same as the email schedule, so if the report is sent weekly, it will contain information regarding the last week.", + "ReportPeriodHelp2": "You can change this, however, if you want to see different information and still retain the email schedule. For example, if the email schedule is weekly, and the report period is 'day', you will get information for the last day, every week." } } diff --git a/plugins/ScheduledReports/templates/_addReport.twig b/plugins/ScheduledReports/templates/_addReport.twig index 3d5bc509c5..11f960619f 100644 --- a/plugins/ScheduledReports/templates/_addReport.twig +++ b/plugins/ScheduledReports/templates/_addReport.twig @@ -38,13 +38,28 @@ {{ 'ScheduledReports_MonthlyScheduleHelp'|translate }} </div> - <div piwik-field uicontrol="select" name="report_period" + <div piwik-field uicontrol="select" name="report_schedule" options="{{ periods|json_encode }}" ng-model="manageScheduledReport.report.period" + ng-change="manageScheduledReport.report.periodParam = manageScheduledReport.report.period === 'never' ? null : manageScheduledReport.report.period" data-title="{{ 'ScheduledReports_EmailSchedule'|translate|e('html_attr') }}" inline-help="#emailScheduleInlineHelp"> </div> + <div id="emailReportPeriodInlineHelp" class="inline-help-node"> + {{ 'ScheduledReports_ReportPeriodHelp'|translate }} + <br/><br/> + {{ 'ScheduledReports_ReportPeriodHelp2'|translate }} + </div> + + <div piwik-field uicontrol="select" name="report_period" + options="{{ paramPeriods|json_encode }}" + ng-model="manageScheduledReport.report.periodParam" + title="{{ 'ScheduledReports_ReportPeriod'|translate|e('html_attr') }}" + inline-help="#emailReportPeriodInlineHelp" + > + </div> + <div piwik-field uicontrol="select" name="report_hour" options="manageScheduledReport.reportHours" ng-change="manageScheduledReport.updateReportHourUtc()" diff --git a/plugins/ScheduledReports/tests/Integration/ApiTest.php b/plugins/ScheduledReports/tests/Integration/ApiTest.php index 11ffcdba77..247b2136da 100644 --- a/plugins/ScheduledReports/tests/Integration/ApiTest.php +++ b/plugins/ScheduledReports/tests/Integration/ApiTest.php @@ -68,6 +68,7 @@ class ApiTest extends IntegrationTestCase 'description' => 'test description"', 'type' => 'email', 'period' => Schedule::PERIOD_DAY, + 'period_param' => 'month', 'hour' => '4', 'format' => 'pdf', 'reports' => array('UserCountry_getCountry'), @@ -708,7 +709,11 @@ class ApiTest extends IntegrationTestCase $data['type'], $data['format'], $data['reports'], - $data['parameters'] + $data['parameters'], + $idSegment = false, + $evolutionPeriodFor = 'prev', + $evolutionPeriodN = null, + $periodParam = isset($data['period_param']) ? $data['period_param'] : null ); return $idReport; } |