changeset 203:55b433cf6922

Convert system-info to component Reviewed-by: jkang Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-September/024965.html
author Andrew Azores <aazores@redhat.com>
date Tue, 12 Sep 2017 10:27:01 -0400
parents 70ac564886ab
children cb5eb207b5cc
files src/app/components/system-info/system-info.component.js 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.routing.js src/app/components/system-info/system-info.routing.spec.js
diffstat 7 files changed, 88 insertions(+), 111 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/app/components/system-info/system-info.component.js	Tue Sep 12 10:27:01 2017 -0400
@@ -0,0 +1,48 @@
+/**
+ * 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 systemCpu from './system-cpu/system-cpu.component.js';
+import systemMemory from './system-memory/system-memory.component.js';
+import systemNetwork from './system-network/system-network.component.js';
+import controller from './system-info.controller.js';
+import service from './system-info.service.js';
+import components from 'shared/components/components.module.js';
+
+export default angular
+  .module('systemInfo.component', [
+    systemCpu,
+    systemMemory,
+    systemNetwork,
+    controller,
+    service,
+    components
+  ])
+  .component('systemInfo', {
+    controller: 'SystemInfoController',
+    template: require('./system-info.html')
+  })
+  .name;
--- a/src/app/components/system-info/system-info.controller.js	Thu Sep 14 15:23:46 2017 -0400
+++ b/src/app/components/system-info/system-info.controller.js	Tue Sep 12 10:27:01 2017 -0400
@@ -29,16 +29,20 @@
 import service from './system-info.service.js';
 
 class SystemInfoController {
-  constructor (systemId, systemInfoService, $interval, $scope, $translate) {
+  constructor ($stateParams, systemInfoService, $interval, $translate) {
     'ngInject';
-    this.systemId = systemId;
+    this.systemId = $stateParams.systemId;
     this.showErr = false;
+    this._svc = systemInfoService;
+    this._interval = $interval;
+    this._translate = $translate;
+  }
 
-    $scope.systemId = systemId;
-    $translate('systemInfo.ERR_TITLE').then(s => $scope.errTitle = s);
-    $translate('systemInfo.ERR_MESSAGE').then(s => $scope.errMessage = s);
+  $onInit () {
+    this._translate('systemInfo.ERR_TITLE').then(s => this.errTitle = s);
+    this._translate('systemInfo.ERR_MESSAGE').then(s => this.errMessage = s);
 
-    systemInfoService.getSystemInfo(systemId).then(
+    this._svc.getSystemInfo(this.systemId).then(
       resp => {
         this.systemInfo = resp.data.response[0];
         this.showErr = false;
--- a/src/app/components/system-info/system-info.controller.spec.js	Thu Sep 14 15:23:46 2017 -0400
+++ b/src/app/components/system-info/system-info.controller.spec.js	Tue Sep 12 10:27:01 2017 -0400
@@ -25,14 +25,16 @@
  * exception statement from your version.
  */
 
+import controllerModule from './system-info.controller.js';
+
 describe('SystemInfoController', () => {
 
-  beforeEach(angular.mock.module('systemInfo.controller'));
+  beforeEach(angular.mock.module(controllerModule));
 
-  let ctrl, scope, interval, infoPromise, translate;
+  let ctrl, rootScope, interval, infoPromise, translate;
   beforeEach(inject(($q, $rootScope, $controller) => {
     'ngInject';
-    scope = $rootScope;
+    rootScope = $rootScope;
     infoPromise = $q.defer();
     interval = sinon.spy();
     translate = sinon.stub().returns({
@@ -43,7 +45,6 @@
     ctrl = $controller('SystemInfoController', {
       systemId: 'foo-systemId',
       systemInfoService: systemInfoService,
-      $scope: scope,
       $interval: interval,
       $translate: translate
     });
@@ -54,6 +55,10 @@
   });
 
   describe('systemInfo', () => {
+    beforeEach(() => {
+      ctrl.$onInit();
+    });
+
     it('should set systemInfo when service resolves', done => {
       let response = {
         osName: 'Linux',
@@ -64,7 +69,7 @@
           response: [response]
         }
       });
-      scope.$apply();
+      rootScope.$apply();
       ctrl.should.have.ownProperty('systemInfo');
       ctrl.systemInfo.should.deepEqual(response);
       ctrl.showErr.should.equal(false);
@@ -73,7 +78,7 @@
 
     it('should set error flag when service rejects', done => {
       infoPromise.reject();
-      scope.$apply();
+      rootScope.$apply();
       ctrl.should.have.ownProperty('showErr');
       ctrl.showErr.should.equal(true);
       done();
--- a/src/app/components/system-info/system-info.html	Thu Sep 14 15:23:46 2017 -0400
+++ b/src/app/components/system-info/system-info.html	Tue Sep 12 10:27:01 2017 -0400
@@ -1,13 +1,13 @@
 <div class="container-fluid container-cards-pf">
   <ol class="breadcrumb" style="margin-bottom: 0px;">
     <li><a ui-sref="landing">Thermostat</a></li>
-    <li><a ui-sref="jvmList({ '#': ctrl.systemId })" translate>systemInfo.JVM_LIST_BREADCRUMB</a></li>
-    <li><a ui-sref="systemInfo({ systemId: ctrl.systemId })">{{ctrl.systemInfo.hostname || ctrl.systemId}}</a></li>
+    <li><a ui-sref="jvmList({ '#': $ctrl.systemId })" translate>systemInfo.JVM_LIST_BREADCRUMB</a></li>
+    <li><a ui-sref="systemInfo({ systemId: $ctrl.systemId })">{{$ctrl.systemInfo.hostname || $ctrl.systemId}}</a></li>
   </ol>
 
-  <customizable-error-message ng-show="ctrl.showErr" dismissible="true" err-message="errMessage" err-title="errTitle"></customizable-error-message>
+  <customizable-error-message ng-show="$ctrl.showErr" dismissible="true" err-message="errMessage" err-title="errTitle"></customizable-error-message>
 
-  <div ng-show="!ctrl.showErr">
+  <div ng-show="!$ctrl.showErr">
     <div class="row">
       <div class="col-xs-12 col-lg-12">
         <div class="panel-group" id="accordion-markup">
@@ -28,23 +28,23 @@
                 <tbody class="break-word-wrap">
                   <tr>
                     <td translate>systemInfo.infoTable.HOSTNAME</td>
-                    <td>{{ctrl.systemInfo.hostname}}</td>
+                    <td>{{$ctrl.systemInfo.hostname}}</td>
                   </tr>
                   <tr>
                     <td translate>systemInfo.infoTable.OS</td>
-                    <td>{{ctrl.systemInfo.osName}}</td>
+                    <td>{{$ctrl.systemInfo.osName}}</td>
                   </tr>
                   <tr>
                     <td translate>systemInfo.infoTable.KERNEL</td>
-                    <td>{{ctrl.systemInfo.osKernel}}</td>
+                    <td>{{$ctrl.systemInfo.osKernel}}</td>
                   </tr>
                   <tr>
                     <td translate>systemInfo.infoTable.CPU</td>
-                    <td translate="systemInfo.infoTable.CPU_MODEL_FMT" translate-values="{ model: ctrl.systemInfo.cpuModel, coreCount: ctrl.systemInfo.cpuCount }"></td>
+                    <td translate="systemInfo.infoTable.CPU_MODEL_FMT" translate-values="{ model: $ctrl.systemInfo.cpuModel, coreCount: $ctrl.systemInfo.cpuCount }"></td>
                   </tr>
                   <tr>
                     <td translate>systemInfo.infoTable.MEMORY</td>
-                    <td>{{ctrl.systemInfo.totalMemory | formatBytes}}</td>
+                    <td>{{$ctrl.systemInfo.totalMemory | formatBytes}}</td>
                   </tr>
                 </tbody>
               </table>
@@ -57,7 +57,7 @@
               </h4>
             </div>
             <div id="collapseTwo" class="panel-collapse collapse">
-              <system-network system-id="ctrl.systemId"></system-network>
+              <system-network system-id="$ctrl.systemId"></system-network>
             </div>
           </div>
         </div>
@@ -66,8 +66,8 @@
 
     <div class="row row-cards-pf">
       <div class="container container-cards-pf">
-        <system-cpu system-id="ctrl.systemId"></system-cpu>
-        <system-memory system-id="ctrl.systemId"></system-memory>
+        <system-cpu system-id="$ctrl.systemId"></system-cpu>
+        <system-memory system-id="$ctrl.systemId"></system-memory>
       </div>
     </div>
 
--- a/src/app/components/system-info/system-info.module.js	Thu Sep 14 15:23:46 2017 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,44 +0,0 @@
-/**
- * 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 SystemInfocontroller from './system-info.controller.js';
-import systemCpu from './system-cpu/system-cpu.component.js';
-import systemMemory from './system-memory/system-memory.component.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';
-
-export default angular
-  .module('systemInfo', [
-    SystemInfocontroller,
-    systemCpu,
-    systemMemory,
-    systemNetwork,
-    service,
-    components
-  ])
-  .name;
--- a/src/app/components/system-info/system-info.routing.js	Thu Sep 14 15:23:46 2017 -0400
+++ b/src/app/components/system-info/system-info.routing.js	Tue Sep 12 10:27:01 2017 -0400
@@ -30,28 +30,17 @@
 
   $stateProvider.state('systemInfo', {
     url: '/system-info/{systemId}',
-    templateProvider: $q => {
-      'ngInject';
-      return $q(resolve =>
-        require.ensure([], () => resolve(require('./system-info.html'))
-        )
-      );
-    },
-    controller: 'SystemInfoController as ctrl',
+    component: 'systemInfo',
     resolve: {
-      loadSystemInfo: ($q, $ocLazyLoad) => {
+      lazyLoad: ($q, $ocLazyLoad) => {
         'ngInject';
         return $q(resolve => {
-          require.ensure(['./system-info.module.js'], () => {
-            let module = require('./system-info.module.js');
+          require.ensure(['./system-info.component.js'], () => {
+            let module = require('./system-info.component.js');
             $ocLazyLoad.load({ name: module.default });
             resolve(module);
           });
         });
-      },
-      systemId: $stateParams => {
-        'ngInject';
-        return $stateParams.systemId;
       }
     }
   });
--- a/src/app/components/system-info/system-info.routing.spec.js	Thu Sep 14 15:23:46 2017 -0400
+++ b/src/app/components/system-info/system-info.routing.spec.js	Tue Sep 12 10:27:01 2017 -0400
@@ -55,24 +55,8 @@
       args[1].url.should.equal('/system-info/{systemId}');
     });
 
-    it('template provider should return system-info.html', done => {
-      let providerFn = args[1].templateProvider[1];
-      providerFn.should.be.a.Function();
-      providerFn(q);
-      q.should.be.calledOnce();
-
-      let deferred = q.args[0][0];
-      deferred.should.be.a.Function();
-
-      let resolve = sinon.stub().callsFake(val => {
-        val.should.equal(require('./system-info.html'));
-        done();
-      });
-      deferred(resolve);
-    });
-
-    it('resolve should load system-info module', done => {
-      let resolveFn = args[1].resolve.loadSystemInfo[2];
+    it('resolve should load system-info component', done => {
+      let resolveFn = args[1].resolve.lazyLoad[2];
       resolveFn.should.be.a.Function();
       resolveFn(q, ocLazyLoad);
       q.should.be.calledOnce();
@@ -81,22 +65,13 @@
       deferred.should.be.a.Function();
 
       let resolve = sinon.stub().callsFake(val => {
-        let mod = require('./system-info.module.js');
+        let mod = require('./system-info.component.js');
         ocLazyLoad.load.should.be.calledWith({ name: mod.default });
         val.should.equal(mod);
         done();
       });
       deferred(resolve);
     });
-
-    it('resolve should provide systemId', () => {
-      let resolveFn = args[1].resolve.systemId[1];
-      resolveFn.should.be.a.Function();
-
-      let expected = 'foo-systemId';
-      let result = resolveFn({ systemId: expected });
-      result.should.be.exactly(expected);
-    });
   });
 
 });