From 57a169026c437da22656dc5731857631f1c0079c Mon Sep 17 00:00:00 2001 From: Vit Stanislav Date: Fri, 9 Jun 2017 08:55:51 +0200 Subject: [PATCH] Unify modals fullscreen and width - Closes #358 --- src/components/delegates/delegates.js | 32 ++++----------- src/components/header/header.js | 3 +- src/components/header/header.pug | 4 +- src/liskNano.js | 1 - src/services/dialog.js | 5 ++- src/services/signVerify.js | 36 ----------------- test/components/delegates/delegates.spec.js | 2 +- test/services/signVerify.spec.js | 44 --------------------- test/test.js | 1 - 9 files changed, 14 insertions(+), 114 deletions(-) delete mode 100644 src/services/signVerify.js delete mode 100644 test/services/signVerify.spec.js diff --git a/src/components/delegates/delegates.js b/src/components/delegates/delegates.js index 36bdf24e0..fac85e8e4 100644 --- a/src/components/delegates/delegates.js +++ b/src/components/delegates/delegates.js @@ -21,15 +21,14 @@ app.component('delegates', { * @constructor */ controller: class delegates { - constructor($scope, $rootScope, Peers, $mdDialog, $mdMedia, - dialog, $timeout, delegateApi, Account) { + constructor($scope, $rootScope, Peers, dialog, $mdMedia, + $timeout, delegateApi, Account) { this.$scope = $scope; this.$rootScope = $rootScope; this.peers = Peers; this.delegateApi = delegateApi; - this.$mdDialog = $mdDialog; - this.$mdMedia = $mdMedia; this.dialog = dialog; + this.$mdMedia = $mdMedia; this.$timeout = $timeout; this.account = Account; @@ -339,31 +338,14 @@ app.component('delegates', { } /** - * Uses mdDialog to show vote list directive. + * Uses dialog.modal to show vote list directive. * * @method openVoteDialog - * @todo Use a general dialog service instead. */ openVoteDialog() { - this.$mdDialog.show({ - controllerAs: '$ctrl', - controller: class voteDialog { - constructor($scope, voteList, unvoteList) { - this.$scope = $scope; - this.$scope.voteList = voteList; - this.$scope.unvoteList = unvoteList; - } - }, - template: - '' + - '' + - '' + - '', - fullscreen: (this.$mdMedia('sm') || this.$mdMedia('xs')) && this.$scope.customFullscreen, - locals: { - voteList: this.voteList, - unvoteList: this.unvoteList, - }, + this.dialog.modal('vote', { + 'vote-list': this.voteList, + 'unvote-list': this.unvoteList, }).then((() => { this.setPendingVotes(); })); diff --git a/src/components/header/header.js b/src/components/header/header.js index 5ed22a925..7ec28e68e 100644 --- a/src/components/header/header.js +++ b/src/components/header/header.js @@ -17,10 +17,9 @@ app.component('header', { * @constructor */ controller: class header { - constructor($rootScope, Account, signVerify) { + constructor($rootScope, Account) { this.$rootScope = $rootScope; this.account = Account; - this.signVerify = signVerify; } }, }); diff --git a/src/components/header/header.pug b/src/components/header/header.pug index 2b6e1896a..b78229e4b 100644 --- a/src/components/header/header.pug +++ b/src/components/header/header.pug @@ -16,10 +16,10 @@ md-content.header(layout='row', layout-align='center center', layout-padding) div(layout='row', flex='') p(flex='') Register as delegate md-menu-item - md-button.sign-message(ng-click='$ctrl.signVerify.openSignMessageDialog()') + md-button.sign-message(data-open-dialog='sign-message') div(layout='row', flex='') p(flex='') Sign message md-menu-item - md-button.verify-message(ng-click='$ctrl.signVerify.openVerifyMessageDialog()') + md-button.verify-message(data-open-dialog='verify-message') div(layout='row', flex='') p(flex='') Verify message diff --git a/src/liskNano.js b/src/liskNano.js index fe7d8037f..63834f296 100644 --- a/src/liskNano.js +++ b/src/liskNano.js @@ -30,7 +30,6 @@ import './services/api/forgingApi'; import './services/api/peers'; import './services/dialog'; import './services/lsk'; -import './services/signVerify'; import './services/sync'; import './services/notification'; diff --git a/src/services/dialog.js b/src/services/dialog.js index b5aebb8c3..bed6c218b 100644 --- a/src/services/dialog.js +++ b/src/services/dialog.js @@ -4,7 +4,7 @@ * @module app * @submodule dialog */ -app.factory('dialog', ($mdDialog, $mdToast) => ({ +app.factory('dialog', ($mdDialog, $mdToast, $mdMedia) => ({ /** * Uses mdToast to show a toast with error theme @@ -114,13 +114,14 @@ app.factory('dialog', ($mdDialog, $mdToast) => ({ return $mdDialog.show({ parent: angular.element(document.body), template: ` - + <${component} ${attrs} close-dialog="closeDialog()" > `, locals: { option: options, }, + fullscreen: $mdMedia('xs'), controller: modalController, }); }, diff --git a/src/services/signVerify.js b/src/services/signVerify.js deleted file mode 100644 index 09aaa740b..000000000 --- a/src/services/signVerify.js +++ /dev/null @@ -1,36 +0,0 @@ -app.factory('signVerify', ($mdDialog, $mdMedia) => ({ - /** - * Uses mdDialog to show signMessage form directive. - * - * @todo This should be replaced by a general dialog service - * which can compile any child component in the dialog - * @returns {promise} mdDialog instance promise - */ - openSignMessageDialog() { - return $mdDialog.show({ - template: - '' + - '' + - '', - fullscreen: ($mdMedia('sm') || $mdMedia('xs')), - }); - }, - - /** - * Uses mdDialog to show verifyMessage form directive. - * - * @todo This should be replaced by a general dialog service - * which can compile any child component in the dialog - * @returns {promise} mdDialog instance promise - */ - openVerifyMessageDialog() { - return $mdDialog.show({ - template: - '' + - '' + - '', - fullscreen: ($mdMedia('sm') || $mdMedia('xs')), - }); - }, -})); - diff --git a/test/components/delegates/delegates.spec.js b/test/components/delegates/delegates.spec.js index e6607be8f..fdec0cde3 100644 --- a/test/components/delegates/delegates.spec.js +++ b/test/components/delegates/delegates.spec.js @@ -195,7 +195,7 @@ describe('delegates component controller', () => { describe('openVoteDialog()', () => { it('opens vote dialog', () => { - const spy = sinon.spy(controller.$mdDialog, 'show'); + const spy = sinon.spy(controller.dialog, 'modal'); controller.openVoteDialog(); expect(spy).to.have.been.calledWith(); }); diff --git a/test/services/signVerify.spec.js b/test/services/signVerify.spec.js deleted file mode 100644 index d3d66da67..000000000 --- a/test/services/signVerify.spec.js +++ /dev/null @@ -1,44 +0,0 @@ -const chai = require('chai'); -const sinon = require('sinon'); -const sinonChai = require('sinon-chai'); - -chai.use(sinonChai); - -describe('Factory: signVerify', () => { - let signVerify; - let $mdDialog; - - beforeEach(angular.mock.module('app')); - - beforeEach(inject((_signVerify_, _$mdDialog_) => { - signVerify = _signVerify_; - $mdDialog = _$mdDialog_; - })); - - describe('openSignMessageDialog(account, passphrase)', () => { - let mock; - - beforeEach(() => { - mock = sinon.mock($mdDialog); - mock.expects('show').withArgs(); - }); - - it('opens a $mdDialog', () => { - signVerify.openSignMessageDialog(); - }); - }); - - describe('openVerifyMessageDialog()', () => { - let mock; - - beforeEach(() => { - mock = sinon.mock($mdDialog); - mock.expects('show').withArgs(); - }); - - it('opens a $mdDialog', () => { - signVerify.openVerifyMessageDialog(); - }); - }); -}); - diff --git a/test/test.js b/test/test.js index 37e84aa9f..2849ef44e 100644 --- a/test/test.js +++ b/test/test.js @@ -23,7 +23,6 @@ require('./services/api/forgingApi.spec'); require('./services/api/peers.spec'); require('./services/lsk.spec'); require('./services/passphrase.spec'); -require('./services/signVerify.spec'); require('./services/notification.spec'); require('./run.spec');