From 52d2fe166152e426e17a1aeca5f17c74a4cf4123 Mon Sep 17 00:00:00 2001 From: m-khan-glyptodon Date: Mon, 3 Dec 2018 09:28:49 -0800 Subject: [PATCH 1/4] GUACAMOLE-302: Additions are made to the login directive so that the appropriate field that needs to be focussed is determined. --- .../main/webapp/app/login/directives/login.js | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/guacamole/src/main/webapp/app/login/directives/login.js b/guacamole/src/main/webapp/app/login/directives/login.js index aad7020b9..6fc3441b0 100644 --- a/guacamole/src/main/webapp/app/login/directives/login.js +++ b/guacamole/src/main/webapp/app/login/directives/login.js @@ -102,6 +102,13 @@ angular.module('login').directive('guacLogin', [function guacLogin() { */ $scope.submitted = false; + /** + * The field that is most relevant to the user. + * + * @type Field + */ + $scope.relevantField = null; + /** * Returns whether a previous login attempt is continuing. * @@ -144,6 +151,8 @@ angular.module('login').directive('guacLogin', [function guacLogin() { $scope.enteredValues[field.name] = ''; }); + console.log(mostRelevantField()); + }); /** @@ -194,12 +203,35 @@ angular.module('login').directive('guacLogin', [function guacLogin() { delete $scope.enteredValues[field.name]; }); + + console.log(mostRelevantField()); } })); }; + /** + * Returns the field most relevant field to the user given the current + * state of the login process. This will normally be the first empty + * field. + * + * @return {Field} + * The field most relevant, null if there is no single most relevant + * field. + */ + var mostRelevantField = function findMostRelevantField() { + + for (var i = 0; i < $scope.remainingFields.length; i++) { + var field = $scope.remainingFields[i]; + if (!$scope.enteredValues[field.name]) + return field; + } + + return null; + + }; + // Reset state after authentication and routing have succeeded $rootScope.$on('$routeChangeSuccess', function routeChanged() { $scope.enteredValues = {}; From 19f0de4ebcf07deff3048eb44207fe4ca7efa284 Mon Sep 17 00:00:00 2001 From: m-khan-glyptodon Date: Fri, 7 Jun 2019 13:38:27 -0700 Subject: [PATCH 2/4] GUACAMOLE-302: Allow guacForm and guacFormField directives to specify which field needs to be focused. --- .../src/main/webapp/app/form/directives/form.js | 13 ++++++++++++- .../main/webapp/app/form/directives/formField.js | 9 ++++++++- .../src/main/webapp/app/form/templates/form.html | 4 +++- .../src/main/webapp/app/login/directives/login.js | 11 ++++------- .../src/main/webapp/app/login/templates/login.html | 1 + 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/guacamole/src/main/webapp/app/form/directives/form.js b/guacamole/src/main/webapp/app/form/directives/form.js index be2f3b176..925128b9e 100644 --- a/guacamole/src/main/webapp/app/form/directives/form.js +++ b/guacamole/src/main/webapp/app/form/directives/form.js @@ -72,7 +72,14 @@ angular.module('form').directive('guacForm', [function form() { * * @type Boolean */ - disabled : '=' + disabled : '=', + + /** + * The name of the field to be focused, if any. + * + * @type String + */ + focused : '=' }, templateUrl: 'app/form/templates/form.html', @@ -180,6 +187,10 @@ angular.module('form').directive('guacForm', [function form() { }); + $scope.isFocused = function isFocused(field) { + return field && (field.name === $scope.focused); + }; + /** * Returns whether the given field should be displayed to the * current user. diff --git a/guacamole/src/main/webapp/app/form/directives/formField.js b/guacamole/src/main/webapp/app/form/directives/formField.js index 15adc29e4..cf3efd027 100644 --- a/guacamole/src/main/webapp/app/form/directives/formField.js +++ b/guacamole/src/main/webapp/app/form/directives/formField.js @@ -61,7 +61,14 @@ angular.module('form').directive('guacFormField', [function formField() { * * @type Boolean */ - disabled : '=' + disabled : '=', + + /** + * Whether this field should be focused. + * + * @type Boolean + */ + focused : '=' }, templateUrl: 'app/form/templates/formField.html', diff --git a/guacamole/src/main/webapp/app/form/templates/form.html b/guacamole/src/main/webapp/app/form/templates/form.html index fe0c8903a..6b19bcce2 100644 --- a/guacamole/src/main/webapp/app/form/templates/form.html +++ b/guacamole/src/main/webapp/app/form/templates/form.html @@ -10,7 +10,9 @@ + focused="isFocused(field)" + field="field" + model="values[field.name]"> diff --git a/guacamole/src/main/webapp/app/login/directives/login.js b/guacamole/src/main/webapp/app/login/directives/login.js index 6fc3441b0..a4145483b 100644 --- a/guacamole/src/main/webapp/app/login/directives/login.js +++ b/guacamole/src/main/webapp/app/login/directives/login.js @@ -151,7 +151,7 @@ angular.module('login').directive('guacLogin', [function guacLogin() { $scope.enteredValues[field.name] = ''; }); - console.log(mostRelevantField()); + $scope.relevantField = getRelevantField(); }); @@ -203,8 +203,6 @@ angular.module('login').directive('guacLogin', [function guacLogin() { delete $scope.enteredValues[field.name]; }); - - console.log(mostRelevantField()); } })); @@ -212,15 +210,14 @@ angular.module('login').directive('guacLogin', [function guacLogin() { }; /** - * Returns the field most relevant field to the user given the current - * state of the login process. This will normally be the first empty - * field. + * Returns the field most relevant to the user given the current state + * of the login process. This will normally be the first empty field. * * @return {Field} * The field most relevant, null if there is no single most relevant * field. */ - var mostRelevantField = function findMostRelevantField() { + var getRelevantField = function getRelevantField() { for (var i = 0; i < $scope.remainingFields.length; i++) { var field = $scope.remainingFields[i]; diff --git a/guacamole/src/main/webapp/app/login/templates/login.html b/guacamole/src/main/webapp/app/login/templates/login.html index 79e6081f0..04111edb4 100644 --- a/guacamole/src/main/webapp/app/login/templates/login.html +++ b/guacamole/src/main/webapp/app/login/templates/login.html @@ -27,6 +27,7 @@ namespace="'LOGIN'" content="remainingFields" model="enteredValues" + focused="relevantField.name" data-disabled="submitted"> From eb50c5c0e8719d3d2d5ceaa4f02928f330a6074b Mon Sep 17 00:00:00 2001 From: m-khan-glyptodon Date: Fri, 7 Jun 2019 14:30:24 -0700 Subject: [PATCH 3/4] GUACAMOLE-302: Additions made to the username and password field types so that they can now be manually focussed using the custom guacFocus directive. --- guacamole/src/main/webapp/app/form/directives/form.js | 9 +++++++++ .../main/webapp/app/form/templates/passwordField.html | 2 +- .../src/main/webapp/app/form/templates/textField.html | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/guacamole/src/main/webapp/app/form/directives/form.js b/guacamole/src/main/webapp/app/form/directives/form.js index 925128b9e..81f500fc9 100644 --- a/guacamole/src/main/webapp/app/form/directives/form.js +++ b/guacamole/src/main/webapp/app/form/directives/form.js @@ -187,6 +187,15 @@ angular.module('form').directive('guacForm', [function form() { }); + /** + * Returns whether the given field should be focused or not. + * + * @param {Field} field + * The field to check. + * + * @returns {Boolean} + * true if the given field should be focused, false otherwise. + */ $scope.isFocused = function isFocused(field) { return field && (field.name === $scope.focused); }; diff --git a/guacamole/src/main/webapp/app/form/templates/passwordField.html b/guacamole/src/main/webapp/app/form/templates/passwordField.html index 56472ef4e..68d36f758 100644 --- a/guacamole/src/main/webapp/app/form/templates/passwordField.html +++ b/guacamole/src/main/webapp/app/form/templates/passwordField.html @@ -1,4 +1,4 @@
- +
\ No newline at end of file diff --git a/guacamole/src/main/webapp/app/form/templates/textField.html b/guacamole/src/main/webapp/app/form/templates/textField.html index 819ae038a..6abd4f6c0 100644 --- a/guacamole/src/main/webapp/app/form/templates/textField.html +++ b/guacamole/src/main/webapp/app/form/templates/textField.html @@ -1,5 +1,5 @@
-