Skip to content

Commit e21345d

Browse files
committed
2 parents 99aa44b + 858595d commit e21345d

8 files changed

Lines changed: 292 additions & 29 deletions

File tree

images/pic05.jpg

414 KB
Loading

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ <h2>¡Participa!</h2>
123123
¿A qué esperas para subir el tuyo?.
124124
</p>
125125
<ul class="actions">
126-
<li><a href="#" class="button">Leer más</a></li>
126+
<li><a href="participa.html" class="button">Leer más</a></li>
127127
</ul>
128128
<small class="imgauthor">
129129
Imagen: <a href="https://github.com/jj">@JJ</a>

nw-miniblip/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/tmp

nw-miniblip/index.html

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<title>Hello World!</title>
4+
<title>MiniBlip Studio</title>
55
<link rel="stylesheet/less" type="text/css" href="styles/main.less" />
66
<link rel="stylesheet" href="styles/font-awesome/css/font-awesome.min.css">
77
<script src="javascript/jquery-2.1.4.min.js" type="text/javascript"></script>
@@ -13,6 +13,7 @@
1313
var editor;
1414
$( document ).ready(function() {
1515
bind_buttons();
16+
bind_drag_and_drop_area();
1617
hide_all_sections();
1718
show_section_firmware_list();
1819
//get_list_firmwares_local();
@@ -24,6 +25,12 @@
2425
editor.setOptions({
2526
fontSize: "15pt"
2627
});
28+
29+
//open source links in a new browser
30+
$('a[target=_blank]').on('click', function(){
31+
require('nw.gui').Shell.openExternal( this.href );
32+
return false;
33+
});
2734
});
2835
</script>
2936

@@ -33,21 +40,42 @@
3340
<div id = "toolbar">
3441
<ul>
3542
<li id = "list"> <i class="fa fa-list fa-2x"></i></li>
36-
<li id = "console"> <i class="fa fa-terminal fa-2x"></i></li>
3743
<li id = "code"> <i class="fa fa-code fa-2x"></i></li>
38-
44+
<li class = "disabled" id = "console"> <i class="fa fa-terminal fa-2x"></i></li>
3945

4046
</ul>
4147
</div>
4248

4349
<div id = "main">
4450

45-
<div id = "firmware-list">
51+
<div id = "firmware-upload-section">
52+
53+
<div id="action">
54+
<div class="info">
55+
<div class="heading">
56+
<div class="name"></div>
57+
<div class="author"></div>
58+
<div class="source"><a target = "_blank" href="">source</a></div>
59+
</div>
60+
<div id="description"></div>
61+
</div>
62+
63+
<button id = "upload"> upload firmware </button>
64+
</div>
4665

47-
</div>
4866

49-
<div id = "board">
50-
<img src="./images/miniblip_board.png">
67+
68+
69+
<div id = "firmware-list">
70+
<h1> FIRMWARES </h1>
71+
<div id = "list"> </div>
72+
</div>
73+
74+
<div id = "board">
75+
<img src="./images/miniblip_board.png">
76+
<h1 id = "info"> MINIBLIP no ha sido detectada </h1>
77+
</div>
78+
5179
</div>
5280

5381
<div id="editor-container">
@@ -77,7 +105,13 @@
77105
tick.attach(detect, 1.0 / 40.0);
78106
}
79107

80-
</div>
108+
</div>
109+
110+
<div id = "info_todo">
111+
112+
El editor/compilador offline podria funcionar, pero aun no lo hace! echas una mano? <a href="https://github.com/hack-miniblip/hack-miniblip.github.io"> Hack MiniBlip </a>
113+
114+
</div>
81115
</div>
82116

83117

nw-miniblip/javascript/main.js

Lines changed: 72 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// TODO
2-
// GET REMOTE JSON
2+
// OK - GET REMOTE JSON
33
// DOWNLOAD FILE ON ITEM CLICK
44
// CHECK BOARD STATUS
55
// UPLOAD FIRMWARE
66
//
77
var fs = require("fs");
8-
var http = require('http');
8+
var https = require('https');
9+
var md5 = require('md5');
910

1011

1112
function detect_board() {
@@ -52,8 +53,10 @@ function get_list_firmwares_remote() {
5253

5354
$.get(url, function(data) {
5455
var obj = $.parseJSON(data);
56+
57+
5558
$.each(obj, function(i, value) {
56-
add_item_to_firmware_list(obj[i], true);
59+
add_item_to_firmware_list(value, true);
5760
});
5861

5962
});
@@ -74,26 +77,41 @@ function get_remote_firmware_url(name) {
7477

7578
function add_item_to_firmware_list(obj, isRemote) {
7679
console.log("added " + obj.name);
77-
var file_url = "";
80+
var file_url = "";
81+
7882
if (isRemote) {
7983
file_url = get_remote_firmware_url(obj.name);
8084
console.log(file_url);
8185
} else {
8286
file_url = get_local_firmware_path(obj.name);
8387
}
8488

85-
$("#firmware-list").append('<div class="item" id = '+obj.id +'><div class="name">' + obj.name +'</div><div class="author">'+obj.author+'</div></div>');
86-
$("#firmware-list #" + obj.id).click(function() {
8789

88-
if (isRemote) {
89-
download_firmware(file_url, function() {
90-
//upload_firmware(file_url, "/dev/sdb");
91-
});
92-
} else {
93-
upload_firmware(file_url, "/dev/sdb");
94-
}
90+
$item = $('<div class="item" id = '+obj.id +'><div class="name">' + obj.name +'</div><div class="author">'+obj.author+'</div></div>');
91+
92+
$("#firmware-list #list").append($item)
93+
94+
$item.click(function() {
95+
var $div = $("#firmware-upload-section #action");
96+
97+
$div.fadeOut("500", function() {
98+
$div.find(".name").text(obj.name);
99+
$div.find(".author").text(obj.author);
100+
$div.find(".source a").attr("href", obj.source);
101+
$(this).fadeIn("500");
102+
103+
});
95104

96-
});
105+
$div.find("#upload").click(function() {
106+
if (isRemote) {
107+
download_firmware(obj, function() {
108+
//upload_firmware(file_url, "/dev/sdb");
109+
});
110+
} else {
111+
upload_firmware(file_url, "/dev/sdb");
112+
}
113+
});
114+
});
97115
}
98116

99117
function get_list_firmwares_local() {
@@ -112,18 +130,40 @@ function get_list_firmwares_local() {
112130

113131

114132
//TODO check md5
115-
function download_firmware(name, url, callback) {
133+
function download_firmware(obj, callback) {
116134
if (!fs.existsSync("./tmp")){
117135
fs.mkdirSync("./tmp");
118136
}
119137

120-
var path = process.cwd() + "/" + name;
138+
var url = get_remote_firmware_url(obj.name);
139+
var path = process.cwd() + "/tmp/" + obj.name+".bin";
140+
console.log("saving from: "+ url);
141+
console.log("saving to " + path );
121142

122143
var file = fs.createWriteStream(path);
123144

124-
var request = http.get(url, function (response) {
145+
var request = https.get(url, function(response) {
146+
console.log(response);
125147
response.pipe(file);
126-
callback();
148+
149+
file.on('finish', function(d) {
150+
//check md5
151+
var md5result;
152+
fs.readFile(path, function(err, buf) {
153+
if (md5(buf) == obj.md5) {
154+
console.log("ok");
155+
md5result = true;
156+
} else {
157+
console.log("nop");
158+
md5result = false;
159+
}
160+
callback(md5result);
161+
}); //readfile
162+
});//fileonfinish
163+
164+
}).on('error', function(e) {
165+
fs.unlink(dest);
166+
console.log(e);
127167
});
128168
}
129169

@@ -153,6 +193,20 @@ function bind_buttons() {
153193
});
154194
}
155195

196+
function bind_drag_and_drop_area() {
197+
var holder = document.getElementById('board');
198+
holder.ondragover = function () { this.className = 'hover'; return false; };
199+
holder.ondragleave = function () { this.className = ''; return false; };
200+
holder.ondrop = function (e) {
201+
e.preventDefault();
202+
203+
for (var i = 0; i < e.dataTransfer.files.length; ++i) {
204+
console.log(e.dataTransfer.files[i].path);
205+
}
206+
return false;
207+
};
208+
}
209+
156210

157211
function hide_all_sections() {
158212
$("#main #editor-container").hide();

nw-miniblip/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.0.1",
44
"main": "index.html",
55
"window": {
6-
"toolbar": false,
6+
"toolbar": true,
77
"width": 960,
88
"height": 800,
99
"resizable": false

nw-miniblip/styles/main.less

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,22 +95,60 @@ body {
9595

9696

9797
li {
98-
padding: 10px;
98+
padding: 10px;
99+
100+
&:hover {
101+
color: black;
102+
}
99103
}
100104

101105
}
102106

103107

108+
#firmware-upload-section {
109+
110+
#action {
111+
position: fixed;
112+
bottom: 0;
113+
left: 355px;
114+
width: 425px;
115+
padding: 10px;
116+
border-radius: 2px 2px 0px 0px;
117+
display: none;
118+
119+
#heading {
120+
font-weight: 800;
121+
font-size: 2em;
122+
}
123+
124+
#upload {
125+
float: right;
126+
padding: 12px;
127+
}
128+
}
129+
130+
}
131+
104132
#firmware-list {
105133
float: left;
106134
width: 200px;
107135
background: white;
108136
height: 500px;
109137
font-size: 1.2em;
110138

139+
h1 {
140+
font-size: 1em;
141+
text-transform: uppercase;
142+
font-weight: 800;
143+
color: gray;
144+
padding: 18px 0px;
145+
text-align: center;
146+
}
147+
111148
.item {
112149
border-bottom: 1px dotted black;
113150
padding: 11px;
151+
cursor: pointer;
114152

115153
.name {
116154
font-weight: bold;
@@ -128,6 +166,21 @@ body {
128166
}
129167
}
130168

169+
#info_todo {
170+
z-index: 10;
171+
background: rgb(245, 105, 105);
172+
bottom: 0;
173+
position: absolute;
174+
width: 500px;
175+
border-radius: 2px 2px 0px 0px;
176+
padding: 18px;
177+
font-size: 2em;
178+
color: white;
179+
box-shadow: 2px 2px 16px black;
180+
left: 144px;
181+
font-weight: 800;
182+
}
183+
131184
#editor {
132185
width: 875px;
133186
height: 800px;
@@ -145,6 +198,18 @@ body {
145198
img {
146199
width: 300px;
147200
opacity: 0.5;
201+
margin-top: 15%;
148202
}
203+
204+
#info {
205+
margin-top: 10px;
206+
font-size: 1.2em;
207+
color: gray;
208+
}
209+
}
210+
211+
.disabled {
212+
opacity: 0.5;
213+
pointer-events:none;
149214
}
150215

0 commit comments

Comments
 (0)