Commit 16e9ed74 authored by Francesc Guasch's avatar Francesc Guasch
Browse files

wip(frontend): rolled back web services

issue #1197
parent 0a090c03
......@@ -119,6 +119,7 @@ ravadaApp.directive("solShowMachine", swMach)
$http.get('/pingbackend.json').then(function(response) {
$scope.pingbe_fail = !response.data;
});
$scope.getMachines = function() {
if( $scope.check_netdata && $scope.check_netdata != "0" ) {
var url = $scope.check_netdata;
$scope.check_netdata = 0;
......@@ -137,76 +138,62 @@ ravadaApp.directive("solShowMachine", swMach)
$http.get("/session/monitoring/0");
});
}
$scope.subscribe_all=function(url) {
subscribe_list_machines(url);
subscribe_list_requests(url);
};
subscribe_list_machines= function(url) {
var ws = new WebSocket(url);
ws.onopen = function (event) { ws.send('list_machines') };
ws.onmessage = function (event) {
var data = JSON.parse(event.data);
$scope.$apply(function () {
$scope.list_machines = [];
var mach;
for (var i=0, iLength = data.length; i<iLength; i++){
mach = data[i];
if (!mach.id_base){
$scope.list_machines[mach.id] = mach;
$scope.list_machines[mach.id].childs = [];
}
}
$scope.n_clones = 0;
for (var i=0, iLength = data.length; i<iLength; i++){
mach = data[i];
if (mach.id_base){
$scope.list_machines[mach.id_base].childs.push(mach);
$scope.n_clones++;
}
}
if ($scope.auto_hide_clones) {
$scope.hide_clones = 0;
if ($scope.n_clones > $scope.n_clones_hide ) {
$scope.hide_clones = 1;
}
}
for (var i = $scope.list_machines.length-1; i >= 0; i--){
if (!$scope.list_machines[i]){
$scope.list_machines.splice(i,1);
}
mach = $scope.list_machines[i];
if (!mach.id_base && typeof $scope.show_clones[mach.id] == 'undefined') {
$scope.show_clones[mach.id] = !$scope.hide_clones;
}
if(!$scope.modalOpened){
if ($scope.list_machines_busy) {
return ;
}
$scope.list_machines_busy = true;
$http.get("/requests.json").then(function(response) {
$scope.requests=response.data;
$scope.download_done=false;
$scope.download_working =false;
for (var i = 0; i < $scope.requests.length; i++){
if ( $scope.requests[i].command == 'download') {
if ($scope.requests[i].status == 'done') {
$scope.download_done=true;
} else {
$scope.download_working=true;
}
});
}
}
}
subscribe_list_requests = function(url) {
$scope.show_requests = false;
var ws = new WebSocket(url);
ws.onopen = function (event) { ws.send('list_requests') };
ws.onmessage = function (event) {
var data = JSON.parse(event.data);
$scope.$apply(function () {
$scope.requests= data;
$scope.download_done=false;
$scope.download_working =false;
for (var i = 0; i < $scope.requests.length; i++){
if ( $scope.requests[i].command == 'download') {
if ($scope.requests[i].status == 'done') {
$scope.download_done=true;
} else {
$scope.download_working=true;
}
}
}
});
});
$http.get("/list_machines.json").then(function(response) {
$scope.list_machines_busy = false;
$scope.list_machines = [];
var mach;
for (var i=0, iLength = response.data.length; i<iLength; i++){
mach = response.data[i];
if (!mach.id_base){
$scope.list_machines[mach.id] = mach;
$scope.list_machines[mach.id].childs = [];
}
}
$scope.n_clones = 0;
for (var i=0, iLength = response.data.length; i<iLength; i++){
mach = response.data[i];
if (mach.id_base){
$scope.list_machines[mach.id_base].childs.push(mach);
$scope.n_clones++;
}
}
for (var i = $scope.list_machines.length-1; i >= 0; i--){
if (!$scope.list_machines[i]){
$scope.list_machines.splice(i,1);
}
}
if ($scope.auto_hide_clones) {
$scope.hide_clones = 0;
if ($scope.n_clones > $scope.n_clones_hide ) {
$scope.hide_clones = 1;
}
}
}
,function (error){;
$scope.list_machines_busy = false;
}
);
}
};
$scope.orderParam = ['name'];
$scope.auto_hide_clones = true;
$scope.orderMachineList = function(type1,type2){
......@@ -217,17 +204,10 @@ ravadaApp.directive("solShowMachine", swMach)
else $scope.orderParam = [type1,'-'+type2];
}
$scope.hide_clones = true;
$scope.showClones = function(value){
$scope.auto_hide_clones = false;
$scope.hide_clones = !value;
for (var i = $scope.list_machines.length-1; i >= 0; i--){
mach = $scope.list_machines[i];
if (!mach.id_base) {
$scope.show_clones[mach.id] = value;
}
}
}
$scope.hideClones = function(){
$scope.hide_clones = !$scope.hide_clones;
$scope.auto_hide_clones = false;
}
$scope.request = function(request, args) {
$http.post('/request/'+request+'/'
,JSON.stringify(args)
......@@ -239,6 +219,7 @@ ravadaApp.directive("solShowMachine", swMach)
$scope.action = function(target,action,machineId){
$http.get('/'+target+'/'+action+'/'+machineId+'.json')
.then(function() {
$scope.getMachines();
});
};
$scope.set_autostart= function(machineId, value) {
......@@ -283,7 +264,8 @@ ravadaApp.directive("solShowMachine", swMach)
$scope.rename= {new_name: 'new_name'};
$scope.show_rename = false;
$scope.new_name_duplicated=false;
$scope.show_clones = {};
$scope.getMachines();
$interval($scope.getMachines,3000);
};
function usersPageC($scope, $http, $interval, request) {
......@@ -408,6 +390,8 @@ ravadaApp.directive("solShowMachine", swMach)
$scope.backend = response.data[0];
});
$scope.validate_node_name = function() {
console.log($scope.name);
$http.get('/node/exists/'+$scope.name)
.then(duplicated_callback, unique_callback);
......
......@@ -160,31 +160,6 @@
};
function singleMachinePageC($scope, $http, $interval, request, $location) {
subscribe_machine_info= function(url) {
var ws = new WebSocket(url);
ws.onopen = function(event) { ws.send('machine_info/'+$scope.showmachineId) };
ws.onmessage = function(event) {
var data = JSON.parse(event.data);
$scope.$apply(function () {
$scope.showmachine = data;
});
}
};
subscribe_requests = function(url) {
var ws = new WebSocket(url);
ws.onopen = function(event) { ws.send('list_requests') };
ws.onmessage = function(event) {
var data = JSON.parse(event.data);
$scope.$apply(function () {
$scope.alerts_ws = data;
});
}
};
$scope.subscribe_ws = function(url) {
subscribe_machine_info(url);
subscribe_requests(url);
};
$scope.init = function(id) {
$scope.showmachineId=id;
$http.get('/machine/info/'+$scope.showmachineId+'.json')
......@@ -194,6 +169,7 @@
$scope.new_name=$scope.showmachine.name+"-2";
$scope.validate_new_name($scope.showmachine.name);
}
$scope.refresh_machine();
$scope.init_ldap_access();
$scope.list_ldap_attributes();
$scope.list_interfaces();
......@@ -220,10 +196,27 @@
$http.get('/pingbackend.json').then(function(response) {
$scope.pingbe_fail = !response.data;
});
/* $scope.getSingleMachine = function(){
$http.get("/list_machines.json").then(function(response) {
for (var i=0, iLength=response.data.length; i<iLength; i++) {
if (response.data[i].id == $scope.showmachineId) {
$scope.showmachine = response.data[i];
if (!$scope.new_name) {
$scope.new_name = $scope.showmachine.name;
}
$scope.domain = response.data[i];
return;
}
}
window.location.href = "/admin/machines";
});
};
*/
$scope.machine_info = function(id) {
$http.get('/machine/info/'+$scope.showmachineId+'.json')
.then(function(response) {
$scope.showmachine=response.data;
$scope.list_nodes();
});
};
$scope.remove = function(machineId) {
......@@ -273,6 +266,7 @@
$scope.rename_requested=1;
$http.get('/machine/rename/'+machineId+'/'
+$scope.new_name);
$scope.refresh_machine();
};
$scope.cancel_rename=function(old_name) {
$scope.new_name = old_name;
......@@ -308,12 +302,22 @@
if (! value) {
value_show = false;
}
$scope.add_message("Setting "+$scope.showmachine.name+" "+field+" to "+value_show);
$http.get("/machine/set/"+$scope.showmachine.id+"/"+field+"/"+value);
};
$scope.set = function(field) {
$scope.add_message("Setting "+$scope.showmachine.name+" "+field+" to "
+$scope.showmachine[field]);
$http.get("/machine/set/"+$scope.showmachine.id+"/"+field+"/"+$scope.showmachine[field]);
};
$scope.add_message = function(text) {
$scope.message.push(text);
setTimeout(function () {
$scope.message = [];
}, 5000);
};
$scope.set_public = function(machineId, value) {
if (value) value=1;
else value=0;
......@@ -327,6 +331,8 @@
}
$http.get("/machine/"+url+"/" +vmId+ "/" +machineId+".json")
.then(function(response) {
$scope.getReqs();
$scope.refresh_machine();
});
};
$scope.copy_machine = function() {
......@@ -337,11 +343,47 @@
,'new_name': $scope.new_name
})
).then(function(response) {
$scope.getReqs();
$scope.refresh_machine();
});
};
//On load code
// $scope.showmachineId = window.location.pathname.split("/")[3].split(".")[0] || -1 ;
$scope.refresh_machine = function() {
if(!$scope.showmachine || $scope.refreshing_machine) { return }
$scope.refreshing_machine = true;
$http.get('/machine/requests/'+$scope.showmachine.id+'.json').then(function(response) {
$scope.refreshing_machine = false;
$scope.requests = response.data;
var pending = 0;
for (var i in response.data) {
if(response.data[i].status != 'done') {
pending++;
}
}
$scope.pending_requests = pending;
if ($scope.requests.length) {
setTimeout(function () {
$scope.refresh_machine();
}, 2000);
}
if( pending < $scope.pending_before) {
if($scope.showmachine) {
$scope.machine_info($scope.showmachine.id);
}
setTimeout(function () {
$scope.machine_info($scope.showmachine.id);
}, 2000);
} else {
setTimeout(function () {
$scope.refresh_machine();
}, 30000);
}
$scope.pending_before = pending;
});
};
$scope.add_hardware = function(hardware, number, extra) {
if (hardware == 'disk' && ! extra) {
$scope.show_new_disk = true;
......@@ -357,6 +399,10 @@
,'data': extra
})
).then(function(response) {
$scope.pending_before++;
if (!$scope.requests || !$scope.requests.length) {
$scope.refresh_machine();
}
});
};
$scope.remove_hardware = function(hardware, index, item, confirmation) {
......@@ -369,6 +415,10 @@
item.remove = false;
$http.get('/machine/hardware/remove/'
+$scope.showmachine.id+'/'+hardware+'/'+index).then(function(response) {
$scope.pending_before++;
if (!$scope.requests || !$scope.requests.length) {
$scope.refresh_machine();
}
});
};
......@@ -405,6 +455,7 @@
,'id_port': id_port
})
).then(function(response) {
$scope.refresh_machine();
});
$scope.init_new_port();
};
......@@ -415,6 +466,7 @@
,'port': port
})
).then(function(response) {
$scope.refresh_machine();
});
};
......@@ -463,7 +515,7 @@
$scope.new_port_name = null;
$scope.new_port_restricted = false;
};
list_nodes = function() {
$scope.list_nodes = function() {
$http.get('/list_nodes.json').then(function(response) {
$scope.nodes = response.data;
});
......@@ -487,6 +539,7 @@
,'data': new_settings
})
).then(function(response) {
$scope.getReqs();
});
};
......@@ -509,6 +562,7 @@
,'data': new_settings
})
).then(function(response) {
$scope.getReqs();
});
};
$scope.add_disk = {
......@@ -522,7 +576,12 @@
$scope.pending_before = 10;
// $scope.getSingleMachine();
// $scope.updatePromise = $interval($scope.getSingleMachine,3000);
list_nodes();
$scope.getReqs= function() {
$http.get('/requests.json').then(function(response) {
$scope.requests=response.data;
});
};
$scope.getReqs();
$scope.list_ldap_attributes();
};
......@@ -732,26 +791,22 @@
};
function notifCrtl($scope, $interval, $http, request){
$scope.getAlerts = function() {
$http.get('/unshown_messages.json').then(function(response) {
$scope.alerts= response.data;
},function error(response) {
if ( response.status == 403 && (typeof $_anonymous == "undefined" || !$_anonymous)) {
window.location.href="/logout";
}
});
};
$interval($scope.getAlerts,10000);
$scope.closeAlert = function(index) {
var message = $scope.alerts_ws.splice(index, 1);
var toGet = '/messages/read/'+message[0].id+'.json';
var message = $scope.alerts.splice(index, 1);
var toGet = '/messages/read/'+message[0].id+'.html';
$http.get(toGet);
};
$scope.subscribe_alerts = function(url) {
var ws = new WebSocket(url);
ws.onopen = function(event) { ws.send('list_alerts') };
ws.onmessage = function(event) {
var data = JSON.parse(event.data);
$scope.$apply(function () {
$scope.alerts_ws = data;
});
}
}
$scope.alerts_ws = [];
$scope.getAlerts();
};
/*
......
<div id="overNotifications" class="notifications" ng-controller="notifCrtl"
ng-init="subscribe_alerts('<%= url_for('ws_subscribe')->to_abs %>', $scope)"
ng-cloak>
<div id="overNotifications" class="notifications" ng-controller="notifCrtl" ng-cloak>
<script type="text/ng-template" id="alert.html">
<div ng-transclude></div>
</script>
<div uib-alert ng-repeat="alert in alerts_ws"
<div uib-alert ng-repeat="alert in alerts"
ng-class="'alert-' + (alert.type || 'warning')"
ng-click="closeAlert($index)"
ng-mouseover="alert.showMessage = false"
......
......@@ -3,7 +3,7 @@
%= include 'bootstrap/header'
<body id="page-top" data-spy="scroll" data-target=".navbar-fixed-top" role="document">
<div id="wrapper">
<div ng-controller="machinesPage" ng-init="subscribe_all('<%= url_for('ws_subscribe')->to_abs %>');n_clones_hide=<%= $n_clones_hide %>;check_netdata='<%= $check_netdata %>'" >
<div ng-controller="machinesPage" ng-init="n_clones_hide=<%= $n_clones_hide %>;check_netdata='<%= $check_netdata %>'" >
%= include 'bootstrap/navigation'
<div id="page-wrapper">
<div id="admin-content">
......@@ -126,10 +126,10 @@
ng-hide="orderParam[0] !== '-name'"></i>
<%=l 'Machine Name' %></div>
<div style="float:right" ng-show="n_clones">
<a ng-show="hide_clones" ng-click="showClones(true)"
<a ng-show="hide_clones" ng-click="hideClones()"
class="badge badge-primary dropdown-toggle text-white"
align="right"><%=l 'show clones' %></a>
<a ng-show="!hide_clones" ng-click="showClones(false)"
<a ng-show="!hide_clones" ng-click="hideClones()"
class="badge badge-primary dropdown-toggle text-white"
align="right"><%=l 'hide clones' %></a>
</div>
......@@ -161,14 +161,6 @@
ng-class="{disabled: !machine.can_manage}"
title ="<%=l 'Manage machine' %>"><b
ng-cloak>{{machine.name}}</b></a> {{machine.comment}}
<button ng-show="machine.has_clones" type="button"
class="badge badge-light text-blue"
ng-click="show_clones[machine.id] = !show_clones[machine.id]"
title="<%=l 'Show/Hide clones' %>">
<b ng-show="show_clones[machine.id]" >-</b>
<b ng-show="!show_clones[machine.id]">+</b>
</button>
</td>
<td class="lgMachToggle">
% if ($_user->can_create_base ) {
......@@ -289,7 +281,7 @@
</td>
<td class="lgMachNode"></td>
</tr>
<tr ng-show="show_clones[machine.id]" ng-repeat="child in machine.childs | orderBy : orderParam">
<tr ng-hide="hide_clones" ng-repeat="child in machine.childs | orderBy : orderParam">
<td class="lgMachName">
&nbsp;<i title="[cloned]" class="fa fa-fw fa-long-arrow-right"
style="color:white"></i>
......
......@@ -8,7 +8,7 @@
<!--BASES AND DOMAINS LIST-->
<div class="page-header">
<div class="card"
ng-controller="singleMachinePage" ng-init="subscribe_ws('<%= url_for('ws_subscribe')->to_abs %>', $scope);init(<%= $id %>);">
ng-controller="singleMachinePage" ng-init="init(<%= $id %>)">
<div class="card-header">
% if ($domain->is_base) {
<h2><%=l 'Virtual Machine' %>
......
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