[Rt-commit] rt branch, 5.0/search-selection-for-dashboards-menus, repushed

Craig Kaiser craig at bestpractical.com
Mon Jul 6 15:18:10 EDT 2020


The branch 5.0/search-selection-for-dashboards-menus was deleted and repushed:
       was a2425a97ea49c8975edd957b3fb5e3973d47b6bc
       now 04279486948a0c0231c067d6f060a4ef63190a0d

1: 9940198328 ! 1: b9dd6fcbb2 Convert Prefs/DashboardsInMenu.html to drag and drop UI
    @@ -18,7 +18,6 @@
     -
     -<&|/Widgets/TitleBox, title => loc("Reset dashboards in menu") &>
     -<div class="mt-3 mb-1 ml-3">
    --  <form method="post" action="DashboardsInMenu.html">
     +<form method="post" name="UpdateSearches" class="mx-auto max-width-lg">
     +  <& /Widgets/SearchSelection,
     +    pane_name => { dashboard => loc('Dashboards in menu') },
    @@ -36,19 +35,19 @@
     +</form>
     +
     +<&|/Widgets/TitleBox, title => loc("Reset dashboards in menu"), class => "mx-auto max-width-lg" &>
    -+  <form method="post" action="/Prefs/DashboardsInMenu.html">
    +   <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") &>
     +<form method="post" name="UpdateSearches" class="mx-auto max-width-lg">
     +  <& /Widgets/SearchSelection,
    @@ -68,42 +67,33 @@
     +
     +<&|/Widgets/TitleBox, title => loc("Reset reports in menu"), class => "mx-auto max-width-lg" &>
      <div class="mt-3 mb-1 ml-3">
    --  <form method="post" action="DashboardsInMenu.html">
    -+  <form method="post" action="/Prefs/DashboardsInMenu.html">
    +   <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>
     @@
    - }
    - 
    - 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'};
    --    }
    -+  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');
    --
    ++my @dashboard_components = map {{ type => 'dashboard', id => $_->id, name => $_->Name, label => $_->Name }} $m->comp("/Dashboards/Elements/ListOfDashboards", IncludeSuperuserGroups => 0 );
    ++my @report_components = map { {%$_, name => $_->{'title'}, type => 'report', label => $_->{'title'} } } @{ ListOfReports() };
    + 
     -my $dashboard_pref =
     -  $session{CurrentUser}->UserObj->Preferences( 'DashboardsInMenu',
     -    $default_dashboards ? $default_dashboards->Content : () );
    --
    ++if ($ARGS{UpdateSearches}) {
    ++    if ( $ARGS{'dashboard_id'} eq 'DashboardsInMenu' ) {
    ++        my @dashboard_ids;
    + 
     -my $current_dashboards = $dashboard_pref->{dashboards} || [];
    --
    ++        my $dashboard_names = ref $ARGS{'dashboard'} eq 'ARRAY' ? $ARGS{'dashboard'} : [$ARGS{'dashboard'}];
    ++        foreach my $name ( @{$dashboard_names} ) {
    ++            next unless $name;
    ++            $name =~ s/dashboard-//;
    + 
     -my @dashboards = map { [$_->id, $_->Name] } $m->comp("/Dashboards/Elements/ListOfDashboards", IncludeSuperuserGroups => 0 );
    --
    ++            my $attribute = RT::Attribute->new( $session{'CurrentUser'} );
    + 
     -my ($dashboard_pane) = $m->comp(
     -    '/Admin/Elements/ConfigureDashboardsInMenu',
     -    Action => 'DashboardsInMenu.html',
    @@ -114,58 +104,42 @@
     -        my ( $conf ) = @_;
     -        my ( $ok, $msg ) =
     -          $user->SetPreferences( 'DashboardsInMenu', $conf );
    --        push @results, $ok ? loc('Preferences saved for dashboards in menu.') : $msg;
    --        delete $session{'dashboards_in_menu'};
    -+my @dashboard_components = map {{ type => 'dashboard', id => $_->id, name => $_->Name, label => $_->Name }} $m->comp("/Dashboards/Elements/ListOfDashboards", IncludeSuperuserGroups => 0 );
    -+my @report_components = map { {%$_, name => $_->{'title'}, type => 'report', label => $_->{'title'} } } @{ ListOfReports() };
    -+
    -+if ($ARGS{UpdateSearches}) {
    -+  if ( $ARGS{'dashboard_id'} eq 'DashboardsInMenu' ) {
    -+      my @dashboard_ids;
    -+
    -+      my $dashboard_names = ref $ARGS{'dashboard'} eq 'ARRAY' ? $ARGS{'dashboard'} : [$ARGS{'dashboard'}];
    -+      foreach my $name ( @{$dashboard_names} ) {
    -+          next unless $name;
    -+          $name =~ s/dashboard-//;
    -+
    -+          my $attribute = RT::Attribute->new( $session{'CurrentUser'} );
    -+
    -+          my ($ret, $msg) = $attribute->LoadByCols( Name => 'Dashboard', Description => $name );
    -+          if ( $ret ) {
    -+              push @dashboard_ids, $attribute->Id;
    -+          }
    -+          else {
    -+              RT::Logger->error( "Could not load dashboard: $msg" );
    -+              push @results, "Could not load dashboard $name";
    -+          }
    -+      }
    -+
    -+      my ( $ok, $msg ) = $user->SetPreferences( $ARGS{'dashboard_id'}, { 'dashboards' => \@dashboard_ids } );
    -+      push @results, $ok ? loc('Preferences saved for dashboards in menu.') : $msg;
    -+      delete $session{'dashboards_in_menu'};
    -+  }
    -+  else {
    -+    my $report_names = ref $ARGS{'report'} eq 'ARRAY' ? $ARGS{'report'} : [$ARGS{'report'}];
    -+    my @ret;
    -+    foreach my $report ( @report_components ) {
    -+        last unless $report_names->[0];
    -+
    -+        push @ret, $report if grep { $_ =~ /report-$report->{'name'}/ } @{$report_names};
    ++            my ($ret, $msg) = $attribute->LoadByCols( Name => 'Dashboard', Description => $name );
    ++            if ( $ret ) {
    ++                push @dashboard_ids, $attribute->Id;
    ++            }
    ++            else {
    ++                RT::Logger->error( "Could not load dashboard: $msg" );
    ++                push @results, "Could not load dashboard $name";
    ++            }
    ++        }
    ++
    ++        my ( $ok, $msg ) = $user->SetPreferences( $ARGS{'dashboard_id'}, { 'dashboards' => \@dashboard_ids } );
    +         push @results, $ok ? loc('Preferences saved for dashboards in menu.') : $msg;
    +         delete $session{'dashboards_in_menu'};
          }
     -);
    ++    else {
    ++      my $report_names = ref $ARGS{'report'} eq 'ARRAY' ? $ARGS{'report'} : [$ARGS{'report'}];
    ++      my @ret;
    ++      foreach my $report ( @report_components ) {
    ++          last unless $report_names->[0];
    ++
    ++          push @ret, $report if grep { $_ =~ /report-$report->{'name'}/ } @{$report_names};
    ++      }
    ++
    ++      my ( $ok, $msg ) = $user->SetPreferences( $ARGS{'dashboard_id'}, \@ret );
    ++      push @results, $ok ? loc('Preferences saved for reports in menu.') : $msg;
    ++      delete $session{'reports_in_menu'};
    ++    }
    ++}
    ++
    ++my %selected;
      
     -my ( @reports, %reports );
     -for my $report ( @{ ListOfReports() } ) {
     -    push @reports, [ $report->{id}, $report->{title} ];
     -    $reports{ $report->{id} } = $report;
    -+    my ( $ok, $msg ) = $user->SetPreferences( $ARGS{'dashboard_id'}, \@ret );
    -+    push @results, $ok ? loc('Preferences saved for reports in menu.') : $msg;
    -+    delete $session{'reports_in_menu'};
    -+  }
    -+}
    -+
    -+my %selected;
    -+
     +my $dashboard_pref = $user->Preferences('DashboardsInMenu');
     +unless ($dashboard_pref) {
     +    my ($defaults) = RT::System->new($session{'CurrentUser'})->Attributes->Named('DashboardsInMenu');
    @@ -191,11 +165,10 @@
     -        }
     -        my ( $ok, $msg ) = $user->SetPreferences( 'ReportsInMenu', $user_reports );
     -        push @results, $msg unless $ok;
    --
    --        delete $session{'reports_in_menu'};
     +# prefs returns an array of Dashboard ID's
     +my $selected_dashboard_ids = $dashboard_pref->{'dashboards'} || [];
    -+
    + 
    +-        delete $session{'reports_in_menu'};
     +my @selected_dashboards;
     +foreach my $id ( @{$selected_dashboard_ids} ) {
     +    my $attribute = RT::Attribute->new( RT->SystemUser );
2: f5e8dade1c ! 2: 390763e6bb Convert Admin/Users/DashboardsInMenu.html to drag and drop UI
    @@ -6,27 +6,18 @@
     --- a/share/html/Admin/Users/DashboardsInMenu.html
     +++ b/share/html/Admin/Users/DashboardsInMenu.html
     @@
    - %# those contributions and any derivatives thereof.
    - %#
    - %# END BPS TAGGED BLOCK }}}
    --<& /Admin/Elements/Header, Title => $title  &>
    --<& /Elements/Tabs &>
    --
    --<& /Elements/ListActions, actions => \@actions &>
    --
    + 
    + <& /Elements/ListActions, actions => \@actions &>
    + 
     -<&|/Widgets/TitleBox,
     -    title => loc('Dashboards in menu'),
     -    bodyclass => ""
    -+<& /Elements/Header, Title => $title &>
    -+<& /Elements/Tabs
    - &>
    +-&>
     -<& /Widgets/SelectionBox:show, self => $dashboard_pane &>
     -</&>
     -
     -<&|/Widgets/TitleBox, title => loc("Reset dashboards in menu") &>
     -<div class="mt-3 mb-1 ml-3">
    -+<& /Elements/ListActions, actions => \@results &>
    -+
     +<form method="post" action="DashboardsInMenu.html" name="UpdateSearches" class="mx-auto max-width-lg">
     +  <& /Widgets/SearchSelection,
     +    pane_name => { dashboard => loc('Dashboards in menu') },
    @@ -45,19 +36,19 @@
     +
     +<&|/Widgets/TitleBox, title => loc("Reset dashboards in menu"), class => "mx-auto max-width-lg" &>
        <form method="post" action="DashboardsInMenu.html">
    --    <input type="hidden" name="id" value="<% $id %>" />
    +     <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>
    --</&>
    --
    + </&>
    + 
     -<&|/Widgets/TitleBox,
     -    title => loc('Reports in menu'),
     -    bodyclass => ""
     -&>
     -<& /Widgets/SelectionBox:show, self => $report_pane &>
    - </&>
    - 
    +-</&>
    +-
     -<&|/Widgets/TitleBox, title => loc("Reset reports in menu") &>
     +<form method="post" name="UpdateSearches" class="mx-auto max-width-lg">
     +  <& /Widgets/SearchSelection,
    @@ -78,41 +69,16 @@
     +<&|/Widgets/TitleBox, title => loc("Reset reports in menu"), class => "mx-auto max-width-lg" &>
      <div class="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("Reports menu for the user [_1]", $UserObj->Name);
    -+<%INIT>
    -+my @results;
    -+
    -+my $user = RT::User->new($session{'CurrentUser'});
    -+$user->Load($id) || Abort("Couldn't load user '" . ($id || '') . "'");
    -+my $title = loc("Reports menu for the user [_1]", $user->Name);
    - 
    - 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;
    -+    my ( $ok, $msg ) = $user->SetPreferences( 'DashboardsInMenu', {} );
    -+    push @results, $ok ? loc( 'Preferences saved for user [_1].', $user->Name ) : $msg;
    - }
    - 
    - if ( $ARGS{ResetReports} ) {
    --    if ( $UserObj->Preferences('ReportsInMenu') ) {
    -+    if ( $user->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 ( $ok, $msg ) = $user->DeletePreferences('ReportsInMenu');
    -+        push @results, $ok ? loc( 'Preferences saved for user [_1].', $user->Name ) : $msg;
    +     <input type="hidden" name="id" value="<% $id %>" />
    +@@
    + 
    + <%init>
    + my @actions;
    ++
    + my $UserObj = RT::User->new($session{'CurrentUser'});
    + $UserObj->Load($id) || Abort("Couldn't load user '" . ($id || '') . "'");
    + my $title = loc("Reports menu for the user [_1]", $UserObj->Name);
    +@@
          }
      }
      
    @@ -166,12 +132,12 @@
     +          }
     +          else {
     +              RT::Logger->error( "Could not load dashboard: $msg" );
    -+              push @results, "Could not load dashboard $name";
    ++              push @actions, "Could not load dashboard $name";
     +          }
     +      }
     +
    -+      my ( $ok, $msg ) = $user->SetPreferences( $ARGS{'dashboard_id'}, { 'dashboards' => \@dashboard_ids } );
    -+      push @results, $ok ? loc('Preferences saved for dashboards in menu.') : $msg;
    ++      my ( $ok, $msg ) = $UserObj->SetPreferences( $ARGS{'dashboard_id'}, { 'dashboards' => \@dashboard_ids } );
    ++      push @actions, $ok ? loc('Preferences saved for dashboards in menu.') : $msg;
     +      delete $session{'dashboards_in_menu'};
     +  }
     +  else {
    @@ -188,18 +154,10 @@
     -for my $report ( @{ ListOfReports() } ) {
     -    push @reports, [ $report->{id}, $report->{title} ];
     -    $reports{ $report->{id} } = $report;
    -+    my ( $ok, $msg ) = $user->SetPreferences( $ARGS{'dashboard_id'}, \@ret );
    -+    push @results, $ok ? loc('Preferences saved for reports in menu.') : $msg;
    ++    my ( $ok, $msg ) = $UserObj->SetPreferences( $ARGS{'dashboard_id'}, \@ret );
    ++    push @actions, $ok ? loc('Preferences saved for reports in menu.') : $msg;
     +    delete $session{'reports_in_menu'};
     +  }
    -+}
    -+
    -+my %selected;
    -+
    -+my $dashboard_pref = $user->Preferences('DashboardsInMenu');
    -+unless ($dashboard_pref) {
    -+    my ($defaults) = RT::System->new($session{'CurrentUser'})->Attributes->Named('DashboardsInMenu');
    -+    $dashboard_pref = $defaults ? $defaults->Content : {};
      }
      
     -my ($default_reports) = RT::System->new( $session{'CurrentUser'} )->Attributes->Named('ReportsInMenu');
    @@ -226,6 +184,14 @@
     -        else {
     -            push @actions, $msg;
     -        }
    ++my %selected;
    ++
    ++my $dashboard_pref = $UserObj->Preferences('DashboardsInMenu');
    ++unless ($dashboard_pref) {
    ++    my ($defaults) = RT::System->new($session{'CurrentUser'})->Attributes->Named('DashboardsInMenu');
    ++    $dashboard_pref = $defaults ? $defaults->Content : {};
    ++}
    ++
     +# prefs returns an array of Dashboard ID's
     +my $selected_dashboard_ids = $dashboard_pref->{'dashboards'} || [];
     +
    @@ -248,17 +214,16 @@
     +    };
     +}
     +$selected{'dashboard'} = \@selected_dashboards;
    -+
    -+my $report_pref = $user->Preferences('ReportsInMenu');
    + 
    ++my $report_pref = $UserObj->Preferences('ReportsInMenu');
     +unless ($report_pref) {
     +    my ($defaults) = RT::System->new( $session{'CurrentUser'} )->Attributes->Named('ReportsInMenu');
     +    $report_pref = $defaults ? $defaults->Content : {};
     +}
     +my @report_pref_sanitized = map { {%$_, name => $_->{'title'}, type => 'report', label => $_->{'title'} } } @{ $report_pref };
     +$selected{'report'} = \@report_pref_sanitized || [];
    -+</%INIT>
    - 
    --</%init>
    + </%init>
    ++
      <%ARGS>
      $id => undef
      </%ARGS>
3: f11b27c69e ! 3: 006e06f399 Convert Admin/Global/DashboardsInMenu.html to drag and drop UI
    @@ -6,19 +6,14 @@
     --- a/share/html/Admin/Global/DashboardsInMenu.html
     +++ b/share/html/Admin/Global/DashboardsInMenu.html
     @@
    - <& /Admin/Elements/Header, Title => loc("Reports menu") &>
      <& /Elements/Tabs &>
      
    --<& /Elements/ListActions, actions => \@actions &>
    + <& /Elements/ListActions, actions => \@actions &>
     -<&|/Widgets/TitleBox, title => loc('Dashboards in menu'), bodyclass => "" &>
     -<& /Widgets/SelectionBox:show, self => $dashboard_pane &></&>
    --
    + 
     -<&|/Widgets/TitleBox, title => loc('Reports in menu'), bodyclass => "" &>
     -<& /Widgets/SelectionBox:show, self => $report_pane &></&>
    --<%init>
    --my @actions;
    -+<& /Elements/ListActions, actions => \@results &>
    -+
     +<form method="post" name="UpdateSearches" class="mx-auto max-width-lg">
     +  <& /Widgets/SearchSelection,
     +    pane_name => { dashboard => loc('Dashboards in menu') },
    @@ -51,8 +46,8 @@
     +  <& /Elements/Submit, Name => "UpdateSearches", Label => loc('Save') &>
     +</form>
     +
    -+<%INIT>
    -+my @results;
    + <%init>
    + my @actions;
     +my $title = loc("Customize").' '.loc("reports menu");
      my $sys = RT::System->new( $session{'CurrentUser'} );
      
    @@ -95,7 +90,7 @@
     -            ($status, $msg) = $dashboard_attr->SetContent($conf);
     +if ($ARGS{UpdateSearches}) {
     +    if ( !$has_right ) {
    -+        push @results, loc('Permission Denied');
    ++        push @actions, loc('Permission Denied');
     +    }
     +    else {
     +        if ( $ARGS{'dashboard_id'} eq 'DashboardsInMenu' ) {
    @@ -114,7 +109,7 @@
     +                }
     +                else {
     +                    RT::Logger->error( "Could not load dashboard: $msg" );
    -+                    push @results, "Could not load dashboard $name";
    ++                    push @actions, "Could not load dashboard $name";
     +                }
     +            }
     +            my ( $ok, $msg );
    @@ -129,7 +124,7 @@
     +                    Content => { 'dashboards' => \@dashboard_ids },
     +                );
     +            }
    -+            push @results, $ok ? loc('Global dashboards in menu saved.') : $msg;
    ++            push @actions, $ok ? loc('Global dashboards in menu saved.') : $msg;
     +            delete $session{'dashboards_in_menu'};
              }
              else {
    @@ -158,7 +153,7 @@
     +                  Content => { 'reports' => \@ret },
     +              );
     +          }
    -+          push @results, $ok ? loc('Preferences saved for reports in menu.') : $msg;
    ++          push @actions, $ok ? loc('Preferences saved for reports in menu.') : $msg;
     +          delete $session{'reports_in_menu'};
              }
     -        push @actions, $status ? loc('Global dashboards in menu saved.') : $msg;
    @@ -215,9 +210,8 @@
     +        next;
          }
     -);
    --
    + 
     -$m->comp( '/Widgets/SelectionBox:process', %ARGS, self => $_ ) for ( $dashboard_pane, $report_pane );
    - 
     +    push @selected_dashboards, {
     +      id      => $id,
     +      name    => $attribute->Description,
    @@ -227,10 +221,10 @@
     +}
     +$selected{'dashboard'} = \@selected_dashboards;
      
    --</%init>
     +my $report_pref = $reports_attr ? $reports_attr->Content : [];
      
     +my @report_pref_sanitized = map { {%$_, name => $_->{'title'}, type => 'report', label => $_->{'title'} } } @{ $report_pref };
     +$selected{'report'} = \@report_pref_sanitized || [];
    -+</%INIT>
    + </%init>
    +-
     
4: a2425a97ea = 4: 0427948694 Update dashboard tests for drag and drop UI



More information about the rt-commit mailing list