diff --git a/Koha/REST/V1/ERM/EUsage/CustomReports.pm b/Koha/REST/V1/ERM/EUsage/CustomReports.pm index e924d00187..2401c5cb27 100644 --- a/Koha/REST/V1/ERM/EUsage/CustomReports.pm +++ b/Koha/REST/V1/ERM/EUsage/CustomReports.pm @@ -28,9 +28,10 @@ use Koha::ERM::EUsage::UsageDatabases; use Koha::ERM::EUsage::UsageDataProvider; use Koha::ERM::EUsage::UsageDataProviders; -use Clone qw( clone ); -use Scalar::Util qw( blessed ); -use Try::Tiny qw( catch try ); +use Clone qw( clone ); +use Scalar::Util qw( blessed ); +use Try::Tiny qw( catch try ); +use List::MoreUtils qw(uniq); use JSON; =head1 API @@ -48,13 +49,12 @@ sub monthly_report { return try { - my $args = $c->validation->output; - + my $args = $c->param('q'); my @query_params_array; my $json = JSON->new; - if ( ref( $args->{q} ) eq 'ARRAY' ) { - foreach my $q ( @{ $args->{q} } ) { + if ( ref($args) eq 'ARRAY' ) { + foreach my $q ( @{$args} ) { push @query_params_array, $json->decode($q) if $q; } @@ -68,6 +68,10 @@ sub monthly_report { Koha::ERM::EUsage::UsageDataProviders->search( {}, {} )->unblessed; my $metric_types = $query_params_array[0][0]->{'erm_usage_muses.metric_type'}; + my $access_types = + $query_params_array[0][0]->{'erm_usage_muses.access_type'} + ? $query_params_array[0][0]->{'erm_usage_muses.access_type'} + : (); # Objects with no data in the selected range will not be returned by the API - we still want to include them if they have been requested my $requested_ids = _get_correct_query_param( @@ -85,45 +89,18 @@ sub monthly_report { push @{$data}, $missing_result if $missing_result; } - my @report_data; - - for my $data_object ( @{$data} ) { - - # Add provider name rather than embed provider object - my $usage_data_provider_id = $data_object->{usage_data_provider_id}; - my @provider_object = - grep { $usage_data_provider_id eq $_->{erm_usage_data_provider_id} } @{$usage_data_providers}; - my $provider_name = $provider_object[0]->{name}; - - # Split data objects into metric_types i.e. one table row per metric_type - for my $metric_type (@$metric_types) { - my $statistics = $data_object->{'erm_usage_muses'}; - my @filtered_statistics = - grep { $metric_type eq $_->{metric_type} } @$statistics; - my @usage_counts = - map { $_->{usage_count} } @filtered_statistics; - my $sum = - scalar(@usage_counts) > 0 - ? eval join '+', @usage_counts - : 0; - - my $data_object_hash = _get_object_hash( - { - data_type => $data_type, - data_object => $data_object, - statistics => \@filtered_statistics, - provider => $provider_name, - metric_type => $metric_type, - period => 'monthly', - sum => $sum - } - ); - - push @report_data, $data_object_hash; + my $report_data = _get_report_data( + { + data_type => $data_type, + data => $data, + metric_types => $metric_types, + access_types => $access_types, + usage_data_providers => $usage_data_providers, + period => 'monthly' } - } + ); - return $c->render( status => 200, openapi => \@report_data ); + return $c->render( status => 200, openapi => $report_data ); } catch { $c->unhandled_exception($_); }; @@ -140,13 +117,12 @@ sub yearly_report { my $c = shift->openapi->valid_input or return; return try { - my $args = $c->validation->output; - + my $args = $c->param('q'); my @query_params_array; my $json = JSON->new; - if ( ref( $args->{q} ) eq 'ARRAY' ) { - foreach my $q ( @{ $args->{q} } ) { + if ( ref($args) eq 'ARRAY' ) { + foreach my $q ( @{$args} ) { push @query_params_array, $json->decode($q) if $q; } @@ -176,38 +152,23 @@ sub yearly_report { } my $metric_types = $query_params_array[0]->{'erm_usage_yuses.metric_type'}; - my @report_data; + my $access_types = + $query_params_array[0]->{'erm_usage_yuses.access_type'} + ? $query_params_array[0]->{'erm_usage_yuses.access_type'} + : (); - for my $data_object ( @{$data} ) { - - # Add provider name rather than embed provider object - my $usage_data_provider_id = $data_object->{usage_data_provider_id}; - my @provider_object = - grep { $usage_data_provider_id eq $_->{erm_usage_data_provider_id} } @{$usage_data_providers}; - my $provider_name = $provider_object[0]->{name}; - - # Split data objects into metric_types i.e. one table row per metric_type - for my $metric_type (@$metric_types) { - my $statistics = $data_object->{'erm_usage_yuses'}; - my @filtered_statistics = - grep { $metric_type eq $_->{metric_type} } @$statistics; - - my $data_object_hash = _get_object_hash( - { - data_type => $data_type, - data_object => $data_object, - statistics => \@filtered_statistics, - provider => $provider_name, - metric_type => $metric_type, - period => 'yearly' - } - ); - - push @report_data, $data_object_hash; + my $report_data = _get_report_data( + { + data_type => $data_type, + data => $data, + metric_types => $metric_types, + access_types => $access_types, + usage_data_providers => $usage_data_providers, + period => 'yearly' } - } + ); - return $c->render( status => 200, openapi => \@report_data ); + return $c->render( status => 200, openapi => $report_data ); } catch { $c->unhandled_exception($_); }; @@ -225,13 +186,12 @@ sub metric_types_report { return try { - my $args = $c->validation->output; - + my $args = $c->param('q'); my @query_params_array; my $json = JSON->new; - if ( ref( $args->{q} ) eq 'ARRAY' ) { - foreach my $q ( @{ $args->{q} } ) { + if ( ref($args) eq 'ARRAY' ) { + foreach my $q ( @{$args} ) { push @query_params_array, $json->decode($q) if $q; } @@ -260,20 +220,19 @@ sub metric_types_report { push @{$data}, $missing_result if $missing_result; } - my @report_data; + my @metric_types = ('metric_types_report'); + my $report_data = _get_report_data( + { + data_type => $data_type, + data => $data, + metric_types => \@metric_types, + access_types => undef, + usage_data_providers => $usage_data_providers, + period => 'monthly' + } + ); - for my $data_object ( @{$data} ) { - - # Add provider name rather than embed provider object - my $usage_data_provider_id = $data_object->{usage_data_provider_id}; - my @provider_object = - grep { $usage_data_provider_id eq $_->{erm_usage_data_provider_id} } @{$usage_data_providers}; - my $provider_name = $provider_object[0]->{name}; - $data_object->{provider_name} = $provider_name; - - push @report_data, $data_object; - } - return $c->render( status => 200, openapi => \@report_data ); + return $c->render( status => 200, openapi => $report_data ); } catch { $c->unhandled_exception($_); }; @@ -291,21 +250,20 @@ sub provider_rollup_report { return try { - my $args = $c->validation->output; - - my $usage_data_providers_set = Koha::ERM::EUsage::UsageDataProviders->new; - my $usage_data_providers = $c->objects->search($usage_data_providers_set); - + my $args = $c->param('q'); my @query_params_array; my $json = JSON->new; - if ( ref( $args->{q} ) eq 'ARRAY' ) { - foreach my $q ( @{ $args->{q} } ) { + if ( ref($args) eq 'ARRAY' ) { + foreach my $q ( @{$args} ) { push @query_params_array, $json->decode($q) if $q; } } + my $usage_data_providers_set = Koha::ERM::EUsage::UsageDataProviders->new; + my $usage_data_providers = $c->objects->search($usage_data_providers_set); + my $data_type = $c->validation->param('data_type'); my $key = 'erm_usage_' . $data_type . 's'; my $metric_types = @@ -325,9 +283,8 @@ sub provider_rollup_report { grep { $metric_type eq $_->{metric_type} } @$statistics; my @usage_counts = map { $_->{usage_count} } @filtered_statistics; - my $sum = - scalar(@usage_counts) > 0 - ? eval join '+', @usage_counts + my $sum = scalar(@usage_counts) > 0 + ? _get_usage_total( \@usage_counts ) : 0; my $data_object_hash = _get_object_hash( @@ -349,7 +306,7 @@ sub provider_rollup_report { map { $_->{usage_total} } @filtered_object_data; my $provider_rollup_total = scalar(@data_object_usage_totals) > 0 - ? eval join '+', @data_object_usage_totals + ? _get_usage_total(@data_object_usage_totals) : 0; my %usage_data_provider_hash = ( @@ -481,6 +438,8 @@ sub _get_object_hash { my $statistics = $args->{statistics}; my $provider = $args->{provider}; my $metric_type = $args->{metric_type}; + my $access_type = $args->{access_type}; + my $yop = $args->{yop}; my $period = $args->{period}; my $sum = $args->{sum}; my %object_hash; @@ -497,7 +456,10 @@ sub _get_object_hash { title_uri => $data_object->{title_uri}, publisher => $data_object->{publisher}, publisher_id => $data_object->{publisher_id}, + platform => $data_object->{platform}, metric_type => $metric_type, + access_type => $access_type, + yop => $yop, ); } if ( $data_type eq 'platform' ) { @@ -572,4 +534,169 @@ sub _get_missing_data { return $item if $item; } +=head3 _get_report_data + +Takes the dataset retrieved from the database and converts it into a reportable set of data +Each title in the dataset needs to be split into rows depending on its different properties - YOP, access_type, metric_type + +=cut + +sub _get_report_data { + my ($args) = @_; + + my $data = $args->{data}; + my $metric_types = $args->{metric_types}; + my $access_types = $args->{access_types}; + my $usage_data_providers = $args->{usage_data_providers}; + my $data_type = $args->{data_type}; + my $period = $args->{period}; + my $data_key = $period eq 'monthly' ? 'erm_usage_muses' : 'erm_usage_yuses'; + my @report_data; + + for my $data_object ( @{$data} ) { + + # Add provider name rather than embed provider object + my $usage_data_provider_id = $data_object->{usage_data_provider_id}; + my @provider_object = + grep { $usage_data_provider_id eq $_->{erm_usage_data_provider_id} } @{$usage_data_providers}; + my $provider_name = $provider_object[0]->{name}; + + my $statistics = $data_object->{$data_key}; + my @yops = uniq map( $_->{yop}, @$statistics ); + @yops = grep defined, @yops; + + # Split data objects into metric_types i.e. one table row per metric_type + if ( scalar(@yops) > 0 ) { + for my $yop (@yops) { + _create_report_rows( + { + data_object => $data_object, + statistics => $statistics, + metric_types => $metric_types, + access_types => $access_types, + provider_name => $provider_name, + data_type => $data_type, + period => $period, + report_data => \@report_data, + yop => $yop, + } + ); + + } + } else { + _create_report_rows( + { + data_object => $data_object, + statistics => $statistics, + metric_types => $metric_types, + access_types => $access_types, + provider_name => $provider_name, + data_type => $data_type, + period => $period, + report_data => \@report_data, + yop => undef, + } + ); + } + } + return \@report_data; +} + +=head3 _create_report_rows + +A helper function for creating report rows based on access_type and metric_type + +=cut + +sub _create_report_rows { + my ($args) = @_; + + my $data_object = $args->{data_object}; + my $statistics = $args->{statistics}; + my $metric_types = $args->{metric_types}; + my $access_types = $args->{access_types}; + my $provider_name = $args->{provider_name}; + my $data_type = $args->{data_type}; + my $period = $args->{period}; + my $report_data = $args->{report_data}; + my $yop = $args->{yop}; + + if ( $access_types && scalar(@$access_types) > 0 ) { + for my $access_type (@$access_types) { + for my $metric_type (@$metric_types) { + my @usage_stats = $yop ? grep { $yop eq $_->{yop} } @$statistics : @$statistics; + my @stats_by_access_type = + grep { $access_type eq $_->{access_type} } @usage_stats; + my @stats_by_metric_type = + grep { $metric_type eq $_->{metric_type} } @stats_by_access_type; + my @usage_counts = + map { $_->{usage_count} } @stats_by_metric_type; + my $sum = $period eq 'monthly' && scalar(@usage_counts) > 0 + ? _get_usage_total( \@usage_counts ) + : 0; + + my $data_object_hash = _get_object_hash( + { + data_type => $data_type, + data_object => $data_object, + statistics => \@stats_by_metric_type, + provider => $provider_name, + metric_type => $metric_type, + access_type => $access_type, + yop => $yop ? $yop : undef, + period => $period, + sum => $sum + } + ); + push @$report_data, $data_object_hash; + } + } + } else { + for my $metric_type (@$metric_types) { + my @usage_stats = $yop ? grep { $yop eq $_->{yop} } @$statistics : @$statistics; + my @stats_by_metric_type = + $metric_type ne 'metric_types_report' + ? grep { $metric_type eq $_->{metric_type} } @usage_stats + : @usage_stats; + my @usage_counts = + map { $_->{usage_count} } @stats_by_metric_type; + my $sum = $period eq 'monthly' && scalar(@usage_counts) > 0 + ? _get_usage_total(\@usage_counts) + : 0; + + my $data_object_hash = _get_object_hash( + { + data_type => $data_type, + data_object => $data_object, + statistics => \@stats_by_metric_type, + provider => $provider_name, + metric_type => $metric_type, + access_type => undef, + yop => $yop ? $yop : undef, + period => $period, + sum => $sum + } + ); + push @$report_data, $data_object_hash; + } + } +} + +=head3 + +A method for summing the usage counts for a data object + +=cut + +sub _get_usage_total { + my ( $statistics ) = @_; + + my $sum = 0; + foreach my $statistic (@$statistics) { + $sum += $statistic; + } + + return $sum +} + 1; diff --git a/Koha/REST/V1/ERM/EUsage/SushiServices.pm b/Koha/REST/V1/ERM/EUsage/SushiServices.pm index 8e17294840..e0b85b1747 100644 --- a/Koha/REST/V1/ERM/EUsage/SushiServices.pm +++ b/Koha/REST/V1/ERM/EUsage/SushiServices.pm @@ -39,11 +39,11 @@ use Koha::Exceptions; sub get { my $c = shift->openapi->valid_input or return; - my $args = $c->validation->output; + my $args = $c->param('q'); my $json = JSON->new; my @query_params_array = - map { $_ ? $json->decode($_) : () } @{ $args->{q} }; + map { $_ ? $json->decode($_) : () } @{ $args }; my $service_url = $query_params_array[0]->{url}; diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProvidersSummary.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProvidersSummary.vue index 002c6471c5..6db374a523 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProvidersSummary.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsDataProvidersSummary.vue @@ -125,13 +125,12 @@ export default { const table = this.$refs.table.$el.getElementsByTagName("table")[0] const row = table.insertRow(0) - const [cellOne, cellTwo, cellThree, cellFour, cellFive] = [ - ...Array(5).keys(), - ].map(item => { - const cell = document.createElement("th") - row.appendChild(cell) - return cell - }) + const [cellOne, cellTwo, cellThree, cellFour, cellFive] = + Array.from("1".repeat(5)).map(item => { + const cell = document.createElement("th") + row.appendChild(cell) + return cell + }) cellTwo.colSpan = 2 cellTwo.innerHTML = "Title reports" cellThree.colSpan = 2 diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsReportBuilder.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsReportBuilder.vue index cf707783bb..a229e04f2f 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsReportBuilder.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsReportBuilder.vue @@ -98,10 +98,10 @@ >{{ $__("Choose metric type") }}: +
  • + + +
  • { return object[`${db_table}_id`] }) - queryByYear[`erm_usage_yuses.${db_table}_id`] = object_ids + queryObject[`erm_usage_yuses.${db_table}_id`] = object_ids } // Add any data provider query if (usage_data_providers) { @@ -772,6 +799,12 @@ export default { break } + if (report_type === "TR_J3" || report_type === "TR_B3") { + this.access_types_options = ["Controlled", "OA_Gold"] + } else { + this.access_types_options = [] + } + for (const metric in this.metric_types_matrix) { if ( this.metric_types_matrix[metric].includes( @@ -889,6 +922,7 @@ export default { data_display, report_type, metric_types, + access_types, } = queryObject if (!report_type || !start_year || !end_year) { @@ -918,6 +952,18 @@ export default { ) queryObject.metric_types = final_metric_types } + // If no access types are selected then all possible values should be included for backend data filtering ( but only for TR_J3 and TR_B3 reports) + if ( + (report_type === "TR_J3" || report_type === "TR_B3") && + (!access_types || (access_types && access_types.length === 0)) + ) { + const final_access_types = this.access_types_options.map( + access => { + return access + } + ) + queryObject.access_types = final_access_types + } // Determine which database table should be queried const url = !data_display.includes("yearly") diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsReportsViewer.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsReportsViewer.vue index c6b1b0bba0..aefc745d70 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsReportsViewer.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/UsageStatisticsReportsViewer.vue @@ -31,11 +31,13 @@ export default { setup() { const table = ref() - const { getMonthsData, getColumnOptions } = inject("reportsStore") + const { getMonthsData, getColumnOptions, checkReportColumns } = + inject("reportsStore") return { getMonthsData, getColumnOptions, + checkReportColumns, table, } }, @@ -106,13 +108,14 @@ export default { } }, methods: { - buildColumnArray(report_type, params, data_type) { + buildColumnArray(report_display, params, data_type) { const columns = params.columns const months_data = this.getMonthsData() const column_options = this.getColumnOptions() const time_period_columns = params.tp_columns const yearly_filter = params.yearly_filter const query = params.queryObject + const report_type = params.queryObject.report_type const column_set = [] columns.forEach(column => { @@ -121,7 +124,7 @@ export default { if (column !== 1) column_options[column].active = false }) - report_type !== "usage_data_provider" && + report_display !== "usage_data_provider" && column_set.unshift({ title: __( data_type.charAt(0).toUpperCase() + data_type.slice(1) @@ -132,7 +135,25 @@ export default { }) // Add metric type to each row - if (report_type !== "metric_type") { + if (report_display !== "metric_type") { + // Add yop if it is required + if (this.checkReportColumns(report_type, "YOP")) { + column_set.push({ + title: __("YOP"), + data: "yop", + searchable: true, + orderable: true, + }) + } + // Add access type if it is required + if (this.checkReportColumns(report_type, "Access_Type")) { + column_set.push({ + title: __("Access type"), + data: "access_type", + searchable: true, + orderable: true, + }) + } column_set.push({ title: __("Metric"), render: function (data, type, row, meta) { @@ -143,7 +164,7 @@ export default { }) } - if (report_type === "usage_data_provider") { + if (report_display === "usage_data_provider") { column_set.unshift({ title: __("Data provider"), data: "name", @@ -180,7 +201,7 @@ export default { }) }) } else { - if (report_type.includes("monthly")) { + if (report_display.includes("monthly")) { const years = Object.keys(time_period_columns) years.forEach(year => { @@ -218,7 +239,7 @@ export default { }) }) } - if (report_type === "yearly") { + if (report_display === "yearly") { const years = time_period_columns years.forEach(year => { @@ -239,32 +260,74 @@ export default { }) }) } - if (report_type === "metric_type") { + if (report_display === "metric_type") { const metric_types = query.metric_types - metric_types.forEach(metric => { + const access_types = query.access_types + // Add yop if it is required + if (this.checkReportColumns(report_type, "YOP")) { column_set.push({ - title: __(metric), - render: function (data, type, row, meta) { - const filterByMetric = - row.erm_usage_muses.filter( - item => item.metric_type === metric - ) - const period_total = filterByMetric.reduce( - (acc, item) => { - return acc + item.usage_count - }, - 0 - ) - return period_total - }, + title: __("YOP"), + data: "yop", searchable: true, orderable: true, }) + } + metric_types.forEach(metric => { + if (access_types && access_types.length > 0) { + access_types.forEach(access => { + column_set.push({ + title: __(access), + render: function (data, type, row, meta) { + const filterByType = + row.erm_usage_muses.filter( + item => + item.access_type === access + ) + const filterByMetric = + filterByType.filter( + item => + item.metric_type === metric + ) + const period_total = + filterByMetric.reduce( + (acc, item) => { + return ( + acc + item.usage_count + ) + }, + 0 + ) + return period_total + }, + searchable: false, + orderable: false, + }) + }) + } else { + column_set.push({ + title: __(metric), + render: function (data, type, row, meta) { + const filterByMetric = + row.erm_usage_muses.filter( + item => item.metric_type === metric + ) + const period_total = filterByMetric.reduce( + (acc, item) => { + return acc + item.usage_count + }, + 0 + ) + return period_total + }, + searchable: false, + orderable: false, + }) + } }) } } // Add totals column if required - if (report_type === "monthly_with_totals") { + if (report_display === "monthly_with_totals") { column_set.push({ title: __("Period total"), data: "usage_total", @@ -281,6 +344,7 @@ export default { const queryObject = {} const { metric_types, + access_types, usage_data_providers, keywords, report_type, @@ -321,6 +385,10 @@ export default { if (metric_types) { queryObject[`erm_usage_muses.metric_type`] = metric_types } + // Add any metric types query + if (access_types) { + queryObject[`erm_usage_muses.access_type`] = access_types + } // Add any data provider query if (usage_data_providers) { queryObject[`erm_usage_muses.usage_data_provider_id`] = @@ -350,14 +418,16 @@ export default { return url } }, - mergeTitleDataIntoOneLine(numberOfMetricTypes) { + mergeTitleDataIntoOneLine(numberOfMetricTypes, numberOfAccessTypes) { let dt = this.$refs.table.useTableObject() dt.on("draw", () => { const rows = dt.rows().nodes().to$() - + const numberOfRows = numberOfAccessTypes + ? numberOfMetricTypes * numberOfAccessTypes + : numberOfMetricTypes const data_rows = [] - for (let i = 0; i < rows.length; i = i + numberOfMetricTypes) { - data_rows.push([rows.slice(i, i + numberOfMetricTypes)]) + for (let i = 0; i < rows.length; i = i + numberOfRows) { + data_rows.push([rows.slice(i, i + numberOfRows)]) } data_rows @@ -366,7 +436,7 @@ export default { Array.from(titleRows).forEach((row, i) => { const cells = row.cells if (i === 0) { - cells[0].rowSpan = numberOfMetricTypes + cells[0].rowSpan = numberOfRows cells[0].style.textAlign = "center" cells[0].style.verticalAlign = "middle" cells[0].style.borderRight = "1px solid #BCBCBC" @@ -378,15 +448,50 @@ export default { }) this.$refs.table_div.classList.remove("hide-table") }, + createMetricReportTableHeader(metric_types, access_types) { + const table = this.$refs.table.$el.getElementsByTagName("table")[0] + const numberOfColumns = table.rows[0].cells.length + const dataColumns = metric_types.length * access_types + const numberOfNonStatisticColumns = numberOfColumns - dataColumns + const numberOfCellsToCreate = + numberOfNonStatisticColumns + metric_types.length + + const row = table.insertRow(0) + const cellsToInsert = Array.from("1".repeat(numberOfCellsToCreate)) + const cells = cellsToInsert.map(item => { + const cell = document.createElement("th") + row.appendChild(cell) + return cell + }) + + const metricTypeColumns = cells.splice(numberOfNonStatisticColumns) + metric_types.forEach((metric, i) => { + const cell = metricTypeColumns[i] + cell.colSpan = access_types + cell.innerHTML = metric + }) + this.$refs.table_div.classList.remove("hide-table") + }, }, watch: { table() { - if (this.report_type !== "metric_type") { - this.mergeTitleDataIntoOneLine( - this.params.queryObject.metric_types.length - ) + const number_of_access_types = this.params.queryObject.access_types + ? this.params.queryObject.access_types.length + : 0 + if (this.report_type === "metric_type") { + if (number_of_access_types) { + this.createMetricReportTableHeader( + this.params.queryObject.metric_types, + number_of_access_types + ) + } else { + this.$refs.table_div.classList.remove("hide-table") + } } else { - this.$refs.table_div.classList.remove("hide-table") + this.mergeTitleDataIntoOneLine( + this.params.queryObject.metric_types.length, + number_of_access_types + ) } }, }, diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/usage-reports.js b/koha-tmpl/intranet-tmpl/prog/js/vue/stores/usage-reports.js index d0fde5a64b..96df00f749 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/usage-reports.js +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/stores/usage-reports.js @@ -1,6 +1,6 @@ import { defineStore } from "pinia"; -export const useReportsStore = defineStore('reports', { +export const useReportsStore = defineStore("reports", { state: () => ({ months_data: [ { short: "Jan", description: "January", value: 1, active: true }, @@ -22,7 +22,7 @@ export const useReportsStore = defineStore('reports', { id: 1, name: "Provider name", active: true, - used_by: ["title", "item", "database", 'platform'], + used_by: ["title", "item", "database", "platform"], column: { title: __("Data provider"), data: "provider_name", @@ -115,13 +115,24 @@ export const useReportsStore = defineStore('reports', { }, }, }, + report_type_map: { + TR_B1: ["YOP", "ISBN"], + TR_B2: ["YOP", "ISBN"], + TR_B3: ["YOP", "Access_Type", "ISBN"], + TR_J3: ["Access_Type"], + TR_J4: ["YOP"], + }, }), actions: { getMonthsData() { - return this.months_data + return this.months_data; }, getColumnOptions() { - return this.title_property_column_options - } - } -}) \ No newline at end of file + return this.title_property_column_options; + }, + checkReportColumns(report_type, column) { + if (!this.report_type_map.hasOwnProperty(report_type)) return false; + return this.report_type_map[report_type].includes(column); + }, + }, +});