From 2509c573a591c731292380e0491bf423bf03de18 Mon Sep 17 00:00:00 2001 From: gconsidine Date: Wed, 3 May 2017 16:39:55 -0400 Subject: [PATCH] Add form, text, and custom dropdown components --- .../client/components/form/form.directive.js | 38 +++++++++++++++++ .../client/components/form/form.partial.html | 5 +++ awx/ui/client/components/index.js | 4 ++ awx/ui/client/components/input/_index.less | 40 ++++++++++++++++-- .../components/input/dropdown.directive.js | 41 +++++++++++++++++++ .../components/input/dropdown.partial.html | 24 +++++++++++ .../components/input/select.directive.js | 1 - .../components/input/select.partial.html | 29 ++++++++----- .../client/components/input/text.directive.js | 11 ++++- .../client/components/input/text.partial.html | 17 ++++---- awx/ui/client/src/app.js | 6 +-- .../credentials/add-credentials.controller.js | 1 + .../src/credentials/add-credentials.view.html | 23 +++-------- awx/ui/client/src/credentials/index.js | 2 +- awx/ui/client/theme/_variables.less | 2 + 15 files changed, 197 insertions(+), 47 deletions(-) create mode 100644 awx/ui/client/components/form/form.directive.js create mode 100644 awx/ui/client/components/form/form.partial.html create mode 100644 awx/ui/client/components/input/dropdown.directive.js create mode 100644 awx/ui/client/components/input/dropdown.partial.html diff --git a/awx/ui/client/components/form/form.directive.js b/awx/ui/client/components/form/form.directive.js new file mode 100644 index 0000000000..8814e6b742 --- /dev/null +++ b/awx/ui/client/components/form/form.directive.js @@ -0,0 +1,38 @@ +function track (element) { + let vm = this; + + let input = { + el: element, + tabindex: vm.form.inputs.length + 1, + autofocus: vm.form.inputs.length === 0 + }; + + vm.form.inputs.push(input); + + return input; +} + +function controller () { + let vm = this; + + vm.form = { + inputs: [] + }; + + vm.track = track; +} + +function atForm () { + return { + restrict: 'E', + transclude: true, + templateUrl: 'static/partials/components/form/form.partial.html', + controller, + controllerAs: 'vm', + scope: { + config: '=' + } + }; +} + +export default atForm; diff --git a/awx/ui/client/components/form/form.partial.html b/awx/ui/client/components/form/form.partial.html new file mode 100644 index 0000000000..95ccc844b1 --- /dev/null +++ b/awx/ui/client/components/form/form.partial.html @@ -0,0 +1,5 @@ +
+
+ +
+
diff --git a/awx/ui/client/components/index.js b/awx/ui/client/components/index.js index 3841db9070..48bdd08955 100644 --- a/awx/ui/client/components/index.js +++ b/awx/ui/client/components/index.js @@ -1,4 +1,6 @@ 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'; @@ -11,6 +13,8 @@ import toggleContent from './toggle/content.directive'; 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 4652ef3083..6c746fc2b6 100644 --- a/awx/ui/client/components/input/_index.less +++ b/awx/ui/client/components/input/_index.less @@ -5,9 +5,13 @@ border-radius: @at-border-radius-md; color: @at-gray-darkest; - &, &:focus, &:active { + &, &:active { border-color: @at-gray-light; } + + &:focus { + border-color: @at-link; + } } .at-Input-label { @@ -28,8 +32,36 @@ color: @at-gray; } -.at-Dropdown-option--placeholder { - &[value=""] { - display: none; +.at-Input--focus { + border-color: @at-link; +} + +.at-InputGroup { + position: relative; + width: 100%; + + & > i { + position: absolute; + z-index: 4; + pointer-events: none; + right: @at-padding-sm; + top: @at-padding-sm; } } + +.at-Dropdown { + height: @at-input-height-md; + position: relative; +} + +.at-Dropdown-input { + position: relative; + z-index: 2; + pointer-events: none; +} + +.at-Dropdown-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 new file mode 100644 index 0000000000..3027fc1f11 --- /dev/null +++ b/awx/ui/client/components/input/dropdown.directive.js @@ -0,0 +1,41 @@ +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 new file mode 100644 index 0000000000..cfa1291b6c --- /dev/null +++ b/awx/ui/client/components/input/dropdown.partial.html @@ -0,0 +1,24 @@ +
+
+ +
+ + + + + +
+
+
diff --git a/awx/ui/client/components/input/select.directive.js b/awx/ui/client/components/input/select.directive.js index dbf0b0375c..a0c57be12d 100644 --- a/awx/ui/client/components/input/select.directive.js +++ b/awx/ui/client/components/input/select.directive.js @@ -2,7 +2,6 @@ function atInputSelect () { function link (scope, element, attrs) { - scope.active = false; } return { diff --git a/awx/ui/client/components/input/select.partial.html b/awx/ui/client/components/input/select.partial.html index 030a1077ad..c45807fb3f 100644 --- a/awx/ui/client/components/input/select.partial.html +++ b/awx/ui/client/components/input/select.partial.html @@ -3,16 +3,23 @@ * {{ config.label }} - + - - + + + + + + + + diff --git a/awx/ui/client/components/input/text.directive.js b/awx/ui/client/components/input/text.directive.js index f6bab7d547..3f9120c413 100644 --- a/awx/ui/client/components/input/text.directive.js +++ b/awx/ui/client/components/input/text.directive.js @@ -1,12 +1,19 @@ -// TODO: i18n +function link (scope, el, attrs, form) { + scope.form = form.track(el); + console.log('text', scope.form); +} function atInputText () { return { restrict: 'E', transclude: true, + replace: true, + require: '^^at-form', templateUrl: 'static/partials/components/input/text.partial.html', + link, scope: { - config: '=' + config: '=', + col: '@' } }; } diff --git a/awx/ui/client/components/input/text.partial.html b/awx/ui/client/components/input/text.partial.html index 91dbe26542..f23f93fd15 100644 --- a/awx/ui/client/components/input/text.partial.html +++ b/awx/ui/client/components/input/text.partial.html @@ -1,8 +1,11 @@ -
- - +
+
+ + +
diff --git a/awx/ui/client/src/app.js b/awx/ui/client/src/app.js index 93bd8ac586..092bb525c9 100644 --- a/awx/ui/client/src/app.js +++ b/awx/ui/client/src/app.js @@ -136,9 +136,9 @@ var tower = angular.module('Tower', [ 'features', 'ngResource', - 'at.component', - 'at.model', - 'at.feature.credentials' + 'at.components', + 'at.models', + 'at.features.credentials' ]) .constant('AngularScheduler.partials', urlPrefix + 'lib/angular-scheduler/lib/') diff --git a/awx/ui/client/src/credentials/add-credentials.controller.js b/awx/ui/client/src/credentials/add-credentials.controller.js index ea8fa34903..4c57f61786 100644 --- a/awx/ui/client/src/credentials/add-credentials.controller.js +++ b/awx/ui/client/src/credentials/add-credentials.controller.js @@ -12,6 +12,7 @@ function AddCredentialsController (credentialType) { vm.kind = { label: 'Type', + placeholder: 'Select a Type', required: true, text: 'kind', value: 'id', diff --git a/awx/ui/client/src/credentials/add-credentials.view.html b/awx/ui/client/src/credentials/add-credentials.view.html index 242052bf68..10ad1e8710 100644 --- a/awx/ui/client/src/credentials/add-credentials.view.html +++ b/awx/ui/client/src/credentials/add-credentials.view.html @@ -4,23 +4,10 @@ - - Details - Permissions - - -
-
- -
- -
- -
- -
- -
-
+ + + + +
diff --git a/awx/ui/client/src/credentials/index.js b/awx/ui/client/src/credentials/index.js index ceb3e14619..707f7b5c76 100644 --- a/awx/ui/client/src/credentials/index.js +++ b/awx/ui/client/src/credentials/index.js @@ -80,7 +80,7 @@ config.$inject = [ ]; angular - .module('at.feature.credentials', []) + .module('at.features.credentials', []) .config(config) .factory('CredentialList', CredentialList) .controller('ListController', ListController) diff --git a/awx/ui/client/theme/_variables.less b/awx/ui/client/theme/_variables.less index 4e09ca6a45..f8a10a27ea 100644 --- a/awx/ui/client/theme/_variables.less +++ b/awx/ui/client/theme/_variables.less @@ -28,3 +28,5 @@ @at-margin-md: 20px; @at-border-radius-md: 5px; + +@at-input-height-md: 34px;