1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

F #5342: Add button to take screenshots (#1107)

(cherry picked from commit 68b8c59af2ef92e3cc6e51fee6fd45a326d8c89f)
This commit is contained in:
Sergio Betanzos 2021-04-15 12:28:52 +02:00 committed by Ruben S. Montero
parent 90ab60c305
commit 763dc43c58
No known key found for this signature in database
GPG Key ID: A0CEA6FA880A1D87
3 changed files with 20 additions and 4 deletions

View File

@ -23,6 +23,7 @@ define(function(require) {
var TemplateHTML = require('hbs!./guac/html');
var Sunstone = require('sunstone');
var GClient = require('utils/gclient');
var Files = require('utils/files');
/*
CONSTANTS
@ -64,11 +65,18 @@ define(function(require) {
}
function _setup(context) {
var that = this;
$("#open_in_a_new_window_gclient", context).on("click", function() {
var dialog = Sunstone.getDialog(DIALOG_ID);
dialog.hide();
});
$("#takeScreenshot_gclient", context).on("click", function() {
var canvas = that.gClient.snapshot();
Files.downloadImage('screenshot', canvas)
});
return false;
}

View File

@ -23,6 +23,9 @@
<i class="fas fa-spinner fa-spin"></i>
</span>
<span id="guacamole-buttons" class="right">
<button class="button primary" id="takeScreenshot_gclient">
<i class="fas fa-camera fa-fw" title="{{tr 'Take screenshot'}}"></i>
</button>
<button class="button secondary" data-close aria-label="{{tr "Close modal"}}" type="button" title="Close Guacamole">
<i class="fas fa-times-circle"></i>
</button>

View File

@ -21,11 +21,12 @@ define(function(require) {
return {
"downloadWFile": _downloadWFile,
"downloadRdpFile": _downloadRdpFile,
"downloadImage": _downloadImage,
};
function _downloadRdpFile(ip, name = "vm_name", credentials = {}) {
var file = _rdpFile(ip, credentials.USERNAME, credentials.PASSWORD);
_download(name, ".rdp", file);
_download(name, ".rdp", 'data:text/plain;charset=utf-8,' + encodeURIComponent(file));
}
function _downloadWFile(response, vm_host, graphics_type, graphics_port) {
@ -57,12 +58,16 @@ define(function(require) {
var proxy = protocol + "//" + proxy_host + ":" + proxy_port + "?token=" + token;
var file = _wFile(graphics_type, filename, vm_host, graphics_port, proxy, password);
_download(filename, ".vv", file);
_download(filename, ".vv", 'data:text/plain;charset=utf-8,' + encodeURIComponent(file));
}
function _download(name, extension, text) {
function _downloadImage(name, image) {
_download(name, '.png', image.toDataURL('image/png'))
}
function _download(name, extension, file) {
var link = $("<a/>", {
href: 'data:text/plain;charset=utf-8,' + encodeURIComponent(text),
href: file,
download: String(name).concat(extension),
}).css({
display: 'none',