Remove some functions from utilsService and consolidate code in workspace-tree.component.js.

This commit is contained in:
Sean Lip
2016-12-05 17:52:45 -08:00
parent 04785a2222
commit 51f42ef5a3
3 changed files with 13 additions and 22 deletions

View File

@@ -362,7 +362,7 @@ blocklyApp.TreeService = ng.core.Class({
var blockRootSuffix = this.getBlockRootSuffix_();
var blockId = blockRootNode.id.substring(
0, blockRootNode.id.length - blockRootSuffix.length);
return this.utilsService.getBlockById(blockId);
return blocklyApp.workspace.getBlockById(blockId);
},
onKeypress: function(e, tree) {
// TODO(sll): Instead of this, have a common ActiveContextService which

View File

@@ -28,7 +28,7 @@
var blocklyApp = {};
blocklyApp.UtilsService = ng.core.Class({
constructor: function() {},
constructor: [function() {}],
generateUniqueId: function() {
return 'blockly-' + Blockly.utils.genUid();
},
@@ -42,22 +42,6 @@ blocklyApp.UtilsService = ng.core.Class({
generateAriaLabelledByAttr: function(mainLabel, secondLabel) {
return mainLabel + (secondLabel ? ' ' + secondLabel : '');
},
getInputTypeLabel: function(connection) {
// Returns the input type name, or 'any' if any official input type
// qualifies.
if (connection.check_) {
return connection.check_.join(', ');
} else {
return Blockly.Msg.ANY;
}
},
getBlockTypeLabel: function(inputBlock) {
if (inputBlock.type == Blockly.NEXT_STATEMENT) {
return Blockly.Msg.BLOCK;
} else {
return Blockly.Msg.VALUE;
}
},
getBlockDescription: function(block) {
// We use 'BLANK' instead of the default '?' so that the string is read
// out. (By default, screen readers tend to ignore punctuation.)
@@ -65,8 +49,5 @@ blocklyApp.UtilsService = ng.core.Class({
},
isWorkspaceEmpty: function() {
return !blocklyApp.workspace.topBlocks_.length;
},
getBlockById: function(blockId) {
return blocklyApp.workspace.getBlockById(blockId);
}
});

View File

@@ -53,7 +53,7 @@ blocklyApp.WorkspaceTreeComponent = ng.core.Component({
[attr.aria-labelledBy]="generateAriaLabelledByAttr(idMap['inputMenuLabel' + i], 'blockly-submenu-indicator')"
[attr.aria-level]="level + 1">
<label [id]="idMap['inputMenuLabel' + i]">
{{utilsService.getInputTypeLabel(blockInput.connection)}} {{utilsService.getBlockTypeLabel(blockInput)}} needed:
{{getBlockNeededLabel(blockInput)}}
</label>
<button [id]="idMap[fieldButtonsInfo[0].baseIdKey + 'Button' + i]"
(click)="fieldButtonsInfo[0].action(blockInput.connection)"
@@ -200,5 +200,15 @@ blocklyApp.WorkspaceTreeComponent = ng.core.Component({
generateAriaLabelledByAttr: function(mainLabel, secondLabel) {
return this.utilsService.generateAriaLabelledByAttr(
mainLabel, secondLabel);
},
getBlockNeededLabel: function(blockInput) {
// The input type name, or 'any' if any official input type qualifies.
var inputTypeLabel = (
blockInput.connection.check_ ?
blockInput.connection.check_.join(', ') : Blockly.Msg.ANY);
var blockTypeLabel = (
blockInput.type == Blockly.NEXT_STATEMENT ?
Blockly.Msg.BLOCK : Blockly.Msg.VALUE);
return inputTypeLabel + ' ' + blockTypeLabel + ' needed:';
}
});