This repository has been archived by the owner on Oct 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 941
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1651 from duckduckgo/zaahir/octopart-update
Zaahir/octopart update
- Loading branch information
Showing
5 changed files
with
79 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,3 @@ | ||
{{#if description}} | ||
<div>Details: {{description}}</div> | ||
{{/if}} | ||
{{#if item.market_status}} | ||
<div>Market Status: {{item.market_status}}</div> | ||
{{/if}} | ||
{{#if price}} | ||
<div>Average Price: ${{price}}</div> | ||
{{/if}} | ||
<br> | ||
{{#if datasheet}} | ||
<a href="{{{datasheet}}}" class="btn btn__datasheet">Datasheet</a> | ||
{{/if}} | ||
{{#if url}} | ||
<a href="{{{url}}}" class="btn btn--primary"> | ||
Buy at Octopart | ||
</a> | ||
{{/if}} | ||
|
||
|
||
<a href="{{{datasheet}}}" class="btn btn__datasheet">Datasheet</a> | ||
<a href="{{{item.octopart_url}}}" class="btn btn--primary">Authorized Distributors</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
{{#if market_status}}<p>Market Status: {{market_status}}</p>{{/if}} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,87 @@ | ||
function ddg_spice_octopart (api_result) { | ||
(function (env) { | ||
"use strict"; | ||
|
||
if(!api_result || !api_result.results || api_result.results.length === 0) { | ||
return Spice.failed('octopart'); | ||
} | ||
// iterate over each distributors | ||
// to get matching large and medium size images | ||
function get_images(imagesets) { | ||
var images = {}; | ||
|
||
// var results = [], | ||
// isRelevant, | ||
// skip_words = [ | ||
// "datasheet", | ||
// "specs", | ||
// "octopart" | ||
// ]; | ||
$.each(imagesets, function(){ | ||
if (!is_mobile && this.large_image && this.medium_image){ | ||
images.large = DDG.toHTTP(this.large_image.url); | ||
images.medium = DDG.toHTTP(this.medium_image.url); | ||
return false; | ||
|
||
// for(var i = 0; i < api_result.results.length; i += 1) { | ||
// var iter = api_result.results[i]; | ||
// fallback in case we never find a large image | ||
// or on mobile device | ||
} else if (this.medium_image){ | ||
images.medium = DDG.toHTTP(this.medium_image.url); | ||
images.large = images.medium; | ||
|
||
// // Checks both the MPN and the manufacturer if the query is somehow relevant. | ||
// isRelevant = DDG.isRelevant(iter.item.mpn, skip_words, 4, true) || | ||
// DDG.isRelevant(iter.item.manufacturer.displayname, skip_words, 4, true); | ||
// worst case | ||
} else if (this.small_image){ | ||
images.medium = DDG.toHTTP(this.small_image.url); | ||
images.large = images.medium; | ||
} | ||
}); | ||
return images; | ||
} | ||
|
||
// // Check if we have images. | ||
// if(iter.item.images.length > 0 && isRelevant) { | ||
// results.push(iter); | ||
// // If an image doesn't exist, add a different image. | ||
// } else if(isRelevant) { | ||
// iter.item.images.push({ | ||
// url_90px: "http://n1.octostatic.com/o3web/detail/images/camera-icon.png" | ||
// }); | ||
// results.push(iter); | ||
// } | ||
// } | ||
env.ddg_spice_octopart = function (api_result) { | ||
|
||
// if(results.length === 0) { | ||
// return; | ||
// } | ||
if(!api_result || !api_result.results || api_result.results.length === 0) { | ||
return Spice.failed('octopart'); | ||
} | ||
|
||
var isMobile = $('.is-mobile').length; | ||
Spice.add({ | ||
id: 'octopart', | ||
name: 'Parts', | ||
data: api_result.results, | ||
signal: 'high', | ||
meta: { | ||
itemType: 'Parts', | ||
sourceName: 'Octopart', | ||
sourceUrl : 'http://octopart.com/search?q=' + api_result.request.q | ||
}, | ||
normalize: function(item) { | ||
|
||
Spice.add({ | ||
id: 'octopart', | ||
name: 'Parts', | ||
data: api_result.results, | ||
signal: 'high', | ||
|
||
meta: { | ||
itemType: 'Parts', | ||
sourceName: 'Octopart', | ||
sourceUrl : 'http://octopart.com/partsearch#search/requestData&q=' + api_result.request.q | ||
}, | ||
normalize: function(item) { | ||
var img = DDG.getProperty(item, "item.images.0.url_90px"); | ||
var desc_length = 60; | ||
var description = (isMobile ? | ||
Handlebars.helpers.ellipsis(DDG.strip_html(item.item.short_description), desc_length) : | ||
DDG.strip_html(item.item.short_description)); | ||
item = item.item; // our item object is wrapped in an "item" property | ||
|
||
return { | ||
brand: item.item.manufacturer.displayname, | ||
price: item.item.avg_price[1] + ' ' + item.item.avg_price[0].toFixed(2), | ||
img: img, | ||
img_m: img, | ||
url: item.item.detail_url, | ||
title: DDG.strip_html(item.item.mpn).toUpperCase(), | ||
heading: DDG.strip_html(item.item.mpn).toUpperCase(), | ||
description: description, | ||
datasheet: item.item.datasheets[0].url | ||
}; | ||
}, | ||
var images = get_images(item.imagesets); | ||
|
||
templates: { | ||
group: 'products', | ||
options: { | ||
rating: false, | ||
buy: Spice.octopart.buy | ||
return { | ||
brand: item.brand.name, | ||
price: item.avg_price_v2[1] + ' $' + item.avg_price_v2[0].toFixed(2), | ||
img: images.medium, | ||
img_m: images.large, | ||
url: item.octopart_url, | ||
title: item.mpn, | ||
heading: item.mpn, | ||
abstract: item.short_description, | ||
datasheet: item.datasheets[0].url, | ||
market_status: item.market_status_v2.replace(/^\w+: /, '') // strip out "GOOD: " from market_status | ||
}; | ||
}, | ||
variants: { | ||
detail: 'light' | ||
templates: { | ||
group: 'products', | ||
options: { | ||
rating: false, | ||
subtitle_content: Spice.octopart.content, | ||
buy: Spice.octopart.buy | ||
}, | ||
variants: { | ||
detail: 'light' | ||
} | ||
}, | ||
relevancy: { | ||
primary: [ | ||
{ required: 'item.short_description' }, | ||
{ required: 'item.octopart_url' }, | ||
{ required: 'item.datasheets' }, | ||
{ required: 'item.imagesets' }, | ||
{ required: 'item.avg_price_v2' }, | ||
], | ||
} | ||
} | ||
|
||
}); | ||
}; | ||
|
||
// Handlebars.registerHelper("toFixed", function(number) { | ||
// "use strict"; | ||
|
||
// return number.toFixed(2); | ||
// }); | ||
}); | ||
}; | ||
})(this); |