moribvndvs / ng2-idle

Responding to idle users in Angular (not AngularJS) applications.
https://moribvndvs.github.io/ng2-idle
Apache License 2.0
315 stars 128 forks source link

interrupt from modal ok button #59

Closed faisalloe closed 6 years ago

faisalloe commented 6 years ago

Angular4 with @ng2-idle trying to capture the inactivity of the user.

code example link https://hackedbychinese.github.io/ng2-idle/

I am trying to customize it so every time user goes idle i show modal with ok button. and user will able to resume only ok is clicked on the modal.

on page load default interrupts are on

idle.setInterrupts(DEFAULT_INTERRUPTSOURCES); 

on idleStart i show my modal and count down begins on onIdleEnd i close my modal

when modal is open i want to disable DEFAULT_INTERRUPTSOURCES only manual interrupt so i called idle.clearInterrupts() and on modal ok press event calling idle.interrupt(true); once modal is close i set idle.setInterrupts(DEFAULT_INTERRUPTSOURCES); again.

does not seems to work very well. after modal close and open again it does not car about DEFAULT_INTERRUPTSOURCES and on setIdle time it goes automiticaly idle mode even though user interacts with the UI.

moribvndvs commented 6 years ago

When configuring idle, use AutoResume.notIdle. This will allow user activity to reset the idle timer as long as they are NOT idle, which means that when they do go idle, you have to reset the idle service manually when they click OK as you requested.

You don't need to do anything extra, like modify or pause the interrupt sources. From the demo you linked, simply import the AutoResume enum and add the following line to the AppComponent constructor (or your equivalent):

idle.setAutoResume(AutoResume.notIdle);

Then in your OK button click handler, just call idle.watch().

faisalloe commented 6 years ago

awesome, great help appreciated.

nutwiss commented 6 years ago

This is perfect. Is this documented anywhere?

Thanks for all your hard work!