[Rt-commit] rt branch, 4.6/sort-saved-searches, created. rt-4.4.4-46-g49f83721e

Craig Kaiser craig at bestpractical.com
Fri May 24 15:47:44 EDT 2019


The branch, 4.6/sort-saved-searches has been created
        at  49f83721e8c05dbeecfbd5e321b1ccbfa0ae538a (commit)

- Log -----------------------------------------------------------------
commit d0e492bde9f2e281b771e46f2a69a5b1825f90f2
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Thu May 23 10:17:29 2019 -0400

    Jump to unread message, if transaction is not loaded yet load it
    
    If the load history as scroll feature is enabled and a user wants to
    jump to an unread message the history leading to the unread transaction
    may need to be loaded.

diff --git a/share/html/Ticket/Elements/ScrollShowHistory b/share/html/Ticket/Elements/ScrollShowHistory
index d2aca08a8..e30f1a57f 100644
--- a/share/html/Ticket/Elements/ScrollShowHistory
+++ b/share/html/Ticket/Elements/ScrollShowHistory
@@ -77,103 +77,111 @@ my $oldestTransactionsFirst = RT->Config->Get("OldestTransactionsFirst", $sessio
 </div>
 
 <script type="text/javascript">
-jQuery(function(){
-    var isLoading = false, // prevent multiple simultaneous load events
-        disableLoading = false, // prevent repeated fruitless attempts
-        loadDistanceFromBottom = 1500, // to load before bottom of page is reached
-        lastTransactionId = null,
-        hash = window.location.hash,
-        hashTransactionId = null,
-        loadAll = false;
-
-    var oldestTransactionsFirst = <% $oldestTransactionsFirst || 0 %>;
-
-    var removeLoadingMessage = function() {
-        jQuery('.loading-message').remove();
-    };
-
-    var removeLoadLink = function() {
-        jQuery('.error-load-history').remove();
-    };
-
-    var showLoadingMessage = function() {
-        removeLoadingMessage();
-        var loadingMessage = jQuery('<span class="loading-message">' +
-            loc_key('loading') + '</span>');
-        jQuery(".history-container").append(loadingMessage);
-    };
-
-    var loadingError = function(reason) {
-        removeLoadingMessage();
-        disableLoading = true;
-        removeLoadLink();
-        var loadLink = jQuery('<div class="error-load-history">' +
-            loc_key('history_scroll_error') + ' ' + reason +
-            '<br/><a href="#">' + loc_key('try_again') + '</a></div>');
-        jQuery(".history-container").append(loadLink);
-    };
-
-    var loadHistoryPage = function() {
-        if (isLoading || disableLoading) return;
-
-        isLoading = true;
-        showLoadingMessage();
-
-        var queryString = '&oldestTransactionsFirst=' + oldestTransactionsFirst;
-        if (lastTransactionId) queryString += '&lastTransactionId=' + lastTransactionId;
-        if (loadAll) queryString += '&loadAll=1';
+var isLoading = false, // prevent multiple simultaneous load events
+    disableLoading = false, // prevent repeated fruitless attempts
+    loadDistanceFromBottom = 1500, // to load before bottom of page is reached
+    lastTransactionId = null,
+    hash = window.location.hash,
+    hashTransactionId = null,
+    loadAll = false;
+
+var oldestTransactionsFirst = <% $oldestTransactionsFirst || 0 %>;
+
+var removeLoadingMessage = function() {
+    jQuery('.loading-message').remove();
+};
+
+var removeLoadLink = function() {
+    jQuery('.error-load-history').remove();
+};
+
+var showLoadingMessage = function() {
+    removeLoadingMessage();
+    var loadingMessage = jQuery('<span class="loading-message">' +
+        loc_key('loading') + '</span>');
+    jQuery(".history-container").append(loadingMessage);
+};
+
+var loadingError = function(reason) {
+    removeLoadingMessage();
+    disableLoading = true;
+    removeLoadLink();
+    var loadLink = jQuery('<div class="error-load-history">' +
+        loc_key('history_scroll_error') + ' ' + reason +
+        '<br/><a href="#">' + loc_key('try_again') + '</a></div>');
+    jQuery(".history-container").append(loadLink);
+};
+
+function loadHistoryPage (path) {
+    if (isLoading || disableLoading) return;
+
+    if ( path ) {
+        hash = path;
+    }
+
+    isLoading = true;
+    showLoadingMessage();
+
+    var queryString = '&oldestTransactionsFirst=' + oldestTransactionsFirst;
+    if (lastTransactionId) queryString += '&lastTransactionId=' + lastTransactionId;
+    if (loadAll) queryString += '&loadAll=1';
+
+    // don't load all over and over again
+    loadAll = false;
+
+    // check for link to specific transaction and make sure we load enough to focus it
+    if (hash && !lastTransactionId) {
+        var matches = hash.match(/^#txn-(\d+)$/);
+        if (matches) {
+            hashTransactionId = matches[1];
+            queryString += '&focusTransactionId=' + hashTransactionId;
+        }
+    }
+
+    jQuery.ajax({
+        url: "<% $url |n %>" + queryString,
+        success: function(html) {
+            var transactions = jQuery(html).filter('div.transaction');
+            if(html && transactions.length) {
+                lastTransactionId = transactions.last().data('transactionId');
+                jQuery(".history-container").append(html);
+                if ( transactions.filter(':not(.hidden.end-of-history-list)').length == 0 ) {
+                    // if none is visible, automatically load more
+                    isLoading = false;
+                    loadHistoryPage();
+                    return;
+                }
 
-        // don't load all over and over again
-        loadAll = false;
+                if (hashTransactionId) { // focus transaction if we are following a link to it
+                    hashTransactionId = null;
+                    location.href = hash;
+                }
+            } else {
+                disableLoading = true;
 
-        // check for link to specific transaction and make sure we load enough to focus it
-        if (hash && !lastTransactionId) {
-            var matches = hash.match(/^#txn-(\d+)$/);
-            if (matches) {
-                hashTransactionId = matches[1];
-                queryString += '&focusTransactionId=' + hashTransactionId;
+                // hide 'Load All' link container if we're done loading
+                var loadAllHistoryContainer = jQuery('#LoadAllHistoryContainer');
+                loadAllHistoryContainer.hide();
             }
-        }
 
-        jQuery.ajax({
-            url: "<% $url |n %>" + queryString,
-            success: function(html) {
-                var transactions = jQuery(html).filter('div.transaction');
-                if(html && transactions.length) {
-                    lastTransactionId = transactions.last().data('transactionId');
-                    jQuery(".history-container").append(html);
-                    if ( transactions.filter(':not(.hidden.end-of-history-list)').length == 0 ) {
-                        // if none is visible, automatically load more
-                        isLoading = false;
-                        loadHistoryPage();
-                        return;
-                    }
-
-                    if (hashTransactionId) { // focus transaction if we are following a link to it
-                        hashTransactionId = null;
-                        location.href = hash;
-                    }
-                } else {
-                    disableLoading = true;
-
-                    // hide 'Load All' link container if we're done loading
-                    var loadAllHistoryContainer = jQuery('#LoadAllHistoryContainer');
-                    loadAllHistoryContainer.hide();
-                }
+            isLoading = false;
+            removeLoadingMessage();
 
-                isLoading = false;
-                removeLoadingMessage();
+            // make sure we load all if we clicked the "Load All" button while we were already loading
+            if (loadAll) loadHistoryPage();
 
-                // make sure we load all if we clicked the "Load All" button while we were already loading
-                if (loadAll) loadHistoryPage();
-            },
-            error: function(xhr, reason) {
-                isLoading = false;
-                loadingError(reason);
+            if ( path ) {
+                window.location.href = path;
             }
-        });
-    };
+        },
+        error: function(xhr, reason) {
+            isLoading = false;
+            loadingError(reason);
+        }
+    });
+};
 
+jQuery(function(){
     var loadAllHistory = function() {
         // hide link container
         var loadAllHistoryContainer = jQuery('#LoadAllHistoryContainer');
diff --git a/share/html/Ticket/Elements/ShowUpdateStatus b/share/html/Ticket/Elements/ShowUpdateStatus
index 9c3bc43f9..a26b3d398 100644
--- a/share/html/Ticket/Elements/ShowUpdateStatus
+++ b/share/html/Ticket/Elements/ShowUpdateStatus
@@ -52,7 +52,7 @@
 <&|/l&>There are unread messages on this ticket.</&>
 </span>
 <span class="new-messages-buttons">
-<a class="button small-button" href="<% RT->Config->Get('WebPath') ."/$DisplayPath/Display.html?id=". $Ticket->id ."#txn-" . $txn->id |n %>"><&|/l&>Jump to Unread</&></a>
+<a class="button small-button" href="<% RT->Config->Get('WebPath') ."/$DisplayPath/Display.html?id=". $Ticket->id ."#txn-" . $txn->id |n %>" onclick="loadHistoryPage('<%"#txn-" . $txn->id%>')"><&|/l&>Jump to Unread</&></a>
 <a class="button small-button" href="<% RT->Config->Get('WebPath') ."/$DisplayPath/Display.html?id=". $Ticket->id. "&MarkAsSeen=1" |n %>"><&|/l&>Mark as Seen</&></a>
 <a class="button small-button" href="<% RT->Config->Get('WebPath') ."/$DisplayPath/Display.html?id=". $Ticket->id ."&MarkAsSeen=1&Anchor=txn-" . $txn->id |n %>"><&|/l&>Jump & Mark as Seen</&></a>
 </span>

commit 49f83721e8c05dbeecfbd5e321b1ccbfa0ae538a
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Fri May 24 15:45:38 2019 -0400

    Allow saved searches to be sorted
    
    Saved searches are saved in the database as attributes meaning that the
    order by cols method usually available is not.

diff --git a/lib/RT/SavedSearches.pm b/lib/RT/SavedSearches.pm
index 224b20a24..d44b8594b 100644
--- a/lib/RT/SavedSearches.pm
+++ b/lib/RT/SavedSearches.pm
@@ -109,6 +109,23 @@ sub LimitToPrivacy {
     }
 }
 
+
+=head2 SortSavedSearches
+
+Sort the list of saved searches. The default is to sort alphabetically.
+
+=cut
+
+sub SortSavedSearches {
+    my $self = shift;
+
+    # Work directly with the internal data structure since saved searches
+    # aren't fully backed by a DB table and can't support typical OrderBy, etc.
+    my @sorted = sort { lcfirst($a->Name) cmp lcfirst($b->Name) } @{$self->{'objects'}};
+    @{$self->{'objects'}} = @sorted;
+    return;
+}
+
 RT::Base->_ImportOverlays();
 
 1;
diff --git a/share/html/Elements/SavedSearches b/share/html/Elements/SavedSearches
index 1ef131c10..9a519873e 100644
--- a/share/html/Elements/SavedSearches
+++ b/share/html/Elements/SavedSearches
@@ -49,6 +49,7 @@
 % foreach my $Object (@Objects) {
 %   my $SavedSearches = RT::SavedSearches->new($session{CurrentUser});
 %   $SavedSearches->LimitToPrivacy(join('-',ref($Object),$Object->Id),'Ticket');
+%   $SavedSearches->SortSavedSearches();
 %   my $title;
 %   if (ref $Object eq 'RT::User' && $Object->Id == $session{CurrentUser}->Id) {
 %       $title = loc("My saved searches");

-----------------------------------------------------------------------


More information about the rt-commit mailing list