SMF 2.1 : 'Browse Packages' - Remember Selected Column

Started by GL700Wing, May 17, 2022, 04:08:26 AM

Previous topic - Next topic

GL700Wing

Okay - so with my SMF 2.0 forums I've been using @Arantor's Sortable Packages (and Installed Time) mod for as long as either the mod or my forums have existed and on forums with lots of mods it's been an invaluable tool.

One of the nicest features of this mod is the fact that each time you click on 'Browse Packages' it remembers both the column you had last sorted the package list by and the sort order you had used.

Having become so used to this behaviour the fact that SMF 2.1 does not do this really bugs me (especially because I have been working on lots of mod updates lately and, depending on whether I'm installing or uninstalling a mod, I have to keep changing the selected column to either 'Mod Name' or 'Installed') - enough so that I decided to (mostly) fix it.

Note:
I haven't been able to work out how to get the saved sort order to work consistently so at this stage clicking on either the 'Package Manager' or 'Browse Packages' options will always show the last selected column in an ascending sort order. 

I am happy with just having the last selected column remembered but if someone else can also work out how to get the last saved sort order to working consistently when choosing either the 'Package Manager' or 'Browse Packages' options after changing the column sort order to descending please feel welcome to add you contribution ...

PS:  The following code saves both the last selected column and last selected sort order in the pkgMgrSort setting.

Enjoy!!


In ./Sources/Packages.php

Find:
foreach ($context['modification_types'] as $type)
{

Add After:
// Tip/Trick: Browse Packages - Remember Selected Column
global $modSettings;
$pkgMgrSort = explode(' ', (!empty($modSettings['pkgMgrSort']) ? $modSettings['pkgMgrSort'] : 'id asc'));
$sortColumn = ($pkgMgrSort[0] == 'sort_id' ? 'id' : ($pkgMgrSort[0] == 'name' ? 'mod_name' : $pkgMgrSort[0]));



Find:
'default_sort_col' => 'id' . $type,
Replace With:
// Tip/Trick: Browse Packages - Remember Selected Column
//'default_sort_col' => 'id' . $type,
'default_sort_col' => $sortColumn . $type,


Find:
if (isset($sort_id[$packageInfo['type']]) && $params == $packageInfo['type'])
{

Add After:
// Tip/Trick: Browse Packages - Remember Selected Column
global $modSettings;
$sortColumn = $sort;
$sortOrder = isset($_GET['desc']) ? 'desc' : 'asc';
$pkgMgrSort = explode(' ', (!empty($modSettings['pkgMgrSort']) ? $modSettings['pkgMgrSort'] : 'id asc'));
if ($sortColumn != $pkgMgrSort[0] || $sortOrder != $pkgMgrSort[1])
updateSettings(array('pkgMgrSort' => $sortColumn . ' ' . $sortOrder));

Life doesn't have to be perfect to be wonderful ...

Steve

Your request is done. However, your P.S. indicates it does remember the sort order when just prior to that you said it didn't consistently. Or am I reading your post wrong?
DO NOT pm me for support!

Shades.

Seems to be working fine for "Mod Name" & "Version" but not on "Installed" time...
(?action=admin;area=packages;sa=browse;type=modification;sort=time_installedmodification;desc).

Edit: Playing with it some more it only works alphabetically A-Z and not Z-A. And same for the other columns, doesn't work for ascending.

But I'm happy with A-Z! ;)
ShadesWeb.com - Custom Logos - My Themes on SMF | My Themes on ShadesWeb
https://shadesweb.com

BikerHound.com - Sniffing out the road ahead
https://bikerhound.com

Dream as if you'll live forever; Live as if you'll die today. - James Dean

GL700Wing

#3
Quote from: Steve on May 18, 2022, 01:35:22 PMYour request is done. However, your P.S. indicates it does remember the sort order when just prior to that you said it didn't consistently. Or am I reading your post wrong?
I worked out how to get the saved sort order to be used so that when either the 'Package Manager' or 'Browse Packages' options were used the list displayed as expected.

However, the problem I encountered was that if the saved sort order was descending it was necessary to click on the column title twice to change the order to ascending (after using either the 'Package Manager' or 'Browse Packages' options the URL for the column always ended in ';desc' even if the sort order was already descending).


Quote from: Shades. on May 18, 2022, 02:57:11 PMSeems to be working fine for "Mod Name" & "Version" but not on "Installed" time...
(?action=admin;area=packages;sa=browse;type=modification;sort=time_installedmodification;desc).

Edit: Playing with it some more it only works alphabetically A-Z and not Z-A. And same for the other columns, doesn't work for ascending.

But I'm happy with A-Z! ;)
Yep - when either the 'Package Manager' or 'Browse Packages' options are used it always reverts to ascending (I haven't done anything to change the column sort orders and the default sort order for the 'Installed' column shows dates from most recent to oldest).  However, if you change the sort order the sort order is saved and if you then refresh the page the saved sort order is used.

I'm still trying to find the file/code that adds ';desc' to the URL ...
Life doesn't have to be perfect to be wonderful ...

Advertisement: