From 9b22df228fc17300d837d9314dce961fe9c5295d Mon Sep 17 00:00:00 2001 From: gconsidine Date: Wed, 12 Jul 2017 17:00:26 -0400 Subject: [PATCH] Refactor to use get method to access strings vs direct --- .../credentials/add-credentials.controller.js | 9 ++++----- .../credentials/add-edit-credentials.view.html | 12 ++++++------ .../credentials/edit-credentials.controller.js | 6 +++--- awx/ui/client/features/credentials/index.js | 6 ++---- .../client/lib/components/form/action.directive.js | 4 ++-- awx/ui/client/lib/components/form/form.directive.js | 10 ++++------ .../client/lib/components/input/base.controller.js | 10 +++++----- .../lib/components/input/checkbox.directive.js | 2 +- .../client/lib/components/input/group.directive.js | 2 +- .../client/lib/components/input/label.partial.html | 2 +- .../client/lib/components/input/lookup.directive.js | 2 +- .../client/lib/components/input/secret.directive.js | 10 +++++----- .../client/lib/components/input/select.directive.js | 4 ++-- .../components/input/textarea-secret.directive.js | 8 ++++---- .../client/lib/components/modal/modal.partial.html | 2 +- .../lib/components/truncate/truncate.directive.js | 6 +++--- 16 files changed, 45 insertions(+), 50 deletions(-) diff --git a/awx/ui/client/features/credentials/add-credentials.controller.js b/awx/ui/client/features/credentials/add-credentials.controller.js index c94efd2ee1..4e829f37ee 100644 --- a/awx/ui/client/features/credentials/add-credentials.controller.js +++ b/awx/ui/client/features/credentials/add-credentials.controller.js @@ -7,9 +7,8 @@ function AddCredentialsController (models, $state, strings) { let organization = models.organization; vm.mode = 'add'; - vm.strings = strings.credentials; - - vm.panelTitle = vm.strings[vm.mode].PANEL_TITLE; + vm.strings = strings; + vm.panelTitle = strings.get('add.PANEL_TITLE'); vm.tab = { details: { _active: true }, @@ -23,12 +22,12 @@ function AddCredentialsController (models, $state, strings) { vm.form.organization._resource = 'organization'; vm.form.organization._route = 'credentials.add.organization'; vm.form.organization._model = organization; - vm.form.organization._placeholder = vm.strings.inputs.ORGANIZATION_PLACEHOLDER; + vm.form.organization._placeholder = strings.get('inputs.ORGANIZATION_PLACEHOLDER'); vm.form.credential_type._resource = 'credential_type'; vm.form.credential_type._route = 'credentials.add.credentialType'; vm.form.credential_type._model = credentialType; - vm.form.credential_type._placeholder = vm.strings.inputs.CREDENTIAL_TYPE_PLACEHOLDER; + vm.form.credential_type._placeholder = strings.get('inputs.CREDENTIAL_TYPE_PLACEHOLDER'); vm.form.inputs = { _get: id => { 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 5625be6dd1..997c513a4a 100644 --- a/awx/ui/client/features/credentials/add-edit-credentials.view.html +++ b/awx/ui/client/features/credentials/add-edit-credentials.view.html @@ -2,8 +2,8 @@ {{ vm.panelTitle }} - {{ vm.strings.tab.DETAILS }} - {{ vm.strings.tab.PERMISSIONS }} + {{:: vm.strings.get('tab.DETAILS') }} + {{:: vm.strings.get('tab.PERMISSIONS') }} @@ -17,7 +17,7 @@ - {{ vm.strings.inputs.GROUP_TITLE }} + {{:: vm.strings.get('inputs.GROUP_TITLE') }} @@ -29,11 +29,11 @@ - {{ vm.strings.permissions.TITLE }} + {{:: vm.strings.get('permissions.TITLE') }} - {{ vm.strings.tab.DETAILS }} - {{ vm.strings.tab.PERMISSIONS }} + {{:: vm.strings.get('tab.DETAILS') }} + {{:: vm.stringss.get('tab.PERMISSIONS') }} diff --git a/awx/ui/client/features/credentials/edit-credentials.controller.js b/awx/ui/client/features/credentials/edit-credentials.controller.js index 5412e6f544..19b05a834b 100644 --- a/awx/ui/client/features/credentials/edit-credentials.controller.js +++ b/awx/ui/client/features/credentials/edit-credentials.controller.js @@ -8,7 +8,7 @@ function EditCredentialsController (models, $state, $scope, strings) { let selectedCredentialType = models.selectedCredentialType; vm.mode = 'edit'; - vm.strings = strings.credentials; + vm.strings = strings; vm.panelTitle = credential.get('name'); vm.tab = { @@ -45,14 +45,14 @@ function EditCredentialsController (models, $state, $scope, strings) { vm.form.organization._route = 'credentials.edit.organization'; vm.form.organization._value = credential.get('summary_fields.organization.id'); vm.form.organization._displayValue = credential.get('summary_fields.organization.name'); - vm.form.organization._placeholder = vm.strings.inputs.ORGANIZATION_PLACEHOLDER; + vm.form.organization._placeholder = strings.get('inputs.ORGANIZATION_PLACEHOLDER'); vm.form.credential_type._resource = 'credential_type'; vm.form.credential_type._model = credentialType; vm.form.credential_type._route = 'credentials.edit.credentialType'; vm.form.credential_type._value = selectedCredentialType.get('id'); vm.form.credential_type._displayValue = selectedCredentialType.get('name'); - vm.form.credential_type._placeholder = vm.strings.inputs.CREDENTIAL_TYPE_PLACEHOLDER; + vm.form.credential_type._placeholder = strings.get('inputs.CREDENTIAL_TYPE_PLACEHOLDER'); vm.form.inputs = { _get (id) { diff --git a/awx/ui/client/features/credentials/index.js b/awx/ui/client/features/credentials/index.js index f203ff471f..c939c98d5d 100644 --- a/awx/ui/client/features/credentials/index.js +++ b/awx/ui/client/features/credentials/index.js @@ -50,13 +50,11 @@ function CredentialsConfig ($stateExtenderProvider, legacyProvider, pathProvider let legacy = legacyProvider.$get(); let strings = stringProvider.$get(); - strings = strings.credentials.state; - stateExtender.addState({ name: 'credentials.add', route: '/add', ncyBreadcrumb: { - label: strings.ADD_BREADCRUMB_LABEL + label: strings.get('state.ADD_BREADCRUMB_LABEL') }, views: { 'add@credentials': { @@ -74,7 +72,7 @@ function CredentialsConfig ($stateExtenderProvider, legacyProvider, pathProvider name: 'credentials.edit', route: '/:credential_id', ncyBreadcrumb: { - label: strings.EDIT_BREADCRUMB_LABEL + label: strings.get('state.EDIT_BREADCRUMB_LABEL') }, views: { 'edit@credentials': { diff --git a/awx/ui/client/lib/components/form/action.directive.js b/awx/ui/client/lib/components/form/action.directive.js index 33db4182c7..a23367821c 100644 --- a/awx/ui/client/lib/components/form/action.directive.js +++ b/awx/ui/client/lib/components/form/action.directive.js @@ -36,14 +36,14 @@ function atFormActionController ($state, strings) { }; vm.setCancelDefaults = () => { - scope.text = strings.CANCEL; + scope.text = strings.get('CANCEL'), scope.fill = 'Hollow'; scope.color = 'default'; scope.action = () => $state.go(scope.to || '^'); }; vm.setSaveDefaults = () => { - scope.text = strings.SAVE; + scope.text = strings.get('SAVE'), scope.fill = ''; scope.color = 'success'; scope.action = () => form.submit(); diff --git a/awx/ui/client/lib/components/form/form.directive.js b/awx/ui/client/lib/components/form/form.directive.js index 75d3aa596a..7d7aa2e30d 100644 --- a/awx/ui/client/lib/components/form/form.directive.js +++ b/awx/ui/client/lib/components/form/form.directive.js @@ -15,8 +15,6 @@ function AtFormController (eventService, strings) { let modal; let form; - strings = strings.components.forms; - vm.components = []; vm.state = { isValid: false, @@ -101,8 +99,8 @@ function AtFormController (eventService, strings) { if (!handled) { let message; - let title = strings.SUBMISSION_ERROR_TITLE; - let preface = strings.SUBMISSION_ERROR_PREFACE; + let title = strings.get('form.SUBMISSION_ERROR_TITLE'); + let preface = strings.get('form.SUBMISSION_ERROR_PREFACE'); if (typeof err.data === 'object') { message = JSON.stringify(err.data); @@ -115,8 +113,8 @@ function AtFormController (eventService, strings) { }; vm.handleUnexpectedError = err => { - let title = strings.SUBMISSION_ERROR_TITLE; - let message = strings.SUBMISSION_ERROR_MESSAGE; + let title = strings.get('form.SUBMISSION_ERROR_TITLE'); + let message = strings.get('form.SUBMISSION_ERROR_MESSAGE'); modal.show(title, message); diff --git a/awx/ui/client/lib/components/input/base.controller.js b/awx/ui/client/lib/components/input/base.controller.js index 1b27b159cd..43a382210f 100644 --- a/awx/ui/client/lib/components/input/base.controller.js +++ b/awx/ui/client/lib/components/input/base.controller.js @@ -51,13 +51,13 @@ function BaseInputController (strings) { if (scope.state._required && !scope.state._value && !scope.state._displayValue) { isValid = false; - message = vm.strings.components.message.REQUIRED_INPUT_MISSING; + message = vm.strings.get('message.REQUIRED_INPUT_MISSING'); } else if (scope.state._validate) { let result = scope.state._validate(scope.state._value); if (!result.isValid) { isValid = false; - message = result.message || vm.strings.components.message.INVALID_INPUT; + message = result.message || vm.strings.get('message.INVALID_INPUT'); } } @@ -83,14 +83,14 @@ function BaseInputController (strings) { scope.state._isBeingReplaced = !scope.state._isBeingReplaced; if (!scope.state._isBeingReplaced) { - scope.state._buttonText = vm.strings.components.REPLACE; + scope.state._buttonText = vm.strings.get('REPLACE'); scope.state._disabled = true; scope.state._enableToggle = true; scope.state._value = scope.state._preEditValue; scope.state._activeModel = '_displayValue'; - scope.state._placeholder = vm.strings.components.ENCRYPTED; + scope.state._placeholder = vm.strings.get('ENCRYPTED'); } else { - scope.state._buttonText = vm.strings.components.REVERT; + scope.state._buttonText = vm.strings.get('REVERT'); scope.state._disabled = false; scope.state._enableToggle = false; scope.state._activeModel = '_value'; diff --git a/awx/ui/client/lib/components/input/checkbox.directive.js b/awx/ui/client/lib/components/input/checkbox.directive.js index 99728cb744..237973b80e 100644 --- a/awx/ui/client/lib/components/input/checkbox.directive.js +++ b/awx/ui/client/lib/components/input/checkbox.directive.js @@ -15,7 +15,7 @@ function AtInputCheckboxController (baseInputController) { vm.init = (scope, element, form) => { baseInputController.call(vm, 'input', scope, element, form); scope.label = scope.state.label; - scope.state.label = vm.strings.components.OPTIONS; + scope.state.label = vm.strings.get('OPTIONS'); vm.check(); }; diff --git a/awx/ui/client/lib/components/input/group.directive.js b/awx/ui/client/lib/components/input/group.directive.js index 865a54611a..cdb14b0e58 100644 --- a/awx/ui/client/lib/components/input/group.directive.js +++ b/awx/ui/client/lib/components/input/group.directive.js @@ -101,7 +101,7 @@ function AtInputGroupController ($scope, $compile) { config._data = input.choices; config._exp = 'index as choice for (index, choice) in state._data'; } else { - let preface = vm.strings.components.UNSUPPORTED_ERROR_PREFACE; + let preface = vm.strings.get('group.UNSUPPORTED_ERROR_PREFACE'); throw new Error(`${preface}: ${input.type}`) } diff --git a/awx/ui/client/lib/components/input/label.partial.html b/awx/ui/client/lib/components/input/label.partial.html index 2a9a61690f..e5c79544d5 100644 --- a/awx/ui/client/lib/components/input/label.partial.html +++ b/awx/ui/client/lib/components/input/label.partial.html @@ -8,7 +8,7 @@ -

{{ vm.strings.components.label.PROMPT_ON_LAUNCH }}

+

{{:: vm.strings.get('label.PROMPT_ON_LAUNCH') }}

diff --git a/awx/ui/client/lib/components/input/lookup.directive.js b/awx/ui/client/lib/components/input/lookup.directive.js index f8845ddd19..362547a9d9 100644 --- a/awx/ui/client/lib/components/input/lookup.directive.js +++ b/awx/ui/client/lib/components/input/lookup.directive.js @@ -68,7 +68,7 @@ function AtInputLookupController (baseInputController, $state, $stateParams) { return { isValid: false, - message: vm.strings.components.lookup.NOT_FOUND + message: vm.strings.get('lookup.NOT_FOUND') }; }; } diff --git a/awx/ui/client/lib/components/input/secret.directive.js b/awx/ui/client/lib/components/input/secret.directive.js index a3ceebd87c..3a5f02df33 100644 --- a/awx/ui/client/lib/components/input/secret.directive.js +++ b/awx/ui/client/lib/components/input/secret.directive.js @@ -20,13 +20,13 @@ function AtInputSecretController (baseInputController) { scope = _scope_; if (!scope.state._value || scope.state._promptOnLaunch) { - scope.state._buttonText = vm.strings.components.SHOW; + scope.state._buttonText = vm.strings.get('SHOW'); scope.type = 'password'; vm.toggle = vm.toggleShowHide; } else { - scope.state._buttonText = vm.strings.components.REPLACE; - scope.state._placeholder = vm.strings.components.ENCRYPTED; + scope.state._buttonText = vm.strings.get('REPLACE'); + scope.state._placeholder = vm.strings.get('ENCRYPTED'); vm.toggle = vm.toggleRevertReplace; } @@ -36,10 +36,10 @@ function AtInputSecretController (baseInputController) { vm.toggleShowHide = () => { if (scope.type === 'password') { scope.type = 'text'; - scope.state._buttonText = vm.strings.components.HIDE; + scope.state._buttonText = vm.strings.get('HIDE'); } else { scope.type = 'password'; - scope.state._buttonText = vm.strings.components.SHOW; + scope.state._buttonText = vm.strings.get('SHOW'); } }; } diff --git a/awx/ui/client/lib/components/input/select.directive.js b/awx/ui/client/lib/components/input/select.directive.js index d61c13f33d..b86f1f8933 100644 --- a/awx/ui/client/lib/components/input/select.directive.js +++ b/awx/ui/client/lib/components/input/select.directive.js @@ -27,7 +27,7 @@ function AtInputSelectController (baseInputController, eventService) { if (!scope.state._data || scope.state._data.length === 0) { scope.state._disabled = true; - scope.state._placeholder = vm.strings.components.EMPTY_PLACEHOLDER; + scope.state._placeholder = vm.strings.get('select.EMPTY_PLACEHOLDER'); } vm.setListeners(); @@ -65,7 +65,7 @@ function AtInputSelectController (baseInputController, eventService) { } else if (scope.state._format === 'grouped-object') { scope.displayModel = scope.state._value[scope.state._display]; } else { - throw new Error(vm.strings.components.UNSUPPORTED_TYPE_ERROR); + throw new Error(vm.strings.get('select.UNSUPPORTED_TYPE_ERROR')); } }; } diff --git a/awx/ui/client/lib/components/input/textarea-secret.directive.js b/awx/ui/client/lib/components/input/textarea-secret.directive.js index ffe15c2741..ef28608b9b 100644 --- a/awx/ui/client/lib/components/input/textarea-secret.directive.js +++ b/awx/ui/client/lib/components/input/textarea-secret.directive.js @@ -26,13 +26,13 @@ function AtInputTextareaSecretController (baseInputController, eventService) { if (scope.state.format === 'ssh_private_key') { scope.ssh = true; - scope.state._hint = scope.state._hint || vm.strings.components.textarea.SSH_KEY_HINT; + scope.state._hint = scope.state._hint || vm.strings.get('textarea.SSH_KEY_HINT'); input = element.find('input')[0]; } if (scope.state._value) { - scope.state._buttonText = vm.strings.components.REPLACE; - scope.state._placeholder = vm.strings.components.ENCRYPTED; + scope.state._buttonText = vm.strings.get('REPLACE'); + scope.state._placeholder = vm.strings.get('ENCRYPTED'); } else { if (scope.state.format === 'ssh_private_key') { vm.listeners = vm.setFileListeners(textarea, input); @@ -52,7 +52,7 @@ function AtInputTextareaSecretController (baseInputController, eventService) { vm.listeners = vm.setFileListeners(textarea, input); } else { scope.state._displayHint = false; - scope.state._placeholder = vm.strings.components.ENCRYPTED; + scope.state._placeholder = vm.strings.get('ENCRYPTED'); eventService.remove(vm.listeners); } }; diff --git a/awx/ui/client/lib/components/modal/modal.partial.html b/awx/ui/client/lib/components/modal/modal.partial.html index 4ff2f44a99..1eca295b2b 100644 --- a/awx/ui/client/lib/components/modal/modal.partial.html +++ b/awx/ui/client/lib/components/modal/modal.partial.html @@ -23,7 +23,7 @@ diff --git a/awx/ui/client/lib/components/truncate/truncate.directive.js b/awx/ui/client/lib/components/truncate/truncate.directive.js index 6367d39918..fdc2eccb79 100644 --- a/awx/ui/client/lib/components/truncate/truncate.directive.js +++ b/awx/ui/client/lib/components/truncate/truncate.directive.js @@ -22,7 +22,7 @@ function AtTruncateController (strings) { vm.tooltip = { popover: { - text: vm.strings.components.truncate.DEFAULT, + text: vm.strings.get('truncate.DEFAULT'), on: 'mouseover', position: 'top', icon: 'fa fa-clone', @@ -32,7 +32,7 @@ function AtTruncateController (strings) { }; function copyToClipboard() { - vm.tooltip.popover.text = vm.strings.components.truncate.COPIED; + vm.tooltip.popover.text = vm.strings.get('truncate.COPIED'); let textarea = el[0].getElementsByClassName('at-Truncate-textarea')[0]; textarea.value = string; @@ -65,4 +65,4 @@ atTruncate.$inject = [ 'PathService' ]; -export default atTruncate; \ No newline at end of file +export default atTruncate;