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

Commit

Permalink
device filtering persist site-wide, don't persist between session (bu…
Browse files Browse the repository at this point in the history
…g 1127080)
  • Loading branch information
ngokevin committed Mar 6, 2015
1 parent a4ef033 commit 2080dac
Show file tree
Hide file tree
Showing 28 changed files with 439 additions and 631 deletions.
2 changes: 1 addition & 1 deletion src/dev.html
Expand Up @@ -38,7 +38,7 @@
<link rel="stylesheet" href="/media/css/buttons-loadmore.styl.css">
<link rel="stylesheet" href="/media/css/categories.styl.css">
<link rel="stylesheet" href="/media/css/category-dropdown-desktop.styl.css">
<link rel="stylesheet" href="/media/css/compat-filtering.styl.css">
<link rel="stylesheet" href="/media/css/compat-filter.styl.css">
<link rel="stylesheet" href="/media/css/debug.styl.css">
<link rel="stylesheet" href="/media/css/desktop-promo.styl.css">
<link rel="stylesheet" href="/media/css/detail/base.styl.css">
Expand Down
File renamed without changes.
147 changes: 147 additions & 0 deletions src/media/js/compat_filter.js
@@ -0,0 +1,147 @@
/*
Compatibility filtering and device filtering. Mainly used to add arguments
to the API router's processor. It also handles `limit` since that can be
affected by the device or form factor.
Device filtering is affected by a dropdown found above app lists. When the
dropdown is changed, we will persist the new device filtering preference
globally and across sessions.
For desktop, device filtering is off by default at the moment.
For feature profiles, if not in querystring, we default to a feature
profile sig that is specially crafted. Includes all features except more
recent ones to hide apps using more recent features from older Marketplaces
that have not been updated yet. Generated in Zamboni with:
f = FeatureProfile.from_signature('fffffffffffffffffffffffffff')
f.update({'mobileid': False, 'precompile_asmjs': False,
'hardware_512mb_ram': False, 'hardware_1gb_ram': False})
f.to_signature()
*/
define('compat_filter',
['core/capabilities', 'core/l10n', 'core/log', 'core/storage',
'core/utils', 'core/views', 'core/z', 'underscore'],
function(caps, l10n, log, storage,
utils, views, z, _) {
'use strict';
var logger = log('compat_filter');
var gettext = l10n.gettext;

var limit = 24;

// Endpoints where feat. profile enabled if conditions met. See apiArgs().
var ENDPOINTS_WITH_FEATURE_PROFILE = [
'category', 'feed', 'feed-app', 'feed-brand', 'feed-collection',
'feed-items', 'feed-shelf', 'installed', 'recommended', 'search'
];
var feature_profile = utils.getVars().pro || '7fffffffffff0.51.6';

var DEVICE_CHOICES = {
'android-mobile': gettext('Android Mobile'),
'android-tablet': gettext('Android Tablet'),
'desktop': gettext('Desktop'),
'firefoxos': gettext('Firefox OS'),
};
var DEVICE_FILTER_CHOICES = [
['all', gettext('All Apps')],
['desktop', gettext('Desktop Apps')],
['firefoxos', gettext('Firefox OS Apps')],
['android-mobile', gettext('Android Mobile Apps')],
['android-tablet', gettext('Android Tablet Apps')]
];
var actual_platform = caps.device_platform();
var actual_formfactor = caps.device_formfactor();
var filterDevice = caps.device_type();

z.body.on('change', '#compat-filter', function() {
// Update stored preferences and reload view to refresh changes.
filterDevice = this[this.selectedIndex].value;
logger.log('Filtering: ' + filterDevice);
views.reload();
});

// Add "Apps for my Device" option on mobile.
if (caps.firefoxOS || caps.firefoxAndroid) {
DEVICE_FILTER_CHOICES.splice(
1, 0, [caps.device_type(), gettext('Apps for My Device')]);
}

// On desktop, the default is no filtering.
if (actual_platform == 'desktop') {
actual_platform = '';
filterDevice = '';
}

// For mobile, set limit to 10.
if (actual_formfactor == 'mobile' || actual_platform == 'firefoxos') {
limit = 10;
}

function isDeviceSelected(value) {
// Return whether value should be currently selected.
if (value == 'all' && !filterDevice) {
// Special case: on desktop, where filterDevice is empty.
// 'all' is default behaviour -> 'follow default filtering'.
value = '';
}

var deviceOverride = utils.getVars().device_override;
if (deviceOverride) {
return deviceOverride == value;
} else {
return filterDevice == value;
}
}

function apiArgs(endpoint) {
// Return API args to use for API router's processor.
var args = {};
var pref;

pref = utils.getVars().device_override || filterDevice;
if (pref) {
// If have device filter preference or override in query string
// extract it.
pref = pref.split('-');
if (pref.length > 1) {
args.dev = pref[0];
args.device = pref[1];
} else if (pref[0] != 'all') {
args.dev = pref[0];
args.device = '';
} else {
// 'all' means no dev/device filtering at all.
args.dev = '';
args.device = '';
}
} else {
// If filterDevice does not exist or is empty value, use default
// filtering according to actual_platform and actual_formfactor.
args.dev = actual_platform;
args.device = actual_formfactor;
}
args.limit = limit;
if (actual_platform === 'firefoxos' &&
actual_platform === args.dev &&
actual_formfactor === args.device &&
_.indexOf(ENDPOINTS_WITH_FEATURE_PROFILE, endpoint) >= 0) {
/*
Include feature profile, but only if we:
Are using a Firefox OS device.
Aren't showing 'all apps'.
Are dealing with endpoint that can handle feature profile.
*/
args.pro = feature_profile;
}
return args;
}

return {
DEVICE_CHOICES: DEVICE_CHOICES,
DEVICE_FILTER_CHOICES: DEVICE_FILTER_CHOICES,
apiArgs: apiArgs,
feature_profile: feature_profile,
isDeviceSelected: isDeviceSelected,
limit: limit,
};
});
164 changes: 0 additions & 164 deletions src/media/js/compatibility_filtering.js

This file was deleted.

19 changes: 0 additions & 19 deletions src/media/js/compatibility_filtering_select.js

This file was deleted.

8 changes: 4 additions & 4 deletions src/media/js/helpers_local.js
@@ -1,9 +1,9 @@
define('helpers_local',
['apps', 'categories', 'compatibility_filtering', 'content-ratings',
['apps', 'categories', 'compat_filter', 'content-ratings',
'core/format', 'core/helpers', 'core/models', 'core/nunjucks',
'core/settings', 'core/urls', 'core/utils', 'core/z', 'feed', 'regions',
'user_helpers', 'utils_local'],
function(apps, categories, compatibility_filtering, iarc,
function(apps, categories, compat_filter, iarc,
format, base_helpers, models, nunjucks,
settings, urls, utils, z, feed, regions,
user_helpers, utils_local) {
Expand Down Expand Up @@ -94,14 +94,14 @@ define('helpers_local',

/* Global variables, provided in default context. */
globals.CATEGORIES = categories;
globals.DEVICE_CHOICES = compatibility_filtering.DEVICE_CHOICES;
globals.DEVICE_CHOICES = compat_filter.DEVICE_CHOICES;
globals.feed = feed;
globals.iarc_names = iarc.names;
globals.NEWSLETTER_LANGUAGES = settings.NEWSLETTER_LANGUAGES;
globals.REGIONS = regions.REGION_CHOICES_SLUG;
globals.user_helpers = user_helpers;
globals.PLACEHOLDER_ICON = urls.media('fireplace/img/icons/placeholder.svg');
globals.compatibility_filtering = compatibility_filtering;
globals.compat_filter = compat_filter;

/* Helpers functions, provided in the default context. */
function indexOf(arr, val) {
Expand Down

0 comments on commit 2080dac

Please sign in to comment.