[Rt-commit] rt branch 5.0/dynamic-reports created. rt-5.0.4-7-g7f875ff419
BPS Git Server
git at git.bestpractical.com
Fri May 12 20:30:22 UTC 2023
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".
The branch, 5.0/dynamic-reports has been created
at 7f875ff41967e72b1579fc76bd1ebd4560003cfd (commit)
- Log -----------------------------------------------------------------
commit 7f875ff41967e72b1579fc76bd1ebd4560003cfd
Author: Ruslan Zakirov <ruslan.zakirov at gmail.com>
Date: Fri May 12 22:43:47 2023 +0300
Add RT::Interface::Web::ReportsRegistry package
Allows plugin authors to register reports that can be added to
the Reports menu in the UI.
Fixes: I#256668
diff --git a/.gitignore b/.gitignore
index 5ad579ba53..c26b4cc109 100644
--- a/.gitignore
+++ b/.gitignore
@@ -61,6 +61,7 @@
/config.pld
/nytprof.out*
/.prove
+/.vscode
*~
*.swp
*.swo
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 444eb1c24e..0e474cd0d3 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -79,6 +79,7 @@ use Plack::Util;
use HTTP::Status qw();
use Regexp::Common;
use RT::Shortener;
+use RT::Interface::Web::ReportsRegistry;
our @SHORTENER_SEARCH_FIELDS
= qw/Class ObjectType BaseQuery Query Format RowsPerPage Order OrderBy ExtraQueryParams ResultPage/;
@@ -5028,39 +5029,13 @@ sub UpdateDashboard {
=head2 ListOfReports
-Returns the list of reports registered with RT.
+Returns the list of reports registered with RT. Alias for
+L<RT::Interface::Web::ReportsRegistry|Reports>.
=cut
sub ListOfReports {
-
- # TODO: Make this a dynamic list generated by loading files in the Reports
- # directory
-
- my $list_of_reports = [
- {
- id => 'resolvedbyowner',
- title => 'Resolved by owner', # loc
- path => '/Reports/ResolvedByOwner.html',
- },
- {
- id => 'resolvedindaterange',
- title => 'Resolved in date range', # loc
- path => '/Reports/ResolvedByDates.html',
- },
- {
- id => 'createdindaterange',
- title => 'Created in a date range', # loc
- path => '/Reports/CreatedByDates.html',
- },
- {
- id => 'user_time',
- title => 'User time worked',
- path => '/Reports/TimeWorkedReport.html',
- },
- ];
-
- return $list_of_reports;
+ return RT::Interface::Web::ReportsRegistry->Reports();
}
=head2 ProcessCustomDateRanges ARGSRef => ARGSREF, UserPreference => 0|1
diff --git a/lib/RT/Interface/Web/ReportsRegistry.pm b/lib/RT/Interface/Web/ReportsRegistry.pm
new file mode 100644
index 0000000000..b5c1b0a510
--- /dev/null
+++ b/lib/RT/Interface/Web/ReportsRegistry.pm
@@ -0,0 +1,82 @@
+package RT::Interface::Web::ReportsRegistry;
+
+use strict;
+use warnings;
+
+our $registry = {
+ resolvedbyowner => {
+ id => 'resolvedbyowner',
+ title => 'Resolved by owner', # loc
+ path => '/Reports/ResolvedByOwner.html',
+ },
+ resolvedindaterange => {
+ id => 'resolvedindaterange',
+ title => 'Resolved in date range', # loc
+ path => '/Reports/ResolvedByDates.html',
+ },
+ createdindaterange => {
+ id => 'createdindaterange',
+ title => 'Created in a date range', # loc
+ path => '/Reports/CreatedByDates.html',
+ },
+ user_time => {
+ id => 'user_time',
+ title => 'User time worked',
+ path => '/Reports/TimeWorkedReport.html',
+ },
+};
+
+=head2 Reports
+
+Returns a list (array ref) of all registered reports. Reports are sorted by title.
+Every element is a hash ref with the following keys:
+
+=over 4
+
+=item id - unique string identifier
+
+=item title - human-readable title
+
+=item path - path to the report relative to the root
+
+=back
+
+=cut
+
+sub Reports {
+ my @res = sort { lc($a->{title}) cmp lc($b->{title}) } values %$registry;
+ return \@res;
+}
+
+=head2 Register
+
+Registers a report that can be added to the Reports menu.
+
+ use RT::Interface::Web::ReportsRegistry;
+ RT::Interface::Web::ReportsRegistry->Register(
+ id => 'my_super_report',
+ title => 'Super report',
+ path => 'MySuperReport.html',
+ );
+
+All reports are expected to be in the /Reports/ directory.
+
+B<Note> that using existing id will overwrite the record in the registry.
+
+=cut
+
+sub Register {
+ my $self = shift;
+ my %args = (
+ id => undef,
+ title => undef,
+ path => undef,
+ @_
+ );
+
+ $registry->{id} = {
+ id => $args{id},
+ title => $args{title},
+ path => '/Reports/'. $args{path},
+ };
+}
-----------------------------------------------------------------------
hooks/post-receive
--
rt
More information about the rt-commit
mailing list