feat(host-details): create mock call to server for agent host info

pull/2255/head
Chaim Lando 2018-09-13 11:48:30 +03:00
parent aa3f7397d8
commit 6751fab987
3 changed files with 57 additions and 27 deletions

View File

@ -1,24 +1,39 @@
angular.module('portainer.agent')
.factory('AgentService', ['$q', 'Agent', function AgentServiceFactory($q, Agent) {
'use strict';
var service = {};
angular.module('portainer.agent').factory('AgentService', [
'$q', 'Agent',
function AgentServiceFactory($q, Agent) {
'use strict';
var service = {};
service.agents = function() {
var deferred = $q.defer();
service.agents = agents;
service.hostInfo = hostInfo;
Agent.query({}).$promise
.then(function success(data) {
var agents = data.map(function (item) {
return new AgentViewModel(item);
function hostInfo() {
return $q.when({
PhysicalDeviceVendor: 'hello',
DeviceVersion: '1.9',
DeviceSerialNumber: '144f',
InstalledPCIDevices: ['usb', 'printer'],
PhysicalDisk: 'none'
});
deferred.resolve(agents);
})
.catch(function error(err) {
deferred.reject({ msg: 'Unable to retrieve agents', err: err });
});
}
return deferred.promise;
};
function agents() {
var deferred = $q.defer();
return service;
}]);
Agent.query({})
.$promise.then(function success(data) {
var agents = data.map(function(item) {
return new AgentViewModel(item);
});
deferred.resolve(agents);
})
.catch(function error(err) {
deferred.reject({ msg: 'Unable to retrieve agents', err: err });
});
return deferred.promise;
}
return service;
}
]);

View File

@ -31,7 +31,7 @@
</tr>
<tr ng-if="$ctrl.host.pciDevices">
<td>Installed PCI devices</td>
<td>{{ $ctrl.host.pciDevices }}</td>
<td>{{ $ctrl.host.pciDevices |commaSeperated }}</td>
</tr>
<tr ng-if="$ctrl.host.physicalDisk">
<td>Physical disk</td>

View File

@ -1,9 +1,9 @@
angular.module('portainer.docker').controller('NodeDetailsViewController', [
'$stateParams', 'NodeService', 'LabelHelper', 'Notifications', '$state', 'StateManager',
function NodeDetailsViewController($stateParams, NodeService, LabelHelper, Notifications, $state, StateManager) {
'$stateParams', 'NodeService', 'LabelHelper', 'Notifications', '$state', 'StateManager', 'AgentService',
function NodeDetailsViewController($stateParams, NodeService, LabelHelper, Notifications, $state, StateManager, AgentService) {
var ctrl = this;
var originalNode;
ctrl.$onInit = initView;
ctrl.updateLabels = updateLabels;
ctrl.updateAvailability = updateAvailability;
@ -13,15 +13,30 @@ angular.module('portainer.docker').controller('NodeDetailsViewController', [
};
function initView() {
NodeService.node($stateParams.id).then(function(node) {
var applicationState = StateManager.getState();
ctrl.state.isAgent = applicationState.endpoint.mode.agentProxy;
var nodeId = $stateParams.id;
NodeService.node(nodeId).then(function(node) {
originalNode = node;
ctrl.hostDetails = buildHostDetails(node);
ctrl.engineDetails = buildEngineDetails(node);
ctrl.nodeDetails = buildNodeDetails(node);
if (ctrl.state.isAgent) {
AgentService.hostInfo(nodeId).then(function onHostInfoLoad(agentHostInfo) {
console.log(agentHostInfo);
enhanceHostDetails(ctrl.hostDetails, agentHostInfo);
});
}
});
var applicationState = StateManager.getState();
ctrl.state.isAgent = applicationState.endpoint.mode.agentProxy;
}
function enhanceHostDetails(hostDetails, agentHostInfo) {
hostDetails.physicalDeviceInfo = agentHostInfo.PhysicalDeviceInfo;
hostDetails.pciDevices = agentHostInfo.InstalledPCIDevices;
hostDetails.physicalDisk = agentHostInfo.PhysicalDisk;
}
function buildHostDetails(node) {
@ -81,7 +96,7 @@ angular.module('portainer.docker').controller('NodeDetailsViewController', [
Id: node.Id,
Version: node.Version
};
NodeService.updateNode(config)
.then(onUpdateSuccess)
.catch(notifyOnError);