From d41b8a363fd23fa07f3edced8767bac11cbd5dcc Mon Sep 17 00:00:00 2001 From: Joe Fiorini Date: Thu, 2 Jul 2015 16:02:07 -0400 Subject: [PATCH] [system_tracking] Display all facts for latest scan when no diffs --- .../js/system-tracking/compare-facts/main.js | 4 +- .../fact-data-table.directive.js | 1 + .../fact-data-table.partial.html | 9 ++- .../static/js/system-tracking/format-facts.js | 13 +++ .../system-tracking.controller.js | 81 ++++++++++++++++--- .../system-tracking.partial.html | 1 + 6 files changed, 96 insertions(+), 13 deletions(-) create mode 100644 awx/ui/static/js/system-tracking/format-facts.js diff --git a/awx/ui/static/js/system-tracking/compare-facts/main.js b/awx/ui/static/js/system-tracking/compare-facts/main.js index e7927df005..404a6b04a1 100644 --- a/awx/ui/static/js/system-tracking/compare-facts/main.js +++ b/awx/ui/static/js/system-tracking/compare-facts/main.js @@ -41,7 +41,9 @@ export function compareFacts(module, facts) { .unique('displayKeyPath') .thru(function(result) { return { factData: result, - isNestedDisplay: _.isPlainObject(renderOptions.factTemplate) + isNestedDisplay: _.isPlainObject(renderOptions.factTemplate), + leftData: facts[0].facts, + rightData: facts[1].facts }; }) .value(); diff --git a/awx/ui/static/js/system-tracking/fact-data-table/fact-data-table.directive.js b/awx/ui/static/js/system-tracking/fact-data-table/fact-data-table.directive.js index 3bf944d13e..21f157d3ff 100644 --- a/awx/ui/static/js/system-tracking/fact-data-table/fact-data-table.directive.js +++ b/awx/ui/static/js/system-tracking/fact-data-table/fact-data-table.directive.js @@ -12,6 +12,7 @@ export default leftDataNoScans: '=', rightDataNoScans: '=', isNestedDisplay: '=', + singleResultView: '=', factData: '=' } }; diff --git a/awx/ui/static/js/system-tracking/fact-data-table/fact-data-table.partial.html b/awx/ui/static/js/system-tracking/fact-data-table/fact-data-table.partial.html index e937b95c86..cbd101ac89 100644 --- a/awx/ui/static/js/system-tracking/fact-data-table/fact-data-table.partial.html +++ b/awx/ui/static/js/system-tracking/fact-data-table/fact-data-table.partial.html @@ -1,4 +1,7 @@
+
+ The selected fact scans were identical for this module. Showing all facts from the latest selected scan instead. +

@@ -10,7 +13,7 @@ {{leftHostname}} {{leftScanDate|longDate}}

-

+

No scans for {{rightHostname}} on {{rightHostname}} {{rightScanDate|longDate}} @@ -25,7 +28,7 @@ {{value}} - + {{value}} @@ -34,7 +37,7 @@
{{group.facts.keyName}} {{group.facts.value1}} - {{group.facts.value2}} + {{group.facts.value2}}

diff --git a/awx/ui/static/js/system-tracking/format-facts.js b/awx/ui/static/js/system-tracking/format-facts.js new file mode 100644 index 0000000000..32ff9fed6c --- /dev/null +++ b/awx/ui/static/js/system-tracking/format-facts.js @@ -0,0 +1,13 @@ +export function formatFactForDisplay(fact, renderOptions) { + + var factTemplate = renderOptions.factTemplate; + + var template = factTemplate; + + // if (!renderOptions.supportsValueArray) { + // comparatorFact = comparatorFact[0]; + // } + + return template.render(fact); + +} 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 a413fa11e2..29bc7e40f6 100644 --- a/awx/ui/static/js/system-tracking/system-tracking.controller.js +++ b/awx/ui/static/js/system-tracking/system-tracking.controller.js @@ -6,6 +6,8 @@ import {searchDateRange} from './search-date-range'; import {compareFacts} from './compare-facts/main'; +import {formatFactForDisplay} from './format-facts'; +import FactTemplate from './compare-facts/fact-template'; function controller($rootScope, $scope, @@ -75,6 +77,8 @@ function controller($rootScope, $scope.leftDateWarning = false; $scope.rightDateWarning = false; + $scope.singleFactOnly = false; + waitIndicator('start'); return getDataForComparison( @@ -173,17 +177,76 @@ function controller($rootScope, $scope.error = null; if (_.isEmpty(info.factData)) { - info = _.reject({ - name: 'NoScanDifferences', - message: 'No differences in the scans on the dates you selected. Please try selecting different dates.', - dateValues: - { leftDate: $scope.leftDate.clone(), - rightDate: $scope.rightDate.clone() - } + // info = _.reject({ + // name: 'NoScanDifferences', + // message: 'No differences in the scans on the dates you selected. Please try selecting different dates.', + // dateValues: + // { leftDate: $scope.leftDate.clone(), + // rightDate: $scope.rightDate.clone() + // } + // }); + $scope.singleFactOnly = true; + $scope.factData = info.leftData.map(function(fact) { + var keyNameMap = activeModule.keyNameMap; + var nameKey = activeModule.nameKey; + var renderOptions = _.merge({}, activeModule); + var isNestedDisplay = false; + var facts; + + if (_.isObject(renderOptions.factTemplate) && + _.isArray(renderOptions.compareKey)) { + + isNestedDisplay = true; + + var templates = _.mapValues(renderOptions.factTemplate, function(template, key) { + if (template === true) { + return { render: function(fact) { + return fact[key]; + } + }; + } else { + return new FactTemplate(template); + } + }); + + facts = _.map(templates, function(template, key) { + var keyName = key; + + if (_.isObject(keyNameMap) && keyNameMap.hasOwnProperty(key)) { + keyName = keyNameMap[key]; + } + + renderOptions.factTemplate = template; + var formattedValue = formatFactForDisplay(fact, renderOptions); + return { keyName: keyName, + isNestedDisplay: true, + value1: formattedValue + }; + }); + + + } else { + renderOptions.factTemplate = new FactTemplate(renderOptions.factTemplate); + var formattedValue = formatFactForDisplay(fact, renderOptions); + isNestedDisplay = false; + facts = { keyName: fact[nameKey], + value1: formattedValue + }; + } + + $scope.isNestedDisplay = isNestedDisplay; + + return { displayKeyPath: fact[renderOptions.nameKey], + nestingLevel: 0, + containsValueArray: false, + facts: facts + }; }); + } else { + $scope.singleFactOnly = false; + $scope.factData = info.factData; + $scope.isNestedDisplay = info.isNestedDisplay; } - $scope.factData = info.factData; - $scope.isNestedDisplay = info.isNestedDisplay; return info; 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 4f762b3c96..cefe3bd7e1 100644 --- a/awx/ui/static/js/system-tracking/system-tracking.partial.html +++ b/awx/ui/static/js/system-tracking/system-tracking.partial.html @@ -87,6 +87,7 @@ left-data-no-scans="leftDataNoScans" right-data-no-scans="rightDataNoScans" is-nested-display="isNestedDisplay" + single-result-view="singleFactOnly" fact-data="factData">