Skip to content

Commit

Permalink
2.6.6
Browse files Browse the repository at this point in the history
  • Loading branch information
akaJes committed Jun 21, 2017
1 parent d777e31 commit 6f7462b
Show file tree
Hide file tree
Showing 15 changed files with 328 additions and 105 deletions.
2 changes: 1 addition & 1 deletion app/hints.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function init_hints(){
function hint(name){
var find=d2i[name]
var banner='<link rel="stylesheet" title="Default" href="libs/highlight.js/styles/default.css">';
var banner2='<script src="head.min.js"></script><script>head.load("sheetrock.min.js");</script>';
var banner2='<script src="js/head.min.js"></script><script>head.load("js/sheetrock.min.js");</script>';
var add_banner='';
if (find){
var ob=headings.reduce((ob,v)=>{
Expand Down
8 changes: 4 additions & 4 deletions app/mc-tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ var addChanged=target=>origin=>
if (i.number != undefined && i.disabled ) return; //no need dublicates
var oo=map[i.name];
if (oo){
oo=oo.filter(i=>!i.disabled)
oo=oo.filter(i=>!i.disabled|| i.number == undefined)
o=oo[oo.length-1];
if (o){
var changed = {};
Expand Down Expand Up @@ -225,7 +225,7 @@ module.exports.updateH=(root,file,json)=>{
.then(onlyChanged)
.then(extendFrom(h))
.then(array2text)
.then(outFile(file))
.then(outFile(path.join(root,'Marlin',path.parse(file).base)))
.then(a=>(console.log('updated h: ',path.relative(root,file)),a))
.catch(a=>{ console.log('fail h: ',file,a); throw a;})
}
Expand Down Expand Up @@ -295,8 +295,8 @@ module.exports.makeHH=(root,name)=>conf=>{
.catch(a=>(console.log('fail conf h: ',file,a),a))
}

module.exports.makeHfile=(root,name)=>conf=>{
var p=path.join(root||'','Marlin',name);
module.exports.makeHfile=(root,name,dir)=>conf=>{
var p=path.join(root||'',dir||'Marlin',name);
var h=inFile(p);
return h
.then(mc.h2json)
Expand Down
67 changes: 54 additions & 13 deletions app/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ var pio = require('./pio');
var http = require('http');
var ua = require('universal-analytics');
var promisify = require('./helpers').promisify;
var walk=require('./helpers').walk;

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

var baseCfg='Marlin';
var serial;
var serial_enabled = !(isElectron&&process.platform=='darwin');
if (serial_enabled)
Expand Down Expand Up @@ -105,9 +107,13 @@ app.get('/checkout/:branch', function (req, res) {
});
var get_cfg=()=>{
var base=Promise.all([git.root(),git.Tag()]);
var list=['Marlin/Configuration.h','Marlin/Configuration_adv.h'].map(f=>{
var list=['Configuration.h','Configuration_adv.h']
.map(f=>{
return base
.then(p=>git.Show(p[1],f).then(file=>mctool.getJson(p[0],file,p[1])(path.join(p[0],f))))
.then(p=>
git.Show(p[1],path.join(baseCfg,f))
.then(file=>mctool.getJson(p[0],file,p[1])(path.join(p[0],'Marlin',f)))
)
.then(o=>(o.names.filter(n=>hints.d2i(n.name),1).map(n=>o.defs[n.name].hint=!0),o))
.then(a=>(a.names=undefined,type='file',a))
.then(a=>
Expand All @@ -123,6 +129,25 @@ app.get('/now/', function (req, res) {
res.set('Content-Type', 'text/plain');
get_cfg().then(a=>res.send(JSON.stringify(a,null,2)))
});
var unique=a=>a.filter((elem, index, self)=>index == self.indexOf(elem))
app.get('/examples', function (req, res) {
git.root()
.then(root=>{
var ex=path.join(root,'Marlin','example_configurations')
return walk(ex)
.then(a=>a.filter(i=>/Configuration(_adv)?\.h/.test(i)))
.then(a=>a.map(i=>path.parse(path.relative(ex,i)).dir))
.then(unique)
.then(a=>(a.unshift('Marlin'),a))
.then(a=>res.send({current:baseCfg,list:a}))
})
});
app.get('/set-base/:path', function (req, res) {
baseCfg=atob(req.params.path).toString();
if (baseCfg!='Marlin')
baseCfg=path.join('Marlin','example_configurations',baseCfg);
res.end();
});
app.get('/version', function (req, res) {
res.set('Content-Type', 'image/svg+xml');
var badge={
Expand All @@ -139,16 +164,18 @@ app.get('/version', function (req, res) {
});
app.get('/version/:screen', function (req, res) {
res.set('Content-Type', 'text/plain');
if (!/\/jes/.test(process.cwd()))
visitor.screenview(req.params.screen, pjson.name,pjson.version).send()
pio.isPIO()
// .then(pio.list)
// .then(p=>"'"+p+"'")
.catch(()=>false)
.then(a=>{
visitor.screenview({
cd:req.params.screen,
an:pjson.name,
av:pjson.version,
ua:req.headers['user-agent'],
ul:req.headers['accept-language'].split(',')[0],
}).send()
Promise.all([pio.isPIO().catch(()=>false),git.root()])
.then(pp=>{
//console.log(a)
var s=JSON.stringify(a);
res.write(`var config={pio:${s},version:"${pjson.version}"};`);
var cfg={pio:pp[0],version:pjson.version,root:pp[1],base:baseCfg};
res.write("var config="+JSON.stringify(cfg));
res.end();
})
});
Expand Down Expand Up @@ -210,7 +237,21 @@ app.get('/status', function (req, res) {
git.Status().then(a=>res.send(a))
});
app.get('/checkout-force', function (req, res) {
git.Checkout('--force').then(a=>res.send(a))
if (baseCfg=='Marlin')
git
.Checkout('--force')
.then(a=>res.send(a));
else
git.root()
.then(root=>
['Configuration.h','Configuration_adv.h']
.map(f=>new Promise((done,fail)=>
fs.createReadStream(path.join(root,baseCfg,f))
.pipe(fs.createWriteStream(path.join(root,'Marlin',f)).on('finish',done))
)
)
)
.then(a=>res.send(a))
});
app.get('/fetch', function (req, res) {
git.Fetch()
Expand Down Expand Up @@ -253,7 +294,7 @@ app.post('/upload', function(req, res){
try{
return mctool
.makeCfg(file.path)
.then(mctool.makeHfile(root,file.name))
.then(mctool.makeHfile(root,file.name,baseCfg))
}catch(e) { console.log(e); throw e; }
})
// return new Promise((done,fail)=>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "marlin-conf",
"version": "2.6.5",
"version": "2.6.6",
"description": "configuration tool for Marlin project",
"main": "./index.js",
"scripts": {
Expand Down
42 changes: 40 additions & 2 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<script src="libs/tether/dist/js/tether.min.js"></script>
<script src="libs/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="libs/socket.io-client/dist/socket.io.js"></script>
<script src="jquery.ba-throttle-debounce.js"></script>
<script src="js/jquery.ba-throttle-debounce.js"></script>
<link href="toggle.css" rel="stylesheet">
<script src="/version/Home"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
Expand Down Expand Up @@ -167,6 +167,31 @@ <h4 class="modal-title" id="tagsModalLabel">Available releases</h4>
</div>
</div>
</div>
<div class="modal fade" id="mct-examples-modal" tabindex="-1" role="dialog" aria-labelledby="examplesModalLabel" aria-hidden="true" >
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="examplesModalLabel">Available examples</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p>Current is:<br><span></sapn></p>
<table class="table table-hover table-sm">
<thead>
<tr>
<th>Name
<tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Change</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="mct-reset-modal" role="dialog" aria-labelledby="resetModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
Expand Down Expand Up @@ -225,11 +250,15 @@ <h4 class="modal-title" id="myModalLabel">Log</h4>
<div class="dropdown-menu" aria-labelledby="dropdownTagsLink">
<button class="dropdown-item mct-change" title="Change version (git checkout)" >Change</button>
<button class="dropdown-item mct-update" title="Update version list from GitHub (git fetch)">Update</button>
<button class="dropdown-item bg-danger text-white mct-reset" title="Reset all changes (git checkout -f)">Reset</button>
<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>
<button class="dropdown-item mct-examples" title="Choose base file from examples">Examples</button>
</div>
</div>
</li>
<li class="nav-item mr-sm-2 my-auto p-1">
<button type="button" class="btn btn-warning mct-info" title="Show information">?</button>
</li>
<li class="nav-item mr-sm-2 my-auto p-1">
<div class="onoffswitch mct-changed" title="Toggle only changed options">
<label class="onoffswitch-label" >
<input type="checkbox" class="onoffswitch-checkbox">
Expand Down Expand Up @@ -281,6 +310,15 @@ <h4 class="alert-heading">Oh snap!</h4>
<p></p>
</div>
</template>
<template class="_info">
<div class="alert alert-info alert-dismissible fade show" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<h4 class="alert-heading">Information</h4>
<p></p>
</div>
</template>
</div>
<div class="progress mct-progress" style="display:none">
<div class="progress-bar" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 0%;">
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
92 changes: 44 additions & 48 deletions static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,6 @@ $(function(){
d.find('.col-sm-6').attr('title',title)//.tooltip(tooltip_large);
}
var b=d.find('button');
if ( /_adv$/.test( file.file.name ) )
b.remove();
else
if ( def.hint == undefined )
b.remove();
else
Expand Down Expand Up @@ -479,21 +476,20 @@ $(function(){
}
})
});
(function(){
var m=$('#mct-tags-modal');
var t=m.find('table tbody');
m.find('button.btn-primary').on('click',function(ev){
(function(btn,ui){
var t=ui.find('table tbody');
ui.find('button.btn-primary').on('click',function(ev){
var row = t.find('.table-success');
if(row.length){
var tag=row.find('td').eq(1).text().split(',');
cmdReload($.ajax('/checkout/'+tag[0]),m);
cmdReload($.ajax('/checkout/'+tag[0]),ui);
}
});
m.find('table tbody').on('click',function(ev){
ui.find('table tbody').on('click',function(ev){
$(this).find('tr').removeClass('table-success');
$(ev.target).parents('tr').addClass('table-success')
});
$('.mct-change').on('click',function(){
btn.on('click',function(){
$.ajax('/tags')
.fail(ajaxAlert)
.then(function(data){
Expand All @@ -502,10 +498,38 @@ $(function(){
data.map(function(row){
t.append($('<tr>').append($('<td>').text(row.date)).append($('<td>').text(row.tag)))
})
m.modal();
ui.modal();
})
})
}());
}($('.mct-change'),$('#mct-tags-modal')));
(function(btn,ui){
var t=ui.find('table tbody');
var hdr=ui.find('.modal-body>p span');
ui.find('button.btn-primary').on('click',function(ev){
var row = t.find('.table-success');
if(row.length){
var path=btoa(row.find('td').text());
cmdReload($.ajax('/set-base/'+path),ui);
}
});
ui.find('table tbody').on('click',function(ev){
$(this).find('tr').removeClass('table-success');
$(ev.target).parents('tr').addClass('table-success')
});
btn.on('click',function(){
$.ajax('/examples')
.fail(ajaxAlert)
.then(function(data){
t.empty();
hdr.text(data.current)
config.base=data.current;
data.list.map(function(row){
t.append($('<tr>').append($('<td>').text(row)))
})
ui.modal();
})
})
}($('.mct-examples'),$('#mct-examples-modal')));
(function(btn,ui){
var p=ui.find('p');
btn.on('click',function(){
Expand All @@ -532,40 +556,7 @@ $(function(){
})
}($('.mct-update')));
$('.mct-consoles').on('click',function(){ window.open('consoles.html','_blank') });
(function(){ //REMOVE
var r=$('#mct-console-modal');
var p=r.find('textarea');
var b=r.find('.modal-body button');
var s=r.find('.modal-body input[type=text]');
var c=r.find('.modal-body input[type=checkbox]');
$('.mct-console').on('click',function(){
$.ajax('/port/ttyUSB0/115200').then(function(url){
// p.empty();
var socket = io.connect({path:url});
socket.on('connect', function(data) {
//socket.emit('message', 'Hello World from client');
});
socket.on('message',function(msg){
p.append(msg)
})
socket.on('disconnect',function(msg){
p.append('\n[closed]')
socket.close();
})
b.unbind('click').on('click',function(){
socket.emit('message',s.val()+(c.prop('checked')?'\r\n':''));
})
r.modal();
r.unbind('hidden.bs.modal').on('hidden.bs.modal', function (e) {
socket.close();
})
})
})
r.find('button.btn-primary').on('click',function(ev){
cmdReload($.ajax('/checkout-force'),r);
})
}());
(function(){
(function(){
var ports=$('.mct-ports')
var title=ports.find('a.btn')
ports.find('.dropdown-menu').on('click',function(ev){
Expand Down Expand Up @@ -605,8 +596,13 @@ $(function(){
var port= JSON.parse(event.data);
removePort(port);
});
}());

}());
(function(btn){
btn.on('click',function(){
_add($('template._info'))
.find('p').html(`Current directory is: ${config.root}<br>Current base files choosen from: ${config.base}`)
})
}($('.mct-info')));
(function(){
var r=$('#mct-pio-modal');
var p=r.find('.form-group pre');
Expand Down
Loading

0 comments on commit 6f7462b

Please sign in to comment.