From 976e9bfe82a51ee60c4a92ac036a19a87bf99f96 Mon Sep 17 00:00:00 2001 From: jaredevantabor Date: Wed, 14 Dec 2016 14:58:40 -0800 Subject: [PATCH] adding callback for when options are received --- .../shared/smart-search/queryset.service.js | 18 ++++++++++++++---- .../smart-search/smart-search.controller.js | 9 +++++---- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/awx/ui/client/src/shared/smart-search/queryset.service.js b/awx/ui/client/src/shared/smart-search/queryset.service.js index a45f8af74f..359245bed4 100644 --- a/awx/ui/client/src/shared/smart-search/queryset.service.js +++ b/awx/ui/client/src/shared/smart-search/queryset.service.js @@ -18,13 +18,23 @@ export default ['$q', 'Rest', 'ProcessErrors', '$rootScope', 'Wait', 'DjangoSear // grab a single model from the cache, if present if (cache.get(path)) { - defer.resolve({[name] : new DjangoSearchModel(name, path, cache.get(path), relations)}); + defer.resolve({ + models: { + [name] : new DjangoSearchModel(name, path, cache.get(path), relations) + }, + options: cache.get(path) + }); } else { this.url = path; resolve = this.options(path) .then((res) => { base = res.data.actions.GET; - defer.resolve({[name]: new DjangoSearchModel(name, path, base, relations)}); + defer.resolve({ + models: { + [name]: new DjangoSearchModel(name, path, base, relations) + }, + options: res + }); }); } return defer.promise; @@ -76,9 +86,9 @@ export default ['$q', 'Rest', 'ProcessErrors', '$rootScope', 'Wait', 'DjangoSear if (Array.isArray(value)){ return _.map(value, (item) => { return `${key.split('__').join(':')}:${item}`; - }); + }); } - else { + else { return `${key.split('__').join(':')}:${value}`; } }, diff --git a/awx/ui/client/src/shared/smart-search/smart-search.controller.js b/awx/ui/client/src/shared/smart-search/smart-search.controller.js index 87dc33198a..3352cb5495 100644 --- a/awx/ui/client/src/shared/smart-search/smart-search.controller.js +++ b/awx/ui/client/src/shared/smart-search/smart-search.controller.js @@ -15,8 +15,9 @@ export default ['$stateParams', '$scope', '$state', 'QuerySet', 'GetBasePath', ' path = GetBasePath($scope.basePath) || $scope.basePath; relations = getRelationshipFields($scope.dataset.results); $scope.searchTags = stripDefaultParams($state.params[`${$scope.iterator}_search`]); - qs.initFieldset(path, $scope.djangoModel, relations).then((models) => { - $scope.models = models; + qs.initFieldset(path, $scope.djangoModel, relations).then((data) => { + $scope.models = data.models; + $scope.$emit(`${$scope.list.iterator}_options`, data.options); }); } @@ -102,12 +103,12 @@ export default ['$stateParams', '$scope', '$state', 'QuerySet', 'GetBasePath', ' params.page = '1'; queryset = _.merge(queryset, params, (objectValue, sourceValue, key, object) => { if (object[key] && object[key] !== sourceValue){ - return [object[key], sourceValue]; + return [object[key], sourceValue]; } else { // // https://lodash.com/docs/3.10.1#merge // If customizer fn returns undefined merging is handled by default _.merge algorithm - return undefined; + return undefined; } }); // https://ui-router.github.io/docs/latest/interfaces/params.paramdeclaration.html#dynamic