From bcebb6e7e6e65aa0265343915aa89ee07630ef91 Mon Sep 17 00:00:00 2001 From: Philip Bjorge Date: Tue, 19 Jan 2016 21:42:44 -0800 Subject: [PATCH 1/9] Update angular-idle typings for 1.1.1 --- angular-idle/angular-idle.d.ts | 58 ++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/angular-idle/angular-idle.d.ts b/angular-idle/angular-idle.d.ts index 4e1e98fb5..95489f53a 100644 --- a/angular-idle/angular-idle.d.ts +++ b/angular-idle/angular-idle.d.ts @@ -1,4 +1,4 @@ -// Type definitions for ng-idle v0.3.5 +// Type definitions for ng-idle v1.1.1 // Project: http://hackedbychinese.github.io/ng-idle/ // Definitions by: mthamil // Definitions: https://github.com/borisyankov/DefinitelyTyped @@ -8,7 +8,7 @@ declare module angular.idle { /** - * Used to configure the $keepalive service. + * Used to configure the Keepalive service. */ interface IKeepAliveProvider extends IServiceProvider { @@ -18,9 +18,9 @@ declare module angular.idle { * You can specify a string, which it will assume to be a URL to a simple GET request. * Otherwise, you can use the same options $http takes. However, cache will always be false. * - * @param value May be string or object, default is null. + * @param value May be string or IRequestConfig, default is null. */ - http(value: any): void; + http(value: string | IRequestConfig): void; /** * This specifies how often the keepalive event is triggered and the @@ -32,10 +32,10 @@ declare module angular.idle { } /** - * $keepalive will use a timeout to periodically wake, broadcast a $keepalive event on the root scope, - * and optionally make an $http request. By default, the $idle service will stop and start $keepalive + * Keepalive will use a timeout to periodically wake, broadcast a Keepalive event on the root scope, + * and optionally make an $http request. By default, the Idle service will stop and start Keepalive * when a user becomes idle or returns from idle, respectively. It is also started automatically when - * $idle.watch() is called. This can be disabled by configuring the $idleProvider. + * Idle.watch() is called. This can be disabled by configuring the IdleProvider. */ interface IKeepAliveService { @@ -56,17 +56,16 @@ declare module angular.idle { } /** - * Used to configure the $idle service. + * Used to configure the Idle service. */ interface IIdleProvider extends IServiceProvider { - /** * Specifies the DOM events the service will watch to reset the idle timeout. * Multiple events should be separated by a space. * * @param events string, default 'mousemove keydown DOMMouseScroll mousewheel mousedown' */ - activeOn(events: string): void; + interrupt(events: string): void; /** * The idle timeout duration in seconds. After this amount of time passes without the user @@ -75,7 +74,7 @@ declare module angular.idle { * * @param seconds integer, default is 20min */ - idleDuration(seconds: number): void; + idle(seconds: number): void; /** * The amount of time the user has to respond (in seconds) before they have been considered @@ -83,7 +82,7 @@ declare module angular.idle { * * @param seconds integer, default is 30s */ - warningDuration(seconds: number): void; + timeout(seconds: number): void; /** * When true, user activity will automatically interrupt the warning countdown and reset the @@ -95,7 +94,7 @@ declare module angular.idle { autoResume(enabled: boolean): void; /** - * When true, the $keepalive service is automatically stopped and started as needed. + * When true, the Keepalive service is automatically stopped and started as needed. * * @param enabled boolean, default is true */ @@ -103,13 +102,39 @@ declare module angular.idle { } /** - * $idle, once watch() is called, will start a timeout which if expires, will enter a warning state + * Idle, once watch() is called, will start a timeout which if expires, will enter a warning state * countdown. Once the countdown reaches zero, idle will broadcast a timeout event indicating the * user has timed out (where your app should log them out or whatever you like). If the user performs * an action that triggers a watched DOM event that bubbles up to document.body, this will reset the * idle/warning state and start the process over again. */ interface IIdleService { + /** + * Gets the current idle value + */ + getIdle(): number; + + /** + * Gets the current timeout value + */ + getTimeout(): number; + + /** + * Updates the idle value (see IdleProvider.idle()) and + * restarts the watch if its running. + */ + setIdle(): void; + + /** + * Updates the timeout value (see IdleProvider.timeout()) and + * restarts the watch if its running. + */ + setTimeout(): void; + + /** + * Whether user has timed out (meaning idleDuration + timeout has passed without any activity) + */ + isExpired(): boolean; /** * Whether or not the watch() has been called and it is watching for idleness. @@ -130,5 +155,10 @@ declare module angular.idle { * Stops watching for idleness, and resets the idle/warning state. */ unwatch(): void; + + /** + * Manually trigger the idle interrupt that normally occurs during user activity. + */ + interrupt(): any; } } From ae814b634b23763ebb75a16c0bb3fbe970e31625 Mon Sep 17 00:00:00 2001 From: Philip Bjorge Date: Tue, 19 Jan 2016 21:54:58 -0800 Subject: [PATCH 2/9] Update tests --- angular-idle/angular-idle-tests.ts | 48 +++++++++++++++++++----------- angular-idle/angular-idle.d.ts | 4 +-- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/angular-idle/angular-idle-tests.ts b/angular-idle/angular-idle-tests.ts index fc39bf72a..c442d4370 100644 --- a/angular-idle/angular-idle-tests.ts +++ b/angular-idle/angular-idle-tests.ts @@ -1,23 +1,37 @@ /// angular.module('app', ['ngIdle']) - .config(['$keepaliveProvider', '$idleProvider', - ($keepaliveProvider: ng.idle.IKeepAliveProvider, $idleProvider: ng.idle.IIdleProvider) => { - $idleProvider.activeOn('mousemove keydown DOMMouseScroll mousewheel mousedown'); - $idleProvider.idleDuration(5); - $idleProvider.warningDuration(5); - $idleProvider.keepalive(true) - $idleProvider.autoResume(true); - $keepaliveProvider.interval(10); + .config(['KeepaliveProvider', 'IdleProvider', + (keepaliveProvider: ng.idle.IKeepAliveProvider, idleProvider: ng.idle.IIdleProvider) => { + idleProvider.interrupt('mousemove keydown DOMMouseScroll mousewheel mousedown'); + idleProvider.idle(5); + idleProvider.timeout(5); + idleProvider.keepalive(true) + idleProvider.autoResume(true); + + const config: ng.IRequestConfig = { + url: "http://google.com", + method: "GET" + }; + + keepaliveProvider.http(config.url); // should accept string and ng.IRequestConfig + keepaliveProvider.http(config); + keepaliveProvider.interval(10); }]) - .run(['$keepalive', '$idle', ($keepalive: ng.idle.IKeepAliveService, $idle: ng.idle.IIdleService) => { - $idle.watch(); - - if ($idle.running() || $idle.idling()) { - $idle.unwatch(); + .run(['Keepalive', 'Idle', (Keepalive: ng.idle.IKeepAliveService, Idle: ng.idle.IIdleService) => { + Idle.setTimeout(Idle.getTimeout()); + Idle.setIdle(Idle.getIdle()); + + Idle.watch(); + Idle.interrupt(); + + const expired: boolean = Idle.isExpired(); + + if (Idle.running() || Idle.idling()) { + Idle.unwatch(); } - - $keepalive.start(); - $keepalive.ping(); - $keepalive.stop(); + + Keepalive.start(); + Keepalive.ping(); + Keepalive.stop(); }]); \ No newline at end of file diff --git a/angular-idle/angular-idle.d.ts b/angular-idle/angular-idle.d.ts index 95489f53a..abdc1e993 100644 --- a/angular-idle/angular-idle.d.ts +++ b/angular-idle/angular-idle.d.ts @@ -123,13 +123,13 @@ declare module angular.idle { * Updates the idle value (see IdleProvider.idle()) and * restarts the watch if its running. */ - setIdle(): void; + setIdle(idle: number): void; /** * Updates the timeout value (see IdleProvider.timeout()) and * restarts the watch if its running. */ - setTimeout(): void; + setTimeout(timeout: number): void; /** * Whether user has timed out (meaning idleDuration + timeout has passed without any activity) From cdb35b399643f70a9215f4a2f7f14176ef4c979c Mon Sep 17 00:00:00 2001 From: Philip Bjorge Date: Tue, 19 Jan 2016 22:08:28 -0800 Subject: [PATCH 3/9] Add Title service to angular-idle --- angular-idle/angular-idle.d.ts | 92 ++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/angular-idle/angular-idle.d.ts b/angular-idle/angular-idle.d.ts index abdc1e993..fc7729f27 100644 --- a/angular-idle/angular-idle.d.ts +++ b/angular-idle/angular-idle.d.ts @@ -7,6 +7,98 @@ declare module angular.idle { + /** + * Used to configure the Title service. + */ + interface ITitleProvider extends IServiceProvider { + + /** + * Enables or disables the Title functionality. + * + * @param enabled Boolean, default is true. + */ + enabled(enabled: boolean): void; + } + + interface ITitleService { + + /** + * Allows the title functionality to be enabled or disabled on the fly. + */ + setEnabled(enabled: boolean): void; + + /** + * Returns whether or not the title functionality has been enabled. + */ + isEnabled(): boolean; + + /** + * Will store val as the "original" title of the document. + * + * Tracking the original title is important when restoring the title after displaying, for example, the idle warning message. + */ + original(val: string): void; + + /** + * Returns the "original" title value that has been previously set. + * + * Tracking the original title is important when restoring the title after displaying, for example, the idle warning message. + */ + original(): string; + + /** + * Changes the actual title of the document. + */ + value(val: string): void; + + /** + * Returns the current document title. + */ + value(): string; + + /** + * If overwrite is false or unspecified, updates the "original" title with the current document title + * if it has not already been stored. If overwrite is true, the current document title is stored regardless. + */ + store(overwrite: boolean): void; + + /** + * Sets the title to the original value (if it was stored or set previously). + */ + restore(): void; + + /** + * Sets the text to use as the message displayed when the user is idle. + */ + idleMessage(val: string): void; + + /** + * Gets the text to use as the message displayed when the user is idle. + */ + idleMessage(): string; + + /** + * Sets the text to use as the message displayed when the user is timed out. + */ + timedOutMessage(val: string): void; + + /** + * Gets the text to use as the message displayed when the user is timed out. + */ + timedOutMessage(): string; + + /** + * Stores the original title if it hasn't been already, determines the number minutes, seconds, + * and total seconds from countdown, and displays the idleMessage with the aforementioned values interpolated. + */ + setAsIdle(countdown: number): void; + + /** + * Stores the original title if it hasn't been already, and displays the timedOutMessage. + */ + setAsTimedOut(); + } + /** * Used to configure the Keepalive service. */ From 23a59921f3433d741bcb6d947a74403e8447267b Mon Sep 17 00:00:00 2001 From: Philip Bjorge Date: Tue, 19 Jan 2016 22:14:00 -0800 Subject: [PATCH 4/9] Add tests for angular idle Title Service --- angular-idle/angular-idle-tests.ts | 19 ++++++++++++++++--- angular-idle/angular-idle.d.ts | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/angular-idle/angular-idle-tests.ts b/angular-idle/angular-idle-tests.ts index c442d4370..74af16c02 100644 --- a/angular-idle/angular-idle-tests.ts +++ b/angular-idle/angular-idle-tests.ts @@ -1,8 +1,9 @@ /// angular.module('app', ['ngIdle']) - .config(['KeepaliveProvider', 'IdleProvider', - (keepaliveProvider: ng.idle.IKeepAliveProvider, idleProvider: ng.idle.IIdleProvider) => { + .config(['KeepaliveProvider', 'IdleProvider', 'TitleProvider', + (keepaliveProvider: ng.idle.IKeepAliveProvider, idleProvider: ng.idle.IIdleProvider, + titleProvider: ng.idle.ITitleProvider) => { idleProvider.interrupt('mousemove keydown DOMMouseScroll mousewheel mousedown'); idleProvider.idle(5); idleProvider.timeout(5); @@ -17,8 +18,10 @@ angular.module('app', ['ngIdle']) keepaliveProvider.http(config.url); // should accept string and ng.IRequestConfig keepaliveProvider.http(config); keepaliveProvider.interval(10); + + titleProvider.enabled(true); }]) - .run(['Keepalive', 'Idle', (Keepalive: ng.idle.IKeepAliveService, Idle: ng.idle.IIdleService) => { + .run(['Keepalive', 'Idle', 'Title', (Keepalive: ng.idle.IKeepAliveService, Idle: ng.idle.IIdleService, Title: ng.idle.ITitleService) => { Idle.setTimeout(Idle.getTimeout()); Idle.setIdle(Idle.getIdle()); @@ -34,4 +37,14 @@ angular.module('app', ['ngIdle']) Keepalive.start(); Keepalive.ping(); Keepalive.stop(); + + Title.setEnabled(Title.isEnabled()); + Title.original(Title.original()); + Title.value(Title.value()); + Title.store(false); + Title.restore(); + Title.idleMessage(Title.idleMessage()); + Title.timedOutMessage(Title.timedOutMessage()); + Title.setAsIdle(120); + Title.setAsTimedOut(); }]); \ No newline at end of file diff --git a/angular-idle/angular-idle.d.ts b/angular-idle/angular-idle.d.ts index fc7729f27..b2087e60d 100644 --- a/angular-idle/angular-idle.d.ts +++ b/angular-idle/angular-idle.d.ts @@ -96,7 +96,7 @@ declare module angular.idle { /** * Stores the original title if it hasn't been already, and displays the timedOutMessage. */ - setAsTimedOut(); + setAsTimedOut(): void; } /** From 9f026569c8cf537857548e873fa13e80c16149ca Mon Sep 17 00:00:00 2001 From: Philip Bjorge Date: Tue, 19 Jan 2016 23:18:20 -0800 Subject: [PATCH 5/9] Use angular.idle instead of ng.idle --- angular-idle/angular-idle-tests.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/angular-idle/angular-idle-tests.ts b/angular-idle/angular-idle-tests.ts index 74af16c02..f3401b10f 100644 --- a/angular-idle/angular-idle-tests.ts +++ b/angular-idle/angular-idle-tests.ts @@ -2,8 +2,8 @@ angular.module('app', ['ngIdle']) .config(['KeepaliveProvider', 'IdleProvider', 'TitleProvider', - (keepaliveProvider: ng.idle.IKeepAliveProvider, idleProvider: ng.idle.IIdleProvider, - titleProvider: ng.idle.ITitleProvider) => { + (keepaliveProvider: angular.idle.IKeepAliveProvider, idleProvider: angular.idle.IIdleProvider, + titleProvider: angular.idle.ITitleProvider) => { idleProvider.interrupt('mousemove keydown DOMMouseScroll mousewheel mousedown'); idleProvider.idle(5); idleProvider.timeout(5); @@ -21,7 +21,8 @@ angular.module('app', ['ngIdle']) titleProvider.enabled(true); }]) - .run(['Keepalive', 'Idle', 'Title', (Keepalive: ng.idle.IKeepAliveService, Idle: ng.idle.IIdleService, Title: ng.idle.ITitleService) => { + .run(['Keepalive', 'Idle', 'Title', (Keepalive: angular.idle.IKeepAliveService, Idle: angular.idle.IIdleService, + Title: angular.idle.ITitleService) => { Idle.setTimeout(Idle.getTimeout()); Idle.setIdle(Idle.getIdle()); From f7287b046a4d217115562df4a1c3fabc444f3752 Mon Sep 17 00:00:00 2001 From: Philip Bjorge Date: Tue, 19 Jan 2016 23:25:47 -0800 Subject: [PATCH 6/9] Update setInterval --- angular-idle/angular-idle-tests.ts | 1 + angular-idle/angular-idle.d.ts | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/angular-idle/angular-idle-tests.ts b/angular-idle/angular-idle-tests.ts index f3401b10f..bcb2f2e55 100644 --- a/angular-idle/angular-idle-tests.ts +++ b/angular-idle/angular-idle-tests.ts @@ -38,6 +38,7 @@ angular.module('app', ['ngIdle']) Keepalive.start(); Keepalive.ping(); Keepalive.stop(); + Keepalive.setInterval(10); Title.setEnabled(Title.isEnabled()); Title.original(Title.original()); diff --git a/angular-idle/angular-idle.d.ts b/angular-idle/angular-idle.d.ts index b2087e60d..a53c3a930 100644 --- a/angular-idle/angular-idle.d.ts +++ b/angular-idle/angular-idle.d.ts @@ -145,6 +145,12 @@ declare module angular.idle { * Performs one ping only. */ ping(): void; + + /** + * Changes the interval value at runtime. + * You will need to restart the pinging process by calling start() manually for the changes to be reflected. + */ + setInterval(seconds: number): void; } /** From 0c29979c89090444e7760a01542c2d5a1ecea205 Mon Sep 17 00:00:00 2001 From: Philip Bjorge Date: Tue, 19 Jan 2016 23:26:19 -0800 Subject: [PATCH 7/9] Updated per new api documentation --- angular-idle/angular-idle.d.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/angular-idle/angular-idle.d.ts b/angular-idle/angular-idle.d.ts index a53c3a930..098c81b15 100644 --- a/angular-idle/angular-idle.d.ts +++ b/angular-idle/angular-idle.d.ts @@ -118,7 +118,7 @@ declare module angular.idle { * This specifies how often the keepalive event is triggered and the * HTTP request is issued. * - * @param seconds Integer, default is 5 minutes. Must be greater than 0. + * @param seconds Integer, default is 10 minutes. Must be greater than 0. */ interval(seconds: number): void; } @@ -183,13 +183,14 @@ declare module angular.idle { timeout(seconds: number): void; /** - * When true, user activity will automatically interrupt the warning countdown and reset the - * idle state. If false, you will need to manually call watch() when you want to start - * watching for idleness again. + * When true or idle, user activity will automatically interrupt the warning countdown + * and reset the idle state. If false or off, you will need to manually call watch() + * when you want to start watching for idleness again. If notIdle, user activity will + * only automatically interrupt if the user is not yet idle. * - * @param enabled boolean, default is true + * @param enabled boolean or string, possible values: off/false, idle/true, or notIdle */ - autoResume(enabled: boolean): void; + autoResume(enabled: boolean | string): void; /** * When true, the Keepalive service is automatically stopped and started as needed. From d4ffe15f647112a42e01ef80f650e523c9b31f7d Mon Sep 17 00:00:00 2001 From: Philip Bjorge Date: Tue, 19 Jan 2016 23:31:41 -0800 Subject: [PATCH 8/9] Switch my spaces to tabs in the test file --- angular-idle/angular-idle-tests.ts | 46 +++++++++++++++--------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/angular-idle/angular-idle-tests.ts b/angular-idle/angular-idle-tests.ts index bcb2f2e55..f7297a94f 100644 --- a/angular-idle/angular-idle-tests.ts +++ b/angular-idle/angular-idle-tests.ts @@ -3,33 +3,33 @@ angular.module('app', ['ngIdle']) .config(['KeepaliveProvider', 'IdleProvider', 'TitleProvider', (keepaliveProvider: angular.idle.IKeepAliveProvider, idleProvider: angular.idle.IIdleProvider, - titleProvider: angular.idle.ITitleProvider) => { + titleProvider: angular.idle.ITitleProvider) => { idleProvider.interrupt('mousemove keydown DOMMouseScroll mousewheel mousedown'); idleProvider.idle(5); idleProvider.timeout(5); idleProvider.keepalive(true) idleProvider.autoResume(true); - const config: ng.IRequestConfig = { - url: "http://google.com", - method: "GET" - }; + const config: ng.IRequestConfig = { + url: "http://google.com", + method: "GET" + }; - keepaliveProvider.http(config.url); // should accept string and ng.IRequestConfig - keepaliveProvider.http(config); + keepaliveProvider.http(config.url); // should accept string and ng.IRequestConfig + keepaliveProvider.http(config); keepaliveProvider.interval(10); - titleProvider.enabled(true); + titleProvider.enabled(true); }]) .run(['Keepalive', 'Idle', 'Title', (Keepalive: angular.idle.IKeepAliveService, Idle: angular.idle.IIdleService, - Title: angular.idle.ITitleService) => { - Idle.setTimeout(Idle.getTimeout()); - Idle.setIdle(Idle.getIdle()); + Title: angular.idle.ITitleService) => { + Idle.setTimeout(Idle.getTimeout()); + Idle.setIdle(Idle.getIdle()); Idle.watch(); - Idle.interrupt(); + Idle.interrupt(); - const expired: boolean = Idle.isExpired(); + const expired: boolean = Idle.isExpired(); if (Idle.running() || Idle.idling()) { Idle.unwatch(); @@ -38,15 +38,15 @@ angular.module('app', ['ngIdle']) Keepalive.start(); Keepalive.ping(); Keepalive.stop(); - Keepalive.setInterval(10); + Keepalive.setInterval(10); - Title.setEnabled(Title.isEnabled()); - Title.original(Title.original()); - Title.value(Title.value()); - Title.store(false); - Title.restore(); - Title.idleMessage(Title.idleMessage()); - Title.timedOutMessage(Title.timedOutMessage()); - Title.setAsIdle(120); - Title.setAsTimedOut(); + Title.setEnabled(Title.isEnabled()); + Title.original(Title.original()); + Title.value(Title.value()); + Title.store(false); + Title.restore(); + Title.idleMessage(Title.idleMessage()); + Title.timedOutMessage(Title.timedOutMessage()); + Title.setAsIdle(120); + Title.setAsTimedOut(); }]); \ No newline at end of file From b878ea974797c05350cc2be2e7b7a38200fa2d37 Mon Sep 17 00:00:00 2001 From: Philip Bjorge Date: Wed, 20 Jan 2016 14:13:25 -0800 Subject: [PATCH 9/9] store arguments are optional --- angular-idle/angular-idle-tests.ts | 1 + angular-idle/angular-idle.d.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/angular-idle/angular-idle-tests.ts b/angular-idle/angular-idle-tests.ts index f7297a94f..e6eb1a9f2 100644 --- a/angular-idle/angular-idle-tests.ts +++ b/angular-idle/angular-idle-tests.ts @@ -44,6 +44,7 @@ angular.module('app', ['ngIdle']) Title.original(Title.original()); Title.value(Title.value()); Title.store(false); + Title.store(); Title.restore(); Title.idleMessage(Title.idleMessage()); Title.timedOutMessage(Title.timedOutMessage()); diff --git a/angular-idle/angular-idle.d.ts b/angular-idle/angular-idle.d.ts index 098c81b15..725beac67 100644 --- a/angular-idle/angular-idle.d.ts +++ b/angular-idle/angular-idle.d.ts @@ -60,7 +60,7 @@ declare module angular.idle { * If overwrite is false or unspecified, updates the "original" title with the current document title * if it has not already been stored. If overwrite is true, the current document title is stored regardless. */ - store(overwrite: boolean): void; + store(overwrite?: boolean): void; /** * Sets the title to the original value (if it was stored or set previously).