1/** 2 * Controller for network 3 * 4 * @module app/configuration 5 * @exports networkController 6 * @name networkController 7 */ 8 9window.angular && (function(angular) { 10 'use strict'; 11 12 angular.module('app.configuration').controller('networkController', [ 13 '$scope', '$window', 'APIUtils', 'dataService', 14 function($scope, $window, APIUtils, dataService) { 15 $scope.dataService = dataService; 16 $scope.network = {}; 17 $scope.interface = {}; 18 $scope.networkDevice = false; 19 $scope.hostname = ''; 20 $scope.set_network_error = ''; 21 $scope.set_network_success = false; 22 $scope.selectedInterface = ''; 23 24 $scope.selectInterface = function(interfaceId) { 25 $scope.interface = $scope.network.interfaces[interfaceId]; 26 $scope.selectedInterface = interfaceId; 27 $scope.networkDevice = false; 28 }; 29 $scope.setNetworkSettings = function() { 30 $scope.set_network_error = ''; 31 $scope.set_network_success = false; 32 // TODO openbmc/openbmc#3165: check if the network settings 33 // changed before setting 34 APIUtils 35 .setMACAddress( 36 $scope.selectedInterface, $scope.interface.MACAddress) 37 .then( 38 function(data) { 39 $scope.set_network_success = true; 40 }, 41 function(error) { 42 console.log(error); 43 $scope.set_network_error = 'MAC Address'; 44 }); 45 }; 46 APIUtils.getNetworkInfo().then(function(data) { 47 $scope.network = data.formatted_data; 48 $scope.hostname = data.hostname; 49 if ($scope.network.interface_ids.length) { 50 $scope.selectedInterface = $scope.network.interface_ids[0]; 51 $scope.interface = 52 $scope.network.interfaces[$scope.selectedInterface]; 53 } 54 }); 55 } 56 ]); 57 58})(angular); 59