From c93b05ca23862847f1897dad1e21dcb74516ff76 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 21 Jan 2022 08:36:28 -0800 Subject: [PATCH 1/4] GUACAMOLE-1509: Automatically generate CSS classes for forms and fields. --- .../frontend/src/app/form/directives/form.js | 17 +++++++ .../src/app/form/directives/formField.js | 15 ++++++ .../src/app/form/services/formService.js | 47 +++++++++++++++++++ .../frontend/src/app/form/templates/form.html | 3 +- .../src/app/form/templates/formField.html | 3 +- 5 files changed, 83 insertions(+), 2 deletions(-) diff --git a/guacamole/src/main/frontend/src/app/form/directives/form.js b/guacamole/src/main/frontend/src/app/form/directives/form.js index 81f500fc9..8d35774c7 100644 --- a/guacamole/src/main/frontend/src/app/form/directives/form.js +++ b/guacamole/src/main/frontend/src/app/form/directives/form.js @@ -86,6 +86,7 @@ angular.module('form').directive('guacForm', [function form() { controller: ['$scope', '$injector', function formController($scope, $injector) { // Required services + var formService = $injector.get('formService'); var translationStringService = $injector.get('translationStringService'); /** @@ -134,6 +135,22 @@ angular.module('form').directive('guacForm', [function form() { }; + /** + * Returns an object as would be provided to the ngClass directive + * that defines the CSS classes that should be applied to the given + * form. + * + * @param {Form} form + * The form to generate the CSS classes for. + * + * @return {!Object.} + * The ngClass object defining the CSS classes for the given + * form. + */ + $scope.getFormClasses = function getFormClasses(form) { + return formService.getClasses('form-', form); + }; + /** * Determines whether the given object is a form, under the * assumption that the object is either a form or a field. diff --git a/guacamole/src/main/frontend/src/app/form/directives/formField.js b/guacamole/src/main/frontend/src/app/form/directives/formField.js index fbc0cfecf..4fcead1d6 100644 --- a/guacamole/src/main/frontend/src/app/form/directives/formField.js +++ b/guacamole/src/main/frontend/src/app/form/directives/formField.js @@ -155,6 +155,21 @@ angular.module('form').directive('guacFormField', [function formField() { }; + /** + * Returns an object as would be provided to the ngClass directive + * that defines the CSS classes that should be applied to this + * field. + * + * @return {!Object.} + * The ngClass object defining the CSS classes for the current + * field. + */ + $scope.getFieldClasses = function getFieldClasses() { + return formService.getClasses('labeled-field-', $scope.field, { + empty: !$scope.model + }); + }; + /** * Returns whether the current field should be displayed. * diff --git a/guacamole/src/main/frontend/src/app/form/services/formService.js b/guacamole/src/main/frontend/src/app/form/services/formService.js index 0e9155c09..0bed36b84 100644 --- a/guacamole/src/main/frontend/src/app/form/services/formService.js +++ b/guacamole/src/main/frontend/src/app/form/services/formService.js @@ -272,6 +272,53 @@ angular.module('form').provider('formService', function formServiceProvider() { }; + /** + * Given form content and an arbitrary prefix, returns a corresponding + * CSS class object as would be provided to the ngClass directive that + * assigns a content-specific CSS class based on the prefix and + * form/field name. Generated class names follow the lowercase with + * dashes naming convention. For example, if the prefix is "field-" and + * the provided content is a field with the name "Swap red/blue", the + * object { 'field-swap-red-blue' : true } would be returned. + * + * @param {!string} prefix + * The arbitrary prefix to prepend to the name of the generated CSS + * class. + * + * @param {!(Form|Field)} [content] + * The form or field whose name should be used to produce the CSS + * class name. + * + * @param {Object.} [object={}] + * The optional base ngClass object that should be used to provide + * additional name/value pairs within the returned object. + * + * @return {!Object.} + * The ngClass object based on the provided object and defining a + * CSS class name for the given content. + */ + service.getClasses = function getClasses(prefix, content, object) { + + // Default to no additional properties + object = object || {}; + + // Perform no transformation if there is no content or + // corresponding name + if (!content || !content.name) + return object; + + // Transform content name and prefix into lowercase-with-dashes + // CSS class name + var className = prefix + content.name.replace(/[^a-zA-Z0-9]+/g, '-').toLowerCase(); + + // Add CSS class name to provided base object (without touching + // base object) + var classes = angular.extend({}, object); + classes[className] = true; + return classes; + + }; + /** * Compiles and links the field associated with the given name to the given * scope, producing a distinct and independent DOM Element which functions diff --git a/guacamole/src/main/frontend/src/app/form/templates/form.html b/guacamole/src/main/frontend/src/app/form/templates/form.html index 6b19bcce2..397a210c5 100644 --- a/guacamole/src/main/frontend/src/app/form/templates/form.html +++ b/guacamole/src/main/frontend/src/app/form/templates/form.html @@ -1,9 +1,10 @@
-

{{getSectionHeader(form) | translate}}

+

{{getSectionHeader(form) | translate}}

diff --git a/guacamole/src/main/frontend/src/app/form/templates/formField.html b/guacamole/src/main/frontend/src/app/form/templates/formField.html index 3e45d4cb6..8534515a2 100644 --- a/guacamole/src/main/frontend/src/app/form/templates/formField.html +++ b/guacamole/src/main/frontend/src/app/form/templates/formField.html @@ -1,4 +1,5 @@ -
+
From a688bc507c79967c676d75fd77a59fb2dda4ee7e Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 23 Jan 2022 12:18:32 -0800 Subject: [PATCH 2/4] GUACAMOLE-1509: Add name attribute to all applicable fields. --- .../src/main/resources/templates/authenticationCodeField.html | 1 + .../main/frontend/src/app/form/templates/checkboxField.html | 1 + .../src/main/frontend/src/app/form/templates/dateField.html | 1 + .../src/main/frontend/src/app/form/templates/emailField.html | 1 + .../main/frontend/src/app/form/templates/languageField.html | 1 + .../src/main/frontend/src/app/form/templates/numberField.html | 1 + .../main/frontend/src/app/form/templates/passwordField.html | 1 + .../src/main/frontend/src/app/form/templates/selectField.html | 1 + .../src/app/form/templates/terminalColorSchemeField.html | 4 +++- .../main/frontend/src/app/form/templates/textAreaField.html | 1 + .../src/main/frontend/src/app/form/templates/textField.html | 1 + .../src/main/frontend/src/app/form/templates/timeField.html | 1 + .../main/frontend/src/app/form/templates/timeZoneField.html | 1 + 13 files changed, 15 insertions(+), 1 deletion(-) diff --git a/extensions/guacamole-auth-totp/src/main/resources/templates/authenticationCodeField.html b/extensions/guacamole-auth-totp/src/main/resources/templates/authenticationCodeField.html index 30c07f434..7f2a3c485 100644 --- a/extensions/guacamole-auth-totp/src/main/resources/templates/authenticationCodeField.html +++ b/extensions/guacamole-auth-totp/src/main/resources/templates/authenticationCodeField.html @@ -41,6 +41,7 @@
diff --git a/guacamole/src/main/frontend/src/app/form/templates/checkboxField.html b/guacamole/src/main/frontend/src/app/form/templates/checkboxField.html index 80666c018..f0881bd11 100644 --- a/guacamole/src/main/frontend/src/app/form/templates/checkboxField.html +++ b/guacamole/src/main/frontend/src/app/form/templates/checkboxField.html @@ -1,5 +1,6 @@ diff --git a/guacamole/src/main/frontend/src/app/form/templates/numberField.html b/guacamole/src/main/frontend/src/app/form/templates/numberField.html index b7666c680..2d270d689 100644 --- a/guacamole/src/main/frontend/src/app/form/templates/numberField.html +++ b/guacamole/src/main/frontend/src/app/form/templates/numberField.html @@ -1,6 +1,7 @@ - diff --git a/guacamole/src/main/frontend/src/app/form/templates/textAreaField.html b/guacamole/src/main/frontend/src/app/form/templates/textAreaField.html index 9761af77e..74284c73c 100644 --- a/guacamole/src/main/frontend/src/app/form/templates/textAreaField.html +++ b/guacamole/src/main/frontend/src/app/form/templates/textAreaField.html @@ -1,4 +1,5 @@ +
+ +
diff --git a/guacamole/src/main/frontend/src/app/form/templates/usernameField.html b/guacamole/src/main/frontend/src/app/form/templates/usernameField.html new file mode 100644 index 000000000..6a5c664d4 --- /dev/null +++ b/guacamole/src/main/frontend/src/app/form/templates/usernameField.html @@ -0,0 +1,10 @@ +
+ +
diff --git a/guacamole/src/main/frontend/src/app/home/templates/guacRecentConnections.html b/guacamole/src/main/frontend/src/app/home/templates/guacRecentConnections.html index 4654bd4d4..08362f66f 100644 --- a/guacamole/src/main/frontend/src/app/home/templates/guacRecentConnections.html +++ b/guacamole/src/main/frontend/src/app/home/templates/guacRecentConnections.html @@ -1,4 +1,4 @@ -
+

{{'HOME.INFO_NO_RECENT_CONNECTIONS' | translate}}

diff --git a/guacamole/src/main/frontend/src/app/home/templates/home.html b/guacamole/src/main/frontend/src/app/home/templates/home.html index 4597dffe1..b2b3db5bd 100644 --- a/guacamole/src/main/frontend/src/app/home/templates/home.html +++ b/guacamole/src/main/frontend/src/app/home/templates/home.html @@ -1,5 +1,4 @@ - -
+
@@ -8,9 +7,7 @@

{{'HOME.SECTION_HEADER_RECENT_CONNECTIONS' | translate}}

-
- -
+
@@ -33,4 +30,4 @@
-
\ No newline at end of file +
diff --git a/guacamole/src/main/frontend/src/app/manage/templates/connectionGroupPermission.html b/guacamole/src/main/frontend/src/app/manage/templates/connectionGroupPermission.html index 8ac52641e..2bc90cce9 100644 --- a/guacamole/src/main/frontend/src/app/manage/templates/connectionGroupPermission.html +++ b/guacamole/src/main/frontend/src/app/manage/templates/connectionGroupPermission.html @@ -1,4 +1,4 @@ -
+
diff --git a/guacamole/src/main/frontend/src/app/manage/templates/connectionPermission.html b/guacamole/src/main/frontend/src/app/manage/templates/connectionPermission.html index 3a0dddaea..e94f9114e 100644 --- a/guacamole/src/main/frontend/src/app/manage/templates/connectionPermission.html +++ b/guacamole/src/main/frontend/src/app/manage/templates/connectionPermission.html @@ -1,4 +1,4 @@ -
+
diff --git a/guacamole/src/main/frontend/src/app/manage/templates/locationChooserConnectionGroup.html b/guacamole/src/main/frontend/src/app/manage/templates/locationChooserConnectionGroup.html index b4371506e..e49b4c0b9 100644 --- a/guacamole/src/main/frontend/src/app/manage/templates/locationChooserConnectionGroup.html +++ b/guacamole/src/main/frontend/src/app/manage/templates/locationChooserConnectionGroup.html @@ -1,4 +1,4 @@ - - + {{item.name}} diff --git a/guacamole/src/main/frontend/src/app/manage/templates/manageConnection.html b/guacamole/src/main/frontend/src/app/manage/templates/manageConnection.html index 8f37b98d4..7be5d75de 100644 --- a/guacamole/src/main/frontend/src/app/manage/templates/manageConnection.html +++ b/guacamole/src/main/frontend/src/app/manage/templates/manageConnection.html @@ -1,5 +1,5 @@ -
+
diff --git a/guacamole/src/main/frontend/src/app/manage/templates/manageConnectionGroup.html b/guacamole/src/main/frontend/src/app/manage/templates/manageConnectionGroup.html index 1ed7e9c16..712183dc6 100644 --- a/guacamole/src/main/frontend/src/app/manage/templates/manageConnectionGroup.html +++ b/guacamole/src/main/frontend/src/app/manage/templates/manageConnectionGroup.html @@ -1,5 +1,5 @@ -
+
diff --git a/guacamole/src/main/frontend/src/app/manage/templates/manageSharingProfile.html b/guacamole/src/main/frontend/src/app/manage/templates/manageSharingProfile.html index f7e9d114e..6458075c0 100644 --- a/guacamole/src/main/frontend/src/app/manage/templates/manageSharingProfile.html +++ b/guacamole/src/main/frontend/src/app/manage/templates/manageSharingProfile.html @@ -1,4 +1,4 @@ -
+
diff --git a/guacamole/src/main/frontend/src/app/manage/templates/managementButtons.html b/guacamole/src/main/frontend/src/app/manage/templates/managementButtons.html index d43209a45..68e4108cc 100644 --- a/guacamole/src/main/frontend/src/app/manage/templates/managementButtons.html +++ b/guacamole/src/main/frontend/src/app/manage/templates/managementButtons.html @@ -1,6 +1,6 @@
- - - - + + + +
diff --git a/guacamole/src/main/frontend/src/app/manage/templates/sharingProfilePermission.html b/guacamole/src/main/frontend/src/app/manage/templates/sharingProfilePermission.html index 8d8311b76..0d1647255 100644 --- a/guacamole/src/main/frontend/src/app/manage/templates/sharingProfilePermission.html +++ b/guacamole/src/main/frontend/src/app/manage/templates/sharingProfilePermission.html @@ -1,4 +1,4 @@ -
+