tweaks to make contact plugin work better

This commit is contained in:
Ibrahim Hadeed 2016-06-10 01:10:50 -04:00
parent 264c85cfba
commit 411e6fc2a1
3 changed files with 60 additions and 143 deletions

View File

@ -66,6 +66,7 @@ import {Vibration} from './plugins/vibration';
import {WebIntent} from './plugins/webintent'; import {WebIntent} from './plugins/webintent';
export * from './plugins/googlemaps'; export * from './plugins/googlemaps';
export * from './plugins/3dtouch'; export * from './plugins/3dtouch';
export * from './plugins/contacts';
export { export {
ActionSheet, ActionSheet,
AdMob, AdMob,

View File

@ -1,5 +1,6 @@
import {Plugin, Cordova, InstanceProperty, CordovaInstance} from './plugin'; import {Plugin, Cordova, InstanceProperty, CordovaInstance} from './plugin';
declare var window: any; declare var window: any,
navigator: any;
export interface IContactProperties { export interface IContactProperties {
/** A globally unique identifier. */ /** A globally unique identifier. */
id?: string; id?: string;
@ -30,75 +31,43 @@ export interface IContactProperties {
/** An array of web pages associated with the contact. */ /** An array of web pages associated with the contact. */
urls?: IContactField[]; urls?: IContactField[];
} }
export class Contact { export class Contact {
private _objectInstance: any; private _objectInstance: any;
@InstanceProperty get id() {return; }
@InstanceProperty @InstanceProperty get displayName() {return; }
get id() {return; } @InstanceProperty get nickname() {return; }
@InstanceProperty get phoneNumbers() {return; }
@InstanceProperty @InstanceProperty get emails() {return; }
get displayName() {return; } @InstanceProperty get addresses() {return; }
@InstanceProperty get ims() {return; }
@InstanceProperty @InstanceProperty get organizations() {return; }
get nickname() {return; } @InstanceProperty get birthday() {return; }
@InstanceProperty get note() {return; }
@InstanceProperty @InstanceProperty get photos() {return; }
get phoneNumbers() {return; } @InstanceProperty get categories() {return; }
@InstanceProperty get urls() {return; }
@InstanceProperty
get emails() {return; }
@InstanceProperty
get addresses() {return; }
@InstanceProperty
get ims() {return; }
@InstanceProperty
get organizations() {return; }
@InstanceProperty
get birthday() {return; }
@InstanceProperty
get note() {return; }
@InstanceProperty
get photos() {return; }
@InstanceProperty
get categories() {return; }
@InstanceProperty
get urls() {return; }
constructor () { constructor () {
this._objectInstance = navigator.contacts.create(); this._objectInstance = navigator.contacts.create();
} }
clone(): Contact { clone(): Contact {
// TODO manually clone the object let newContact = new Contact();
return; for (let prop in this) {
if (prop === 'id') return;
newContact[prop] = this[prop];
}
return newContact;
} }
@CordovaInstance() @CordovaInstance()
remove(): Promise<any> {return; } remove(): Promise<any> {return; }
@CordovaInstance() @CordovaInstance()
save(): Promise<any> {return; } save(): Promise<any> {return; }
} }
interface IContactError { interface IContactError {
/** Error code */ /** Error code */
code: number; code: number;
/** Error message */ /** Error message */
message: string; message: string;
} }
declare var ContactError: { declare var ContactError: {
new(code: number): IContactError; new(code: number): IContactError;
UNKNOWN_ERROR: number; UNKNOWN_ERROR: number;
@ -109,7 +78,6 @@ declare var ContactError: {
NOT_SUPPORTED_ERROR: number; NOT_SUPPORTED_ERROR: number;
PERMISSION_DENIED_ERROR: number PERMISSION_DENIED_ERROR: number
}; };
export interface IContactName { export interface IContactName {
/** The complete name of the contact. */ /** The complete name of the contact. */
formatted?: string; formatted?: string;
@ -124,26 +92,17 @@ export interface IContactName {
/** The contact's suffix (example Esq.). */ /** The contact's suffix (example Esq.). */
honorificSuffix?: string; honorificSuffix?: string;
} }
export class ContactName implements IContactName { export class ContactName implements IContactName {
private _objectInstance: any; private _objectInstance: any;
constructor(formatted?: string, familyName?: string, givenName?: string, middleName?: string, honorificPrefix?: string, honorificSuffix?: string) { constructor(formatted?: string, familyName?: string, givenName?: string, middleName?: string, honorificPrefix?: string, honorificSuffix?: string) {
this._objectInstance = new window.ContactName(formatted, familyName, givenName, middleName, honorificPrefix, honorificSuffix); this._objectInstance = new window.ContactName(formatted, familyName, givenName, middleName, honorificPrefix, honorificSuffix);
} }
@InstanceProperty get formatted(): string {return; }
@InstanceProperty @InstanceProperty get familyName(): string {return; }
get formatted(): string {return; } @InstanceProperty get givenName(): string {return; }
@InstanceProperty @InstanceProperty get middleName(): string {return; }
get familyName(): string {return; } @InstanceProperty get honorificPrefix(): string {return; }
@InstanceProperty @InstanceProperty get honorificSuffix(): string {return; }
get givenName(): string {return; }
@InstanceProperty
get middleName(): string {return; }
@InstanceProperty
get honorificPrefix(): string {return; }
@InstanceProperty
get honorificSuffix(): string {return; }
} }
export interface IContactField { export interface IContactField {
@ -160,12 +119,9 @@ export class ContactField implements IContactField {
constructor(type?: string, value?: string, pref?: boolean) { constructor(type?: string, value?: string, pref?: boolean) {
this._objectInstance = new window.ContactField(type, value, pref); this._objectInstance = new window.ContactField(type, value, pref);
} }
@InstanceProperty @InstanceProperty get type(): string {return; }
get type(): string {return; } @InstanceProperty get value(): string {return; }
@InstanceProperty @InstanceProperty get pref(): boolean {return; }
get value(): string {return; }
@InstanceProperty
get pref(): boolean {return; }
} }
export interface IContactAddress { export interface IContactAddress {
@ -189,7 +145,6 @@ export interface IContactAddress {
export class ContactAddress implements IContactAddress { export class ContactAddress implements IContactAddress {
private _objectInstance: any; private _objectInstance: any;
constructor (pref?: boolean, constructor (pref?: boolean,
type?: string, type?: string,
formatted?: string, formatted?: string,
@ -200,30 +155,14 @@ export class ContactAddress implements IContactAddress {
country?: string) { country?: string) {
this._objectInstance = new window.ContactAddress(pref, type, formatted, streetAddress, locality, region, postalCode, country); this._objectInstance = new window.ContactAddress(pref, type, formatted, streetAddress, locality, region, postalCode, country);
} }
@InstanceProperty get pref(): boolean {return; }
@InstanceProperty @InstanceProperty get type(): string {return; }
get pref(): boolean {return; } @InstanceProperty get formatted(): string {return; }
@InstanceProperty get streetAddress(): string {return; }
@InstanceProperty @InstanceProperty get locality(): string {return; }
get type(): string {return; } @InstanceProperty get region(): string {return; }
@InstanceProperty get postalCode(): string {return; }
@InstanceProperty @InstanceProperty get country(): string {return; }
get formatted(): string {return; }
@InstanceProperty
get streetAddress(): string {return; }
@InstanceProperty
get locality(): string {return; }
@InstanceProperty
get region(): string {return; }
@InstanceProperty
get postalCode(): string {return; }
@InstanceProperty
get country(): string {return; }
} }
export interface IContactOrganization { export interface IContactOrganization {
@ -244,24 +183,15 @@ export class ContactOrganization implements IContactOrganization {
constructor () { constructor () {
this._objectInstance = new window.ContactOrganization(); this._objectInstance = new window.ContactOrganization();
} }
@InstanceProperty @InstanceProperty get pref(): boolean {return; }
get pref(): boolean {return; } @InstanceProperty get type(): string {return; }
@InstanceProperty get name(): string {return; }
@InstanceProperty @InstanceProperty get department(): string {return; }
get type(): string {return; } @InstanceProperty get title(): string {return; }
@InstanceProperty
get name(): string {return; }
@InstanceProperty
get department(): string {return; }
@InstanceProperty
get title(): string {return; }
} }
/** Search options to filter navigator.contacts. */ /** Search options to filter navigator.contacts. */
interface IContactFindOptions { export interface IContactFindOptions {
/** The search string used to find navigator.contacts. */ /** The search string used to find navigator.contacts. */
filter?: string; filter?: string;
/** Determines if the find operation returns multiple navigator.contacts. */ /** Determines if the find operation returns multiple navigator.contacts. */
@ -275,37 +205,29 @@ export class ContactFindOptions implements IContactFindOptions {
constructor () { constructor () {
this._objectInstance = new window.ContactFindOptions(); this._objectInstance = new window.ContactFindOptions();
} }
@InstanceProperty @InstanceProperty get filter(): string {return; }
public get filter(): string {return; } @InstanceProperty get multiple(): boolean {return; }
@InstanceProperty get desiredFields(): any {return; }
@InstanceProperty @InstanceProperty get hasPhoneNumber(): boolean {return; }
public get multiple(): boolean {return; }
@InstanceProperty
public get desiredFields(): any {return; }
@InstanceProperty
public get hasPhoneNumber(): boolean {return; }
} }
/** /**
* @name Contacts * @name Contacts
* @description * @description
* Access and manage Contacts on the device. * Access and manage Contacts on the device.
* *
* Requires plugin: `cordova-plugin-contacts`
* For full info, please see the [Cordova Contacts plugin docs](https://github.com/apache/cordova-plugin-contacts)
*
* @usage * @usage
* *
* ```js * ```js
* import {Contacts} from 'ionic-native'; * import {Contact} from 'ionic-native';
* *
* *
* *
* Contacts.create({ * let contact = new Contact();
* displayName: "Mr. Ionitron" * contact.displayName = "Mr. Ionitron";
* }).then((contact) => {}, (err) => {}) * contact.save().then(
* () => console.log("Contact saved!", contact),
* (error: any) => console.error("Error saving contact.", error)
* );
* ``` * ```
* *
* *
@ -316,13 +238,9 @@ export class ContactFindOptions implements IContactFindOptions {
repo: 'https://github.com/apache/cordova-plugin-contacts' repo: 'https://github.com/apache/cordova-plugin-contacts'
}) })
export class Contacts { export class Contacts {
static create(): Contact { static create(): Contact {
return new Contact(); return new Contact();
} }
// TODO add fieldType options
/** /**
* Search for contacts in the Contacts list. * Search for contacts in the Contacts list.
* *
@ -345,12 +263,10 @@ export class Contacts {
errorIndex: 2 errorIndex: 2
}) })
static find(fields: string[], options?: any): Promise<any> { return; } static find(fields: string[], options?: any): Promise<any> { return; }
/** /**
* Select a single Contact. * Select a single Contact.
* @return Returns a Promise that resolves with the selected Contact * @return Returns a Promise that resolves with the selected Contact
*/ */
@Cordova() @Cordova()
static pickContact(): Promise<any> { return; } static pickContact(): Promise<any> {return; }
} }

View File

@ -323,13 +323,13 @@ export function CordovaProperty(target: Function, key: string, descriptor: Typed
* @param descriptor * @param descriptor
* @constructor * @constructor
*/ */
export function InstanceProperty(target: Function, key: string, descriptor: TypedPropertyDescriptor<any>) { export function InstanceProperty(target: any, key: string, descriptor: TypedPropertyDescriptor<any>) {
descriptor.get = function() { descriptor.get = function() {
return this._objectInstance[key]; return this._objectInstance[key];
}; };
descriptor.set = function(...args: any[]) { descriptor.set = function(...args: any[]) {
return this._objectInstance[key] = args[0]; this._objectInstance[key] = args[0];
}; };
return descriptor; return descriptor;