jmuehlner commented on code in PR #668:
URL: https://github.com/apache/guacamole-client/pull/668#discussion_r929307997


##########
guacamole/src/main/frontend/src/app/client/directives/guacClientMessage.js:
##########
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Directive which displays a message for the client.
+ */
+angular.module('client').directive('guacClientMessage', [function 
guacClientMessage() {
+
+    return {
+        restrict: 'E',
+        replace: true,
+        scope: {
+
+            /**
+             * The message to display to the client.
+             * 
+             * @type {!ManagedClientMessage}
+             */
+            message : '='
+
+        },
+
+        templateUrl: 'app/client/templates/guacClientMessage.html',
+        
+        controller: ['$scope', '$injector', '$element',
+                function guacClientMessageController($scope, $injector, 
$element) {
+            
+            const ManagedClientMessage = $injector.get('ManagedClientMessage');
+            
+            /**
+             * Uses the msgcode to retrieve the correct translation key for
+             * the client message.
+             * 
+             * @returns {string}
+             */
+            $scope.getMessageKey = function getMessageKey() {
+                
+                let msgString = "DEFAULT";
+                if 
(Object.values(Guacamole.Client.Message).includes($scope.message.msgcode))
+                    msgString = Object.keys(Guacamole.Client.Message).find(key 
=> Guacamole.Client.Message[key] === $scope.message.msgcode);
+                
+                return "CLIENT.CLIENT_MESSAGE_" + msgString.toUpperCase();
+            };
+            
+            /**
+             * Returns a set of key/value object pairs that represent the
+             * arguments provided as part of the message in the form
+             * ARGS[0] = value.
+             * 
+             * @returns {Object}
+             */
+            $scope.getMessageArgs = function getMessageArgs() {
+                return $scope.message.args.reduce(

Review Comment:
   That is a bit more clear - though I wonder consider quoting the value 
`"ARGS[0]"` just to make it extra super clear that it's a string. I know object 
values in javascript have to be strings anyway, but making it explicitly clear 
never hurts.
   
   It might be even more clear if you used a format for these keys that doesn't 
look like an array index, like `ARGS_0` or something, just to make it even more 
obvious that they're strings.
   



##########
guacamole/src/main/frontend/src/app/client/directives/guacClientMessage.js:
##########
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Directive which displays a message for the client.
+ */
+angular.module('client').directive('guacClientMessage', [function 
guacClientMessage() {
+
+    return {
+        restrict: 'E',
+        replace: true,
+        scope: {
+
+            /**
+             * The message to display to the client.
+             * 
+             * @type {!ManagedClientMessage}
+             */
+            message : '='
+
+        },
+
+        templateUrl: 'app/client/templates/guacClientMessage.html',
+        
+        controller: ['$scope', '$injector', '$element',
+                function guacClientMessageController($scope, $injector, 
$element) {
+            
+            const ManagedClientMessage = $injector.get('ManagedClientMessage');
+            
+            /**
+             * Uses the msgcode to retrieve the correct translation key for
+             * the client message.
+             * 
+             * @returns {string}
+             */
+            $scope.getMessageKey = function getMessageKey() {
+                
+                let msgString = "DEFAULT";
+                if 
(Object.values(Guacamole.Client.Message).includes($scope.message.msgcode))
+                    msgString = Object.keys(Guacamole.Client.Message).find(key 
=> Guacamole.Client.Message[key] === $scope.message.msgcode);
+                
+                return "CLIENT.CLIENT_MESSAGE_" + msgString.toUpperCase();
+            };
+            
+            /**
+             * Returns a set of key/value object pairs that represent the
+             * arguments provided as part of the message in the form
+             * ARGS[0] = value.
+             * 
+             * @returns {Object}
+             */
+            $scope.getMessageArgs = function getMessageArgs() {
+                return $scope.message.args.reduce(

Review Comment:
   That is a bit more clear - though I wonder consider quoting the value 
`"ARGS[0]"` just to make it extra super clear that it's a string. I know object 
values in javascript have to be strings anyway, but making it explicitly clear 
never hurts.
   
   It might be even more clear if you used a format for these keys that doesn't 
look like an array index, like `"ARGS_0"` or something, just to make it even 
more obvious that they're strings.
   



-- 
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]

Reply via email to