Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

treeview: handle custom previews #10990

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions browser/src/control/Control.JSDialogBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -2892,6 +2892,8 @@ L.Control.JSDialogBuilder = L.Control.extend({

if (typeof control.updateRenders == 'function')
control.updateRenders(data.pos);
else
console.error('widget doesn\'t support custom entries');

break;

Expand Down
4 changes: 4 additions & 0 deletions browser/src/control/jsdialog/Definitions.Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ type JSDialogCallback = (
builder: any,
) => void;

// callback triggered for custom rendered entries
type CustomEntryRenderCallback = (pos: number | string) => void;

// used to define menus
type MenuDefinition = {
id: string; // unique identifier
Expand Down Expand Up @@ -128,6 +131,7 @@ interface TreeColumnJSON {
link?: string;
collapsed?: string | boolean;
expanded?: string | boolean;
customEntryRenderer?: boolean; // has custome rendering enabled
collapsedimage?: string;
expandedimage?: string;
}
Expand Down
79 changes: 58 additions & 21 deletions browser/src/control/jsdialog/Widget.TreeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,29 +78,11 @@ class TreeViewControl {
_filterTimer: ReturnType<typeof setTimeout>;

constructor(data: TreeWidgetJSON, builder: any) {
this._isRealTree = this.isRealTree(data);
this._container = L.DomUtil.create(
'div',
builder.options.cssClass + ' ui-treeview',
);
this._container.id = data.id;
this._columns = TreeViewControl.countColumns(data);
this._hasState = TreeViewControl.hasState(data);
this._hasIcon = TreeViewControl.hasIcon(data);
this._isNavigator = this.isNavigator(data);
this._singleClickActivate = TreeViewControl.isSingleClickActivate(data);

this._tbody = this._container;
(this._container as any).filterEntries = this.filterEntries.bind(this);

this.setupDragAndDrop(data, builder);
this.setupKeyEvents(data, builder);

if (this._isRealTree) {
this._container.setAttribute('role', 'treegrid');
if (!data.headers || data.headers.length === 0)
L.DomUtil.addClass(this._container, 'ui-treeview-tree');
} else this._container.setAttribute('role', 'grid');
}

get Container() {
Expand Down Expand Up @@ -475,6 +457,7 @@ class TreeViewControl {
}

createTextCell(
treeViewData: TreeWidgetJSON,
parent: HTMLElement,
entry: TreeEntryJSON,
index: any,
Expand All @@ -486,6 +469,18 @@ class TreeViewControl {
parent,
);
cell.innerText = entry.columns[index].text || entry.text;

if (entry.columns[index].customEntryRenderer) {
JSDialog.OnDemandRenderer(
builder,
treeViewData.id,
'treeview',
entry.row,
cell,
parent,
entry.text,
);
}
}

createLinkCell(
Expand Down Expand Up @@ -573,7 +568,7 @@ class TreeViewControl {
entry.columns[index].text &&
!this.isSeparator(entry.columns[index])
) {
this.createTextCell(text, entry, index, builder);
this.createTextCell(treeViewData, text, entry, index, builder);
}

// row sub-elements
Expand Down Expand Up @@ -1246,12 +1241,29 @@ class TreeViewControl {
}

build(data: TreeWidgetJSON, builder: any, parentContainer: HTMLElement) {
this._isRealTree = this.isRealTree(data);
this._columns = TreeViewControl.countColumns(data);
this._hasState = TreeViewControl.hasState(data);
this._hasIcon = TreeViewControl.hasIcon(data);
this._isNavigator = this.isNavigator(data);
this._singleClickActivate = TreeViewControl.isSingleClickActivate(data);

this._tbody = this._container;
(this._container as any).filterEntries = this.filterEntries.bind(this);

this.setupDragAndDrop(data, builder);
this.setupKeyEvents(data, builder);

if (this._isRealTree) {
this._container.setAttribute('role', 'treegrid');
if (!data.headers || data.headers.length === 0)
L.DomUtil.addClass(this._container, 'ui-treeview-tree');
} else this._container.setAttribute('role', 'grid');

this.preprocessColumnData(data.entries);
this.fillHeaders(data.headers, builder);
this.fillEntries(data, data.entries, builder, 1, this._tbody);

parentContainer.appendChild(this._container);

return true;
}
}
Expand All @@ -1263,6 +1275,31 @@ JSDialog.treeView = function (
) {
var treeView = new TreeViewControl(data, builder);
treeView.build(data, builder, parentContainer);
parentContainer.appendChild(treeView._container);

const updateRenders: CustomEntryRenderCallback = (pos: number | string) => {
const row = treeView.findEntryWithRow(data.entries, pos);
if (!row) {
console.error('treeview updateRenders: row "' + pos + '" not found');
return;
}

const image = builder.rendersCache[data.id].images[pos];
if (!image) {
console.error(
'treeview updateRenders: image for row "' + pos + '" not found',
);
return;
}

row.columns[row.columns.length > 1 ? 1 : 0].collapsedimage = image;
row.columns[row.columns.length > 1 ? 1 : 0].expandedimage = image;

treeView._container.innerHTML = '';
treeView.build(data, builder, parentContainer);
};

(treeView._container as any).updateRenders = updateRenders;

return false;
};
Expand Down
Loading