Commit 4b93da87 authored by joelalju's avatar joelalju
Browse files

805_snap_choice: feat(wip): Add upload screenshot function

parent 09b5d575
......@@ -1759,6 +1759,23 @@ sub _cmd_copy_screenshot {
}
}
sub _cmd_upload_screenshot($self, $request) {
my $self = shift;
my $request = shift;
my $id_domain = $request->args('id_domain');
my $fileuploaded = $request->args('file');
my $filename = $request->args('filename');
if (!$domain->can_screenshot) {
die "I can't take a screenshot of the domain ".$domain->name;
} else {
$bytes = $domain->upload_screenshot($request->args('filename'), $request->args('file'));
$bytes = $domain->upload_screenshot($request->args('filename'), $request->args('file')) if !$bytes;
}
$request->error("No data received") if !$bytes;
}
sub _cmd_create{
my $self = shift;
my $request = shift;
......@@ -2318,6 +2335,7 @@ sub _req_method {
,refresh_storage => \&_cmd_refresh_storage
,domain_autostart=> \&_cmd_domain_autostart
,change_owner => \&_cmd_change_owner
,upload_screenshot => \&_cmd_upload_screenshot
);
return $methods{$cmd};
......
......@@ -174,6 +174,7 @@ after 'rename' => \&_post_rename;
before 'clone' => \&_pre_clone;
after 'screenshot' => \&_post_screenshot;
after 'upload_screenshot' => \&_post_screenshot;
after '_select_domain_db' => \&_post_select_domain_db;
......
......@@ -937,6 +937,23 @@ sub screenshot {
unlink $file_tmp or warn "$! removing $file_tmp";
}
=head2 upload_screenshot
Uploads a screenshot, it stores it in file.
=cut
sub upload_screenshot {
my $self = shift;
my $filename = (shift or $self->_file_screenshot);
my $file = shift;
my ($path) = $filename =~ m{(.*)/};
make_path($path) if ! -e $path;
$file->move_to($path);
}
sub _file_screenshot {
my $self = shift;
my $doc = XML::LibXML->load_xml(string => $self->_vm->storage_pool->get_xml_description);
......
......@@ -65,6 +65,7 @@ our %VALID_ARG = (
,refresh_storage => { id_vm => 2 }
,clone => { uid => 1, id_domain => 1, name => 1, memory => 2 }
,change_owner => {uid => 1, id_domain => 1}
,upload_screenshot => { id_domain => 1, file => 1, filename => 1}
);
our %CMD_SEND_MESSAGE = map { $_ => 1 }
......@@ -921,6 +922,32 @@ sub change_owner {
);
}
=head2 upload_screenshot
Changes the screenshot of a machine with an image uploaded
my $req = Ravada::Request->upload_screenshot(
id_domain => $domain->id
,file => $c->param("myScreenshot")
);
=cut
sub upload_screenshot {
my $proto = shift;
my $class = ref($proto) || $proto;
my $args = _check_args('upload_screenshot', @_ );
my $self = {};
bless($self,$class);
return _new_request($self
, command => 'upload_screenshot'
, args =>$args
);
}
=head2 domain_autostart
Sets the autostart flag on a domain
......
......@@ -12,6 +12,7 @@ use Mojolicious::Lite 'Ravada::I18N';
use Time::Piece;
#use Mojolicious::Plugin::I18N;
use Mojo::Home;
use Mojo::Upload;
#####
#my $self->plugin('I18N');
#package Ravada::I18N:en;
......@@ -1434,6 +1435,24 @@ sub settings_machine {
_enable_buttons($c, $domain);
if ($c->req->upload('myScreenshot')) {
# my $filename = $upload->filename;
# $upload->filename = "${domain->id}."
# $upload = $upload->move_to('/tmp/${filename}');
warn "hey";
my $id = $domain->id;
# my $filename =~ s/.*\.(.*)/$id.$1/;
my $fileuploaded = $c->req->upload('myScreenshot');
my $filename = "$DOCUMENT_ROOT/img/screenshots/".$domain->id.$1;
warn "hey";
$req = Ravada::Request->upload_screenshot(
id_domain => $domain->name
, file => $fileuploaded
, filename => $filename
)
}
$c->stash(message => '');
my @reqs = ();
for (qw(sound video network image jpeg zlib playback streaming)) {
......
......@@ -10,12 +10,21 @@
<button ng-click="copy_screenshot(<%= $domain->id %>, '<%= $domain->file_screenshot %>')">
<%=l "Set base picture" %></button>
</div>
% }
<i ng-show="reload_page_msg" ng-cloak><font color="green">Saving the screenshot, please wait a moment...</font></i>
<i ng-show="fail_page_msg" ng-cloak><font color="red">You need to run the machine in order to take a screenshot.</font></i>
<i ng-show="reload_page_copy_msg" ng-cloak><font color="green">Copying the screenshot, please wait a moment...</font></i>
<i ng-show="fail_page_copy_msg" ng-cloak><font color="red">You need a screenshot in order to copy it to the base machine.</font></i>
</div>
% if ( $USER->is_admin ) {
<div class="row">
<form method='post' enctype="multipart/form-data">
<div class="col-lg-5"><input type="file" name="myScreenshot" id="myScreenshot" /></div>
<div class="col-lg-2"><input type="submit" onclick='this.form.submit();' name="uploadScreenshot" id="uploadScreenshot" value="<%=l "Upload Screenshot" %>"></input></div>
</form>
</div>
% }
<div class="row">
<div class="col-lg-4">
<div class="panel panel-default">
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment