Skip to content

Commit

Permalink
Merge branch 'hotfix/0.4.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
frankiejol committed Jul 17, 2019
2 parents 19ea039 + 6455749 commit 121cf51
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 7 deletions.
10 changes: 10 additions & 0 deletions public/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ ravadaApp.directive("solShowMachine", swMach)
$scope.seeswap = !($scope.seeswap);
};

$scope.get_machine_info = function(id) {
$http.get('/machine/info/'+id+'.json')
.then( function(response) {
$scope.machine = response.data;
$scope.ramsize = ($scope.machine.max_mem / 1024 / 1024);
if ( $scope.ramsize <1 ) {
$scope.ramsize = 1;
}
});
};

$http.get('/list_machines.json').then(function(response) {
$scope.base = response.data;
Expand Down
23 changes: 23 additions & 0 deletions rvd_front.pl
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@
return new_machine($c);
};

any '/copy_machine' => sub {
my $c = shift;
return new_machine_copy($c);
};

get '/domain/new.html' => sub {
my $c = shift;

Expand Down Expand Up @@ -2090,6 +2095,24 @@ sub copy_machine {
return $c->render(json => { request => [map { $_->id } @ reqs ] } );
}

sub new_machine_copy($c) {
my $id_base = $c->param('src_machine');
my $copy_name = $c->param('copy_name');

my $ram = $c->param('copy_ram');
$ram = 0 if !$ram || $ram !~ /^\d+(\.\d+)?$/;
$ram = int($ram*1024*1024);

my $req = Ravada::Request->clone(
uid => $USER->id
,id_domain => $id_base
,name => $copy_name
,memory => $ram
);

return $c->redirect_to("/admin/machines");
}

sub copy_machine_many($base, $number, $create_args) {
my $domains = $RAVADA->list_domains;
my %domain_exists = map { $_->{name} => 1 } @$domains;
Expand Down
34 changes: 27 additions & 7 deletions templates/ng-templates/new_machine_other.html.ep
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<div class="tab-pane fade" id="frommachine" role="tabpanel">
<div class="card-body">
<form class="form" method="post" action="/machine/copy">
<form name="new_machine_other_form"
role="form" method="post" action="/copy_machine" novalidate>
<div class="form-group row">
<input class="form-control" type="hidden" name="id_base" value="{{src_machine.id}}">
<label for="src_machine" class="col-xl-3 col-form-label"><%=l 'Source Machine' %></label>
<div class="col-lg-9">
<select class="form-control"
name ="src_machine"
ng-model="src_machine"
ng-options="item.name for item in base track by item.id"
ng-options="item.name for item in base | orderBy:'name' track by item.id "
required=""
ng-change="get_machine_info(src_machine.id)"
></select>
</div>
</div>
Expand All @@ -21,10 +23,13 @@
</div>
<div class="form-group row">
<div class="col-xl-2">
<label class="col-xl-12 text-muted" for="copy_name_{{src_machine.id}}"><%=l 'Name' %>:</label>
<label class="col-xl-12 text-muted" for="copy_name"><%=l 'Name' %>:</label>
</div>
<div class="col-xl-10">
<input class="form-control" name="copy_name_{{src_machine.id}}" type="text" size="40"
<input class="form-control" name="copy_name" type="text" size="40"
ng-model="name"
ng-pattern ="/^[a-zA-Z0-9_-]+$/"
ng-change="validate_new_name()"
value="{{src_machine.name}}-copy">
<!-- todo check unique name -->
</div>
Expand All @@ -34,8 +39,10 @@
<label class="col-xl-12 text-muted" for="copy_ram">RAM (Gb):</label>
</div>
<div class="col-xl-2">
<input class="form-control" ng-model="ramsize" type="number" name="copy_ram"
min="1" max="4" required="">
<input class="form-control" ng-model="ramsize" type="text"
ng-pattern ="/^[0-9]+\.?[0-9]+$/"
name="copy_ram"
required="">
</div>
</div>
<div class="form-group row alert alert-warning"
Expand All @@ -44,11 +51,24 @@
prepared before it can be copied. This
process may take some minutes.
</div>
<div ng-show="name_duplicated" class="form-group row alert alert-danger"
role="alert">
<strong><%=l 'Error' %> : </strong> <%=l 'A machine with that name already exists.' %>
</div>
<div ng-show="new_machine_other_form.copy_name.$error.pattern"
class="form-group row alert alert-danger" role="alert">
<strong><%=l 'Error' %> : </strong> <%=l 'The machine name must contain only alphabetic, numbers, undercores and dashes.' %>
</div>


<div class="form-group row">
<button type="reset" class="btn btn-outline-secondary mr-2" onclick = "location='/admin/machines'"><%=l 'Cancel' %></button>
<input type="submit" class="btn btn-primary" value="<%=l 'Submit' %>">
<input type="submit" class="btn btn-primary" value="<%=l 'Submit' %>"
ng-disabled="new_machine_other_form.$invalid || name_duplicated"
>
</div>
</div>
</form>

</div>
</div>

0 comments on commit 121cf51

Please sign in to comment.