From cbc20093d7031b10ed2f78424685464a986fdea0 Mon Sep 17 00:00:00 2001 From: John Mitchell Date: Fri, 16 Mar 2018 17:15:28 -0400 Subject: [PATCH] move users tokens to features folder --- awx/ui/client/features/_index.less | 1 + awx/ui/client/features/index.js | 4 +- awx/ui/client/features/users/index.js | 8 ++++ .../users/tokens/_index.less} | 3 -- awx/ui/client/features/users/tokens/index.js | 9 +++++ .../users/tokens}/tokens.strings.js | 5 ++- .../users-tokens-add-application.route.js | 38 +++++++++---------- .../tokens}/users-tokens-add.controller.js | 38 ++++++++++++------- .../tokens}/users-tokens-add.partial.html | 0 .../users/tokens}/users-tokens-add.route.js | 9 ++--- .../tokens}/users-tokens-list.controller.js | 2 +- .../tokens}/users-tokens-list.partial.html | 0 .../users/tokens}/users-tokens-list.route.js | 14 +++---- .../lib/components/input/select.partial.html | 2 +- awx/ui/client/lib/theme/index.less | 1 - awx/ui/client/src/users/main.js | 10 ++--- 16 files changed, 84 insertions(+), 60 deletions(-) create mode 100644 awx/ui/client/features/users/index.js rename awx/ui/client/{src/users/token-modal.block.less => features/users/tokens/_index.less} (84%) create mode 100644 awx/ui/client/features/users/tokens/index.js rename awx/ui/client/{src/users => features/users/tokens}/tokens.strings.js (86%) rename awx/ui/client/{src/users => features/users/tokens}/users-tokens-add-application.route.js (68%) rename awx/ui/client/{src/users => features/users/tokens}/users-tokens-add.controller.js (77%) rename awx/ui/client/{src/users => features/users/tokens}/users-tokens-add.partial.html (100%) rename awx/ui/client/{src/users => features/users/tokens}/users-tokens-add.route.js (77%) rename awx/ui/client/{src/users => features/users/tokens}/users-tokens-list.controller.js (97%) rename awx/ui/client/{src/users => features/users/tokens}/users-tokens-list.partial.html (100%) rename awx/ui/client/{src/users => features/users/tokens}/users-tokens-list.route.js (76%) diff --git a/awx/ui/client/features/_index.less b/awx/ui/client/features/_index.less index 5046881522..e2339dc9e4 100644 --- a/awx/ui/client/features/_index.less +++ b/awx/ui/client/features/_index.less @@ -1 +1,2 @@ @import 'credentials/_index'; +@import 'users/tokens/_index'; diff --git a/awx/ui/client/features/index.js b/awx/ui/client/features/index.js index 75093bf39c..01216e575f 100644 --- a/awx/ui/client/features/index.js +++ b/awx/ui/client/features/index.js @@ -5,6 +5,7 @@ import atLibModels from '~models'; import atFeaturesApplications from '~features/applications'; import atFeaturesCredentials from '~features/credentials'; import atFeaturesTemplates from '~features/templates'; +import atFeaturesUsers from '~features/users'; const MODULE_NAME = 'at.features'; @@ -14,7 +15,8 @@ angular.module(MODULE_NAME, [ atLibModels, atFeaturesApplications, atFeaturesCredentials, - atFeaturesTemplates + atFeaturesTemplates, + atFeaturesUsers ]); export default MODULE_NAME; diff --git a/awx/ui/client/features/users/index.js b/awx/ui/client/features/users/index.js new file mode 100644 index 0000000000..b8f6a8052f --- /dev/null +++ b/awx/ui/client/features/users/index.js @@ -0,0 +1,8 @@ +import atFeaturesUsersTokens from '~features/users/tokens'; + +const MODULE_NAME = 'at.features.users'; + +angular + .module(MODULE_NAME, [atFeaturesUsersTokens]); + +export default MODULE_NAME; diff --git a/awx/ui/client/src/users/token-modal.block.less b/awx/ui/client/features/users/tokens/_index.less similarity index 84% rename from awx/ui/client/src/users/token-modal.block.less rename to awx/ui/client/features/users/tokens/_index.less index d913b3e3ef..f1052b5fa6 100644 --- a/awx/ui/client/src/users/token-modal.block.less +++ b/awx/ui/client/features/users/tokens/_index.less @@ -7,6 +7,3 @@ font-weight: bold; width: 130px; } - -.TokenModal-value { -} diff --git a/awx/ui/client/features/users/tokens/index.js b/awx/ui/client/features/users/tokens/index.js new file mode 100644 index 0000000000..6d635b572d --- /dev/null +++ b/awx/ui/client/features/users/tokens/index.js @@ -0,0 +1,9 @@ +import TokensStrings from './tokens.strings'; + +const MODULE_NAME = 'at.features.users.tokens'; + +angular + .module(MODULE_NAME, []) + .service('TokensStrings', TokensStrings); + +export default MODULE_NAME; diff --git a/awx/ui/client/src/users/tokens.strings.js b/awx/ui/client/features/users/tokens/tokens.strings.js similarity index 86% rename from awx/ui/client/src/users/tokens.strings.js rename to awx/ui/client/features/users/tokens/tokens.strings.js index 0dc2fa61b5..ac0af8e15f 100644 --- a/awx/ui/client/src/users/tokens.strings.js +++ b/awx/ui/client/features/users/tokens/tokens.strings.js @@ -25,7 +25,10 @@ function TokensStrings (BaseString) { ERROR_HEADER: t.s('COULD NOT CREATE TOKEN'), ERROR_BODY_LABEL: t.s('Returned status:'), LAST_USED_LABEL: t.s('by'), - DELETE_ACTION_LABEL: t.s('DELETE') + DELETE_ACTION_LABEL: t.s('DELETE'), + SCOPE_PLACEHOLDER: t.s('Select a scope'), + SCOPE_READ_LABEL: t.s('Read'), + SCOPE_WRITE_LABEL: t.s('Write') }; ns.list = { diff --git a/awx/ui/client/src/users/users-tokens-add-application.route.js b/awx/ui/client/features/users/tokens/users-tokens-add-application.route.js similarity index 68% rename from awx/ui/client/src/users/users-tokens-add-application.route.js rename to awx/ui/client/features/users/tokens/users-tokens-add-application.route.js index 4ab5998d74..13197ca11d 100644 --- a/awx/ui/client/src/users/users-tokens-add-application.route.js +++ b/awx/ui/client/features/users/tokens/users-tokens-add-application.route.js @@ -33,27 +33,25 @@ export default { } }, resolve: { - ListDefinition: [() => { - return { - name: 'applications', - iterator: 'application', - hover: true, - index: false, - fields: { - name: { - key: true, - label: 'Name', - columnClass: 'col-lg-4 col-md-6 col-sm-8 col-xs-8', - awToolTip: '{{application.description | sanitize}}', - dataPlacement: 'top' - }, + ListDefinition: [() => ({ + name: 'applications', + iterator: 'application', + hover: true, + index: false, + fields: { + name: { + key: true, + label: 'Name', + columnClass: 'col-lg-4 col-md-6 col-sm-8 col-xs-8', + awToolTip: '{{application.description | sanitize}}', + dataPlacement: 'top' }, - actions: { - }, - fieldActions: { - } + }, + actions: { + }, + fieldActions: { } - }], + })], Dataset: ['QuerySet', 'GetBasePath', '$stateParams', 'ListDefinition', (qs, GetBasePath, $stateParams, list) => qs.search( GetBasePath('applications'), @@ -68,4 +66,4 @@ export default { $('body').removeClass('modal-open'); } } -} +}; diff --git a/awx/ui/client/src/users/users-tokens-add.controller.js b/awx/ui/client/features/users/tokens/users-tokens-add.controller.js similarity index 77% rename from awx/ui/client/src/users/users-tokens-add.controller.js rename to awx/ui/client/features/users/tokens/users-tokens-add.controller.js index 6e5d4c4d26..1421077b1c 100644 --- a/awx/ui/client/src/users/users-tokens-add.controller.js +++ b/awx/ui/client/features/users/tokens/users-tokens-add.controller.js @@ -1,4 +1,7 @@ -function AddTokensController (models, $state, strings, Rest, Alert, Wait, GetBasePath, $filter) { +function AddTokensController ( + models, $state, strings, Rest, Alert, Wait, GetBasePath, + $filter, ProcessErrors +) { const vm = this || {}; const { application } = models; @@ -28,21 +31,29 @@ function AddTokensController (models, $state, strings, Rest, Alert, Wait, GetBas vm.form.description.required = false; vm.form.scope = { - choices: ['', 'read', 'write'], + choices: [ + '', + 'read', + 'write' + ], help_text: strings.get('add.SCOPE_HELP_TEXT'), id: 'scope', label: 'Scope', required: true, _component: 'at-input-select', - _data: ['', 'read', 'write'], + _data: [ + strings.get('add.SCOPE_PLACEHOLDER'), + strings.get('add.SCOPE_READ_LABEL'), + strings.get('add.SCOPE_WRITE_LABEL') + ], _exp: 'choice for (index, choice) in state._data', _format: 'array' - } + }; - vm.form.save = data => { - Rest.setUrl(GetBasePath('users') + $state.params.user_id + '/authorized_tokens'); - return Rest.post(data) - .then(({data}) => { + vm.form.save = payload => { + Rest.setUrl(`${GetBasePath('users')}${$state.params.user_id}/authorized_tokens`); + return Rest.post(payload) + .then(({ data }) => { Alert(strings.get('add.TOKEN_MODAL_HEADER'), `
@@ -71,8 +82,8 @@ function AddTokensController (models, $state, strings, Rest, Alert, Wait, GetBas `, null, null, null, null, null, true); Wait('stop'); }) - .catch(({data, status}) => { - ProcessErrors($scope, data, status, null, { + .catch(({ data, status }) => { + ProcessErrors(null, data, status, null, { hdr: strings.get('add.ERROR_HEADER'), msg: `${strings.get('add.ERROR_BODY_LABEL')} ${status}` }); @@ -80,7 +91,7 @@ function AddTokensController (models, $state, strings, Rest, Alert, Wait, GetBas }); }; - vm.form.onSaveSuccess = res => { + vm.form.onSaveSuccess = () => { $state.go('^', { user_id: $state.params.user_id }, { reload: true }); }; } @@ -88,12 +99,13 @@ function AddTokensController (models, $state, strings, Rest, Alert, Wait, GetBas AddTokensController.$inject = [ 'resolvedModels', '$state', - 'ApplicationsStrings', + 'TokensStrings', 'Rest', 'Alert', 'Wait', 'GetBasePath', - '$filter' + '$filter', + 'ProcessErrors' ]; export default AddTokensController; diff --git a/awx/ui/client/src/users/users-tokens-add.partial.html b/awx/ui/client/features/users/tokens/users-tokens-add.partial.html similarity index 100% rename from awx/ui/client/src/users/users-tokens-add.partial.html rename to awx/ui/client/features/users/tokens/users-tokens-add.partial.html diff --git a/awx/ui/client/src/users/users-tokens-add.route.js b/awx/ui/client/features/users/tokens/users-tokens-add.route.js similarity index 77% rename from awx/ui/client/src/users/users-tokens-add.route.js rename to awx/ui/client/features/users/tokens/users-tokens-add.route.js index f1047fb24b..350e9bd2dd 100644 --- a/awx/ui/client/src/users/users-tokens-add.route.js +++ b/awx/ui/client/features/users/tokens/users-tokens-add.route.js @@ -1,10 +1,9 @@ -import { N_ } from '../i18n'; +import { N_ } from '../../../src/i18n'; import AddController from './users-tokens-add.controller'; -const addTemplate = require('~src/users/users-tokens-add.partial.html'); +const addTemplate = require('~features/users/tokens/users-tokens-add.partial.html'); function TokensDetailResolve ($q, Application) { - const promises = {}; promises.application = new Application('options'); @@ -18,12 +17,12 @@ TokensDetailResolve.$inject = [ ]; export default { - url: "/add-token", + url: '/add-token', name: 'users.edit.tokens.add', params: { }, ncyBreadcrumb: { - label: N_("CREATE TOKEN") + label: N_('CREATE TOKEN') }, views: { 'preFormView@users.edit': { diff --git a/awx/ui/client/src/users/users-tokens-list.controller.js b/awx/ui/client/features/users/tokens/users-tokens-list.controller.js similarity index 97% rename from awx/ui/client/src/users/users-tokens-list.controller.js rename to awx/ui/client/features/users/tokens/users-tokens-list.controller.js index da1de35507..c2fe647928 100644 --- a/awx/ui/client/src/users/users-tokens-list.controller.js +++ b/awx/ui/client/features/users/tokens/users-tokens-list.controller.js @@ -47,7 +47,7 @@ function ListTokensController ( let html = $filter('longDate')(lastUsed); - const { username, id } = _.get(user, 'summary_fields.last_used', {}); + const { username, id } = _.get(token, 'summary_fields.last_used', {}); if (username && id) { html += ` ${strings.get('add.LAST_USED_LABEL')} ${$filter('sanitize')(username)}`; diff --git a/awx/ui/client/src/users/users-tokens-list.partial.html b/awx/ui/client/features/users/tokens/users-tokens-list.partial.html similarity index 100% rename from awx/ui/client/src/users/users-tokens-list.partial.html rename to awx/ui/client/features/users/tokens/users-tokens-list.partial.html diff --git a/awx/ui/client/src/users/users-tokens-list.route.js b/awx/ui/client/features/users/tokens/users-tokens-list.route.js similarity index 76% rename from awx/ui/client/src/users/users-tokens-list.route.js rename to awx/ui/client/features/users/tokens/users-tokens-list.route.js index 81ec099adc..c8a780e473 100644 --- a/awx/ui/client/src/users/users-tokens-list.route.js +++ b/awx/ui/client/features/users/tokens/users-tokens-list.route.js @@ -1,19 +1,17 @@ -import { N_ } from '../i18n'; +import { N_ } from '../../../src/i18n'; import ListController from './users-tokens-list.controller'; -const listTemplate = require('~src/users/users-tokens-list.partial.html'); +const listTemplate = require('~features/users/tokens/users-tokens-list.partial.html'); export default { - url: "/tokens", + url: '/tokens', name: 'users.edit.tokens', - params: { - }, ncyBreadcrumb: { - label: N_("TOKENS") + label: N_('TOKENS') }, views: { - 'related': { + related: { templateUrl: listTemplate, controller: ListController, controllerAs: 'vm' @@ -36,7 +34,7 @@ export default { 'QuerySet', ($stateParams, Wait, GetBasePath, qs) => { const searchParam = $stateParams.token_search; - const searchPath = GetBasePath('users') + $stateParams.user_id + '/tokens'; + const searchPath = `${GetBasePath('users')}${$stateParams.user_id}/tokens`; Wait('start'); return qs.search(searchPath, searchParam) .finally(() => { diff --git a/awx/ui/client/lib/components/input/select.partial.html b/awx/ui/client/lib/components/input/select.partial.html index aaa31bebee..f3ba5e845a 100644 --- a/awx/ui/client/lib/components/input/select.partial.html +++ b/awx/ui/client/lib/components/input/select.partial.html @@ -12,7 +12,7 @@