# HG changeset patch # User Andrew Azores # Date 1506349867 14400 # Node ID 6568fdab115d6739a8a82959e71089d539efe135 # Parent 57a4676a934301da74f5ec7790e708753cdc8226 Move Byteman rules view into tabbed subview Reviewed-by: jkang Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-September/025171.html diff -r 57a4676a9343 -r 6568fdab115d src/app/components/jvm-info/byteman/byteman.component.js --- a/src/app/components/jvm-info/byteman/byteman.component.js Fri Sep 22 14:33:18 2017 -0400 +++ b/src/app/components/jvm-info/byteman/byteman.component.js Mon Sep 25 10:31:07 2017 -0400 @@ -26,9 +26,13 @@ */ import BytemanController from './byteman.controller.js'; +import BytemanRulesComponent from './rules/byteman-rules.component.js'; export default angular - .module('byteman', [BytemanController]) + .module('byteman', [ + BytemanController, + BytemanRulesComponent + ]) .component('byteman', { controller: 'BytemanController', template: require('./byteman.html') diff -r 57a4676a9343 -r 6568fdab115d src/app/components/jvm-info/byteman/byteman.controller.js --- a/src/app/components/jvm-info/byteman/byteman.controller.js Fri Sep 22 14:33:18 2017 -0400 +++ b/src/app/components/jvm-info/byteman/byteman.controller.js Mon Sep 25 10:31:07 2017 -0400 @@ -25,75 +25,20 @@ * exception statement from your version. */ -import service from './byteman.service.js'; - class BytemanController { - constructor ($stateParams, $translate, bytemanService) { + constructor ($state) { 'ngInject'; - this.jvmId = $stateParams.jvmId; - this.systemId = $stateParams.systemId; - this._translate = $translate; - this._svc = bytemanService; - - this.loadedRule = ''; + this._state = $state; } $onInit () { - this._updateRules(); - } - - $onDestroy () { - } - - _updateRules () { - return this._svc.getLoadedRules(this.jvmId) - .then(res => { - this.loadedRule = res; - this._clearInput(); - }); - } - - _clearInput () { - this.ruleText = ''; - } - - refresh () { - return this._updateRules(); - } - - unload () { - if (!this.loadedRule) { - return; + if (this._state.is('jvmInfo.byteman')) { + this._state.go('jvmInfo.byteman.rules'); } - return this._svc.unloadRules(this.systemId, this.jvmId) - .then(() => this._updateRules()); - } - - push () { - return this._svc.loadRule(this.systemId, this.jvmId, this.ruleText) - .then(() => this._updateRules()); - } - - pull () { - return this._svc.getLoadedRules(this.jvmId) - .then(res => { - this.loadedRule = res; - if (res) { - this.ruleText = res; - } - }); - } - - generateTemplate () { - return this._svc.getJvmMainClass(this.systemId, this.jvmId) - .then(mainClass => { - return this._translate('byteman.RULE_TEMPLATE', { mainClass: mainClass }) - .then(res => this.ruleText = res); - }); } } export default angular - .module('byteman.controller', [service]) + .module('byteman.controller', []) .controller('BytemanController', BytemanController) .name; diff -r 57a4676a9343 -r 6568fdab115d src/app/components/jvm-info/byteman/byteman.controller.spec.js --- a/src/app/components/jvm-info/byteman/byteman.controller.spec.js Fri Sep 22 14:33:18 2017 -0400 +++ b/src/app/components/jvm-info/byteman/byteman.controller.spec.js Mon Sep 25 10:31:07 2017 -0400 @@ -29,160 +29,42 @@ describe('BytemanController', () => { - let ctrl, stateParams, translate, svc; + let ctrl, state; beforeEach(() => { angular.mock.module(controllerModule); - stateParams = { - jvmId: 'foo-jvmId', - systemId: 'foo-systemId' + state = { + go: sinon.spy(), + is: sinon.stub() }; - - translate = sinon.stub(); - translate.then = sinon.stub(); - translate.returns({ then: translate.then }); - - svc = { - getLoadedRules: sinon.stub(), - loadRule: sinon.stub(), - unloadRules: sinon.stub(), - getJvmMainClass: sinon.stub() - }; - angular.mock.inject($controller => { 'ngInject'; ctrl = $controller('BytemanController', { - $stateParams: stateParams, - $translate: translate, - bytemanService: svc + $state: state }); }); }); describe('$onInit ()', () => { - it('should load injected rules', () => { - svc.getLoadedRules.should.not.be.called(); - svc.getLoadedRules.returns({ - then: sinon.stub().yields('fake rule') - }); + it('should default to rules state', () => { + state.go.should.not.be.called(); + state.is.should.not.be.called(); + state.is.returns(true); ctrl.$onInit(); - svc.getLoadedRules.should.be.calledOnce(); - svc.getLoadedRules.should.be.calledWith(stateParams.jvmId); - ctrl.loadedRule.should.equal('fake rule'); - }); - }); - - describe('_clearInput ()', () => { - it('should reset ruleText property to the empty string', () => { - ctrl.ruleText = 'foo'; - ctrl._clearInput(); - ctrl.ruleText.should.equal(''); - }); - }); - - describe('refresh ()', () => { - it('should load injected rules', () => { - svc.getLoadedRules.should.not.be.called(); - svc.getLoadedRules.returns({ - then: sinon.stub().yields('fake rule') - }); - - ctrl.refresh(); - - svc.getLoadedRules.should.be.calledOnce(); - svc.getLoadedRules.should.be.calledWith(stateParams.jvmId); - ctrl.loadedRule.should.equal('fake rule'); - }); - }); - - describe('unload ()', () => { - it('should do nothing if no loaded rule', () => { - svc.unloadRules.should.not.be.called(); - ctrl.unload(); - svc.unloadRules.should.not.be.called(); + state.go.should.be.calledOnce(); + state.go.should.be.calledWith('jvmInfo.byteman.rules'); }); - it('should unload rules', () => { - svc.getLoadedRules.should.not.be.called(); - svc.getLoadedRules.returns({ - then: sinon.stub().yields('fake rule') - }); - ctrl.refresh(); - - svc.getLoadedRules.returns({ - then: sinon.stub().yields('') - }); - svc.unloadRules.returns({ - then: sinon.stub().yields() - }); - ctrl.unload(); - ctrl.loadedRule.should.equal(''); - }); - }); - - describe('push ()', () => { - it('should send local rule text to service', () => { - const injectedRule = 'injected rule'; - ctrl.ruleText = injectedRule; - svc.loadRule.returns({ - then: sinon.stub().yields() - }); - svc.getLoadedRules.returns({ - then: sinon.stub().yields(injectedRule) - }); - - ctrl.push(); - - svc.loadRule.should.be.calledOnce(); - svc.loadRule.should.be.calledWith(stateParams.systemId, stateParams.jvmId, injectedRule); - ctrl.loadedRule.should.equal(injectedRule); - }); - }); + it('should not redirect if URL contains non-rules state', () => { + state.go.should.not.be.called(); + state.is.should.not.be.called(); + state.is.returns(false); - describe('pull ()', () => { - it('should pull injected rule into editor', () => { - const loadedRule = 'loaded rule'; - svc.getLoadedRules.returns({ - then: sinon.stub().yields(loadedRule) - }); - - ctrl.pull(); - - svc.getLoadedRules.should.be.calledOnce(); - svc.getLoadedRules.should.be.calledWith(stateParams.jvmId); - - ctrl.loadedRule.should.equal(loadedRule); - ctrl.ruleText.should.equal(loadedRule); - }); - - it('should not clobber rule text if no remotely injected rules', () => { - svc.getLoadedRules.returns({ - then: sinon.stub().yields() - }); + ctrl.$onInit(); - ctrl.ruleText = 'locally edited rule'; - ctrl.pull(); - - svc.getLoadedRules.should.be.calledOnce(); - svc.getLoadedRules.should.be.calledWith(stateParams.jvmId); - - should(ctrl.loadedRule).be.undefined(); - ctrl.ruleText.should.equal('locally edited rule'); - }); - }); - - describe('generateTemplate ()', () => { - it('should set rule text to template', () => { - svc.getJvmMainClass.returns({ - then: sinon.stub().yields('com.example.FooClass') - }); - translate.then.yields('rule template'); - ctrl.generateTemplate(); - translate.should.be.calledOnce(); - translate.should.be.calledWith('byteman.RULE_TEMPLATE', { mainClass: 'com.example.FooClass' }); - ctrl.ruleText.should.equal('rule template'); + state.go.should.not.be.called(); }); }); diff -r 57a4676a9343 -r 6568fdab115d src/app/components/jvm-info/byteman/byteman.html --- a/src/app/components/jvm-info/byteman/byteman.html Fri Sep 22 14:33:18 2017 -0400 +++ b/src/app/components/jvm-info/byteman/byteman.html Mon Sep 25 10:31:07 2017 -0400 @@ -1,40 +1,8 @@
-
- -
-
- - -
-
- -
- -
- -