Skip to content

Commit

Permalink
Remember download page settings
Browse files Browse the repository at this point in the history
Save and restore download page settings:
* filter status
* filter category
* sort field
* sort order
  • Loading branch information
elbowz committed Jan 9, 2023
1 parent 882cfda commit ca528a0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
44 changes: 35 additions & 9 deletions downloads.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,17 @@
var $inputCommand = $('input[name="command"]');
var $listDownloads = $('#list-downloads');
var $filterName = $('#filter-download-input');
var $filterStatus = $('select[name="status"]');
var $filterCategory = $('select[name="category"]');
var $sortOn = $('select[name="sort"]');
var $sortReverse = $('#sort_reverse');
var $inputSortRevrse = $('input[name="download_sort_reverse"]');

// AUTO REFRESH DOWNLOADS LIST
$filterStatus.val(mm.settings.page.downloads.filterStatus).change();
$filterCategory.val(mm.settings.page.downloads.filterCategory).change();
$sortOn.val(mm.settings.page.downloads.sortOn).change();

submitFormAndUpdate();

if (!!mm.settings.page.downloads.refreshList) {
Expand Down Expand Up @@ -191,29 +200,46 @@
$('#' + checkboxHashId).toggleClass('ui-btn-active');
});

$('select[name="status"], select[name="category"]').change(function() {
$('input[name="command"]').attr('value', 'filter');
$filterStatus.change(onFilterChange);
$filterCategory.change(onFilterChange);

function onFilterChange() {
newValue = $(this).val();
mm.settings.page.downloads.filterStatus = newValue;
mm.localStorage.set('page-downloads-filterStatus', newValue);

$inputCommand.attr('value', 'filter');
submitFormAndUpdate();
});
}

$sortOn.change(function() {
newValue = $(this).val();
mm.settings.page.downloads.sortOn = newValue;
mm.localStorage.set('page-downloads-sortOn', newValue);

$('select[name="sort"]').change(function() {
submitFormAndUpdate();
});

$('#sort_reverse').on('vclick', function(event) {
$sortReverse.on('vclick', function(event) {
event.preventDefault();

var $inputSortRevrse = $('input[name="download_sort_reverse"]');
var value = $inputSortRevrse.val();
$inputSortRevrse.val(value == '1' ? '0' : '1');
var newValue = value == '1' ? '0' : '1'
$inputSortRevrse.val(newValue);

mm.settings.page.downloads.sortOrder = newValue;
mm.localStorage.set('page-downloads-sortOrder', newValue);

submitFormAndUpdate();

$('#sort_reverse').attr({ 'data-icon': value == '1' ? 'arrow-u' : 'arrow-d' })
$(this).attr({ 'data-icon': value == '1' ? 'arrow-u' : 'arrow-d' })
.toggleClass('ui-icon-arrow-d ui-icon-arrow-u')
.text(value == '1' ? 'Descendent' : 'Ascendent');
});

if ($inputSortRevrse.val() != mm.settings.page.downloads.sortOrder) {
$sortReverse.trigger('vclick');
}

// UTILS FUNCTIONS

function formCommandSubmit(command) {
Expand Down
4 changes: 4 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ mm.settings.page.status.tickChart = _.isUndefined(mm.settings.page.status.tickCh

mm.settings.page.downloads = mm.settings.page.downloads || {};
mm.settings.page.downloads.refreshList = _.isUndefined(mm.settings.page.downloads.refreshList) ? 3000 : mm.settings.page.downloads.refreshList;
mm.settings.page.downloads.filterStatus = mm.localStorage.get('page-downloads-filterStatus', 'all');
mm.settings.page.downloads.filterCategory = mm.localStorage.get('page-downloads-filterCategory', 'all');
mm.settings.page.downloads.sortOn = mm.localStorage.get('page-downloads-sortOn', 'name');
mm.settings.page.downloads.sortOrder = mm.localStorage.get('page-downloads-sortOrder', '0');

mm.settings.page.graph = mm.settings.page.graph || {};
mm.settings.page.graph.refresh = _.isUndefined(mm.settings.page.graph.refresh) ? 3000 : mm.settings.page.graph.refresh;
Expand Down

0 comments on commit ca528a0

Please sign in to comment.