Skip to content

Commit

Permalink
Merge branch '6.0/search-refresh-button'
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnavy committed Jan 24, 2025
2 parents 4d69fa1 + f6415ff commit f8ffcfd
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 13 deletions.
1 change: 1 addition & 0 deletions etc/RT_Config.pm.in
Original file line number Diff line number Diff line change
Expand Up @@ -2337,6 +2337,7 @@ C<%SVG> allows you to customize SVG images used in RT.

Set(
%SVG,
'arrow-clockwise' => '<path fill-rule="evenodd" d="M8 3a5 5 0 1 0 4.546 2.914.5.5 0 0 1 .908-.417A6 6 0 1 1 8 2z"/><path d="M8 4.466V.534a.25.25 0 0 1 .41-.192l2.36 1.966c.12.1.12.284 0 .384L8.41 4.658A.25.25 0 0 1 8 4.466"/>',
'arrow-up' => '<path fill-rule="evenodd" d="M1 8a7 7 0 1 0 14 0A7 7 0 0 0 1 8m15 0A8 8 0 1 1 0 8a8 8 0 0 1 16 0m-7.5 3.5a.5.5 0 0 1-1 0V5.707L5.354 7.854a.5.5 0 1 1-.708-.708l3-3a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1-.708.708L8.5 5.707z"/>',
'arrow-down' => '<path fill-rule="evenodd" d="M1 8a7 7 0 1 0 14 0A7 7 0 0 0 1 8m15 0A8 8 0 1 1 0 8a8 8 0 0 1 16 0M8.5 4.5a.5.5 0 0 0-1 0v5.793L5.354 8.146a.5.5 0 1 0-.708.708l3 3a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293z"/>',
'bookmark' => '<path d="M2 2a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v13.5a.5.5 0 0 1-.777.416L8 13.101l-5.223 2.815A.5.5 0 0 1 2 15.5zm2-1a1 1 0 0 0-1 1v12.566l4.723-2.482a.5.5 0 0 1 .554 0L13 14.566V2a1 1 0 0 0-1-1z"/>',
Expand Down
51 changes: 40 additions & 11 deletions share/html/Elements/ShowSearch
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,17 @@
hideable => $hideable,
class => 'fullwidth',
htmx_get => RT->Config->Get('WebPath') . ( $session{CurrentUser}->Privileged ? '' : '/SelfService' ) . '/Views/Component/SavedSearch?SavedSearch=' . $SavedSearch . $htmx_query_args,
htmx_load => $HTMXLoad &>
htmx_load => $HTMXLoad,
htmx_id => 'rt-savedsearch-' . $search->Id,
&>
<& $query_display_component, hideable => $hideable, %$ProcessedSearchArg, ShowNavigation => 0, Class => $class, HasResults => $HasResults, PreferOrderBy => 1 &>
% if ( $refresh_seconds ) {
<div class="refresh-text">
<small class="text-body-secondary"><&|/l&>Last loaded</&> <% $loaded_date->AsString %>.</small>
% if ( $refresh_seconds ) {
<small class="text-body-secondary"><&|/l, RT::Date->new($session{CurrentUser})->DurationAsString($refresh_seconds) &>Refreshing every [_1].</&></small>
</div>
% }
</div>
<& /Widgets/Spinner &>
</&>
<%init>
my $search;
Expand Down Expand Up @@ -134,6 +137,10 @@ if ($SavedSearch) {
$SearchArg->{'SavedChartSearchId'} ||= $SavedSearch;
$class = $SearchArg->{Class} if $SearchArg->{Class};
$type = 'Chart';
$customize
= RT->Config->Get('WebPath')
. '/Search/Chart.html?'
. $m->comp( '/Elements/QueryString', SavedSearchLoad => $SavedSearch );
}


Expand All @@ -153,10 +160,11 @@ if ($SavedSearch) {
}
}

$loaded_date = RT::Date->new( $session{CurrentUser} );
$loaded_date->Set( Format => 'Unix', Value => $m->{'rt_base_time'}->[0] );

if ( $SearchArg->{'SearchRefreshInterval'} ) {
$refresh_seconds = $SearchArg->{'SearchRefreshInterval'};
$loaded_date = RT::Date->new( $session{CurrentUser} );
$loaded_date->Set( Format => 'Unix', Value => $m->{'rt_base_time'}->[0] );
}

}
Expand Down Expand Up @@ -241,20 +249,41 @@ if ( exists $Override{'Rows'} ) {

my $title = loc(RT::SavedSearch->EscapeDescription($search->Description), $ProcessedSearchArg->{'Rows'});

if ( $m->request_path =~ m{^/Views/} ) {
# If the request is a manual reload from clicking the button, don't
# set the refresh trigger on that link element.
if ( $m->request_path =~ m{^/Views/} && !$m->request_args->{'Reload'} ) {
$event{triggerChanged} = 'every ' . $refresh_seconds . 's[checkRefreshState(this)]' if $refresh_seconds;
$event{widgetTitleChanged} = $title . ( $title_raw // '' );
$r->headers_out->{'HX-Trigger'} = JSON( \%event, ascii => 1, );
}

if ( $m->request_args->{'Reload'} ) {
$r->headers_out->{'HX-Trigger'} = JSON( { actionsChanged => [ loc( '[_1] reloaded', $title ) ] }, ascii => 1, );
}

my @icon_links;
push @icon_links,
{
icon_name => 'arrow-clockwise',
tooltip_text => loc('Reload'),
icon_href => '#',
htmx_get => RT->Config->Get('WebPath')
. ( $session{CurrentUser}->Privileged ? '' : '/SelfService' )
. '/Views/Component/SavedSearch?SavedSearch='
. $SavedSearch
. $htmx_query_args
. '&Reload=1',
htmx_target => '#rt-savedsearch-' . $search->Id,
htmx_indicator => '#rt-savedsearch-' . $search->Id,
};

if ( $customize ) {
push @icon_links, {
icon_name => 'gear',
tooltip_text => loc('Edit'),
icon_href => $customize
};
push @icon_links,
{
icon_name => 'gear',
tooltip_text => loc('Edit'),
icon_href => $customize,
};
}

</%init>
Expand Down
5 changes: 5 additions & 0 deletions share/html/Widgets/HTMXLoadStart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
%#
%# END BPS TAGGED BLOCK }}}
<div
% if ( $htmx_id ) {
id="<% $htmx_id %>"
% }

% if ( $htmx_get ) {
hx-get="<% $htmx_get %>"
% }
Expand All @@ -71,6 +75,7 @@ $htmx_get => undef
$htmx_post => undef
$htmx_values => undef
$htmx_params => undef
$htmx_id => ''
$show_spinner => 1
$lazy_load => 1
</%ARGS>
Expand Down
3 changes: 2 additions & 1 deletion share/html/Widgets/TitleBox
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
% }

% if ( $htmx_load ) {
<& HTMXLoadStart, htmx_get => $htmx_get, htmx_post => $htmx_post, htmx_params => $htmx_params, htmx_values => $htmx_values &>
<& HTMXLoadStart, htmx_get => $htmx_get, htmx_post => $htmx_post, htmx_params => $htmx_params, htmx_values => $htmx_values, htmx_id => $htmx_id &>
% }

<% $content | n %>
Expand All @@ -81,6 +81,7 @@ $htmx_get => undef
$htmx_post => undef
$htmx_params => undef
$htmx_values => undef
$htmx_id => undef
</%ARGS>
<%INIT>

Expand Down
12 changes: 11 additions & 1 deletion share/html/Widgets/TitleBoxStart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,17 @@
</span>
% } else {
<span class="rt-inline-icon border rounded <% $icon->{class} // '' %>" <% $icon->{modal} ? qq{data-bs-toggle="modal" data-bs-target="$icon->{modal}"} : '' |n %> >
<a class="menu-item" data-bs-toggle="tooltip" data-bs-title="<% $icon->{tooltip_text} %>"href="<% $icon->{icon_href} %>" alt="<% $icon->{tooltip_text} %>" aria-haspopup="false" aria-expanded="false"><% GetSVGImage(Name => $icon->{icon_name}) |n %></a>
<a class="menu-item" data-bs-toggle="tooltip" data-bs-title="<% $icon->{tooltip_text} %>" href="<% $icon->{icon_href} %>" alt="<% $icon->{tooltip_text} %>" aria-haspopup="false" aria-expanded="false"
% if ( $icon->{htmx_get} ) {
hx-get="<% $icon->{htmx_get} %>"
% }
% if ( $icon->{htmx_target} ) {
hx-target="<% $icon->{htmx_target} %>"
% }
% if ( $icon->{htmx_indicator} ) {
hx-indicator="<% $icon->{htmx_indicator} %>"
% }
><% GetSVGImage(Name => $icon->{icon_name}) |n %></a>
</span>
% }
% }
Expand Down

0 comments on commit f8ffcfd

Please sign in to comment.