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

Improve tree node component to toggle expand collapse by click on the name/description of items #1630

Merged
merged 5 commits into from
Oct 11, 2023
Merged
Prev Previous commit
Next Next commit
Refactor to use isCollapsed property from the node
  • Loading branch information
alejandro-bulgaris-qcif committed Oct 10, 2023
commit 85dd28ca77e6b18007ea3c34d9f4abd3e5606677
25 changes: 2 additions & 23 deletions angular-legacy/shared/form/field-andsvocab.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,18 +335,6 @@ export class ANDSVocabComponent extends SimpleComponent {
that.andsTree.treeModel.setState(state);
that.andsTree.treeModel.update();
that.expandNodeIds = _.sortBy(that.expandNodeIds, (o) => { return _.isString(o) ? o.length : 0 });

//Populate a list of expanded node ids on first load based of expandNodeIds
for(let i = 0; i < that.expandNodeIds.length; i++) {
let nodeId = that.expandNodeIds[i];

//Ignore child nodes with 6 digit codes
if(nodeId.length > 4) {
continue;
}

that.treeNodeLiveStatusIDs.push({nodeId: nodeId, nodeStatus: 'exapanded'});
}
}

//Takes the first entry in expandNodeIds list and expands the node and the removed the id from the list
Expand All @@ -365,25 +353,16 @@ export class ANDSVocabComponent extends SimpleComponent {
const nodeId = _.get(nodeEvent,'id','');

//Ignore child nodes with 6 digit codes
if(nodeId.length > 4) {
if(nodeId == '' || nodeId.length > 4) {
return;
}

let nodeStatusObject = _.find(this.treeNodeLiveStatusIDs, (o: any) => { return o.nodeId == nodeId });
let nodeStatus = 'collapsed';
if(!_.isUndefined(nodeStatusObject)) {
nodeStatus = _.get(nodeStatusObject, 'nodeStatus', 'collapsed');
}
const node = this.andsTree.treeModel.getNodeById(nodeId);
if (node) {
if(nodeStatus == 'collapsed') {
if(_.get(node, 'isCollapsed', false)) {
node.expand();
_.remove(this.treeNodeLiveStatusIDs, (o: any) => { return o.nodeId == nodeId });
this.treeNodeLiveStatusIDs.push({nodeId: nodeId, nodeStatus: 'exapanded'});
} else {
node.collapse();
_.remove(this.treeNodeLiveStatusIDs, (o: any) => { return o.nodeId == nodeId });
this.treeNodeLiveStatusIDs.push({nodeId: nodeId, nodeStatus: 'collapsed'});
}
}
}
Expand Down