From 6a7e01810077ba79522c4d41d874b2ff17a86266 Mon Sep 17 00:00:00 2001 From: gconsidine Date: Fri, 28 Jul 2017 15:23:08 -0400 Subject: [PATCH] Add comments and minor changes from PR feedback --- .../edit-credentials.controller.js | 5 ++++ .../lib/components/input/lookup.directive.js | 6 +++-- awx/ui/client/lib/models/Base.js | 23 +++++++++++++++---- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/awx/ui/client/features/credentials/edit-credentials.controller.js b/awx/ui/client/features/credentials/edit-credentials.controller.js index 602972ff73..ccdb687761 100644 --- a/awx/ui/client/features/credentials/edit-credentials.controller.js +++ b/awx/ui/client/features/credentials/edit-credentials.controller.js @@ -70,6 +70,11 @@ function EditCredentialsController (models, $state, $scope, strings) { _key: 'inputs' }; + /** + * If a credential's `credential_type` is changed while editing, the inputs associated with + * the old type need to be cleared before saving the inputs associated with the new type. + * Otherwise inputs are merged together making the request invalid. + */ vm.form.save = data => { data.user = me.getSelf().id; credential.unset('inputs'); diff --git a/awx/ui/client/lib/components/input/lookup.directive.js b/awx/ui/client/lib/components/input/lookup.directive.js index 58ab894737..b2c60e15bd 100644 --- a/awx/ui/client/lib/components/input/lookup.directive.js +++ b/awx/ui/client/lib/components/input/lookup.directive.js @@ -81,6 +81,10 @@ function AtInputLookupController (baseInputController, $q, $state, $stateParams) vm.search = () => { scope.state._touched = true; + if (scope.state._displayValue === '' && !scope.state._required) { + return vm.check({ isValid: true }); + } + return model.search({ [search.key]: scope.state._displayValue }, search.config) .then(found => { if (!found) { @@ -105,8 +109,6 @@ function AtInputLookupController (baseInputController, $q, $state, $stateParams) return vm.resetDebounce(); } - scope.state._touched = true; - vm.searchAfterDebounce(); }; } diff --git a/awx/ui/client/lib/models/Base.js b/awx/ui/client/lib/models/Base.js index 4fa46e50a0..b728e93ca1 100644 --- a/awx/ui/client/lib/models/Base.js +++ b/awx/ui/client/lib/models/Base.js @@ -11,6 +11,19 @@ function request (method, resource) { return this.http[method](resource); } +/** + * Intended to be useful in searching and filtering results using params + * supported by the API. + * + * @param {object} params - An object of keys and values to to format and + * to the URL as a query string. Refer to the API documentation for the + * resource in use for specifics. + * @param {object} config - Configuration specific to the UI to accommodate + * common use cases. + * + * @returns {Promise} - $http + * @yields {(Boolean|object)} + */ function search (params, config) { let req = { method: 'GET', @@ -19,19 +32,19 @@ function search (params, config) { }; return $http(req) - .then(res => { - if (!res.data.count) { + .then(({ data }) => { + if (!data.count) { return false; } if (config.unique) { - if (res.data.count !== 1) { + if (data.count !== 1) { return false; } - this.model.GET = res.data.results[0]; + this.model.GET = data.results[0]; } else { - this.model.GET = res.data; + this.model.GET = data; } return true;