From 3637fe5a062c4a1ab987a22960c4c12f61296ef0 Mon Sep 17 00:00:00 2001 From: Kapil Sachdeva Date: Wed, 28 Oct 2015 19:01:23 -0500 Subject: [PATCH] Add the ngCordova type definitions This changeset add the bindings for $cordovaDevice & $cordovaToast services --- ngCordova/device-tests.ts | 42 +++++++++++++++++++++ ngCordova/device.d.ts | 77 +++++++++++++++++++++++++++++++++++++++ ngCordova/toast-tests.ts | 51 ++++++++++++++++++++++++++ ngCordova/toast.d.ts | 21 +++++++++++ ngCordova/tsd.d.ts | 2 + 5 files changed, 193 insertions(+) create mode 100644 ngCordova/device-tests.ts create mode 100644 ngCordova/device.d.ts create mode 100644 ngCordova/toast-tests.ts create mode 100644 ngCordova/toast.d.ts create mode 100644 ngCordova/tsd.d.ts diff --git a/ngCordova/device-tests.ts b/ngCordova/device-tests.ts new file mode 100644 index 000000000..c5f761326 --- /dev/null +++ b/ngCordova/device-tests.ts @@ -0,0 +1,42 @@ +/// +/// +/// + +// For the full application demo please see follow repo : +// https://github.com/ksachdeva/ngCordova-typescript-demo + +namespace demo.device { + 'use strict'; + + interface IDeviceViewModel { + available:boolean; + cordova:string; + model:string; + platform:string; + uuid:string; + version:string; + } + + export class DeviceController { + + public vm:IDeviceViewModel; + + static $inject:Array = ["$ionicPlatform", "$cordovaDevice"]; + constructor($ionicPlatform:ionic.platform.IonicPlatformService, $cordovaDevice:ngCordova.IDeviceService) { + + $ionicPlatform.ready(() => { + this.vm = { + available : $cordovaDevice.getDevice().available, + cordova : $cordovaDevice.getCordova(), + model : $cordovaDevice.getModel(), + platform : $cordovaDevice.getPlatform(), + uuid : $cordovaDevice.getUUID(), + version : $cordovaDevice.getVersion() + }; + }); + } + + } + + angular.module("demo.device").controller("DeviceController", DeviceController); +} \ No newline at end of file diff --git a/ngCordova/device.d.ts b/ngCordova/device.d.ts new file mode 100644 index 000000000..760b37cef --- /dev/null +++ b/ngCordova/device.d.ts @@ -0,0 +1,77 @@ +// Type definitions for ngCordova device plugin +// Project: https://github.com/driftyco/ng-cordova +// Definitions by: Kapil Sachdeva + +declare module ngCordova { + + interface IDeviceInfo { + available:boolean; + platform:string; + version:string; + uuid:string; + cordova:string; + model:string; + manufacturer:string; + isVirtual:boolean; + serial:string; + } + + interface IDeviceService { + + /** + * Returns the whole device object. + * @see https://github.com/apache/cordova-plugin-device + * @returns {Object} The device object. + */ + getDevice():IDeviceInfo; + + /** + * Returns the Cordova version. + * @see https://github.com/apache/cordova-plugin-device#devicecordova + * @returns {String} The Cordova version. + */ + getCordova():string; + + /** + * Returns the name of the device's model or product. + * @see https://github.com/apache/cordova-plugin-device#devicemodel + * @returns {String} The name of the device's model or product. + */ + getModel():string; + + + /** + * @deprecated device.name is deprecated as of version 2.3.0. Use device.model instead. + * @returns {String} + */ + getName():string; + + /** + * Returns the device's operating system name. + * @see https://github.com/apache/cordova-plugin-device#deviceplatform + * @returns {String} The device's operating system name. + */ + getPlatform():string; + + + /** + * Returns the device's Universally Unique Identifier. + * @see https://github.com/apache/cordova-plugin-device#deviceuuid + * @returns {String} The device's Universally Unique Identifier + */ + getUUID():string; + + /** + * Returns the operating system version. + * @see https://github.com/apache/cordova-plugin-device#deviceversion + * @returns {String} + */ + getVersion():string; + + /** + * Returns the device manufacturer. + * @returns {String} + */ + getManufacturer():string; + } +} \ No newline at end of file diff --git a/ngCordova/toast-tests.ts b/ngCordova/toast-tests.ts new file mode 100644 index 000000000..1d067a92b --- /dev/null +++ b/ngCordova/toast-tests.ts @@ -0,0 +1,51 @@ +/// +/// +/// + +// For the full application demo please see follow repo : +// https://github.com/ksachdeva/ngCordova-typescript-demo + +namespace demo.toast { + 'use strict'; + + export class ToastController { + + toastMessage:string = 'enter a message'; + msg:string; + + static $inject:Array = ["$cordovaToast"]; + constructor(private $cordovaToast:ngCordova.IToastService) { + + } + + center() { + this.$cordovaToast.show(this.toastMessage, 'long', 'center') + .then((success) => { + console.log("center msg displayed"); + }, (error) => { + this.msg = error.message; + }); + } + + top() { + this.$cordovaToast.showShortTop(this.toastMessage) + .then((success) => { + console.log("short top msg displayed"); + }, (error) => { + this.msg = error.message; + }); + } + + bottom() { + this.$cordovaToast.showLongBottom(this.toastMessage) + .then((success) => { + console.log("long bottom msg displayed"); + }, (error) => { + this.msg = error.message; + }); + } + + } + + angular.module("demo.toast").controller("ToastController", ToastController); +} \ No newline at end of file diff --git a/ngCordova/toast.d.ts b/ngCordova/toast.d.ts new file mode 100644 index 000000000..c7dd6a980 --- /dev/null +++ b/ngCordova/toast.d.ts @@ -0,0 +1,21 @@ +// Type definitions for ngCordova toast plugin +// Project: https://github.com/driftyco/ng-cordova +// Definitions by: Kapil Sachdeva + +/// + +declare module ngCordova { + + interface IToastService { + + showShortTop(message:string):angular.IPromise; + showShortCenter(message:string):angular.IPromise; + showShortBottom(message:string):angular.IPromise; + + showLongTop(message:string):angular.IPromise; + showLongCenter(message:string):angular.IPromise; + showLongBottom(message:string):angular.IPromise; + + show(message:string, duration:string, position:string):angular.IPromise; + } +} \ No newline at end of file diff --git a/ngCordova/tsd.d.ts b/ngCordova/tsd.d.ts new file mode 100644 index 000000000..13cbd0f26 --- /dev/null +++ b/ngCordova/tsd.d.ts @@ -0,0 +1,2 @@ +/// +///