mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-29 19:22:57 +02:00
entity list, default column sort orders, when in default order always move empty values to bottom
This commit is contained in:
parent
66d5b16a5d
commit
ae2e85d802
1 changed files with 46 additions and 22 deletions
|
@ -44,6 +44,7 @@ const COLUMNS = {
|
||||||
initialWidth: 0.16,
|
initialWidth: 0.16,
|
||||||
initiallyShown: true,
|
initiallyShown: true,
|
||||||
alwaysShown: true,
|
alwaysShown: true,
|
||||||
|
defaultSortOrder: ASCENDING_SORT,
|
||||||
},
|
},
|
||||||
name: {
|
name: {
|
||||||
columnHeader: "Name",
|
columnHeader: "Name",
|
||||||
|
@ -51,6 +52,7 @@ const COLUMNS = {
|
||||||
initialWidth: 0.34,
|
initialWidth: 0.34,
|
||||||
initiallyShown: true,
|
initiallyShown: true,
|
||||||
alwaysShown: true,
|
alwaysShown: true,
|
||||||
|
defaultSortOrder: ASCENDING_SORT,
|
||||||
},
|
},
|
||||||
url: {
|
url: {
|
||||||
columnHeader: "File",
|
columnHeader: "File",
|
||||||
|
@ -58,6 +60,7 @@ const COLUMNS = {
|
||||||
propertyID: "url",
|
propertyID: "url",
|
||||||
initialWidth: 0.34,
|
initialWidth: 0.34,
|
||||||
initiallyShown: true,
|
initiallyShown: true,
|
||||||
|
defaultSortOrder: ASCENDING_SORT,
|
||||||
},
|
},
|
||||||
locked: {
|
locked: {
|
||||||
columnHeader: "",
|
columnHeader: "",
|
||||||
|
@ -66,6 +69,7 @@ const COLUMNS = {
|
||||||
initialWidth: 0.08,
|
initialWidth: 0.08,
|
||||||
initiallyShown: true,
|
initiallyShown: true,
|
||||||
alwaysShown: true,
|
alwaysShown: true,
|
||||||
|
defaultSortOrder: DESCENDING_SORT,
|
||||||
},
|
},
|
||||||
visible: {
|
visible: {
|
||||||
columnHeader: "",
|
columnHeader: "",
|
||||||
|
@ -74,25 +78,29 @@ const COLUMNS = {
|
||||||
initialWidth: 0.08,
|
initialWidth: 0.08,
|
||||||
initiallyShown: true,
|
initiallyShown: true,
|
||||||
alwaysShown: true,
|
alwaysShown: true,
|
||||||
|
defaultSortOrder: DESCENDING_SORT,
|
||||||
},
|
},
|
||||||
verticesCount: {
|
verticesCount: {
|
||||||
columnHeader: "Verts",
|
columnHeader: "Verts",
|
||||||
dropdownLabel: "Vertices",
|
dropdownLabel: "Vertices",
|
||||||
propertyID: "verticesCount",
|
propertyID: "verticesCount",
|
||||||
initialWidth: 0.08,
|
initialWidth: 0.08,
|
||||||
|
defaultSortOrder: DESCENDING_SORT,
|
||||||
},
|
},
|
||||||
texturesCount: {
|
texturesCount: {
|
||||||
columnHeader: "Texts",
|
columnHeader: "Texts",
|
||||||
dropdownLabel: "Textures",
|
dropdownLabel: "Textures",
|
||||||
propertyID: "texturesCount",
|
propertyID: "texturesCount",
|
||||||
initialWidth: 0.08,
|
initialWidth: 0.08,
|
||||||
|
defaultSortOrder: DESCENDING_SORT,
|
||||||
},
|
},
|
||||||
texturesSize: {
|
texturesSize: {
|
||||||
columnHeader: "Text MB",
|
columnHeader: "Text MB",
|
||||||
dropdownLabel: "Texture Size",
|
dropdownLabel: "Texture Size",
|
||||||
propertyID: "texturesSize",
|
propertyID: "texturesSize",
|
||||||
initialWidth: 0.10,
|
initialWidth: 0.10,
|
||||||
format: decimalMegabytes
|
format: decimalMegabytes,
|
||||||
|
defaultSortOrder: DESCENDING_SORT,
|
||||||
},
|
},
|
||||||
hasTransparent: {
|
hasTransparent: {
|
||||||
columnHeader: "",
|
columnHeader: "",
|
||||||
|
@ -100,6 +108,7 @@ const COLUMNS = {
|
||||||
dropdownLabel: "Transparency",
|
dropdownLabel: "Transparency",
|
||||||
propertyID: "hasTransparent",
|
propertyID: "hasTransparent",
|
||||||
initialWidth: 0.04,
|
initialWidth: 0.04,
|
||||||
|
defaultSortOrder: DESCENDING_SORT,
|
||||||
},
|
},
|
||||||
isBaked: {
|
isBaked: {
|
||||||
columnHeader: "",
|
columnHeader: "",
|
||||||
|
@ -107,12 +116,14 @@ const COLUMNS = {
|
||||||
dropdownLabel: "Baked",
|
dropdownLabel: "Baked",
|
||||||
propertyID: "isBaked",
|
propertyID: "isBaked",
|
||||||
initialWidth: 0.08,
|
initialWidth: 0.08,
|
||||||
|
defaultSortOrder: DESCENDING_SORT,
|
||||||
},
|
},
|
||||||
drawCalls: {
|
drawCalls: {
|
||||||
columnHeader: "Draws",
|
columnHeader: "Draws",
|
||||||
dropdownLabel: "Draws",
|
dropdownLabel: "Draws",
|
||||||
propertyID: "drawCalls",
|
propertyID: "drawCalls",
|
||||||
initialWidth: 0.08,
|
initialWidth: 0.08,
|
||||||
|
defaultSortOrder: DESCENDING_SORT,
|
||||||
},
|
},
|
||||||
hasScript: {
|
hasScript: {
|
||||||
columnHeader: "k",
|
columnHeader: "k",
|
||||||
|
@ -120,27 +131,10 @@ const COLUMNS = {
|
||||||
dropdownLabel: "Script",
|
dropdownLabel: "Script",
|
||||||
propertyID: "hasScript",
|
propertyID: "hasScript",
|
||||||
initialWidth: 0.06,
|
initialWidth: 0.06,
|
||||||
|
defaultSortOrder: DESCENDING_SORT,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const COMPARE_ASCENDING = function(a, b) {
|
|
||||||
let va = a[currentSortColumnID];
|
|
||||||
let vb = b[currentSortColumnID];
|
|
||||||
|
|
||||||
if (va < vb) {
|
|
||||||
return -1;
|
|
||||||
} else if (va > vb) {
|
|
||||||
return 1;
|
|
||||||
} else if (a.id < b.id) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
};
|
|
||||||
const COMPARE_DESCENDING = function(a, b) {
|
|
||||||
return COMPARE_ASCENDING(b, a);
|
|
||||||
};
|
|
||||||
|
|
||||||
const FILTER_TYPES = [
|
const FILTER_TYPES = [
|
||||||
"Shape",
|
"Shape",
|
||||||
"Model",
|
"Model",
|
||||||
|
@ -644,6 +638,10 @@ function loaded() {
|
||||||
refreshEntityList();
|
refreshEntityList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isNullOrEmpty = function(value) {
|
||||||
|
return value === undefined || value === null || value === "";
|
||||||
|
};
|
||||||
|
|
||||||
function refreshEntityList() {
|
function refreshEntityList() {
|
||||||
PROFILE("refresh-entity-list", function() {
|
PROFILE("refresh-entity-list", function() {
|
||||||
PROFILE("filter", function() {
|
PROFILE("filter", function() {
|
||||||
|
@ -660,8 +658,34 @@ function loaded() {
|
||||||
});
|
});
|
||||||
|
|
||||||
PROFILE("sort", function() {
|
PROFILE("sort", function() {
|
||||||
let cmp = currentSortOrder === ASCENDING_SORT ? COMPARE_ASCENDING : COMPARE_DESCENDING;
|
let isAscendingSort = currentSortOrder === ASCENDING_SORT;
|
||||||
visibleEntities.sort(cmp);
|
let isDefaultSort = currentSortOrder === COLUMNS[currentSortColumnID].defaultSortOrder;
|
||||||
|
visibleEntities.sort((entityA, entityB) => {
|
||||||
|
/**
|
||||||
|
* If the default sort is ascending, empty should be considered largest.
|
||||||
|
* If the default sort is descending, empty should be considered smallest.
|
||||||
|
*/
|
||||||
|
if (!isAscendingSort) {
|
||||||
|
[entityA, entityB] = [entityB, entityA];
|
||||||
|
}
|
||||||
|
let valueA = entityA[currentSortColumnID];
|
||||||
|
let valueB = entityB[currentSortColumnID];
|
||||||
|
|
||||||
|
if (valueA === valueB) {
|
||||||
|
if (entityA.id < entityB.id) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isNullOrEmpty(valueA)) {
|
||||||
|
return (isDefaultSort && isAscendingSort) ? 1 : -1;
|
||||||
|
}
|
||||||
|
if (isNullOrEmpty(valueB)) {
|
||||||
|
return (isDefaultSort && isAscendingSort) ? -1 : 1;
|
||||||
|
}
|
||||||
|
return valueA < valueB ? -1 : 1;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
PROFILE("update-dom", function() {
|
PROFILE("update-dom", function() {
|
||||||
|
@ -757,7 +781,7 @@ function loaded() {
|
||||||
} else {
|
} else {
|
||||||
elSortOrders[currentSortColumnID].innerHTML = "";
|
elSortOrders[currentSortColumnID].innerHTML = "";
|
||||||
currentSortColumnID = columnID;
|
currentSortColumnID = columnID;
|
||||||
currentSortOrder = ASCENDING_SORT;
|
currentSortOrder = COLUMNS[currentSortColumnID].defaultSortOrder;
|
||||||
}
|
}
|
||||||
refreshSortOrder();
|
refreshSortOrder();
|
||||||
refreshEntityList();
|
refreshEntityList();
|
||||||
|
|
Loading…
Reference in a new issue