changeset 210:f058b116e664

Avoid using $scope in multicharts Reviewed-by: jkang Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-September/025051.html
author Andrew Azores <aazores@redhat.com>
date Mon, 18 Sep 2017 12:11:37 -0400
parents eebc9b8f9e61
children 784310522116
files src/app/components/multichart/multichart.controller.js src/app/components/multichart/multichart.controller.spec.js src/app/components/multichart/multichart.html
diffstat 3 files changed, 11 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/app/components/multichart/multichart.controller.js	Mon Sep 18 12:10:54 2017 -0400
+++ b/src/app/components/multichart/multichart.controller.js	Mon Sep 18 12:11:37 2017 -0400
@@ -29,8 +29,7 @@
 import components from 'shared/components/components.module.js';
 
 class MultiChartController {
-  constructor ($scope, multichartService, $translate) {
-    this.scope = $scope;
+  constructor (multichartService, $translate) {
     this.svc = multichartService;
     this.showErr = false;
     this.newChartName = '';
@@ -51,9 +50,8 @@
     this.showErr = false;
     this.svc.addChart(this.newChartName);
     this.newChartName = '';
-    let form = this.scope.newChartForm;
-    form.$setPristine();
-    form.$setUntouched();
+    this.form.$setPristine();
+    this.form.$setUntouched();
   }
 
   isValid (chartName) {
--- a/src/app/components/multichart/multichart.controller.spec.js	Mon Sep 18 12:10:54 2017 -0400
+++ b/src/app/components/multichart/multichart.controller.spec.js	Mon Sep 18 12:11:37 2017 -0400
@@ -29,13 +29,13 @@
 
 describe('MultiChartController', () => {
 
-  let scope, svc, ctrl, translate;
+  let svc, ctrl, translate, newChartForm;
   beforeEach(() => {
     angular.mock.module(controllerModule);
-    angular.mock.inject(($rootScope, $controller) => {
+    angular.mock.inject($controller => {
       'ngInject';
-      scope = $rootScope.$new();
-      scope.newChartForm = {
+
+      newChartForm = {
         $setPristine: sinon.spy(),
         $setUntouched: sinon.spy()
       };
@@ -47,10 +47,10 @@
         then: sinon.stub().yields()
       });
       ctrl = $controller('MultichartController', {
-        $scope: scope,
         multichartService: svc,
         $translate: translate
       });
+      ctrl.form = newChartForm;
     });
   });
 
@@ -81,8 +81,8 @@
       svc.addChart.should.be.calledOnce();
       svc.addChart.should.be.calledWith('foo');
       ctrl.newChartName.should.equal('');
-      scope.newChartForm.$setUntouched.should.be.calledOnce();
-      scope.newChartForm.$setPristine.should.be.calledOnce();
+      newChartForm.$setUntouched.should.be.calledOnce();
+      newChartForm.$setPristine.should.be.calledOnce();
     });
 
     it('should trim spaces from chart names', () => {
--- a/src/app/components/multichart/multichart.html	Mon Sep 18 12:10:54 2017 -0400
+++ b/src/app/components/multichart/multichart.html	Mon Sep 18 12:11:37 2017 -0400
@@ -9,7 +9,7 @@
 
     <div class="row">
       <div class="col-xs-12 col-md-4">
-        <form name="newChartForm" class="input-group" ng-submit="$ctrl.createChart()">
+        <form name="$ctrl.form" class="input-group" ng-submit="$ctrl.createChart()">
           <span class="input-group-addon" translate>multicharts.form.NAME</span>
           <input type="text" class="form-control" translate-attr="{ placeholder: 'multicharts.form.PLACEHOLDER' }" ng-model="$ctrl.newChartName"/>
           <input type="submit" translate-attr="{ value: 'multicharts.form.SUBMIT_LABEL' }"/>