Skip to content

Commit

Permalink
Merge pull request #29400 from code-dot-org/dtl_candidate_f5111ebd
Browse files Browse the repository at this point in the history
  • Loading branch information
deploy-code-org committed Jun 27, 2019
2 parents f7a4b6d + f5111eb commit fe4686a
Show file tree
Hide file tree
Showing 238 changed files with 92,067 additions and 32,232 deletions.
1 change: 0 additions & 1 deletion apps/i18n/common/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@
"cleverForceConnectDialogTitle": "Link your Clever login to your Code.org account",
"cleverForceConnectDialogContent": "It looks like you already have a Code.org account that uses the same email address as your Clever account. Click the \"Link my account\" button and then log into your existing Code.org account. This will connect your Clever login with your existing Code.org account so that you can use Clever to log into the Code.org account in the future.",
"clickToRemix": "Click \"Remix\" to spin-off your own version!",
"chooseDataset": "Choose Dataset",
"chooseSection": "Choose Section",
"chooseSounds": "Choose Sounds",
"code": "Code:",
Expand Down
2 changes: 2 additions & 0 deletions apps/src/applab/DesignModeBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default class DesignModeBox extends React.Component {
onDelete: PropTypes.func.isRequired,
onDepthChange: PropTypes.func.isRequired,
onDuplicate: PropTypes.func.isRequired,
onRestoreThemeDefaults: PropTypes.func.isRequired,
onInsertEvent: PropTypes.func.isRequired,
screenIds: PropTypes.arrayOf(PropTypes.string).isRequired
};
Expand Down Expand Up @@ -75,6 +76,7 @@ export default class DesignModeBox extends React.Component {
onChangeElement={this.props.onChangeElement}
onDepthChange={this.props.onDepthChange}
onDuplicate={this.props.onDuplicate}
onRestoreThemeDefaults={this.props.onRestoreThemeDefaults}
onDelete={this.props.onDelete}
onInsertEvent={this.props.onInsertEvent}
screenIds={this.props.screenIds}
Expand Down
2 changes: 2 additions & 0 deletions apps/src/applab/DesignWorkspace.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class DesignWorkspace extends React.Component {
onChangeElement: PropTypes.func.isRequired,
onDepthChange: PropTypes.func.isRequired,
onDuplicate: PropTypes.func.isRequired,
onRestoreThemeDefaults: PropTypes.func.isRequired,
onDelete: PropTypes.func.isRequired,
onInsertEvent: PropTypes.func.isRequired,
isDimmed: PropTypes.bool.isRequired,
Expand Down Expand Up @@ -60,6 +61,7 @@ class DesignWorkspace extends React.Component {
onDelete={this.props.onDelete}
onDepthChange={this.props.onDepthChange}
onDuplicate={this.props.onDuplicate}
onRestoreThemeDefaults={this.props.onRestoreThemeDefaults}
onInsertEvent={this.props.onInsertEvent}
screenIds={this.props.screenIds}
/>
Expand Down
8 changes: 0 additions & 8 deletions apps/src/applab/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,6 @@ export function open(url) {
return Applab.executeCmd(null, 'openUrl', {url: url});
}

export function getList(tableName, columnName, callback) {
return Applab.executeCmd(null, 'getList', {
tableName: tableName,
columnName: columnName,
callback: callback
});
}

export function startWebRequest(url, func) {
return Applab.executeCmd(null, 'startWebRequest', {url: url, func: func});
}
Expand Down
87 changes: 1 addition & 86 deletions apps/src/applab/applab.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import {Provider} from 'react-redux';
import {getStore} from '../redux';
import {actions, reducers} from './redux/applab';
import {add as addWatcher} from '../redux/watchedExpressions';
import {setApplabLibraries} from '../code-studio/components/applabLibraryRedux';
import {changeScreen} from './redux/screens';
import * as applabConstants from './constants';
const {ApplabInterfaceMode} = applabConstants;
Expand Down Expand Up @@ -323,11 +322,6 @@ Applab.getHtml = function() {
return Applab.levelHtml;
};

Applab.getLibraries = function() {
var libraries = getStore().getState().applabLibrary.libraries;
return libraries.length ? libraries : undefined;
};

/**
* Sets Applab.levelHtml as well as #designModeViz contents.
* designModeViz is the source of truth for the app's HTML.
Expand Down Expand Up @@ -406,8 +400,6 @@ Applab.init = function(config) {
// replace studioApp methods with our own
studioApp().reset = this.reset.bind(this);
studioApp().runButtonClick = this.runButtonClick.bind(this);
config.getLibrary = getLibrary;
config.codeContainsError = codeContainsError;

config.runButtonClickWrapper = runButtonClickWrapper;

Expand All @@ -418,8 +410,7 @@ Applab.init = function(config) {
if (config.level.editBlocks) {
header.showLevelBuilderSaveButton(() => ({
start_blocks: Applab.getCode(),
start_html: Applab.getHtml(),
start_libraries: Applab.getLibraries()
start_html: Applab.getHtml()
}));
}
Applab.channelId = config.channel;
Expand Down Expand Up @@ -546,7 +537,6 @@ Applab.init = function(config) {
config.afterClearPuzzle = function() {
designMode.resetIds();
Applab.setLevelHtml(config.level.startHtml || '');
getStore().dispatch(setApplabLibraries(config.level.startLibraries));
Applab.storage.populateTable(level.dataTables, true, () => {}, outputError); // overwrite = true
Applab.storage.populateKeyValue(
level.dataProperties,
Expand Down Expand Up @@ -701,39 +691,6 @@ Applab.init = function(config) {
});
}

var librariesExist = level.libraries && level.libraries.length > 0;

if (
!librariesExist &&
level.startLibraries &&
level.startLibraries.length > 0
) {
level.libraries = level.startLibraries;
librariesExist = true;
}

// Libraries should be added to redux whether the experiment is enabled or
// not. This prevents work from being lost if a levelbuilder toggles the
// experiment flag.
if (librariesExist) {
getStore().dispatch(setApplabLibraries(level.libraries));
}

if (experiments.isEnabled('student-libraries') && librariesExist) {
level.libraries.forEach(library => {
config.dropletConfig.additionalPredefValues.push(library.name);
});
let importedConfigs = level.libraries
.map(library => library.dropletConfig)
.reduce((a, b) => a.concat(b));
if (importedConfigs) {
Object.keys(importedConfigs).map(key => {
config.dropletConfig.blocks.push(importedConfigs[key]);
level.codeFunctions[importedConfigs[key].func] = null;
});
}
}

// Set the custom set of blocks (may have had maker blocks merged in) so
// we can later pass the custom set to the interpreter.
config.level.levelBlocks = config.dropletConfig.blocks;
Expand Down Expand Up @@ -1152,26 +1109,6 @@ Applab.onReportComplete = function(response) {
displayFeedback();
};

/**
* Generates a library from the functions in the project code
*/
function getLibrary() {
var temporaryInterpreter = new JSInterpreter({studioApp: studioApp()});
temporaryInterpreter.parse({code: studioApp().getCode()});
return temporaryInterpreter.getFunctionsAndParams(studioApp().getCode());
}

/**
* Returns true if a lint error (red gutter warning) exists in the code
*/
function codeContainsError() {
var errors = annotationList.getJSLintAnnotations().filter(annotation => {
return annotation.type === 'error';
});

return errors.length > 0;
}

/**
* Execute the app
*/
Expand Down Expand Up @@ -1214,28 +1151,6 @@ Applab.execute = function() {
}
getStore().dispatch(jsDebugger.attach(Applab.JSInterpreter));

// Set up student-created libraries
if (experiments.isEnabled('student-libraries')) {
getStore()
.getState()
.applabLibrary.libraries.map(library => {
var functionNames = library.functionNames
.map(name => {
return name + ': ' + name;
})
.join(',');
var libraryClosure =
'var ' +
library.name +
' = (function() {\n' +
library.source +
'\nreturn {' +
functionNames +
'};})();';
codeWhenRun = libraryClosure + codeWhenRun;
});
}

// Initialize the interpreter and parse the student code
Applab.JSInterpreter.parse({
code: codeWhenRun,
Expand Down
66 changes: 0 additions & 66 deletions apps/src/applab/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {getAppOptions} from '@cdo/apps/code-studio/initApp/loadApp';
import {AllowedWebRequestHeaders} from '@cdo/apps/util/sharedConstants';
import {actions} from './redux/applab';
import {getStore} from '../redux';
import datasetLibrary from '@cdo/apps/code-studio/datasetLibrary.json';
import $ from 'jquery';

// For proxying non-https xhr requests
Expand Down Expand Up @@ -1755,71 +1754,6 @@ applabCommands.handleReadValue = function(opts, value) {
}
};

applabCommands.getList = function(opts) {
validateGetListArgs(opts.tableName, opts.columnName);
var onSuccess = handleGetListSync.bind(this, opts);
var onError = handleGetListSyncError.bind(this, opts);
Applab.storage.readRecords(opts.tableName, {}, onSuccess, onError);
};

var validateGetListArgs = function(tableName, columnName) {
let dataset = datasetLibrary.datasets.find(d => d.name === tableName);
if (!dataset) {
outputWarning(
tableName +
' is not a data set in this project. Check the Data tab to see the names of your tables'
);
return;
}
const columnList = dataset.columns.split(',');
if (columnList.indexOf(columnName) === -1) {
outputWarning(
columnName +
' is not a column in ' +
tableName +
'. Check the Data tab to see the names of the columns in that table.'
);
}
};

var handleGetListSync = function(opts, values) {
let columnList = [];

if (values.length > 0) {
values.forEach(row => {
if (row.hasOwnProperty(opts.columnName)) {
columnList.push(row[opts.columnName]);
}
});
opts.callback(columnList);
return;
}

let url;
datasetLibrary.datasets.forEach(dataset => {
if (dataset.name === opts.tableName) {
url = dataset.url;
}
});
if (url) {
// Import the dataset, then try getList again.
Applab.storage.importDataset(
opts.tableName,
url,
() => applabCommands.getList(opts),
() => console.log('error')
);
} else {
// No dataset with the specified name, call back into interpreter and return the empty list.
opts.callback(columnList);
}
};

var handleGetListSyncError = function(opts, values) {
console.log('handleGetListSyncError');
opts.callback();
};

applabCommands.getKeyValueSync = function(opts) {
apiValidateType(opts, 'getKeyValueSync', 'key', opts.key, 'string');
var onSuccess = handleGetKeyValueSync.bind(this, opts);
Expand Down
36 changes: 36 additions & 0 deletions apps/src/applab/designElements/RestoreThemeDefaultsButton.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react';
import commonStyles from '../../commonStyles';
import PropTypes from 'prop-types';
import Radium from 'radium';

const styles = {
restoreButton: {
backgroundColor: '#0aa',
color: 'white',
float: 'right'
}
};

/**
* A restore theme defaults button
*/
class RestoreThemeDefaultsButton extends React.Component {
static propTypes = {
handleRestore: PropTypes.func.isRequired
};

render() {
const {handleRestore} = this.props;
return (
<button
type="button"
style={[commonStyles.button, styles.restoreButton]}
onClick={handleRestore}
>
Apply Theme
</button>
);
}
}

export default Radium(RestoreThemeDefaultsButton);
6 changes: 3 additions & 3 deletions apps/src/applab/designElements/button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,11 @@ export default {
designMode.activeScreen()
);
const fontSize = this.themeValues.fontSize[currentTheme];
const small = fontSize <= MAX_SMALL_FONT_SIZE;
element.style.height = small
const fontIsSmall = fontSize <= MAX_SMALL_FONT_SIZE;
element.style.height = fontIsSmall
? DEFAULT_BUTTON_HEIGHT_SMALL
: DEFAULT_BUTTON_HEIGHT;
element.style.width = small
element.style.width = fontIsSmall
? DEFAULT_BUTTON_WIDTH_SMALL
: DEFAULT_BUTTON_WIDTH;
elementLibrary.setAllPropertiesToCurrentTheme(
Expand Down
18 changes: 6 additions & 12 deletions apps/src/applab/designElements/screen.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,21 +210,15 @@ export default {
}
},
readProperty: function(element, name) {
switch (name) {
case 'theme':
return element.getAttribute('data-theme');
default:
throw `unknown property name ${name}`;
if (name === 'theme') {
return element.getAttribute('data-theme');
}
throw `unknown property name ${name}`;
},
onPropertyChange: function(element, name, value) {
switch (name) {
case 'theme': {
designMode.changeThemeForScreen(element, value);
return true;
}
default:
break;
if (name === 'theme') {
designMode.changeThemeForScreen(element, value);
return true;
}
return false;
}
Expand Down

0 comments on commit fe4686a

Please sign in to comment.