[Rt-commit] rt branch, 5.0/dashboards-to-report-menu-2, created. rt-5.0.0alpha1-221-g64fdc7c748

Jim Brandt jbrandt at bestpractical.com
Wed May 6 09:29:37 EDT 2020


The branch, 5.0/dashboards-to-report-menu-2 has been created
        at  64fdc7c748858d1b885b58ae09fb9566a9a3ef28 (commit)

- Log -----------------------------------------------------------------
commit 82136e8b8f86cbef91ca8df88b7bdb7260c2e5ba
Author: michel <michel at bestpractical.com>
Date:   Wed Apr 15 15:16:57 2020 +0200

    Moved initial dashboards to the Reports menu.

diff --git a/lib/RT/Interface/Web/MenuBuilder.pm b/lib/RT/Interface/Web/MenuBuilder.pm
index 613f4b903a..22bc442027 100644
--- a/lib/RT/Interface/Web/MenuBuilder.pm
+++ b/lib/RT/Interface/Web/MenuBuilder.pm
@@ -95,58 +95,6 @@ sub BuildMainNav {
     $home->child( create_ticket => title => loc("Create Ticket"),
                   path => "/Ticket/Create.html" );
 
-    unless ($HTML::Mason::Commands::session{'dashboards_in_menu'}) {
-        my $dashboards_in_menu = $current_user->UserObj->Preferences(
-            'DashboardsInMenu',
-            {},
-        );
-
-        unless ($dashboards_in_menu->{dashboards}) {
-            my ($default_dashboards) =
-                RT::System->new( $current_user )
-                    ->Attributes
-                    ->Named('DashboardsInMenu');
-            if ($default_dashboards) {
-                $dashboards_in_menu = $default_dashboards->Content;
-            }
-        }
-
-        $HTML::Mason::Commands::session{'dashboards_in_menu'} = $dashboards_in_menu->{dashboards} || [];
-    }
-
-    my @dashboards;
-    for my $id ( @{$HTML::Mason::Commands::session{'dashboards_in_menu'}} ) {
-        my $dash = RT::Dashboard->new( $current_user );
-        my ( $status, $msg ) = $dash->LoadById($id);
-        if ( $status ) {
-            push @dashboards, $dash;
-        } else {
-            $RT::Logger->debug( "Failed to load dashboard $id: $msg, removing from menu" );
-            $home->RemoveDashboardMenuItem(
-                DashboardId => $id,
-                CurrentUser => $HTML::Mason::Commands::session{CurrentUser}->UserObj,
-            );
-            @{ $HTML::Mason::Commands::session{'dashboards_in_menu'} } =
-              grep { $_ != $id } @{ $HTML::Mason::Commands::session{'dashboards_in_menu'} };
-        }
-    }
-
-    my $dashes = $top->child('home');
-    if (@dashboards) {
-        for my $dash (@dashboards) {
-            $home->child( 'dashboard-' . $dash->id,
-                title => $dash->Name,
-                path  => '/Dashboards/' . $dash->id . '/' . $dash->Name
-            );
-        }
-    }
-    $dashes->child( edit => title => loc('Update This Menu'), path => 'Prefs/DashboardsInMenu.html' );
-    $dashes->child( more => title => loc('All Dashboards'),   path => 'Dashboards/index.html' );
-    my $dashboard = RT::Dashboard->new( $current_user );
-    if ( $dashboard->CurrentUserCanCreateAny ) {
-        $dashes->child('dashboard_create' => title => loc('New Dashboard'), path => "/Dashboards/Modify.html?Create=1" );
-    }
-
     my $search = $top->child( search => title => loc('Search'), path => '/Search/Simple.html' );
 
     my $tickets = $search->child( tickets => title => loc('Tickets'), path => '/Search/Build.html' );
@@ -195,6 +143,52 @@ sub BuildMainNav {
         description => loc('Reports summarizing ticket resolution and status'),
         path        => loc('/Reports'),
     );
+
+    unless ($HTML::Mason::Commands::session{'dashboards_in_menu'}) {
+        my $dashboards_in_menu = $current_user->UserObj->Preferences(
+            'DashboardsInMenu',
+            {},
+        );
+
+        unless ($dashboards_in_menu->{dashboards}) {
+            my ($default_dashboards) =
+                RT::System->new( $current_user )
+                    ->Attributes
+                    ->Named('DashboardsInMenu');
+            if ($default_dashboards) {
+                $dashboards_in_menu = $default_dashboards->Content;
+            }
+        }
+
+        $HTML::Mason::Commands::session{'dashboards_in_menu'} = $dashboards_in_menu->{dashboards} || [];
+    }
+
+    my @dashboards;
+    for my $id ( @{$HTML::Mason::Commands::session{'dashboards_in_menu'}} ) {
+        my $dash = RT::Dashboard->new( $current_user );
+        my ( $status, $msg ) = $dash->LoadById($id);
+        if ( $status ) {
+            push @dashboards, $dash;
+        } else {
+            $RT::Logger->debug( "Failed to load dashboard $id: $msg, removing from menu" );
+            $home->RemoveDashboardMenuItem(
+                DashboardId => $id,
+                CurrentUser => $HTML::Mason::Commands::session{CurrentUser}->UserObj,
+            );
+            @{ $HTML::Mason::Commands::session{'dashboards_in_menu'} } =
+              grep { $_ != $id } @{ $HTML::Mason::Commands::session{'dashboards_in_menu'} };
+        }
+    }
+
+    if (@dashboards) {
+        for my $dash (@dashboards) {
+            $reports->child( 'dashboard-' . $dash->id,
+                title => $dash->Name,
+                path  => '/Dashboards/' . $dash->id . '/' . $dash->Name
+            );
+        }
+    }
+
     $reports->child( resolvedbyowner =>
         title       => loc('Resolved by owner'),
         path        => '/Reports/ResolvedByOwner.html',
@@ -211,6 +205,14 @@ sub BuildMainNav {
         description => loc('Examine tickets created in a queue between two dates'),
     );
 
+    $reports->child( edit => title => loc('Update This Menu'), path => '/Prefs/DashboardsInMenu.html' );
+    $reports->child( more => title => loc('All Dashboards'),   path => '/Dashboards/index.html' );
+    my $dashboard = RT::Dashboard->new( $current_user );
+    if ( $dashboard->CurrentUserCanCreateAny ) {
+        $reports->child('dashboard_create' => title => loc('New Dashboard'), path => "/Dashboards/Modify.html?Create=1" );
+    }
+
+
     if ($current_user->HasRight( Right => 'ShowArticlesMenu', Object => RT->System )) {
         my $articles = $top->child( articles => title => loc('Articles'), path => "/Articles/index.html");
         $articles->child( articles => title => loc('Overview'), path => "/Articles/index.html" );

commit 16957ce4c8be4371fdb4008156a21d7fd9935836
Author: michel <michel at bestpractical.com>
Date:   Thu Apr 16 13:21:19 2020 +0200

    Get the list of reports in the Reports menu from attribute
    
    The initial list is created from initialdata, in the ReportsInMenu attribute.
    It can be modified in the Pref-ReportsInMenu user preference,
    similar to dashboards.

diff --git a/etc/initialdata b/etc/initialdata
index 74951a5b85..630dd216b0 100644
--- a/etc/initialdata
+++ b/etc/initialdata
@@ -923,6 +923,27 @@ Hour:         { $SubscriptionObj->SubValue('Hour') }
               ],
         },
     },
+# initial reports
+    { Name => 'ReportsInMenu',
+      Description => 'Content of the Reports menu', #loc
+      Content     => [
+          {
+              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',
+          },
+      ],
+    },
 );
 
 @Classes = (
diff --git a/lib/RT/Interface/Web/MenuBuilder.pm b/lib/RT/Interface/Web/MenuBuilder.pm
index 22bc442027..0b77f49f38 100644
--- a/lib/RT/Interface/Web/MenuBuilder.pm
+++ b/lib/RT/Interface/Web/MenuBuilder.pm
@@ -189,21 +189,37 @@ sub BuildMainNav {
         }
     }
 
-    $reports->child( resolvedbyowner =>
-        title       => loc('Resolved by owner'),
-        path        => '/Reports/ResolvedByOwner.html',
-        description => loc('Examine tickets resolved in a queue, grouped by owner'),
-    );
-    $reports->child( resolvedindaterange =>
-        title       => loc('Resolved in date range'),
-        path        => '/Reports/ResolvedByDates.html',
-        description => loc('Examine tickets resolved in a queue between two dates'),
-    );
-    $reports->child( createdindaterange =>
-        title       => loc('Created in a date range'),
-        path        => '/Reports/CreatedByDates.html',
-        description => loc('Examine tickets created in a queue between two dates'),
-    );
+    # Get the list of reports in the Reports menu
+    unless (   $HTML::Mason::Commands::session{'reports_in_menu'}
+            && ref( $HTML::Mason::Commands::session{'reports_in_menu'}) eq 'ARRAY'
+            && @{$HTML::Mason::Commands::session{'reports_in_menu'}}
+           ) {
+        my $reports_in_menu = $current_user->UserObj->Preferences(
+            'ReportsInMenu',
+            {},
+        );
+        unless ( $reports_in_menu && ref $reports_in_menu eq 'ARRAY' ) {
+            my ($default_reports) =
+                RT::System->new( RT->SystemUser )
+                    ->Attributes
+                    ->Named('ReportsInMenu');
+            if ($default_reports) {
+                $reports_in_menu = $default_reports->Content;
+            }
+            else {
+                $reports_in_menu = [];
+            }
+        }
+
+        $HTML::Mason::Commands::session{'reports_in_menu'} = $reports_in_menu || [];
+    }
+
+    for my $report ( @{$HTML::Mason::Commands::session{'reports_in_menu'}} ) {
+        $reports->child(  $report->{id} =>
+            title       => $report->{title},
+            path        => $report->{path},
+        );
+    }
 
     $reports->child( edit => title => loc('Update This Menu'), path => '/Prefs/DashboardsInMenu.html' );
     $reports->child( more => title => loc('All Dashboards'),   path => '/Dashboards/index.html' );

commit 64138321a38fa36a36e6c4137c0c5fd88316a009
Author: michel <michel at bestpractical.com>
Date:   Tue Apr 28 18:08:44 2020 +0200

    Add upgrade step: create the ReportsInMenu attribute if needed.

diff --git a/etc/upgrade/4.5.5/content b/etc/upgrade/4.5.5/content
new file mode 100644
index 0000000000..518adad8ef
--- /dev/null
+++ b/etc/upgrade/4.5.5/content
@@ -0,0 +1,38 @@
+use strict;
+use warnings;
+
+our @Initial = (
+    # add default reports
+    sub {
+        my $reports_in_menu = 'ReportsInMenu';
+        my $attr = RT::Attribute->new( RT->SystemUser );
+        my( $ok, $msg) = $attr->LoadByNameAndObject( Object => RT->System, Name => $reports_in_menu );
+        # add attribute only if it does not already exist
+        if ( !$ok ) {
+            RT->Logger->debug( "Adding default reports in menu" );
+            my $content = [
+                {
+                    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',
+                },
+            ];
+
+            RT->System->AddAttribute(
+                        Name => $reports_in_menu,
+                        Description => 'Content of the Reports menu',
+                        Content => $content,
+            );
+        }
+    }
+);

commit f046ab5d512eafcc8a2b49c3a9b985f7a725719e
Author: michel <michel at bestpractical.com>
Date:   Fri May 1 17:01:02 2020 +0200

    Fix tests to reflect changes in dashboard menu ids.

diff --git a/t/web/dashboards-basics.t b/t/web/dashboards-basics.t
index 567eb0635b..3367ba6935 100644
--- a/t/web/dashboards-basics.t
+++ b/t/web/dashboards-basics.t
@@ -66,7 +66,7 @@ $m->content_contains("Create");
 
 $m->get_ok($url."Dashboards/index.html");
 $m->content_contains("New", "'New' link because we now have ModifyOwnDashboard");
-$m->follow_link_ok({ id => 'home-dashboard_create'});
+$m->follow_link_ok({ id => 'reports-dashboard_create'});
 $m->form_name('ModifyDashboard');
 $m->field("Name" => 'different dashboard');
 $m->content_lacks('Delete', "Delete button hidden because we are creating");
diff --git a/t/web/dashboards-groups.t b/t/web/dashboards-groups.t
index 9f1c37debe..443ff06f23 100644
--- a/t/web/dashboards-groups.t
+++ b/t/web/dashboards-groups.t
@@ -54,14 +54,14 @@ ok($inner_group->HasMemberRecursively($user_obj->PrincipalId), "inner has user r
 ok $m->login(customer => 'customer'), "logged in";
 
 
-$m->follow_link_ok({ id => 'home-dashboard_create'});
+$m->follow_link_ok({ id => 'reports-dashboard_create'});
 $m->form_name('ModifyDashboard');
 is_deeply([$m->current_form->find_input('Privacy')->possible_values], ["RT::User-" . $user_obj->Id], "the only selectable privacy is user");
 $m->content_lacks('Delete', "Delete button hidden because we are creating");
 
 $user_obj->PrincipalObj->GrantRight(Right => 'CreateGroupDashboard', Object => $inner_group);
 
-$m->follow_link_ok({ id => 'home-dashboard_create'});
+$m->follow_link_ok({ id => 'reports-dashboard_create'});
 $m->form_name('ModifyDashboard');
 is_deeply([$m->current_form->find_input('Privacy')->possible_values], ["RT::User-" . $user_obj->Id, "RT::Group-" . $inner_group->Id], "the only selectable privacies are user and inner group (not outer group)");
 $m->field("Name" => 'broken dashboard');
@@ -74,7 +74,7 @@ $user_obj->PrincipalObj->GrantRight(
     Right  => 'SeeGroupDashboard',
     Object => $inner_group,
 );
-$m->follow_link_ok({ id => 'home-dashboard_create'});
+$m->follow_link_ok({ id => 'reports-dashboard_create'});
 $m->form_name('ModifyDashboard');
 $m->field("Name" => 'inner dashboard');
 $m->field("Privacy" => "RT::Group-" . $inner_group->Id);
diff --git a/t/web/dashboards-permissions.t b/t/web/dashboards-permissions.t
index 433fdd3731..a22c043d7f 100644
--- a/t/web/dashboards-permissions.t
+++ b/t/web/dashboards-permissions.t
@@ -28,7 +28,7 @@ $user_obj->PrincipalObj->GrantRight(Right => $_, Object => $RT::System)
 ok $m->login(customer => 'customer'), "logged in";
 
 
-$m->follow_link_ok( {id => 'home-dashboard_create'});
+$m->follow_link_ok( {id => 'reports-dashboard_create'});
 $m->form_name('ModifyDashboard');
 is_deeply([$m->current_form->find_input('Privacy')->possible_values], ["RT::User-" . $user_obj->Id], "the only selectable privacy is user");
 $m->content_lacks('Delete', "Delete button hidden because we are creating");
diff --git a/t/web/dashboards-subscription.t b/t/web/dashboards-subscription.t
index 8a3473e919..1e493332cb 100644
--- a/t/web/dashboards-subscription.t
+++ b/t/web/dashboards-subscription.t
@@ -25,7 +25,7 @@ ok $m->login(customer => 'customer'), "logged in";
 $m->get_ok($url."Dashboards/Modify.html?Create=1");
 
 # Create Dashboard
-$m->follow_link_ok({ id => 'home-dashboard_create' });
+$m->follow_link_ok({ id => 'reports-dashboard_create' });
 $m->form_name('ModifyDashboard');
 $m->field("Name" => 'test dashboard');
 $m->click_button(value => 'Create');

commit decfb5af82afbf2b15b42e08b7fcf23a6518a8cf
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Fri May 1 16:48:44 2020 -0400

    Update report menu description

diff --git a/lib/RT/Interface/Web/MenuBuilder.pm b/lib/RT/Interface/Web/MenuBuilder.pm
index 0b77f49f38..a758739674 100644
--- a/lib/RT/Interface/Web/MenuBuilder.pm
+++ b/lib/RT/Interface/Web/MenuBuilder.pm
@@ -140,7 +140,7 @@ sub BuildMainNav {
 
     my $reports = $top->child( reports =>
         title       => loc('Reports'),
-        description => loc('Reports summarizing ticket resolution and status'),
+        description => loc('Reports and Dashboards'),
         path        => loc('/Reports'),
     );
 
diff --git a/share/html/Reports/index.html b/share/html/Reports/index.html
index 2b4cbedcf2..1012ea75ef 100644
--- a/share/html/Reports/index.html
+++ b/share/html/Reports/index.html
@@ -45,6 +45,6 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-<& /Elements/Header, Title => loc('Reports') &>
+<& /Elements/Header, Title => loc('Reports and Dashboards') &>
 <& /Elements/Tabs &>
 <& /Elements/ListMenu, menu => Menu()->child('reports') &>

commit 90be973ada5b51658f437fab99d8895674d0d6da
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Mon May 4 16:15:44 2020 -0400

    Add and remove reports from the Reports menu
    
    Add report processing to the "Update This Menu" functionality
    for the Reports (formerly Home/Dashboards) menu.

diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 987b4c890b..8bef4fd086 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -4742,6 +4742,38 @@ sub UpdateDashboard {
     }
 }
 
+=head2 ListOfReports
+
+Returns the list of reports registered with RT.
+
+=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',
+        },
+    ];
+
+    return $list_of_reports;
+}
+
 package RT::Interface::Web;
 RT::Base->_ImportOverlays();
 
diff --git a/share/html/Prefs/DashboardsInMenu.html b/share/html/Prefs/DashboardsInMenu.html
index db456df2b9..05965e1bbf 100644
--- a/share/html/Prefs/DashboardsInMenu.html
+++ b/share/html/Prefs/DashboardsInMenu.html
@@ -50,36 +50,58 @@
 &>
 <& /Elements/ListActions, actions => \@results &>
 
-<br />
-
-% for my $pane ( @panes ) {
 <&|/Widgets/TitleBox,
     title => loc('Dashboards in menu'),
     bodyclass => ""
 &>
-<& /Widgets/SelectionBox:show, self => $pane &>
+<& /Widgets/SelectionBox:show, self => $dashboard_pane &>
 </&>
-% }
 
 <&|/Widgets/TitleBox, title => loc("Reset dashboards in menu") &>
-<form method="post" action="DashboardsInMenu.html">
-<input type="hidden" name="Reset" value="1" />
-<input type="submit" class="button form-control btn btn-primary"" value="<% loc('Reset to default') %>">
-</form>
+<div class="form-row mt-3 mb-1 ml-3">
+  <form method="post" action="DashboardsInMenu.html">
+    <input type="submit" name="ResetDashboards" class="button form-control btn btn-primary" value="<% loc('Reset dashboards to default') %>">
+  </form>
+</div>
 </&>
 
+<&|/Widgets/TitleBox,
+    title => loc('Reports in menu'),
+    bodyclass => ""
+&>
+<& /Widgets/SelectionBox:show, self => $report_pane &>
+</&>
+
+<&|/Widgets/TitleBox, title => loc("Reset reports in menu") &>
+<div class="form-row mt-3 mb-1 ml-3">
+  <form method="post" action="DashboardsInMenu.html">
+    <input type="submit" name="ResetReports" class="button form-control btn btn-primary" value="<% loc('Reset reports to default') %>">
+  </form>
+</div>
+</&>
 
 <%INIT>
 my @results;
-my $title = loc("Customize").' '.loc("dashboards in menu");
+my $title = loc("Customize").' '.loc("reports menu");
 my $user = $session{'CurrentUser'}->UserObj;
 
-if ($ARGS{Reset}) {
+if ( $ARGS{ResetDashboards} ) {
+    # Empty DashboardsInMenu pref means to use system default.
     my ($ok, $msg) = $user->SetPreferences('DashboardsInMenu', {});
     push @results, $ok ? loc('Preferences saved.') : $msg;
     delete $session{'dashboards_in_menu'};
 }
 
+if ( $ARGS{ResetReports} ) {
+    if ( $user->Preferences('ReportsInMenu') ) {
+        # Empty ReportsInMenu pref means empty, not to use default,
+        # thus we need to delete preference instead.
+        my ( $ok, $msg ) = $user->DeletePreferences('ReportsInMenu');
+        push @results, $ok ? loc('Preferences saved.') : $msg;
+        delete $session{'reports_in_menu'};
+    }
+}
+
 my ($default_dashboards) =
 RT::System->new($session{'CurrentUser'})->Attributes->Named('DashboardsInMenu');
 
@@ -91,7 +113,7 @@ my $current_dashboards = $dashboard_pref->{dashboards} || [];
 
 my @dashboards = map { [$_->id, $_->Name] } $m->comp("/Dashboards/Elements/ListOfDashboards", IncludeSuperuserGroups => 0 );
 
-my @panes = $m->comp(
+my ($dashboard_pane) = $m->comp(
     '/Admin/Elements/ConfigureDashboardsInMenu',
     Action => 'DashboardsInMenu.html',
     panes => ['dashboards_in_menu'],
@@ -106,8 +128,37 @@ my @panes = $m->comp(
     }
 );
 
-$m->comp( '/Widgets/SelectionBox:process', %ARGS, self => $_ )
-    for @panes;
+my ( @reports, %reports );
+for my $report ( @{ ListOfReports() } ) {
+    push @reports, [ $report->{id}, $report->{title} ];
+    $reports{ $report->{id} } = $report;
+}
+
+my ($default_reports) = RT::System->new( $session{'CurrentUser'} )->Attributes->Named('ReportsInMenu');
+my $report_pref
+    = $session{CurrentUser}->UserObj->Preferences( 'ReportsInMenu', $default_reports ? $default_reports->Content : () );
+my $current_reports = [ map { $_->{id} } @{ $report_pref || [] } ];
+
+my ($report_pane) = $m->comp(
+    '/Admin/Elements/ConfigureDashboardsInMenu',
+    Action           => 'DashboardsInMenu.html',
+    panes            => ['reports_in_menu'],
+    items            => \@reports,
+    current_portlets => $current_reports,
+    OnSave           => sub {
+        my ($conf) = @_;
+        my $user_reports = [];
+        foreach my $id ( @{ $conf->{dashboards} } ) {
+            push @$user_reports, $reports{$id} if $reports{$id};
+        }
+        my ( $ok, $msg ) = $user->SetPreferences( 'ReportsInMenu', $user_reports );
+        push @results, $msg unless $ok;
+
+        delete $session{'reports_in_menu'};
+    }
+);
+
+$m->comp( '/Widgets/SelectionBox:process', %ARGS, self => $_ ) for ( $dashboard_pane, $report_pane );
 
 </%INIT>
 

commit e71fb69297decee252642ddcb7b383f0481b7733
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Mon May 4 17:08:19 2020 -0400

    Add reports to global reports menu editor

diff --git a/share/html/Admin/Global/DashboardsInMenu.html b/share/html/Admin/Global/DashboardsInMenu.html
index 21b12077ac..c211f0201a 100644
--- a/share/html/Admin/Global/DashboardsInMenu.html
+++ b/share/html/Admin/Global/DashboardsInMenu.html
@@ -45,16 +45,15 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-<& /Admin/Elements/Header, Title => loc("Dashboards in menu") &>
+<& /Admin/Elements/Header, Title => loc("Reports menu") &>
 <& /Elements/Tabs &>
 
 <& /Elements/ListActions, actions => \@actions &>
-<br />
-% for my $pane (@panes) {
 <&|/Widgets/TitleBox, title => loc('Dashboards in menu'), bodyclass => "" &>
-<& /Widgets/SelectionBox:show, self => $pane &></&>
-<br />
-% }
+<& /Widgets/SelectionBox:show, self => $dashboard_pane &></&>
+
+<&|/Widgets/TitleBox, title => loc('Reports in menu'), bodyclass => "" &>
+<& /Widgets/SelectionBox:show, self => $report_pane &></&>
 <%init>
 my @actions;
 my $sys = RT::System->new( $session{'CurrentUser'} );
@@ -76,7 +75,7 @@ while ( my $dashboard = $dashboards->Next ) {
     push @dashboards, [$dashboard->id, $dashboard->Name];
 }
 
-my @panes = $m->comp(
+my ($dashboard_pane) = $m->comp(
     '/Admin/Elements/ConfigureDashboardsInMenu',
     Action => 'DashboardsInMenu.html',
     panes => ['dashboards_in_menu'],
@@ -105,8 +104,42 @@ my @panes = $m->comp(
     }
 );
 
-$m->comp( '/Widgets/SelectionBox:process', %ARGS, self => $_ )
-    for @panes;
+my ($reports_attr) = RT::System->new( RT->SystemUser )->Attributes->Named('ReportsInMenu');
+
+my ( @reports, %reports );
+for my $report ( @{ ListOfReports() } ) {
+    push @reports, [ $report->{id}, $report->{title} ];
+    $reports{ $report->{id} } = $report;
+}
+
+my ($report_pane) = $m->comp(
+    '/Admin/Elements/ConfigureDashboardsInMenu',
+    Action           => 'DashboardsInMenu.html',
+    panes            => ['reports_in_menu'],
+    ReadOnly         => !$has_right,
+    items            => \@reports,
+    current_portlets => [ map { $_->{id} } @{ $reports_attr->Content || [] } ],
+    OnSave           => sub {
+        my ($conf) = @_;
+        my ( $status, $msg );
+
+        if ( !$has_right ) {
+            push @actions, loc('Permission Denied');
+        }
+        else {
+            my $system_reports = [];
+            foreach my $id ( @{ $conf->{dashboards} } ) {
+                push @$system_reports, $reports{$id} if $reports{$id};
+            }
+
+            ( $status, $msg ) = $reports_attr->SetContent($system_reports);
+            push @actions, $msg unless $status;
+        }
+        push @actions, $status ? loc('Global reports in menu saved.') : $msg;
+    }
+);
+
+$m->comp( '/Widgets/SelectionBox:process', %ARGS, self => $_ ) for ( $dashboard_pane, $report_pane );
 
 
 </%init>

commit c86010d7af65f2ac24d7234a389641b7a7aee412
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Mon May 4 17:32:39 2020 -0400

    Add reports to user admin menu edit

diff --git a/share/html/Admin/Users/DashboardsInMenu.html b/share/html/Admin/Users/DashboardsInMenu.html
index 35efa9c9c9..92f9147863 100644
--- a/share/html/Admin/Users/DashboardsInMenu.html
+++ b/share/html/Admin/Users/DashboardsInMenu.html
@@ -50,33 +50,57 @@
 
 <& /Elements/ListActions, actions => \@actions &>
 
-<form method="post" action="DashboardsInMenu.html">
-<input type="hidden" name="id" value="<% $id %>" />
-<input type="hidden" name="Reset" value="1" />
-<div class="form-row">
-  <div class="col-12">
-    <input type="submit" class="form-control btn btn-primary button" value="<%loc('Reset to default')%>">
-  </div>
+<&|/Widgets/TitleBox,
+    title => loc('Dashboards in menu'),
+    bodyclass => ""
+&>
+<& /Widgets/SelectionBox:show, self => $dashboard_pane &>
+</&>
+
+<&|/Widgets/TitleBox, title => loc("Reset dashboards in menu") &>
+<div class="form-row mt-3 mb-1 ml-3">
+  <form method="post" action="DashboardsInMenu.html">
+    <input type="hidden" name="id" value="<% $id %>" />
+    <input type="submit" name="ResetDashboards" class="button form-control btn btn-primary" value="<% loc('Reset dashboards to default') %>">
+  </form>
 </div>
-</form>
+</&>
 
-<br />
+<&|/Widgets/TitleBox,
+    title => loc('Reports in menu'),
+    bodyclass => ""
+&>
+<& /Widgets/SelectionBox:show, self => $report_pane &>
+</&>
 
-% for my $pane (@panes) {
-<&|/Widgets/TitleBox, title => loc('Dashboards in menu'), bodyclass => "" &>
-<& /Widgets/SelectionBox:show, self => $pane &></&>
-<br />
-% }
+<&|/Widgets/TitleBox, title => loc("Reset reports in menu") &>
+<div class="form-row mt-3 mb-1 ml-3">
+  <form method="post" action="DashboardsInMenu.html">
+    <input type="hidden" name="id" value="<% $id %>" />
+    <input type="submit" name="ResetReports" class="button form-control btn btn-primary" value="<% loc('Reset reports to default') %>">
+  </form>
+</div>
+</&>
 
 <%init>
 my @actions;
 my $UserObj = RT::User->new($session{'CurrentUser'});
 $UserObj->Load($id) || Abort("Couldn't load user '" . ($id || '') . "'");
-my $title = loc("Dashboards in menu for the user [_1]", $UserObj->Name);
+my $title = loc("Reports menu for the user [_1]", $UserObj->Name);
 
-if ($ARGS{Reset}) {
-    my ($ok, $msg) = $UserObj->SetPreferences('DashboardsInMenu', {});
-    push @actions, $ok ? loc('Preferences saved for user [_1].', $UserObj->Name) : $msg;
+if ( $ARGS{ResetDashboards} ) {
+    # Empty DashboardsInMenu pref means to use system default.
+    my ( $ok, $msg ) = $UserObj->SetPreferences( 'DashboardsInMenu', {} );
+    push @actions, $ok ? loc( 'Preferences saved for user [_1].', $UserObj->Name ) : $msg;
+}
+
+if ( $ARGS{ResetReports} ) {
+    if ( $UserObj->Preferences('ReportsInMenu') ) {
+        # Empty ReportsInMenu pref means empty, not to use default,
+        # thus we need to delete preference instead.
+        my ( $ok, $msg ) = $UserObj->DeletePreferences('ReportsInMenu');
+        push @actions, $ok ? loc( 'Preferences saved for user [_1].', $UserObj->Name ) : $msg;
+    }
 }
 
 my ($default_dashboards) =
@@ -97,7 +121,7 @@ my $current_portlets =
   ? $current_pref->{dashboards}
   : [];
 
-my @panes = $m->comp(
+my ($dashboard_pane) = $m->comp(
     '/Admin/Elements/ConfigureDashboardsInMenu',
     Action           => "DashboardsInMenu.html?id=$id",
     panes            => ['dashboards_in_menu'],
@@ -112,9 +136,40 @@ my @panes = $m->comp(
     }
 );
 
+my ( @reports, %reports );
+for my $report ( @{ ListOfReports() } ) {
+    push @reports, [ $report->{id}, $report->{title} ];
+    $reports{ $report->{id} } = $report;
+}
+
+my ($default_reports) = RT::System->new( $session{'CurrentUser'} )->Attributes->Named('ReportsInMenu');
+my $report_pref = $UserObj->Preferences( 'ReportsInMenu', $default_reports ? $default_reports->Content : () );
+my $current_reports = [ map { $_->{id} } @{ $report_pref || [] } ];
+
+my ($report_pane) = $m->comp(
+    '/Admin/Elements/ConfigureDashboardsInMenu',
+    Action           => "DashboardsInMenu.html?id=$id",
+    panes            => ['reports_in_menu'],
+    items            => \@reports,
+    current_portlets => $current_reports,
+    OnSave           => sub {
+        my ($conf) = @_;
+        my $user_reports = [];
+        foreach my $id ( @{ $conf->{dashboards} } ) {
+            push @$user_reports, $reports{$id} if $reports{$id};
+        }
+
+        my ( $ok, $msg ) = $UserObj->SetPreferences( 'ReportsInMenu', $user_reports );
+        if ($ok) {
+            push @actions, loc('Preferences saved for dashboards in menu.');
+        }
+        else {
+            push @actions, $msg;
+        }
+    }
+);
 
-$m->comp( '/Widgets/SelectionBox:process', %ARGS, self => $_ )
-    for @panes;
+$m->comp( '/Widgets/SelectionBox:process', %ARGS, self => $_ ) for ( $dashboard_pane, $report_pane );
 
 </%init>
 <%ARGS>

commit 23247d40ce576779d807a644a4e78ddf21f0930d
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Mon May 4 17:15:07 2020 -0400

    Update label to reflect new Reports menu location

diff --git a/lib/RT/Interface/Web/MenuBuilder.pm b/lib/RT/Interface/Web/MenuBuilder.pm
index a758739674..e7afd9c2f8 100644
--- a/lib/RT/Interface/Web/MenuBuilder.pm
+++ b/lib/RT/Interface/Web/MenuBuilder.pm
@@ -299,7 +299,7 @@ sub BuildMainNav {
         $settings->child( search_options => title => loc('Search options'), path => '/Prefs/SearchOptions.html' );
         $settings->child( myrt           => title => loc('RT at a glance'), path => '/Prefs/MyRT.html' );
         $settings->child( dashboards_in_menu =>
-            title => loc('Dashboards in menu'),
+            title => loc('Modify Reports menu'),
             path  => '/Prefs/DashboardsInMenu.html',
         );
         $settings->child( queue_list    => title => loc('Queue list'),   path => '/Prefs/QueueList.html' );
@@ -1147,7 +1147,7 @@ sub _BuildAdminMenu {
         path        => '/Admin/Global/MyRT.html',
     );
     $admin_global->child( 'dashboards-in-menu' =>
-        title       => loc('Dashboards in menu'),
+        title       => loc('Modify Reports menu'),
         description => loc('Customize dashboards in menu'),
         path        => '/Admin/Global/DashboardsInMenu.html',
     );
@@ -1270,7 +1270,7 @@ sub _BuildAdminMenu {
                 $page->child( history     => title => loc('History'),        path => "/Admin/Users/History.html?id=" . $id );
                 $page->child( 'my-rt'     => title => loc('RT at a glance'), path => "/Admin/Users/MyRT.html?id=" . $id );
                 $page->child( 'dashboards-in-menu' =>
-                    title => loc('Dashboards in menu'),
+                    title => loc('Modify Reports menu'),
                     path  => '/Admin/Users/DashboardsInMenu.html?id=' . $id,
                 );
                 if ( RT->Config->Get('Crypt')->{'Enable'} ) {

commit 918394273d1ae9f6cb78e650a64b953e54b3ab1f
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed May 6 04:56:56 2020 +0800

    Update dashboard pref tests as we updated reset input name

diff --git a/t/web/dashboards-in-menu.t b/t/web/dashboards-in-menu.t
index 3915bb2367..ea7d3b1dba 100644
--- a/t/web/dashboards-in-menu.t
+++ b/t/web/dashboards-in-menu.t
@@ -84,7 +84,7 @@ $m->click_button(name => 'Delete');
 
 diag "Reset dashboard menu";
 $m->get_ok( $baseurl."/Prefs/DashboardsInMenu.html");
-$m->form_with_fields('Reset');
+$m->form_with_fields('ResetDashboards');
 $m->click;
 $m->content_contains( 'Preferences saved', 'prefs saved' );
 ok( $m->find_link( text => 'system foo' ), 'got system foo link' );

commit 64fdc7c748858d1b885b58ae09fb9566a9a3ef28
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Wed May 6 09:28:57 2020 -0400

    Note reports change in upgrading doc

diff --git a/docs/UPGRADING-5.0 b/docs/UPGRADING-5.0
index 54c15e23ed..ebe2958dd5 100644
--- a/docs/UPGRADING-5.0
+++ b/docs/UPGRADING-5.0
@@ -111,6 +111,17 @@ need the extension installed. The C<%PriorityAsString>> configuration is
 simplified and consolidated, so check the documentation for details on
 updating your previous configuration.
 
+=item *
+
+Dashboards previously in the Home menu have been moved to the Reports menu.
+The reports previously in the Reports menu are still there, but you can now
+edit the Reports menu like the previous Home menu, so you can remove the
+default reports if you like.
+
+All other dashboard menu functionality should be the same including editing
+your own menu, the global settings, and setting a user's menu from the user
+admin page for that user.
+
 =back
 
 =cut

-----------------------------------------------------------------------


More information about the rt-commit mailing list