xref: /openbmc/phosphor-webui/app/configuration/controllers/network-controller.js (revision d27bb135f1561b87a174d1b9890dde2f3cf01c80)
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
12*d27bb135SAndrew Geissler  angular.module('app.configuration').controller('networkController', [
13*d27bb135SAndrew Geissler    '$scope', '$window', 'APIUtils', 'dataService',
14cd789508SIftekharul Islam    function($scope, $window, APIUtils, dataService) {
15cd789508SIftekharul Islam      $scope.dataService = dataService;
162a489554SIftekharul Islam      $scope.network = {};
172a489554SIftekharul Islam      $scope.interface = {};
182a489554SIftekharul Islam      $scope.networkDevice = false;
19ba5e3f34SAndrew Geissler      $scope.hostname = '';
202a489554SIftekharul Islam
212a489554SIftekharul Islam      $scope.selectInterface = function(interfaceId) {
222a489554SIftekharul Islam        $scope.interface = $scope.network.interfaces[interfaceId];
232a489554SIftekharul Islam        $scope.selectedInterface = interfaceId;
242a489554SIftekharul Islam        $scope.networkDevice = false;
25ba5e3f34SAndrew Geissler      };
262a489554SIftekharul Islam      APIUtils.getNetworkInfo().then(function(data) {
272a489554SIftekharul Islam        $scope.network = data.formatted_data;
282a489554SIftekharul Islam        $scope.hostname = data.hostname;
292a489554SIftekharul Islam        if ($scope.network.interface_ids.length) {
302a489554SIftekharul Islam          $scope.selectedInterface = $scope.network.interface_ids[0];
31*d27bb135SAndrew Geissler          $scope.interface =
32*d27bb135SAndrew Geissler              $scope.network.interfaces[$scope.selectedInterface];
332a489554SIftekharul Islam        }
342a489554SIftekharul Islam      });
35cd789508SIftekharul Islam    }
36ba5e3f34SAndrew Geissler  ]);
37cd789508SIftekharul Islam
38cd789508SIftekharul Islam})(angular);
39