xref: /openbmc/phosphor-webui/app/configuration/controllers/network-controller.js (revision 9a0094dc45518e73135b5b31a1eb1d5e5707ff6e)
1cd789508SIftekharul Islam/**
2cd789508SIftekharul Islam * Controller for network
3cd789508SIftekharul Islam *
4cd789508SIftekharul Islam * @module app/configuration
5cd789508SIftekharul Islam * @exports networkController
6cd789508SIftekharul Islam * @name networkController
7cd789508SIftekharul Islam */
8cd789508SIftekharul Islam
9cd789508SIftekharul Islamwindow.angular && (function(angular) {
10cd789508SIftekharul Islam  'use strict';
11cd789508SIftekharul Islam
12d27bb135SAndrew Geissler  angular.module('app.configuration').controller('networkController', [
13*9a0094dcSGunnar Mills    '$scope', '$window', 'APIUtils', 'dataService', '$route',
14*9a0094dcSGunnar Mills    function($scope, $window, APIUtils, dataService, $route) {
15cd789508SIftekharul Islam      $scope.dataService = dataService;
162a489554SIftekharul Islam      $scope.network = {};
172a489554SIftekharul Islam      $scope.interface = {};
182a489554SIftekharul Islam      $scope.networkDevice = false;
19ba5e3f34SAndrew Geissler      $scope.hostname = '';
207ddc7274SGunnar Mills      $scope.set_network_error = '';
217ddc7274SGunnar Mills      $scope.set_network_success = false;
227ddc7274SGunnar Mills      $scope.selectedInterface = '';
232a489554SIftekharul Islam
242a489554SIftekharul Islam      $scope.selectInterface = function(interfaceId) {
252a489554SIftekharul Islam        $scope.interface = $scope.network.interfaces[interfaceId];
262a489554SIftekharul Islam        $scope.selectedInterface = interfaceId;
272a489554SIftekharul Islam        $scope.networkDevice = false;
28ba5e3f34SAndrew Geissler      };
297ddc7274SGunnar Mills      $scope.setNetworkSettings = function() {
307ddc7274SGunnar Mills        $scope.set_network_error = '';
317ddc7274SGunnar Mills        $scope.set_network_success = false;
327ddc7274SGunnar Mills        // TODO openbmc/openbmc#3165: check if the network settings
337ddc7274SGunnar Mills        // changed before setting
347ddc7274SGunnar Mills        APIUtils
357ddc7274SGunnar Mills            .setMACAddress(
367ddc7274SGunnar Mills                $scope.selectedInterface, $scope.interface.MACAddress)
377ddc7274SGunnar Mills            .then(
387ddc7274SGunnar Mills                function(data) {
397ddc7274SGunnar Mills                  $scope.set_network_success = true;
407ddc7274SGunnar Mills                },
417ddc7274SGunnar Mills                function(error) {
427ddc7274SGunnar Mills                  console.log(error);
437ddc7274SGunnar Mills                  $scope.set_network_error = 'MAC Address';
447ddc7274SGunnar Mills                });
457ddc7274SGunnar Mills      };
46*9a0094dcSGunnar Mills      $scope.refresh = function() {
47*9a0094dcSGunnar Mills        $route.reload();
48*9a0094dcSGunnar Mills      };
492a489554SIftekharul Islam      APIUtils.getNetworkInfo().then(function(data) {
502a489554SIftekharul Islam        $scope.network = data.formatted_data;
512a489554SIftekharul Islam        $scope.hostname = data.hostname;
522a489554SIftekharul Islam        if ($scope.network.interface_ids.length) {
532a489554SIftekharul Islam          $scope.selectedInterface = $scope.network.interface_ids[0];
54d27bb135SAndrew Geissler          $scope.interface =
55d27bb135SAndrew Geissler              $scope.network.interfaces[$scope.selectedInterface];
562a489554SIftekharul Islam        }
572a489554SIftekharul Islam      });
58cd789508SIftekharul Islam    }
59ba5e3f34SAndrew Geissler  ]);
60cd789508SIftekharul Islam
61cd789508SIftekharul Islam})(angular);
62