From 31202e1c64d6d1b828ba667ca7ca36af1aab3aee Mon Sep 17 00:00:00 2001 From: Pablo Ogando Ferreira Date: Thu, 17 Oct 2024 12:49:13 +0200 Subject: [PATCH] Merge 3.0.x (#53) * PHPCSFixer * Add column in table of most viewed objects of a series (#49) * TTK-26553: Wrap statistics table text (#50) * Add services definition: * TTK-26998: Shown OM stats (#51) * Bugfix stats bundle (#52) * TTK-26552: Correct operation of cleaning filters and restarting the pager * TTK-26552: Reload to base url * Remove .idea folder * Update composer requirements --------- Co-authored-by: albacodina <48245111+albacodina@users.noreply.github.com> --- Controller/StatsController.php | 1 + .../PumukitStatsUIExtension.php | 5 ++ Resources/config/pumukit_stats_ui.yaml | 11 +++ Resources/public/css/statsui.css | 4 ++ Resources/views/MostViewed/index.html.twig | 4 +- Resources/views/Stats/js.html.twig | 72 +++++++++---------- composer.json | 2 +- 7 files changed, 59 insertions(+), 40 deletions(-) create mode 100644 Resources/config/pumukit_stats_ui.yaml diff --git a/Controller/StatsController.php b/Controller/StatsController.php index 57f8c1f..bd728d7 100644 --- a/Controller/StatsController.php +++ b/Controller/StatsController.php @@ -13,6 +13,7 @@ /** * @Route("/admin/stats") + * * @Security("is_granted('ROLE_ACCESS_STATS')") */ class StatsController extends AbstractController diff --git a/DependencyInjection/PumukitStatsUIExtension.php b/DependencyInjection/PumukitStatsUIExtension.php index bf4c23f..597e343 100644 --- a/DependencyInjection/PumukitStatsUIExtension.php +++ b/DependencyInjection/PumukitStatsUIExtension.php @@ -4,7 +4,9 @@ namespace Pumukit\StatsUIBundle\DependencyInjection; +use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Loader; use Symfony\Component\HttpKernel\DependencyInjection\Extension; class PumukitStatsUIExtension extends Extension @@ -14,6 +16,9 @@ public function load(array $configs, ContainerBuilder $container): void $configuration = new Configuration(); $this->processConfiguration($configuration, $configs); + $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $loader->load('pumukit_stats_ui.yaml'); + $permissions = [['role' => 'ROLE_ACCESS_STATS', 'description' => 'Access Stats']]; $newPermissions = array_merge($container->getParameter('pumukitschema.external_permissions'), $permissions); $container->setParameter('pumukitschema.external_permissions', $newPermissions); diff --git a/Resources/config/pumukit_stats_ui.yaml b/Resources/config/pumukit_stats_ui.yaml new file mode 100644 index 0000000..553294e --- /dev/null +++ b/Resources/config/pumukit_stats_ui.yaml @@ -0,0 +1,11 @@ +services: + _defaults: + autowire: true + autoconfigure: true + public: true + + + Pumukit\StatsUIBundle\Controller\: + resource: '../../Controller' + tags: [ 'controller.service_arguments' ] + diff --git a/Resources/public/css/statsui.css b/Resources/public/css/statsui.css index 91281a9..3952011 100644 --- a/Resources/public/css/statsui.css +++ b/Resources/public/css/statsui.css @@ -210,6 +210,10 @@ box-shadow:0 3px 10px rgba(0,0,0,.23), 0 3px 10px rgba(0,0,0,.16); } +.block-preview table th, .block-preview table tr { + word-break: break-all; +} + .btn-stats-search { padding: 8px 10px; } diff --git a/Resources/views/MostViewed/index.html.twig b/Resources/views/MostViewed/index.html.twig index c353cca..bed1de8 100644 --- a/Resources/views/MostViewed/index.html.twig +++ b/Resources/views/MostViewed/index.html.twig @@ -15,10 +15,10 @@ {{ title }} -
+
{% include "@PumukitStatsUI/MostViewed/list.html.twig" %}
-
+
diff --git a/Resources/views/Stats/js.html.twig b/Resources/views/Stats/js.html.twig index bbca555..5f47638 100644 --- a/Resources/views/Stats/js.html.twig +++ b/Resources/views/Stats/js.html.twig @@ -54,22 +54,17 @@ $('.btn-stats-calendar-remove').on('click', function(event){ event.preventDefault(); - $('#form_daterangepicker').val(moment().startOf('year').format('YYYY-MM-DD') + ' - ' + moment().format('YYYY-MM-DD')); - window.initializeAjaxRequest(); + window.location = window.location.href.split("?")[0]; }); $('.btn-stats-search-remove').on('click', function(event){ event.preventDefault(); - $('#title').val(''); - var data = window.prepareSearch(); - window.getAjaxRequest(data); + window.location = window.location.href.split("?")[0]; }); $('.btn-reset-filter').on('click',function(event) { event.preventDefault(); - $('#title').val(''); - $('#form_daterangepicker').val(moment().startOf('year').format('YYYY-MM-DD') + ' - ' + moment().format('YYYY-MM-DD')); - window.initializeAjaxRequest(); + window.location = window.location.href.split("?")[0]; }); $('.ripple-wrapper').on('click', function(event) { @@ -172,25 +167,25 @@ window.initializeAjaxRequest = function() { {% if app.request.get('_route') == 'pumukit_stats_series_index' %} - window.most_viewed_series(null,null,page); - window.views(null, null,null,page, 'month'); + window.most_viewed_series(null,null,null,0); + window.views(null, null,null,0, 'month'); {% endif %} {% if app.request.get('_route') == 'pumukit_stats_mmobj_index' %} - window.most_viewed_mmobj(null,null,page); - window.views(null,null,null,page, 'month'); + window.most_viewed_mmobj(null,null,null, 0); + window.views(null,null,null,0,'month'); {% endif %} {% if app.request.get('_route') == 'pumukit_stats_series_index_id' %} var series = "{{ app.request.attributes.get('_route_params')['id'] }}"; - window.most_viewed_series_by_id(series,null, null, null, page); - window.views_series(series,null, null,null, page, 'month'); + window.most_viewed_series_by_id(series,null, null, null, 0); + window.views_series(series,null, null,null, 0, 'month'); {% endif %} {% if app.request.get('_route') == 'pumukit_stats_mmobj_index_id' %} var mmobj = "{{ app.request.attributes.get('_route_params')['id'] }}"; - window.most_viewed_mmobj_by_id(mmobj, null, null, null, page); - window.views_mmobj(mmobj,null, null, null, page, 'month'); + window.most_viewed_mmobj_by_id(mmobj, null, null, null, 0); + window.views_mmobj(mmobj,null, null, null, 0, 'month'); {% endif %} }; @@ -333,7 +328,7 @@ var data = window.defaultAjaxValues(); from_date = data['from_date']; to_date = data['to_date']; - page = data['page']; + page = (page == 0) ? page : data['page']; } var url = "{{ path('pumukit_stats_api_mmobjmostviewed') }}"; @@ -371,7 +366,7 @@ "" + "" + "" + moment(data.mmobj.recordDate).format('YYYY-MM-DD HH:mm:ss') + "" + - "" + data.mmobj.series.i18nTitle[locale] + "" + + "" + data.mmobj.seriesTitle + "" + "" + data.num_viewed + "" + "" ); @@ -384,7 +379,8 @@ "" + "" + (page * 10 + i) + "" + "" + - "" + + "" + + "" + "" + "" ); @@ -403,7 +399,7 @@ var data = window.defaultAjaxValues(); from_date = data['from_date']; to_date = data['to_date']; - page = data['page']; + page = (page == 0) ? page : data['page']; } var url = "{{ path('pumukit_schema_api_multimediaobjects') }}"; @@ -437,8 +433,8 @@ "" + "" + moment(mmobj.recordDate).format('YYYY-MM-DD HH:mm:ss') + "" + "" + - "" + - mmobj.series.i18nTitle[locale] + + "" + + mmobj.seriesTitle + "" + "" + "" + 0 + "" + @@ -446,7 +442,7 @@ ); window.getInfoMmobj(id, from_date, to_date); window.showMmobj(mmobj); - $('.title_of_most_viewed').html(mmobj.series.i18nTitle[locale]); + $('.title_of_most_viewed').html(mmobj.seriesTitle); } }); }; @@ -456,7 +452,7 @@ var data = window.defaultAjaxValues(); from_date = data['from_date']; to_date = data['to_date']; - page = data['page']; + page = (page == 0) ? page : data['page']; group_by = data['group_by']; } @@ -478,7 +474,7 @@ }, success: function(response) { var objects = response.views; - var total = 1; + var total = 0; $('.views-table-body').html(''); objects.forEach(function(data) { total = total + data.numView; @@ -526,7 +522,7 @@ }, success: function(response) { var objects = response.views; - var total = 1; + var total = 0; $('.views-table-body').html(''); objects.forEach(function(data) { total = total + data.numView; @@ -538,6 +534,7 @@ "" ); }); + $('.total-views-objects').html(total); $('#foot-views').html(total); @@ -552,13 +549,14 @@ var data = window.defaultAjaxValues(); from_date = data['from_date']; to_date = data['to_date']; - page = data['page']; + page = (page == 0) ? page : data['page']; } var url = "{{ path('pumukit_stats_api_mmobjmostviewed') }}"; if(criteria != null && criteria !== '') { url = url + "?criteria[$text][$search]=" + criteria; } + $.ajax({ url: url, type: 'GET', @@ -586,8 +584,8 @@ "" + "" + moment(data.mmobj.recordDate).format('YYYY-MM-DD HH:mm:ss') + "" + "" + - "" + - data.mmobj.series.i18nTitle[locale] + + "" + + data.mmobj.seriesTitle + "" + "" + "" + data.num_viewed + "" + @@ -622,7 +620,7 @@ var data = window.defaultAjaxValues(); from_date = data['from_date']; to_date = data['to_date']; - page = data['page']; + page = (page == 0) ? page : data['page']; group_by = data['group_by']; } @@ -729,13 +727,13 @@ var range; if (num > 6){ if (page > 3 && page < num-3){ - range = [1,'...',page-1,page,page+1,'...',num]; + range = [0,'...',page-1,page,page+1,'...',num-1]; }else if (page <= 3){ - range = [1,2,3,4,'...',num]; - }else if (page >= num-2){ - range = [1,'...',num-3,num-2,num-1,num]; + range = [0,1,2,3,4,'...',num-1]; + }else if (page >= num-3){ + range = [0,'...',num-3,num-2,num-1]; } else { - range = [1,'...',page,'...',num]; + range = [0,'...',page,'...',num-1]; } }else{ range = Array.apply(null,Array(num)).map(function (x, i) { return i; }); @@ -748,7 +746,7 @@ window.createPager = function(data) { var pages = Math.ceil(data.total / 10); - var active_page = parseInt("{{ app.request.get('page')|default(0) }}"); + var active_page = data.page == 0 ? data.page : parseInt("{{ app.request.get('page')|default(0) }}"); var aPages = range(pages,active_page); var disabled_previous = ''; var disabled_next = ''; @@ -774,7 +772,7 @@ htmlPage = "
  • " + (element +1 )+ "
  • "; } } else { - htmlPage = "
  • " + (element +1 ) + "
  • "; + htmlPage = "
  • " + element + "
  • "; } html = html + htmlPage; }); diff --git a/composer.json b/composer.json index e7ccfbf..fa7ee83 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ "teltek" ], "require": { - "php": ">=7.2", + "php": "^8.2", "pumukit/pumukit": "^4.0" }, "homepage": "https://github.com/teltek/PumukitStatsUIBundle",