Skip to content

Commit

Permalink
Support to show lifecycle UI on ticket/asset display pages
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnavy committed Oct 11, 2023
1 parent 1d2508b commit 526ffb0
Show file tree
Hide file tree
Showing 8 changed files with 713 additions and 0 deletions.
8 changes: 8 additions & 0 deletions etc/RT_Config.pm.in
Original file line number Diff line number Diff line change
Expand Up @@ -3029,6 +3029,14 @@ Set this option to C<0> to disable this feature.

Set($QuoteSelectedText, 1);

=item C<$ShowLifecycleViewer>

Set to 1 to show lifecycle viewer on ticket/asset display pages.

=cut

Set($ShowLifecycleViewer, 0);

=back

=head2 Group Summary Configuration
Expand Down
10 changes: 10 additions & 0 deletions lib/RT/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,16 @@ our %META;
}
},

ShowLifecycleViewer => {
Section => 'Ticket display',
Overridable => 1,
SortOrder => 14,
Widget => '/Widgets/Form/Boolean',
WidgetArguments => {
Description => 'Show lifecycle viewer', #loc
},
},

# User overridable locale options
DateTimeFormat => {
Section => 'Locale', #loc
Expand Down
14 changes: 14 additions & 0 deletions share/html/Asset/Elements/ShowSummary
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,19 @@ for my $section (@sections) {
TitleBoxARGS => { title_class => "inverse" },
GroupingClass => 'col-4'
&>

% if ( RT->Config->Get( 'ShowLifecycleViewer', $session{CurrentUser} ) ) {
% my $modify_url = RT->Config->Get('WebPath'). "/Admin/Lifecycles/Modify.html?Type=asset&Name=" . $AssetObj->LifecycleObj->Name;
% my $expand = loc('Expand');
<div class="col-8">
<&| /Widgets/TitleBox, title => loc('Lifecycle'),
$session{'CurrentUser'}->HasRight(Object=> $RT::System, Right => 'SuperUser') ? (title_href => $modify_url) : (),
titleright_raw => qq{<a href="#" data-toggle="modal" data-target="#lifecycle-ui-viewer-modal"><span class="fas fa-expand-arrows-alt icon-bordered fa-2x" alt="$expand" data-toggle="tooltip" data-placement="top" data-original-title="$expand"></span></a>},
class => 'asset-info-lifecycle',
&>
<& /Elements/Lifecycle/Viewer, Object => $AssetObj &>
</&>
</div>
% }
</div>
</div>
184 changes: 184 additions & 0 deletions share/html/Elements/Lifecycle/Viewer
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
%# BEGIN BPS TAGGED BLOCK {{{
%#
%# COPYRIGHT:
%#
%# This software is Copyright (c) 1996-2022 Best Practical Solutions, LLC
%# <[email protected]>
%#
%# (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 }}}

<div class="lifecycle-ui lifecycle-ui-viewer" id="lifecycle-ui-viewer" data-id="<% $Object->Id %>" data-status="<% $current_status %>">
<script type="text/javascript" src="<% RT->Config->Get('WebPath') %>/static/js/d3.min.js"></script>
<script type="text/javascript" src="<% RT->Config->Get('WebPath') %>/static/js/lifecycleui-viewer.js"></script>

<div class="lifecycle-ui-float">
<div id="lifecycle-ui-tooltip" data-toggle="tooltip" data-html="true"></div>

% for my $status (keys %menus) {
<div class="lifecycle-ui-status-menu hidden" data-status="<% $status %>">
% my $menu = $menus{$status};
<& /Elements/Menu, menu => $menu &>
</div>
% }
</div>

<div class="form-row">
<div class="col-12">
<svg></svg>
</div>
</div>

<div class="modal fade" id="lifecycle-ui-viewer-modal" data-id="<% $Object->Id %>" data-status="<% $current_status %>">
<div class="modal-dialog modal-xl modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><&|/l&>Lifecycle</&></h5>
<a href="javascript:void(0)" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</a>
</div>
<div class="modal-body">
<div class="form-row">
<div class="col-12">
<svg></svg>
</div>
</div>
</div>
</div>
</div>
</div>
</div>



<script type="text/javascript">
jQuery(function () {
new RT.LifecycleViewer( document.getElementById('lifecycle-ui-viewer'), <% $config |n %> <% $layout ? ", $layout" : () |n %> );
// Move to body to avoid container's position style, which ruins the position calculation of actions/tooltips.
jQuery('.lifecycle-ui-float').detach().appendTo('body');

jQuery('#lifecycle-ui-viewer-modal').on('shown.bs.modal', function() {
if ( !jQuery(this).hasClass('expanded') ) {
new RT.LifecycleViewer( document.getElementById('lifecycle-ui-viewer-modal'), <% $config |n %> <% $layout ? ", $layout" : () |n %> );
jQuery(this).addClass('expanded');
}
});
});
</script>
<%INIT>

my $name = $Object->LifecycleObj->Name;

my $config = JSON( RT->Config->Get('Lifecycles')->{$name} );

my $conf = RT::Configuration->new( $session{CurrentUser} );
$conf->LoadByCols( 'Name' => "LifecycleLayout-$name", Disabled => 0 );
my $layout = JSON( $conf->_DeserializeContent( $conf->Content ) ) if $conf->Id;

my $lifecycle = $Object->LifecycleObj;

my %menus;

# largely borrowed from /Elements/Tabs
my $current_status = $Object->Status;
my $hide_resolve_with_deps = RT->Config->Get('HideResolveActionsWithDependencies')
&& $Object->HasUnresolvedDependencies;
my $query_string = sub {
my %args = @_;
my $u = URI->new();
$u->query_form( map { $_ => $args{$_} } sort keys %args );
return $u->query;
};

for my $status ( $lifecycle->Valid ) {
$menus{$status} = RT::Interface::Web::Menu->new();
}

my $add_menu = sub {
my $next = shift;
my $info = shift || {};

return unless $lifecycle->IsTransition( $current_status => $next );

my $check = $lifecycle->CheckRight( $current_status => $next );
return unless $Object->CurrentUserHasRight($check);

return
if $hide_resolve_with_deps
&& $lifecycle->IsInactive($next)
&& !$lifecycle->IsInactive($current_status);

my $action = $info->{'update'} || '';
my $url = '/Ticket/';
$url .= "Update.html?"
. $query_string->(
$action
? ( Action => $action )
: ( SubmitTicket => 1, Status => $next ),
DefaultStatus => $next,
id => $Object->Id,
);
my $key = $info->{'label'};
$menus{$next}->child(
$key => title => loc($key),
path => $url,
attributes => {
$info->{description}
? (
'data-toggle' => 'tooltip',
'data-original-title' => loc( $info->{description} ),
alt => loc( $info->{description} ),
)
: (),
}
);
};

foreach my $info ( $lifecycle->Actions($current_status) ) {
$add_menu->( $info->{to}, $info );
}

</%INIT>

<%ARGS>
$Object
</%ARGS>
13 changes: 13 additions & 0 deletions share/html/Ticket/Elements/ShowSummary
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,19 @@ my $people_behavior = $InlineEdit ? ($inline_edit_behavior{People} || $inline_ed
<& /Ticket/Elements/ShowAttachments, Ticket => $Ticket, Attachments => $Attachments, Count => RT->Config->Get('AttachmentListCount') &>
% $m->callback( %ARGS, CallbackName => 'AfterAttachments' );
<& /Ticket/Elements/ShowRequestor, Ticket => $Ticket &>

% if ( RT->Config->Get( 'ShowLifecycleViewer', $session{CurrentUser} ) ) {
% my $modify_url = RT->Config->Get('WebPath'). "/Admin/Lifecycles/Modify.html?Type=ticket&Name=" . $Ticket->LifecycleObj->Name;
% my $expand = loc('Expand');
<&| /Widgets/TitleBox, title => loc('Lifecycle'),
$session{'CurrentUser'}->HasRight(Object=> $RT::System, Right => 'SuperUser') ? (title_href => $modify_url) : (),
titleright_raw => qq{<a href="#" data-toggle="modal" data-target="#lifecycle-ui-viewer-modal"><span class="fas fa-expand-arrows-alt icon-bordered fa-2x" alt="$expand" data-toggle="tooltip" data-placement="top" data-original-title="$expand"></span></a>},
class => 'ticket-info-lifecycle',
&>
<& /Elements/Lifecycle/Viewer, Object => $Ticket &>
</&>
% }

% $m->callback( %ARGS, CallbackName => 'LeftColumn' );
</div>
<div class="boxcontainer col-md-6">
Expand Down
3 changes: 3 additions & 0 deletions share/static/css/elevator-light/boxes.css
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ div.results .titlebox .titlebox-content {
.titlebox.card.ticket-info-article {
border-top: 3px solid #E58F45;
}
.titlebox.card.ticket-info-lifecycle, .titlebox.card.asset-info-lifecycle {
border-top: 3px solid #f3bf4c;
}
/* reset to default border for .card-body */
#comp-Admin-Queues-DefaultValues .titlebox.card.ticket-info-cfs {
border-top: 1px solid #dde4eb;
Expand Down
29 changes: 29 additions & 0 deletions share/static/css/elevator-light/lifecycleui.css
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,32 @@ svg .rect {
position: absolute;
z-index: 999;
}

.lifecycle-ui-status-menu {
position: absolute;
z-index: 99;
}

.lifecycle-ui-viewer .link {
stroke: #888;
cursor: crosshair;
}

.lifecycle-ui-viewer .marker {
fill: #888;
}


.lifecycle-ui-viewer .status-active {
cursor: pointer;
}

.lifecycle-ui-viewer .link-active {
stroke: #87a96b;
cursor: pointer;
}

.lifecycle-ui-viewer .marker-active,
.lifecycle-ui-viewer .status-current {
fill: #87a96b;
}
Loading

0 comments on commit 526ffb0

Please sign in to comment.