From 9d6fab9417a1c9257c4499ce8d1bff148fa72abd Mon Sep 17 00:00:00 2001 From: John Mitchell Date: Mon, 12 Mar 2018 17:40:08 -0400 Subject: [PATCH] update edit controller to PUT app instead of POST remove old applications tokens code --- .../edit-applications.controller.js | 6 +- .../src/users/tokens/application.list.js | 22 ---- .../users/tokens/users-tokens.controller.js | 108 ------------------ .../src/users/tokens/users-tokens.form.js | 70 ------------ 4 files changed, 5 insertions(+), 201 deletions(-) delete mode 100644 awx/ui/client/src/users/tokens/application.list.js delete mode 100644 awx/ui/client/src/users/tokens/users-tokens.controller.js delete mode 100644 awx/ui/client/src/users/tokens/users-tokens.form.js diff --git a/awx/ui/client/features/applications/edit-applications.controller.js b/awx/ui/client/features/applications/edit-applications.controller.js index dbd7c0e010..6279b642ee 100644 --- a/awx/ui/client/features/applications/edit-applications.controller.js +++ b/awx/ui/client/features/applications/edit-applications.controller.js @@ -97,7 +97,11 @@ function EditApplicationsController (models, $state, strings, $scope) { const payload = _.merge(data, hiddenData); - return application.request('post', { data: payload }); + return application.request('put', { data: payload }); + }; + + vm.form.onSaveSuccess = () => { + $state.go('applications.edit', { application_id: application.get('id') }, { reload: true }); }; } diff --git a/awx/ui/client/src/users/tokens/application.list.js b/awx/ui/client/src/users/tokens/application.list.js deleted file mode 100644 index 37df5c2717..0000000000 --- a/awx/ui/client/src/users/tokens/application.list.js +++ /dev/null @@ -1,22 +0,0 @@ -export default ['i18n', function(i18n) { - return { - - name: 'applications', - search: { - order_by: 'id' - }, - iterator: 'application', - // TODO: change - basePath: 'projects', - listTitle: i18n._('APPLICATIONS'), - index: false, - hover: true, - - fields: { - name: { - key: true, - label: i18n._('Name'), - columnClass: 'col-md-3 col-sm-3 col-xs-9' - }, - } - };}]; diff --git a/awx/ui/client/src/users/tokens/users-tokens.controller.js b/awx/ui/client/src/users/tokens/users-tokens.controller.js deleted file mode 100644 index 377e4012ac..0000000000 --- a/awx/ui/client/src/users/tokens/users-tokens.controller.js +++ /dev/null @@ -1,108 +0,0 @@ -/************************************************* - * Copyright (c) 2015 Ansible, Inc. - * - * All Rights Reserved - *************************************************/ - -export default ['Rest', 'Wait', 'UserTokensFormObject', - 'ProcessErrors', 'GetBasePath', 'Alert', - 'GenerateForm', '$scope', '$state', 'CreateSelect2', 'GetChoices' 'i18n', - function( - Rest, Wait, UserTokensFormObject, - ProcessErrors, GetBasePath, Alert, - GenerateForm, $scope, $state, CreateSelect2, GetChoices i18n - ) { - - var generator = GenerateForm, - form = UserTokensFormObject; - - init(); - - function init() { - Rest.setUrl(GetBasePath('users') + '/authorized_tokens'); - Rest.options() - .then(({data}) => { - if (!data.actions.POST) { - $state.go("^"); - Alert('Permission Error', 'You do not have permission to add a token.', 'alert-info'); - } - }); - // apply form definition's default field values - GenerateForm.applyDefaults(form, $scope); - } - - CreateSelect2({ - element: '#user_token_scope', - multiple: false - }); - - // Save - $scope.formSave = function() { - // var params, - // v = $scope.notification_type.value; - // - // generator.clearApiErrors($scope); - // params = { - // "name": $scope.name, - // "description": $scope.description, - // "organization": $scope.organization, - // "notification_type": v, - // "notification_configuration": {} - // }; - // - // function processValue(value, i, field) { - // if (field.type === 'textarea') { - // if (field.name === 'headers') { - // $scope[i] = JSON.parse($scope[i]); - // } else { - // $scope[i] = $scope[i].toString().split('\n'); - // } - // } - // if (field.type === 'checkbox') { - // $scope[i] = Boolean($scope[i]); - // } - // if (field.type === 'number') { - // $scope[i] = Number($scope[i]); - // } - // if (i === "username" && $scope.notification_type.value === "email" && value === null) { - // $scope[i] = ""; - // } - // if (field.type === 'sensitive' && value === null) { - // $scope[i] = ""; - // } - // return $scope[i]; - // } - // - // params.notification_configuration = _.object(Object.keys(form.fields) - // .filter(i => (form.fields[i].ngShow && form.fields[i].ngShow.indexOf(v) > -1)) - // .map(i => [i, processValue($scope[i], i, form.fields[i])])); - // - // delete params.notification_configuration.email_options; - // - // for(var j = 0; j < form.fields.email_options.options.length; j++) { - // if(form.fields.email_options.options[j].ngShow && form.fields.email_options.options[j].ngShow.indexOf(v) > -1) { - // params.notification_configuration[form.fields.email_options.options[j].value] = Boolean($scope[form.fields.email_options.options[j].value]); - // } - // } - // - // Wait('start'); - // Rest.setUrl(url); - // Rest.post(params) - // .then(() => { - // $state.go('notifications', {}, { reload: true }); - // Wait('stop'); - // }) - // .catch(({data, status}) => { - // ProcessErrors($scope, data, status, form, { - // hdr: 'Error!', - // msg: 'Failed to add new notifier. POST returned status: ' + status - // }); - // }); - }; - - $scope.formCancel = function() { - $state.go('notifications'); - }; - - } -]; diff --git a/awx/ui/client/src/users/tokens/users-tokens.form.js b/awx/ui/client/src/users/tokens/users-tokens.form.js deleted file mode 100644 index 6dc73b734f..0000000000 --- a/awx/ui/client/src/users/tokens/users-tokens.form.js +++ /dev/null @@ -1,70 +0,0 @@ -/************************************************* - * Copyright (c) 2015 Ansible, Inc. - * - * All Rights Reserved - *************************************************/ - - /** - * @ngdoc function - * @name forms.function:Tokens - * @description This form is for adding a token on the user's page -*/ - -export default ['i18n', -function(i18n) { - return { - addTitle: i18n._('CREATE TOKEN'), - name: 'token', - basePath: 'tokens', - well: false, - formLabelSize: 'col-lg-3', - formFieldSize: 'col-lg-9', - iterator: 'token', - stateTree: 'users', - fields: { - application: { - label: i18n._('Application'), - type: 'lookup', - list: 'ApplicationList', - sourceModel: 'application', - // TODO: update to actual path - basePath: 'projects', - sourceField: 'name', - dataTitle: i18n._('Application'), - required: true, - dataContainer: 'body', - dataPlacement: 'right', - ngDisabled: '!(token.summary_fields.user_capabilities.edit || canAdd)', - awLookupWhen: '(token.summary_fields.user_capabilities.edit || canAdd)' - // TODO: help popover - }, - scope: { - label: i18n._('Description'), - type: 'select', - class: 'Form-dropDown--scmType', - defaultText: 'Choose a scope', - ngOptions: 'scope.label for scope in scope_options track by scope.value', - required: true, - ngDisabled: '!(token.summary_fields.user_capabilities.edit || canAdd)' - // TODO: help popover - } - }, - buttons: { - cancel: { - ngClick: 'formCancel()', - ngShow: '(token.summary_fields.user_capabilities.edit || canAdd)' - }, - close: { - ngClick: 'formCancel()', - ngShow: '!(token.summary_fields.user_capabilities.edit || canAdd)' - }, - save: { - ngClick: 'formSave()', - ngDisabled: true, - ngShow: '(token.summary_fields.user_capabilities.edit || canAdd)' - } - }, - related: { - } - }; - }];