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

how to deselect a node from controller? #220

Closed
srikarshastry opened this issue Feb 15, 2018 · 8 comments
Closed

how to deselect a node from controller? #220

srikarshastry opened this issue Feb 15, 2018 · 8 comments

Comments

@srikarshastry
Copy link

srikarshastry commented Feb 15, 2018

i was reading the documentation and did fair amount of research but could not find a way to programatically deselect a node.

My Scenario:

When user 'left click' a node, a form template needs to show up right below the value. But since it is still part of the node, when user tries to click inside the form, the "node selection" event fires again, triggering the code to select node again.

my template:

<tree [tree]="tree" #treeComponent
          (menuItemSelected)="onMenuItemSelected($event)" 
          (nodeMoved)="handleMoved($event)" 
          (nodeRenamed)="handleRenamed($event)" 
          (nodeRemoved)="handleRemoved($event)" 
          (nodeSelected)="handleSelected($event)" 
          (nodeCreated)="handleCreated($event)">
        <ng-template let-node>
            <p [ngClass]="{'wfTrigger-query': node.id === 'trigger'}" [innerHTML]="node.value"></p>
            <div class="tree-form-container" *ngIf="node.showForm">    <-------- node.showForm is the flag
                    <div class="form-group">
                        <button type="button" class="close pull-right" aria-label="Close" (click)="handleClosingContent(node)">
                            <i class="fa fa-times"></i>
                        </button>
                        <div>
                            <input type="text" id="description" name="description" class="form-control" [(ngModel)]="node.value"/>
                        </div>
                    </div>
                </div>
        </ng-template>
    </tree>

my component:

private handleSelected(e: any): void {
        if (e && e.node && e.node.node && !e.node.node.showForm) {
            e.node.node['showForm'] = true;
        }
    }

    private handleClosingContent(node: any): void {
        const oopNodeController = this.treeComponent.getControllerByNodeId(node.id);
        
        if (node && node.showForm){
            delete node['showForm'];
            oopNodeController.deselect();  // looking for something like this as the 'handleSelected' is getting called again
        }
    }

by the way, thank you so much for a flexible yet powerful tree plugin.

@rychkog
Copy link
Contributor

rychkog commented Feb 15, 2018

@Hotdog1987 Thanks!
I will have a look - this actually might be a bug

@srikarshastry
Copy link
Author

srikarshastry commented Feb 15, 2018

@rychkog Thank you for a quick look at it. Is there a workaround/hack I can try at this moment? If this is an actual bug then the fix might not be available till it is released. Correct me if I'm wrong.

Thing is, we are deep into the project that this needs to be addressed.

Thank you.

@rychkog
Copy link
Contributor

rychkog commented Feb 15, 2018

@Hotdog1987 I can add the deselect method on the weekend, also I think something like controller.disableSelection() and controller.enableSelection() might be useful. So new release will be there during the weekend.

@srikarshastry
Copy link
Author

@rychkog wow that would be awesome. Thanks alot!

@rychkog
Copy link
Contributor

rychkog commented Feb 18, 2018

@Hotdog1987 I've released a new version with an API for allowing, forbidding node selection. Though, this feature is still absent in docs (will add later). You can have a look at the API in here. I hope it is intuitive enough.
Looking forward to the feedback.

@srikarshastry
Copy link
Author

@rychkog Thank you so much for a weekend update. But, I'm little confused about the three new APIs that were introduced. We are seeking for an option to deselect a node from controller not forbidding selection. What is happening now is when I say controller.forbidSelection() everything works as it should but now the callback (nodeSelected)="handleSelected($event)" never gets triggered as it was forbidden from selection.
If I'm missing something, please let me know.

@rychkog
Copy link
Contributor

rychkog commented Feb 20, 2018

@Hotdog1987 I've released a new version - rc.8
There you can (nodeUnselected)="handleUnselected($event)" and controller.unselect(). It triggers NodeUnselectedEvent

@srikarshastry
Copy link
Author

@rychkog Thank you alot!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants