diff --git a/demos/blocklyfactory/app_controller.js b/demos/blocklyfactory/app_controller.js index 4e05e720f..2c195d510 100644 --- a/demos/blocklyfactory/app_controller.js +++ b/demos/blocklyfactory/app_controller.js @@ -47,6 +47,16 @@ AppController = function() { // Initialize Block Exporter this.exporter = new BlockExporterController(this.blockLibraryController.storage); + + // Map of tab type to the div element for the tab. + this.tabMap = { + 'BLOCK_FACTORY' : goog.dom.getElement('blockFactory_tab'), + 'WORKSPACE_FACTORY': goog.dom.getElement('workspaceFactory_tab'), + 'EXPORTER' : goog.dom.getElement('blocklibraryExporter_tab') + }; + + // Selected tab. + this.selectedTab = 'BLOCK_FACTORY'; }; /** @@ -197,71 +207,92 @@ AppController.prototype.onSelectedBlockChanged = function(blockLibraryDropdown) }; /** - * Add tab handlers to allow switching between the Block Factory - * tab and the Block Exporter tab. + * Add click handlers to each tab to allow switching between the Block Factory, + * Workspace Factory, and Block Exporter tab. * - * @param {string} blockFactoryTabID - ID of element containing Block Factory - * tab - * @param {string} blockExporterTabID - ID of element containing Block - * Exporter tab + * @param {!Object} tabMap - Map of tab name to div element that is the tab. */ -AppController.prototype.addTabHandlers = - function(blockFactoryTabID, blockExporterTabID) { - // Assign this instance of Block Factory Expansion to self in order to - // keep the reference to this object upon tab click. +AppController.prototype.addTabHandlers = function(tabMap) { var self = this; - // Get div elements representing tabs - var blockFactoryTab = goog.dom.getElement(blockFactoryTabID); - var blockExporterTab = goog.dom.getElement(blockExporterTabID); - // Add event listeners. - blockFactoryTab.addEventListener('click', - function() { - self.onFactoryTab(blockFactoryTab, blockExporterTab); - }); - blockExporterTab.addEventListener('click', - function() { - self.onExporterTab(blockFactoryTab, blockExporterTab); - }); + for (var tabName in tabMap) { + var tab = tabMap[tabName]; + // Use an additional closure to correctly assign the tab callback. + tab.addEventListener('click', self.makeTabClickHandler_(tabName)); + } }; /** - * Tied to 'Block Factory' Tab. Shows Block Factory and Block Library. + * Set the selected tab. + * @private * - * @param {string} blockFactoryTab - div element that is the Block Factory tab - * @param {string} blockExporterTab - div element that is the Block Exporter tab + * @param {string} tabName 'BLOCK_FACTORY', 'WORKSPACE_FACTORY', or 'EXPORTER' */ -AppController.prototype.onFactoryTab = - function(blockFactoryTab, blockExporterTab) { - // Turn factory tab on and exporter tab off. - goog.dom.classlist.addRemove(blockFactoryTab, 'taboff', 'tabon'); - goog.dom.classlist.addRemove(blockExporterTab, 'tabon', 'taboff'); - - // Hide container of exporter. - BlockFactory.hide('blockLibraryExporter'); - - // Resize to render workspaces' toolboxes correctly. - window.dispatchEvent(new Event('resize')); +AppController.prototype.setSelected_ = function(tabName) { + this.selectedTab = tabName; }; /** - * Tied to 'Block Exporter' Tab. Shows Block Exporter. + * Creates the tab click handler specific to the tab specified. + * @private * - * @param {string} blockFactoryTab - div element that is the Block Factory tab - * @param {string} blockExporterTab - div element that is the Block Exporter tab + * @param {string} tabName 'BLOCK_FACTORY', 'WORKSPACE_FACTORY', or 'EXPORTER' + * @return {Function} The tab click handler. */ -AppController.prototype.onExporterTab = - function(blockFactoryTab, blockExporterTab) { - // Turn exporter tab on and factory tab off. - goog.dom.classlist.addRemove(blockFactoryTab, 'tabon', 'taboff'); - goog.dom.classlist.addRemove(blockExporterTab, 'taboff', 'tabon'); +AppController.prototype.makeTabClickHandler_ = function(tabName) { + var self = this; + return function() { + self.setSelected_(tabName); + self.onTab(); + }; +}; - // Update toolbox to reflect current block library. - this.exporter.updateToolbox(); +/** + * Called on each tab click. Hides and shows specific content based on which tab + * (Block Factory, Workspace Factory, or Exporter) is selected. + * + * TODO(quachtina96): Refactor the code to avoid repetition of addRemove. + */ +AppController.prototype.onTab = function() { + // Get tab div elements. + var blockFactoryTab = this.tabMap['BLOCK_FACTORY']; + var exporterTab = this.tabMap['EXPORTER']; + var workspaceFactoryTab = this.tabMap['WORKSPACE_FACTORY']; - // Show container of exporter. - BlockFactory.show('blockLibraryExporter'); + if (this.selectedTab == 'EXPORTER') { + // Turn exporter tab on and other tabs off. + goog.dom.classlist.addRemove(exporterTab, 'taboff', 'tabon'); + goog.dom.classlist.addRemove(blockFactoryTab, 'tabon', 'taboff'); + goog.dom.classlist.addRemove(workspaceFactoryTab, 'tabon', 'taboff'); - // Resize to render workspaces' toolboxes correctly. + // Update toolbox to reflect current block library. + this.exporter.updateToolbox(); + + // Show container of exporter. + BlockFactory.show('blockLibraryExporter'); + BlockFactory.hide('workspaceFactoryContent'); + + } else if (this.selectedTab == 'BLOCK_FACTORY') { + // Turn factory tab on and other tabs off. + goog.dom.classlist.addRemove(blockFactoryTab, 'taboff', 'tabon'); + goog.dom.classlist.addRemove(exporterTab, 'tabon', 'taboff'); + goog.dom.classlist.addRemove(workspaceFactoryTab, 'tabon', 'taboff'); + + // Hide container of exporter. + BlockFactory.hide('blockLibraryExporter'); + BlockFactory.hide('workspaceFactoryContent'); + + } else if (this.selectedTab == 'WORKSPACE_FACTORY') { + console.log('workspaceFactoryTab'); + goog.dom.classlist.addRemove(workspaceFactoryTab, 'taboff', 'tabon'); + goog.dom.classlist.addRemove(blockFactoryTab, 'tabon', 'taboff'); + goog.dom.classlist.addRemove(exporterTab, 'tabon', 'taboff'); + // Hide container of exporter. + BlockFactory.hide('blockLibraryExporter'); + // Show workspace factory container. + BlockFactory.show('workspaceFactoryContent'); + } + + // Resize to render workspaces' toolboxes correctly for all tabs. window.dispatchEvent(new Event('resize')); }; @@ -273,13 +304,13 @@ AppController.prototype.assignExporterClickHandlers = function() { // Export blocks when the user submits the export settings. document.getElementById('exporterSubmitButton').addEventListener('click', function() { - self.exporter.exportBlocks(); + self.exporter.export(); }); document.getElementById('clearSelectedButton').addEventListener('click', function() { self.exporter.clearSelectedBlocks(); }); - document.getElementById('addAllButton').addEventListener('click', + document.getElementById('addAllFromLibButton').addEventListener('click', function() { self.exporter.addAllBlocksToWorkspace(); }); @@ -435,7 +466,7 @@ AppController.prototype.init = function() { media: '../../media/'}); // Add tab handlers for switching between Block Factory and Block Exporter. - this.addTabHandlers("blockfactory_tab", "blocklibraryExporter_tab"); + this.addTabHandlers(this.tabMap); this.exporter.addChangeListenersToSelectorWorkspace(); diff --git a/demos/blocklyfactory/block_exporter_controller.js b/demos/blocklyfactory/block_exporter_controller.js index 04892e5d8..10e7601ce 100644 --- a/demos/blocklyfactory/block_exporter_controller.js +++ b/demos/blocklyfactory/block_exporter_controller.js @@ -90,20 +90,47 @@ BlockExporterController.prototype.getSelectedBlockTypes_ = function() { /** * Get selected blocks from selector workspace, pulls info from the Export - * Settings form in Block Exporter, and downloads block code accordingly. + * Settings form in Block Exporter, and downloads code accordingly. + * + * TODO(quachtina96): allow export as zip. */ -BlockExporterController.prototype.exportBlocks = function() { +BlockExporterController.prototype.export = function() { + // Get selected blocks' information. var blockTypes = this.getSelectedBlockTypes_(); var blockXmlMap = this.blockLibStorage.getBlockXmlMap(blockTypes); - // Pull inputs from the Export Settings form. + // Pull workspace-related settings from the Export Settings form. + var wantToolbox = document.getElementById('toolboxCheck').checked; + var wantPreloadedWorkspace = + document.getElementById('preloadedWorkspaceCheck').checked; + var wantWorkspaceOptions = + document.getElementById('workspaceOptsCheck').checked; + + // Pull block definition(s) settings from the Export Settings form. + var wantBlockDef = document.getElementById('blockDefCheck').checked; var definitionFormat = document.getElementById('exportFormat').value; - var language = document.getElementById('exportLanguage').value; var blockDef_filename = document.getElementById('blockDef_filename').value; + + // Pull block generator stub(s) settings from the Export Settings form. + var wantGenStub = document.getElementById('genStubCheck').checked; + var language = document.getElementById('exportLanguage').value; var generatorStub_filename = document.getElementById( 'generatorStub_filename').value; - var wantBlockDef = document.getElementById('blockDefCheck').checked; - var wantGenStub = document.getElementById('genStubCheck').checked; + + if (wantToolbox) { + // TODO(quachtina96): create and download file once wfactory has been + // integrated. + } + + if (wantPreloadedWorkspace) { + // TODO(quachtina96): create and download file once wfactory has been + // integrated. + } + + if (wantWorkspaceOptions) { + // TODO(quachtina96): create and download file once wfactory has been + // integrated. + } if (wantBlockDef) { // User wants to export selected blocks' definitions. @@ -134,6 +161,7 @@ BlockExporterController.prototype.exportBlocks = function() { genStubs, generatorStub_filename, language); } } + }; /** diff --git a/demos/blocklyfactory/block_exporter_tools.js b/demos/blocklyfactory/block_exporter_tools.js index 65c50ddad..dc88cb8ea 100644 --- a/demos/blocklyfactory/block_exporter_tools.js +++ b/demos/blocklyfactory/block_exporter_tools.js @@ -179,6 +179,7 @@ BlockExporterTools.prototype.addBlockDefinitions = function(blockXmlMap) { * Pulls information about all blocks in the block library to generate xml * for the selector workpace's toolbox. * + * @param {!BlockLibraryStorage} blockLibStorage - Block Library Storage object. * @return {!Element} Xml representation of the toolbox. */ BlockExporterTools.prototype.generateToolboxFromLibrary diff --git a/demos/blocklyfactory/factory.css b/demos/blocklyfactory/factory.css index 171e7927e..d2a72bc64 100644 --- a/demos/blocklyfactory/factory.css +++ b/demos/blocklyfactory/factory.css @@ -161,6 +161,16 @@ button, .buttonStyle { width: 50%; } +/* Workspace Factory */ + +#workspaceFactoryContent { + clear: both; + display: none; + height: 100%; +} + +/* Exporter */ + #blockLibraryExporter { clear: both; display: none; @@ -170,12 +180,13 @@ button, .buttonStyle { #exportSelector { float: left; height: 75%; - width: 60%; + width: 30%; } #exportSettings { - margin: auto; + float: left; padding: 16px; + width: 30%; overflow: hidden; } @@ -183,6 +194,13 @@ button, .buttonStyle { display: none; } +#exporterPreview { + float: right; + padding: 16px; + overflow: hidden; + background-color: blue; +} + /* Tabs */ .tab { diff --git a/demos/blocklyfactory/index.html b/demos/blocklyfactory/index.html index 4ebe83837..86c2ef442 100644 --- a/demos/blocklyfactory/index.html +++ b/demos/blocklyfactory/index.html @@ -40,27 +40,41 @@ Demos > Blockly Factory
-
Block Factory
+
Block Factory
-
Block Library Exporter
+
Workspace Factory
+
+
Exporter
-
- - -
+

Block Selector

Drag blocks into your workspace to select them for download.

+
+ + + +
-

Block Export Settings

+

Export Settings


- Download Block Definition: + Toolbox Xml: + +
+ Pre-loaded Workspace: + +
+ Workspace Option(s): + +
+
+ Block Definition(s):
Language code:
Block Definition(s) File Name:
-
+
- Download Generator Stubs: +
+ Generator Stub(s):