Skip to content

Commit 5ad99b7

Browse files
committed
add getDate and getTime, add "new" icon
1 parent 298295c commit 5ad99b7

7 files changed

Lines changed: 203 additions & 3 deletions

File tree

blocks/msg/en.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ goog.provide('Blockly.Msg.Webduino.en');
55
goog.require('Blockly.Msg.Webduino');
66

77
Blockly.Msg.CUSTOM_JS_CONSOLE = "Console:";
8+
Blockly.Msg.CUSTOM_JS_Date = "Date:";
9+
Blockly.Msg.CUSTOM_JS_Date_1 = "year / month / date";
10+
Blockly.Msg.CUSTOM_JS_Date_2 = "month / date / year";
11+
Blockly.Msg.CUSTOM_JS_Date_3 = "date / month / year";
12+
Blockly.Msg.CUSTOM_JS_Date_4 = "year";
13+
Blockly.Msg.CUSTOM_JS_Date_5 = "month";
14+
Blockly.Msg.CUSTOM_JS_Date_6 = "date";
15+
Blockly.Msg.CUSTOM_JS_Time = "Time:";
16+
Blockly.Msg.CUSTOM_JS_Time_1 = "hours : minutes : seconds";
17+
Blockly.Msg.CUSTOM_JS_Time_2 = "hours";
18+
Blockly.Msg.CUSTOM_JS_Time_3 = "minutes";
19+
Blockly.Msg.CUSTOM_JS_Time_4 = "seconds";
820

921
Blockly.Msg.WEBDUINO_TIMER_AFTER = "After";
1022
Blockly.Msg.WEBDUINO_TIMER_SECOND = "seconds";

blocks/msg/zh-hant.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ goog.provide('Blockly.Msg.Webduino.zh.hant');
55
goog.require('Blockly.Msg.Webduino');
66

77
Blockly.Msg.CUSTOM_JS_CONSOLE = "控制台顯示";
8+
Blockly.Msg.CUSTOM_JS_Date = "現在的日期";
9+
Blockly.Msg.CUSTOM_JS_Date_1 = "年 / 月 / 日";
10+
Blockly.Msg.CUSTOM_JS_Date_2 = "月 / 日 / 年";
11+
Blockly.Msg.CUSTOM_JS_Date_3 = "日 / 月 / 年";
12+
Blockly.Msg.CUSTOM_JS_Date_4 = "年";
13+
Blockly.Msg.CUSTOM_JS_Date_5 = "月";
14+
Blockly.Msg.CUSTOM_JS_Date_6 = "日";
15+
Blockly.Msg.CUSTOM_JS_Time = "現在的時間";
16+
Blockly.Msg.CUSTOM_JS_Time_1 = "時:分:秒";
17+
Blockly.Msg.CUSTOM_JS_Time_2 = "時";
18+
Blockly.Msg.CUSTOM_JS_Time_3 = "分";
19+
Blockly.Msg.CUSTOM_JS_Time_4 = "秒";
820

921
Blockly.Msg.WEBDUINO_TIMER_AFTER = "在";
1022
Blockly.Msg.WEBDUINO_TIMER_SECOND = "秒之後";

blocks/webduino.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,45 @@ Blockly.Blocks['console'] = {
1919
}
2020
};
2121

22+
/**
23+
* date and time
24+
* https://blockly-demo.appspot.com/static/demos/blockfactory/index.html#rrm4nf
25+
*/
26+
Blockly.Blocks['getdate'] = {
27+
init: function () {
28+
this.appendDummyInput()
29+
.appendField(Blockly.Msg.CUSTOM_JS_Date,"現在的日期")
30+
.appendField(new Blockly.FieldDropdown([
31+
[Blockly.Msg.CUSTOM_JS_Date_1, "1"],
32+
[Blockly.Msg.CUSTOM_JS_Date_2, "2"],
33+
[Blockly.Msg.CUSTOM_JS_Date_3, "3"],
34+
[Blockly.Msg.CUSTOM_JS_Date_4, "4"],
35+
[Blockly.Msg.CUSTOM_JS_Date_5, "5"],
36+
[Blockly.Msg.CUSTOM_JS_Date_6, "6"]
37+
]), "date_");
38+
this.setOutput(true);
39+
this.setTooltip('');
40+
this.setColour(20);
41+
this.setHelpUrl('http://www.example.com/');
42+
}
43+
};
44+
Blockly.Blocks['gettime'] = {
45+
init: function () {
46+
this.appendDummyInput()
47+
.appendField(Blockly.Msg.CUSTOM_JS_Time,"現在的時間")
48+
.appendField(new Blockly.FieldDropdown([
49+
[Blockly.Msg.CUSTOM_JS_Time_1, "1"],
50+
[Blockly.Msg.CUSTOM_JS_Time_2, "2"],
51+
[Blockly.Msg.CUSTOM_JS_Time_3, "3"],
52+
[Blockly.Msg.CUSTOM_JS_Time_4, "4"]
53+
]), "time_");
54+
this.setOutput(true);
55+
this.setTooltip('');
56+
this.setColour(20);
57+
this.setHelpUrl('http://www.example.com/');
58+
}
59+
};
60+
2261
Blockly.Blocks['board_ready'] = {
2362
init: function () {
2463
this.appendValueInput("device_")

generators/webduino.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,88 @@ Blockly.JavaScript['console'] = function (block) {
99
return code;
1010
};
1111

12+
Blockly.JavaScript['getdate'] = function (block) {
13+
var dropdown_date_ = block.getFieldValue('date_');
14+
var varNow = Blockly.JavaScript.variableDB_.getDistinctName(
15+
'varNow', Blockly.Variables.NAME_TYPE);
16+
var varDate = Blockly.JavaScript.variableDB_.getDistinctName(
17+
'varDate', Blockly.Variables.NAME_TYPE);
18+
var code;
19+
if (dropdown_date_ == 1) {
20+
code = '(function(){\n' +
21+
' var ' + varDate + ' = new Date();\n' +
22+
' var ' + varNow + ' = ' + varDate + '.getFullYear().toString() + "/" + (' + varDate + '.getMonth()+1).toString() + "/" +' + varDate + '.getDate().toString();\n' +
23+
' return ' + varNow + ';\n' +
24+
'})()';
25+
} else if (dropdown_date_ == 2) {
26+
code = '(function(){\n' +
27+
' var ' + varDate + ' = new Date();\n' +
28+
' var ' + varNow + ' = (' + varDate + '.getMonth()+1).toString() + "/" + ' + varDate + '.getDate().toString() + "/" +' + varDate + '.getFullYear().toString();\n' +
29+
' return ' + varNow + ';\n' +
30+
'})()';
31+
} else if (dropdown_date_ == 3) {
32+
code = '(function(){\n' +
33+
' var ' + varDate + ' = new Date();\n' +
34+
' var ' + varNow + ' = ' + varDate + '.getDate().toString() + "/" + (' + varDate + '.getMonth()+1).toString() + "/" +' + varDate + '.getFullYear().toString();\n' +
35+
' return ' + varNow + ';\n' +
36+
'})()';
37+
} else if (dropdown_date_ == 4) {
38+
code = '(function(){\n' +
39+
' var ' + varDate + ' = new Date();\n' +
40+
' var ' + varNow + ' = ' + varDate + '.getFullYear().toString();\n' +
41+
' return ' + varNow + ';\n' +
42+
'})()';
43+
} else if (dropdown_date_ == 5) {
44+
code = '(function(){\n' +
45+
' var ' + varDate + ' = new Date();\n' +
46+
' var ' + varNow + ' = ' + varDate + '.getMonth().toString();\n' +
47+
' return ' + varNow + ';\n' +
48+
'})()';
49+
} else if (dropdown_date_ == 6) {
50+
code = '(function(){\n' +
51+
' var ' + varDate + ' = new Date();\n' +
52+
' var ' + varNow + ' = ' + varDate + '.getDate().toString();\n' +
53+
' return ' + varNow + ';\n' +
54+
'})()';
55+
}
56+
return [code, Blockly.JavaScript.ORDER_ATOMIC];
57+
};
58+
59+
Blockly.JavaScript['gettime'] = function (block) {
60+
var dropdown_time_ = block.getFieldValue('time_');
61+
var varNow = Blockly.JavaScript.variableDB_.getDistinctName(
62+
'varNow', Blockly.Variables.NAME_TYPE);
63+
var varTime = Blockly.JavaScript.variableDB_.getDistinctName(
64+
'varTime', Blockly.Variables.NAME_TYPE);
65+
var code;
66+
if (dropdown_time_ == 1) {
67+
code = '(function(){\n' +
68+
' var ' + varTime + ' = new Date();\n' +
69+
' var ' + varNow + ' = ' + varTime + '.getHours().toString() + ":" + ' + varTime + '.getMinutes().toString() + ":" +' + varTime + '.getSeconds().toString();\n' +
70+
' return ' + varNow + ';\n' +
71+
'})()';
72+
} else if (dropdown_time_ == 2) {
73+
code = '(function(){\n' +
74+
' var ' + varTime + ' = new Date();\n' +
75+
' var ' + varNow + ' = ' + varTime + '.getHours().toString();\n' +
76+
' return ' + varNow + ';\n' +
77+
'})()';
78+
} else if (dropdown_time_ == 3) {
79+
code = '(function(){\n' +
80+
' var ' + varTime + ' = new Date();\n' +
81+
' var ' + varNow + ' = ' + varTime + '.getMinutes().toString();\n' +
82+
' return ' + varNow + ';\n' +
83+
'})()';
84+
} else if (dropdown_time_ == 4) {
85+
code = '(function(){\n' +
86+
' var ' + varTime + ' = new Date();\n' +
87+
' var ' + varNow + ' = ' + varTime + '.getSeconds().toString();\n' +
88+
' return ' + varNow + ';\n' +
89+
'})()';
90+
}
91+
return [code, Blockly.JavaScript.ORDER_ATOMIC];
92+
};
93+
1294
Blockly.JavaScript['board_ready'] = function (block) {
1395
var value_device_ = Blockly.JavaScript.valueToCode(block, 'device_', Blockly.JavaScript.ORDER_NONE);
1496
var statements_callbacks_ = Blockly.JavaScript.statementToCode(block, 'callbacks_');

index-tutorials.css

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ li h4 {
6464
}
6565

6666
li a {
67-
color: #ccc;
67+
color: #bbb;
6868
text-decoration: none;
6969
font-size: 14px;
7070
}
7171

7272
li a:hover {
73-
color: #bbb;
73+
color: #999;
7474
}
7575

7676
li h4 a {
@@ -79,6 +79,59 @@ li h4 a {
7979
border-bottom: 1px dotted #999;
8080
font-size: 20px;
8181
}
82+
li h4 i{
83+
position:relative;
84+
font-style: normal;
85+
font-weight: normal;
86+
display:inline-block;
87+
padding:1px 4px 2px 2px;
88+
background:#f00;
89+
color:#fff;
90+
font-size:12px;
91+
line-height: 12px;
92+
font-family: 'arial';
93+
margin-left:10px;
94+
margin-top:8px;
95+
vertical-align: top;
96+
animation:ai 1s infinite;
97+
-moz-animation:ai 1s infinite;
98+
-webkit-animation:ai 1s infinite;
99+
}
100+
@keyframes ai{
101+
0%{
102+
margin-left:10px;
103+
}
104+
50%{
105+
margin-left:14px;
106+
}
107+
}
108+
@-moz-keyframes ai{
109+
0%{
110+
margin-left:10px;
111+
}
112+
50%{
113+
margin-left:14px;
114+
}
115+
}
116+
@-webkit-keyframes ai{
117+
0%{
118+
margin-left:10px;
119+
}
120+
50%{
121+
margin-left:14px;
122+
}
123+
}
124+
li h4 i:before{
125+
content:'';
126+
position:absolute;
127+
top:0;
128+
left:-6px;
129+
width:0;
130+
height:0;
131+
border-style:solid;
132+
border-width:7px 6px 8px 0;
133+
border-color:transparent #f00 transparent transparent;
134+
}
82135

83136
li h4 a:hover {
84137
color: #f90;

index-tutorials.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ <h4><a href="./?lang=zh-hant&page=tutorials/ultrasonic-4" target="_blank">利用
7272
<div>( <a href="https://youtu.be/8lDL6_2io1Y" target="_blank">影片教學</a> | <a href="./?lang=zh-hant&page=tutorials/ultrasonic-4#-JvS1HjBSLU7wbtmLxKB" target="_blank">解答</a> )</div>
7373
</li>
7474
<li>
75-
<h4><a href="./?lang=zh-hant&page=tutorials/ultrasonic-5" target="_blank">利用超音波傳感器控制 Youtube 音量大小</a></h4> <div>(
75+
<h4><a href="./?lang=zh-hant&page=tutorials/ultrasonic-5" target="_blank">利用超音波傳感器控制 Youtube 音量大小</a><i>new</i></h4> <div>(
7676
<!-- <a href="#" target="_blank">影片教學</a> | --><a href="./?lang=zh-hant&page=tutorials/ultrasonic-5#-JwgqGd0PtGFPC8GNcfY" target="_blank">解答</a> )</div>
7777
</li>
7878
</ul>

views/index.handlebars

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@
260260
</category>
261261
<category id="catConsole">
262262
<block type="console"></block>
263+
<block type="getdate"></block>
264+
<block type="gettime"></block>
263265
</category>
264266
<category id="catDatabase">
265267
<block type="data_firebase">

0 commit comments

Comments
 (0)