Fix entity list not handling deleted entities

This commit is contained in:
Ryan Huffman 2018-09-07 10:35:41 -07:00
parent 335f66d165
commit 9b9785d250

View file

@ -34,9 +34,6 @@ const COMPARE_DESCENDING = function(a, b) {
return COMPARE_ASCENDING(b, a); return COMPARE_ASCENDING(b, a);
} }
//console.log = function() { };
// List of all entities // List of all entities
let entities = [] let entities = []
@ -49,7 +46,7 @@ var selectedEntities = [];
var currentSortColumn = 'type'; var currentSortColumn = 'type';
var currentSortOrder = ASCENDING_SORT; var currentSortOrder = ASCENDING_SORT;
const ENABLE_PROFILING = true; const ENABLE_PROFILING = false;
var profileIndent = ''; var profileIndent = '';
const PROFILE = !ENABLE_PROFILING ? function() { } : function(name, fn, args) { const PROFILE = !ENABLE_PROFILING ? function() { } : function(name, fn, args) {
console.log("PROFILE-Web " + profileIndent + "(" + name + ") Begin"); console.log("PROFILE-Web " + profileIndent + "(" + name + ") Begin");
@ -62,10 +59,6 @@ const PROFILE = !ENABLE_PROFILING ? function() { } : function(name, fn, args) {
console.log("PROFILE-Web " + profileIndent + "(" + name + ") End " + delta + "ms"); console.log("PROFILE-Web " + profileIndent + "(" + name + ") End " + delta + "ms");
}; };
debugPrint = function (message) {
console.log(message);
};
function loaded() { function loaded() {
openEventBridge(function() { openEventBridge(function() {
elEntityTable = document.getElementById("entity-table"); elEntityTable = document.getElementById("entity-table");
@ -127,7 +120,6 @@ function loaded() {
function onRowClicked(clickEvent) { function onRowClicked(clickEvent) {
let entityID = this.dataset.entityID; let entityID = this.dataset.entityID;
console.log("CLICKED", entityID, this);
let selection = [entityID]; let selection = [entityID];
if (clickEvent.ctrlKey) { if (clickEvent.ctrlKey) {
let selectedIndex = selectedEntities.indexOf(entityID); let selectedIndex = selectedEntities.indexOf(entityID);
@ -212,7 +204,6 @@ function loaded() {
// Update the entity list with the new set of data sent from edit.js // Update the entity list with the new set of data sent from edit.js
function updateEntityList(entityData) { function updateEntityList(entityData) {
console.warn("updating entity list");
const IMAGE_MODEL_NAME = 'default-image-model.fbx'; const IMAGE_MODEL_NAME = 'default-image-model.fbx';
entities = [] entities = []
@ -291,13 +282,11 @@ function loaded() {
function refreshEntityList() { function refreshEntityList() {
PROFILE("refresh-entity-list", function() { PROFILE("refresh-entity-list", function() {
console.warn("refreshing entity list");
PROFILE("filter", function() { PROFILE("filter", function() {
let searchTerm = elFilter.value; let searchTerm = elFilter.value;
if (searchTerm === '') { if (searchTerm === '') {
visibleEntities = entities.slice(0); visibleEntities = entities.slice(0);
} else { } else {
console.log("Filtering on: ", searchTerm);
visibleEntities = entities.filter(function(e) { visibleEntities = entities.filter(function(e) {
return e.name.indexOf(searchTerm) > -1 return e.name.indexOf(searchTerm) > -1
|| e.type.indexOf(searchTerm) > -1 || e.type.indexOf(searchTerm) > -1
@ -308,7 +297,6 @@ function loaded() {
PROFILE("sort", function() { PROFILE("sort", function() {
let cmp = currentSortOrder === ASCENDING_SORT ? COMPARE_ASCENDING : COMPARE_DESCENDING; let cmp = currentSortOrder === ASCENDING_SORT ? COMPARE_ASCENDING : COMPARE_DESCENDING;
console.log("Doing sort", currentSortColumn, currentSortOrder);
visibleEntities.sort(cmp); visibleEntities.sort(cmp);
}); });
@ -322,16 +310,27 @@ function loaded() {
} }
function removeEntities(deletedIDs) { function removeEntities(deletedIDs) {
return; // Loop from the back so we can pop items off while iterating
for (i = 0, length = deletedIDs.length; i < length; i++) { for (let j = entities.length - 1; j >= 0; --j) {
let id = deletedIDs[i]; let id = entities[j];
entities[id].el.remove(); for (let i = 0, length = deletedIDs.length; i < length; ++i) {
delete entities[id]; if (id === deletedIDs[i]) {
entities.splice(j, 1);
entitiesByID[id].el.remove();
delete entitiesByID[id];
break;
}
}
} }
refreshEntities();
} }
function clearEntities() { function clearEntities() {
entities = {}; entities = []
entitiesByID = {};
visibleEntities = [];
elEntityTableBody.innerHTML = '';
refreshFooter(); refreshFooter();
} }
@ -351,14 +350,14 @@ function loaded() {
} }
function setSortColumn(column) { function setSortColumn(column) {
PROFILE("set-sort-column", function() { PROFILE("set-sort-column", function() {
if (currentSortColumn == column) { if (currentSortColumn === column) {
currentSortOrder *= -1; currentSortOrder *= -1;
} else { } else {
elSortOrder[currentSortColumn].innerHTML = ""; elSortOrder[currentSortColumn].innerHTML = "";
currentSortColumn = column; currentSortColumn = column;
currentSortOrder = ASCENDING_SORT; currentSortOrder = ASCENDING_SORT;
} }
elSortOrder[column].innerHTML = currentSortOrder == ASCENDING_SORT ? ASCENDING_STRING : DESCENDING_STRING; elSortOrder[column].innerHTML = currentSortOrder === ASCENDING_SORT ? ASCENDING_STRING : DESCENDING_STRING;
refreshEntityList(); refreshEntityList();
}); });
} }
@ -485,11 +484,8 @@ function loaded() {
elFooter.firstChild.nodeValue = "0 entities found"; elFooter.firstChild.nodeValue = "0 entities found";
} else if (newEntities) { } else if (newEntities) {
elNoEntitiesMessage.style.display = "none"; elNoEntitiesMessage.style.display = "none";
//entityData = newEntities;
updateEntityList(newEntities); updateEntityList(newEntities);
//refreshEntityList();
updateSelectedEntities(data.selectedIDs); updateSelectedEntities(data.selectedIDs);
//resize();
} }
}); });
} else if (data.type === "removeEntities" && data.deletedIDs !== undefined && data.selectedIDs !== undefined) { } else if (data.type === "removeEntities" && data.deletedIDs !== undefined && data.selectedIDs !== undefined) {