Change default sort

This commit is contained in:
Rob Garrison 2018-12-30 21:02:11 -06:00
parent 218b6b41ec
commit 198315c626
2 changed files with 21 additions and 16 deletions

View File

@ -435,7 +435,7 @@
<div class="entry-col header-id"> <div class="entry-col header-id">
<a href="#" class="sortable tt-se" data-type="order" i18n-data-title="sortLabel;sortColumnInjection">#<span></span></a> <a href="#" class="sortable tt-se" data-type="order" i18n-data-title="sortLabel;sortColumnInjection">#<span></span></a>
</div> </div>
<a href="#" class="entry-col sortable header-state center-text tt-se" i18n-text="genericEnabledLabel" i18n-data-title="sortLabel;sortColumnEnabled" data-type="disabled"><span></span></a> <a href="#" class="entry-col sortable header-state center-text tt-se" i18n-text="genericEnabledLabel" i18n-data-title="sortLabel;sortColumnEnabled" data-type="enabled"><span></span></a>
<div class="entry-col header-name"> <div class="entry-col header-name">
<a href="#" class="sortable tt-se" i18n-text="genericName" i18n-data-title="sortLabel;sortColumnName" data-type="title"><span></span></a> <a href="#" class="sortable tt-se" i18n-text="genericName" i18n-data-title="sortLabel;sortColumnName" data-type="title"><span></span></a>
</div> </div>

View File

@ -35,11 +35,16 @@ const sorter = (() => {
parse: ({style}) => style.usercssData ? 0 : 1, parse: ({style}) => style.usercssData ? 0 : 1,
sorter: sorterType.number sorter: sorterType.number
}, },
disabled: { enabled: {
text: t('genericDisabledLabel'), // added as either "enabled" or "disabled" by the addOptions function text: t('genericEnabledLabel'),
parse: ({style}) => style.enabled ? 0 : 1, parse: ({style}) => style.enabled ? 0 : 1,
sorter: sorterType.number sorter: sorterType.number
}, },
disabled: {
text: t('genericDisabledLabel'),
parse: ({style}) => style.enabled ? 1 : 0,
sorter: sorterType.number
},
version: { version: {
text: '#', text: '#',
parse: ({style}) => (style.usercssData && style.usercssData.version || ''), parse: ({style}) => (style.usercssData && style.usercssData.version || ''),
@ -69,10 +74,10 @@ const sorter = (() => {
return styles; return styles;
} }
sortBy = sortBy.split(splitRegex); sortBy = sortBy.split(splitRegex);
if (sortBy.join('') === '') {
sortBy = defaultSort.split(splitRegex);
}
updateHeaders(sortBy); updateHeaders(sortBy);
// Always append an ascending title (default) sort to keep sorts consistent; but don't
// show it in the header
sortBy = sortBy.concat(defaultSort.split(splitRegex));
const len = sortBy.length; const len = sortBy.length;
return styles.sort((a, b) => { return styles.sort((a, b) => {
let types, direction, x, y; let types, direction, x, y;
@ -81,17 +86,17 @@ const sorter = (() => {
// multi-sort // multi-sort
while (result === 0 && index < len) { while (result === 0 && index < len) {
types = tagData[sortBy[index++]]; types = tagData[sortBy[index++]];
direction = sortBy[index++] === 'asc' ? 1 : -1;
x = types.parse(a); x = types.parse(a);
y = types.parse(b);
// sort empty values to the bottom // sort empty values to the bottom
if (x === '') { if (x === '') {
result = 1; return 1;
} else if (y === '') {
result = -1;
} else {
direction = sortBy[index++] === 'asc' ? 1 : -1;
result = types.sorter(x, y) * direction;
} }
y = types.parse(b);
if (y === '') {
return -1;
}
result = types.sorter(x, y) * direction;
} }
return result; return result;
}); });
@ -184,8 +189,9 @@ const sorter = (() => {
function updateColumnCount() { function updateColumnCount() {
let newValue = 1; let newValue = 1;
for (let el = document.documentElement.lastElementChild; for (let el = document.documentElement.lastElementChild;
el.localName === 'style'; el.localName === 'style';
el = el.previousElementSibling) { el = el.previousElementSibling
) {
if (el.textContent.includes('--columns:')) { if (el.textContent.includes('--columns:')) {
newValue = Math.max(1, getComputedStyle(document.documentElement).getPropertyValue('--columns') | 0); newValue = Math.max(1, getComputedStyle(document.documentElement).getPropertyValue('--columns') | 0);
break; break;
@ -199,7 +205,6 @@ const sorter = (() => {
function init() { function init() {
prefs.subscribe(['manage.newUI.sort'], update); prefs.subscribe(['manage.newUI.sort'], update);
// addOptions();
updateColumnCount(); updateColumnCount();
} }