Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 1 | /** |
| 2 | * Controller for network |
| 3 | * |
| 4 | * @module app/configuration |
| 5 | * @exports networkController |
| 6 | * @name networkController |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 7 | */ |
| 8 | |
Andrew Geissler | ba5e3f3 | 2018-05-24 10:58:00 -0700 | [diff] [blame] | 9 | window.angular && (function(angular) { |
| 10 | 'use strict'; |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 11 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 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 = ''; |
Gunnar Mills | 7ddc727 | 2018-04-12 16:12:03 -0500 | [diff] [blame^] | 20 | $scope.set_network_error = ''; |
| 21 | $scope.set_network_success = false; |
| 22 | $scope.selectedInterface = ''; |
Iftekharul Islam | 2a48955 | 2017-11-02 13:23:08 -0500 | [diff] [blame] | 23 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 24 | $scope.selectInterface = function(interfaceId) { |
| 25 | $scope.interface = $scope.network.interfaces[interfaceId]; |
| 26 | $scope.selectedInterface = interfaceId; |
| 27 | $scope.networkDevice = false; |
| 28 | }; |
Gunnar Mills | 7ddc727 | 2018-04-12 16:12:03 -0500 | [diff] [blame^] | 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 | }; |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 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 | ]); |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 57 | |
| 58 | })(angular); |