From 21334d2ae1046dbed8a15a3ea5b45c6cbe65db81 Mon Sep 17 00:00:00 2001 From: Stephan Classen Date: Wed, 5 Apr 2017 11:55:39 +0200 Subject: [PATCH 1/4] add types for angular-block-ui --- .../angular-block-ui-tests.ts | 41 +++++ types/angular-block-ui/index.d.ts | 171 ++++++++++++++++++ types/angular-block-ui/tsconfig.json | 23 +++ types/angular-block-ui/tslint.json | 1 + 4 files changed, 236 insertions(+) create mode 100644 types/angular-block-ui/angular-block-ui-tests.ts create mode 100644 types/angular-block-ui/index.d.ts create mode 100644 types/angular-block-ui/tsconfig.json create mode 100644 types/angular-block-ui/tslint.json diff --git a/types/angular-block-ui/angular-block-ui-tests.ts b/types/angular-block-ui/angular-block-ui-tests.ts new file mode 100644 index 0000000000..c3c69345c9 --- /dev/null +++ b/types/angular-block-ui/angular-block-ui-tests.ts @@ -0,0 +1,41 @@ +var app: angular.IModule = angular.module('at', ['blockUI']); + +app.config((blockUIConfig: angular.blockUI.IBlockUIConfig) => { + blockUIConfig.message = 'Please stop clicking!'; + blockUIConfig.delay = 100; + blockUIConfig.template = '
{{ state | json }}
'; + blockUIConfig.templateUrl = 'my-templates/block-ui-overlay.html'; + blockUIConfig.autoBlock = false; + blockUIConfig.resetOnException = false; + blockUIConfig.autoInjectBodyBlock = false; + blockUIConfig.cssClass = 'block-ui my-custom-class'; + blockUIConfig.blockBrowserNavigation = true; + + blockUIConfig.requestFilter = function (config) { + if (config.url.match(/^\/api\/quote($|\/).*/)) { + return false; + } + return true; + }; + + blockUIConfig.requestFilter = function (config) { + if (config.url.match(/^\/api\/quote($|\/).*/)) { + return 'Hello World'; + } + return 'Loading...'; + }; +}); + +app.controller('Ctrl', ($scope: ng.IScope, blockUI: angular.blockUI.IBlockUIService) => { + blockUI.start(); + blockUI.start('Hello'); + blockUI.start({}); + blockUI.start({message: 'World'}); + blockUI.start({delay: 100}); + + blockUI.stop(); + blockUI.reset(); + blockUI.message("Hello Types"); + blockUI.done(); + let b: boolean = blockUI.isBlocking(); +}); diff --git a/types/angular-block-ui/index.d.ts b/types/angular-block-ui/index.d.ts new file mode 100644 index 0000000000..4e67dbcb52 --- /dev/null +++ b/types/angular-block-ui/index.d.ts @@ -0,0 +1,171 @@ +// Type definitions for angular-block-ui v0.2.2 +// Project: https://github.com/McNull/angular-block-ui +// Definitions by: Lasse Nørregaard , Stephan Classen +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +import * as angular from 'angular'; + +declare module 'angular' { + export namespace blockUI { + + interface IBlockUIConfig { + /** + * Changes the default message to be used when no message + * has been provided to the start method of the service. + * + * Default value is 'Loading ...'. + */ + message?: string; + + /** + * Specifies the amount in milliseconds before the block + * is visible to the user. By delaying a visible block your + * application will appear more responsive. + * + * The default value is 250. + */ + delay?: number; + + /** + * Specifies a custom template to use as the overlay. + */ + template?: string; + + /** + * Specifies a url to retrieve the template from. + * The current release only works with pre-cached templates, + * which means that this url should be known in the + * $templateCache service of Angular. + * + * If you're using the grunt with html2js or angular-templates, + * which I highly recommend, you're already set. + */ + templateUrl?: string; + + /** + * By default the BlockUI module will start a block whenever + * the Angular $http service has an pending request. + * + * If you don't want this behaviour and want to do all the + * blocking manually you can change this value to false. + */ + autoBlock?: boolean; + + /** + * By default the BlockUI module will reset the block count and + * hide the overlay whenever an exception has occurred. + * + * You can set this value to false if you don't want this behaviour. + */ + resetOnException?: boolean; + + /** + * Allows you to specify a filter function to exclude certain ajax + * requests from blocking the user interface. + * The blockUI service will ignore requests when the function returns `false`. + * + * If the filter function returns a string it will be passed as the message + * argument to the start method of the service. + * + * @param {angular.IRequestConfig} config - the Angular request config object. + * + */ + requestFilter?: (config: angular.IRequestConfig) => (string | boolean); + + /** + * When the module is started it will inject the main block element + * by adding the block-ui directive to the body element. + */ + autoInjectBodyBlock?: boolean; + + /** + * A string containing the default css classes, separated by spaces, + * that should be applied to each block-ui element. + * + * The default value is `block-ui block-ui-anim-fade` + */ + cssClass?: string; + + /** + * Whenever a user interface block is active, because the single page + * application is still waiting for a response from the backend server, + * the user can still navigate away using the back and forward buttons + * of the browser. + * + * Callbacks registered to handle the responses from the server will + * be executed even if a different view/controller is currently active. + * By setting the blockBrowserNavigation property to true the + * angular-block-ui module will prevent navigation while a fullscreen + * block is active. + * + * Programatic location changes via the $location service are still + * allowed however. + * The navigation block is disabled by default. + */ + blockBrowserNavigation?: boolean; + } + + interface IBlockUIService { + /** + * The start method will start the user interface block. + * Because multiple user interface elements can request + * a user interface block at the same time, the service + * keeps track of the number of start calls. + * + * Each call to start() will increase the count and every + * call to stop() will decrease the value. + * Whenever the count reaches 0 the block will end. + * + * Note: By default the block is immediately active after + * calling this method, but to prevent trashing the user + * interface each time a button is pressed, the block is + * visible after a short delay. + * + * This behaviour can be modified in the configuration. + * + * @param {string|IBlockUIConfig} messageOrOptions - + * Either supply the message (string) to be show in the + * overlay or specify an IBlockUIConfig object that will be + * merged/extended into the block ui instance state. + * If no argument is specified the default text message + * from the configuration is used. + */ + start: (messageOrOptions?: (string | IBlockUIConfig)) => void; + + /** + * This will decrease the block count. + * + * The block will end if the count is 0. + */ + stop: () => void; + + /** + * The reset will force an unblock by setting the block count to 0. + */ + reset: () => void; + + /** + * Queues a callback function to be called when the block has finished. + * + * This can be useful whenever you wish to redirect the user + * to a different location while there are still pending AJAX requests. + */ + done: () => void; + + /** + * Allows the message shown in the overlay to be updated + * while to block is active. + * + * @param {string} message - The message to show in the overlay. + */ + message: (message: string) => void; + + /** + * Returns whether currently a block is shown for the instance or not. + */ + isBlocking: () => boolean; + } + } +} diff --git a/types/angular-block-ui/tsconfig.json b/types/angular-block-ui/tsconfig.json new file mode 100644 index 0000000000..b1b705a6e5 --- /dev/null +++ b/types/angular-block-ui/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "angular-block-ui-tests.ts" + ] +} diff --git a/types/angular-block-ui/tslint.json b/types/angular-block-ui/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/types/angular-block-ui/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" } From 714e405e324614def731875f7831e5f6ee38b9fe Mon Sep 17 00:00:00 2001 From: Stephan Classen Date: Wed, 5 Apr 2017 12:29:52 +0200 Subject: [PATCH 2/4] fix lint warnings --- .../angular-block-ui-tests.ts | 10 ++++---- types/angular-block-ui/index.d.ts | 23 +++++++++---------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/types/angular-block-ui/angular-block-ui-tests.ts b/types/angular-block-ui/angular-block-ui-tests.ts index c3c69345c9..4b3903f9cc 100644 --- a/types/angular-block-ui/angular-block-ui-tests.ts +++ b/types/angular-block-ui/angular-block-ui-tests.ts @@ -1,6 +1,6 @@ -var app: angular.IModule = angular.module('at', ['blockUI']); +let app: angular.IModule = angular.module('at', ['blockUI']); -app.config((blockUIConfig: angular.blockUI.IBlockUIConfig) => { +app.config((blockUIConfig: angular.blockUI.BlockUIConfig) => { blockUIConfig.message = 'Please stop clicking!'; blockUIConfig.delay = 100; blockUIConfig.template = '
{{ state | json }}
'; @@ -11,14 +11,14 @@ app.config((blockUIConfig: angular.blockUI.IBlockUIConfig) => { blockUIConfig.cssClass = 'block-ui my-custom-class'; blockUIConfig.blockBrowserNavigation = true; - blockUIConfig.requestFilter = function (config) { + blockUIConfig.requestFilter = (config) => { if (config.url.match(/^\/api\/quote($|\/).*/)) { return false; } return true; }; - blockUIConfig.requestFilter = function (config) { + blockUIConfig.requestFilter = (config) => { if (config.url.match(/^\/api\/quote($|\/).*/)) { return 'Hello World'; } @@ -26,7 +26,7 @@ app.config((blockUIConfig: angular.blockUI.IBlockUIConfig) => { }; }); -app.controller('Ctrl', ($scope: ng.IScope, blockUI: angular.blockUI.IBlockUIService) => { +app.controller('Ctrl', ($scope: ng.IScope, blockUI: angular.blockUI.BlockUIService) => { blockUI.start(); blockUI.start('Hello'); blockUI.start({}); diff --git a/types/angular-block-ui/index.d.ts b/types/angular-block-ui/index.d.ts index 4e67dbcb52..6b0f59f910 100644 --- a/types/angular-block-ui/index.d.ts +++ b/types/angular-block-ui/index.d.ts @@ -5,12 +5,11 @@ /// -import * as angular from 'angular'; +import * as angular from "angular"; declare module 'angular' { - export namespace blockUI { - - interface IBlockUIConfig { + namespace blockUI { + interface BlockUIConfig { /** * Changes the default message to be used when no message * has been provided to the start method of the service. @@ -72,7 +71,7 @@ declare module 'angular' { * @param {angular.IRequestConfig} config - the Angular request config object. * */ - requestFilter?: (config: angular.IRequestConfig) => (string | boolean); + requestFilter?(config: angular.IRequestConfig): (string | boolean); /** * When the module is started it will inject the main block element @@ -107,7 +106,7 @@ declare module 'angular' { blockBrowserNavigation?: boolean; } - interface IBlockUIService { + interface BlockUIService { /** * The start method will start the user interface block. * Because multiple user interface elements can request @@ -132,19 +131,19 @@ declare module 'angular' { * If no argument is specified the default text message * from the configuration is used. */ - start: (messageOrOptions?: (string | IBlockUIConfig)) => void; + start(messageOrOptions?: (string | BlockUIConfig)): void; /** * This will decrease the block count. * * The block will end if the count is 0. */ - stop: () => void; + stop(): void; /** * The reset will force an unblock by setting the block count to 0. */ - reset: () => void; + reset(): void; /** * Queues a callback function to be called when the block has finished. @@ -152,7 +151,7 @@ declare module 'angular' { * This can be useful whenever you wish to redirect the user * to a different location while there are still pending AJAX requests. */ - done: () => void; + done(): void; /** * Allows the message shown in the overlay to be updated @@ -160,12 +159,12 @@ declare module 'angular' { * * @param {string} message - The message to show in the overlay. */ - message: (message: string) => void; + message(message: string): void; /** * Returns whether currently a block is shown for the instance or not. */ - isBlocking: () => boolean; + isBlocking(): boolean; } } } From 79afe266db85b4e603cfcc792c47209d8d120e27 Mon Sep 17 00:00:00 2001 From: Stephan Classen Date: Mon, 17 Apr 2017 22:50:23 +0200 Subject: [PATCH 3/4] use new tslint default "dtslint/dt.json" --- types/angular-block-ui/tslint.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/angular-block-ui/tslint.json b/types/angular-block-ui/tslint.json index 377cc837d4..3db14f85ea 100644 --- a/types/angular-block-ui/tslint.json +++ b/types/angular-block-ui/tslint.json @@ -1 +1 @@ -{ "extends": "../tslint.json" } +{ "extends": "dtslint/dt.json" } From 51c5e6dfb5a11de9c8a6060feabafbb641d37208 Mon Sep 17 00:00:00 2001 From: sclassen Date: Mon, 17 Apr 2017 23:13:51 +0200 Subject: [PATCH 4/4] Fix tslint errors in angular-block-ui/index.ts --- types/angular-block-ui/index.d.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/types/angular-block-ui/index.d.ts b/types/angular-block-ui/index.d.ts index 6b0f59f910..bf311b04a1 100644 --- a/types/angular-block-ui/index.d.ts +++ b/types/angular-block-ui/index.d.ts @@ -1,10 +1,8 @@ -// Type definitions for angular-block-ui v0.2.2 +// Type definitions for angular-block-ui 0.2 // Project: https://github.com/McNull/angular-block-ui // Definitions by: Lasse Nørregaard , Stephan Classen // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -/// - import * as angular from "angular"; declare module 'angular' {