From b615df5124e97738365d701e4cfde064e512a484 Mon Sep 17 00:00:00 2001 From: Joe Fiorini Date: Fri, 29 May 2015 17:05:04 -0400 Subject: [PATCH] Display error messages when no scan jobs are found --- .../js/system-tracking/compare-facts/flat.js | 34 +--- .../system-tracking.controller.js | 75 +++++++-- .../system-tracking.partial.html | 150 +++++++++--------- 3 files changed, 145 insertions(+), 114 deletions(-) diff --git a/awx/ui/static/js/system-tracking/compare-facts/flat.js b/awx/ui/static/js/system-tracking/compare-facts/flat.js index da64984389..5354d94c32 100644 --- a/awx/ui/static/js/system-tracking/compare-facts/flat.js +++ b/awx/ui/static/js/system-tracking/compare-facts/flat.js @@ -7,38 +7,8 @@ export default function flatCompare(facts, nameKey, compareKeys) { - // Make sure we always start comparison against - // a non-empty array - // - // Partition with _.isEmpty will give me an array - // with empty arrays in index 0, and non-empty - // arrays in index 1 - // - - // Save the position of the data so we - // don't lose it later - - facts[0].position = 'left'; - facts[1].position = 'right'; - - var splitFacts = _.partition(facts, _.isEmpty); - var emptyScans = splitFacts[0]; - var nonEmptyScans = splitFacts[1]; - var basisFacts, comparatorFacts; - - if (_.isEmpty(nonEmptyScans)) { - // we have NO data, so don't bother! - return []; - } else if (_.isEmpty(emptyScans)) { - // both scans have facts, rejoice! - comparatorFacts = nonEmptyScans[0]; - basisFacts = nonEmptyScans[1]; - } else { - // only one scan has facts, so we use that - // as the basis for our comparison - basisFacts = nonEmptyScans[0]; - comparatorFacts = []; - } + var comparatorFacts = facts[0]; + var basisFacts = facts[1]; return basisFacts.reduce(function(arr, basisFact) { var searcher = {}; diff --git a/awx/ui/static/js/system-tracking/system-tracking.controller.js b/awx/ui/static/js/system-tracking/system-tracking.controller.js index 50877c6a16..da1a249664 100644 --- a/awx/ui/static/js/system-tracking/system-tracking.controller.js +++ b/awx/ui/static/js/system-tracking/system-tracking.controller.js @@ -51,12 +51,15 @@ function controller($rootScope, } function reloadData(params, initialData) { + searchConfig = _.merge({}, searchConfig, params); var factData = initialData; var leftRange = searchConfig.leftRange; var rightRange = searchConfig.rightRange; var activeModule = searchConfig.module; + var leftScanDate, rightScanDate; + if (!factData) { factData = @@ -69,8 +72,8 @@ function controller($rootScope, var responses = factDataAndModules[1]; var data = _.pluck(responses, 'fact'); - $scope.leftScanDate = moment(responses[0].timestamp); - $scope.rightScanDate = moment(responses[1].timestamp); + leftScanDate = moment(responses[0].timestamp); + rightScanDate = moment(responses[1].timestamp); return data; }, true); @@ -78,18 +81,62 @@ function controller($rootScope, waitIndicator('start'); - _(factData) - .thenAll(_.partial(compareFacts, activeModule)) + return _(factData) + .thenAll(function(facts) { + // Make sure we always start comparison against + // a non-empty array + // + // Partition with _.isEmpty will give me an array + // with empty arrays in index 0, and non-empty + // arrays in index 1 + // + + // Save the position of the data so we + // don't lose it later + + facts[0].position = 'left'; + facts[1].position = 'right'; + + var splitFacts = _.partition(facts, _.isEmpty); + var emptyScans = splitFacts[0]; + var nonEmptyScans = splitFacts[1]; + + if (_.isEmpty(nonEmptyScans)) { + // we have NO data, throw an error + throw { + name: 'NoScanData', + message: 'No scans ran on eithr of the dates you selected. Please try selecting different dates.', + dateValues: + { leftDate: $scope.leftDate.clone(), + rightDate: $scope.rightDate.clone() + } + }; + } else if (nonEmptyScans.length === 1) { + // one of them is not empty, throw an error + throw { + name: 'InsufficientScanData', + message: 'No scans ran on one of the selected dates. Please try selecting a different date.', + dateValue: emptyScans[0].position === 'left' ? $scope.leftDate.clone() : $scope.rightDate.clone() + }; + } + + // all scans have data, rejoice! + return facts; + + }) + .then(_.partial(compareFacts, activeModule)) .then(function(info) { + // Clear out any errors from the previous run... + $scope.error = null; + $scope.factData = info; - setHeaderValues(viewType); + setHeaderValues(viewType, leftScanDate, rightScanDate); }).finally(function() { waitIndicator('stop'); - }) - .value(); + }); } $scope.setActiveModule = function(newModuleName, initialData) { @@ -107,9 +154,12 @@ function controller($rootScope, $location.replace(); $location.search('module', newModuleName); - reloadData( - { module: newModule - }, initialData); + reloadData({ module: newModule + }, initialData) + + .catch(function(error) { + $scope.error = error; + }).value(); }; function dateWatcher(dateProperty) { @@ -128,7 +178,10 @@ function controller($rootScope, var params = {}; params[dateProperty] = newDate; - reloadData(params); + reloadData(params) + .catch(function(error) { + $scope.error = error; + }).value(); }; } diff --git a/awx/ui/static/js/system-tracking/system-tracking.partial.html b/awx/ui/static/js/system-tracking/system-tracking.partial.html index 3c7bb10a63..ab3732d5c8 100644 --- a/awx/ui/static/js/system-tracking/system-tracking.partial.html +++ b/awx/ui/static/js/system-tracking/system-tracking.partial.html @@ -1,84 +1,92 @@ - - - - - +
+ + + + + -
-
- {{ factModulePickersLabelLeft }} - -
-
- {{ factModulePickersLabelRight }} - -
-
- - - -
-

- There were no facts collected for that module in the selected date range. Please pick a different range or module and try again. -

-
-
-
-

{{comparisonLeftHeader|stringOrDate:'L LT'}}

-

{{comparisonRightHeader|stringOrDate:'L LT'}}

-
-
-
-

- {{group.displayKeyPath}} -

-

- {{group.displayKeyPath}} -

-

- {{group.displayKeyPath}} -

-
- {{group.displayKeyPath}} -
+
+
+ {{ factModulePickersLabelLeft }} +
-
-
-
-

+

+ {{ factModulePickersLabelRight }} + +
+
+ + + +
+

+ There were no facts collected on the dates you selected ({{error.dateValues.leftDate|amDateFormat:'L'}} and {{error.dateValues.rightDate|amDateFormat:'L'}}). Please pick a different range or module and try again. +

+

+ There were no facts collected on one of the dates you selected ({{error.dateValue|amDateFormat:'L'}}). Please select a different date and try again. +

+

+ To setup or run scan jobs, edit the "{{inventory.name}}" inventory and select "Scan Jobs Templates". +

+
+
+
+

{{comparisonLeftHeader|stringOrDate:'L LT'}}

+

{{comparisonRightHeader|stringOrDate:'L LT'}}

+
+
+
+

+ {{group.displayKeyPath}} +

+

+ {{group.displayKeyPath}} +

+

+ {{group.displayKeyPath}} +

+
+ {{group.displayKeyPath}} +
+
+
+
+
+

+ {{fact.keyName}} +

+

+ {{fact.value1}} +

+

+ {{fact.value2}} +

+
+
+
+

{{fact.keyName}}

-

+

{{fact.value1}}

-

+

{{fact.value2}}

-
-

- {{fact.keyName}} -

-

- {{fact.value1}} -

-

- {{fact.value2}} -

-
-
+