Skip to content

Commit

Permalink
Use TicketsAssets autocomplete excluding existing links
Browse files Browse the repository at this point in the history
  • Loading branch information
bkembreeBPS committed Nov 13, 2023
1 parent bc63b8d commit 4ef82fd
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions share/html/Elements/AddLinks
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,32 @@ my $id = ($Object and $Object->id)
? $Object->id
: "new";

my $exclude = qq| data-autocomplete="Tickets" data-autocomplete-multiple="1"|;
$exclude .= qq| data-autocomplete-exclude="$id"| if $Object->id;
my $exclude = qq| data-autocomplete="TicketsAssets" data-autocomplete-multiple="1"|;
my @excludes;
push @excludes, ( $Object->isa('RT::Asset') ? 'asset:' : '' ) . $id
if $id ne 'new';

my %exclude_links = (
DependsOn => '',
DependedOnBy => '',
MemberOf => '',
Members => '',
RefersTo => '',
ReferredToBy => '',
);
foreach my $link_type ( keys %exclude_links ) {
my @ids;
if ( $id ne 'new' ) {
my $links = $Object->$link_type;
while ( my $link = $links->Next ) {
if ( my $TargetObj = $link->TargetObj ) {
push @ids, ( $TargetObj->isa('RT::Asset') ? 'asset:' : '' ) . $TargetObj->id;
}
}
}
$exclude_links{$link_type} = $exclude . ' data-autocomplete-exclude="' . join( ' ', @excludes, @ids ) . '"'
if @excludes || @ids;
}
</%init>
% if (ref($Object) eq 'RT::Ticket') {
<i><&|/l&>Enter tickets or URIs to link tickets to. Separate multiple entries with spaces.</&>
Expand All @@ -76,24 +100,24 @@ $exclude .= qq| data-autocomplete-exclude="$id"| if $Object->id;


<&| /Elements/LabeledValue, RawLabel => $m->scomp('ShowRelationLabel', Object => $Object, Label => loc('Depends on'), Relation => 'DependsOn') &>
<input type="text" class="form-control" name="<%$id%>-DependsOn" value="<% $ARGSRef->{"$id-DependsOn"} || '' %>" <% $exclude |n%>/>
<input type="text" class="form-control" name="<%$id%>-DependsOn" value="<% $ARGSRef->{"$id-DependsOn"} || '' %>" <% $exclude_links{DependsOn} |n%>/>
</&>
<&| /Elements/LabeledValue, RawLabel => $m->scomp('ShowRelationLabel', Object => $Object, Label => loc('Depended on by'), Relation => 'DependedOnBy') &>
<input type="text" class="form-control" name="DependsOn-<%$id%>" value="<% $ARGSRef->{"DependsOn-$id"} || '' %>" <% $exclude |n%>/>
<input type="text" class="form-control" name="DependsOn-<%$id%>" value="<% $ARGSRef->{"DependsOn-$id"} || '' %>" <% $exclude_links{DependedOnBy} |n%>/>
</&>

<&| /Elements/LabeledValue, RawLabel => $m->scomp('ShowRelationLabel', Object => $Object, Label => loc('Parents'), Relation => 'Parents') &>
<input type="text" class="form-control" name="<%$id%>-MemberOf" value="<% $ARGSRef->{"$id-MemberOf"} || '' %>" <% $exclude |n%>/>
<input type="text" class="form-control" name="<%$id%>-MemberOf" value="<% $ARGSRef->{"$id-MemberOf"} || '' %>" <% $exclude_links{MemberOf} |n%>/>
</&>
<&| /Elements/LabeledValue, RawLabel => $m->scomp('ShowRelationLabel', Object => $Object, Label => loc('Children'), Relation => 'Children') &>
<input type="text" class="form-control" name="MemberOf-<%$id%>" value="<% $ARGSRef->{"MemberOf-$id"} || '' %>" <% $exclude |n%>/>
<input type="text" class="form-control" name="MemberOf-<%$id%>" value="<% $ARGSRef->{"MemberOf-$id"} || '' %>" <% $exclude_links{Members} |n%>/>
</&>

<&| /Elements/LabeledValue, RawLabel => $m->scomp('ShowRelationLabel', Object => $Object, Label => loc('Refers to'), Relation => 'RefersTo') &>
<input type="text" class="form-control" name="<%$id%>-RefersTo" value="<% $ARGSRef->{"$id-RefersTo"} || '' %>" <% $exclude |n%>/>
<input type="text" class="form-control" name="<%$id%>-RefersTo" value="<% $ARGSRef->{"$id-RefersTo"} || '' %>" <% $exclude_links{RefersTo} |n%>/>
</&>
<&| /Elements/LabeledValue, RawLabel => $m->scomp('ShowRelationLabel', Object => $Object, Label => loc('Referred to by'), Relation => 'ReferredToBy') &>
<input type="text" class="form-control" name="RefersTo-<%$id%>" value="<% $ARGSRef->{"RefersTo-$id"} || '' %>" <% $exclude |n%>/>
<input type="text" class="form-control" name="RefersTo-<%$id%>" value="<% $ARGSRef->{"RefersTo-$id"} || '' %>" <% $exclude_links{ReferredToBy} |n%>/>
</&>

<& /Elements/EditCustomFields,
Expand Down

0 comments on commit 4ef82fd

Please sign in to comment.