[Rt-commit] rt branch, 5.0/dashboards-to-report-menu, created. rt-5.0.0alpha1-94-gb6e42c6d0b

Michel Rodriguez michel at bestpractical.com
Fri May 1 11:52:04 EDT 2020


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

- Log -----------------------------------------------------------------
commit 26bc02f337aba8f3e40ab275bd7d5e48e0a20392
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 a45a5dea68..af6e809c3a 100644
--- a/lib/RT/Interface/Web/MenuBuilder.pm
+++ b/lib/RT/Interface/Web/MenuBuilder.pm
@@ -92,6 +92,49 @@ sub BuildMainNav {
     }
 
     my $home = $top->child( home => title => loc('Homepage'), path => '/' );
+
+    my $search = $top->child( search => title => loc('Search'), path => '/Search/Simple.html' );
+
+    my $tickets = $search->child( tickets => title => loc('Tickets'), path => '/Search/Build.html' );
+    $tickets->child( simple => title => loc('Simple Search'), path => "/Search/Simple.html" );
+    $tickets->child( new    => title => loc('New Search'),    path => "/Search/Build.html?NewQuery=1" );
+
+    my $recents = $tickets->child( recent => title => loc('Recently Viewed'));
+    for my $ticket ( $current_user->RecentlyViewedTickets ) {
+        my $title = $ticket->{subject} || loc( "(No subject)" );
+        if ( length $title > 50 ) {
+            $title = substr($title, 0, 47);
+            $title =~ s/\s+$//;
+            $title .= "...";
+        }
+        $title = "#$ticket->{id}: " . $title;
+        $recents->child( "$ticket->{id}" => title => $title, path => "/Ticket/Display.html?id=" . $ticket->{id} );
+    }
+
+    $search->child( articles => title => loc('Articles'),   path => "/Articles/Article/Search.html" )
+        if $current_user->HasRight( Right => 'ShowArticlesMenu', Object => RT->System );
+
+    $search->child( users => title => loc('Users'),   path => "/User/Search.html" );
+
+    $search->child( groups      =>
+                    title       => loc('Groups'),
+                    path        => "/Group/Search.html",
+                    description => 'Group search'
+    );
+
+    $search->child( assets => title => loc("Assets"), path => "/Asset/Search/" )
+        if $current_user->HasRight( Right => 'ShowAssetsMenu', Object => RT->System );
+
+    my $txns = $search->child( transactions => title => loc('Transactions'), path => '/Search/Build.html?Class=RT::Transactions&ObjectType=RT::Ticket' );
+    my $txns_tickets = $txns->child( tickets => title => loc('Tickets'), path => "/Search/Build.html?Class=RT::Transactions&ObjectType=RT::Ticket" );
+    $txns_tickets->child( new => title => loc('New Search'), path => "/Search/Build.html?Class=RT::Transactions&ObjectType=RT::Ticket&NewQuery=1" );
+
+    my $reports = $top->child( reports =>
+        title       => loc('Reports'),
+        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',
@@ -128,63 +171,15 @@ sub BuildMainNav {
         }
     }
 
-    my $dashes = $top->child('home');
     if (@dashboards) {
         for my $dash (@dashboards) {
-            $home->child( 'dashboard-' . $dash->id,
+            $reports->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' );
-    $tickets->child( simple => title => loc('Simple Search'), path => "/Search/Simple.html" );
-    $tickets->child( new    => title => loc('New Search'),    path => "/Search/Build.html?NewQuery=1" );
-
-    my $recents = $tickets->child( recent => title => loc('Recently Viewed'));
-    for my $ticket ( $current_user->RecentlyViewedTickets ) {
-        my $title = $ticket->{subject} || loc( "(No subject)" );
-        if ( length $title > 50 ) {
-            $title = substr($title, 0, 47);
-            $title =~ s/\s+$//;
-            $title .= "...";
-        }
-        $title = "#$ticket->{id}: " . $title;
-        $recents->child( "$ticket->{id}" => title => $title, path => "/Ticket/Display.html?id=" . $ticket->{id} );
-    }
-
-    $search->child( articles => title => loc('Articles'),   path => "/Articles/Article/Search.html" )
-        if $current_user->HasRight( Right => 'ShowArticlesMenu', Object => RT->System );
-
-    $search->child( users => title => loc('Users'),   path => "/User/Search.html" );
 
-    $search->child( groups      =>
-                    title       => loc('Groups'),
-                    path        => "/Group/Search.html",
-                    description => 'Group search'
-    );
-
-    $search->child( assets => title => loc("Assets"), path => "/Asset/Search/" )
-        if $current_user->HasRight( Right => 'ShowAssetsMenu', Object => RT->System );
-
-    my $txns = $search->child( transactions => title => loc('Transactions'), path => '/Search/Build.html?Class=RT::Transactions&ObjectType=RT::Ticket' );
-    my $txns_tickets = $txns->child( tickets => title => loc('Tickets'), path => "/Search/Build.html?Class=RT::Transactions&ObjectType=RT::Ticket" );
-    $txns_tickets->child( new => title => loc('New Search'), path => "/Search/Build.html?Class=RT::Transactions&ObjectType=RT::Ticket&NewQuery=1" );
-
-    my $reports = $top->child( reports =>
-        title       => loc('Reports'),
-        description => loc('Reports summarizing ticket resolution and status'),
-        path        => loc('/Reports'),
-    );
     $reports->child( resolvedbyowner =>
         title       => loc('Resolved by owner'),
         path        => '/Reports/ResolvedByOwner.html',
@@ -201,6 +196,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 6227e37fe24ccc20a4dd1f2057e76f52129f8187
Author: michel <michel at bestpractical.com>
Date:   Thu Apr 16 13:21:19 2020 +0200

    Get the list of reports in the reports in the Reports menu from pref/attribute.
    
    The initial list is created from initial_data, 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..527cc638fe 100644
--- a/etc/initialdata
+++ b/etc/initialdata
@@ -923,6 +923,30 @@ 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',
+              description => 'Examine tickets resolved in a queue, grouped by owner', #loc
+          },
+          {
+              id          => 'resolvedindaterange',
+              title       => 'Resolved in date range', # loc
+              path        => '/Reports/ResolvedByDates.html',
+              description => 'Examine tickets resolved in a queue between two dates', # loc
+          },
+          {
+              id          => 'createdindaterange',
+              title       => 'Created in a date range', # loc
+              path        => '/Reports/CreatedByDates.html',
+              description => 'Examine tickets created in a queue between two dates', # loc
+          },
+      ],
+    },
 );
 
 @Classes = (
diff --git a/lib/RT/Interface/Web/MenuBuilder.pm b/lib/RT/Interface/Web/MenuBuilder.pm
index af6e809c3a..2ab8b77039 100644
--- a/lib/RT/Interface/Web/MenuBuilder.pm
+++ b/lib/RT/Interface/Web/MenuBuilder.pm
@@ -171,6 +171,7 @@ sub BuildMainNav {
         }
     }
 
+
     if (@dashboards) {
         for my $dash (@dashboards) {
             $reports->child( 'dashboard-' . $dash->id,
@@ -180,21 +181,38 @@ 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},
+            description => $report->{description},
+        );
+    }
 
     $reports->child( edit => title => loc('Update This Menu'), path => '/Prefs/DashboardsInMenu.html' );
     $reports->child( more => title => loc('All Dashboards'),   path => '/Dashboards/index.html' );

commit 2c186b74b8841e9206435336422321be68396250
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..530075fa3a
--- /dev/null
+++ b/etc/upgrade/4.5.5/content
@@ -0,0 +1,41 @@
+use strict;
+use warnings;
+
+our @Initial = (
+    # add default reports
+    sub {
+        my $reports_in_menu = 'ReportsInMenu';
+        my $attr = RT::Attribute->new( RT->System );
+        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',
+                    description => 'Examine tickets resolved in a queue, grouped by owner', #loc
+                },
+                {
+                    id          => 'resolvedindaterange',
+                    title       => 'Resolved in date range', # loc
+                    path        => '/Reports/ResolvedByDates.html',
+                    description => 'Examine tickets resolved in a queue between two dates', # loc
+                },
+                {
+                    id          => 'createdindaterange',
+                    title       => 'Created in a date range', # loc
+                    path        => '/Reports/CreatedByDates.html',
+                    description => 'Examine tickets created in a queue between two dates', # loc
+                },
+            ];
+
+            RT->System->AddAttribute(
+                        Name => $reports_in_menu,
+                        Description => 'Content of the Reports menu',
+                        Content => $content,
+            );
+        }
+    }    
+);

commit b6e42c6d0bfa43a179c990d95d62f8221a7e8c00
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 fd93c6a799..50ff460b40 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');

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


More information about the rt-commit mailing list