Skip to content

Commit

Permalink
Bug 952415 - [Rocketbar] Duplicate results should not appear. r=armin
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinGrandon committed Mar 3, 2014
1 parent fbb6faa commit 966a106
Show file tree
Hide file tree
Showing 17 changed files with 516 additions and 44 deletions.
3 changes: 1 addition & 2 deletions apps/browser/js/browser.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

var rscheme = /^(?:[a-z\u00a1-\uffff0-9-+]+)(?::|:\/\/)/i;
var _ = navigator.mozL10n.get;

var Browser = {
Expand Down Expand Up @@ -668,7 +667,7 @@ var Browser = {
},

getUrlFromInput: function browser_getUrlFromInput(input) {
var hasScheme = !!(rscheme.exec(input) || [])[0];
var hasScheme = UrlHelper.hasScheme(input);

// Not a valid URL, could be a search term
if (UrlHelper.isNotURL(input) && this.searchEngine.uri) {
Expand Down
9 changes: 6 additions & 3 deletions apps/search/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
<script defer src="js/eme/eme.js"></script>
<script defer src="js/eme/api.js"></script>
<script defer src="js/providers/provider.js"></script>
<script defer src="js/providers/bgimage.js"></script>

<!-- Ordering of the following files will impact which queries we send first -->
<script defer src="js/providers/marketplace.js"></script>
<script defer src="js/providers/places.js"></script>
<script defer src="js/providers/local_apps.js"></script>
<script defer src="js/providers/suggestions.js"></script>
<script defer src="js/providers/bgimage.js"></script>
<script defer src="js/providers/webresults.js"></script>
<script defer src="js/providers/local_apps.js"></script>
<script defer src="js/providers/marketplace.js"></script>

<script defer src="shared/js/l10n.js"></script>
<head>
<body>
Expand Down
4 changes: 2 additions & 2 deletions apps/search/js/providers/contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
});
},

search: function(input) {
search: function(input, collect) {
var options = {
filterValue: input,
filterBy: ['givenName'],
Expand Down Expand Up @@ -63,7 +63,7 @@
renderResults.push(renderObj);
}
}
this.render(renderResults);
collect(renderResults);
}).bind(this);

request.onerror = function() {
Expand Down
45 changes: 33 additions & 12 deletions apps/search/js/providers/local_apps.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
/* global Provider, Search */
/* global Provider, Search, UrlHelper */

(function() {

'use strict';

function LocalApps() {
this.apps = {};
navigator.mozApps.mgmt.getAll().onsuccess = (function(evt) {
evt.target.result.forEach(function r_getApps(app) {
this.apps[app.manifestURL] = app;
}, this);
}).bind(this);

var mozApps = navigator.mozApps.mgmt;
var self = this;

mozApps.oninstall = function oninstall(e) {
self.apps[e.application.manifestURL] = e.application;
};

mozApps.onuninstall = function oninstall(e) {
delete self.apps[e.application.manifestURL];
};

mozApps.getAll().onsuccess = function r_getApps(e) {
e.target.result.forEach(function r_AppsForEach(app) {
self.apps[app.manifestURL] = app;
});
};
}

LocalApps.prototype = {
Expand All @@ -19,6 +31,9 @@

name: 'LocalApps',

dedupes: true,
dedupeStrategy: 'exact',

click: function(e) {
var target = e.target;

Expand All @@ -34,7 +49,7 @@
}
},

search: function(input) {
search: function(input, collect) {
this.clear();

var results = this.find(input);
Expand All @@ -51,10 +66,15 @@
var icons = result.manifest.icons || {};
var imgUrl = '';
for (var i in icons) {
var a = document.createElement('a');
a.href = result.origin;
imgUrl = a.protocol + '//' + a.host + icons[i];
break;
var eachUrl = icons[i];
if (UrlHelper.hasScheme(eachUrl)) {
imgUrl = eachUrl;
} else {
// For relative URLs
var a = document.createElement('a');
a.href = result.origin;
imgUrl = a.protocol + '//' + a.host + eachUrl;
}
}

// Only display results which have icons.
Expand All @@ -65,10 +85,11 @@
formatted.push({
title: result.manifest.name,
icon: imgUrl,
dedupeId: result.manifestURL,
dataset: dataset
});
}, this);
this.render(formatted);
collect(formatted);
},

find: function(query) {
Expand Down
12 changes: 8 additions & 4 deletions apps/search/js/providers/marketplace.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
'use strict';

const NUM_DISPLAY = 4;
const API = 'https://marketplace.firefox.com/api/v1/apps/search/?q={q}';
const API = 'https://marketplace.firefox.com/api/v1/apps/search/' +
'?q={q}&limit=' + NUM_DISPLAY;

function Marketplace() {}

Expand All @@ -15,6 +16,9 @@

name: 'Marketplace',

dedupes: true,
dedupeStrategy: 'exact',

click: function(e) {
var slug = e.target.dataset.slug;
var activity = new MozActivity({
Expand All @@ -29,7 +33,7 @@
};
},

search: function(input) {
search: function(input, collect) {
this.clear();
this.abort();

Expand All @@ -45,7 +49,6 @@
var formatted = [];
for (var i = 0; i < length; i++) {
var app = results.objects[i];

var nameL10n = '';
for (var locale in app.name) {
// Default the app name if we haven't found a matching locale
Expand All @@ -60,12 +63,13 @@
title: navigator.mozL10n.get('install-marketplace-title',
{title: nameL10n}),
icon: app.icons['64'],
dedupeId: app.manifest_url,
dataset: {
slug: app.slug
}
});
}
this.render(formatted);
collect(formatted);
}).bind(this);
req.onerror = function onerror() {
console.log('Marketplace error.');
Expand Down
4 changes: 2 additions & 2 deletions apps/search/js/providers/places.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
window.open(target.dataset.url, '_blank', 'remote=true');
},

search: function(filter) {
search: function(filter, collect) {
this.clear();
var matched = 0;
var renderResults = [];
Expand All @@ -187,7 +187,7 @@
break;
}
}
this.render(renderResults);
collect(renderResults);
}
};

Expand Down
8 changes: 7 additions & 1 deletion apps/search/js/providers/provider.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
/* global UrlHelper */

/**
* Base Provider class
Expand All @@ -14,6 +15,11 @@ Provider.prototype = {
*/
name: 'Provider',

/**
* Whether or not this provider dedupes results.
*/
dedupes: false,

/**
* Initializes the provider container and adds listeners
*/
Expand Down Expand Up @@ -79,7 +85,7 @@ Provider.prototype = {
result.dataset[i] = config.dataset[i];
}

if (config.icon && /^(app|http)/.test(config.icon)) {
if (config.icon && UrlHelper.hasScheme(config.icon)) {
icon.src = config.icon;
} else if (config.icon) {
icon.src = window.URL.createObjectURL(config.icon);
Expand Down
8 changes: 6 additions & 2 deletions apps/search/js/providers/webresults.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

name: 'WebResults',

dedupes: true,
dedupeStrategy: 'fuzzy',

init: function() {
Provider.prototype.init.apply(this, arguments);
eme.init();
Expand All @@ -28,7 +31,7 @@
}
},

search: function(input) {
search: function(input, collect) {
this.clear();
if (!eme.api.Apps) {
return;
Expand All @@ -45,14 +48,15 @@
return {
title: app.name,
icon: app.icon,
dedupeId: app.appUrl,
dataset: {
title: app.name,
url: app.appUrl,
icon: app.icon
}
};
});
this.render(results);
collect(results);
}
}).bind(this), function reject(reason) {
// handle errors
Expand Down
Loading

0 comments on commit 966a106

Please sign in to comment.