making rename functionality list refresh proof

This commit is contained in:
Thijs Wenker 2018-11-16 20:02:16 +01:00
parent 31d37e7e75
commit e89346c146
3 changed files with 48 additions and 7 deletions

View file

@ -187,6 +187,7 @@ let startThClick = null;
let renameTimeout = null; let renameTimeout = null;
let renameLastBlur = null; let renameLastBlur = null;
let renameLastEntityID = null; let renameLastEntityID = null;
let isRenameFieldIsBeingMoved = false;
let elEntityTable, let elEntityTable,
elEntityTableHeader, elEntityTableHeader,
@ -210,7 +211,8 @@ let elEntityTable,
elNoEntitiesMessage, elNoEntitiesMessage,
elColumnsMultiselectBox, elColumnsMultiselectBox,
elColumnsOptions, elColumnsOptions,
elToggleSpaceMode; elToggleSpaceMode,
elRenameInput;
const ENABLE_PROFILING = false; const ENABLE_PROFILING = false;
let profileIndent = ''; let profileIndent = '';
@ -395,7 +397,7 @@ function loaded() {
elEntityTableHeaderRow = document.querySelectorAll("#entity-table thead th"); elEntityTableHeaderRow = document.querySelectorAll("#entity-table thead th");
entityList = new ListView(elEntityTableBody, elEntityTableScroll, elEntityTableHeaderRow, entityList = new ListView(elEntityTableBody, elEntityTableScroll, elEntityTableHeaderRow,
createRow, updateRow, clearRow, WINDOW_NONVARIABLE_HEIGHT); createRow, updateRow, clearRow, beforeUpdate, afterUpdate, WINDOW_NONVARIABLE_HEIGHT);
entityListContextMenu = new EntityListContextMenu(); entityListContextMenu = new EntityListContextMenu();
@ -407,7 +409,7 @@ function loaded() {
} }
let elCell = entity.elRow.childNodes[getColumnIndex("name")]; let elCell = entity.elRow.childNodes[getColumnIndex("name")];
let elRenameInput = document.createElement("input"); elRenameInput = document.createElement("input");
elRenameInput.setAttribute('class', 'rename-entity'); elRenameInput.setAttribute('class', 'rename-entity');
elRenameInput.value = entity.name; elRenameInput.value = entity.name;
let ignoreClicks = function(event) { let ignoreClicks = function(event) {
@ -422,6 +424,9 @@ function loaded() {
}; };
elRenameInput.onblur = function(event) { elRenameInput.onblur = function(event) {
if (isRenameFieldIsBeingMoved) {
return;
}
let value = elRenameInput.value; let value = elRenameInput.value;
EventBridge.emitWebEvent(JSON.stringify({ EventBridge.emitWebEvent(JSON.stringify({
type: 'rename', type: 'rename',
@ -429,9 +434,10 @@ function loaded() {
name: value name: value
})); }));
entity.name = value; entity.name = value;
elCell.innerText = value; elRenameInput.parentElement.innerText = value;
renameLastBlur = Date.now(); renameLastBlur = Date.now();
elRenameInput = null;
}; };
elCell.innerHTML = ""; elCell.innerHTML = "";
@ -440,6 +446,32 @@ function loaded() {
elRenameInput.select(); elRenameInput.select();
} }
function beforeUpdate() {
// move the rename input to the body
if (elRenameInput) {
isRenameFieldIsBeingMoved = true;
document.body.appendChild(elRenameInput);
// keep the focus
elRenameInput.select();
}
}
function afterUpdate() {
if (!elRenameInput || !isRenameFieldIsBeingMoved) {
return;
}
let entity = entitiesByID[renameLastEntityID];
if (!entity || entity.locked || !entity.elRow) {
return;
}
let elCell = entity.elRow.childNodes[getColumnIndex("name")];
elCell.innerHTML = "";
elCell.appendChild(elRenameInput);
// keep the focus
elRenameInput.select();
isRenameFieldIsBeingMoved = false;
}
entityListContextMenu.setOnSelectedCallback(function(optionName, selectedEntityID) { entityListContextMenu.setOnSelectedCallback(function(optionName, selectedEntityID) {
switch (optionName) { switch (optionName) {
case "Cut": case "Cut":
@ -464,6 +496,11 @@ function loaded() {
}); });
function onRowContextMenu(clickEvent) { function onRowContextMenu(clickEvent) {
if (elRenameInput) {
// disallow the context menu from popping up while renaming
return;
}
let entityID = this.dataset.entityID; let entityID = this.dataset.entityID;
if (!selectedEntities.includes(entityID)) { if (!selectedEntities.includes(entityID)) {

View file

@ -14,7 +14,7 @@ debugPrint = function (message) {
}; };
function ListView(elTableBody, elTableScroll, elTableHeaderRow, createRowFunction, function ListView(elTableBody, elTableScroll, elTableHeaderRow, createRowFunction,
updateRowFunction, clearRowFunction, WINDOW_NONVARIABLE_HEIGHT) { updateRowFunction, clearRowFunction, beforeRefreshFunction, afterRefreshFunction, WINDOW_NONVARIABLE_HEIGHT) {
this.elTableBody = elTableBody; this.elTableBody = elTableBody;
this.elTableScroll = elTableScroll; this.elTableScroll = elTableScroll;
this.elTableHeaderRow = elTableHeaderRow; this.elTableHeaderRow = elTableHeaderRow;
@ -25,6 +25,8 @@ function ListView(elTableBody, elTableScroll, elTableHeaderRow, createRowFunctio
this.createRowFunction = createRowFunction; this.createRowFunction = createRowFunction;
this.updateRowFunction = updateRowFunction; this.updateRowFunction = updateRowFunction;
this.clearRowFunction = clearRowFunction; this.clearRowFunction = clearRowFunction;
this.beforeRefreshFunction = beforeRefreshFunction;
this.afterRefreshFunction = afterRefreshFunction;
// the list of row elements created in the table up to max viewable height plus SCROLL_ROWS rows for scrolling buffer // the list of row elements created in the table up to max viewable height plus SCROLL_ROWS rows for scrolling buffer
this.elRows = []; this.elRows = [];
@ -173,6 +175,7 @@ ListView.prototype = {
}, },
refresh: function() { refresh: function() {
this.beforeRefreshFunction();
// block refreshing before rows are initialized // block refreshing before rows are initialized
let numRows = this.getNumRows(); let numRows = this.getNumRows();
if (numRows === 0) { if (numRows === 0) {
@ -211,6 +214,7 @@ ListView.prototype = {
this.lastRowShiftScrollTop = 0; this.lastRowShiftScrollTop = 0;
} }
} }
this.afterRefreshFunction();
}, },
refreshBuffers: function() { refreshBuffers: function() {
@ -230,7 +234,7 @@ ListView.prototype = {
refreshRowOffset: function() { refreshRowOffset: function() {
// make sure the row offset isn't causing visible rows to pass the end of the item list and is clamped to 0 // make sure the row offset isn't causing visible rows to pass the end of the item list and is clamped to 0
var numRows = this.getNumRows(); let numRows = this.getNumRows();
if (this.rowOffset + numRows > this.itemData.length) { if (this.rowOffset + numRows > this.itemData.length) {
this.rowOffset = this.itemData.length - numRows; this.rowOffset = this.itemData.length - numRows;
} }

View file

@ -17,7 +17,7 @@ var profileIndent = '';
const PROFILE_NOOP = function(_name, fn, args) { const PROFILE_NOOP = function(_name, fn, args) {
fn.apply(this, args); fn.apply(this, args);
}; };
PROFILE = !PROFILING_ENABLED ? PROFILE_NOOP : function(name, fn, args) { const PROFILE = !PROFILING_ENABLED ? PROFILE_NOOP : function(name, fn, args) {
console.log("PROFILE-Script " + profileIndent + "(" + name + ") Begin"); console.log("PROFILE-Script " + profileIndent + "(" + name + ") Begin");
var previousIndent = profileIndent; var previousIndent = profileIndent;
profileIndent += ' '; profileIndent += ' ';