Commit 0dfde9f7 authored by Ahmed Zarioh's avatar Ahmed Zarioh

display graph in raw monitor + restructured client side

parent 5a09d293
......@@ -5,4 +5,4 @@
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
</IfModule>
RedirectMatch 404 /\.git
\ No newline at end of file
RedirectMatch 404 /\.git
......@@ -19,7 +19,6 @@
/*
* @author Ahmed Zarioh (ahmed.zarioh@gmail.com)
*/
//require_once __DIR__.'/../Service/RestService.php';
class RestController
{
......@@ -133,7 +132,7 @@ class RestController
$ret = [];
foreach($options as $option)
{
$ret[$option] = json_decode(static::getSimpleAll($option));
$ret[$option] = static::getSimpleAll($option);
}
return $ret;
}
......
<?php
/*
* Copyright 2015 be.wan s.p.r.l.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/*
* @author Ahmed Zarioh (ahmed.zarioh@gmail.com)
*/
class RawMonitorService extends ColosseumService
{
/***********************************/
/* */
/***********************************/
public static function getOne($apiname,$val)
{
$url ="/$apiname/$val";
//GET VM BY ID
$result = static::getSimpleOne($apiname,$val);
//GET monitorInstance
$array = [];
foreach ($result->monitorInstances as $key => $value)
{
$temp = static::getSimpleOne("monitorInstance",$value);
$result->sensorDescription = static::getSimpleOne("sensorDescription",$result->sensorDescription);
$temp->metricName = $result->sensorDescription->metricName;
$array[] = $temp;
}
$result->monitorInstances = $array;
return $result;
}
}
\ No newline at end of file
......@@ -19,6 +19,26 @@
/*
* @author Ahmed Zarioh (ahmed.zarioh@gmail.com)
*/
function include_all_javascript($folder)
{
foreach (glob(__DIR__."/../{$folder}/*.js") as $filename)
{
//$filename strrchr($filename,'/');
?>
<script src="<?php echo "{$folder}/".basename($filename); ?>"></script>
<?php
}
foreach (glob(__DIR__."/../{$folder}/*") as $foldername)
{
if(is_dir($foldername))
{
include_all_javascript("{$folder}/".basename($foldername));
}
}
}
?>
<!DOCTYPE html>
<html>
......@@ -66,15 +86,14 @@
<!-- App -->
<script src="public/js/app.js"></script>
<!-- Controllers -->
<?php foreach (glob("public/js/controller/*.js") as $filename) { ?>
<script src="<?php echo $filename?>"></script>
<?php } ?>
<!-- Services -->
<?php foreach (glob("public/js/service/*.js") as $filename) { ?>
<script src="<?php echo $filename?>"></script>
<?php } ?>
<!-- Controllers-->
<?php include_all_javascript("public/js/controller"); ?>
<!-- Services-->
<?php include_all_javascript("public/js/service"); ?>
<script src="public/js/filters.js"></script>
</head>
......
......@@ -66,6 +66,10 @@ paasageApp.config(
templateUrl: 'public/partials/monitorInstance-detail.html',
controller: 'MonitorInstanceDetailCtrl'
})
.when('/rawMonitor/:apiid', {
templateUrl: 'public/partials/rawMonitor-detail.html',
controller: 'RawMonitorDetailCtrl'
})
.when('/application/:apiid', {
templateUrl: 'public/partials/application-detail.html',
controller: 'ApplicationDetailCtrl'
......
......@@ -19,10 +19,8 @@
/*
* @author Ahmed Zarioh (ahmed.zarioh@gmail.com)
*/
//'use strict';
/* Controllers */
crudControllers.controller('ChartsCtrl', function($scope,$interval,$http,ajaxFactory)
{
$scope.url = "kairosapi/charts";
......@@ -43,15 +41,6 @@ crudControllers.controller('ChartsCtrl', function($scope,$interval,$http,ajaxFac
$scope.graphDetails.start_relative = {};
$scope.graphDetails.start_relative.value = 1;
$scope.graphDetails.apiEndpoint = monitorInstance.apiEndpoint;
/*
$scope.graphDetails.interval = {};
$scope.graphDetails.interval.value = monitorInstance.interval.period;
$scope.graphDetails.interval.unit = monitorInstance.interval.timeUnit;
$scope.graphDetails.start_relative = {};
$scope.graphDetails.start_relative.value = 1;
*/
switch($scope.graphDetails.interval.unit)
{
......@@ -80,96 +69,30 @@ crudControllers.controller('ChartsCtrl', function($scope,$interval,$http,ajaxFac
{
//TODO add a protection like a synchronized thread (a variable that is false durring the ajax and would hide/enabled the inputs)
$scope.wait = true;
$scope.error = false;
//to change to "pure" angularjs code
var graph = $("#graph-num-"+$scope.k);
$scope.canvW = graph.find("canvas").width();
$scope.canvH = graph.find("canvas").height();
$scope.wait = true;
$scope.error = false;
//to change to "pure" angularjs code
var graph = $("#graph-num-"+$scope.k);
$scope.canvW = graph.find("canvas").width();
$scope.canvH = graph.find("canvas").height();
//$scope.azara = $scope.graphDetails;
console.log($scope.graphDetails);
ajaxFactory.post("charts",$scope.graphDetails).then(function(data, status, headers, config)
{
//$scope.azara = data;
$scope.data = getInfoChart(data.queries);
$scope.wait = false;
},
function(data, status, headers, config)
{
$scope.wait = false;
$scope.error = true;
});
//$scope.azara = $scope.graphDetails;
console.log($scope.graphDetails);
ajaxFactory.post("charts",$scope.graphDetails).then(function(data, status, headers, config)
{
//$scope.azara = data;
$scope.data = getInfoChart(data.queries);
$scope.wait = false;
},
function(data, status, headers, config)
{
$scope.wait = false;
$scope.error = true;
});
};
$scope.interval = $interval($scope.change,10000);
$scope.$on("$destroy", function(){
$interval.cancel($scope.interval);
});
});
crudControllers.controller('unitValueController', function($scope)
{
$scope.template = 'public/partials/value-unit.html';
$scope.unitNames = ["seconds","minutes","hours","days","months","years"];
$scope.unitChange = function(clickEvent)
{
$scope.valUnit.unit = clickEvent.currentTarget.innerHTML;
$scope.change();
};
$scope.addValue= function(x)
{
$scope.valUnit.value = +$scope.valUnit.value+x;
$scope.change();
}
$scope.init = function(title,valUnit)
{
$scope.valUnitTitle = title;
$scope.valUnit = valUnit;
}
});
crudControllers.directive('ngGraph', function($interval)
{
return{
restrict: 'E',
/*scope :{
data : "=",
change : "&"
},*/
link: function(scope, elem, attrs)
{
var graph = null;
var flotOptions = {
series: { lines: { show: true }, points: { show: true } },
grid: { hoverable: true },
selection: { mode: "xy" },
xaxis: { mode: "time", timezone: "browser" },
colors: ["#37ABC8","#006680"]
};
// If the data changes somehow, update it in the chart
scope.$watch('data', function(v)
{
if(v)
{
if(!graph)
{
graph = $.plot(elem, v , flotOptions);
elem.show();
elem.UseTooltip();
}
else
{
graph.setData(v);
graph.setupGrid();
graph.draw();
}
}
});
}
};
});
\ No newline at end of file
/*
* Copyright 2015 be.wan s.p.r.l.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/*
* @author Ahmed Zarioh (ahmed.zarioh@gmail.com)
*/
/* Directive */
crudControllers.directive('ngGraph', function($interval)
{
return{
restrict: 'E',
/*scope :{
data : "=",
change : "&"
},*/
link: function(scope, elem, attrs)
{
var graph = null;
var flotOptions = {
series: { lines: { show: true }, points: { show: true } },
grid: { hoverable: true },
selection: { mode: "xy" },
xaxis: { mode: "time", timezone: "browser" },
colors: ["#37ABC8","#006680"]
};
// If the data changes somehow, update it in the chart
scope.$watch('data', function(v)
{
if(v)
{
if(!graph)
{
graph = $.plot(elem, v , flotOptions);
elem.show();
elem.UseTooltip();
}
else
{
graph.setData(v);
graph.setupGrid();
graph.draw();
}
}
});
}
};
});
\ No newline at end of file
/*
* Copyright 2015 be.wan s.p.r.l.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/*
* @author Ahmed Zarioh (ahmed.zarioh@gmail.com)
*/
/* Controllers */
crudControllers.controller('unitValueController', function($scope)
{
$scope.template = 'public/partials/value-unit.html';
$scope.unitNames = ["seconds","minutes","hours","days","months","years"];
$scope.unitChange = function(clickEvent)
{
$scope.valUnit.unit = clickEvent.currentTarget.innerHTML;
$scope.change();
};
$scope.addValue= function(x)
{
$scope.valUnit.value = +$scope.valUnit.value+x;
$scope.change();
}
$scope.init = function(title,valUnit)
{
$scope.valUnitTitle = title;
$scope.valUnit = valUnit;
}
});
\ No newline at end of file
......@@ -18,7 +18,6 @@
/*
* @author Ahmed Zarioh (ahmed.zarioh@gmail.com)
*/
//'use strict';
/* Controllers */
crudControllers.controller('ApplicationAddCtrl', function($scope,$rootScope,$location,$routeParams,ajaxFactory,$controller)
......
......@@ -18,7 +18,6 @@
/*
* @author Ahmed Zarioh (ahmed.zarioh@gmail.com)
*/
//'use strict';
/* Controllers */
crudControllers.controller('ApplicationDetailCtrl', function($rootScope,$scope,$location,$routeParams,ajaxFactory,$controller)
......
......@@ -18,7 +18,6 @@
/*
* @author Ahmed Zarioh (ahmed.zarioh@gmail.com)
*/
//'use strict';
/* Controllers */
crudControllers.controller('ApplicationUpdateCtrl', function($scope,$rootScope,$location,$routeParams,ajaxFactory,$controller,$q)
......
/*
* Copyright 2015 be.wan s.p.r.l.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/*
* @author Ahmed Zarioh (ahmed.zarioh@gmail.com)
*/
/* Controllers */
crudControllers.controller('MonitorInstanceDetailCtrl', function($controller,$rootScope,$scope,$location,$routeParams,ajaxFactory)
{
$routeParams.apiname = "monitorInstance";
angular.extend(this, $controller('AbstractDetailCtrl', {$rootScope,$scope,$location,$routeParams,ajaxFactory}));
$scope.init = function()
{
$scope.chart = { name: 'charts.html', url: 'public/partials/charts.html'};
$scope.url = $routeParams.apiname+"/"+$routeParams.apiid+"/";
//get the VM
ajaxFactory.get($scope.url).then(function(data)
{
$scope.item = data;
});
$scope.redirectUrl = $routeParams.apiname+"/";
}
$scope.init();
});
\ No newline at end of file
/*
* Copyright 2015 be.wan s.p.r.l.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/*
* @author Ahmed Zarioh (ahmed.zarioh@gmail.com)
*/
/* Controllers */
crudControllers.controller('RawMonitorDetailCtrl', function($controller,$rootScope,$scope,$location,$routeParams,ajaxFactory)
{
$routeParams.apiname = "rawMonitor";
angular.extend(this, $controller('AbstractDetailCtrl', {$rootScope,$scope,$location,$routeParams,ajaxFactory}));
$scope.init = function()
{
$scope.chart = { name: 'charts.html', url: 'public/partials/charts.html'};
$scope.url = $routeParams.apiname+"/"+$routeParams.apiid+"/";
//get the VM
ajaxFactory.get($scope.url).then(function(data)
{
$scope.item = data;
});
$scope.redirectUrl = $routeParams.apiname+"/";
}
$scope.init();
});
\ No newline at end of file
/*
* Copyright 2015 be.wan s.p.r.l.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/*
* @author Ahmed Zarioh (ahmed.zarioh@gmail.com)
*/
/* Controllers */
crudControllers.controller('VMDetailCtrl', function($controller,$rootScope,$scope,$location,$routeParams,ajaxFactory)
{
$routeParams.apiname = "virtualMachine";
......
/*
* Copyright 2015 be.wan s.p.r.l.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/*
* @author Ahmed Zarioh (ahmed.zarioh@gmail.com)
*/
/* Controllers */
crudControllers.controller('AbstractDetailCtrl', function($rootScope,$scope,$location,$routeParams,ajaxFactory)
{
$scope.clearError();
$scope.apiname = $routeParams.apiname;
$scope.init = function()
{
$scope.url = $routeParams.apiname+"/"+$routeParams.apiid+"/";
$scope.arguments = mainConfig["apisObjects"][$routeParams.apiname]["details"];
$scope.getApiName = ajaxFactory.getApiName;
ajaxFactory.get($scope.url).then(function(data)
{
$scope.item = data;
},function(data)
{
console.log(data);
});
};
$scope.del = function()
{
if(confirm("Do you realy want to delete this "+$routeParams.apiname+"?"))
{
ajaxFactory.del($scope.url).then(function(data)
{
$scope.list();
});
}
};
$scope.list = function()
{
$location.path("/"+$routeParams.apiname);
};
$scope.edit = function(item)
{
$location.path("/"+$routeParams.apiname+"/"+$scope.item.id+"/set");
};