mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUACAMOLE-1293: Change msg instruction to code plus arguments.
This commit is contained in:
@@ -28,15 +28,54 @@ angular.module('client').directive('guacClientMessage', [function guacClientMess
|
||||
scope: {
|
||||
|
||||
/**
|
||||
* The message to display.
|
||||
* The message to display to the client.
|
||||
*
|
||||
* @type String
|
||||
* @type {!ManagedClientMessage}
|
||||
*/
|
||||
message : '='
|
||||
|
||||
},
|
||||
|
||||
templateUrl: 'app/client/templates/guacClientMessage.html'
|
||||
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(
|
||||
function(acc, value, index) {
|
||||
acc[`ARGS[${index}]`] = value;
|
||||
return acc;
|
||||
},
|
||||
{}
|
||||
);
|
||||
};
|
||||
|
||||
}]
|
||||
|
||||
};
|
||||
}]);
|
||||
|
@@ -1,6 +1,8 @@
|
||||
<div class="client-message" ng-click="clear()">
|
||||
|
||||
<!-- Message text -->
|
||||
<p class="client-message-text">{{ message }}</p>
|
||||
<p class="client-message-text"
|
||||
translate="{{ getMessageKey() }}"
|
||||
translate-values="{{ getMessageArgs() }}"></p>
|
||||
|
||||
</div>
|
||||
|
@@ -28,6 +28,7 @@ angular.module('client').factory('ManagedClient', ['$rootScope', '$injector',
|
||||
const ClientIdentifier = $injector.get('ClientIdentifier');
|
||||
const ClipboardData = $injector.get('ClipboardData');
|
||||
const ManagedArgument = $injector.get('ManagedArgument');
|
||||
const ManagedClientMessage = $injector.get('ManagedClientMessage');
|
||||
const ManagedClientState = $injector.get('ManagedClientState');
|
||||
const ManagedClientThumbnail = $injector.get('ManagedClientThumbnail');
|
||||
const ManagedDisplay = $injector.get('ManagedDisplay');
|
||||
@@ -178,7 +179,7 @@ angular.module('client').factory('ManagedClient', ['$rootScope', '$injector',
|
||||
* All messages that have been sent to the client that should be
|
||||
* displayed.
|
||||
*
|
||||
* @type String[]
|
||||
* @type ManagedClientMessage[]
|
||||
*/
|
||||
this.messages = template.messages || [];
|
||||
|
||||
@@ -496,10 +497,14 @@ angular.module('client').factory('ManagedClient', ['$rootScope', '$injector',
|
||||
};
|
||||
|
||||
// Handle messages received from guacd to display to the client.
|
||||
client.onmsg = function clientMessage(message) {
|
||||
client.onmsg = function clientMessage(msgcode, args) {
|
||||
|
||||
msg = new ManagedClientMessage();
|
||||
msg.msgcode = msgcode;
|
||||
msg.args = args;
|
||||
|
||||
$rootScope.$apply(function updateMessages() {
|
||||
managedClient.messages.push(message);
|
||||
managedClient.messages.push(msg);
|
||||
});
|
||||
|
||||
};
|
||||
|
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides the ManagedClientMessage class used for messages displayed in
|
||||
* a ManagedClient.
|
||||
*/
|
||||
angular.module('client').factory('ManagedClientMessage', [function defineManagedClientMessage() {
|
||||
|
||||
/**
|
||||
* Object which represents a message to be displayed to a Guacamole client.
|
||||
*
|
||||
* @constructor
|
||||
* @param {ManagedClientMessage|Object} [template={}]
|
||||
* The object whose properties should be copied within the new
|
||||
* ManagedClientMessage.
|
||||
*/
|
||||
var ManagedClientMessage = function ManagedClientMessage(template) {
|
||||
|
||||
// Use empty object by default
|
||||
template = template || {};
|
||||
|
||||
/**
|
||||
* The message code sent by the server that will be used to locate the
|
||||
* message within the Guacamole translation framework.
|
||||
*/
|
||||
this.msgcode = template.msgcode;
|
||||
|
||||
/**
|
||||
* Any arguments that should be passed through the translation system
|
||||
* and displayed as part of the message.
|
||||
*/
|
||||
this.args = template.args;
|
||||
|
||||
};
|
||||
|
||||
return ManagedClientMessage;
|
||||
|
||||
}]);
|
@@ -72,6 +72,10 @@
|
||||
"ACTION_SHARE" : "@:APP.ACTION_SHARE",
|
||||
"ACTION_UPLOAD_FILES" : "Upload Files",
|
||||
|
||||
"CLIENT_MESSAGE_DEFAULT" : "",
|
||||
"CLIENT_MESSAGE_JOINED" : "User {ARGS[0]} has joined the connection.",
|
||||
"CLIENT_MESSAGE_LEFT" : "User {ARGS[0]} has left the connection.",
|
||||
|
||||
"DIALOG_HEADER_CONNECTING" : "Connecting",
|
||||
"DIALOG_HEADER_CONNECTION_ERROR" : "Connection Error",
|
||||
"DIALOG_HEADER_DISCONNECTED" : "Disconnected",
|
||||
|
Reference in New Issue
Block a user