Move away from using a common modal service, since the block options and the toolbox modals are going to end up behaving fairly differently.

This commit is contained in:
Sean Lip
2016-11-16 16:47:26 -08:00
parent dd95203cdc
commit a027ec8573
7 changed files with 30 additions and 39 deletions

View File

@@ -55,7 +55,7 @@ blocklyApp.AppView = ng.core.Component({
providers: [ providers: [
blocklyApp.ClipboardService, blocklyApp.NotificationsService, blocklyApp.ClipboardService, blocklyApp.NotificationsService,
blocklyApp.TreeService, blocklyApp.UtilsService, blocklyApp.TreeService, blocklyApp.UtilsService,
blocklyApp.AudioService, blocklyApp.ModalService, blocklyApp.AudioService, blocklyApp.BlockOptionsModalService,
blocklyApp.KeyboardInputService] blocklyApp.KeyboardInputService]
}) })
.Class({ .Class({

View File

@@ -26,12 +26,12 @@
blocklyApp.BlockOptionsModalComponent = ng.core.Component({ blocklyApp.BlockOptionsModalComponent = ng.core.Component({
selector: 'blockly-block-options-modal', selector: 'blockly-block-options-modal',
template: ` template: `
<div *ngIf="modalIsVisible" id="modalId" role="dialog" tabindex="-1"> <div *ngIf="modalIsVisible" id="blockOptionsModal" role="dialog" tabindex="-1">
<div (click)="hideModal()" class="blocklyModalCurtain"> <div (click)="hideModal()" class="blocklyModalCurtain">
<!-- The $event.stopPropagation() here prevents the modal from <!-- The $event.stopPropagation() here prevents the modal from
closing when its interior is clicked. --> closing when its interior is clicked. -->
<div class="blocklyModal" (click)="$event.stopPropagation()" role="document"> <div class="blocklyModal" (click)="$event.stopPropagation()" role="document">
<h3>{{modalHeaderHtml}}</h3> <h3>Block Options</h3>
<div class="blocklyModalButtonContainer" <div class="blocklyModalButtonContainer"
*ngFor="#buttonInfo of actionButtonsInfo; #i=index"> *ngFor="#buttonInfo of actionButtonsInfo; #i=index">
@@ -84,27 +84,23 @@ blocklyApp.BlockOptionsModalComponent = ng.core.Component({
}) })
.Class({ .Class({
constructor: [ constructor: [
blocklyApp.ModalService, blocklyApp.KeyboardInputService, blocklyApp.BlockOptionsModalService, blocklyApp.KeyboardInputService,
blocklyApp.AudioService, blocklyApp.AudioService,
function(modalService_, keyboardInputService_, audioService_) { function(blockOptionsModalService_, keyboardInputService_, audioService_) {
this.modalService = modalService_; this.blockOptionsModalService = blockOptionsModalService_;
this.keyboardInputService = keyboardInputService_; this.keyboardInputService = keyboardInputService_;
this.audioService = audioService_; this.audioService = audioService_;
this.modalIsVisible = false; this.modalIsVisible = false;
this.modalHeaderHtml = '';
this.actionButtonsInfo = []; this.actionButtonsInfo = [];
this.activeActionButtonIndex = 0; this.activeActionButtonIndex = 0;
this.onHideCallback = null;
var that = this; var that = this;
this.modalService.registerPreShowHook( this.blockOptionsModalService.registerPreShowHook(
function(newModalHeaderHtml, newActionButtonsInfo, onHideCallback) { function(newActionButtonsInfo) {
that.modalIsVisible = true; that.modalIsVisible = true;
that.modalHeaderHtml = newModalHeaderHtml;
that.actionButtonsInfo = newActionButtonsInfo; that.actionButtonsInfo = newActionButtonsInfo;
that.activeActionButtonIndex = 0; that.activeActionButtonIndex = 0;
that.onHideCallback = onHideCallback;
that.keyboardInputService.setOverride({ that.keyboardInputService.setOverride({
// Tab key: no-op. // Tab key: no-op.
'9': function(evt) { '9': function(evt) {
@@ -156,7 +152,7 @@ blocklyApp.BlockOptionsModalComponent = ng.core.Component({
}); });
setTimeout(function() { setTimeout(function() {
document.getElementById('modalId').focus(); document.getElementById('blockOptionsModal').focus();
}, 150); }, 150);
} }
); );
@@ -184,6 +180,6 @@ blocklyApp.BlockOptionsModalComponent = ng.core.Component({
hideModal: function() { hideModal: function() {
this.modalIsVisible = false; this.modalIsVisible = false;
this.keyboardInputService.clearOverride(); this.keyboardInputService.clearOverride();
this.modalService.hideModal(); this.blockOptionsModalService.hideModal();
} }
}); });

View File

@@ -18,30 +18,27 @@
*/ */
/** /**
* @fileoverview Angular2 Service that stores the content for custom modals. * @fileoverview Angular2 Service for the block options modal.
* This is a singleton service.
* *
* @author sll@google.com (Sean Lip) * @author sll@google.com (Sean Lip)
*/ */
blocklyApp.ModalService = ng.core.Class({ blocklyApp.BlockOptionsModalService = ng.core.Class({
constructor: [function() { constructor: [function() {
this.modalHeaderHtml = '';
this.actionButtonsInfo = []; this.actionButtonsInfo = [];
this.preShowHookHtml = null; this.preShowHook = null;
this.modalIsShown = false; this.modalIsShown = false;
this.onHideCallback = null; this.onHideCallback = null;
}], }],
registerPreShowHook: function(preShowHook) { registerPreShowHook: function(preShowHook) {
this.preShowHook = function() { this.preShowHook = function() {
preShowHook(this.modalHeaderHtml, this.actionButtonsInfo); preShowHook(this.actionButtonsInfo);
}; };
}, },
isModalShown: function() { isModalShown: function() {
return this.modalIsShown; return this.modalIsShown;
}, },
showModal: function(modalHeaderHtml, actionButtonsInfo, onHideCallback) { showModal: function(actionButtonsInfo, onHideCallback) {
this.modalHeaderHtml = modalHeaderHtml;
this.actionButtonsInfo = actionButtonsInfo; this.actionButtonsInfo = actionButtonsInfo;
this.onHideCallback = onHideCallback; this.onHideCallback = onHideCallback;

View File

@@ -73,12 +73,11 @@ blocklyApp.ToolboxComponent = ng.core.Component({
}) })
.Class({ .Class({
constructor: [ constructor: [
blocklyApp.TreeService, blocklyApp.UtilsService, blocklyApp.ModalService, blocklyApp.TreeService, blocklyApp.UtilsService,
function(_treeService, _utilsService, _modalService) { function(_treeService, _utilsService) {
this.toolboxCategories = []; this.toolboxCategories = [];
this.treeService = _treeService; this.treeService = _treeService;
this.utilsService = _utilsService; this.utilsService = _utilsService;
this.modalService = _modalService;
this.xmlHasCategories = false; this.xmlHasCategories = false;
} }
@@ -120,9 +119,6 @@ blocklyApp.ToolboxComponent = ng.core.Component({
}); });
} }
}, },
isModalShown: function() {
return this.modalService.isModalShown();
},
getActiveDescId: function() { getActiveDescId: function() {
return this.treeService.getActiveDescId('blockly-toolbox-tree'); return this.treeService.getActiveDescId('blockly-toolbox-tree');
}, },

View File

@@ -27,17 +27,17 @@
blocklyApp.TreeService = ng.core.Class({ blocklyApp.TreeService = ng.core.Class({
constructor: [ constructor: [
blocklyApp.NotificationsService, blocklyApp.UtilsService, blocklyApp.NotificationsService, blocklyApp.UtilsService,
blocklyApp.ClipboardService, blocklyApp.ModalService, blocklyApp.ClipboardService, blocklyApp.BlockOptionsModalService,
blocklyApp.AudioService, blocklyApp.AudioService,
function( function(
_notificationsService, _utilsService, _clipboardService, _notificationsService, _utilsService, _clipboardService,
_modalService, _audioService) { _blockOptionsModalService, _audioService) {
// Stores active descendant ids for each tree in the page. // Stores active descendant ids for each tree in the page.
this.activeDescendantIds_ = {}; this.activeDescendantIds_ = {};
this.notificationsService = _notificationsService; this.notificationsService = _notificationsService;
this.utilsService = _utilsService; this.utilsService = _utilsService;
this.clipboardService = _clipboardService; this.clipboardService = _clipboardService;
this.modalService = _modalService; this.blockOptionsModalService = _blockOptionsModalService;
this.audioService = _audioService; this.audioService = _audioService;
this.toolboxWorkspaces = {}; this.toolboxWorkspaces = {};
} }
@@ -357,7 +357,7 @@ blocklyApp.TreeService = ng.core.Class({
}, },
showBlockOptionsModal: function(block, blockRootNode) { showBlockOptionsModal: function(block, blockRootNode) {
var that = this; var that = this;
this.modalService.showModal('Block options', [{ var actionButtonsInfo = [{
translationIdForText: 'MARK_SPOT_BEFORE', translationIdForText: 'MARK_SPOT_BEFORE',
action: function() { action: function() {
that.clipboardService.markConnection(block.previousConnection); that.clipboardService.markConnection(block.previousConnection);
@@ -436,7 +436,9 @@ blocklyApp.TreeService = ng.core.Class({
isDisabled: function() { isDisabled: function() {
return false; return false;
} }
}], function() { }];
this.blockOptionsModalService.showModal(actionButtonsInfo, function() {
// TODO(sll): If there are no blocks in the workspace, focus on the // TODO(sll): If there are no blocks in the workspace, focus on the
// entire workspace instead. // entire workspace instead.
that.focusOnBlock(block.id); that.focusOnBlock(block.id);
@@ -464,7 +466,9 @@ blocklyApp.TreeService = ng.core.Class({
this.utilsService.getBlockById(blockId); this.utilsService.getBlockById(blockId);
}, },
onKeypress: function(e, tree) { onKeypress: function(e, tree) {
if (this.modalService.isModalShown()) { // TODO(sll): Instead of this, have a common ActiveContextService which
// returns true if at least one modal is shown, and false otherwise.
if (this.blockOptionsModalService.isModalShown()) {
return; return;
} }

View File

@@ -79,17 +79,15 @@ blocklyApp.WorkspaceTreeComponent = ng.core.Component({
.Class({ .Class({
constructor: [ constructor: [
blocklyApp.ClipboardService, blocklyApp.NotificationsService, blocklyApp.ClipboardService, blocklyApp.NotificationsService,
blocklyApp.TreeService, blocklyApp.UtilsService, blocklyApp.TreeService, blocklyApp.UtilsService, blocklyApp.AudioService,
blocklyApp.AudioService, blocklyApp.ModalService,
function( function(
_clipboardService, _notificationsService, _treeService, _clipboardService, _notificationsService, _treeService,
_utilsService, _audioService, _modalService) { _utilsService, _audioService) {
this.clipboardService = _clipboardService; this.clipboardService = _clipboardService;
this.notificationsService = _notificationsService; this.notificationsService = _notificationsService;
this.treeService = _treeService; this.treeService = _treeService;
this.utilsService = _utilsService; this.utilsService = _utilsService;
this.audioService = _audioService; this.audioService = _audioService;
this.modalService = _modalService;
}], }],
ngOnInit: function() { ngOnInit: function() {
var SUPPORTED_FIELDS = [ var SUPPORTED_FIELDS = [

View File

@@ -20,7 +20,7 @@
<script src="../../accessible/utils.service.js"></script> <script src="../../accessible/utils.service.js"></script>
<script src="../../accessible/audio.service.js"></script> <script src="../../accessible/audio.service.js"></script>
<script src="../../accessible/modal.service.js"></script> <script src="../../accessible/block-options-modal.service.js"></script>
<script src="../../accessible/keyboard-input.service.js"></script> <script src="../../accessible/keyboard-input.service.js"></script>
<script src="../../accessible/notifications.service.js"></script> <script src="../../accessible/notifications.service.js"></script>
<script src="../../accessible/clipboard.service.js"></script> <script src="../../accessible/clipboard.service.js"></script>