From 8251405c2138f9f1b5f64e49d2e92272cefeaf0d Mon Sep 17 00:00:00 2001 From: Amir Nissim Date: Sun, 29 Sep 2013 12:58:05 +0300 Subject: [PATCH] Bug 911569 - [e.me][bug] Pre-installed apps don't show in relevant collections [r=ranbena] --- apps/homescreen/everything.me/js/Brain.js | 4 +- .../everything.me/js/api/DoATAPI.js | 1 + .../modules/Collection/Collection.js | 122 +++--------------- .../Results/providers/InstalledApps.js | 23 +++- 4 files changed, 37 insertions(+), 113 deletions(-) diff --git a/apps/homescreen/everything.me/js/Brain.js b/apps/homescreen/everything.me/js/Brain.js index 96590d58378f..0d3f797121db 100644 --- a/apps/homescreen/everything.me/js/Brain.js +++ b/apps/homescreen/everything.me/js/Brain.js @@ -1172,10 +1172,10 @@ this.InstalledAppsService = new function InstalledAppsService() { Evme.CollectionsSuggest.Loading.show(); - Evme.CollectionStorage.getAllCollections(function onCollections(collections) { + EvmeManager.getCollections(function onCollections(collections) { var existingCollectionsQueries = []; for (var i = 0, collection; collection = collections[i++];) { - existingCollectionsQueries.push(collection.query); + existingCollectionsQueries.push(collection.manifest.name); } // load suggested shortcuts from API diff --git a/apps/homescreen/everything.me/js/api/DoATAPI.js b/apps/homescreen/everything.me/js/api/DoATAPI.js index 69fa2982365d..65aaf2098630 100644 --- a/apps/homescreen/everything.me/js/api/DoATAPI.js +++ b/apps/homescreen/everything.me/js/api/DoATAPI.js @@ -722,6 +722,7 @@ Evme.DoATAPI = new function Evme_DoATAPI() { "methodNamespace": methodNamespace, "methodName": methodName, "params": params, + "originalOptions": options, "callback": callback, "requestTimeout": MAX_REQUEST_TIME, "retries": NUMBER_OF_RETRIES, diff --git a/apps/homescreen/everything.me/modules/Collection/Collection.js b/apps/homescreen/everything.me/modules/Collection/Collection.js index 05b30de20126..0206025db9e5 100644 --- a/apps/homescreen/everything.me/modules/Collection/Collection.js +++ b/apps/homescreen/everything.me/modules/Collection/Collection.js @@ -104,7 +104,7 @@ void function() { Evme.CollectionSettings.update(collectionSettings, data, function onUpdate(updatedSettings){ // collection is open and apps changed - if (currentSettings && 'apps' in data) { + if (currentSettings && currentSettings.id === collectionSettings.id && 'apps' in data) { resultsManager.renderStaticApps(updatedSettings.apps); } @@ -119,7 +119,7 @@ void function() { // first 3 apps changed if (!shouldUpdateIcon && 'apps' in data) { - shouldUpdateIcon = !Evme.Utils.arraysEqual(originalAppIds, + shouldUpdateIcon = !Evme.Utils.arraysEqual(originalAppIds, pluck(updatedSettings.apps, 'id'), numIcons); } @@ -128,7 +128,7 @@ void function() { var numApps = ('apps' in data) ? data.apps.length : originalAppIds.length;; if (numApps < numIcons){ - shouldUpdateIcon = !Evme.Utils.arraysEqual(originalIcons, + shouldUpdateIcon = !Evme.Utils.arraysEqual(originalIcons, pluck(updatedSettings.extraIconsData, 'icon'), numIcons); } } @@ -192,9 +192,10 @@ void function() { }; this.onQueryIndexUpdated = function onQueryIndexUpdated() { - // TODO - Evme.CollectionSettings.updateAll(); - // move update homescreen here + var gridCollections = EvmeManager.getCollections(); + gridCollections.forEach(function populate(gridCollection) { + Evme.CollectionStorage.get(gridCollection.id, populateCollection); + }); }; this.show = function show(e) { @@ -457,17 +458,6 @@ void function() { } }; - Evme.CollectionSettings.updateAll = function updateAll() { - // TODO - // see if this method required any changes - // get collection by EvmeManager.getCollections? - var ids = Evme.CollectionStorage.getAllIds(); - - for (var i = 0, id; id = ids[i++];) { - Evme.CollectionStorage.get(id, populateCollection); - } - }; - // save collection settings in storage and run callback async. function saveSettings(settings, cb) { Evme.CollectionStorage.add(settings, function onStored() { @@ -479,7 +469,7 @@ void function() { var existingIds = Evme.Utils.pluck(settings.apps, 'id'); var newApps = Evme.InstalledAppsService.getMatchingApps({ - 'query': settings.query + 'experienceId': settings.experienceId }); newApps = newApps.filter(function isNew(app) { @@ -518,39 +508,27 @@ void function() { /** * CollectionStorage - * Persists settings to local storage + * Persists collection settings to local storage * - * TODO encapsulate - don't expose as Evme.CollectionStorage */ Evme.CollectionStorage = new function Evme_CollectionStorage() { var NAME = 'CollectionStorage', - IDS_STORAGE_KEY = 'evmeCollection', PREFIX = 'collectionsettings_', - self = this, - ids = null, - ID_LOCK_RETRY_TIME = 100, - locked = false; // locks the ids list + self = this; this.init = function init() { - Evme.Storage.get(IDS_STORAGE_KEY, function onGet(storedIds) { - ids = storedIds || []; - }); - window.addEventListener('collectionUninstalled', onCollectionUninstalled); }; this.remove = function remove(collectionId) { - removeId(collectionId); + Evme.Storage.remove(PREFIX + collectionId); }; - this.add = function add(settings, cb) { + this.add = function add(settings, cb=Evme.Utils.NOOP) { if (!settings.id) return; Evme.Storage.set(PREFIX + settings.id, settings, function onSet() { - addId(settings.id); - if (cb instanceof Function) { - cb(settings); - } + cb(settings); }); }; @@ -561,82 +539,18 @@ void function() { self.add(settings, cb); }; - this.get = function get(settingsId, cb) { + this.get = function get(settingsId, cb=Evme.Utils.NOOP) { Evme.Storage.get(PREFIX + settingsId, function onGet(storedSettings) { - if (cb && storedSettings !== null) { + if (storedSettings !== null) { var settings = new Evme.CollectionSettings(storedSettings); - if (cb instanceof Function) { - cb(settings); - } + cb(settings); } }); }; - this.getAllIds = function getAllIds() { - return ids; - }; - - this.getAllCollections = function getAllCollections(callback) { - var ids = self.getAllIds(), - collections = []; - - for (var i = 0, id; id = ids[i++];) { - self.get(id, onGotCollectionSettings); - } - - function onGotCollectionSettings(settings) { - collections.push(settings); - if (collections.length === ids.length) { - callback(collections); - } - } - }; - function onCollectionUninstalled(e) { - removeId(e.detail.collection.id); - } - - function addId(id) { - if (ids && ids.indexOf(id) > -1) return; - - if (ids === null || locked) { - setTimeout(function retry() {addId(id); }, ID_LOCK_RETRY_TIME); - return; - } - - try { - lock(); - ids.push(id); - Evme.Storage.set(IDS_STORAGE_KEY, ids, unlock); - } catch (ex) { - unlock(); - } - } - - function removeId(id) { - if (ids === null || locked) { - setTimeout(function retry() {removeId(id); }, ID_LOCK_RETRY_TIME); - return; - } - - try { - lock(); - ids = ids.filter(function neqId(storedId) {return storedId !== id }); - Evme.CollectionStorage.set(IDS_STORAGE_KEY, ids, function onRemoved() { - unlock(); - Evme.Storage.remove(PREFIX + collectionId); - }); - } catch (ex) { - unlock(); - } - } - - function lock() { - locked = true; - } - - function unlock() { - locked = false; + var collectionId = e.detail.collection.id; + self.remove(collectionId); } }; diff --git a/apps/homescreen/everything.me/modules/Results/providers/InstalledApps.js b/apps/homescreen/everything.me/modules/Results/providers/InstalledApps.js index a809fa0d2f21..c67538119872 100644 --- a/apps/homescreen/everything.me/modules/Results/providers/InstalledApps.js +++ b/apps/homescreen/everything.me/modules/Results/providers/InstalledApps.js @@ -111,9 +111,10 @@ Evme.InstalledAppsService = new function Evme_InstalledAppsService() { } this.requestAppsInfo = function requestAppsInfo() { - var gridApps = EvmeManager.getGridApps(), - guids = gridApps.map(function getId(gridApp){ - return gridApp.manifestURL || gridApp.bookmarkURL; + var gridApps = EvmeManager.getGridApps(); + + var guids = gridApps.map(function getId(gridApp){ + return gridApp.app.manifestURL || gridApp.app.bookmarkURL; }); Evme.EventHandler.trigger(NAME, "requestAppsInfo", guids); @@ -154,12 +155,20 @@ Evme.InstalledAppsService = new function Evme_InstalledAppsService() { }; this.getMatchingApps = function getMatchingApps(data) { - if (!data || !data.query) { - return []; + var matchingApps = [], + query; + + if (data.query) { + query = data.query; + } else if (data.experienceId) { + query = Evme.Utils.shortcutIdToKey(data.experienceId); } - var matchingApps = [], - query = normalizeQuery(data.query); + if (!query) { + return matchingApps; + } + + query = normalizeQuery(query); // search appIndex // search query within first letters of app name words