Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Commit

Permalink
PackageTracking: Correct date handling, improve title and subtitles (#…
Browse files Browse the repository at this point in the history
…3278)

* Fix images for Fedex and UPS

* Better title, subtitle; Corrected date handling

* append time to exisitding dateFormat
  • Loading branch information
moollaza authored and pjhampton committed May 5, 2017
1 parent 147b7e6 commit 83a44d2
Showing 1 changed file with 42 additions and 16 deletions.
58 changes: 42 additions & 16 deletions share/spice/package_tracking/package_tracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@
}

var logo = api_result.c;

switch (logo) {
case 'ups-packages':
logo = 'ups';
break;

case 'fedex-express':
logo = 'fedex';
break;
if (/^ups-.+/.test(logo)) {
logo = 'ups';
}
else if (/^fedex-.+/.test(logo)) {
logo = 'fedex';
}

var details_url = "https://www.packagetrackr.com/track/" + [api_result.c, api_result.n].join("/"),
Expand All @@ -40,12 +36,12 @@
data: api_result,
normalize: function (data) {

var status = statusCodes[data.status_code];

var obj = {
url: carrierUrl || details_url,
title: data.status_description.replace(/\.$/, ""),
subtitle: [
"Updated: " + moment(data.progress_at).fromNow(),
],
url: details_url,
title: status,
subtitle: data.status_description === status ? false : data.status_description,
image: DDG.get_asset_path('package_tracking', logo + '.png'),
record_data: {
"Tracking number": data.n,
Expand All @@ -55,8 +51,15 @@

$.each(dates, function(property, text){
var value = data[property];
if (value){
obj.record_data[text] = moment(value).format('lll');
var dateFormat = 'ddd, MMM D, YYYY';

if (value) {
if (text === "Delivered") {
text = "Delivered on";
dateFormat += ', h:mm A';
}

obj.record_data[text] = moment(value).utc().format(dateFormat);
}
});

Expand Down Expand Up @@ -87,6 +90,29 @@
act_delivery_at: "Delivered"
};

var statusCodes = {
NA: "N/A",
PD: "Pending",
IR: "Information Received",
AP: "At Pickup",
AF: "Arrived at Facility",
AC: "At Customs Clearance",
TP: "Tendered to Partner",
IT: "In Transit",
DS: "Delivery Scheduled",
OD: "Out for Delivery",
DA: "Delivery Attempt",
WP: "Will Pickup",
RS: "Return to Shipper",
DL: "Delivered",
DE: "Delivery Exception",
SU: "Stop Updating",
EX: "Expired",
IU: "Information Updated",
VD: "Voided",
TF: "Track Failed",
};

var carriers = {
"a1-international": { name: "A1 International" },
"aramex-express": { name: "Aramex Express" },
Expand Down

0 comments on commit 83a44d2

Please sign in to comment.