Skip to content
This repository was archived by the owner on Jul 24, 2019. It is now read-only.

Search Block #16

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/assets/sass/scratch/_toolbox.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
@import '../base/mixins';

$category-colours: (
search : #afffda,
trade-definition: #303f9f,
before-purchase : #00897b,
during-purchase : #78909c,
after-purchase : #d81b60,
mathematical : #689f38,
logic : #8e24aa,
text : #fb8c00,
variables : #5d4037,
functions : #1976d2,
loop : #e53935,
list : #00acc1,
indicators : #616161,
time : #afb42b,
tick-analysis : #2e7d32,
candle : #5e35b1,
miscellaneous : #ffb300,
trade_parameters : #30409f,
purchase_conditions: #00897b,
sell_conditions : #78909c,
Expand Down Expand Up @@ -144,6 +161,13 @@ $category-colours: (
}
}
}

#search_input {
padding: 10px;
border-radius: 5px;
border: solid $grey 1px;
margin: 3px;
}
&__separator {
padding: 20px 0;
border-top: 1px solid $lightgrey;
Expand Down
26 changes: 24 additions & 2 deletions src/scratch/blocks/Advanced/Functions/procedures_callnoreturn.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,16 @@ Blockly.Blocks.procedures_callnoreturn = {
this.argumentVarModels = [];
this.previousDisabledState = false;

this.jsonInit({
this.jsonInit(this.definition());
},
/**
* Block definitions describe how a block looks and behaves, including the text,
* the colour, the shape, and what other blocks it can connect to. We've separated
* the block definition from the init function so we can search through it.
* https://developers.google.com/blockly/guides/create-custom-blocks/define-blocks
*/
definition() {
return {
message0: '%1 %2',
args0 : [
{
Expand All @@ -25,7 +34,20 @@ Blockly.Blocks.procedures_callnoreturn = {
colourTertiary : Blockly.Colours.BinaryProcedures.colourTertiary,
previousStatement: null,
nextStatement : null,
});
tooltip : translate('Function with no return value tooltip'),
category : Blockly.Categories.Functions,
};
},
/**
* Meta returns an object with with properties that contain human readable strings,
* these strings are used in the flyout help content, as well as used for searching
* for specific blocks.
*/
meta() {
return {
'display_name': translate('Function With no Return name'),
'description' : translate('Function with no return value description'),
};
},
/**
* Procedure calls cannot exist without the corresponding procedure
Expand Down
17 changes: 15 additions & 2 deletions src/scratch/blocks/Advanced/Functions/procedures_callreturn.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { translate } from '../../../../utils/lang/i18n';

Blockly.Blocks.procedures_callreturn = {
init() {
this.arguments = [];
this.previousDisabledState = false;

this.jsonInit({
this.jsonInit(this.definition());
},
definition(){
return {
message0: '%1 %2',
args0 : [
{
Expand All @@ -20,7 +25,15 @@ Blockly.Blocks.procedures_callreturn = {
colour : Blockly.Colours.BinaryProcedures.colour,
colourSecondary: Blockly.Colours.BinaryProcedures.colourSecondary,
colourTertiary : Blockly.Colours.BinaryProcedures.colourTertiary,
});
tooltip : translate('Function with return value'),
category : Blockly.Categories.Functions,
};
},
meta(){
return {
'display_name': translate('Function with return value'),
'description' : translate('Function with return value Description'),
};
},
onchange : Blockly.Blocks.procedures_callnoreturn.onchange,
getProcedureDefinition: Blockly.Blocks.procedures_callnoreturn.getProcedureDefinition,
Expand Down
35 changes: 23 additions & 12 deletions src/scratch/blocks/Advanced/Functions/procedures_defnoreturn.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,20 @@ Blockly.Blocks.procedures_defnoreturn = {
this.arguments = [];
this.argumentVarModels = [];

this.jsonInit({
this.jsonInit(this.definition());

// Enforce unique procedure names
const nameField = this.getField('NAME');
nameField.setValidator(Blockly.Procedures.rename);

// Render a ➕-icon for adding parameters
const fieldImage = new Blockly.FieldImage(plusIconLight, 24, 24, '+', () => this.onAddClick());
this.appendDummyInput('ADD_ICON').appendField(fieldImage);

this.setStatements(true);
},
definition() {
return {
message0: translate('function %1 %2'),
args0 : [
{
Expand All @@ -24,17 +37,15 @@ Blockly.Blocks.procedures_defnoreturn = {
colour : Blockly.Colours.BinaryProcedures.colour,
colourSecondary: Blockly.Colours.BinaryProcedures.colourSecondary,
colourTertiary : Blockly.Colours.BinaryProcedures.colourTertiary,
});

// Enforce unique procedure names
const nameField = this.getField('NAME');
nameField.setValidator(Blockly.Procedures.rename);

// Render a ➕-icon for adding parameters
const fieldImage = new Blockly.FieldImage(plusIconLight, 24, 24, '+', () => this.onAddClick());
this.appendDummyInput('ADD_ICON').appendField(fieldImage);

this.setStatements(true);
tooltip : translate('function with no return tooltip'),
category : Blockly.Categories.Functions,
};
},
meta() {
return {
'display_name': translate('Function with no return value'),
'description' : translate('Function with no return value description'),
};
},
/**
* Sets the block colour and updates this procedure's caller blocks
Expand Down
37 changes: 24 additions & 13 deletions src/scratch/blocks/Advanced/Functions/procedures_defreturn.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,21 @@ Blockly.Blocks.procedures_defreturn = {
this.arguments = [];
this.argumentVarModels = [];

this.jsonInit({
this.jsonInit(this.definition());

// Enforce unique procedure names
const nameField = this.getField('NAME');
nameField.setValidator(Blockly.Procedures.rename);

// Render a ➕-icon for adding parameters
const fieldImage = new Blockly.FieldImage(plusIconDark, 24, 24, '+', () => this.onAddClick());
this.appendDummyInput('ADD_ICON').appendField(fieldImage);
this.moveInputBefore('ADD_ICON', 'RETURN');

this.setStatements(true);
},
definition(){
return {
message0: translate('function %1 %2 %3'),
message1: 'return %1',
args0 : [
Expand Down Expand Up @@ -35,18 +49,15 @@ Blockly.Blocks.procedures_defreturn = {
colour : Blockly.Colours.BinaryProcedures.colour,
colourSecondary: Blockly.Colours.BinaryProcedures.colourSecondary,
colourTertiary : Blockly.Colours.BinaryProcedures.colourTertiary,
});

// Enforce unique procedure names
const nameField = this.getField('NAME');
nameField.setValidator(Blockly.Procedures.rename);

// Render a ➕-icon for adding parameters
const fieldImage = new Blockly.FieldImage(plusIconDark, 24, 24, '+', () => this.onAddClick());
this.appendDummyInput('ADD_ICON').appendField(fieldImage);
this.moveInputBefore('ADD_ICON', 'RETURN');

this.setStatements(true);
tooltip : translate('Function def with return value'),
category : Blockly.Categories.Functions,
};
},
meta(){
return {
'display_name': translate('Function def with return value'),
'description' : translate('Function def with return value Description'),
};
},
onAddClick : Blockly.Blocks.procedures_defnoreturn.onAddClick,
onchange : Blockly.Blocks.procedures_defnoreturn.onchange,
Expand Down
15 changes: 13 additions & 2 deletions src/scratch/blocks/Advanced/Functions/procedures_ifreturn.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ Blockly.Blocks.procedures_ifreturn = {
init() {
this.hasReturnValue = true;

this.jsonInit({
this.jsonInit(this.definition());
},
definition(){
return {
message0: translate('if %1 return %2'),
args0 : [
{
Expand All @@ -26,7 +29,15 @@ Blockly.Blocks.procedures_ifreturn = {
colourTertiary : Blockly.Colours.BinaryProcedures.colourTertiary,
previousStatement: null,
nextStatement : null,
});
tooltip : translate('Function If Else'),
category : Blockly.Categories.Functions,
};
},
meta(){
return {
'display_name': translate('Function If else'),
'description' : translate('Function If else Description'),
};
},
/**
* Create XML to represent whether this block has a return value.
Expand Down
25 changes: 18 additions & 7 deletions src/scratch/blocks/Advanced/List/lists_create_with.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@ import { translate } from '../../../../utils/lang/i18n';

Blockly.Blocks.lists_create_with = {
init() {
this.jsonInit({
this.jsonInit(this.definition());

// Render a ➕-icon for adding additional `lists_statement` blocks
const fieldImage = new Blockly.FieldImage(plusIconDark, 25, 25, '', () => this.onIconClick());
this.appendDummyInput('ADD_ICON').appendField(fieldImage);
this.moveInputBefore('ADD_ICON', 'STACK');
},
definition(){
return {
message0: translate('set %1 to create list with'),
message1: '%1',
args0 : [
Expand All @@ -24,12 +32,15 @@ Blockly.Blocks.lists_create_with = {
colourTertiary : Blockly.Colours.Binary.colourTertiary,
previousStatement: null,
nextStatement : null,
});

// Render a ➕-icon for adding additional `lists_statement` blocks
const fieldImage = new Blockly.FieldImage(plusIconDark, 25, 25, '', () => this.onIconClick());
this.appendDummyInput('ADD_ICON').appendField(fieldImage);
this.moveInputBefore('ADD_ICON', 'STACK');
tooltip : translate('Create List with'),
category : Blockly.Categories.List,
};
},
meta(){
return {
'display_name': translate('Create list with'),
'description' : translate('Create list with description'),
};
},
onIconClick() {
if (!this.workspace || this.isInFlyout) {
Expand Down
6 changes: 6 additions & 0 deletions src/scratch/blocks/Advanced/List/lists_getIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ Blockly.Blocks.lists_getIndex = {

this.updateAt(true);
},
meta(){
return {
'display_name': translate('List Get Index'),
'description' : translate('List Get Index Description'),
};
},
mutationToDom() {
const container = document.createElement('mutation');
const isStatement = !this.outputConnection;
Expand Down
6 changes: 6 additions & 0 deletions src/scratch/blocks/Advanced/List/lists_getSublist.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ Blockly.Blocks.lists_getSublist = {
this.updateAt(1, true);
this.updateAt(2, true);
},
meta() {
return {
'display_name': translate('List get sublit'),
'description' : translate('List get sublist description'),
};
},
mutationToDom() {
const container = document.createElement('mutation');
const isAt1 = this.getInput('AT1').type === Blockly.INPUT_VALUE;
Expand Down
15 changes: 13 additions & 2 deletions src/scratch/blocks/Advanced/List/lists_indexOf.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { translate } from '../../../../utils/lang/i18n';

Blockly.Blocks.lists_indexOf = {
init() {
this.jsonInit({
this.jsonInit(this.definition());
},
definition(){
return {
message0: translate('in list %1 find %2 occurence of item %3'),
args0 : [
{
Expand All @@ -24,7 +27,15 @@ Blockly.Blocks.lists_indexOf = {
colour : Blockly.Colours.Binary.colour,
colourSecondary: Blockly.Colours.Binary.colourSecondary,
colourTertiary : Blockly.Colours.Binary.colourTertiary,
});
tooltip : translate('Index of List Tooltip'),
category : Blockly.Categories.List,
};
},
meta(){
return {
'display_name': translate('Index Of List'),
'description' : translate('Index of List Description'),
};
},
};

Expand Down
15 changes: 13 additions & 2 deletions src/scratch/blocks/Advanced/List/lists_isEmpty.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { translate } from '../../../../utils/lang/i18n';

Blockly.Blocks.lists_isEmpty = {
init() {
this.jsonInit({
this.jsonInit(this.definition());
},
definition(){
return {
message0: translate('list %1 is empty'),
args0 : [
{
Expand All @@ -16,7 +19,15 @@ Blockly.Blocks.lists_isEmpty = {
colour : Blockly.Colours.Binary.colour,
colourSecondary: Blockly.Colours.Binary.colourSecondary,
colourTertiary : Blockly.Colours.Binary.colourTertiary,
});
tooltip : translate('List is Empty Tooltip'),
category : Blockly.Categories.List,
};
},
meta(){
return {
'display_name': translate('List is Empty'),
'description' : translate('List is empty Description'),
};
},
};

Expand Down
15 changes: 13 additions & 2 deletions src/scratch/blocks/Advanced/List/lists_length.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { translate } from '../../../../utils/lang/i18n';

Blockly.Blocks.lists_length = {
init() {
this.jsonInit({
this.jsonInit(this.definition());
},
definition(){
return {
message0: translate('length of %1'),
args0 : [
{
Expand All @@ -15,7 +18,15 @@ Blockly.Blocks.lists_length = {
colour : Blockly.Colours.Binary.colour,
colourSecondary: Blockly.Colours.Binary.colourSecondary,
colourTertiary : Blockly.Colours.Binary.colourTertiary,
});
tooltip : translate('List Length Tooltip'),
category : Blockly.Categories.List,
};
},
meta(){
return {
'display_name': translate('List Length'),
'description' : translate('List Length Description'),
};
},
};

Expand Down
Loading