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') angular.module('portainer.agent').factory('AgentService', [
.factory('AgentService', ['$q', 'Agent', function AgentServiceFactory($q, Agent) { '$q', 'Agent',
'use strict'; function AgentServiceFactory($q, Agent) {
var service = {}; 'use strict';
var service = {};
service.agents = function() { service.agents = agents;
var deferred = $q.defer(); service.hostInfo = hostInfo;
Agent.query({}).$promise function hostInfo() {
.then(function success(data) { return $q.when({
var agents = data.map(function (item) { PhysicalDeviceVendor: 'hello',
return new AgentViewModel(item); 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>
<tr ng-if="$ctrl.host.pciDevices"> <tr ng-if="$ctrl.host.pciDevices">
<td>Installed PCI devices</td> <td>Installed PCI devices</td>
<td>{{ $ctrl.host.pciDevices }}</td> <td>{{ $ctrl.host.pciDevices |commaSeperated }}</td>
</tr> </tr>
<tr ng-if="$ctrl.host.physicalDisk"> <tr ng-if="$ctrl.host.physicalDisk">
<td>Physical disk</td> <td>Physical disk</td>

View File

@ -1,9 +1,9 @@
angular.module('portainer.docker').controller('NodeDetailsViewController', [ angular.module('portainer.docker').controller('NodeDetailsViewController', [
'$stateParams', 'NodeService', 'LabelHelper', 'Notifications', '$state', 'StateManager', '$stateParams', 'NodeService', 'LabelHelper', 'Notifications', '$state', 'StateManager', 'AgentService',
function NodeDetailsViewController($stateParams, NodeService, LabelHelper, Notifications, $state, StateManager) { function NodeDetailsViewController($stateParams, NodeService, LabelHelper, Notifications, $state, StateManager, AgentService) {
var ctrl = this; var ctrl = this;
var originalNode; var originalNode;
ctrl.$onInit = initView; ctrl.$onInit = initView;
ctrl.updateLabels = updateLabels; ctrl.updateLabels = updateLabels;
ctrl.updateAvailability = updateAvailability; ctrl.updateAvailability = updateAvailability;
@ -13,15 +13,30 @@ angular.module('portainer.docker').controller('NodeDetailsViewController', [
}; };
function initView() { 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; originalNode = node;
ctrl.hostDetails = buildHostDetails(node); ctrl.hostDetails = buildHostDetails(node);
ctrl.engineDetails = buildEngineDetails(node); ctrl.engineDetails = buildEngineDetails(node);
ctrl.nodeDetails = buildNodeDetails(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) { function buildHostDetails(node) {
@ -81,7 +96,7 @@ angular.module('portainer.docker').controller('NodeDetailsViewController', [
Id: node.Id, Id: node.Id,
Version: node.Version Version: node.Version
}; };
NodeService.updateNode(config) NodeService.updateNode(config)
.then(onUpdateSuccess) .then(onUpdateSuccess)
.catch(notifyOnError); .catch(notifyOnError);