From 8a2be07ccbf9490db9b5e87ed05f06f730f8326d Mon Sep 17 00:00:00 2001 From: mabashian Date: Mon, 9 Jul 2018 15:52:58 -0400 Subject: [PATCH] Tweaked logic around the lookup modal and new form lookup fields in order to support dynamic breadcrumbs and selecting applications with the same name. --- .../add-applications.controller.js | 11 ++++-- .../add-edit-applications.view.html | 1 + .../edit-applications.controller.js | 6 ++++ .../credentials/add-credentials.controller.js | 12 +++++++ .../add-edit-credentials.view.html | 2 ++ .../edit-credentials.controller.js | 12 +++++++ .../tokens/users-tokens-add.controller.js | 11 ++++-- .../tokens/users-tokens-add.partial.html | 1 + .../lib/components/input/lookup.directive.js | 36 ++++++++++--------- .../lib/components/input/lookup.partial.html | 4 +-- 10 files changed, 73 insertions(+), 23 deletions(-) diff --git a/awx/ui/client/features/applications/add-applications.controller.js b/awx/ui/client/features/applications/add-applications.controller.js index c848bcd345..4318d29c82 100644 --- a/awx/ui/client/features/applications/add-applications.controller.js +++ b/awx/ui/client/features/applications/add-applications.controller.js @@ -1,4 +1,4 @@ -function AddApplicationsController (models, $state, strings) { +function AddApplicationsController (models, $state, strings, $scope) { const vm = this || {}; const { application, me, organization } = models; @@ -62,12 +62,19 @@ function AddApplicationsController (models, $state, strings) { vm.form.onSaveSuccess = res => { $state.go('applications.edit', { application_id: res.data.id }, { reload: true }); }; + + $scope.$watch('organization', () => { + if ($scope.organization) { + vm.form.organization._idFromModal = $scope.organization; + } + }); } AddApplicationsController.$inject = [ 'resolvedModels', '$state', - 'ApplicationsStrings' + 'ApplicationsStrings', + '$scope' ]; export default AddApplicationsController; diff --git a/awx/ui/client/features/applications/add-edit-applications.view.html b/awx/ui/client/features/applications/add-edit-applications.view.html index 1b77c009bf..873f75ded0 100644 --- a/awx/ui/client/features/applications/add-edit-applications.view.html +++ b/awx/ui/client/features/applications/add-edit-applications.view.html @@ -1,3 +1,4 @@ +
diff --git a/awx/ui/client/features/applications/edit-applications.controller.js b/awx/ui/client/features/applications/edit-applications.controller.js index 1bf6b8c91b..cf53a1abc3 100644 --- a/awx/ui/client/features/applications/edit-applications.controller.js +++ b/awx/ui/client/features/applications/edit-applications.controller.js @@ -43,6 +43,12 @@ function EditApplicationsController (models, $state, strings, $scope) { } }); + $scope.$watch('organization', () => { + if ($scope.organization) { + vm.form.organization._idFromModal = $scope.organization; + } + }); + if (isEditable) { vm.form = application.createFormSchema('put', { omit }); } else { diff --git a/awx/ui/client/features/credentials/add-credentials.controller.js b/awx/ui/client/features/credentials/add-credentials.controller.js index e0b575bf2d..6f99792a89 100644 --- a/awx/ui/client/features/credentials/add-credentials.controller.js +++ b/awx/ui/client/features/credentials/add-credentials.controller.js @@ -115,6 +115,18 @@ function AddCredentialsController (models, $state, $scope, strings, componentsSt return { obj, error }; }; + + $scope.$watch('organization', () => { + if ($scope.organization) { + vm.form.organization._idFromModal = $scope.organization; + } + }); + + $scope.$watch('credential_type', () => { + if ($scope.credential_type) { + vm.form.credential_type._idFromModal = $scope.credential_type; + } + }); } AddCredentialsController.$inject = [ diff --git a/awx/ui/client/features/credentials/add-edit-credentials.view.html b/awx/ui/client/features/credentials/add-edit-credentials.view.html index 277994cd81..43e56259aa 100644 --- a/awx/ui/client/features/credentials/add-edit-credentials.view.html +++ b/awx/ui/client/features/credentials/add-edit-credentials.view.html @@ -1,3 +1,5 @@ +
+
diff --git a/awx/ui/client/features/credentials/edit-credentials.controller.js b/awx/ui/client/features/credentials/edit-credentials.controller.js index 81b6ebe5fb..560b2605a6 100644 --- a/awx/ui/client/features/credentials/edit-credentials.controller.js +++ b/awx/ui/client/features/credentials/edit-credentials.controller.js @@ -32,6 +32,18 @@ function EditCredentialsController (models, $state, $scope, strings, componentsS } }); + $scope.$watch('organization', () => { + if ($scope.organization) { + vm.form.organization._idFromModal = $scope.organization; + } + }); + + $scope.$watch('credential_type', () => { + if ($scope.credential_type) { + vm.form.credential_type._idFromModal = $scope.credential_type; + } + }); + // Only exists for permissions compatibility $scope.credential_obj = credential.get(); diff --git a/awx/ui/client/features/users/tokens/users-tokens-add.controller.js b/awx/ui/client/features/users/tokens/users-tokens-add.controller.js index 67e15fa0ad..26ce20e5f2 100644 --- a/awx/ui/client/features/users/tokens/users-tokens-add.controller.js +++ b/awx/ui/client/features/users/tokens/users-tokens-add.controller.js @@ -1,6 +1,6 @@ function AddTokensController ( models, $state, strings, Rest, Alert, Wait, GetBasePath, - $filter, ProcessErrors + $filter, ProcessErrors, $scope ) { const vm = this || {}; const { application } = models; @@ -94,6 +94,12 @@ function AddTokensController ( vm.form.onSaveSuccess = () => { $state.go('^', { user_id: $state.params.user_id }, { reload: true }); }; + + $scope.$watch('application', () => { + if ($scope.application) { + vm.form.application._idFromModal = $scope.application; + } + }); } AddTokensController.$inject = [ @@ -105,7 +111,8 @@ AddTokensController.$inject = [ 'Wait', 'GetBasePath', '$filter', - 'ProcessErrors' + 'ProcessErrors', + '$scope' ]; export default AddTokensController; diff --git a/awx/ui/client/features/users/tokens/users-tokens-add.partial.html b/awx/ui/client/features/users/tokens/users-tokens-add.partial.html index 4b8343a0ed..f9055fd2e5 100644 --- a/awx/ui/client/features/users/tokens/users-tokens-add.partial.html +++ b/awx/ui/client/features/users/tokens/users-tokens-add.partial.html @@ -1,3 +1,4 @@ +
diff --git a/awx/ui/client/lib/components/input/lookup.directive.js b/awx/ui/client/lib/components/input/lookup.directive.js index 0447d6b448..13632d8eb3 100644 --- a/awx/ui/client/lib/components/input/lookup.directive.js +++ b/awx/ui/client/lib/components/input/lookup.directive.js @@ -34,23 +34,20 @@ function AtInputLookupController (baseInputController, $q, $state) { } }; - scope.$watch(scope.state._resource, vm.watchResource); + // This should get triggered when the user selects something in the lookup modal and + // hits save to close the modal. This won't get triggered when the user types in + // a value in the input. + scope.$watch('state._idFromModal', () => { + if (scope.state._idFromModal && + (scope.state._idFromModal !== scope.state._value) + ) { + vm.search({ id: scope.state._idFromModal }); + } + }); vm.check(); }; - vm.watchResource = () => { - if (!scope[scope.state._resource]) { - return; - } - - if (scope[scope.state._resource] !== scope.state._value) { - scope.state._displayValue = scope[`${scope.state._resource}_name`]; - - vm.search(); - } - }; - vm.lookup = () => { const params = {}; @@ -62,6 +59,7 @@ function AtInputLookupController (baseInputController, $q, $state) { }; vm.reset = () => { + scope.state._idFromModal = undefined; scope.state._value = undefined; scope[scope.state._resource] = undefined; }; @@ -80,15 +78,20 @@ function AtInputLookupController (baseInputController, $q, $state) { vm.searchAfterDebounce(); }; - vm.search = () => { + vm.search = (searchParams) => { scope.state._touched = true; - if (scope.state._displayValue === '' && !scope.state._required) { + if (!scope.state._required && + scope.state._displayValue === '' && + !scope.state._idFromModal + ) { scope.state._value = null; return vm.check({ isValid: true }); } - return model.search({ [search.key]: scope.state._displayValue }, search.config) + searchParams = searchParams || { [search.key]: scope.state._displayValue }; + + return model.search(searchParams, search.config) .then(found => { if (!found) { vm.reset(); @@ -99,6 +102,7 @@ function AtInputLookupController (baseInputController, $q, $state) { scope[scope.state._resource] = model.get('id'); scope.state._value = model.get('id'); scope.state._displayValue = model.get('name'); + scope.state._idFromModal = undefined; }) .catch(() => vm.reset()) .finally(() => { diff --git a/awx/ui/client/lib/components/input/lookup.partial.html b/awx/ui/client/lib/components/input/lookup.partial.html index 24cde94edc..5a951cdb31 100644 --- a/awx/ui/client/lib/components/input/lookup.partial.html +++ b/awx/ui/client/lib/components/input/lookup.partial.html @@ -30,6 +30,4 @@ - -
- +