From 91de9715fed2bbaa8ac0889689ee30e74187cd4e Mon Sep 17 00:00:00 2001 From: Ibrahim Hadeed Date: Sun, 6 Mar 2016 13:51:12 -0500 Subject: [PATCH 1/3] fix(datepicker): fix plugin functionality --- src/plugins/datepicker.ts | 105 +++++++++++++++++++++++++++----------- 1 file changed, 76 insertions(+), 29 deletions(-) diff --git a/src/plugins/datepicker.ts b/src/plugins/datepicker.ts index a0d1d24d..f48b5255 100644 --- a/src/plugins/datepicker.ts +++ b/src/plugins/datepicker.ts @@ -1,26 +1,91 @@ import {Plugin, Cordova} from './plugin'; +export interface datePickerOptions { + /** + * Platforms: iOS, Android, Windows + * The mode of the date picker + * Values: date | time | datetime + * Default: date + */ + mode?: string, + + /** + * Platforms: iOS, Android, Windows + * Selected date + * Default: new Date() + */ + date?: Date, + + /** + * Platforms: iOS, Android, Windows + * Minimum date + * Type: Date | empty String + * Default: empty String + */ + minDate?: Date, + + /** + * Platforms: iOS, Android, Windows + * Maximum date + * Type: Date | empty String + * Default: empty String + */ + maxDate?: Date, + + /** + * Platforms: Android + * Label for the dialog title. If empty, uses android default (Set date/Set time). + * Type: String + * Default: empty String + */ + titleText?: string, + + /** + * Platforms: Android + * Label of BUTTON_POSITIVE (done button) on Android + */ + okText?: string, + + // TODO complete documentation here, and copy params & docs to main plugin docs + cancelText?: string, + todayText?: string, + nowText?: string, + is24Hour?: boolean, + androidTheme?: number, + allowOldDate?: boolean, + allowFutureDates?: boolean, + doneButtonLabel?: string, + doneButtonColor?: string, + cancelButtonLabel?: string, + cancelButtonColor?: string, + x?: number, + y?: number, + minuteInterval?: number, + popoverArrowDirection?: string, + locale?: string +} + /** * The DatePicker plugin allows the user to fetch date or time using native dialogs. * * Platforms supported: iOS, Android, Windows * - * Requires Cordova plugin: `cordova-plugin-datepicker`. For more info, please see the [Datepicker plugin docs](https://github.com/VitaliiBlagodir/cordova-plugin-datepicker). + * Requires Cordova plugin: `cordova-plugin-datepicker`. For more info, please see the [DatePicker plugin docs](https://github.com/VitaliiBlagodir/cordova-plugin-datepicker). * * Install the plugin by running the following command: * ```shell - * ionic plugin add cordova-plugin-datepicker + * cordova plugin add https://github.com/VitaliiBlagodir/cordova-plugin-datepicker.git * ``` * * @usage * ```js - * DatePicker. + * DatePicker.show(); * ``` * */ @Plugin({ - plugin: 'cordova-plugin-datepicker', - pluginRef: 'plugins.datePicker' + plugin: 'https://github.com/VitaliiBlagodir/cordova-plugin-datepicker.git', + pluginRef: 'datePicker' }) export class DatePicker { @@ -30,30 +95,12 @@ export class DatePicker { * @returns {Promise} Returns a promise that resolves with the picked date and/or time, or rejects with an error. */ @Cordova() - static show(options?: { - mode?: string, - date?: Date, - minDate?: Date, - maxDate?: Date, - titleText?: string, - okText?: string, - cancelText?: string, - todayText?: string, - nowText?: string, - is24Hour?: boolean, - androidTheme?: number, - allowOldDate?: boolean, - allowFutureDates?: boolean, - doneButtonLabel?: string, - doneButtonColor?: string, - cancelButtonLabel?: string, - cancelButtonColor?: string, - x?: number, - y?: number, - minuteInterval?: number, - popoverArrowDirection?: string, - locale?: string - }): Promise { + static show(options?: datePickerOptions): Promise { + // This Promise is replaced by one from the @Cordova decorator that wraps + // the plugin's callbacks. We provide a dummy one here so TypeScript + // knows that the correct return type is Promise, because there's no way + // for it to know the return type from a decorator. + // See https://github.com/Microsoft/TypeScript/issues/4881 return new Promise((res, rej) => {}); } From 1a778e7f10ff383eabf32495845d12c07530a373 Mon Sep 17 00:00:00 2001 From: Ibrahim Hadeed Date: Sun, 6 Mar 2016 14:31:00 -0500 Subject: [PATCH 2/3] fix(datepicker): fix plugin functionality Fixed and tested the core plugin functionality --- src/plugins/datepicker.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/plugins/datepicker.ts b/src/plugins/datepicker.ts index f48b5255..d1bfa908 100644 --- a/src/plugins/datepicker.ts +++ b/src/plugins/datepicker.ts @@ -5,16 +5,14 @@ export interface datePickerOptions { * Platforms: iOS, Android, Windows * The mode of the date picker * Values: date | time | datetime - * Default: date */ - mode?: string, + mode: string, /** * Platforms: iOS, Android, Windows * Selected date - * Default: new Date() */ - date?: Date, + date: Date, /** * Platforms: iOS, Android, Windows @@ -79,7 +77,13 @@ export interface datePickerOptions { * * @usage * ```js - * DatePicker.show(); + * DatePicker.show({ + * date: new Date(), + * mode: 'date' + * }).then( + * date => console.log("Got date: ", date), + * err => console.log("Error occurred while getting date:", err) + * ); * ``` * */ @@ -95,7 +99,7 @@ export class DatePicker { * @returns {Promise} Returns a promise that resolves with the picked date and/or time, or rejects with an error. */ @Cordova() - static show(options?: datePickerOptions): Promise { + static show(options: datePickerOptions): Promise { // This Promise is replaced by one from the @Cordova decorator that wraps // the plugin's callbacks. We provide a dummy one here so TypeScript // knows that the correct return type is Promise, because there's no way From 44365f4c603dcbd8a30424768080d2ba0632807e Mon Sep 17 00:00:00 2001 From: Ibrahim Hadeed Date: Tue, 8 Mar 2016 14:23:22 -0500 Subject: [PATCH 3/3] fix(plugin): fix options properties --- src/plugins/datepicker.ts | 40 +++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/plugins/datepicker.ts b/src/plugins/datepicker.ts index d1bfa908..3758db96 100644 --- a/src/plugins/datepicker.ts +++ b/src/plugins/datepicker.ts @@ -20,7 +20,7 @@ export interface datePickerOptions { * Type: Date | empty String * Default: empty String */ - minDate?: Date, + minDate: Date, /** * Platforms: iOS, Android, Windows @@ -28,7 +28,7 @@ export interface datePickerOptions { * Type: Date | empty String * Default: empty String */ - maxDate?: Date, + maxDate: Date, /** * Platforms: Android @@ -36,31 +36,31 @@ export interface datePickerOptions { * Type: String * Default: empty String */ - titleText?: string, + titleText: string, /** * Platforms: Android * Label of BUTTON_POSITIVE (done button) on Android */ - okText?: string, + okText: string, // TODO complete documentation here, and copy params & docs to main plugin docs - cancelText?: string, - todayText?: string, - nowText?: string, - is24Hour?: boolean, - androidTheme?: number, - allowOldDate?: boolean, - allowFutureDates?: boolean, - doneButtonLabel?: string, - doneButtonColor?: string, - cancelButtonLabel?: string, - cancelButtonColor?: string, - x?: number, - y?: number, - minuteInterval?: number, - popoverArrowDirection?: string, - locale?: string + cancelText: string, + todayText: string, + nowText: string, + is24Hour: boolean, + androidTheme: number, + allowOldDate: boolean, + allowFutureDates: boolean, + doneButtonLabel: string, + doneButtonColor: string, + cancelButtonLabel: string, + cancelButtonColor: string, + x: number, + y: number, + minuteInterval: number, + popoverArrowDirection: string, + locale: string } /**