Skip to content

Commit

Permalink
documentar codi
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Alloza committed Feb 24, 2024
1 parent c2c6f5c commit 37aa957
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ export class EdaBlankPanelComponent implements OnInit {
});
}

/**
* When selecting a node from the tree, it loads the columns to display.
* @param event selected node. Can be rootNode (table_id) or childNode (child_id).
*/
public tableNodeSelect(event: any): void {
console.log('tableNodeSelect');
console.log(event);
Expand All @@ -237,20 +241,28 @@ export class EdaBlankPanelComponent implements OnInit {
PanelInteractionUtils.loadColumns(this, this.findTable(node.child_id.split('.')[0]), true);
}


if (node.joins) {
// Add the sourceJoins from this node. When select a column then will add this join to this column for generate the query
this.nodeJoins.push(node.joins);
}
}

console.log(this.nodeJoins)
}

/**
* Expand table relations
* @param event node to expand. Empty for nodes without more paths.
*/
public tableNodeExpand(event: any): void {
console.log('tableNodeExpand');
console.log(event);
this.loadingNodes = true;

const node = event?.node;

if (node) {
PanelInteractionUtils.expandTableNode(this, node);
}

this.loadingNodes = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ export const PanelInteractionUtils = {

console.log(ebp.currentQuery);
},


/**
* Generate the rootTree for the currentQuery columns
* @param ebp EdaBlankPanelComponent
*/
loadTableNodes: (ebp: EdaBlankPanelComponent) => {
const idTables = [...new Set(ebp.currentQuery.map((q) => q.table_id))];
const dataSource = ebp.inject.dataSource.model.tables;
Expand All @@ -88,15 +92,24 @@ export const PanelInteractionUtils = {
}
},

/**
* Find all nodes from the expanNode. expandNode can be rootNode or a childNode.
* Both have the children array property.
* @param ebp EdaBlankPanelComponent
* @param expandNode node to find all possible children nodes.
*/
expandTableNode: (ebp: EdaBlankPanelComponent, expandNode: any) => {
const dataSource = ebp.inject.dataSource.model.tables;

/** @rootNode have table_id @childNode have child_id ("table_name.column_name") */
const table_id = expandNode.table_id || expandNode.child_id.split('.')[0];

console.log(expandNode);
if (table_id) {
expandNode.children = [];

const table = dataSource.find((source) => source.table_name == table_id);


/** find all the existing childNodes found before */
const getAllChildIds = (node: any, ids: string[] = []): string[] => {
if (node.child_id) ids.push(node.child_id);

Expand All @@ -109,33 +122,41 @@ export const PanelInteractionUtils = {
const childrenId = getAllChildIds(expandNode);

for (const relation of table.relations) {
// Init child_id
const child_id = relation.target_table+'.'+relation.target_column[0];

// if (!rootTree.includes(relation.target_table) && !childrenId.includes(child_id)) {
/** Checks if the current child_node is included before.
* This prevents duplicated paths.*/
if (!rootTree.includes(relation.target_table) && !childrenId.includes(child_id)) {
// Label to show on the treeComponent
let childLabel = relation.display_name?.default
? `${relation.display_name.default} - ${relation.target_column[0]}`
: `${relation.target_table} - ${relation.target_column[0]}`;


// Check if the childNode have more possible paths to explore
let isexpandible = dataSource.find((source) => relation.target_table == source.table_name)?.relations?.length > 0;

/** This creates the path to relate this node with the previous tables.
* It will be used later to generate the query. */
let sourceJoin = relation.source_table+'.'+relation.source_column[0];
let joins = expandNode.joins ? [].concat(expandNode.joins, [[sourceJoin, child_id]]) : [[sourceJoin, child_id]];

// Init childNode object
let childNode: any = {
label: childLabel,
child_id: child_id,
joins
};

// If it's expandable, we add properties to expand the node.
if (isexpandible) {
childNode.expandedIcon = "pi pi-folder-open";
childNode.collapsedIcon = "pi pi-folder";
childNode.children = [{}];
}

// Finally add this childNode to expandNode. This will create the tree.
expandNode.children.push(childNode);
//}
}
}
}

Expand Down

0 comments on commit 37aa957

Please sign in to comment.