Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id 3D120E00930; Wed, 10 Dec 2014 02:57:11 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on yocto-www.yoctoproject.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-HAM-Report: * -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] * -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low * trust * [74.125.82.47 listed in list.dnswl.org] Received: from mail-wg0-f47.google.com (mail-wg0-f47.google.com [74.125.82.47]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id 8D994E00922 for ; Wed, 10 Dec 2014 02:57:07 -0800 (PST) Received: by mail-wg0-f47.google.com with SMTP id n12so3254692wgh.20 for ; Wed, 10 Dec 2014 02:57:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=peVfh2KLTsST1AQ/h2DaZqVGF24je9P9hl2MgxQqeBI=; b=B9iiBgqs2vQldqSOAT3TXhKhd0r6vPaDroYX1dcGuTXUANblSwFAV92yh64325JLYY PCY1pDzMCe3KpvFDIKQDj9bo5okfZAmsrNq7u0UYDUxt9//jCXJw5sXniE0mApEKB6c0 L7CkYIC+PDNrtkkQ6ZwcluEGdHxScw9YnuPFrUQQjyv1YEeyDAZ32FmVfeZ1E1KfRe0L 1yWl8ortvgZXVhEwbt339F5ST53xGfMPgkoJHlrhs3hkt8DVzrslOEhFr06Oe9DLNJJs Nyk+bN2utgfXVXXfpv4kTi0w7bQ4BC82Fq1x7KMTOdHn2Zfi7RF/lKOQQBRSr7VxLa7Q maTg== X-Gm-Message-State: ALoCoQkTv/npD7z/fzQEtUUvNj4Z+BiAeSJG9YS8FHUTb/OGpx+PHRhQkaU5wRG7ntZX/ZCQzman X-Received: by 10.180.211.108 with SMTP id nb12mr5349443wic.76.1418209025575; Wed, 10 Dec 2014 02:57:05 -0800 (PST) Received: from draco.icx.intel.com ([83.217.123.106]) by mx.google.com with ESMTPSA id a14sm17421447wib.22.2014.12.10.02.57.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 10 Dec 2014 02:57:05 -0800 (PST) From: Michael Wood To: toaster@yoctoproject.org Date: Wed, 10 Dec 2014 10:57:01 +0000 Message-Id: <1418209021-18671-1-git-send-email-michael.g.wood@intel.com> X-Mailer: git-send-email 2.1.0 Subject: [review-request][PATCH] bitbake: toaster: Improve client side error handling X-BeenThere: toaster@yoctoproject.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Web based interface for BitBake List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Dec 2014 10:57:11 -0000 Make use of the toastermain.settings.DEBUG flag to toggle the client side error logging. Make the error logging consistent by using console.warn/error across the project, this adds traceability to the warnings. Also handles the case where console is not available by stubbing it in libtoaster. Signed-off-by: Michael Wood --- .../lib/toaster/toastergui/static/js/libtoaster.js | 39 +++++++++++++++++++--- .../lib/toaster/toastergui/static/js/projectapp.js | 28 ++++++++-------- bitbake/lib/toaster/toastergui/templates/base.html | 5 +++ .../lib/toaster/toastergui/templates/layers.html | 8 ++--- .../toaster/toastergui/templates/mrb_section.html | 8 ++--- .../lib/toaster/toastergui/templates/targets.html | 8 ++--- bitbake/lib/toaster/toastergui/views.py | 6 ++-- 7 files changed, 69 insertions(+), 33 deletions(-) diff --git a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js index 37fc80e..390a63c 100644 --- a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js +++ b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js @@ -76,14 +76,14 @@ var libtoaster = (function (){ headers: { 'X-CSRFToken' : $.cookie('csrftoken')}, success: function (_data) { if (_data.error != "ok") { - console.log(_data.error); + console.warn(_data.error); } else { if (onsuccess != undefined) onsuccess(_data); } }, error: function (_data) { - console.log("Call failed"); - console.log(_data); + console.warn("Call failed"); + console.warn(_data); if (onfail) onfail(data); } }); }; @@ -97,13 +97,13 @@ var libtoaster = (function (){ headers: { 'X-CSRFToken' : $.cookie('csrftoken')}, success: function (_data) { if (_data.error != "ok") { - console.log(_data.error); + console.warn(_data.error); } else { if (onsuccess != undefined) onsuccess(_data); } }, error: function (_data) { - console.log(_data); + console.warn(_data); if (onfail) onfail(data); } }); @@ -114,6 +114,7 @@ var libtoaster = (function (){ startABuild : _startABuild, makeTypeahead : _makeTypeahead, getProjectInfo: _getProjectInfo, + debug: false, } })(); @@ -149,6 +150,15 @@ function reload_params(params) { /* Things that happen for all pages */ $(document).ready(function() { + /* If we don't have a console object which might be the case in some + * browsers, no-op it to avoid undefined errors. + */ + if (!window.console) { + window.console = {}; + window.console.warn = function() {}; + window.console.error = function() {}; + } + /* * PrettyPrint plugin. * @@ -266,4 +276,23 @@ $(document).ready(function() { if (location.href.search('#warnings') > -1) { $('#collapse-warnings').addClass('in'); } + + function check_for_duplicate_ids () { + /* warn about duplicate element ids */ + var ids = {}; + $("[id]").each(function() { + if (this.id && ids[this.id]) { + console.warn('Duplicate element id #'+this.id); + } + ids[this.id] = true; + }); + } + + if (libtoaster.debug) { + check_for_duplicate_ids(); + } else { + /* Debug is false so supress warnings by overriding the functions */ + window.console.warn = function () {}; + window.console.error = function () {}; + } }); diff --git a/bitbake/lib/toaster/toastergui/static/js/projectapp.js b/bitbake/lib/toaster/toastergui/static/js/projectapp.js index e9b07c7..411a184 100644 --- a/bitbake/lib/toaster/toastergui/static/js/projectapp.js +++ b/bitbake/lib/toaster/toastergui/static/js/projectapp.js @@ -136,7 +136,7 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc $http({method:"GET", url: $scope.urls.xhr_datatypeahead, params : { type: type, value: currentValue}}) .success(function (_data) { if (_data.error != "ok") { - alert(_data.error); + console.warn(_data.error); deffered.reject(_data.error); } deffered.resolve(_data.list); @@ -152,12 +152,12 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc if (inXHRcall) { if (callparams.data === undefined) { // we simply skip the data refresh calls - console.log("race on XHR, aborted"); + console.warn("race on XHR, aborted"); return; } else { // we return a promise that we'll solve by reissuing the command later var delayed = $q.defer(); - console.log("race on XHR, delayed"); + console.warn("race on XHR, delayed"); $interval(function () {$scope._makeXHRCall(callparams).then(function (d) { delayed.resolve(d); });}, 100, 1); return delayed.promise; @@ -171,7 +171,7 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc $http(callparams).success(function(_data, _status, _headers, _config) { if (_data.error != "ok") { - alert("Failed XHR request (" + _status + "): " + _data.error); + console.warn("Failed XHR request (" + _status + "): " + _data.error); console.error("Failed XHR request: ", _data, _status, _headers, _config); // stop refreshing hte page $interval.cancel($scope.pollHandle); @@ -267,7 +267,7 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc deffered.resolve(_data); } }).error(function(_data, _status, _headers, _config) { - alert("Failed HTTP XHR request (" + _status + ")" + _data); + console.warn("Failed HTTP XHR request (" + _status + ")" + _data); console.error("Failed HTTP XHR request: ", _data, _status, _headers, _config); inXHRcall = false; deffered.reject(_data.error); @@ -298,7 +298,7 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc $scope.targetNamedBuild = function(target) { if ($scope.targetName === undefined && $scope.targetName1 === undefined){ - alert("No target defined, please type in a target name"); + console.warn("No target defined, please type in a target name"); return; } @@ -310,7 +310,7 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc targets: $scope.safeTargetName, } }).then(function (data) { - console.log("received ", data); + console.warn("received ", data); $scope.targetName = undefined; $scope.targetName1 = undefined; $location.hash('buildslist'); @@ -357,7 +357,7 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc $http({method:"GET", url: $scope.urls.xhr_datatypeahead, params : { type: "layerdeps", value: $scope.layerAddId }}) .success(function (_data) { if (_data.error != "ok") { - alert(_data.error); + console.warn(_data.error); } else { if (_data.list.length > 0) { // activate modal @@ -369,7 +369,7 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc $scope.selectedItems = (function () { s = {}; for (var i = 0; i < items.length; i++) { s[items[i].id] = true; };return s; })(); $scope.ok = function() { - console.log("scope selected is ", $scope.selectedItems); + console.warn("scope selected is ", $scope.selectedItems); $modalInstance.close(Object.keys($scope.selectedItems).filter(function (e) { return $scope.selectedItems[e];})); }; @@ -378,7 +378,7 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc }; $scope.update = function() { - console.log("updated ", $scope.selectedItems); + console.warn("updated ", $scope.selectedItems); }; }, resolve: { @@ -393,7 +393,7 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc modalInstance.result.then(function (selectedArray) { selectedArray.push($scope.layerAddId); - console.log("selected", selectedArray); + console.warn("selected", selectedArray); $scope._makeXHRCall({ method: "POST", url: $scope.urls.xhr_edit, @@ -473,7 +473,7 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc $scope.edit = function(elementid) { var data = {}; - console.log("edit with ", elementid); + console.warn("edit with ", elementid); var alertText = undefined; var alertZone = undefined; var oldLayers = []; @@ -637,7 +637,7 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc */ function test_diff_arrays() { - _diffArrays([1,2,3], [2,3,4], function(e,f) { return e==f; }, function(e) {console.log("added", e)}, function(e) {console.log("deleted", e);}) + _diffArrays([1,2,3], [2,3,4], function(e,f) { return e==f; }, function(e) {console.warn("added", e)}, function(e) {console.warn("deleted", e);}) } // test_diff_arrays(); @@ -647,6 +647,6 @@ var s = undefined; function test_set_alert(text) { s = angular.element("div#main").scope(); s.displayAlert(s.zone3alerts, text); - console.log(s.zone3alerts); + console.warn(s.zone3alerts); s.$digest(); } diff --git a/bitbake/lib/toaster/toastergui/templates/base.html b/bitbake/lib/toaster/toastergui/templates/base.html index 594c495..e828106 100644 --- a/bitbake/lib/toaster/toastergui/templates/base.html +++ b/bitbake/lib/toaster/toastergui/templates/base.html @@ -21,6 +21,11 @@ +{% if DEBUG %} + +{% endif %} {%if MANAGED %}