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

Commit

Permalink
pretty debug pages
Browse files Browse the repository at this point in the history
  • Loading branch information
ngokevin committed Mar 6, 2015
1 parent 6cecc4c commit a4ef033
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 140 deletions.
1 change: 1 addition & 0 deletions src/dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<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/debug.styl.css">
<link rel="stylesheet" href="/media/css/desktop-promo.styl.css">
<link rel="stylesheet" href="/media/css/detail/base.styl.css">
<link rel="stylesheet" href="/media/css/detail/content-ratings.styl.css">
Expand Down
56 changes: 56 additions & 0 deletions src/media/css/debug.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
@import 'lib';

.debug {
.button {
display: inline-block;
margin: 5px 0;
width: 100%;
}
div > h3 {
_h3();
margin-bottom: 30px;
}
dl {
margin-left: 0;
}
dt {
clear: left;
margin-bottom: 5px;
display: block;
}
dd {
margin-bottom: 20px;
}
label {
display: inline-block;
font-size: 18px;
margin-top: 20px;
}
select {
display: block;
margin: 10px 0;
width: 100%;
}
}

.debug-features {
div > h3 {
_h3();
margin-bottom: 30px;
}
.present {
background: $action-success;
}
.absent {
background: $action-error;
}
dt {
color: $greyscale-white;
font-weight: 500;
margin: 35px 0 10px;
padding: 10px 0 10px 5px;
}
dd {
type_body();
}
}
93 changes: 59 additions & 34 deletions src/media/js/views/debug.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,69 @@
define('views/debug',
['core/cache', 'core/capabilities', 'compatibility_filtering', 'core/log', 'core/models', 'core/notification', 'regions', 'core/requests', 'core/settings', 'core/storage', 'core/user', 'core/utils', 'core/z'],
function(cache, capabilities, compatibility_filtering, log, models, notification, regions, requests, settings, storage, user, utils, z) {
['core/cache', 'core/capabilities', 'compatibility_filtering', 'core/log',
'core/models', 'core/notification', 'core/requests', 'core/settings',
'core/storage', 'core/user', 'core/utils', 'core/z', 'regions'],
function(cache, capabilities, compatibility_filtering, log,
models, notification, requests, settings,
storage, user, utils, z, regions) {
'use strict';

var persistent_console_debug = log.persistent('debug', 'change');
var persistent_console_network = log.persistent('mobilenetwork', 'change');

var label = $(document.getElementById('debug-status'));

z.doc.on('click', '#clear-localstorage', function(e) {
storage.clear();
notification.notification({message: 'localStorage cleared', timeout: 1000});
notification.notification({message: 'localStorage cleared',
timeout: 1000});
})

}).on('click', '#enable-offline-cache', function() {
.on('click', '#enable-offline-cache', function() {
storage.removeItem('offline_cache_disabled');
persistent_console_debug.log('Offline cache enabled:', new Date());
require('views').reload();
notification.notification({message: 'Offline cache enabled', timeout: 1000});
notification.notification({message: 'Offline cache enabled',
timeout: 1000});
})

}).on('click', '#disable-offline-cache', function() {
.on('click', '#disable-offline-cache', function() {
storage.setItem('offline_cache_disabled', 1);
persistent_console_debug.log('Offline cache disabled:', new Date());
require('views').reload();
notification.notification({message: 'Offline cache disabled', timeout: 1000});
notification.notification({message: 'Offline cache disabled',
timeout: 1000});
})

}).on('click', '#clear-offline-cache', function() {
.on('click', '#clear-offline-cache', function() {
cache.flush();
// This actually flushes all model caches.
models('app').flush();
persistent_console_debug.log('Offline cache cleared:', new Date());
notification.notification({message: 'Offline cache cleared', timeout: 1000});
notification.notification({message: 'Offline cache cleared',
timeout: 1000});
window.location.reload();

}).on('click', '#clear-cookies', function() {
})

.on('click', '#clear-cookies', function() {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var e = cookies[i].indexOf('=');
var name = e > -1 ? cookies[i].substr(0, e) : c[i];
document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:00 GMT';
}
notification.notification({message: 'cookies cleared', timeout: 1000});
notification.notification({message: 'Cookies cleared', timeout: 1000});
})

}).on('click', '#nukecounter', function(e) {
storage.removeItem('newscounter');
notification.notification({message: 'newscounter reset', timeout: 1000});

}).on('click', '.cache-menu a', function(e) {
.on('click', '.cache-menu a', function(e) {
e.preventDefault();
var data = cache.get($(this).data('url'));
data = JSON.stringify(data, null, ' ');
$('#cache-inspector').html(utils.escape_(data));

}).on('click', '#submit-debug', function(e) {
})

.on('click', '#submit-debug', function(e) {
e.preventDefault();
var data = {body: JSON.stringify({
app: settings.app_name,
Expand All @@ -62,48 +75,60 @@ define('views/debug',
report_version: 1.0,
profile: compatibility_filtering.feature_profile
})};
requests.post('https://ashes.paas.allizom.org/post_report', data).done(function(data) {
notification.notification({
message: 'ID: ' + data.id,
timeout: 30000
});

var ashesUrl = 'https://ashes.paas.allizom.org/post_report';
requests.post(ashesUrl, data).done(function(data) {
notification.notification({message: 'Logs uploaded: ' + data.id,
timeout: 30000});
});
})

}).on('change', '#debug-page select[name=region]', function(e) {
.on('change', '#debug-page select[name=region]', function(e) {
var val = $(this).val();
var current_region = user.get_setting('region_override');
if (current_region !== val) {
persistent_console_network.log('Manual region override change:', current_region, '→', val);
persistent_console_network.log('Manual region override change:',
current_region, '→', val);
}
user.update_settings({region_override: val});
z.page.trigger('reload_chrome');
notification.notification({message: 'Region updated to ' + (regions.REGION_CHOICES_SLUG[val] || '---')});
notification.notification({
message: 'Region updated to ' +
(regions.REGION_CHOICES_SLUG[val] || '---')});
})

}).on('change', '#debug-page select[name=carrier]', function(e) {
.on('change', '#debug-page select[name=carrier]', function(e) {
var val = $(this).val();
var current_carrier = user.get_setting('carrier_override');
if (current_carrier !== val) {
persistent_console_network.log('Manual carrier override change:', current_carrier, '→', val);
persistent_console_network.log('Manual carrier override change:',
current_carrier, '→', val);
}
user.update_settings({carrier_override: val});
z.page.trigger('reload_chrome');
notification.notification({message: 'Carrier updated to ' + val});
});

function callIfFunction(val) {
if (typeof(val) == 'function') {
return val();
}
return val;
}

return function(builder, args) {
var recent_logs = log.get_recent(100);
builder.z('type', 'leaf debug');

builder.start('debug.html', {
carriers: require('mobilenetwork').carriers,
cache: cache.raw,
callIfFunction: callIfFunction,
capabilities: capabilities,
profile: compatibility_filtering.feature_profile,
recent_logs: recent_logs,
persistent_logs: log.persistent.all,
carriers: require('mobilenetwork').carriers,
filter: log.filter,
persistent_logs: log.persistent.all,
profile: compatibility_filtering.feature_profile,
recent_logs: log.get_recent(100),
request_cache: storage.getItem('request_cache') || {}
});

builder.z('type', 'leaf debug');
};
});

0 comments on commit a4ef033

Please sign in to comment.