App.controller('serverController', function($scope, $http) {
$http.get('/server/model/servers.php').success(function(data) {
$scope.servers = data;
});
});
<div class="row">
<div class="col-lg-4" ng-repeat="server in servers track by $index">
<!-- START panel-->
<div id="panel3" class="panel" ng-class="{1:'panel-danger', 0:'panel-default', 2:'panel-warning'}[server.status]">
<div class="panel-heading"><i class="fa fa-{{server.os}}"></i> {{server.hostname}} - {{server.ipaddress}}
<paneltool tool-collapse="tool-collapse" ng-init="panel3=true"></paneltool>
</div>
<!-- .panel-wrapper is the element to be collapsed-->
<div collapse="panel3" class="panel-wrapper">
<div class="panel-body">
<div class="row">
<div class="col-lg-12"></div>
<div class="col-lg-8">
<div><p>Uptime: {{server.uptime}}</p></div>
<p>{{server.description}}</p>
</div>
<div class="col-lg-2">
<div class="radial-bar radial-bar-{{server.uptimePer}} radial-bar-sm" data-label="{{server.uptimePer}}%"></div>
</div>
</div>
<div ng-if = "server.app_installation_id > 0">
<div class="panel-footer"</div>
</div>
</div>
</div>
</div>
<!-- END panel-->
</div>
</div>
$q.all([servers,installations]).then(function(data){
$scope.servers = merge_join(data[0], 'app_installation_id', data[1], 'id');
})
<div ng-if = "server.app_installation_id > 0">
<div class="panel-footer">Name: {{server. installation}}</div>
</div>
function merge_join(leftList, leftKey, rightList, rightKey){
leftList.sort(function(a,b){
return a[leftKey] - b[leftKey];
})
rightList.sort(function(a,b){
return a[rightKey] - b[rightKey];
})
var left = 0, right = 0;
while(left < leftList.length && right < rightList.length){
if(leftList[left][leftKey] == rightList[right][rightKey]){
angular.extend( leftList[left], rightList[right] );
left++;
right++;
}else if(leftList[left][leftKey] < rightList[right][rightKey]){
left++;
}else if(leftList[left][leftKey] > rightList[right][rightKey]){
right++;
}
}
return leftList
}
$q.all([servers,installations]).then(function(data){
var _servers = merge_join(data[0], 'app_installation_id', data[1], 'id');
$scope.servers = _servers.sort(function(a,b){
if (a.hostname < b.hostname) { return -1; }
if (a.hostname > b.hostname) { return 1; }
return 0;
})
})
$q.all([servers,installations]).then(function(data){
console.log("data: ", data)
$scope.servers = merge_join(data[0], 'app_installation_id', data[1], 'id');
})
[
{
"id": "2",
"ipaddress": "10.10.10.10",
"hostname": "nooslbps01",
"location": "Oslo",
"description": null,
"os": "linux",
"app_installation_id": "6",
"entryID": "98",
"server_id": "2",
"status": "0",
"uptime_sec": "2354495"
},
{
"id": "1",
"ipaddress": "11.11.11.11",
"hostname": "vss01lanet",
"location": "Landskrona",
"description": null,
"os": "linux",
"app_installation_id": "3",
"entryID": "49",
"server_id": "1",
"status": "0",
"uptime_sec": "24339332"
}
]
App.service('ServersService', Servers);
Servers.$inject = ['$http'];
function Servers($http){
var self = this;
self.getServers = function(){ // returns a promise you can use in your controller
return $http.get('/server/model/servers.php')
}
self.getInstallations = function(){
return $http.get('/server/model/installations.php')
}
}
App.controller('serverController', Server);
Server.$inject = ['$scope','$q', 'ServersService']
function merge_join(leftList, leftKey, rightList, rightKey){
leftList.sort(function(a,b){
return a[leftKey] - b[leftKey];
})
rightList.sort(function(a,b){
return a[rightKey] - b[rightKey];
})
var left = 0, right = 0;
while(left < leftList.length && right < rightList.length){
if(leftList[left][leftKey] == rightList[right][rightKey]){
angular.extend( leftList[left], rightList[right] );
left++;
right++;
}else if(leftList[left][leftKey] < rightList[right][rightKey]){
left++;
}else if(leftList[left][leftKey] > rightList[right][rightKey]){
right++;
}
}
return leftList
}
function Server($scope, $q, ServersService) {
var servers = ServersService.getServers();
var installations = ServersService.getInstallations();
$q.all([servers,installations]).then(function(data){
var _servers = merge_join(data[0], 'app_installation_id', data[1], 'id');
$scope.servers = _servers.sort(function(a,b){
if (a.hostname < b.hostname) { return -1; }
if (a.hostname > b.hostname) { return 1; }
return 0;
})
})
}
<div ng-if = "server.app_installation_id > 0">
<div class="panel-footer">Name: {{server.installation}}</div>
</div>
"data: " Array [ Object, Object ]
[
{"id": "13841",
"server_id": "1",
"rtt_ms": "30.53",
"time": "2015-04-13 06:01:01"},
{"id": "13843",
"server_id": "1",
"rtt_ms": "30.75",
"time": "2015-04-13 06:02:02"},
{
"id": "13844",
"server_id": "2",
"rtt_ms": "27.57",
"time": "2015-04-13 06:02:02"}
]
var servers = ServersService.getServers();
var installations = ServersService.getInstallations();
var latencyData = ServersService.getLatencyData();
$q.all([servers,installations,latencyData]).then(function(data){
// do something with the data...
})
function arrToObj(array) {
var obj = {};
array.map(function (element) {
if(!obj[element.server_id]){
obj[element.server_id] = []
}
obj[element.id].push(element);
})
return obj;
}
[{
"id": "13841",
"server_id": "1",
"rtt_ms": "30.53",
"time": "2015-04-13 06:01:01"
}, {
"id": "13843",
"server_id": "1",
"rtt_ms": "30.75",
"time": "2015-04-13 06:02:02"
}, {
"id": "13844",
"server_id": "2",
"rtt_ms": "27.57",
"time": "2015-04-13 06:02:02"
}]
{
"1": [{
"id": "13841",
"server_id": "1",
"rtt_ms": "30.53",
"time": "2015-04-13 06:01:01"
},
{
"id": "13843",
"server_id": "1",
"rtt_ms": "30.75",
"time": "2015-04-13 06:02:02"
}],
"2": {
"id": "13844",
"server_id": "2",
"rtt_ms": "27.57",
"time": "2015-04-13 06:02:02"
}
}
Open in new window
And the applications:
Open in new window