Skip to content

Commit

Permalink
Improve tree node component to toggle expand collapse by click on the…
Browse files Browse the repository at this point in the history
… name/description of items (#1630)

* Add tree node exapad collapse status list

* Ignore six digit codes that don't need to expand collapse

* Refactor to use isCollapsed property from the node

* Add property to disable expand collapse toggle by name

* Add generic property to skip expand collapse event processing
  • Loading branch information
alejandro-bulgaris-qcif authored Oct 11, 2023
1 parent aba0a4d commit c319202
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions angular-legacy/shared/form/field-andsvocab.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export class ANDSVocabField extends FieldBase<any> {
public disableCheckboxRegexPattern:string;
public disableCheckboxRegexTestValue:string;
public disableCheckboxRegexCaseSensitive: boolean;
public disableExpandCollapseToggleByName: boolean;
public skipLeafNodeExpandCollapseProcessing: number;
public component:any;

constructor(options: any, injector: any) {
Expand All @@ -56,6 +58,8 @@ export class ANDSVocabField extends FieldBase<any> {
this.disableCheckboxRegexPattern = options['disableCheckboxRegexPattern'] || "";
this.disableCheckboxRegexTestValue = options['disableCheckboxRegexTestValue'] || "";
this.disableCheckboxRegexCaseSensitive = options['disableCheckboxRegexCaseSensitive'] || true;
this.disableExpandCollapseToggleByName = options['disableExpandCollapseToggleByName'] || false;
this.skipLeafNodeExpandCollapseProcessing = options['skipLeafNodeExpandCollapseProcessing'] || 4;

this.andsService = this.getFromInjector(ANDSService);
}
Expand Down Expand Up @@ -238,6 +242,7 @@ export class ANDSVocabComponent extends SimpleComponent {
}
}

//This method is called when the record edit view is first loaded and sets state and expand nodes that have checkboxes selected
protected startTreeInit() {
this.treeInitListener = Observable.interval(1000).subscribe(()=> {

Expand Down Expand Up @@ -279,6 +284,7 @@ export class ANDSVocabComponent extends SimpleComponent {
event = eventArr[1];
}
let currentState = this.getNodeSelected(event.node.id);

switch(event.eventName) {
case "nodeActivate":
if (currentState == undefined) {
Expand All @@ -296,6 +302,10 @@ export class ANDSVocabComponent extends SimpleComponent {
this.updateSingleNodeSelectedState(event.node, false);
break;
}

if(!this.field.disableExpandCollapseToggleByName) {
this.expandCollapseNode(event.node);
}
}

protected updateSingleNodeSelectedState(node, state) {
Expand All @@ -315,6 +325,7 @@ export class ANDSVocabComponent extends SimpleComponent {
this.nodeEventSubject.next(event);
}

//This method is called when the record edit view is first loaded populates expandNodeIds list
public updateTreeView(that) {
const state = that.andsTree.treeModel.getState();
that.expandNodeIds = [];
Expand All @@ -331,6 +342,7 @@ export class ANDSVocabComponent extends SimpleComponent {
that.expandNodeIds = _.sortBy(that.expandNodeIds, (o) => { return _.isString(o) ? o.length : 0 });
}

//Takes the first entry in expandNodeIds list and expands the node and the removed the id from the list
protected expandNodes() {
if (!_.isEmpty(this.expandNodeIds)) {
const parentId = this.expandNodeIds[0];
Expand All @@ -342,6 +354,24 @@ export class ANDSVocabComponent extends SimpleComponent {
}
}

protected expandCollapseNode(nodeEvent: any) {
const nodeId = _.get(nodeEvent,'id','');

//Ignore expand collapse processing if id string value has length that exceeds default
if(nodeId == '' || nodeId.length > this.field.skipLeafNodeExpandCollapseProcessing) {
return;
}

const node = this.andsTree.treeModel.getNodeById(nodeId);
if (node) {
if(_.get(node, 'isCollapsed', false)) {
node.expand();
} else {
node.collapse();
}
}
}

protected collapseNodes() {
this.andsTree.treeModel.collapseAll();
}
Expand Down

0 comments on commit c319202

Please sign in to comment.