changeset 199:0767a8183508

Extract system-network into component Reviewed-by: jkang Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-September/024945.html
author Andrew Azores <aazores@redhat.com>
date Mon, 11 Sep 2017 11:26:31 -0400
parents 90e9e14c8a29
children 42e34f861a44
files src/app/components/system-info/en.locale.yaml src/app/components/system-info/system-info.controller.js src/app/components/system-info/system-info.controller.spec.js src/app/components/system-info/system-info.html src/app/components/system-info/system-info.module.js src/app/components/system-info/system-info.service.js src/app/components/system-info/system-info.service.spec.js src/app/components/system-info/system-network/en.locale.yaml src/app/components/system-info/system-network/system-network.component.js src/app/components/system-info/system-network/system-network.controller.js src/app/components/system-info/system-network/system-network.controller.spec.js src/app/components/system-info/system-network/system-network.html src/app/components/system-info/system-network/system-network.service.js src/app/components/system-info/system-network/system-network.service.spec.js
diffstat 14 files changed, 335 insertions(+), 96 deletions(-) [+]
line wrap: on
line diff
--- a/src/app/components/system-info/en.locale.yaml	Wed Sep 13 10:17:03 2017 -0400
+++ b/src/app/components/system-info/en.locale.yaml	Mon Sep 11 11:26:31 2017 -0400
@@ -18,10 +18,6 @@
 
   networkTable:
     HEADER: Network Interfaces
-    DISPLAY_NAME_COLUMN_LABEL: Display Name
-    INTERFACE_NAME_COLUMN_LABEL: Interface Name
-    IPV4_COLUMN_LABEL: IPv4 Address
-    IPV6_COLUMN_LABEL: IPv6 Address
 
   refresh:
     DISABLED: Disabled
--- a/src/app/components/system-info/system-info.controller.js	Wed Sep 13 10:17:03 2017 -0400
+++ b/src/app/components/system-info/system-info.controller.js	Mon Sep 11 11:26:31 2017 -0400
@@ -47,16 +47,6 @@
         this.showErr = true;
       }
     );
-
-    systemInfoService.getNetworkInfo(systemId).then(
-      resp => {
-        this.networkInfo = resp.data.response[0];
-        this.showErr = false;
-      },
-      () => {
-        this.showErr = true;
-      }
-    );
   }
 }
 
--- a/src/app/components/system-info/system-info.controller.spec.js	Wed Sep 13 10:17:03 2017 -0400
+++ b/src/app/components/system-info/system-info.controller.spec.js	Mon Sep 11 11:26:31 2017 -0400
@@ -29,21 +29,17 @@
 
   beforeEach(angular.mock.module('systemInfo.controller'));
 
-  let ctrl, scope, interval, infoPromise, networkPromise, translate;
+  let ctrl, scope, interval, infoPromise, translate;
   beforeEach(inject(($q, $rootScope, $controller) => {
     'ngInject';
     scope = $rootScope;
     infoPromise = $q.defer();
-    networkPromise = $q.defer();
     interval = sinon.spy();
     translate = sinon.stub().returns({
       then: sinon.stub().yields()
     });
 
-    let systemInfoService = {
-      getSystemInfo: () => infoPromise.promise,
-      getNetworkInfo: () => networkPromise.promise
-    };
+    let systemInfoService = { getSystemInfo: () => infoPromise.promise };
     ctrl = $controller('SystemInfoController', {
       systemId: 'foo-systemId',
       systemInfoService: systemInfoService,
@@ -84,33 +80,4 @@
     });
   });
 
-  describe('networkInfo', () => {
-    it('should set networkInfo when service resolves', done => {
-      let response = {
-        interfaceName: 'lo',
-        displayName: 'lo',
-        ip4Addr: '192.168.1.2',
-        ip6Addr: '0:0:0:0:0:0:1%lo'
-      };
-      networkPromise.resolve({
-        data: {
-          response: [response]
-        }
-      });
-      scope.$apply();
-      ctrl.should.have.ownProperty('networkInfo');
-      ctrl.networkInfo.should.deepEqual(response);
-      ctrl.showErr.should.equal(false);
-      done();
-    });
-
-    it('should set error flag when service rejects', done => {
-      networkPromise.reject();
-      scope.$apply();
-      ctrl.should.have.ownProperty('showErr');
-      ctrl.showErr.should.equal(true);
-      done();
-    });
-  });
-
 });
--- a/src/app/components/system-info/system-info.html	Wed Sep 13 10:17:03 2017 -0400
+++ b/src/app/components/system-info/system-info.html	Mon Sep 11 11:26:31 2017 -0400
@@ -57,24 +57,7 @@
               </h4>
             </div>
             <div id="collapseTwo" class="panel-collapse collapse">
-              <table class="table table-fixed table-striped table-bordered">
-                <thead>
-                  <tr>
-                    <th translate>systemInfo.networkTable.DISPLAY_NAME_COLUMN_LABEL</th>
-                    <th translate>systemInfo.networkTable.INTERFACE_NAME_COLUMN_LABEL</th>
-                    <th translate>systemInfo.networkTable.IPV4_COLUMN_LABEL</th>
-                    <th translate>systemInfo.networkTable.IPV6_COLUMN_LABEL</th>
-                  </tr>
-                </thead>
-                <tbody class="break-word-wrap">
-                  <tr ng-repeat="iface in ctrl.networkInfo.interfaces">
-                    <td>{{iface.displayName}}</td>
-                    <td>{{iface.interfaceName}}</td>
-                    <td>{{iface.ip4Addr}}</td>
-                    <td>{{iface.ip6Addr}}</td>
-                  </tr>
-                </tbody>
-              </table>
+              <system-network system-id="ctrl.systemId"></system-network>
             </div>
           </div>
         </div>
--- a/src/app/components/system-info/system-info.module.js	Wed Sep 13 10:17:03 2017 -0400
+++ b/src/app/components/system-info/system-info.module.js	Mon Sep 11 11:26:31 2017 -0400
@@ -28,6 +28,7 @@
 import SystemInfocontroller from './system-info.controller.js';
 import systemCpu from './system-cpu/system-cpu.component.js';
 import SystemMemoryController from './system-memory.controller.js';
+import systemNetwork from './system-network/system-network.component.js';
 import service from './system-info.service.js';
 import components from 'shared/components/components.module.js';
 
@@ -36,6 +37,7 @@
     SystemInfocontroller,
     systemCpu,
     SystemMemoryController,
+    systemNetwork,
     service,
     components
   ])
--- a/src/app/components/system-info/system-info.service.js	Wed Sep 13 10:17:03 2017 -0400
+++ b/src/app/components/system-info/system-info.service.js	Mon Sep 11 11:26:31 2017 -0400
@@ -52,15 +52,6 @@
       }
     });
   }
-
-  getNetworkInfo (systemId) {
-    return this.http.get(urlJoin(this.gatewayUrl, 'system-network', '0.0.1', 'systems', systemId), {
-      params: {
-        sort: '-timeStamp',
-        limit: 1
-      }
-    });
-  }
 }
 
 export default angular
--- a/src/app/components/system-info/system-info.service.spec.js	Wed Sep 13 10:17:03 2017 -0400
+++ b/src/app/components/system-info/system-info.service.spec.js	Mon Sep 11 11:26:31 2017 -0400
@@ -90,24 +90,4 @@
     });
   });
 
-  describe('getNetworkInfo(systemId)', () => {
-    it('should resolve mock data', done => {
-      let expected = {
-        interfaceName: 'lo',
-        displayName: 'lo',
-        ip4Addr: '192.168.1.2',
-        ip6Addr: '0:0:0:0:0:0:1%lo'
-      };
-      httpBackend.when('GET', 'http://example.com:1234/system-network/0.0.1/systems/foo-systemId?limit=1&sort=-timeStamp')
-        .respond(expected);
-      svc.getNetworkInfo('foo-systemId').then(res => {
-        res.data.should.deepEqual(expected);
-        done();
-      });
-      httpBackend.expectGET('http://example.com:1234/system-network/0.0.1/systems/foo-systemId?limit=1&sort=-timeStamp');
-      httpBackend.flush();
-      scope.$apply();
-    });
-  });
-
 });
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/app/components/system-info/system-network/en.locale.yaml	Mon Sep 11 11:26:31 2017 -0400
@@ -0,0 +1,5 @@
+systemNetwork:
+  DISPLAY_NAME_COLUMN_LABEL: Display Name
+  INTERFACE_NAME_COLUMN_LABEL: Interface Name
+  IPV4_COLUMN_LABEL: IPv4 Address
+  IPV6_COLUMN_LABEL: IPv6 Address
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/app/components/system-info/system-network/system-network.component.js	Mon Sep 11 11:26:31 2017 -0400
@@ -0,0 +1,43 @@
+/**
+ * Copyright 2012-2017 Red Hat, Inc.
+ *
+ * Thermostat is distributed under the GNU General Public License,
+ * version 2 or any later version (with a special exception described
+ * below, commonly known as the "Classpath Exception").
+ *
+ * A copy of GNU General Public License (GPL) is included in this
+ * distribution, in the file COPYING.
+ *
+ * Linking Thermostat code with other modules is making a combined work
+ * based on Thermostat.  Thus, the terms and conditions of the GPL
+ * cover the whole combination.
+ *
+ * As a special exception, the copyright holders of Thermostat give you
+ * permission to link this code with independent modules to produce an
+ * executable, regardless of the license terms of these independent
+ * modules, and to copy and distribute the resulting executable under
+ * terms of your choice, provided that you also meet, for each linked
+ * independent module, the terms and conditions of the license of that
+ * module.  An independent module is a module which is not derived from
+ * or based on Thermostat code.  If you modify Thermostat, you may
+ * extend this exception to your version of the software, but you are
+ * not obligated to do so.  If you do not wish to do so, delete this
+ * exception statement from your version.
+ */
+
+import controller from './system-network.controller.js';
+import service from './system-network.service.js';
+
+export default angular
+  .module('systemNetwork.component', [
+    controller,
+    service
+  ])
+  .component('systemNetwork', {
+    bindings: {
+      systemId: '<'
+    },
+    controller: 'SystemNetworkController',
+    template: require('./system-network.html')
+  })
+  .name;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/app/components/system-info/system-network/system-network.controller.js	Mon Sep 11 11:26:31 2017 -0400
@@ -0,0 +1,51 @@
+/**
+ * Copyright 2012-2017 Red Hat, Inc.
+ *
+ * Thermostat is distributed under the GNU General Public License,
+ * version 2 or any later version (with a special exception described
+ * below, commonly known as the "Classpath Exception").
+ *
+ * A copy of GNU General Public License (GPL) is included in this
+ * distribution, in the file COPYING.
+ *
+ * Linking Thermostat code with other modules is making a combined work
+ * based on Thermostat.  Thus, the terms and conditions of the GPL
+ * cover the whole combination.
+ *
+ * As a special exception, the copyright holders of Thermostat give you
+ * permission to link this code with independent modules to produce an
+ * executable, regardless of the license terms of these independent
+ * modules, and to copy and distribute the resulting executable under
+ * terms of your choice, provided that you also meet, for each linked
+ * independent module, the terms and conditions of the license of that
+ * module.  An independent module is a module which is not derived from
+ * or based on Thermostat code.  If you modify Thermostat, you may
+ * extend this exception to your version of the software, but you are
+ * not obligated to do so.  If you do not wish to do so, delete this
+ * exception statement from your version.
+ */
+
+import service from './system-network.service.js';
+
+class SystemNetworkController {
+  constructor (systemNetworkService) {
+    'ngInject';
+    this._svc = systemNetworkService;
+  }
+
+  $onInit () {
+    this._svc.getNetworkInfo(this.systemId).then(
+      resp => {
+        this.networkInfo = resp.data.response[0];
+      }
+    );
+  }
+}
+
+export default angular
+  .module('systemNetwork.controller', [
+    'patternfly',
+    service
+  ])
+  .controller('SystemNetworkController', SystemNetworkController)
+  .name;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/app/components/system-info/system-network/system-network.controller.spec.js	Mon Sep 11 11:26:31 2017 -0400
@@ -0,0 +1,80 @@
+/**
+ * Copyright 2012-2017 Red Hat, Inc.
+ *
+ * Thermostat is distributed under the GNU General Public License,
+ * version 2 or any later version (with a special exception described
+ * below, commonly known as the "Classpath Exception").
+ *
+ * A copy of GNU General Public License (GPL) is included in this
+ * distribution, in the file COPYING.
+ *
+ * Linking Thermostat code with other modules is making a combined work
+ * based on Thermostat.  Thus, the terms and conditions of the GPL
+ * cover the whole combination.
+ *
+ * As a special exception, the copyright holders of Thermostat give you
+ * permission to link this code with independent modules to produce an
+ * executable, regardless of the license terms of these independent
+ * modules, and to copy and distribute the resulting executable under
+ * terms of your choice, provided that you also meet, for each linked
+ * independent module, the terms and conditions of the license of that
+ * module.  An independent module is a module which is not derived from
+ * or based on Thermostat code.  If you modify Thermostat, you may
+ * extend this exception to your version of the software, but you are
+ * not obligated to do so.  If you do not wish to do so, delete this
+ * exception statement from your version.
+ */
+
+import controllerModule from './system-network.controller.js';
+
+describe('SystemNetworkController', () => {
+
+  beforeEach(angular.mock.module(controllerModule));
+
+  let ctrl, svc;
+  beforeEach(inject(($controller) => {
+    'ngInject';
+    let promise = sinon.spy();
+    svc = {
+      getNetworkInfo: sinon.stub().returns({
+        then: promise
+      }),
+      promise: promise
+    };
+    ctrl = $controller('SystemNetworkController', { systemNetworkService: svc });
+    ctrl.systemId = 'foo-systemId';
+  }));
+
+  it('should exist', () => {
+    should.exist(ctrl);
+  });
+
+  describe('networkInfo', () => {
+    it('should be called on init', () => {
+      svc.getNetworkInfo.should.not.be.called();
+      ctrl.$onInit();
+      svc.getNetworkInfo.should.be.calledOnce();
+    });
+
+    it('should set networkInfo when service resolves', () => {
+      let response = {
+        interfaceName: 'lo',
+        displayName: 'lo',
+        ip4Addr: '192.168.1.2',
+        ip6Addr: '0:0:0:0:0:0:1%lo'
+      };
+      svc.promise.should.not.be.called();
+      ctrl.$onInit();
+      svc.promise.should.be.calledOnce();
+      svc.promise.should.be.calledWith(sinon.match.func);
+      svc.promise.args[0][0]({
+        data: {
+          response: [response]
+        }
+      });
+      ctrl.should.have.ownProperty('networkInfo');
+      ctrl.networkInfo.should.deepEqual(response);
+    });
+  });
+
+});
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/app/components/system-info/system-network/system-network.html	Mon Sep 11 11:26:31 2017 -0400
@@ -0,0 +1,19 @@
+<table class="table table-fixed table-striped table-bordered">
+  <thead>
+    <tr>
+      <th translate>systemNetwork.DISPLAY_NAME_COLUMN_LABEL</th>
+      <th translate>systemNetwork.INTERFACE_NAME_COLUMN_LABEL</th>
+      <th translate>systemNetwork.IPV4_COLUMN_LABEL</th>
+      <th translate>systemNetwork.IPV6_COLUMN_LABEL</th>
+    </tr>
+  </thead>
+  <tbody class="break-word-wrap">
+    <tr ng-repeat="iface in $ctrl.networkInfo.interfaces">
+      <td>{{iface.displayName}}</td>
+      <td>{{iface.interfaceName}}</td>
+      <td>{{iface.ip4Addr}}</td>
+      <td>{{iface.ip6Addr}}</td>
+    </tr>
+  </tbody>
+</table>
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/app/components/system-info/system-network/system-network.service.js	Mon Sep 11 11:26:31 2017 -0400
@@ -0,0 +1,52 @@
+/**
+ * Copyright 2012-2017 Red Hat, Inc.
+ *
+ * Thermostat is distributed under the GNU General Public License,
+ * version 2 or any later version (with a special exception described
+ * below, commonly known as the "Classpath Exception").
+ *
+ * A copy of GNU General Public License (GPL) is included in this
+ * distribution, in the file COPYING.
+ *
+ * Linking Thermostat code with other modules is making a combined work
+ * based on Thermostat.  Thus, the terms and conditions of the GPL
+ * cover the whole combination.
+ *
+ * As a special exception, the copyright holders of Thermostat give you
+ * permission to link this code with independent modules to produce an
+ * executable, regardless of the license terms of these independent
+ * modules, and to copy and distribute the resulting executable under
+ * terms of your choice, provided that you also meet, for each linked
+ * independent module, the terms and conditions of the license of that
+ * module.  An independent module is a module which is not derived from
+ * or based on Thermostat code.  If you modify Thermostat, you may
+ * extend this exception to your version of the software, but you are
+ * not obligated to do so.  If you do not wish to do so, delete this
+ * exception statement from your version.
+ */
+
+import config from 'shared/config/config.module.js';
+import urlJoin from 'url-join';
+
+class SystemNetworkService {
+  constructor ($q, $http, gatewayUrl) {
+    'ngInject';
+    this.q = $q;
+    this.http = $http;
+    this.gatewayUrl = gatewayUrl;
+  }
+
+  getNetworkInfo (systemId) {
+    return this.http.get(urlJoin(this.gatewayUrl, 'system-network', '0.0.1', 'systems', systemId), {
+      params: {
+        sort: '-timeStamp',
+        limit: 1
+      }
+    });
+  }
+}
+
+export default angular
+  .module('systemNetwork.service', [config])
+  .service('systemNetworkService', SystemNetworkService)
+  .name;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/app/components/system-info/system-network/system-network.service.spec.js	Mon Sep 11 11:26:31 2017 -0400
@@ -0,0 +1,80 @@
+/**
+ * Copyright 2012-2017 Red Hat, Inc.
+ *
+ * Thermostat is distributed under the GNU General Public License,
+ * version 2 or any later version (with a special exception described
+ * below, commonly known as the "Classpath Exception").
+ *
+ * A copy of GNU General Public License (GPL) is included in this
+ * distribution, in the file COPYING.
+ *
+ * Linking Thermostat code with other modules is making a combined work
+ * based on Thermostat.  Thus, the terms and conditions of the GPL
+ * cover the whole combination.
+ *
+ * As a special exception, the copyright holders of Thermostat give you
+ * permission to link this code with independent modules to produce an
+ * executable, regardless of the license terms of these independent
+ * modules, and to copy and distribute the resulting executable under
+ * terms of your choice, provided that you also meet, for each linked
+ * independent module, the terms and conditions of the license of that
+ * module.  An independent module is a module which is not derived from
+ * or based on Thermostat code.  If you modify Thermostat, you may
+ * extend this exception to your version of the software, but you are
+ * not obligated to do so.  If you do not wish to do so, delete this
+ * exception statement from your version.
+ */
+
+import configModule from 'shared/config/config.module.js';
+import serviceModule from './system-network.service.js';
+
+describe('SystemNetworkService', () => {
+
+  beforeEach(() => {
+    angular.mock.module(configModule, $provide => {
+      'ngInject';
+      $provide.constant('gatewayUrl', 'http://example.com:1234');
+    });
+
+    angular.mock.module(serviceModule);
+  });
+
+  let httpBackend, scope, svc;
+  beforeEach(inject(($httpBackend, $rootScope, systemNetworkService) => {
+    'ngInject';
+    httpBackend = $httpBackend;
+
+    scope = $rootScope;
+    svc = systemNetworkService;
+  }));
+
+  afterEach(() => {
+    httpBackend.verifyNoOutstandingExpectation();
+    httpBackend.verifyNoOutstandingRequest();
+  });
+
+  it('should exist', () => {
+    should.exist(svc);
+  });
+
+  describe('getNetworkInfo(systemId)', () => {
+    it('should resolve mock data', done => {
+      let expected = {
+        interfaceName: 'lo',
+        displayName: 'lo',
+        ip4Addr: '192.168.1.2',
+        ip6Addr: '0:0:0:0:0:0:1%lo'
+      };
+      httpBackend.when('GET', 'http://example.com:1234/system-network/0.0.1/systems/foo-systemId?limit=1&sort=-timeStamp')
+        .respond(expected);
+      svc.getNetworkInfo('foo-systemId').then(res => {
+        res.data.should.deepEqual(expected);
+        done();
+      });
+      httpBackend.expectGET('http://example.com:1234/system-network/0.0.1/systems/foo-systemId?limit=1&sort=-timeStamp');
+      httpBackend.flush();
+      scope.$apply();
+    });
+  });
+
+});