From f741470365afcc9cb92c744cfec6d005b28588e2 Mon Sep 17 00:00:00 2001 From: gconsidine Date: Thu, 4 May 2017 16:58:01 -0400 Subject: [PATCH] Refine recently added components --- .../client/components/form/form.directive.js | 40 +++++++++++------ awx/ui/client/components/index.js | 2 - awx/ui/client/components/input/_index.less | 8 ++-- .../components/input/dropdown.directive.js | 41 ----------------- .../components/input/dropdown.partial.html | 24 ---------- .../components/input/search.directive.js | 6 ++- .../components/input/secret.directive.js | 0 .../components/input/select.directive.js | 28 +++++++++--- .../components/input/select.partial.html | 44 +++++++++---------- .../client/components/input/text.directive.js | 9 ++-- .../client/components/input/text.partial.html | 4 +- .../components/input/textarea.directive.js | 0 awx/ui/client/components/panel/_index.less | 24 ++++++++++ .../client/components/panel/body.directive.js | 7 ++- .../components/panel/heading.directive.js | 12 ++++- .../components/panel/heading.partial.html | 16 ++++--- .../components/panel/panel.directive.js | 28 +++++++++++- awx/ui/client/lib/index.js | 5 +++ awx/ui/client/lib/path.service.js | 16 +++++++ awx/ui/client/src/app.js | 2 + .../credentials/add-credentials.controller.js | 4 ++ .../src/credentials/add-credentials.view.html | 7 ++- awx/ui/client/src/credentials/index.js | 14 +++--- awx/ui/client/theme/_common.less | 21 +-------- awx/ui/client/theme/_utility.less | 14 +++++- 25 files changed, 211 insertions(+), 165 deletions(-) delete mode 100644 awx/ui/client/components/input/dropdown.directive.js delete mode 100644 awx/ui/client/components/input/dropdown.partial.html delete mode 100644 awx/ui/client/components/input/secret.directive.js delete mode 100644 awx/ui/client/components/input/textarea.directive.js create mode 100644 awx/ui/client/lib/index.js create mode 100644 awx/ui/client/lib/path.service.js diff --git a/awx/ui/client/components/form/form.directive.js b/awx/ui/client/components/form/form.directive.js index 8814e6b742..5922a08b20 100644 --- a/awx/ui/client/components/form/form.directive.js +++ b/awx/ui/client/components/form/form.directive.js @@ -1,32 +1,42 @@ -function track (element) { +function use (componentScope, componentElement) { let vm = this; - let input = { - el: element, - tabindex: vm.form.inputs.length + 1, - autofocus: vm.form.inputs.length === 0 - }; + let input = vm.track(componentElement); - vm.form.inputs.push(input); + componentScope.meta = input; +} - return input; +function track (componentElement) { + let vm = this; + + let input = { + el: componentElement, + tabindex: vm.inputs.length + 1 + }; + + if (vm.inputs.length === 0) { + input.autofocus = true; + componentElement.find('input').focus(); + } + + vm.inputs.push(input); + + return input; } function controller () { let vm = this; - vm.form = { - inputs: [] - }; - + vm.inputs = []; + vm.use = use; vm.track = track; } -function atForm () { +function atForm (pathService) { return { restrict: 'E', transclude: true, - templateUrl: 'static/partials/components/form/form.partial.html', + templateUrl: pathService.getPartialPath('components/form/form'), controller, controllerAs: 'vm', scope: { @@ -35,4 +45,6 @@ function atForm () { }; } +atForm.$inject = ['PathService']; + export default atForm; diff --git a/awx/ui/client/components/index.js b/awx/ui/client/components/index.js index 48bdd08955..bdcccc1470 100644 --- a/awx/ui/client/components/index.js +++ b/awx/ui/client/components/index.js @@ -1,6 +1,5 @@ import badge from './badge/badge.directive'; import form from './form/form.directive'; -import inputDropdown from './input/dropdown.directive'; import inputSearch from './input/search.directive'; import inputSelect from './input/select.directive'; import inputText from './input/text.directive'; @@ -14,7 +13,6 @@ angular .module('at.components', []) .directive('atBadge', badge) .directive('atForm', form) - .directive('atInputDropdown', inputDropdown) .directive('atInputSearch', inputSearch) .directive('atInputSelect', inputSelect) .directive('atInputText', inputText) diff --git a/awx/ui/client/components/input/_index.less b/awx/ui/client/components/input/_index.less index 6c746fc2b6..79492ed1da 100644 --- a/awx/ui/client/components/input/_index.less +++ b/awx/ui/client/components/input/_index.less @@ -42,25 +42,25 @@ & > i { position: absolute; - z-index: 4; + z-index: 3; pointer-events: none; right: @at-padding-sm; top: @at-padding-sm; } } -.at-Dropdown { +.at-Select { height: @at-input-height-md; position: relative; } -.at-Dropdown-input { +.at-Select-input { position: relative; z-index: 2; pointer-events: none; } -.at-Dropdown-select { +.at-Select-select { position: absolute; z-index: 1; top: 0; diff --git a/awx/ui/client/components/input/dropdown.directive.js b/awx/ui/client/components/input/dropdown.directive.js deleted file mode 100644 index 3027fc1f11..0000000000 --- a/awx/ui/client/components/input/dropdown.directive.js +++ /dev/null @@ -1,41 +0,0 @@ -function link (scope, el, attrs, form) { - scope.form = form.track(el); - - scope.open = false; - - let input = el.find('input')[0]; - let select = el.find('select')[0]; - - input.addEventListener('focus', () => select.focus()); - select.addEventListener('focus', () => input.classList.add('at-Input--focus')); - - select.addEventListener('mousedown', () => { - scope.open = true; - }); - - select.addEventListener('blur', () => { - input.classList.remove('at-Input--focus'); - scope.open = false; - }); - - select.addEventListener('change', () => { - scope.open = false; - }); -} - -function atInputDropdown () { - return { - restrict: 'E', - transclude: true, - replace: true, - require: '^^at-form', - templateUrl: 'static/partials/components/input/dropdown.partial.html', - link, - scope: { - config: '=', - col: '@' - } - }; -} - -export default atInputDropdown; diff --git a/awx/ui/client/components/input/dropdown.partial.html b/awx/ui/client/components/input/dropdown.partial.html deleted file mode 100644 index cfa1291b6c..0000000000 --- a/awx/ui/client/components/input/dropdown.partial.html +++ /dev/null @@ -1,24 +0,0 @@ -
-
- -
- - - - - -
-
-
diff --git a/awx/ui/client/components/input/search.directive.js b/awx/ui/client/components/input/search.directive.js index e64f58ac57..36995b6340 100644 --- a/awx/ui/client/components/input/search.directive.js +++ b/awx/ui/client/components/input/search.directive.js @@ -1,6 +1,6 @@ // TODO: i18n -function atInputSearch () { +function atInputSearch (pathService) { function link (scope) { scope.config = scope.config || {}; scope.config.placeholder = scope.config.placeholder || 'SEARCH'; @@ -9,7 +9,7 @@ function atInputSearch () { return { restrict: 'E', transclude: true, - templateUrl: 'static/partials/components/input/search.partial.html', + templateUrl: pathService.getPartialPath('components/input/search'), link, scope: { config: '=' @@ -17,4 +17,6 @@ function atInputSearch () { }; } +atInputSearch.$inject = ['PathService']; + export default atInputSearch; diff --git a/awx/ui/client/components/input/secret.directive.js b/awx/ui/client/components/input/secret.directive.js deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/awx/ui/client/components/input/select.directive.js b/awx/ui/client/components/input/select.directive.js index a0c57be12d..599b89d284 100644 --- a/awx/ui/client/components/input/select.directive.js +++ b/awx/ui/client/components/input/select.directive.js @@ -1,18 +1,34 @@ -// TODO: i18n +function link (scope, el, attrs, form) { + form.use(scope, el); -function atInputSelect () { - function link (scope, element, attrs) { - } + let input = el.find('input')[0]; + let select = el.find('select')[0]; + input.addEventListener('focus', () => select.focus()); + select.addEventListener('focus', () => input.classList.add('at-Input--focus')); + select.addEventListener('mousedown', () => scope.open = !scope.open); + select.addEventListener('change', () => scope.open = false ); + select.addEventListener('blur', () => { + input.classList.remove('at-Input--focus') + scope.open = scope.open && false; + }); +} + +function atInputSelect (pathService) { return { restrict: 'E', transclude: true, - templateUrl: 'static/partials/components/input/select.partial.html', + replace: true, + require: '^^at-form', + templateUrl: pathService.getPartialPath('components/input/select'), link, scope: { - config: '=' + config: '=', + col: '@' } }; } +atInputSelect.$inject = ['PathService']; + export default atInputSelect; diff --git a/awx/ui/client/components/input/select.partial.html b/awx/ui/client/components/input/select.partial.html index c45807fb3f..98d708954e 100644 --- a/awx/ui/client/components/input/select.partial.html +++ b/awx/ui/client/components/input/select.partial.html @@ -1,25 +1,23 @@ -
- -
- - - - +
+
+ +
+ + + + +
diff --git a/awx/ui/client/components/input/text.directive.js b/awx/ui/client/components/input/text.directive.js index 3f9120c413..5bb3b57490 100644 --- a/awx/ui/client/components/input/text.directive.js +++ b/awx/ui/client/components/input/text.directive.js @@ -1,15 +1,14 @@ function link (scope, el, attrs, form) { - scope.form = form.track(el); - console.log('text', scope.form); + form.use(scope, el); } -function atInputText () { +function atInputText (pathService) { return { restrict: 'E', transclude: true, replace: true, require: '^^at-form', - templateUrl: 'static/partials/components/input/text.partial.html', + templateUrl: pathService.getPartialPath('components/input/text'), link, scope: { config: '=', @@ -18,4 +17,6 @@ function atInputText () { }; } +atInputText.$inject = ['PathService']; + export default atInputText; diff --git a/awx/ui/client/components/input/text.partial.html b/awx/ui/client/components/input/text.partial.html index f23f93fd15..711bd93669 100644 --- a/awx/ui/client/components/input/text.partial.html +++ b/awx/ui/client/components/input/text.partial.html @@ -1,11 +1,11 @@
-
+
diff --git a/awx/ui/client/components/input/textarea.directive.js b/awx/ui/client/components/input/textarea.directive.js deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/awx/ui/client/components/panel/_index.less b/awx/ui/client/components/panel/_index.less index 47686b419d..13889adf45 100644 --- a/awx/ui/client/components/panel/_index.less +++ b/awx/ui/client/components/panel/_index.less @@ -8,7 +8,31 @@ padding: 0; } +.at-Panel-dismiss { + line-height: 0.9; + text-align: right; + color: @at-gray-light; + + & > i { + cursor: pointer; + } + + & > i:hover { + color: @at-gray; + } +} + .at-Panel-body { margin: @at-margin-md 0 0 0; padding: 0; } + +.at-Panel-headingTitle { + color: @at-gray-dark; + font-size: @at-font-md; + font-weight: bold; + line-height: 0.9; + text-transform: uppercase; + margin: 0; + padding: 0; +} diff --git a/awx/ui/client/components/panel/body.directive.js b/awx/ui/client/components/panel/body.directive.js index 2f8f5b0102..157a8d8ad7 100644 --- a/awx/ui/client/components/panel/body.directive.js +++ b/awx/ui/client/components/panel/body.directive.js @@ -1,9 +1,12 @@ -function atPanelBody () { +function atPanelBody (pathService) { return { restrict: 'E', + require: '^^atPanel', transclude: true, - templateUrl: 'static/partials/components/panel/body.partial.html' + templateUrl: pathService.getPartialPath('components/panel/body'), }; } +atPanelBody.$inject = ['PathService']; + export default atPanelBody; diff --git a/awx/ui/client/components/panel/heading.directive.js b/awx/ui/client/components/panel/heading.directive.js index 51f29e8a1f..1f8e4459a8 100644 --- a/awx/ui/client/components/panel/heading.directive.js +++ b/awx/ui/client/components/panel/heading.directive.js @@ -1,12 +1,20 @@ -function atPanelHeading () { +function link (scope, el, attrs, panel) { + panel.use(scope); +} + +function atPanelHeading (pathService) { return { restrict: 'E', + require: '^^atPanel', transclude: true, - templateUrl: 'static/partials/components/panel/heading.partial.html', + templateUrl: pathService.getPartialPath('components/panel/heading'), + link, scope: { config: '=' } }; } +atPanelHeading.$inject = ['PathService']; + export default atPanelHeading; diff --git a/awx/ui/client/components/panel/heading.partial.html b/awx/ui/client/components/panel/heading.partial.html index ca88c959ba..50f50327b1 100644 --- a/awx/ui/client/components/panel/heading.partial.html +++ b/awx/ui/client/components/panel/heading.partial.html @@ -1,8 +1,12 @@ -
-
-
- +
+
+

+ {{ config.text }} +

+
+
+
+ +
-
- diff --git a/awx/ui/client/components/panel/panel.directive.js b/awx/ui/client/components/panel/panel.directive.js index 70ae28d30a..386ff543fe 100644 --- a/awx/ui/client/components/panel/panel.directive.js +++ b/awx/ui/client/components/panel/panel.directive.js @@ -1,9 +1,33 @@ -function atPanel () { +function use (scope) { + scope.dismiss = this.dismiss; +} + +function dismiss ($state) { + $state.go('^'); +} + +function controller ($state) { + let vm = this; + + vm.dismiss = dismiss.bind(vm, $state); + vm.use = use; +} + +controller.$inject = ['$state']; + +function atPanel (pathService) { return { restrict: 'E', transclude: true, - templateUrl: 'static/partials/components/panel/panel.partial.html' + templateUrl: pathService.getPartialPath('components/panel/panel'), + controller, + controllerAs: 'vm', + scope: { + config: '=' + } }; } +atPanel.$inject = ['PathService']; + export default atPanel; diff --git a/awx/ui/client/lib/index.js b/awx/ui/client/lib/index.js new file mode 100644 index 0000000000..e6f66c9832 --- /dev/null +++ b/awx/ui/client/lib/index.js @@ -0,0 +1,5 @@ +import PathService from './path.service'; + +angular + .module('at.lib', []) + .factory('PathService', PathService); diff --git a/awx/ui/client/lib/path.service.js b/awx/ui/client/lib/path.service.js new file mode 100644 index 0000000000..fd1180c935 --- /dev/null +++ b/awx/ui/client/lib/path.service.js @@ -0,0 +1,16 @@ +function getPartialPath (path) { + return `/static/partials/${path}.partial.html`; +} + +function getViewPath (path) { + return `/static/views/${path}.view.html`; +} + +function PathService () { + return { + getPartialPath, + getViewPath + }; +} + +export default PathService; diff --git a/awx/ui/client/src/app.js b/awx/ui/client/src/app.js index 092bb525c9..edc04c82f4 100644 --- a/awx/ui/client/src/app.js +++ b/awx/ui/client/src/app.js @@ -74,6 +74,7 @@ import instanceGroups from './instance-groups/main'; import '../components'; import '../models'; +import '../lib'; import './credentials'; var tower = angular.module('Tower', [ @@ -138,6 +139,7 @@ var tower = angular.module('Tower', [ 'ngResource', 'at.components', 'at.models', + 'at.lib', 'at.features.credentials' ]) diff --git a/awx/ui/client/src/credentials/add-credentials.controller.js b/awx/ui/client/src/credentials/add-credentials.controller.js index 4c57f61786..406a02d79c 100644 --- a/awx/ui/client/src/credentials/add-credentials.controller.js +++ b/awx/ui/client/src/credentials/add-credentials.controller.js @@ -10,6 +10,10 @@ function AddCredentialsController (credentialType) { label: 'Description' }; + vm.heading = { + text: 'Create Credentials' + }; + vm.kind = { label: 'Type', placeholder: 'Select a Type', diff --git a/awx/ui/client/src/credentials/add-credentials.view.html b/awx/ui/client/src/credentials/add-credentials.view.html index 10ad1e8710..cb5f3f5c83 100644 --- a/awx/ui/client/src/credentials/add-credentials.view.html +++ b/awx/ui/client/src/credentials/add-credentials.view.html @@ -1,13 +1,12 @@ - - - Create Credentials + + - + diff --git a/awx/ui/client/src/credentials/index.js b/awx/ui/client/src/credentials/index.js index 707f7b5c76..2ff69704ed 100644 --- a/awx/ui/client/src/credentials/index.js +++ b/awx/ui/client/src/credentials/index.js @@ -3,7 +3,8 @@ import ListController from './list/credentials-list.controller'; import AddController from './add-credentials.controller.js'; import { N_ } from '../i18n'; -function config ($stateExtenderProvider) { +function config ($stateExtenderProvider, pathServiceProvider) { + let pathService = pathServiceProvider.$get(); let stateExtender = $stateExtenderProvider.$get(); stateExtender.addState({ @@ -14,7 +15,7 @@ function config ($stateExtenderProvider) { }, views: { '@': { - templateUrl: '/static/views/credentials/index.view.html', + templateUrl: pathService.getViewPath('credentials/index') }, 'list@credentials': { templateProvider: function(CredentialList, generateList) { @@ -47,14 +48,14 @@ function config ($stateExtenderProvider) { }, views: { 'add@credentials': { - templateUrl: '/static/views/credentials/add-credentials.view.html', + templateUrl: pathService.getViewPath('credentials/add-credentials'), controller: AddController, controllerAs: 'vm' } }, resolve: { - credentialType: ['CredentialType', CredentialType => { - return CredentialType.get().then(() => CredentialType); + credentialType: ['CredentialType', credentialType => { + return credentialType.get().then(() => credentialType); }] } }); @@ -76,7 +77,8 @@ function config ($stateExtenderProvider) { } config.$inject = [ - '$stateExtenderProvider' + '$stateExtenderProvider', + 'PathServiceProvider' ]; angular diff --git a/awx/ui/client/theme/_common.less b/awx/ui/client/theme/_common.less index 665db39da4..d85df32ae1 100644 --- a/awx/ui/client/theme/_common.less +++ b/awx/ui/client/theme/_common.less @@ -1,28 +1,11 @@ /** * For styles that are used in more than one place throughout the application. * - * 1. Content - * 2. Buttons + * 1. Buttons * */ -// 1. Content -// ------------------------------------------------------------------------------------------------ -.at-Title-row { - align-items: center; - flex: 1 0 auto; - display: flex; -} - -.at-Title-text { - color: @at-gray-dark; - font-size: @at-font-md; - font-weight: bold; - margin-right: @at-margin-sm; - text-transform: uppercase; -} - -// 2. Buttons +// 1. Buttons // ------------------------------------------------------------------------------------------------ .at-Button--success { .at-Button(@at-success, @at-white); diff --git a/awx/ui/client/theme/_utility.less b/awx/ui/client/theme/_utility.less index ac6ee55f23..178e7faa7e 100644 --- a/awx/ui/client/theme/_utility.less +++ b/awx/ui/client/theme/_utility.less @@ -1,3 +1,13 @@ -.at-u-noPadding { - padding: 0; +.at-u-flat { + padding-top: 0; + padding-bottom: 0; + margin-top: 0; + margin-bottom: 0; +} + +.at-u-thin { + padding-left: 0; + padding-right: 0; + margin-left: 0; + margin-right: 0; }