/usr/share/maas/web/static/js/angular/controllers/node_result.js is in maas-region-api 2.4.0~beta2-6865-gec43e47e6-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | /* Copyright 2015-2018 Canonical Ltd. This software is licensed under the
* GNU Affero General Public License version 3 (see the file LICENSE).
*
* MAAS Script Result Controller
*/
angular.module('MAAS').controller('NodeResultController', [
'$scope', '$rootScope', '$routeParams', '$location',
'MachinesManager', 'ControllersManager', 'NodeResultsManagerFactory',
'ManagerHelperService', 'ErrorService',
function($scope, $rootScope, $routeParams, $location, MachinesManager,
ControllersManager, NodeResultsManagerFactory,
ManagerHelperService, ErrorService) {
// Set the title and page.
$rootScope.title = "Loading...";
// Initial values.
$scope.loaded = false;
$scope.resultLoaded = false;
$scope.node = null;
$scope.output = 'combined';
$scope.result = null;
$scope.get_result_data = function(output) {
$scope.output = output;
$scope.data = "Loading...";
var nodeResultsManager = NodeResultsManagerFactory.getManager(
$scope.node);
nodeResultsManager.get_result_data(
$scope.result.id, $scope.output).then(
function(data) {
if(data === '') {
$scope.data = "Empty file.";
}else{
$scope.data = data;
}
});
};
// Called once the node is loaded.
function nodeLoaded(node) {
$scope.node = node;
$scope.loaded = true;
// Get the NodeResultsManager and load it.
var nodeResultsManager = NodeResultsManagerFactory.getManager(
$scope.node);
var requestedResult = parseInt($routeParams.id, 10);
nodeResultsManager.getItem(requestedResult).then(function(result) {
$scope.result = result;
$scope.get_result_data($scope.output);
$scope.resultLoaded = true;
$rootScope.title = $scope.node.fqdn + " - " +
$scope.result.name;
});
}
// Update the title when the fqdn of the node changes.
$scope.$watch("node.fqdn", function() {
if(angular.isObject($scope.node) &&
angular.isObject($scope.result)) {
$rootScope.title = $scope.node.fqdn + " - " +
$scope.result.name;
}
});
if($location.path().indexOf("/controller") !== -1) {
$scope.nodesManager = ControllersManager;
$scope.type_name = 'controller';
$rootScope.page = 'controllers';
}else{
$scope.nodesManager = MachinesManager;
$scope.type_name = 'machine';
$rootScope.page = 'machines';
}
// Load nodes manager.
ManagerHelperService.loadManager(
$scope, $scope.nodesManager).then(function() {
// If redirected from the NodeDetailsController then the node
// will already be active. No need to set it active again.
var activeNode = $scope.nodesManager.getActiveItem();
if(angular.isObject(activeNode) &&
activeNode.system_id === $routeParams.system_id) {
nodeLoaded(activeNode);
} else {
$scope.nodesManager.setActiveItem(
$routeParams.system_id).then(function(node) {
nodeLoaded(node);
}, function(error) {
ErrorService.raiseError(error);
});
}
});
// Destroy the NodeResultsManager when the scope is destroyed. This is
// so the client will not recieve any more notifications about results
// from this node.
$scope.$on("$destroy", function() {
var nodeResultsManager = NodeResultsManagerFactory.getManager(
$scope.node);
if(angular.isObject(nodeResultsManager)) {
nodeResultsManager.destroy();
}
});
}]);
|