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', [ |
Gunnar Mills | 9a0094d | 2018-05-02 21:50:56 -0500 | [diff] [blame] | 13 | '$scope', '$window', 'APIUtils', 'dataService', '$route', |
| 14 | function($scope, $window, APIUtils, dataService, $route) { |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 15 | $scope.dataService = dataService; |
| 16 | $scope.network = {}; |
| 17 | $scope.interface = {}; |
| 18 | $scope.networkDevice = false; |
| 19 | $scope.hostname = ''; |
Gunnar Mills | e9f5fe7 | 2018-05-04 13:43:10 -0500 | [diff] [blame^] | 20 | $scope.defaultgateway = ''; |
Gunnar Mills | 7ddc727 | 2018-04-12 16:12:03 -0500 | [diff] [blame] | 21 | $scope.set_network_error = ''; |
| 22 | $scope.set_network_success = false; |
| 23 | $scope.selectedInterface = ''; |
Gunnar Mills | d01504c | 2018-05-03 13:01:51 -0500 | [diff] [blame] | 24 | $scope.confirm_settings = false; |
Iftekharul Islam | 2a48955 | 2017-11-02 13:23:08 -0500 | [diff] [blame] | 25 | |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 26 | $scope.selectInterface = function(interfaceId) { |
| 27 | $scope.interface = $scope.network.interfaces[interfaceId]; |
| 28 | $scope.selectedInterface = interfaceId; |
| 29 | $scope.networkDevice = false; |
| 30 | }; |
Gunnar Mills | 7ddc727 | 2018-04-12 16:12:03 -0500 | [diff] [blame] | 31 | $scope.setNetworkSettings = function() { |
Gunnar Mills | d01504c | 2018-05-03 13:01:51 -0500 | [diff] [blame] | 32 | // Hides the confirm network settings modal |
| 33 | $scope.confirm_settings = false; |
Gunnar Mills | 7ddc727 | 2018-04-12 16:12:03 -0500 | [diff] [blame] | 34 | $scope.set_network_error = ''; |
| 35 | $scope.set_network_success = false; |
| 36 | // TODO openbmc/openbmc#3165: check if the network settings |
| 37 | // changed before setting |
| 38 | APIUtils |
| 39 | .setMACAddress( |
| 40 | $scope.selectedInterface, $scope.interface.MACAddress) |
| 41 | .then( |
| 42 | function(data) { |
| 43 | $scope.set_network_success = true; |
| 44 | }, |
| 45 | function(error) { |
| 46 | console.log(error); |
| 47 | $scope.set_network_error = 'MAC Address'; |
| 48 | }); |
| 49 | }; |
Gunnar Mills | 9a0094d | 2018-05-02 21:50:56 -0500 | [diff] [blame] | 50 | $scope.refresh = function() { |
| 51 | $route.reload(); |
| 52 | }; |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 53 | APIUtils.getNetworkInfo().then(function(data) { |
| 54 | $scope.network = data.formatted_data; |
| 55 | $scope.hostname = data.hostname; |
Gunnar Mills | e9f5fe7 | 2018-05-04 13:43:10 -0500 | [diff] [blame^] | 56 | $scope.defaultgateway = data.defaultgateway; |
Andrew Geissler | d27bb13 | 2018-05-24 11:07:27 -0700 | [diff] [blame] | 57 | if ($scope.network.interface_ids.length) { |
| 58 | $scope.selectedInterface = $scope.network.interface_ids[0]; |
| 59 | $scope.interface = |
| 60 | $scope.network.interfaces[$scope.selectedInterface]; |
| 61 | } |
| 62 | }); |
| 63 | } |
| 64 | ]); |
Iftekharul Islam | cd78950 | 2017-04-19 14:37:55 -0500 | [diff] [blame] | 65 | |
| 66 | })(angular); |