GUAC-1053 New endpoint for listing languages, JS service for retrieving languages, and settings section for choosing language.

This commit is contained in:
James Muehlner
2015-04-22 22:39:57 -07:00
parent 5788876283
commit c2b2302708
9 changed files with 340 additions and 15 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2014 Glyptodon LLC
* Copyright (C) 2015 Glyptodon LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -41,6 +41,13 @@ angular.module('rest').factory('cacheService', ['$injector',
*/
service.connections = $cacheFactory('API-CONNECTIONS');
/**
* Cache used by languageService.
*
* @type $cacheFactory.Cache
*/
service.languages = $cacheFactory('API-LANGUAGES');
/**
* Cache used by protocolService.
*
@@ -59,8 +66,9 @@ angular.module('rest').factory('cacheService', ['$injector',
* Clear all caches defined in this service.
*/
service.clearCaches = function clearCaches() {
service.protocols.removeAll();
service.connections.removeAll();
service.languages.removeAll();
service.protocols.removeAll();
service.users.removeAll();
};

View File

@@ -0,0 +1,64 @@
/*
* Copyright (C) 2015 Glyptodon LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* Service for operating on language metadata via the REST API.
*/
angular.module('rest').factory('languageService', ['$injector',
function languageService($injector) {
// Required services
var $http = $injector.get('$http');
var authenticationService = $injector.get('authenticationService');
var cacheService = $injector.get('cacheService');
var service = {};
/**
* Makes a request to the REST API to get the list of languages, returning
* a promise that provides a map of language names by language key if
* successful.
*
* @returns {Promise.<Object.<String, String>>}
* A promise which will resolve with a map of language names by
* language key upon success.
*/
service.getLanguages = function getLanguages() {
// Build HTTP parameters set
var httpParameters = {
token : authenticationService.getCurrentToken()
};
// Retrieve available protocols
return $http({
cache : cacheService.languages,
method : 'GET',
url : 'api/languages',
params : httpParameters
});
};
return service;
}]);

View File

@@ -30,8 +30,7 @@ angular.module('settings').directive('guacSettingsPreferences', [function guacSe
restrict: 'E',
replace: true,
scope: {
},
scope: {},
templateUrl: 'app/settings/templates/settingsPreferences.html',
controller: ['$scope', '$injector', function settingsPreferencesController($scope, $injector) {
@@ -40,11 +39,13 @@ angular.module('settings').directive('guacSettingsPreferences', [function guacSe
var PermissionSet = $injector.get('PermissionSet');
// Required services
var $translate = $injector.get('$translate');
var authenticationService = $injector.get('authenticationService');
var guacNotification = $injector.get('guacNotification');
var userService = $injector.get('userService');
var languageService = $injector.get('languageService');
var permissionService = $injector.get('permissionService');
var preferenceService = $injector.get('preferenceService');
var userService = $injector.get('userService');
/**
* An action to be provided along with the object sent to
@@ -71,6 +72,21 @@ angular.module('settings').directive('guacSettingsPreferences', [function guacSe
* @type Object.<String, Object>
*/
$scope.preferences = preferenceService.preferences;
/**
* A map of all available language keys to their human-readable
* names.
*
* @type Object.<String, String>
*/
$scope.languages = null;
/**
* Switches the active display langugae to the chosen language.
*/
$scope.changeLanguage = function changeLanguage() {
$translate.use($scope.preferences.language);
};
/**
* The new password for the user.
@@ -151,6 +167,12 @@ angular.module('settings').directive('guacSettingsPreferences', [function guacSe
};
// Retrieve defined languages
languageService.getLanguages()
.success(function languagesRetrieved(languages) {
$scope.languages = languages;
});
// Retrieve current permissions
permissionService.getPermissions(username)
.success(function permissionsRetrieved(permissions) {
@@ -161,7 +183,23 @@ angular.module('settings').directive('guacSettingsPreferences', [function guacSe
});
/**
* Returns whether critical data has completed being loaded.
*
* @returns {Boolean}
* true if enough data has been loaded for the user interface to be
* useful, false otherwise.
*/
$scope.isLoaded = function isLoaded() {
return $scope.canChangePassword !== null
&& $scope.languages !== null;
};
}]
};
}]);

View File

@@ -28,8 +28,9 @@ angular.module('settings').factory('preferenceService', ['$injector',
function preferenceService($injector) {
// Required services
var $window = $injector.get('$window');
var $rootScope = $injector.get('$rootScope');
var $translate = $injector.get('$translate');
var $window = $injector.get('$window');
var service = {};
@@ -95,7 +96,14 @@ angular.module('settings').factory('preferenceService', ['$injector',
*
* @type String
*/
inputMethod : service.inputMethods.NONE
inputMethod : service.inputMethods.NONE,
/**
* The selected language.
*
* @type String
*/
language : $translate.use()
};

View File

@@ -1,4 +1,4 @@
<div class="preferences">
<div class="preferences" ng-class="{loading: !isLoaded()}">
<!--
Copyright 2015 Glyptodon LLC.
@@ -21,6 +21,21 @@
THE SOFTWARE.
-->
<!-- Language settings -->
<div class="settings section language update-password">
<p>{{'SETTINGS_PREFERENCES.HELP_LANGUAGE' | translate}}</p>
<!-- Language selection -->
<div class="form">
<table class="fields">
<tr>
<th>{{'SETTINGS_PREFERENCES.FIELD_HEADER_LANGUAGE' | translate}}</th>
<td><select ng-model="preferences.language" ng-change="changeLanguage()" ng-options="key as name for (key, name) in languages | orderBy: name"></select></td>
</tr>
</table>
</div>
</div>
<!-- Password update -->
<div class="settings section update-password" ng-show="canChangePassword">
<p>{{'SETTINGS_PREFERENCES.HELP_UPDATE_PASSWORD' | translate}}</p>

View File

@@ -1,5 +1,7 @@
{
"NAME" : "English (US)",
"APP" : {
"ACTION_ACKNOWLEDGE" : "OK",
@@ -411,6 +413,7 @@
"ERROR_PASSWORD_BLANK" : "Your password cannot be blank.",
"ERROR_PASSWORD_MISMATCH" : "@:APP.ERROR_PASSWORD_MISMATCH",
"FIELD_HEADER_LANGUAGE" : "Display language:",
"FIELD_HEADER_PASSWORD" : "Password:",
"FIELD_HEADER_PASSWORD_OLD" : "Current Password:",
"FIELD_HEADER_PASSWORD_NEW" : "New Password:",
@@ -422,6 +425,7 @@
"HELP_INPUT_METHOD_NONE" : "@:CLIENT.HELP_INPUT_METHOD_NONE",
"HELP_INPUT_METHOD_OSK" : "@:CLIENT.HELP_INPUT_METHOD_OSK",
"HELP_INPUT_METHOD_TEXT" : "@:CLIENT.HELP_INPUT_METHOD_TEXT",
"HELP_LANGUAGE" : "Select a different language below to change the language of all text within Guacamole. Available choices will depend on which languages are installed.",
"HELP_MOUSE_MODE_ABSOLUTE" : "@:CLIENT.HELP_MOUSE_MODE_ABSOLUTE",
"HELP_MOUSE_MODE_RELATIVE" : "@:CLIENT.HELP_MOUSE_MODE_RELATIVE",
"HELP_UPDATE_PASSWORD" : "If you wish to change your password, enter your current password and the desired new password below, and click \"Update Password\". The change will take effect immediately.",