jmuehlner commented on code in PR #751:
URL: https://github.com/apache/guacamole-client/pull/751#discussion_r957851887
##########
guacamole/src/main/frontend/src/app/settings/directives/guacSettingsPreferences.js:
##########
@@ -197,7 +240,84 @@
angular.module('settings').directive('guacSettingsPreferences', [function guacSe
};
+
+ /**
+ * Saves the current user, displaying an acknowledgement message if
+ * saving was successful, or an error if the save failed.
+ */
+ $scope.saveUser = function saveUser() {
+ return userService.saveUser(dataSource, $scope.user)
+ .then(() => guacNotification.showStatus({
+ text : {
+ key :
'SETTINGS_PREFERENCES.INFO_PREFERENCE_ATTRIBUTES_CHANGED'
+ },
+
+ // Reload the user on successful save in case any
attributes changed
+ actions : [ ACKNOWLEDGE_ACTION_RELOAD ]
+ }),
+ guacNotification.SHOW_REQUEST_ERROR);
+ };
+
+ // Fetch the user record
+ userService.getUser(dataSource, username).then(function
saveUserData(user) {
+ $scope.user = user;
+ })
+
+ // Get all datasources that are available for this user
+ authenticationService.getAvailableDataSources().forEach(function
loadAttributesForDataSource(dataSource) {
+
+ // Fetch all user attribute forms defined for the datasource
+
schemaService.getUserPreferenceAttributes(dataSource).then(function
saveAttributes(attributes) {
+
+ // Iterate through all attribute forms
+ attributes.forEach(function addAttribute(attributeForm) {
+
+ // If the form with the retrieved name already exists
+ if ($scope.attributeMap.has(attributeForm.name)) {
+ const existingFields =
$scope.attributeMap.get(attributeForm.name).fields;
+
+ // Add each field to the existing list for this
form
+ attributeForm.fields.forEach(function
addAllFieldsToExistingMap(field) {
+ existingFields.set(field.name, field);
+ })
+ }
+
+ else {
+
+ // Create a new entry for the form
+ $scope.attributeMap.set(attributeForm.name, {
+ name: attributeForm.name,
+
+ // With the field array from the API converted
into a Map
+ fields: attributeForm.fields.reduce(
+ function addFieldToMap(currentFieldMap,
field) {
+ currentFieldMap.set(field.name, field);
+ return currentFieldMap;
+ }, new Map()
+ )
+
+ })
+ }
+
+ });
+
+ // Re-generate the attributes array every time
+ $scope.attributes =
Array.of(...$scope.attributeMap.values()).map(function
convertFieldsToArray(formObject) {
Review Comment:
The spread operator does get polyfilled, to this:
`Array.of.apply(Array,$jscomp.arrayFromIterable(a.attributeMap.values())).`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]