Skip to content

Commit 6f7462b

Browse files
committed
2.6.6
1 parent d777e31 commit 6f7462b

File tree

15 files changed

+328
-105
lines changed

15 files changed

+328
-105
lines changed

app/hints.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function init_hints(){
7777
function hint(name){
7878
var find=d2i[name]
7979
var banner='<link rel="stylesheet" title="Default" href="libs/highlight.js/styles/default.css">';
80-
var banner2='<script src="head.min.js"></script><script>head.load("sheetrock.min.js");</script>';
80+
var banner2='<script src="js/head.min.js"></script><script>head.load("js/sheetrock.min.js");</script>';
8181
var add_banner='';
8282
if (find){
8383
var ob=headings.reduce((ob,v)=>{

app/mc-tool.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ var addChanged=target=>origin=>
7878
if (i.number != undefined && i.disabled ) return; //no need dublicates
7979
var oo=map[i.name];
8080
if (oo){
81-
oo=oo.filter(i=>!i.disabled)
81+
oo=oo.filter(i=>!i.disabled|| i.number == undefined)
8282
o=oo[oo.length-1];
8383
if (o){
8484
var changed = {};
@@ -225,7 +225,7 @@ module.exports.updateH=(root,file,json)=>{
225225
.then(onlyChanged)
226226
.then(extendFrom(h))
227227
.then(array2text)
228-
.then(outFile(file))
228+
.then(outFile(path.join(root,'Marlin',path.parse(file).base)))
229229
.then(a=>(console.log('updated h: ',path.relative(root,file)),a))
230230
.catch(a=>{ console.log('fail h: ',file,a); throw a;})
231231
}
@@ -295,8 +295,8 @@ module.exports.makeHH=(root,name)=>conf=>{
295295
.catch(a=>(console.log('fail conf h: ',file,a),a))
296296
}
297297

298-
module.exports.makeHfile=(root,name)=>conf=>{
299-
var p=path.join(root||'','Marlin',name);
298+
module.exports.makeHfile=(root,name,dir)=>conf=>{
299+
var p=path.join(root||'',dir||'Marlin',name);
300300
var h=inFile(p);
301301
return h
302302
.then(mc.h2json)

app/server.js

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ var pio = require('./pio');
1313
var http = require('http');
1414
var ua = require('universal-analytics');
1515
var promisify = require('./helpers').promisify;
16+
var walk=require('./helpers').walk;
1617

1718
var port = 3000;
1819
var server = http.Server(app);
1920
var visitor = ua('UA-99239389-1');
2021
var isElectron=module.parent&&module.parent.filename.indexOf('index.js')>=0;
2122

23+
var baseCfg='Marlin';
2224
var serial;
2325
var serial_enabled = !(isElectron&&process.platform=='darwin');
2426
if (serial_enabled)
@@ -105,9 +107,13 @@ app.get('/checkout/:branch', function (req, res) {
105107
});
106108
var get_cfg=()=>{
107109
var base=Promise.all([git.root(),git.Tag()]);
108-
var list=['Marlin/Configuration.h','Marlin/Configuration_adv.h'].map(f=>{
110+
var list=['Configuration.h','Configuration_adv.h']
111+
.map(f=>{
109112
return base
110-
.then(p=>git.Show(p[1],f).then(file=>mctool.getJson(p[0],file,p[1])(path.join(p[0],f))))
113+
.then(p=>
114+
git.Show(p[1],path.join(baseCfg,f))
115+
.then(file=>mctool.getJson(p[0],file,p[1])(path.join(p[0],'Marlin',f)))
116+
)
111117
.then(o=>(o.names.filter(n=>hints.d2i(n.name),1).map(n=>o.defs[n.name].hint=!0),o))
112118
.then(a=>(a.names=undefined,type='file',a))
113119
.then(a=>
@@ -123,6 +129,25 @@ app.get('/now/', function (req, res) {
123129
res.set('Content-Type', 'text/plain');
124130
get_cfg().then(a=>res.send(JSON.stringify(a,null,2)))
125131
});
132+
var unique=a=>a.filter((elem, index, self)=>index == self.indexOf(elem))
133+
app.get('/examples', function (req, res) {
134+
git.root()
135+
.then(root=>{
136+
var ex=path.join(root,'Marlin','example_configurations')
137+
return walk(ex)
138+
.then(a=>a.filter(i=>/Configuration(_adv)?\.h/.test(i)))
139+
.then(a=>a.map(i=>path.parse(path.relative(ex,i)).dir))
140+
.then(unique)
141+
.then(a=>(a.unshift('Marlin'),a))
142+
.then(a=>res.send({current:baseCfg,list:a}))
143+
})
144+
});
145+
app.get('/set-base/:path', function (req, res) {
146+
baseCfg=atob(req.params.path).toString();
147+
if (baseCfg!='Marlin')
148+
baseCfg=path.join('Marlin','example_configurations',baseCfg);
149+
res.end();
150+
});
126151
app.get('/version', function (req, res) {
127152
res.set('Content-Type', 'image/svg+xml');
128153
var badge={
@@ -139,16 +164,18 @@ app.get('/version', function (req, res) {
139164
});
140165
app.get('/version/:screen', function (req, res) {
141166
res.set('Content-Type', 'text/plain');
142-
if (!/\/jes/.test(process.cwd()))
143-
visitor.screenview(req.params.screen, pjson.name,pjson.version).send()
144-
pio.isPIO()
145-
// .then(pio.list)
146-
// .then(p=>"'"+p+"'")
147-
.catch(()=>false)
148-
.then(a=>{
167+
visitor.screenview({
168+
cd:req.params.screen,
169+
an:pjson.name,
170+
av:pjson.version,
171+
ua:req.headers['user-agent'],
172+
ul:req.headers['accept-language'].split(',')[0],
173+
}).send()
174+
Promise.all([pio.isPIO().catch(()=>false),git.root()])
175+
.then(pp=>{
149176
//console.log(a)
150-
var s=JSON.stringify(a);
151-
res.write(`var config={pio:${s},version:"${pjson.version}"};`);
177+
var cfg={pio:pp[0],version:pjson.version,root:pp[1],base:baseCfg};
178+
res.write("var config="+JSON.stringify(cfg));
152179
res.end();
153180
})
154181
});
@@ -210,7 +237,21 @@ app.get('/status', function (req, res) {
210237
git.Status().then(a=>res.send(a))
211238
});
212239
app.get('/checkout-force', function (req, res) {
213-
git.Checkout('--force').then(a=>res.send(a))
240+
if (baseCfg=='Marlin')
241+
git
242+
.Checkout('--force')
243+
.then(a=>res.send(a));
244+
else
245+
git.root()
246+
.then(root=>
247+
['Configuration.h','Configuration_adv.h']
248+
.map(f=>new Promise((done,fail)=>
249+
fs.createReadStream(path.join(root,baseCfg,f))
250+
.pipe(fs.createWriteStream(path.join(root,'Marlin',f)).on('finish',done))
251+
)
252+
)
253+
)
254+
.then(a=>res.send(a))
214255
});
215256
app.get('/fetch', function (req, res) {
216257
git.Fetch()
@@ -253,7 +294,7 @@ app.post('/upload', function(req, res){
253294
try{
254295
return mctool
255296
.makeCfg(file.path)
256-
.then(mctool.makeHfile(root,file.name))
297+
.then(mctool.makeHfile(root,file.name,baseCfg))
257298
}catch(e) { console.log(e); throw e; }
258299
})
259300
// return new Promise((done,fail)=>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "marlin-conf",
3-
"version": "2.6.5",
3+
"version": "2.6.6",
44
"description": "configuration tool for Marlin project",
55
"main": "./index.js",
66
"scripts": {

static/index.html

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<script src="libs/tether/dist/js/tether.min.js"></script>
1717
<script src="libs/bootstrap/dist/js/bootstrap.min.js"></script>
1818
<script src="libs/socket.io-client/dist/socket.io.js"></script>
19-
<script src="jquery.ba-throttle-debounce.js"></script>
19+
<script src="js/jquery.ba-throttle-debounce.js"></script>
2020
<link href="toggle.css" rel="stylesheet">
2121
<script src="/version/Home"></script>
2222
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
@@ -167,6 +167,31 @@ <h4 class="modal-title" id="tagsModalLabel">Available releases</h4>
167167
</div>
168168
</div>
169169
</div>
170+
<div class="modal fade" id="mct-examples-modal" tabindex="-1" role="dialog" aria-labelledby="examplesModalLabel" aria-hidden="true" >
171+
<div class="modal-dialog" role="document">
172+
<div class="modal-content">
173+
<div class="modal-header">
174+
<h4 class="modal-title" id="examplesModalLabel">Available examples</h4>
175+
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
176+
<span aria-hidden="true">&times;</span>
177+
</button>
178+
</div>
179+
<div class="modal-body">
180+
<p>Current is:<br><span></sapn></p>
181+
<table class="table table-hover table-sm">
182+
<thead>
183+
<tr>
184+
<th>Name
185+
<tbody>
186+
</table>
187+
</div>
188+
<div class="modal-footer">
189+
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
190+
<button type="button" class="btn btn-primary">Change</button>
191+
</div>
192+
</div>
193+
</div>
194+
</div>
170195
<div class="modal fade" id="mct-reset-modal" role="dialog" aria-labelledby="resetModalLabel" aria-hidden="true">
171196
<div class="modal-dialog">
172197
<div class="modal-content">
@@ -225,11 +250,15 @@ <h4 class="modal-title" id="myModalLabel">Log</h4>
225250
<div class="dropdown-menu" aria-labelledby="dropdownTagsLink">
226251
<button class="dropdown-item mct-change" title="Change version (git checkout)" >Change</button>
227252
<button class="dropdown-item mct-update" title="Update version list from GitHub (git fetch)">Update</button>
228-
<button class="dropdown-item bg-danger text-white mct-reset" title="Reset all changes (git checkout -f)">Reset</button>
253+
<button class="dropdown-item bg-danger text-white mct-reset" title="Reset all changes (git checkout -f) or copy from examples if choosen">Reset</button>
254+
<button class="dropdown-item mct-examples" title="Choose base file from examples">Examples</button>
229255
</div>
230256
</div>
231257
</li>
232258
<li class="nav-item mr-sm-2 my-auto p-1">
259+
<button type="button" class="btn btn-warning mct-info" title="Show information">?</button>
260+
</li>
261+
<li class="nav-item mr-sm-2 my-auto p-1">
233262
<div class="onoffswitch mct-changed" title="Toggle only changed options">
234263
<label class="onoffswitch-label" >
235264
<input type="checkbox" class="onoffswitch-checkbox">
@@ -281,6 +310,15 @@ <h4 class="alert-heading">Oh snap!</h4>
281310
<p></p>
282311
</div>
283312
</template>
313+
<template class="_info">
314+
<div class="alert alert-info alert-dismissible fade show" role="alert">
315+
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
316+
<span aria-hidden="true">&times;</span>
317+
</button>
318+
<h4 class="alert-heading">Information</h4>
319+
<p></p>
320+
</div>
321+
</template>
284322
</div>
285323
<div class="progress mct-progress" style="display:none">
286324
<div class="progress-bar" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 0%;">
File renamed without changes.
File renamed without changes.
File renamed without changes.

static/main.js

Lines changed: 44 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,6 @@ $(function(){
382382
d.find('.col-sm-6').attr('title',title)//.tooltip(tooltip_large);
383383
}
384384
var b=d.find('button');
385-
if ( /_adv$/.test( file.file.name ) )
386-
b.remove();
387-
else
388385
if ( def.hint == undefined )
389386
b.remove();
390387
else
@@ -479,21 +476,20 @@ $(function(){
479476
}
480477
})
481478
});
482-
(function(){
483-
var m=$('#mct-tags-modal');
484-
var t=m.find('table tbody');
485-
m.find('button.btn-primary').on('click',function(ev){
479+
(function(btn,ui){
480+
var t=ui.find('table tbody');
481+
ui.find('button.btn-primary').on('click',function(ev){
486482
var row = t.find('.table-success');
487483
if(row.length){
488484
var tag=row.find('td').eq(1).text().split(',');
489-
cmdReload($.ajax('/checkout/'+tag[0]),m);
485+
cmdReload($.ajax('/checkout/'+tag[0]),ui);
490486
}
491487
});
492-
m.find('table tbody').on('click',function(ev){
488+
ui.find('table tbody').on('click',function(ev){
493489
$(this).find('tr').removeClass('table-success');
494490
$(ev.target).parents('tr').addClass('table-success')
495491
});
496-
$('.mct-change').on('click',function(){
492+
btn.on('click',function(){
497493
$.ajax('/tags')
498494
.fail(ajaxAlert)
499495
.then(function(data){
@@ -502,10 +498,38 @@ $(function(){
502498
data.map(function(row){
503499
t.append($('<tr>').append($('<td>').text(row.date)).append($('<td>').text(row.tag)))
504500
})
505-
m.modal();
501+
ui.modal();
506502
})
507503
})
508-
}());
504+
}($('.mct-change'),$('#mct-tags-modal')));
505+
(function(btn,ui){
506+
var t=ui.find('table tbody');
507+
var hdr=ui.find('.modal-body>p span');
508+
ui.find('button.btn-primary').on('click',function(ev){
509+
var row = t.find('.table-success');
510+
if(row.length){
511+
var path=btoa(row.find('td').text());
512+
cmdReload($.ajax('/set-base/'+path),ui);
513+
}
514+
});
515+
ui.find('table tbody').on('click',function(ev){
516+
$(this).find('tr').removeClass('table-success');
517+
$(ev.target).parents('tr').addClass('table-success')
518+
});
519+
btn.on('click',function(){
520+
$.ajax('/examples')
521+
.fail(ajaxAlert)
522+
.then(function(data){
523+
t.empty();
524+
hdr.text(data.current)
525+
config.base=data.current;
526+
data.list.map(function(row){
527+
t.append($('<tr>').append($('<td>').text(row)))
528+
})
529+
ui.modal();
530+
})
531+
})
532+
}($('.mct-examples'),$('#mct-examples-modal')));
509533
(function(btn,ui){
510534
var p=ui.find('p');
511535
btn.on('click',function(){
@@ -532,40 +556,7 @@ $(function(){
532556
})
533557
}($('.mct-update')));
534558
$('.mct-consoles').on('click',function(){ window.open('consoles.html','_blank') });
535-
(function(){ //REMOVE
536-
var r=$('#mct-console-modal');
537-
var p=r.find('textarea');
538-
var b=r.find('.modal-body button');
539-
var s=r.find('.modal-body input[type=text]');
540-
var c=r.find('.modal-body input[type=checkbox]');
541-
$('.mct-console').on('click',function(){
542-
$.ajax('/port/ttyUSB0/115200').then(function(url){
543-
// p.empty();
544-
var socket = io.connect({path:url});
545-
socket.on('connect', function(data) {
546-
//socket.emit('message', 'Hello World from client');
547-
});
548-
socket.on('message',function(msg){
549-
p.append(msg)
550-
})
551-
socket.on('disconnect',function(msg){
552-
p.append('\n[closed]')
553-
socket.close();
554-
})
555-
b.unbind('click').on('click',function(){
556-
socket.emit('message',s.val()+(c.prop('checked')?'\r\n':''));
557-
})
558-
r.modal();
559-
r.unbind('hidden.bs.modal').on('hidden.bs.modal', function (e) {
560-
socket.close();
561-
})
562-
})
563-
})
564-
r.find('button.btn-primary').on('click',function(ev){
565-
cmdReload($.ajax('/checkout-force'),r);
566-
})
567-
}());
568-
(function(){
559+
(function(){
569560
var ports=$('.mct-ports')
570561
var title=ports.find('a.btn')
571562
ports.find('.dropdown-menu').on('click',function(ev){
@@ -605,8 +596,13 @@ $(function(){
605596
var port= JSON.parse(event.data);
606597
removePort(port);
607598
});
608-
}());
609-
599+
}());
600+
(function(btn){
601+
btn.on('click',function(){
602+
_add($('template._info'))
603+
.find('p').html(`Current directory is: ${config.root}<br>Current base files choosen from: ${config.base}`)
604+
})
605+
}($('.mct-info')));
610606
(function(){
611607
var r=$('#mct-pio-modal');
612608
var p=r.find('.form-group pre');

0 commit comments

Comments
 (0)