Change the TreeService to a singleton.

This commit is contained in:
Sean Lip
2016-06-13 17:58:13 -07:00
parent 6851baea12
commit 6c13b5c81b
5 changed files with 118 additions and 74 deletions

View File

@@ -37,27 +37,24 @@ blocklyApp.WorkspaceComponent = ng.core
{{buttonConfig.text}}
</button>
</span>
<button id="clear-workspace" (click)="workspace.clear()"
<button id="clear-workspace" (click)="clearWorkspace()"
[disabled]="isWorkspaceEmpty()" class="blocklyTree">
{{'CLEAR_WORKSPACE'|translate}}
</button>
</div>
<div *ngIf="workspace">
<ol #tree id="blockly-workspace-tree{{i}}" *ngFor="#block of workspace.topBlocks_; #i = index"
tabIndex="0" role="group" class="blocklyTree" [attr.aria-labelledby]="workspaceTitle.id"
[attr.aria-activedescendant]="tree.getAttribute('aria-activedescendant') || tree.id + '-node0' "
<ol #tree *ngFor="#block of workspace.topBlocks_; #i = index"
tabIndex="0" role="group" class="blocklyTree"
[attr.aria-labelledby]="workspaceTitle.id"
(keydown)="onKeypress($event, tree)">
<blockly-workspace-tree [level]=1 [block]="block" [isTopBlock]="true"
[topBlockIndex]="i" [parentId]="tree.id"
[tree]="tree">
<blockly-workspace-tree [level]=1 [block]="block" [tree]="tree">
</blockly-workspace-tree>
</ol>
</div>
`,
directives: [blocklyApp.WorkspaceTreeComponent],
pipes: [blocklyApp.TranslatePipe],
providers: [blocklyApp.TreeService]
pipes: [blocklyApp.TranslatePipe]
})
.Class({
constructor: [blocklyApp.TreeService, function(_treeService) {
@@ -72,14 +69,18 @@ blocklyApp.WorkspaceComponent = ng.core
this.workspace = blocklyApp.workspace;
this.treeService = _treeService;
}],
clearWorkspace: function() {
this.workspace.clear();
this.treeService.initTreeRegistry();
},
onWorkspaceToolbarKeypress: function(event) {
var activeElementId = document.activeElement.id;
this.treeService.onWorkspaceToolbarKeypress(event, activeElementId);
this.treeService.onWorkspaceToolbarKeypress(
event, document.activeElement.id);
},
onKeypress: function(event, tree){
this.treeService.onKeypress(event, tree);
},
isWorkspaceEmpty: function() {
return !blocklyApp.workspace.topBlocks_.length;
return !this.workspace.topBlocks_.length;
}
});