Skip to content

Commit

Permalink
Added support for AU addresses (#4)
Browse files Browse the repository at this point in the history
* Added support for Australian addresses.

Added `country_code` property allowing users to specify the country to search against.
Moved `api_key` property to the top of the property list.

* Added support for AU country code.

Added AU specific fields.
Added latitude and longitude.

* Updated README

Updated documentaion with NZ and AU address diferrences.

* Increment version

* Workaround for property binding issue.

Added workaround until PCF bug 1505831 is resolved by Micrososft.

* Update index.ts
  • Loading branch information
ryanmichaeljames authored Oct 29, 2019
1 parent 65f9f82 commit 244138a
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 30 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ Option: Show Points of Interest | Boolean | `false` | Set to true to return poin

> For more information regarding the AddressFinder options see the options section of the AddressFinder Widget [documentation](https://addressfinder.nz/docs/widget_docs).
### New Zealand vs Australian addresses

By default, the AddressFinder Widget control will return New Zealand addresses, even if the `Country Code` input property is not set. To return Australian addresses the `Country Code` property must be set to `AU`.

There are a few subtle differences in the properties that are populated between New Zealand and Australian addresses. This is due to the AddressFinder API returning different properties in the search responses for each country. As a result, the following output properties are only populated by their respective countries.

Property | Country
--- | ---
City | New Zealand
Suburb | New Zealand
Locality | Australia
State/Territory | Australia

## Roadmap

Expand Down
13 changes: 9 additions & 4 deletions src/AddressFinderWidget/ControlManifest.Input.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<manifest>
<control namespace="Pcf" constructor="AddressFinderWidget" version="1.1.16" display-name-key="AddressFinder Widget" description-key="AddressFinder Widget" control-type="standard">
<control namespace="Pcf" constructor="AddressFinderWidget" version="1.2.21" display-name-key="AddressFinder Widget" description-key="AddressFinder Widget" control-type="standard">
<property name="api_key" display-name-key="API Key" description-key="Your AddressFinder API Key." of-type="SingleLine.Text" usage="input" required="true" />
<property name="country_code" display-name-key="Country Code" description-key="The country code you want to search against (NZ/AU). (Default: NZ)" of-type="SingleLine.Text" usage="input" required="false" />
<property name="address_line_1" display-name-key="Line 1" description-key="The address line 1." of-type="SingleLine.Text" usage="bound" required="false" />
<property name="address_line_2" display-name-key="Line 2" description-key="The address line 2." of-type="SingleLine.Text" usage="bound" required="false" />
<property name="city" display-name-key="City" description-key="The address city." of-type="SingleLine.Text" usage="bound" required="false" />
<property name="suburb" display-name-key="Suburb" description-key="The address suburb." of-type="SingleLine.Text" usage="bound" required="false" />
<property name="suburb" display-name-key="Suburb" description-key="The address suburb. (NZ only)" of-type="SingleLine.Text" usage="bound" required="false" />
<property name="city" display-name-key="City" description-key="The address city. (NZ only)" of-type="SingleLine.Text" usage="bound" required="false" />
<property name="locality_name" display-name-key="Locality" description-key="The locality name. (AU only)" of-type="SingleLine.Text" usage="bound" required="false" />
<property name="state_territory" display-name-key="State/Territory" description-key="The sate or territory. (AU only)" of-type="SingleLine.Text" usage="bound" required="false" />
<property name="postcode" display-name-key="Post Code" description-key="The address post code." of-type="SingleLine.Text" usage="bound" required="false" />
<property name="country" display-name-key="Country" description-key="The address country." of-type="SingleLine.Text" usage="bound" required="false" />
<property name="api_key" display-name-key="API Key" description-key="Your AddressFinder API Key." of-type="SingleLine.Text" usage="input" required="true" />
<property name="latitude" display-name-key="Latitude" description-key="The latitude." of-type="SingleLine.Text" usage="bound" required="false" />
<property name="longitude" display-name-key="Longitude" description-key="The longitude." of-type="SingleLine.Text" usage="bound" required="false" />
<property name="options_empty_content" display-name-key="Options: Empty Content" description-key="Message to display to users when there are no found addresses or locations." of-type="SingleLine.Text" usage="input" required="false" />
<property name="options_ignore_returns" display-name-key="Options: Ignore Returns" description-key="Ignore the use of the enter key when no list item is selected. (Default: true)" of-type="SingleLine.Text" usage="input" required="false" />
<property name="options_max_results" display-name-key="Options: Max Results" description-key="Maximum number of results to display. (Default: 10)" of-type="Whole.None" usage="input" required="false" />
Expand Down
124 changes: 100 additions & 24 deletions src/AddressFinderWidget/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@ export class AddressFinderWidget implements ComponentFramework.StandardControl<I
// Reference to PowerApps component framework Context object
private _context: ComponentFramework.Context<IInputs>;

// AddressFinder params
private _country_code: string | null;
private _options: object;

// AddressFinder fields
private _address_line_1: string;
private _address_line_2: string;
private _city: string;
private _suburb: string;
private _suburb: string; // NZ only
private _city: string; // NZ only
private _locality_name: string; // AU only
private _state_territory: string; // AU only
private _postcode: string;
private _country: string;
private _latitude: string;
private _longitude: string;

// AddressFinder widget
private AddressFinder: any;
Expand Down Expand Up @@ -49,6 +57,15 @@ export class AddressFinderWidget implements ComponentFramework.StandardControl<I
this.initContainter();
container = this._container;

// Country code
if (this._context.parameters.country_code.raw != null && this._context.parameters.country_code.raw != "")
this._country_code = this._context.parameters.country_code.raw;
else
this._country_code = "NZ"

// Options
this._options = this.getOptions;

// Initialize AddressFinder widget
this.initAddressFinder();
}
Expand All @@ -67,14 +84,56 @@ export class AddressFinderWidget implements ComponentFramework.StandardControl<I
* @returns an object based on nomenclature defined in manifest, expecting object[s] for property marked as “bound” or “output”
*/
public getOutputs(): IOutputs {
return {
address_line_1: this._address_line_1,
address_line_2: this._address_line_2,
city: this._city,
suburb: this._suburb,
postcode: this._postcode,
country: this._country
};

// return {
// address_line_1: this._address_line_1,
// address_line_2: this._address_line_2,
// suburb: this._suburb,
// city: this._city,
// locality_name: this._locality_name,
// state_territory: this._state_territory,
// postcode: this._postcode,
// country: this._country,
// latitude: this._latitude,
// longitude: this._longitude
// };

// Work around until PCF bug 1505831 is resolved by Micrososft
// see https://powerusers.microsoft.com/t5/PowerApps-Component-Framework/BUG-Non-required-parameters-not-bound/td-p/307838

var output: { [k: string]: any } = {};

if (this._context.parameters.address_line_1.type != null)
output.address_line_1 = this._address_line_1;

if (this._context.parameters.address_line_2.type != null)
output.address_line_2 = this._address_line_2;

if (this._context.parameters.suburb.type != null)
output.suburb = this._suburb;

if (this._context.parameters.city.type != null)
output.city = this._city;

if (this._context.parameters.locality_name.type != null)
output.locality_name = this._locality_name;

if (this._context.parameters.state_territory.type != null)
output.state_territory = this._state_territory;

if (this._context.parameters.postcode.type != null)
output.postcode = this._postcode;

if (this._context.parameters.country.type != null)
output.country = this._country;

if (this._context.parameters.latitude.type != null)
output.latitude = this._latitude;

if (this._context.parameters.longitude.type != null)
output.longitude = this._longitude;

return output;
}

/**
Expand All @@ -92,22 +151,39 @@ export class AddressFinderWidget implements ComponentFramework.StandardControl<I
this.Widget = new this.AddressFinder.Widget(
document.getElementById("addressfinder_search"),
this._context.parameters.api_key.raw,
"NZ",
this.getOptions()
this._country_code,
this._options
);

this.Widget.on("result:select", (fullAddress: any, metaData: any) => {

var selected = new this.AddressFinder.NZSelectedAddress(fullAddress, metaData);

this._address_line_1 = selected.address_line_1();
this._address_line_2 = selected.address_line_2();
this._suburb = selected.suburb();
this._city = selected.city();
this._postcode = selected.postcode();
this._country = "New Zealand";
this._notifyOutputChanged();
});
switch (this._country_code) {
case "AU":
this.Widget.on("result:select", (fullAddress: any, metaData: any) => {
this._address_line_1 = metaData.address_line_1;
this._address_line_2 = metaData.address_line_2;
this._locality_name = metaData.locality_name;
this._state_territory = metaData.state_territory;
this._postcode = metaData.postcode;
this._country = "Australia";
this._latitude = metaData.latitude;
this._longitude = metaData.longitude;
this._notifyOutputChanged();
});
break;
default: // NZ
this.Widget.on("result:select", (fullAddress: any, metaData: any) => {
var selected = new this.AddressFinder.NZSelectedAddress(fullAddress, metaData);
this._address_line_1 = selected.address_line_1();
this._address_line_2 = selected.address_line_2();
this._suburb = selected.suburb();
this._city = selected.city();
this._postcode = selected.postcode();
this._country = "New Zealand";
this._latitude = selected.metaData.y;
this._longitude = selected.metaData.x;
this._notifyOutputChanged();
});
break;
}
};

/**
Expand Down
6 changes: 4 additions & 2 deletions src/solution/Other/Solution.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
<!-- Localized Solution Name in language code -->
<LocalizedName description="AddressFinder Widget" languagecode="1033" />
</LocalizedNames>
<Descriptions />
<Version>1.1.16</Version>
<Descriptions>
<Description description="The PCF AddressFinder Widget is a PowerApps Component Framework (PCF) control for Dynamics 365 and Common Data Service (CDS) the uses the AddressFinder JavaScript Widget to search for New Zealand and Australian addresses." languagecode="1033" />
</Descriptions>
<Version>1.2.21</Version>
<!-- Solution Package Type: Unmanaged(0)/Managed(1)/Both(2)-->
<Managed>2</Managed>
<Publisher>
Expand Down

0 comments on commit 244138a

Please sign in to comment.