mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-10 15:11:22 +00:00
GUAC-1373: Modify connection history page to show duration instead of end date.
This commit is contained in:
@@ -37,8 +37,9 @@ angular.module('settings').directive('guacSettingsConnectionHistory', [function
|
||||
controller: ['$scope', '$injector', function settingsConnectionHistoryController($scope, $injector) {
|
||||
|
||||
// Get required types
|
||||
var FilterToken = $injector.get('FilterToken');
|
||||
var SortOrder = $injector.get('SortOrder');
|
||||
var ConnectionHistoryEntryWrapper = $injector.get('ConnectionHistoryEntryWrapper');
|
||||
var FilterToken = $injector.get('FilterToken');
|
||||
var SortOrder = $injector.get('SortOrder');
|
||||
|
||||
// Get required services
|
||||
var $routeParams = $injector.get('$routeParams');
|
||||
@@ -53,12 +54,12 @@ angular.module('settings').directive('guacSettingsConnectionHistory', [function
|
||||
$scope.dataSource = $routeParams.dataSource;
|
||||
|
||||
/**
|
||||
* All matching connection history records, or null if these
|
||||
* records have not yet been retrieved.
|
||||
* All wrapped matching connection history entries, or null if these
|
||||
* entries have not yet been retrieved.
|
||||
*
|
||||
* @type ConnectionHistoryEntry[]
|
||||
* @type ConnectionHistoryEntryWrapper[]
|
||||
*/
|
||||
$scope.historyRecords = null;
|
||||
$scope.historyEntryWrappers = null;
|
||||
|
||||
/**
|
||||
* The search terms to use when filtering the history records.
|
||||
@@ -82,7 +83,7 @@ angular.module('settings').directive('guacSettingsConnectionHistory', [function
|
||||
*/
|
||||
$scope.order = new SortOrder([
|
||||
'-startDate',
|
||||
'-endDate',
|
||||
'-duration',
|
||||
'username',
|
||||
'connectionName'
|
||||
]);
|
||||
@@ -107,8 +108,8 @@ angular.module('settings').directive('guacSettingsConnectionHistory', [function
|
||||
*
|
||||
*/
|
||||
$scope.isLoaded = function isLoaded() {
|
||||
return $scope.historyRecords !== null
|
||||
&& $scope.dateFormat !== null;
|
||||
return $scope.historyEntryWrappers !== null
|
||||
&& $scope.dateFormat !== null;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -121,7 +122,7 @@ angular.module('settings').directive('guacSettingsConnectionHistory', [function
|
||||
* records are present, false otherwise.
|
||||
*/
|
||||
$scope.isHistoryEmpty = function isHistoryEmpty() {
|
||||
return $scope.isLoaded() && $scope.historyRecords.length === 0;
|
||||
return $scope.isLoaded() && $scope.historyEntryWrappers.length === 0;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -131,7 +132,7 @@ angular.module('settings').directive('guacSettingsConnectionHistory', [function
|
||||
$scope.search = function search() {
|
||||
|
||||
// Clear current results
|
||||
$scope.historyRecords = null;
|
||||
$scope.historyEntryWrappers = null;
|
||||
|
||||
// Tokenize search string
|
||||
var tokens = FilterToken.tokenize($scope.searchString);
|
||||
@@ -168,10 +169,13 @@ angular.module('settings').directive('guacSettingsConnectionHistory', [function
|
||||
return predicate === 'startDate' || predicate === '-startDate';
|
||||
})
|
||||
)
|
||||
.success(function historyRetrieved(historyRecords) {
|
||||
.success(function historyRetrieved(historyEntries) {
|
||||
|
||||
// Store retrieved permissions
|
||||
$scope.historyRecords = historyRecords;
|
||||
// Wrap all history entries for sake of display
|
||||
$scope.historyEntryWrappers = [];
|
||||
angular.forEach(historyEntries, function wrapHistoryEntry(historyEntry) {
|
||||
$scope.historyEntryWrappers.push(new ConnectionHistoryEntryWrapper(historyEntry));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
@@ -43,8 +43,8 @@
|
||||
<th guac-sort-order="order" guac-sort-property="'startDate'">
|
||||
{{'SETTINGS_CONNECTION_HISTORY.TABLE_HEADER_SESSION_STARTDATE' | translate}}
|
||||
</th>
|
||||
<th guac-sort-order="order" guac-sort-property="'endDate'">
|
||||
{{'SETTINGS_CONNECTION_HISTORY.TABLE_HEADER_SESSION_ENDDATE' | translate}}
|
||||
<th guac-sort-order="order" guac-sort-property="'duration'">
|
||||
{{'SETTINGS_CONNECTION_HISTORY.TABLE_HEADER_SESSION_DURATION' | translate}}
|
||||
</th>
|
||||
<th guac-sort-order="order" guac-sort-property="'connectionName'">
|
||||
{{'SETTINGS_CONNECTION_HISTORY.TABLE_HEADER_SESSION_CONNECTION_NAME' | translate}}
|
||||
@@ -52,11 +52,12 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody ng-class="{loading: !isLoaded()}">
|
||||
<tr ng-repeat="historyRecord in historyRecordPage" class="history">
|
||||
<td>{{historyRecord.username}}</td>
|
||||
<td>{{historyRecord.startDate | date : dateFormat}}</td>
|
||||
<td>{{historyRecord.endDate | date : dateFormat}}</td>
|
||||
<td>{{historyRecord.connectionName}}</td>
|
||||
<tr ng-repeat="historyEntryWrapper in historyEntryWrapperPage" class="history">
|
||||
<td>{{historyEntryWrapper.username}}</td>
|
||||
<td>{{historyEntryWrapper.startDate | date : dateFormat}}</td>
|
||||
<td translate="{{historyEntryWrapper.readableDurationText}}"
|
||||
translate-values="{VALUE: historyEntryWrapper.readableDuration.value, UNIT: historyEntryWrapper.readableDuration.unit}"></td>
|
||||
<td>{{historyEntryWrapper.connectionName}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -67,8 +68,8 @@
|
||||
</p>
|
||||
|
||||
<!-- Pager for history list -->
|
||||
<guac-pager page="historyRecordPage" page-size="25"
|
||||
items="historyRecords | orderBy : order.predicate"></guac-pager>
|
||||
<guac-pager page="historyEntryWrapperPage" page-size="25"
|
||||
items="historyEntryWrappers | orderBy : order.predicate"></guac-pager>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* A service for defining the ConnectionHistoryEntryWrapper class.
|
||||
*/
|
||||
angular.module('settings').factory('ConnectionHistoryEntryWrapper', ['$injector',
|
||||
function defineConnectionHistoryEntryWrapper($injector) {
|
||||
|
||||
// Required types
|
||||
var ConnectionHistoryEntry = $injector.get('ConnectionHistoryEntry');
|
||||
|
||||
/**
|
||||
* Wrapper for ConnectionHistoryEntry which adds display-specific
|
||||
* properties, such as a duration.
|
||||
*
|
||||
* @constructor
|
||||
* @param {ConnectionHistoryEntry} historyEntry
|
||||
* The ConnectionHistoryEntry that should be wrapped.
|
||||
*/
|
||||
var ConnectionHistoryEntryWrapper = function ConnectionHistoryEntryWrapper(historyEntry) {
|
||||
|
||||
/**
|
||||
* The identifier of the connection associated with this history entry.
|
||||
*
|
||||
* @type String
|
||||
*/
|
||||
this.connectionIdentifier = historyEntry.connectionIdentifier;
|
||||
|
||||
/**
|
||||
* The name of the connection associated with this history entry.
|
||||
*
|
||||
* @type String
|
||||
*/
|
||||
this.connectionName = historyEntry.connectionName;
|
||||
|
||||
/**
|
||||
* The username of the user associated with this particular usage of
|
||||
* the connection.
|
||||
*
|
||||
* @type String
|
||||
*/
|
||||
this.username = historyEntry.username;
|
||||
|
||||
/**
|
||||
* The time that usage began, in seconds since 1970-01-01 00:00:00 UTC.
|
||||
*
|
||||
* @type Number
|
||||
*/
|
||||
this.startDate = historyEntry.startDate;
|
||||
|
||||
/**
|
||||
* The time that usage ended, in seconds since 1970-01-01 00:00:00 UTC.
|
||||
* The absence of an endDate does NOT necessarily indicate that the
|
||||
* connection is still in use, particularly if the server was shutdown
|
||||
* or restarted before the history entry could be updated. To determine
|
||||
* whether a connection is still active, check the active property of
|
||||
* this history entry.
|
||||
*
|
||||
* @type Number
|
||||
*/
|
||||
this.endDate = historyEntry.endDate;
|
||||
|
||||
/**
|
||||
* The total amount of time the connection associated with the wrapped
|
||||
* history record was open, in seconds.
|
||||
*
|
||||
* @type Number
|
||||
*/
|
||||
this.duration = this.endDate - this.startDate;
|
||||
|
||||
/**
|
||||
* An object providing value and unit properties, denoting the duration
|
||||
* and its corresponding units.
|
||||
*
|
||||
* @type ConnectionHistoryEntry.Duration
|
||||
*/
|
||||
this.readableDuration = null;
|
||||
|
||||
// Set the duration if the necessary information is present
|
||||
if (this.endDate && this.startDate)
|
||||
this.readableDuration = new ConnectionHistoryEntry.Duration(this.duration);
|
||||
|
||||
/**
|
||||
* The string to display as the duration of this history entry. If a
|
||||
* duration is available, its value and unit will be exposed to any
|
||||
* given translation string as the VALUE and UNIT substitution
|
||||
* variables respectively.
|
||||
*
|
||||
* @type String
|
||||
*/
|
||||
this.readableDurationText = 'SETTINGS_CONNECTION_HISTORY.TEXT_HISTORY_DURATION';
|
||||
|
||||
// Inform user if end date is not known
|
||||
if (!this.endDate)
|
||||
this.readableDurationText = 'SETTINGS_CONNECTION_HISTORY.INFO_CONNECTION_DURATION_UNKNOWN';
|
||||
|
||||
};
|
||||
|
||||
return ConnectionHistoryEntryWrapper;
|
||||
|
||||
}]);
|
Reference in New Issue
Block a user