Add reload 4 seconds after network set success

Since an IPV4 interface (e.g. IP address, gateway, or netmask) edit
is a delete then an add and the GUI can't calculate the interface
id (e.g. 5c083707) beforehand and it is not returned by the REST
call, reload the page after an edit, which makes another REST call.

Do this for all network changes, instead of just IPV4 interface
edits due to the possibility of a set network failing even
though it returned success, openbmc/openbmc#1641.

This REST call also updates dataService and old_interface
which is used to know which data has changed if the user
continues to edit network settings.

The issue this is solving is the GUI deletes the old IPV4
interface (5c083707), creates a new one (4d9b1add), then
let's say the user modifies the IPV4 interface again without
a refresh, the GUI doesn't know what old IPV4 interface to
delete (i.e. the GUI doesn't know to delete 4d9b1add).

Choose 4 seconds to give the network manager time to set
the network.

Tested: Did the above scenario.
Change-Id: I36cb438b12eb6540dc74f235f8f134df67e60389
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
diff --git a/app/configuration/controllers/network-controller.js b/app/configuration/controllers/network-controller.js
index cc803d7..6ebbf4f 100644
--- a/app/configuration/controllers/network-controller.js
+++ b/app/configuration/controllers/network-controller.js
@@ -10,8 +10,8 @@
   'use strict';
 
   angular.module('app.configuration').controller('networkController', [
-    '$scope', '$window', 'APIUtils', 'dataService', '$route', '$q',
-    function($scope, $window, APIUtils, dataService, $route, $q) {
+    '$scope', '$window', 'APIUtils', 'dataService', '$timeout', '$route', '$q',
+    function($scope, $window, APIUtils, dataService, $timeout, $route, $q) {
       $scope.dataService = dataService;
       $scope.network = {};
       $scope.old_interface = {};
@@ -69,14 +69,30 @@
           }
         }
 
-        $q.all(promises).finally(function() {
+        if (promises.length) {
+          $q.all(promises).finally(function() {
+            $scope.loading = false;
+            if (!$scope.set_network_error) {
+              $scope.set_network_success = true;
+              // Since an IPV4 interface (e.g. IP address, gateway, or netmask)
+              // edit is a delete then an add and the GUI can't calculate the
+              // interface id (e.g. 5c083707) beforehand and it is not returned
+              // by the REST call, openbmc#3227, reload the page after an edit,
+              // which makes a 2nd REST call.
+              // Do this for all network changes due to the possibility of a set
+              // network failing even though it returned success, openbmc#1641,
+              // and to update dataService and old_interface to know which
+              // data has changed if the user continues to edit network
+              // settings.
+              // TODO: The reload is not ideal. Revisit this.
+              $timeout(function() {
+                $route.reload();
+              }, 4000);
+            }
+          });
+        } else {
           $scope.loading = false;
-          // $q.all with an empty array resolves immediately but don't show
-          // the success message
-          if (!$scope.set_network_error && promises.length) {
-            $scope.set_network_success = true;
-          }
-        });
+        }
 
       };