From 5beb7b1aa0e9c9d9834b4461f4282179c6fad84e Mon Sep 17 00:00:00 2001 From: Joe Fiorini Date: Tue, 2 Jun 2015 12:11:03 -0400 Subject: [PATCH] Display package version string for packages --- awx/ui/static/js/shared/main.js | 6 +- .../js/shared/string-filters/append.filter.js | 10 ++ .../static/js/shared/string-filters/main.js | 7 + .../shared/string-filters/prepend.filter.js | 9 ++ .../js/system-tracking/compare-facts.js | 2 +- .../js/system-tracking/compare-facts/flat.js | 140 +++++++++++++----- .../get-module-options.factory.js | 9 +- .../system-tracking.controller.js | 4 +- .../system-tracking.partial.html | 9 +- 9 files changed, 153 insertions(+), 43 deletions(-) create mode 100644 awx/ui/static/js/shared/string-filters/append.filter.js create mode 100644 awx/ui/static/js/shared/string-filters/main.js create mode 100644 awx/ui/static/js/shared/string-filters/prepend.filter.js diff --git a/awx/ui/static/js/shared/main.js b/awx/ui/static/js/shared/main.js index 8dbe63b7a7..c97aaa774d 100644 --- a/awx/ui/static/js/shared/main.js +++ b/awx/ui/static/js/shared/main.js @@ -7,8 +7,12 @@ import listGenerator from './list-generator/main'; import title from './title.directive'; import lodashAsPromised from './lodash-as-promised'; +import stringFilters from './string-filters/main'; export default - angular.module('shared', [listGenerator.name]) + angular.module('shared', + [ listGenerator.name, + stringFilters.name + ]) .factory('lodashAsPromised', lodashAsPromised) .directive('title', title); diff --git a/awx/ui/static/js/shared/string-filters/append.filter.js b/awx/ui/static/js/shared/string-filters/append.filter.js new file mode 100644 index 0000000000..42860cd499 --- /dev/null +++ b/awx/ui/static/js/shared/string-filters/append.filter.js @@ -0,0 +1,10 @@ +export default function() { + return function(string, append) { + if (string) { + return string + append; + } + + return ""; + }; +} + diff --git a/awx/ui/static/js/shared/string-filters/main.js b/awx/ui/static/js/shared/string-filters/main.js new file mode 100644 index 0000000000..3c51d184d2 --- /dev/null +++ b/awx/ui/static/js/shared/string-filters/main.js @@ -0,0 +1,7 @@ +import prepend from './prepend.filter'; +import append from './append.filter'; + +export default + angular.module('stringFilters', []) + .filter('prepend', prepend) + .filter('append', append); diff --git a/awx/ui/static/js/shared/string-filters/prepend.filter.js b/awx/ui/static/js/shared/string-filters/prepend.filter.js new file mode 100644 index 0000000000..a9d87be94c --- /dev/null +++ b/awx/ui/static/js/shared/string-filters/prepend.filter.js @@ -0,0 +1,9 @@ +export default function() { + return function(string, prepend) { + if (string) { + return prepend + string; + } + + return ""; + }; +} diff --git a/awx/ui/static/js/system-tracking/compare-facts.js b/awx/ui/static/js/system-tracking/compare-facts.js index e3c9721fed..1c57931da6 100644 --- a/awx/ui/static/js/system-tracking/compare-facts.js +++ b/awx/ui/static/js/system-tracking/compare-facts.js @@ -11,6 +11,6 @@ export function compareFacts(module, facts) { if (module.displayType === 'nested') { return compareNestedFacts(facts); } else { - return compareFlatFacts(facts, module.nameKey, module.compareKey); + return compareFlatFacts(facts, module.nameKey, module.compareKey, module.factTemplate); } } 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 5354d94c32..e49f4e02b6 100644 --- a/awx/ui/static/js/system-tracking/compare-facts/flat.js +++ b/awx/ui/static/js/system-tracking/compare-facts/flat.js @@ -4,8 +4,41 @@ * All Rights Reserved *************************************************/ +import stringFilters from 'tower/shared/string-filters/main'; + +var $injector = angular.injector(['ng', stringFilters.name]); +var $interpolate = $injector.get('$interpolate'); + +function parseFactTemplate(factTemplate, fact) { + if (_.isFunction(factTemplate)) { + return factTemplate(fact); + } else { + return factTemplate; + } +} + +function renderFactTemplate(template, fact) { + return $interpolate(template)(fact); +} + +function slotFactValues(basisPosition, basisValue, comparatorValue) { + var leftValue, rightValue; + + if (basisPosition === 'left') { + leftValue = basisValue; + rightValue = comparatorValue; + } else { + rightValue = basisValue; + leftValue = comparatorValue; + } + + return { left: leftValue, + right: rightValue + }; +} + export default - function flatCompare(facts, nameKey, compareKeys) { + function flatCompare(facts, nameKey, compareKeys, factTemplate) { var comparatorFacts = facts[0]; var basisFacts = facts[1]; @@ -14,56 +47,91 @@ export default var searcher = {}; searcher[nameKey] = basisFact[nameKey]; - var isNewFactValue = false; + var isNestedDisplay = false; + var basisTemplate, comparatorTemplate, slottedValues, basisValue, comparatorValue; var matchingFact = _.where(comparatorFacts, searcher); var diffs; if (_.isEmpty(matchingFact)) { - isNewFactValue = true; - diffs = - _.map(basisFact, function(value, key) { - return { keyName: key, - value1: value, - value2: '' - }; - }); + if (!_.isUndefined(factTemplate)) { + + basisTemplate = parseFactTemplate(factTemplate, basisFact); + + basisValue = renderFactTemplate(basisTemplate, basisFact); + slottedValues = slotFactValues(basisFacts.position, basisValue, 'absent'); + + diffs = + { keyName: basisFact[nameKey], + isNestedDisplay: false, + value1: slottedValues.left, + value2: slottedValues.right + }; + + } else { + + isNestedDisplay = true; + diffs = + _.map(basisFact, function(value, key) { + var slottedValues = slotFactValues(basisFacts.position, value, 'absent'); + + return { keyName: key, + value1: slottedValues.left, + value2: slottedValues.right + }; + }); + } } else { + matchingFact = matchingFact[0]; - diffs = _(compareKeys) - .map(function(key) { - var basisValue = basisFact[key]; - var comparatorValue = matchingFact[key]; - var leftValue, rightValue; + if (!_.isUndefined(factTemplate)) { - if (basisFacts.position === 'left') { - leftValue = basisValue; - rightValue = comparatorValue; - } else { - rightValue = basisValue; - leftValue = comparatorValue; - } + basisTemplate = parseFactTemplate(factTemplate, basisFact); + comparatorTemplate = parseFactTemplate(factTemplate, matchingFact); - if (leftValue !== rightValue) { - return { - keyName: key, - value1: leftValue, - value2: rightValue - }; - } - }).compact() - .value(); + basisValue = renderFactTemplate(basisTemplate, basisFact); + comparatorValue = renderFactTemplate(comparatorTemplate, matchingFact); + + slottedValues = slotFactValues(basisFacts.position, basisValue, comparatorValue); + + diffs = + { keyName: basisFact[nameKey], + isNestedDisplay: false, + value1: slottedValues.left, + value2: slottedValues.right + }; + + } else { + + isNestedDisplay = true; + + diffs = _(compareKeys) + .map(function(key) { + var slottedValues = slotFactValues(basisFacts.position, + basisFact[key], + matchingFact[key]); + + if (slottedValues.left !== slottedValues.right) { + return { + keyName: key, + value1: slottedValues.left, + value2: slottedValues.right + }; + } + }).compact() + .value(); + } } var descriptor = - { displayKeyPath: basisFact[nameKey], - isNew: isNewFactValue, - nestingLevel: 0, - facts: diffs - }; + { displayKeyPath: basisFact[nameKey], + isNestedDisplay: isNestedDisplay, + nestingLevel: 0, + facts: diffs + }; return arr.concat(descriptor); }, []).filter(function(diff) { diff --git a/awx/ui/static/js/system-tracking/data-services/get-module-options.factory.js b/awx/ui/static/js/system-tracking/data-services/get-module-options.factory.js index 5ea39f2480..94f1dd1be8 100644 --- a/awx/ui/static/js/system-tracking/data-services/get-module-options.factory.js +++ b/awx/ui/static/js/system-tracking/data-services/get-module-options.factory.js @@ -3,7 +3,14 @@ var moduleConfig = { compareKey: ['release', 'version'], nameKey: 'name', displayType: 'flat', - sortKey: 1 + sortKey: 1, + factTemplate: function(fact) { + if (fact.source === 'deb') { + return "{{version}}-{{architecture}}"; + } else if (fact.source === 'rpm') { + return "{{epoch|append:':'}}{{version}}-{{release}}.{{arch}}"; + } + } }, 'services': { compareKey: ['state', 'source'], 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 6e1c15950e..f6fca4ccde 100644 --- a/awx/ui/static/js/system-tracking/system-tracking.controller.js +++ b/awx/ui/static/js/system-tracking/system-tracking.controller.js @@ -52,7 +52,7 @@ function controller($rootScope, function reloadData(params, initialData) { - searchConfig = _.merge({}, searchConfig, params); + searchConfig = _.assign({}, searchConfig, params); var factData = initialData; var leftRange = searchConfig.leftRange; @@ -124,7 +124,7 @@ function controller($rootScope, return facts; }) - .then(_.partial(compareFacts, activeModule)) + .then(_.partial(compareFacts, _.log('activeModule', activeModule))) .then(function(info) { // Clear out any errors from the previous run... 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 ab3732d5c8..64c770c3b5 100644 --- a/awx/ui/static/js/system-tracking/system-tracking.partial.html +++ b/awx/ui/static/js/system-tracking/system-tracking.partial.html @@ -46,8 +46,13 @@

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

-
-

+
+

{{group.facts.keyName}}

+

{{group.facts.value1}}

+

{{group.facts.value2}}

+
+
+

{{group.displayKeyPath}}