Repository: incubator-ignite Updated Branches: refs/heads/ignite-843 6036af68b -> 7511acce4
IGNITE-843 Minor refactoring of focusing logic. Fixed typeahead loosing cursor position on typing. Updated libraries. Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/7511acce Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/7511acce Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/7511acce Branch: refs/heads/ignite-843 Commit: 7511acce42da41a6bdec1369b7a4c5d96e95fb41 Parents: 6036af6 Author: AKuznetsov <akuznet...@gridgain.com> Authored: Tue Aug 4 00:28:09 2015 +0700 Committer: AKuznetsov <akuznet...@gridgain.com> Committed: Tue Aug 4 00:28:09 2015 +0700 ---------------------------------------------------------------------- .../main/js/controllers/caches-controller.js | 14 ++-- .../src/main/js/controllers/common-module.js | 74 +++++++++++++++++--- .../main/js/controllers/metadata-controller.js | 32 ++++----- .../main/js/controllers/models/metadata.json | 4 +- .../control-center-web/src/main/js/package.json | 1 - .../src/main/js/routes/generator/common.js | 6 +- .../main/js/views/configuration/summary.jade | 5 +- .../src/main/js/views/includes/controls.jade | 14 ++-- .../src/main/js/views/templates/layout.jade | 9 +-- 9 files changed, 106 insertions(+), 53 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7511acce/modules/control-center-web/src/main/js/controllers/caches-controller.js ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/controllers/caches-controller.js b/modules/control-center-web/src/main/js/controllers/caches-controller.js index 7844e02..3469ff8 100644 --- a/modules/control-center-web/src/main/js/controllers/caches-controller.js +++ b/modules/control-center-web/src/main/js/controllers/caches-controller.js @@ -126,15 +126,15 @@ controlCenterModule.controller('cachesController', ['$scope', '$http', '$common' return false; }; - function focusInvalidField(index, newId, curId) { - $focus(index < 0 ? newId : curId); + function focusInvalidField(index, id) { + $focus(index < 0 ? 'new' + id : 'cur' + id); return false; } $scope.tableSimpleValid = function (item, field, fx, index) { if (!$common.isValidJavaClass('SQL function', fx, false)) - return focusInvalidField(index, 'newSqlFxField', 'curSqlFxField'); + return focusInvalidField(index, 'SqlFxField'); var model = item[field.model]; @@ -145,7 +145,7 @@ controlCenterModule.controller('cachesController', ['$scope', '$http', '$common' if (idx >= 0 && idx != index) { $common.showError('SQL function with such class name already exists!'); - return focusInvalidField(index, 'newSqlFxField', 'curSqlFxField'); + return focusInvalidField(index, 'SqlFxField'); } } @@ -154,10 +154,10 @@ controlCenterModule.controller('cachesController', ['$scope', '$http', '$common' $scope.tablePairValid = function (item, field, keyCls, valCls, index) { if (!$common.isValidJavaClass('Indexed type key', keyCls, true)) - return focusInvalidField(index, 'newIndexedType', 'curIndexedType'); + return focusInvalidField(index, 'IndexedType'); if (!$common.isValidJavaClass('Indexed type value', valCls, true)) - return focusInvalidField(index, 'newIndexedType_next', 'curIndexedType_next'); + return focusInvalidField(index, 'IndexedTypeNext'); var model = item[field.model]; @@ -170,7 +170,7 @@ controlCenterModule.controller('cachesController', ['$scope', '$http', '$common' if (idx >= 0 && idx != index) { $common.showError('Indexed type with such key class already exists!'); - return focusInvalidField(index, 'newIndexedType', 'curIndexedType'); + return focusInvalidField(index, 'IndexedType'); } } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7511acce/modules/control-center-web/src/main/js/controllers/common-module.js ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/controllers/common-module.js b/modules/control-center-web/src/main/js/controllers/common-module.js index 744ea28..af54b42 100644 --- a/modules/control-center-web/src/main/js/controllers/common-module.js +++ b/modules/control-center-web/src/main/js/controllers/common-module.js @@ -92,7 +92,7 @@ controlCenterModule.service('$common', ['$alert', function ($alert) { } var javaBuildInClasses = [ - 'BigDecimal, Boolean', 'Byte', 'Date', 'Double', 'Float', 'Integer', 'Long', 'Short', 'String', 'Time', 'Timestamp', 'UUID' + 'BigDecimal', 'Boolean', 'Byte', 'Date', 'Double', 'Float', 'Integer', 'Long', 'Short', 'String', 'Time', 'Timestamp', 'UUID' ]; var javaBuildInFullNameClasses = [ @@ -464,8 +464,8 @@ controlCenterModule.directive('match', function ($parse) { // Directive to bind ENTER key press with some user action. controlCenterModule.directive('onEnter', function ($timeout) { - return function (scope, element, attrs) { - element.bind('keydown keypress', function (event) { + return function (scope, elem, attrs) { + elem.on('keydown keypress', function (event) { if (event.which === 13) { scope.$apply(function () { $timeout(function () { @@ -476,13 +476,18 @@ controlCenterModule.directive('onEnter', function ($timeout) { event.preventDefault(); } }); + + // Removes bound events in the element itself when the scope is destroyed + scope.$on('$destroy', function () { + elem.off('keydown keypress'); + }); }; }); // Directive to bind ESC key press with some user action. controlCenterModule.directive('onEscape', function () { - return function (scope, element, attrs) { - element.bind('keydown keyup', function (event) { + return function (scope, elem, attrs) { + elem.on('keydown keypress', function (event) { if (event.which === 27) { scope.$apply(function () { scope.$eval(attrs.onEscape); @@ -491,6 +496,55 @@ controlCenterModule.directive('onEscape', function () { event.preventDefault(); } }); + + // Removes bound events in the element itself when the scope is destroyed + scope.$on('$destroy', function () { + elem.off('keydown keypress'); + }); + }; +}); + +// Directive to retain selection. +controlCenterModule.directive('retainSelection', function ($timeout) { + return function (scope, elem, attr) { + elem.on('keydown', function (event) { + var key = event.which; + + console.log(key); + + var input = this; + + var start = input.selectionStart; + + $timeout(function() { + var setCursor = false; + + // Handle Backspace. + if (key == 8 && start > 0) { + start -= 1; + + setCursor = true; + } + // Handle Del. + else if (key == 46) + setCursor = true; + // Handle: Caps Lock, Tab, Shift, Ctrl, Alt, Esc, Enter, Arrows, Home, End, PgUp, PgDown, F1..F12, Num Lock, Scroll Lock. + else if (!(key == 9 || key == 13 || (key > 15 && key < 20) || key == 27 || + (key > 32 && key < 41) || (key > 111 && key < 124) || key == 144 || key == 145)) { + start += 1; + + setCursor = true; + } + + if (setCursor) + input.setSelectionRange(start, start); + }); + }); + + // Removes bound events in the element itself when the scope is destroyed + scope.$on('$destroy', function () { + elem.off('keydown'); + }); }; }); @@ -501,18 +555,18 @@ controlCenterModule.factory('$focus', function ($timeout, $window) { // E.g. click events that need to run before the focus or inputs elements that are // in a disabled state but are enabled when those events are triggered. $timeout(function () { - var element = $window.document.getElementById(id); + var elem = $window.document.getElementById(id); - if (element) - element.focus(); + if (elem) + elem.focus(); }); }; }); // Directive to focus next element on ENTER key. controlCenterModule.directive('enterFocusNext', function ($focus) { - return function (scope, element, attrs) { - element.bind('keydown keypress', function (event) { + return function (scope, elem, attrs) { + elem.on('keydown keypress', function (event) { if (event.which === 13) { event.preventDefault(); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7511acce/modules/control-center-web/src/main/js/controllers/metadata-controller.js ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/controllers/metadata-controller.js b/modules/control-center-web/src/main/js/controllers/metadata-controller.js index 5af7ff3..96718fd 100644 --- a/modules/control-center-web/src/main/js/controllers/metadata-controller.js +++ b/modules/control-center-web/src/main/js/controllers/metadata-controller.js @@ -507,8 +507,8 @@ controlCenterModule.controller('metadataController', ['$scope', '$http', '$commo }); }; - function focusInvalidField(index, newId, curId) { - $focus(index < 0 ? newId : curId); + function focusInvalidField(index, id) { + $focus(index < 0 ? 'new' + id : 'cur' + id); return false; } @@ -523,7 +523,7 @@ controlCenterModule.controller('metadataController', ['$scope', '$http', '$commo if (idx >= 0 && idx != index) { $common.showError('Field with such name already exists!'); - return focusInvalidField(index, 'newTextField', 'curTextField'); + return focusInvalidField(index, 'TextField'); } } @@ -531,9 +531,9 @@ controlCenterModule.controller('metadataController', ['$scope', '$http', '$commo }; var pairFields = { - queryFields: {msg: 'Query field class', newId: 'newQryField', curId: 'curQryField'}, - ascendingFields: {msg: 'Ascending field class', newId: 'newAscField', curId: 'curAscField'}, - descendingFields: {msg: 'Descending field class', newId: 'newDescField', curId: 'curDescField'} + queryFields: {msg: 'Query field class', id: 'QryField'}, + ascendingFields: {msg: 'Ascending field class', id: 'AscField'}, + descendingFields: {msg: 'Descending field class', id: 'DescField'} }; $scope.tablePairValid = function (item, field, name, clsName, index) { @@ -541,7 +541,7 @@ controlCenterModule.controller('metadataController', ['$scope', '$http', '$commo if (pairField) { if (!$common.isValidJavaClass(pairField.msg, clsName, true)) - return focusInvalidField(index, pairField.newId + '_next', pairField.curId + '_next'); + return focusInvalidField(index, pairField.id + 'Next'); var model = item[field.model]; @@ -554,7 +554,7 @@ controlCenterModule.controller('metadataController', ['$scope', '$http', '$commo if (idx >= 0 && idx != index) { $common.showError('Field with such name already exists!'); - return focusInvalidField(index, pairField.newId, pairField.curId); + return focusInvalidField(index, pairField.id); } } } @@ -567,8 +567,8 @@ controlCenterModule.controller('metadataController', ['$scope', '$http', '$commo }; var dbFields = { - keyFields: {msg: 'Key field', newId: 'newKeyField', curId: 'curKeyField'}, - valueFields: {msg: 'Value field', newId: 'newValField', curId: 'curValField'} + keyFields: {msg: 'Key field', id: 'KeyField'}, + valueFields: {msg: 'Value field', id: 'ValueField'} }; $scope.tableDbFieldSave = function (field, newDatabaseName, newDatabaseType, newJavaName, newJavaType, index) { @@ -587,7 +587,7 @@ controlCenterModule.controller('metadataController', ['$scope', '$http', '$commo }; if (!$common.isValidJavaIdentifier(dbField.msg + ' java name', newJavaName)) - return focusInvalidField(index, dbField.newId + '_next', dbField.curId + '_next'); + return focusInvalidField(index, dbField.id + 'Next'); if ($common.isDefined(model)) { var idx = _.findIndex(model, function (dbMeta) { @@ -598,7 +598,7 @@ controlCenterModule.controller('metadataController', ['$scope', '$http', '$commo if (idx >= 0 && index != idx) { $common.showError('DB field with such name already exists!'); - return focusInvalidField(index, dbField.newId, dbField.curId); + return focusInvalidField(index, dbField.id); } if (index < 0) { @@ -639,7 +639,7 @@ controlCenterModule.controller('metadataController', ['$scope', '$http', '$commo if (idx >= 0 && idx != index) { $common.showError('Group with such name already exists!'); - return focusInvalidField(index, 'newGroupName', 'curGroupName'); + return focusInvalidField(index, 'GroupName'); } } @@ -714,7 +714,7 @@ controlCenterModule.controller('metadataController', ['$scope', '$http', '$commo function tableGroupItemValid(fieldName, className, groupIndex, index) { if (!$common.isValidJavaClass('Group field', className, true)) - return focusInvalidField(index, 'newFieldName_next', 'curFieldName_next'); + return focusInvalidField(index, 'FieldNameNext'); var fields = $scope.backupItem.groups[groupIndex].fields; @@ -727,7 +727,7 @@ controlCenterModule.controller('metadataController', ['$scope', '$http', '$commo if (idx >= 0 && idx != index) { $common.showError('Field with such name already exists in group!'); - return focusInvalidField(index, 'newFieldName', 'curFieldName'); + return focusInvalidField(index, 'FieldName'); } } @@ -811,4 +811,4 @@ controlCenterModule.controller('metadataController', ['$scope', '$http', '$commo }; }] ) -; \ No newline at end of file +; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7511acce/modules/control-center-web/src/main/js/controllers/models/metadata.json ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/controllers/models/metadata.json b/modules/control-center-web/src/main/js/controllers/models/metadata.json index ff16347..9c60217 100644 --- a/modules/control-center-web/src/main/js/controllers/models/metadata.json +++ b/modules/control-center-web/src/main/js/controllers/models/metadata.json @@ -111,8 +111,8 @@ "keyName": "name", "valueName": "className", "hide": "backupItem.kind != 'both' && backupItem.kind == 'query'", - "focusNewItemId": "newValField", - "focusCurItemId": "curValField", + "focusNewItemId": "newValueField", + "focusCurItemId": "curValueField", "addTip": "Add value field.", "removeTip": "Remove value field.", "tip": [ http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7511acce/modules/control-center-web/src/main/js/package.json ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/package.json b/modules/control-center-web/src/main/js/package.json index f7926cf..39c138b 100644 --- a/modules/control-center-web/src/main/js/package.json +++ b/modules/control-center-web/src/main/js/package.json @@ -20,7 +20,6 @@ "node": ">=0.12.4" }, "dependencies": { - "angular-ui-ace": "^0.2.3", "archiver": "^0.14.4", "body-parser": "~1.12.0", "connect-flash": "^0.1.1", http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7511acce/modules/control-center-web/src/main/js/routes/generator/common.js ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/routes/generator/common.js b/modules/control-center-web/src/main/js/routes/generator/common.js index c005f58..0d2bc82 100644 --- a/modules/control-center-web/src/main/js/routes/generator/common.js +++ b/modules/control-center-web/src/main/js/routes/generator/common.js @@ -17,9 +17,11 @@ var _ = require('lodash'); -exports.isDefined = function (v) { +function isDefined(v) { return !(v === undefined || v === null); -}; +} + +exports.isDefined = isDefined; exports.mainComment = mainComment; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7511acce/modules/control-center-web/src/main/js/views/configuration/summary.jade ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/views/configuration/summary.jade b/modules/control-center-web/src/main/js/views/configuration/summary.jade index ba63343..86661d1 100644 --- a/modules/control-center-web/src/main/js/views/configuration/summary.jade +++ b/modules/control-center-web/src/main/js/views/configuration/summary.jade @@ -19,9 +19,6 @@ extends sidebar append scripts script(src='/summary-controller.js') - script(src='//cdn.jsdelivr.net/angularjs/1.3.15/angular-animate.min.js') - script(src='//cdn.jsdelivr.net/angularjs/1.3.15/angular-sanitize.min.js') - script(src='//cdnjs.cloudflare.com/ajax/libs/ace/1.2.0/theme-chrome.js') script(src='//cdnjs.cloudflare.com/ajax/libs/ace/1.2.0/mode-xml.js') script(src='//cdnjs.cloudflare.com/ajax/libs/ace/1.2.0/mode-java.js') @@ -86,7 +83,7 @@ block content .col-sm-2 label(for='os') Operation System: .col-sm-4 - input#os.form-control(type='text' ng-model='configServer.os' placeholder='debian:8' data-min-length='0' data-html='1' data-auto-select='true' data-animation='am-flip-x' bs-typeahead bs-options='os for os in oss') + input#os.form-control(type='text' ng-model='configServer.os' placeholder='debian:8' data-min-length='0' data-html='1' data-auto-select='true' bs-typeahead retain-selection bs-options='os for os in oss') div(ui-ace='{ onLoad: aceInit, mode: "dockerfile" }' ng-model='dockerServer') .padding-dflt(bs-collapse data-start-collapsed='false') .panel.panel-default http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7511acce/modules/control-center-web/src/main/js/views/includes/controls.jade ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/views/includes/controls.jade b/modules/control-center-web/src/main/js/views/includes/controls.jade index e70f7c9..7ca9017 100644 --- a/modules/control-center-web/src/main/js/views/includes/controls.jade +++ b/modules/control-center-web/src/main/js/views/includes/controls.jade @@ -53,13 +53,13 @@ mixin btn-down(show, click) i.tipField.fa.fa-arrow-down(ng-show=show ng-click=click bs-tooltip data-title='Move item down') mixin table-pair-edit(keyModel, valModel, keyPlaceholder, valPlaceholder, keyJavaBuildInTypes, valueJavaBuildInTypes, focusId, index) - -var focusIdNext = focusId + '_next' + -var focusIdNext = focusId + 'Next' .col-sm-6 label.fieldSep / .input-tip if keyJavaBuildInTypes - input.form-control(id=focusId enter-focus-next enter-focus-next-id=focusIdNext type='text' ng-model=keyModel placeholder=keyPlaceholder bs-typeahead data-min-length='1' bs-options='javaClass for javaClass in javaBuildInClasses' on-escape='tableReset()') + input.form-control(id=focusId enter-focus-next enter-focus-next-id=focusIdNext type='text' ng-model=keyModel placeholder=keyPlaceholder bs-typeahead retain-selection data-min-length='1' bs-options='javaClass for javaClass in javaBuildInClasses' on-escape='tableReset()') else input.form-control(id=focusId enter-focus-next enter-focus-next-id=focusIdNext type='text' ng-model=keyModel placeholder=keyPlaceholder on-escape='tableReset()') .col-sm-6 @@ -71,7 +71,7 @@ mixin table-pair-edit(keyModel, valModel, keyPlaceholder, valPlaceholder, keyJav +btn-save(btnVisible, btnSave) .input-tip if valueJavaBuildInTypes - input.form-control(id=focusIdNext type='text' ng-model=valModel placeholder=valPlaceholder bs-typeahead data-min-length='1' bs-options='javaClass for javaClass in javaBuildInClasses' on-enter=btnVisibleAndSave on-escape='tableReset()') + input.form-control(id=focusIdNext type='text' ng-model=valModel placeholder=valPlaceholder bs-typeahead retain-selection data-min-length='1' bs-options='javaClass for javaClass in javaBuildInClasses' on-enter=btnVisibleAndSave on-escape='tableReset()') else input.form-control(id=focusIdNext type='text' ng-model=valModel placeholder=valPlaceholder on-enter=btnVisibleAndSave on-escape='tableReset()') @@ -164,7 +164,7 @@ mixin details-row +ico-exclamation('{{detail.model}}', 'ipaddress', 'Invalid address, see help for format description.') mixin table-db-field-edit(databaseName, databaseType, javaName, javaType, focusId, index) - -var focusIdNext = focusId + '_next' + -var focusIdNext = focusId + 'Next' .col-sm-3 label.fieldSep / @@ -188,7 +188,7 @@ mixin table-db-field-edit(databaseName, databaseType, javaName, javaType, focusI button.form-control(ng-model=javaType bs-select data-placeholder='Java type' bs-options='item.value as item.label for item in {{javaTypes}}') mixin table-group-item-edit(fieldName, className, direction, index) - -var focusIdNext = fieldName + '_next' + -var focusIdNext = fieldName + 'Next' -var args = fieldName + ', ' + className -var btnVisible = 'tableGroupItemSaveVisible(' + args + ')' -var btnSave = 'tableGroupItemSave(' + args + ', ' + direction + ', groupIndex, ' + index +')' @@ -201,7 +201,7 @@ mixin table-group-item-edit(fieldName, className, direction, index) .col-sm-5 label.fieldSep / .input-tip - input.form-control(id=focusIdNext type='text' ng-model=className placeholder='Class name' bs-typeahead data-min-length='1' bs-options='javaClass for javaClass in javaBuildInClasses' on-enter=btnVisibleAndSave on-escape='tableReset()') + input.form-control(id=focusIdNext type='text' ng-model=className placeholder='Class name' bs-typeahead retain-selection data-min-length='1' bs-options='javaClass for javaClass in javaBuildInClasses' on-enter=btnVisibleAndSave on-escape='tableReset()') .col-sm-3 +btn-save(btnVisible, btnSave) .input-tip @@ -235,7 +235,7 @@ mixin form-row-custom(lblClasses, fieldClasses) div(class=fieldClasses) +tipField('field.tip') .input-tip - input.form-control(id='{{::field.id}}' type='text' placeholder='{{::field.placeholder}}' bs-typeahead data-min-length='1' bs-options='javaClass for javaClass in javaBuildInClasses')&attributes(fieldCommon) + input.form-control(id='{{::field.id}}' type='text' placeholder='{{::field.placeholder}}' bs-typeahead retain-selection data-min-length='1' bs-options='javaClass for javaClass in javaBuildInClasses')&attributes(fieldCommon) div(ng-switch-when='password' ng-hide=fieldHide) label(class=lblClasses ng-class=fieldRequiredClass) {{::field.label}}: div(class=fieldClasses) http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7511acce/modules/control-center-web/src/main/js/views/templates/layout.jade ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/views/templates/layout.jade b/modules/control-center-web/src/main/js/views/templates/layout.jade index 8e92edb..2e3fc5d 100644 --- a/modules/control-center-web/src/main/js/views/templates/layout.jade +++ b/modules/control-center-web/src/main/js/views/templates/layout.jade @@ -36,10 +36,11 @@ html(ng-app='ignite-web-control-center' ng-init='user = #{JSON.stringify(user)}; script(src='//cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.0/lodash.min.js') - script(src='//ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.js') - script(src='//cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.2/angular-sanitize.js') - script(src='//cdnjs.cloudflare.com/ajax/libs/angular-strap/2.3.0/angular-strap.js') - script(src='//cdnjs.cloudflare.com/ajax/libs/angular-strap/2.3.0/angular-strap.tpl.min.js') + script(src='//ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.js') + script(src='//cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.3/angular-sanitize.js') + + script(src='//cdnjs.cloudflare.com/ajax/libs/angular-strap/2.3.1/angular-strap.js') + script(src='//cdnjs.cloudflare.com/ajax/libs/angular-strap/2.3.1/angular-strap.tpl.min.js') script(src='//cdnjs.cloudflare.com/ajax/libs/angular-smart-table/2.1.1/smart-table.js')