%# BEGIN BPS TAGGED BLOCK {{{ %# %# COPYRIGHT: %# %# This software is Copyright (c) 1996-2025 Best Practical Solutions, LLC %# <sales@bestpractical.com> %# %# (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 }}} <& /Admin/Elements/Header, Title => $title &> <& /Elements/Tabs &> <& /Elements/ListActions, actions => \@results &>

<&|/l&>The advanced view gives you direct access to the content configuration for advanced changes.

% if ( $self_service_dashboard ) { % } else { % } <&| /Widgets/TitleBox, title => loc('Content'), content_class => 'mx-auto width-sm' &>
<% $Content %>
<&|/l&>Invalid JSON
<& /Elements/Submit, Label => loc('Validate'), Name => 'Validate' &>
<& /Elements/Submit, Label => loc('Save Changes'), Name => 'Update' &>
<%INIT> my @results; my $Dashboard = RT::Dashboard->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); } Abort('Permission Denied') unless $Dashboard->CurrentUserCanSee; my $title; my $self_service_dashboard = $Dashboard->IsSelfService; if ($self_service_dashboard) { $title = loc("Modify the self-service home page"); } else { $title = loc("Modify the content of dashboard [_1]", $Dashboard->Name); } $Content ||= JSON::to_json(($Dashboard->Content || {})->{Elements} || [], { canonical => 1, pretty => 1 }); my @available_widgets = GetAvailableWidgets( Class => 'RT::Dashboard', Page => $self_service_dashboard ? 'SelfService' : '', Dashboard => $Dashboard, ); $m->callback( CallbackName => 'Default', AvailableWidgets => \@available_widgets, Content => $Content, Dashboard => $Dashboard, ); my %available_widgets = map { join( '-', $_->{portlet_type}, $_->{component} || $_->{id} ) => $_ } @available_widgets; if ( $Validate || $Update ) { my $new_content = JSON::from_json($Content); my ( $valid, @warnings ); for my $item (@$new_content) { if ( ref $item eq 'HASH' ) { if ( $item->{Elements} ) { for my $element ( @{ $item->{Elements} } ) { for my $item ( ref $element eq 'ARRAY' ? @$element : $element ) { my $key = join '-', $item->{portlet_type}, $item->{component} || $item->{id}; if ( !$available_widgets{$key} ) { push @warnings, loc( 'Invalid widget: [_1]', $key ); $valid = 0; } } } } else { my $key = join '-', $item->{portlet_type}, $item->{component} || $item->{id}; push @warnings, loc( 'Invalid widget: [_1]', $key ); } } else { push @warnings, loc( 'Invalid widget: [_1]', ref $item ? JSON::to_json( $item, { canonical => 1, pretty => 1 } ) : $item ); $valid = 0; } } $valid //= 1; my $updated; if ($valid) { if ($Validate) { push @results, loc('Content is valid'); } else { if ( JSON::to_json( $new_content, { canonical => 1, pretty => 1 } ) ne JSON::to_json( ( $Dashboard->Content || {} )->{Elements} || [], { canonical => 1, pretty => 1 } ) ) { my ( $ret, $msg ) = $Dashboard->SetContent( { Elements => $new_content } ); if ($self_service_dashboard) { push @results, $ret ? loc('Self-Service home page updated') : $msg; } else { push @results, $ret ? loc('Dashboard updated') : $msg; } } } } else { push @results, @warnings; } my $path; my $args = {}; if ($self_service_dashboard) { $path = '/Admin/Global/SelfServiceHomePage.html'; $args->{Advanced} = 1; } else { $path = '/Dashboards/Advanced.html'; $args->{id} = $id; } MaybeRedirectForResults( Actions => \@results, Path => $path, Arguments => $args, ) unless $Validate; } else { for my $widget ( $Dashboard->Portlets ) { if ( !$available_widgets{ join( '-', $widget->{portlet_type}, $widget->{component} || $widget->{id} )} ) { push @results, loc('Unable to find [_1] [_2]', $widget->{portlet_type}, $widget->{description}); } } } <%ARGS> $id => undef $Content => undef $Validate => undef $Update => undef