%# BEGIN BPS TAGGED BLOCK {{{ %# %# COPYRIGHT: %# %# This software is Copyright (c) 1996-2023 Best Practical Solutions, LLC %# %# %# (Except where explicitly superseded by other copyright notices) %# %# %# LICENSE: %# %# This work is made available to you under the terms of Version 2 of %# the GNU General Public License. A copy of that license should have %# been provided with this software, but in any event can be snarfed %# from www.gnu.org. %# %# This work is distributed in the hope that it will be useful, but %# WITHOUT ANY WARRANTY; without even the implied warranty of %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU %# General Public License for more details. %# %# You should have received a copy of the GNU General Public License %# along with this program; if not, write to the Free Software %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA %# 02110-1301 or visit their web page on the internet at %# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html. %# %# %# CONTRIBUTION SUBMISSION POLICY: %# %# (The following paragraph is not intended to limit the rights granted %# to you to modify and distribute this software under the terms of %# the GNU General Public License and is only of importance to you if %# you choose to contribute your changes and enhancements to the %# community by submitting them to Best Practical Solutions, LLC.) %# %# By intentionally submitting any modifications, corrections or %# derivatives to this work, or any other work intended for use with %# Request Tracker, to Best Practical Solutions, LLC, you confirm that %# you are the copyright holder for those contributions and you grant %# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable, %# royalty-free, perpetual, license to use, copy, create derivative %# works based on those contributions, and sublicense and distribute %# those contributions and any derivatives thereof. %# %# END BPS TAGGED BLOCK }}} <& /Elements/Header, Title => $title &> <& /Elements/Tabs &> <& /Elements/ListActions, actions => \@results &> <& /Widgets/SearchSelection, pane_name => \%pane_name, sections => \@sections, selected => \%selected, filters => \@filters, &> <& /Elements/Submit, Name => "UpdateSearches", Label => loc('Save') &> <%INIT> my @results; # Don't permit someone to supply "self_service_dashboard=1" on the URL line if ($m->request_path ne '/Admin/Global/SelfServiceHomePage.html') { $self_service_dashboard = 0; } my $class = $self_service_dashboard ? 'RT::Dashboard::SelfService' : 'RT::Dashboard'; RT::StaticUtil::RequireModule($class); my $Dashboard = $class->new($session{'CurrentUser'}); my ($ok, $msg) = $Dashboard->LoadById($id); unless ($ok) { RT::Logger->error("Unable to load dashboard with $id: $msg"); Abort(loc("Could not load dashboard [_1]", $id), Code => HTTP::Status::HTTP_NOT_FOUND); } my $title; if ($self_service_dashboard) { $title = loc("Modify the self-service home page"); } else { $title = loc("Modify the content of dashboard [_1]", $Dashboard->Name); } my @sections; my %item_for; my @components; if ($self_service_dashboard) { @components = map { type => "component", name => $_, label => loc($_) }, @{RT->Config->Get('SelfServicePageComponents') || []}; } else { @components = map { type => "component", name => $_, label => loc($_) }, @{RT->Config->Get('HomepageComponents')}; } $item_for{ $_->{type} }{ $_->{name} } = $_ for @components; push @sections, { id => 'components', label => loc("Components"), items => \@components, }; my $sys = RT::System->new($session{'CurrentUser'}); my @objs = ($sys); push @objs, RT::SavedSearch->new( $session{CurrentUser} )->ObjectsForLoading if $session{'CurrentUser'}->HasRight( Right => 'LoadSavedSearch', Object => $RT::System ); for my $object (@objs) { my @items; my $object_id = ref($object) . '-' . $object->Id; # saved searches and charts for ($m->comp("/Search/Elements/SearchesForObject", Object => $object)) { my ($desc, $loc_desc, $search) = @$_; my $SearchType = 'Ticket'; if ((ref($search->Content)||'') eq 'HASH') { $SearchType = $search->Content->{'SearchType'} if $search->Content->{'SearchType'}; } else { $RT::Logger->debug("Search ".$search->id." ($desc) appears to have no Content"); } my $item; my $oid = $object_id.'-SavedSearch-'.$search->Id; $item = { type => 'saved', name => $oid, search_type => $SearchType, label => $loc_desc }; my $setting = RT::SavedSearch->new($session{CurrentUser}); $setting->Load($object, $search->Id); $item->{possibly_hidden} = !$setting->IsVisibleTo($Dashboard->Privacy); $item_for{ $item->{type} }{ $item->{name} } = $item; push @items, $item; } for my $dashboard ($m->comp("/Dashboards/Elements/DashboardsForObject", Object => $object, Flat => 1)) { # Users *can* set up mutually recursive dashboards, but don't make it # THIS easy for them to shoot themselves in the foot. next if $dashboard->Id == $Dashboard->id; my $name = 'dashboard-' . $dashboard->Id . '-' . $dashboard->Privacy; my $item = { type => 'dashboard', name => $name, label => $dashboard->Name }; $item->{possibly_hidden} = !$dashboard->IsVisibleTo($Dashboard->Privacy); $item_for{ $item->{type} }{ $item->{name} } = $item; push @items, $item; } my $label = $object eq $sys ? loc('System') : $object->isa('RT::Group') ? $object->Label : $object->Name; push @sections, { id => $object_id, label => $label, items => [ sort { lc($a->{label}) cmp lc($b->{label}) } @items ], }; } my %pane_name = ( 'body' => loc('Body'), 'sidebar' => loc('Sidebar'), ); my %selected; do { my $panes = $Dashboard->Panes; for my $pane (keys %$panes) { my @items; for my $saved (@{ $panes->{$pane} }) { my $item; if ($saved->{portlet_type} eq 'component') { $item = $item_for{ $saved->{portlet_type} }{ $saved->{component} }; } elsif ($saved->{portlet_type} eq 'search') { my $name = join '-', $saved->{privacy}, 'SavedSearch', $saved->{id}; $item = $item_for{saved}{$name}; } else { my $type = $saved->{portlet_type}; my $name = join '-', $type, $saved->{id}, $saved->{privacy}; $item = $item_for{$type}{$name}; } if ($item) { push @items, $item; } else { push @results, loc('Unable to find [_1] [_2]', $saved->{portlet_type}, $saved->{description}); } } $selected{$pane} = \@items; } }; my @filters = ( [ 'component' => loc('Components') ], [ 'dashboard' => loc('Dashboards') ], [ 'ticket' => loc('Tickets') ], [ 'chart' => loc('Charts') ], ); $m->callback( CallbackName => 'Default', pane_name => \%pane_name, sections => \@sections, selected => \%selected, filters => \@filters, ); if ( $ARGS{UpdateSearches} ) { $ARGS{dashboard_id} = $id; $ARGS{self_service_dashboard} = $self_service_dashboard; my ($ok, $msg) = UpdateDashboard( \%ARGS, \%item_for ); if ($self_service_dashboard) { push @results, $ok ? loc('Self-Service home page updated') : $msg; } else { push @results, $ok ? loc('Dashboard updated') : $msg; } my $path; my $args; if ($self_service_dashboard) { $path = '/Admin/Global/SelfServiceHomePage.html'; $args = { }; } else { $path = '/Dashboards/Queries.html'; $args = { id => $id }; } MaybeRedirectForResults( Actions => \@results, Path => $path, Arguments => $args, ); } <%ARGS> $id => '' unless defined $id $self_service_dashboard => 0