From e2c01f4b12d76baf3b08b9d5d646d69d1d2a6156 Mon Sep 17 00:00:00 2001 From: Max Lynch Date: Tue, 8 Sep 2015 14:39:56 -0500 Subject: [PATCH 1/7] feat(native): device plugin --- ionic/components/app/test/native/index.ts | 6 +- ionic/components/app/test/native/main.html | 5 +- ionic/native/device/device.ts | 117 +++++++++++++++++++++ ionic/native/plugin.ts | 17 ++- ionic/native/plugins.ts | 1 + 5 files changed, 143 insertions(+), 3 deletions(-) create mode 100644 ionic/native/device/device.ts diff --git a/ionic/components/app/test/native/index.ts b/ionic/components/app/test/native/index.ts index 474d23e509..894026b2be 100644 --- a/ionic/components/app/test/native/index.ts +++ b/ionic/components/app/test/native/index.ts @@ -3,7 +3,7 @@ import {Control, ControlGroup} from 'angular2/forms'; import {App, Http} from 'ionic/ionic'; -import {Camera, Geolocation, Vibration, Battery} from 'ionic/ionic'; +import {Camera, Geolocation, Vibration, Battery, Device} from 'ionic/ionic'; let testUrl = 'https://ionic-api-tester.herokuapp.com/json'; let testUrl404 = 'https://ionic-api-tester.herokuapp.com/404'; @@ -15,6 +15,10 @@ let testUrl404 = 'https://ionic-api-tester.herokuapp.com/404'; class IonicApp { constructor() { } + doDevice() { + let device = Device.getDevice(); + console.log('Got device', device); + } doGetLocation() { console.log('Getting location'); this.gettingLocation = true; diff --git a/ionic/components/app/test/native/main.html b/ionic/components/app/test/native/main.html index 48c2948f6b..820585f7c2 100644 --- a/ionic/components/app/test/native/main.html +++ b/ionic/components/app/test/native/main.html @@ -1,5 +1,9 @@ +

Device

+ +
+

Camera

Geolocation

@@ -25,7 +29,6 @@

Contacts

-
diff --git a/ionic/native/device/device.ts b/ionic/native/device/device.ts new file mode 100644 index 0000000000..f1ff8c3f61 --- /dev/null +++ b/ionic/native/device/device.ts @@ -0,0 +1,117 @@ +import * as Rx from 'rx'; + +import * as util from 'ionic/util'; +import {NativePlugin} from '../plugin'; +import {Platform} from '../../platform/platform'; + +@NativePlugin({ + name: 'Device', + platforms: { + cordova: 'cordova-plugin-device' + } +}) +export class Device { + /** + * Returns the whole device object. + * @see https://github.com/apache/cordova-plugin-device + * @returns {Object} The device object. + */ + static getDevice() { + return this.ifPlugin(window.device, () => { + return device; + }, () => { + return { + name: Platform.platforms().join(',') + } + }); + } + + /** + * Returns the Cordova version. + * @see https://github.com/apache/cordova-plugin-device#devicecordova + * @returns {String} The Cordova version. + */ + static getCordova() { + this.ifPlugin(window.device, () => { + return device.cordova; + }); + } + + /** + * 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. + */ + static getModel() { + this.ifPlugin(window.device, () => { + return device.model; + }, () => { + return 'unknown' + }); + } + + /** + * @deprecated device.name is deprecated as of version 2.3.0. Use device.model instead. + * @returns {String} + */ + static getName() { + this.ifPlugin(window.device, () => { + return device.name; + }, () => { + return 'unknown' + }); + } + + /** + * Returns the device's operating system name. + * @see https://github.com/apache/cordova-plugin-device#deviceplatform + * @returns {String} The device's operating system name. + */ + static getPlatform() { + this.ifPlugin(window.device, () => { + return device.name; + }, () => { + return { + name: Platform.name() + } + }); + } + + /** + * Returns the device's Universally Unique Identifier. + * @see https://github.com/apache/cordova-plugin-device#deviceuuid + * @returns {String} The device's Universally Unique Identifier + */ + static getUUID() { + this.ifPlugin(window.device, () => { + return device.uuid; + }, () => { + return 'unknown'; + }); + } + + /** + * Returns the operating system version. + * @see https://github.com/apache/cordova-plugin-device#deviceversion + * @returns {String} + */ + static getVersion() { + this.ifPlugin(window.device, () => { + return device.version; + }, () => { + return 'unknown'; + }); + } + + /** + * Returns the device manufacturer. + * @returns {String} + */ + static getManufacturer() { + this.ifPlugin(window.device, () => { + return device.manufacturer; + }, () => { + return 'unknown'; + }); + } +} diff --git a/ionic/native/plugin.ts b/ionic/native/plugin.ts index b506519f1b..9b37805a92 100644 --- a/ionic/native/plugin.ts +++ b/ionic/native/plugin.ts @@ -3,13 +3,28 @@ export class NativePluginDecorator { this.cls = cls; this.config = config; + cls.ifPlugin = (check, cb, returnType=null) => { + // Convert to boolean the plugin param + var exists = !!check; + if(typeof check === 'function') { + exists = check(); + } + if(exists) { + return cb(); + } + + cls.pluginWarn(); + + return (typeof returnType === 'function') ? returnType() : returnType; + }; + cls.pluginWarn = () => { let platformString = []; for(var k in this.config.platforms) { platformString.push('\t' + k + ': '+ this.config.platforms[k]); } console.warn('Plugin for ' + this.config.name + - ' not installed. For native functionality, please instead the correct plugin for your platform:\n' + + ' not installed. For native functionality, please install the correct plugin for your platform:\n' + platformString.join('\n')); } } diff --git a/ionic/native/plugins.ts b/ionic/native/plugins.ts index 975d2815ce..0987e69131 100644 --- a/ionic/native/plugins.ts +++ b/ionic/native/plugins.ts @@ -2,5 +2,6 @@ export * from './plugin' export * from './battery/battery' export * from './camera/camera' export * from './contacts/contacts' +export * from './device/device' export * from './geolocation/geolocation' export * from './vibration/vibration' From b95ddaafa2e42e5e673952aab994e671efd9f8ef Mon Sep 17 00:00:00 2001 From: Drew Rygh Date: Tue, 8 Sep 2015 15:00:14 -0500 Subject: [PATCH 2/7] docs: fix doc tags --- ionic/components/action-menu/action-menu.ts | 4 ++-- ionic/components/checkbox/checkbox.ts | 4 ++-- ionic/components/content/content.ts | 2 +- ionic/components/item/item-swipe-buttons.ts | 4 ++-- ionic/components/item/item.ts | 4 ++-- ionic/components/list/list.ts | 2 +- ionic/components/modal/modal.ts | 4 ++-- ionic/components/popup/popup.ts | 4 ++-- ionic/components/radio/radio.ts | 8 ++++---- ionic/components/scroll/pull-to-refresh.ts | 12 +++++------- ionic/components/switch/switch.ts | 10 ++++------ ionic/components/tabs/tab.ts | 4 ++-- ionic/components/tabs/tabs.ts | 4 ++-- 13 files changed, 31 insertions(+), 35 deletions(-) diff --git a/ionic/components/action-menu/action-menu.ts b/ionic/components/action-menu/action-menu.ts index c675a5649a..5639214439 100644 --- a/ionic/components/action-menu/action-menu.ts +++ b/ionic/components/action-menu/action-menu.ts @@ -17,12 +17,12 @@ import * as util from 'ionic/util'; /** * @name ActionMenu - * @classdesc + * @description * The Action Menu is a slide-up pane that lets the user choose from a set of options. Dangerous options are made obvious. * * There are easy ways to cancel out of the action sheet, such as tapping the backdrop or even hitting escape on the keyboard for desktop testing. * - * @example + * @usage * ```ts * openMenu() { * diff --git a/ionic/components/checkbox/checkbox.ts b/ionic/components/checkbox/checkbox.ts index 45367b92e0..ad186f6609 100644 --- a/ionic/components/checkbox/checkbox.ts +++ b/ionic/components/checkbox/checkbox.ts @@ -14,12 +14,12 @@ import {TapClick} from '../button/button'; /** * @name ionCheckbox - * @classdesc + * @description * The checkbox is no different than the HTML checkbox input, except it's styled differently * * See the [Angular 2 Docs](https://angular.io/docs/js/latest/api/forms/) for more info on forms and input. * - * @example + * @usage * ```html * * HTML5 diff --git a/ionic/components/content/content.ts b/ionic/components/content/content.ts index 3e93ae6c46..1d691824fd 100644 --- a/ionic/components/content/content.ts +++ b/ionic/components/content/content.ts @@ -8,7 +8,7 @@ import {hasFocusedTextInput} from '../../util/dom'; /** * @name ionContent - * @classdesc + * @description * TODO * */ diff --git a/ionic/components/item/item-swipe-buttons.ts b/ionic/components/item/item-swipe-buttons.ts index c2199a87bf..911b1808dd 100644 --- a/ionic/components/item/item-swipe-buttons.ts +++ b/ionic/components/item/item-swipe-buttons.ts @@ -5,10 +5,10 @@ import {SlideGesture} from 'ionic/gestures/slide-gesture'; /** * @name ionPrimarySwipeButtons - * @classdesc + * @description * Creates a swipeable button inside a list item, that is visible when the item is swiped to the left by the user. Swiped open buttons can be hidden with `setOpen(false)`. * - * @example + * @usage * TODO */ @Directive({ diff --git a/ionic/components/item/item.ts b/ionic/components/item/item.ts index 8d4d6847b2..5e10ab75e4 100644 --- a/ionic/components/item/item.ts +++ b/ionic/components/item/item.ts @@ -6,11 +6,11 @@ import {dom} from 'ionic/util'; /** * @name ionItem - * @classdesc + * @description * Creates a list-item that can easily be swiped, * deleted, reordered, edited, and more. * - * @example + * @usage * ```html * * diff --git a/ionic/components/list/list.ts b/ionic/components/list/list.ts index 6eb8f2ee2e..0e33dad135 100644 --- a/ionic/components/list/list.ts +++ b/ionic/components/list/list.ts @@ -8,7 +8,7 @@ import * as util from 'ionic/util'; /** * @name ionList - * @classdesc + * @description * The List is a widely used interface element in almost any mobile app, and can include * content ranging from basic text all the way to buttons, toggles, icons, and thumbnails. * diff --git a/ionic/components/modal/modal.ts b/ionic/components/modal/modal.ts index 30459cb6a7..680dbc899e 100644 --- a/ionic/components/modal/modal.ts +++ b/ionic/components/modal/modal.ts @@ -6,10 +6,10 @@ import * as util from 'ionic/util'; /** * @name ionModal - * @classdesc + * @description * The Modal is a content pane that can go over the user's main view temporarily. Usually used for making a choice or editing an item. * - * @example + * @usage * ```ts * class MyApp { * diff --git a/ionic/components/popup/popup.ts b/ionic/components/popup/popup.ts index 72ea5e0472..337658db56 100644 --- a/ionic/components/popup/popup.ts +++ b/ionic/components/popup/popup.ts @@ -8,12 +8,12 @@ import * as util from 'ionic/util'; /** * @name ionPopup - * @classdesc + * @description * The Ionic Popup service allows programmatically creating and showing popup windows that require the user to respond in order to continue. * * The popup system has support for more flexible versions of the built in `alert()`, `prompt()`, and `confirm()` functions that users are used to, in addition to allowing popups with completely custom content and look. * - * @example + * @usage * ```ts * class myApp { * diff --git a/ionic/components/radio/radio.ts b/ionic/components/radio/radio.ts index b3bd25fb61..2acb2e189c 100644 --- a/ionic/components/radio/radio.ts +++ b/ionic/components/radio/radio.ts @@ -9,7 +9,7 @@ import {ListHeader} from '../list/list'; /** * @name ionRadioGroup - * @classdesc + * @description * A radio group is a group of radio components. * * Selecting a radio button in the group unselects all others in the group. @@ -18,7 +18,7 @@ import {ListHeader} from '../list/list'; * * See the [Angular 2 Docs](https://angular.io/docs/js/latest/api/forms/) for more info on forms and input. * - * @example + * @usage * ```html * * @@ -152,12 +152,12 @@ export class RadioGroup extends Ion { /** * @name ionRadio - * @classdesc + * @description * A single radio component. * * See the [Angular 2 Docs](https://angular.io/docs/js/latest/api/forms/) for more info on forms and input. * - * @example + * @usage * ```html * * Radio Label diff --git a/ionic/components/scroll/pull-to-refresh.ts b/ionic/components/scroll/pull-to-refresh.ts index 46e91714db..637389776b 100644 --- a/ionic/components/scroll/pull-to-refresh.ts +++ b/ionic/components/scroll/pull-to-refresh.ts @@ -7,20 +7,18 @@ import {raf, ready, CSS} from 'ionic/util/dom'; /** * @name ionRefresher - * @classdesc + * @description * Allows you to add pull-to-refresh to an ionContent component. * * Place it as the first child of your ionContent or ionScroll element. * * When refreshing is complete, call `refresher.complete()` from your controller. * - * @example - * ```html - * - * ``` - * - * @example + * @usage * ```ts + * + * + * * doRefresh(refresher) { * console.log('Refreshing!', refresher); * diff --git a/ionic/components/switch/switch.ts b/ionic/components/switch/switch.ts index 687eb1df51..0d1425143a 100644 --- a/ionic/components/switch/switch.ts +++ b/ionic/components/switch/switch.ts @@ -48,23 +48,21 @@ class MediaSwitch { /** * @name ionSwitch - * @classdesc + * @description * A switch technically is the same thing as an HTML checkbox input, except it looks different and is easier to use on a touch device. Ionic prefers to wrap the checkbox input with the