MCPcopy Create free account
hub / github.com/pgadmin-org/pgadmin4 / Tree

Class Tree

web/pgadmin/static/js/tree/tree.js:78–596  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76
77
78export class Tree {
79 constructor(tree, manageTree, pgBrowser, type) {
80 this.tree = tree;
81 this.tree.type = type || 'browser';
82 this.tree.onTreeEvents(manageTreeEvents);
83
84 this.rootNode = manageTree.tempTree;
85 this.Nodes = pgBrowser ? pgBrowser.Nodes : pgAdmin.Browser.Nodes;
86
87 // Flag to suppress added and opened tree event being called during object search operations,
88 // tree.select of search object clashes with other tree.select.
89 this.suppressEventsForPath = null;
90 this.draggableTypes = {};
91 }
92
93 async refresh(item) {
94 // Set _children to null as empty array not reload the children nodes on refresh.
95 if(item.children?.length == 0) {
96 item._children = null;
97 }
98 await this.tree.refresh(item);
99 }
100
101 async add(item, data) {
102 await this.tree.create(item.parent, data.itemData);
103 }
104
105 async before(item, data) {
106 return Promise.resolve(await this.tree.create(item.parent, data));
107 }
108
109 async update(item, data) {
110 await this.tree.update(item, data);
111 }
112
113 async remove(item) {
114 await this.tree.remove(item);
115 }
116
117 async append(item, data) {
118 return Promise.resolve(await this.tree.create(item, data));
119 }
120
121 async destroy() {
122 const model = this.tree.getModel();
123 this.rootNode.children = [];
124 if (model.root) {
125 model.root.isExpanded = false;
126 return Promise.resolve(await model.root.hardReloadChildren());
127 }
128 }
129
130 next(item) {
131 if (item) {
132 let parent = this.parent(item);
133 if (parent && parent.children.length > 0) {
134 let idx = parent.children.indexOf(item);
135 if (idx !== -1 && parent.children.length !== idx + 1) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected