Skip to content

Commit

Permalink
Enable/disable Dashboards on list pages
Browse files Browse the repository at this point in the history
Now that Dashboards can be enabled or disabled, users should be
able to do this on list pages for easier bulk management.

To display the results of this action, the "ListActions" call was moved
from the caller page/component to the top of the ShowDashboards
component.
  • Loading branch information
richieri-bps committed Feb 28, 2025
1 parent 7014fd6 commit 9626602
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 20 deletions.
2 changes: 0 additions & 2 deletions share/html/Admin/Global/Dashboards.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@
<& /Elements/Header, Title => loc("Global Dashboards") &>
<& /Elements/Tabs &>

<& /Elements/ListActions &>

<& /Dashboards/Elements/ShowDashboards, Rows => $ARGS{RowsPerPage} // RT->Config->Get('DefaultSearchResultRowsPerPage') // 50, %ARGS, ShowForm => 1, Object => RT->System &>

<%INIT>
Expand Down
92 changes: 78 additions & 14 deletions share/html/Dashboards/Elements/ShowDashboards
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
%#
%# END BPS TAGGED BLOCK }}}
% if ( $ShowForm ) {
<form method="get" action="<% $FormAction || '?' %>">
<& /Elements/ListActions, actions => \@results &>
<form method="post" action="<% $FormAction || '?' %>">
<div class="row mt-2">
<div class="col-12">
<div class="form-check">
Expand All @@ -63,34 +64,97 @@
</div>
</div>
</div>
</form>
% }

% foreach my $Object (@Objects) {
% my $Dashboards = $Object->Dashboards;
% $Dashboards->FindAllRows if $IncludeDisabled;
% my $title;
% if (ref $Object eq 'RT::User' && $Object->Id == $session{CurrentUser}->Id) {
% $title = loc("My dashboards");
% } else {
% $title = loc("[_1]'s dashboards",$Object->Name);
% }
% $title =~ s/([\\'])/\\$1/g;
% $title = $m->interp->apply_escapes($title, 'h');
<%perl>
foreach my $Object (@Objects) {
my $Dashboards = $Object->Dashboards;
$Dashboards->FindAllRows if $IncludeDisabled;
my $title;
if (ref $Object eq 'RT::User' && $Object->Id == $session{CurrentUser}->Id) {
$title = loc("My dashboards");
} else {
$title = loc("[_1]'s dashboards",$Object->Name);
}
$title =~ s/([\\'])/\\$1/g;
$title = $m->interp->apply_escapes($title, 'h');

my $format = qq{'<a href="__WebPath__/__ShowURL__">__Name__</a>/TITLE:$title', __Subscription__, __Disabled__};
my $can_modify;
if ( $ShowForm && $Dashboards->Count ) {

# Load first Dashboard to check if current user can modify it
my $Dashboard = $Dashboards->First;
my $dashboard_current_user
= RT::Dashboard->new( $session{CurrentUser} );
$dashboard_current_user->Load( $Dashboard->Id );
$can_modify = $dashboard_current_user->CurrentUserCanModify();
}
if ($can_modify) {
$format = qq{'<a href="__WebPath__/__ShowURL__">__Name__</a>/TITLE:$title', __Subscription__, '__CheckBox.{Enabled}__/TITLE:Enabled'};
$ShowSubmit = 1;
}
</%perl>

<& /Elements/CollectionList,
%ARGS,
Format => qq{'<a href="__WebPath__/__ShowURL__">__Name__</a>/TITLE:$title', __Subscription__, __Disabled__},
Format => $format,
Collection => $Dashboards,
PassArguments => [qw(IncludeDisabled RowsPerPage id)],
&>
% }
% if ( $ShowForm ) {
% if ($ShowSubmit) {
<div class="row mt-2">
<div class="col-12">
<div align="right">
<input type="submit" name="Update" class="btn btn-primary" value="<&|/l&>Update</&>" />
</div>
</div>
</div>
% }
</form>
% }
<%init>
my $ShowSubmit = 0;
my @results;
my @Objects = $Object ? $Object : RT::Dashboard->new($session{CurrentUser})->ObjectsForLoading();
foreach my $object (@Objects) {
my $Dashboards = $object->Dashboards();
$Dashboards->FindAllRows if $IncludeDisabled;
while (my $Dashboard = $Dashboards->Next) {
# Load dashboard with current user to check if they can modify it
my $dashboard_current_user = RT::Dashboard->new($session{CurrentUser});
$dashboard_current_user->Load($Dashboard->Id);
if ($Update && $dashboard_current_user->CurrentUserCanModify()) {
if ($Dashboard->Disabled && grep { $_ == $Dashboard->Id } @Enabled) {
my ($ok, $msg) = $Dashboard->SetDisabled(0);
if ($ok) {
push @results, loc( '[_1] updated', loc($Dashboard->__Value('Name')) );
} else {
push @results, loc( "Can't update [_1]", loc($Dashboard->__Value('Name')) );
}
} elsif (!$Dashboard->Disabled && !grep { $_ == $Dashboard->Id } @Enabled) {
my ($ok, $msg) = $Dashboard->SetDisabled(1);
if ($ok) {
push @results, loc( '[_1] updated', loc($Dashboard->__Value('Name')) );
} else {
push @results, loc( "Can't update [_1]", loc($Dashboard->__Value('Name')) );
}
}
}
push @Enabled, $Dashboard->Id unless $Dashboard->Disabled;
}
}
# __CheckBox column type only reads from DECODED_ARGS
$DECODED_ARGS->{Enabled} = \@Enabled;
</%init>

<%ARGS>
$IncludeDisabled => undef
$Object => undef
$ShowForm => undef
$FormAction => undef
@Enabled => ()
$Update => undef
</%ARGS>
2 changes: 0 additions & 2 deletions share/html/Group/Dashboards.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@
<& /Elements/Header, Title => loc('Dashboards of group: [_1]', $group->Name) &>
<& /Elements/Tabs &>

<& /Elements/ListActions &>

<& /Dashboards/Elements/ShowDashboards, Rows => $ARGS{RowsPerPage} // RT->Config->Get('DefaultSearchResultRowsPerPage') // 50, %ARGS, ShowForm => 1, Object => $group, FormAction => "?id=$id" &>

<%INIT>
Expand Down
2 changes: 0 additions & 2 deletions share/html/User/Dashboards.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@
<& /Elements/Header, Title => loc('Dashboards of user: [_1]', $user->Name) &>
<& /Elements/Tabs &>

<& /Elements/ListActions &>

<& /Dashboards/Elements/ShowDashboards, Rows => $ARGS{RowsPerPage} // RT->Config->Get('DefaultSearchResultRowsPerPage') // 50, %ARGS, ShowForm => 1, Object => $user, FormAction => "?id=$id" &>

<%INIT>
Expand Down

0 comments on commit 9626602

Please sign in to comment.