gui: Show Javascript error indicator on dev builds, remove logging of missing translations

This commit is contained in:
Lars K.W. Gohlke 2016-04-05 06:36:53 +00:00 committed by Jakob Borg
parent 181939c841
commit 492e92d65d
8 changed files with 68 additions and 54 deletions

View File

@ -0,0 +1,12 @@
.dev-top-bar{
display: none;
background-color: yellow;
}
.dev-error .hasCount{
background-color: red;
}
.dev-warn .hasCount{
background-color: yellow;
}

View File

@ -26,6 +26,8 @@
</head> </head>
<body> <body>
<script src="syncthing/development/logbar.js"></script>
<div ng-if="version.isDevelopmentVersion" ng-include="'syncthing/development/logbar.html'"></div>
<!-- Top bar --> <!-- Top bar -->
<nav class="navbar navbar-top navbar-default" role="navigation"> <nav class="navbar navbar-top navbar-default" role="navigation">
@ -602,7 +604,6 @@
<script src="vendor/jquery/jquery-2.2.2.js"></script> <script src="vendor/jquery/jquery-2.2.2.js"></script>
<script src="vendor/angular/angular.js"></script> <script src="vendor/angular/angular.js"></script>
<script src="vendor/angular/angular-translate.js"></script> <script src="vendor/angular/angular-translate.js"></script>
<script src="vendor/angular/angular-translate-handler-log.js"></script>
<script src="vendor/angular/angular-translate-loader-static-files.js"></script> <script src="vendor/angular/angular-translate-loader-static-files.js"></script>
<script src="vendor/angular/angular-dirPagination.js"></script> <script src="vendor/angular/angular-dirPagination.js"></script>
<script src="vendor/bootstrap/js/bootstrap.js"></script> <script src="vendor/bootstrap/js/bootstrap.js"></script>

View File

@ -56,7 +56,6 @@ syncthing.config(function ($httpProvider, $translateProvider, LocaleServiceProvi
prefix: 'assets/lang/lang-', prefix: 'assets/lang/lang-',
suffix: '.json' suffix: '.json'
}); });
$translateProvider.useMissingTranslationHandlerLog();
LocaleServiceProvider.setAvailableLocales(validLangs); LocaleServiceProvider.setAvailableLocales(validLangs);
LocaleServiceProvider.setDefaultLocale('en'); LocaleServiceProvider.setDefaultLocale('en');

View File

@ -97,6 +97,7 @@ angular.module('syncthing.core')
} }
$scope.version = data; $scope.version = data;
$scope.version.isDevelopmentVersion = data.version.indexOf('-')>0;
}).error($scope.emitHTTPError); }).error($scope.emitHTTPError);
$http.get(urlbase + '/svc/report').success(function (data) { $http.get(urlbase + '/svc/report').success(function (data) {
@ -810,7 +811,7 @@ angular.module('syncthing.core')
}; };
$scope.deviceName = function (deviceCfg) { $scope.deviceName = function (deviceCfg) {
if (typeof deviceCfg === 'undefined') { if (typeof deviceCfg === 'undefined' || typeof deviceCfg.deviceID === 'undefined') {
return ""; return "";
} }
if (deviceCfg.name) { if (deviceCfg.name) {

View File

@ -0,0 +1,13 @@
<div class="dev-top-bar" id="dev-top-bar">
<link href="assets/css/dev.css" rel="stylesheet">
<div class="row">
<div class="col-xs-4"><b>DEV</b></div>
<div id="log" class="col-xs-8">
<span>
JS:
<span class="dev-error fa fa-exclamation-triangle"> errors <span id="log_error">0</span></span>
<span class="dev-warn fa fa-frown-o"> warn <span id="log_warn">0</span></span>
</span>
</div>
</div>
</div>

View File

@ -0,0 +1,39 @@
'use strict';
function intercept(method, handler) {
var console = window.console;
var original = console[method];
console[method] = function () {
handler(method);
// do sneaky stuff
if (original.apply) {
// Do this for normal browsers
original.apply(console, arguments);
} else {
// Do this for IE
var message = Array.prototype.slice.apply(arguments).join(' ');
original(message);
}
};
}
function handleConsoleCall(type) {
var element = document.querySelector('#log_' + type);
if (element) {
if (!element.classList.contains("hasCount")) {
element.classList.add("hasCount");
}
var devTopBar = document.querySelector('#dev-top-bar');
devTopBar.style.display = 'block';
element.innerHTML = parseInt(element.innerHTML) + 1;
}
}
if (window.console) {
var methods = ['error', 'warn'];
for (var i = 0; i < methods.length; i++) {
intercept(methods[i], handleConsoleCall);
}
}

View File

@ -3,5 +3,4 @@ The files contained herein are:
- angular 1.5.3 - angular 1.5.3
- angular-translate 2.9.0.1 - angular-translate 2.9.0.1
- angular-translate-loader-static-files 2.11.0 - angular-translate-loader-static-files 2.11.0
- angular-translate-handler-log 2.11.0
- angular-dirPagination 759009c - angular-dirPagination 759009c

View File

@ -1,50 +0,0 @@
/*!
* angular-translate - v2.11.0 - 2016-03-20
*
* Copyright (c) 2016 The angular-translate team, Pascal Precht; Licensed MIT
*/
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module unless amdModuleId is set
define([], function () {
return (factory());
});
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory();
} else {
factory();
}
}(this, function () {
$translateMissingTranslationHandlerLog.$inject = ['$log'];
angular.module('pascalprecht.translate')
/**
* @ngdoc object
* @name pascalprecht.translate.$translateMissingTranslationHandlerLog
* @requires $log
*
* @description
* Uses angular's `$log` service to give a warning when trying to translate a
* translation id which doesn't exist.
*
* @returns {function} Handler function
*/
.factory('$translateMissingTranslationHandlerLog', $translateMissingTranslationHandlerLog);
function $translateMissingTranslationHandlerLog ($log) {
'use strict';
return function (translationId) {
$log.warn('Translation for ' + translationId + ' doesn\'t exist');
};
}
$translateMissingTranslationHandlerLog.displayName = '$translateMissingTranslationHandlerLog';
return 'pascalprecht.translate';
}));