Skip to content

Commit

Permalink
toolbar refining
Browse files Browse the repository at this point in the history
  • Loading branch information
akaJes committed May 31, 2017
1 parent 1d47188 commit 48d1fc7
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 74 deletions.
23 changes: 6 additions & 17 deletions app/git-tool.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var git = require('simple-git');
var exec = require('child_process').exec;
var exec = require('child_process').exec;
var promisify = require('./helpers').promisify;
var root;


Expand All @@ -15,9 +16,6 @@ new Promise((done,fail)=>git(root).raw(['describe','--tags'],(e,a)=>e?fail(e):do
.then(root=>(console.log('[gitTag]',root),root))
.catch(mst=>console.log('no tag'))

var gitTags2=()=>
new Promise((done,fail)=>git(root).tags([],(e,a)=>e?fail(e):done(a)))
.then(root=>(console.log('[gitTags]',root.all.toString()),root))
var getTag=msg=>{
var m=msg.match(/\(tag:\s(.*)\)/)
return m&&m[1];
Expand All @@ -29,22 +27,13 @@ new Promise((done,fail)=>git(root).log(['--tags','--simplify-by-decoration'],(e,
.then(root=>(verbose&&console.log('[gitTags]',root),root))
.catch(mst=>console.log('no tags'))

var gitShow=(branch,file)=>
new Promise((done,fail)=>git(root).show([branch+':'+file],(e,a)=>e?fail(e):done(a)));

var gitCheckout=(branch)=>
new Promise((done,fail)=>git(root).checkout(branch,(e,a)=>e?fail(e):done(a)));

var gitStatus=()=>
new Promise((done,fail)=>git(root).status((e,a)=>e?fail(e):done(a)));


exports.Checkout=gitCheckout;
exports.Status=gitStatus;
exports.Checkout=promisify('checkout',git(root)); //(branch)
exports.Status=promisify('status',git(root)); //()
exports.Fetch=promisify('fetch',git(root)); //()
exports.Root=gitRoot;
exports.Tag=gitTag;
exports.Tags=gitTags;
exports.Show=gitShow;
exports.Show=(branch,file)=>promisify('show',git(root))([branch+':'+file]);
exports.git=git;
exports.root=a=>{
if (a){
Expand Down
4 changes: 2 additions & 2 deletions app/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Object.prototype.filter = function( predicate, obj ) {
};


function promisify(func) {
function promisify(func,that) {
return function() {
return new Promise((resolve, reject) => {
const args = Array.prototype.slice.apply(arguments);
Expand All @@ -24,7 +24,7 @@ function promisify(func) {
}
resolve(data);
});
func.apply(null, args);
(that&&that[func]||func).apply(that||null, args);
});
};
}
Expand Down
5 changes: 5 additions & 0 deletions app/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ app.get('/status', function (req, res) {
app.get('/checkout-force', function (req, res) {
git.Checkout('--force').then(a=>res.send(a))
});
app.get('/fetch', function (req, res) {
git.Fetch()
.then(a=>res.end(JSON.stringify(a)))
.catch(e=>res.status(403).send(e))
});
app.get('/hint/:name', function (req, res) {
res.send(hints.hint(req.params.name));
})
Expand Down
41 changes: 22 additions & 19 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ <h4 class="modal-title" id="resetModalLabel">Changed files</h4>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Reset</button>
<button type="button" class="btn btn-danger">Reset</button>
</div>
</div>
</div>
Expand Down Expand Up @@ -217,45 +217,48 @@ <h4 class="modal-title" id="myModalLabel">Log</h4>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item mr-sm-2 my-auto p-1">
Release:
<button type="button" class="btn btn-info mct-tags" title="choose current release"> TAGS</button>
<button type="button" class="btn btn-danger mct-reset" title="reset all changes">Reset</button>
</li>
<li class="nav-item" style="width:100px">
<span class="mct-status"></span>
<div class="dropdown d-inline-block">
<button class="btn btn-info dropdown-toggle mct-tags" title="Current release" id="dropdownTagsLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
TAGS
</button>
<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>
</div>
</div>
</li>
<li class="nav-item mr-sm-2 my-auto p-1">
<div class="onoffswitch mct-changed" title="toggle only changed">
<div class="onoffswitch mct-changed" title="Toggle only changed options">
<label class="onoffswitch-label" >
<input type="checkbox" class="onoffswitch-checkbox">
<span class="onoffswitch-inner" data-content-on="Changed" data-content-off="All"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
<button type="button" class="btn btn-warning mct-upload" title="upload your old configuration or drag it in browser">Upload</button>
<button type="button" class="btn btn-warning mct-upload" title="Upload your old configuration or drag it in browser">Upload</button>
<input type="file" name="files[]" class="mct-upload" multiple style="display:none;">
</li>
<li class="nav-item mr-sm-2 p-1">
<button type="button" class="btn btn-secondary mct-pio-compile disabled" data-toggle="toggle" title="PlatformIO not installed">compile</button>
<button type="button" class="btn btn-secondary mct-pio-flash disabled" data-toggle="toggle" title="PlatformIO not installed">flash</button>
<div class="dropdown d-inline-block mct-ports">
<a class="btn btn-secondary dropdown-toggle" href="https://example.com" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<button type="button" class="btn btn-secondary mct-pio-compile disabled" data-toggle="toggle" title="Compile Marlin with PlatformIO">Compile</button>
<button type="button" class="btn btn-secondary mct-pio-flash disabled" data-toggle="toggle" title="Upload firmware with PlatformIO to selected port">Flash</button>
<div class="dropdown d-inline-block mct-ports" title="Select port for PlatformIO">
<a class="btn btn-secondary dropdown-toggle" href="#" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Auto port
</a>
<div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
<template class="_ports">
<a class="dropdown-item" href="#"></a>
</template>
</div>
</div>
</li>
<li class="nav-item mr-sm-2 p-1">
<button type="button" class="btn btn-secondary mct-consoles" data-toggle="toggle" title="PlatformIO not installed">consoles</button>
<!-- <button type="button" class="btn btn-secondary mct-console disabled" data-toggle="toggle" title="PlatformIO not installed">console</button>-->
<button type="button" class="btn btn-secondary mct-consoles" data-toggle="toggle" title="Manager of serial consoles">Consoles</button>
</li>
<li class="nav-item mr-sm-2 p-1">
<button type="button" class="btn btn-warning mct-issue" title="create an issue on Marlin github repository" >Issue</button>
<button type="button" class="btn btn-warning mct-issue" title="Create an issue on Marlin GitHub repository" >Issue</button>
</li>

</ul>
<div class="text-right">
<a target="_blank" href="https://github.com/akaJes/marlin-config"><img src="/version" title="current version" height="18"></a><br>
Expand Down Expand Up @@ -348,7 +351,7 @@ <h4 class="alert-heading">Oh snap!</h4>
</select>
</div>
<div class="col-sm-1 my-auto">
<button type="button" class="btn btn-warning btn-sm">?</button>
<button type="button" class="btn btn-warning btn-sm" title="Show explanation">?</button>
</div>
</div>
</template>
Expand All @@ -371,7 +374,7 @@ <h4 class="alert-heading">Oh snap!</h4>
<div class="col-sm-2 my-auto" data-toggle="tooltip" data-animation="false">
</div>
<div class="col-sm-1 my-auto">
<button type="button" class="btn btn-warning btn-sm">?</button>
<button type="button" class="btn btn-warning btn-sm" title="Show explanation">?</button>
</div>
</div>
</template>
Expand Down
83 changes: 47 additions & 36 deletions static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,24 @@ function addNewSection(tab,id,section,sec){
}

function loadHint(name){
$.ajax('/hint/'+name).then(function(data){
$.ajax('/hint/'+name)
.fail(ajaxAlert)
.then(function(data){
$('.mct-hint').html(data);
})
}
function loadGcode(name){
$.ajax('/gcode/'+name).then(function(data){
$.ajax('/gcode/'+name)
.fail(ajaxAlert)
.then(function(data){
$('.mct-hint').html(data).prop('scrollTop',0);
})
}
function saveProp(cmd){
var state=$('.mct-status')
state.text('saving...').fadeIn().css({color:'black'});
progress(0)(true)('50%');
return $.post(cmd)
.then(function(a){ state.text('saved').fadeOut(1000); return a})
.fail(function(a){ state.text(''+a.responseJSON.code).css({color:'red'})})
.then(function(a){ progress('100%')(false); return a})
.fail(function(e){ progress(1)('ERROR: '+(e.responseText||e.state())); return ajaxAlert(e) });
}
function applyProp(def,row,prop,val){
def.changed=def.changed||{}
Expand All @@ -62,27 +65,29 @@ function getVal(ob,name){
return ob.changed[name]
return ob[name]
}
function ajaxAlert(fail){
_add($('template._alert'))
.find('p').text(fail.responseText||(fail.statusText+': '+fail.state()))
return fail;
}
function cmdReload(cmd,modal){
cmd
.then(function(data){
$(window).unbind('beforeunload');
window.location.reload();
})
.fail(function(a){
.fail(function(e){
modal&&modal.modal('hide')
_add($('template._alert'))
.find('p').text(a.responseText)
return ajaxAlert(e);
})
}
function progress(val){
var dom = $('.mct-progress');
val===true&&dom.toggle(val);
val===false&&dom.fadeOut(5000);
if (typeof val =='string'){
dom.find('span').text(val)
$('.mct-progress .progress-bar').width(val);
}
typeof val =='number'&& dom.find('.progress-bar').toggleClass('progress-bar-danger',!!val);
val===false&&dom.stop().fadeOut(3000);
if (typeof val =='string')
dom.find('.progress-bar').width(val).find('span').text(val);
typeof val =='number'&& dom.find('.progress-bar').toggleClass('bg-danger',!!val);
return progress;
}
// The plugin code https://gist.github.com/meleyal/3794126
Expand All @@ -105,7 +110,6 @@ $.fn.draghover = function(options) {
});
};
function upload_files(files){
// return new Promise((done,fail)=>{
if ( !files.length )
return ;//fail('no files')
var formData = new FormData();
Expand Down Expand Up @@ -135,17 +139,14 @@ function upload_files(files){
// once the upload reaches 100%, set the progress bar text to done
if (percentComplete === 100){
progress(false);
// done();
}
}
}, false);
return xhr;
}
}).fail(function(e){
progress(1)('ERROR '+e.responseText);
// fail(e.responseText)
progress(1)('ERROR: '+(e.responseText||e.state()));
});
// })
}
function stream_cmd(command,proc){
return function(){
Expand Down Expand Up @@ -480,7 +481,6 @@ $(function(){
});
(function(){
var m=$('#mct-tags-modal');
var a=$('#mct-alert');
var t=m.find('table tbody');
m.find('button.btn-primary').on('click',function(ev){
var row = t.find('.table-success');
Expand All @@ -493,8 +493,10 @@ $(function(){
$(this).find('tr').removeClass('table-success');
$(ev.target).parents('tr').addClass('table-success')
});
$('.mct-tags').on('click',function(){
$.ajax('/tags').then(function(data){
$('.mct-change').on('click',function(){
$.ajax('/tags')
.fail(ajaxAlert)
.then(function(data){
data=data.sort(function(a,b){ return a.date<b.date?1:a.date>b.date?-1:0;})
t.empty();
data.map(function(row){
Expand All @@ -503,25 +505,34 @@ $(function(){
m.modal();
})
})
})();
(function(){
var r=$('#mct-reset-modal');
var p=r.find('p');
$('.mct-reset').on('click',function(){
$.ajax('/status').then(function(data){
}());
(function(btn,ui){
var p=ui.find('p');
btn.on('click',function(){
$.ajax('/status')
.fail(ajaxAlert)
.then(function(data){
p.empty();
data.files.map(function(file){
p.append(file.path+'<br>')
})
r.modal();
ui.modal();
})
})
r.find('button.btn-primary').on('click',function(ev){
cmdReload($.ajax('/checkout-force'),r);
ui.find('button.btn-danger').on('click',function(ev){
cmdReload($.ajax('/checkout-force'),ui);
})
})();
}($('.mct-reset'),$('#mct-reset-modal')));
(function(btn){
btn.on('click',function(){
progress(0)(true)('50%');
$.ajax('/fetch')
.fail(ajaxAlert)
.then(function(a){ progress('100%')(false); return a})
})
}($('.mct-update')));
$('.mct-consoles').on('click',function(){ window.open('consoles.html','_blank') });
(function(){
(function(){ //REMOVE
var r=$('#mct-console-modal');
var p=r.find('textarea');
var b=r.find('.modal-body button');
Expand Down Expand Up @@ -612,7 +623,7 @@ $(function(){
var cmd;
$('.mct-pio-compile, .mct-pio-flash, .mct-ports a')
.toggleClass('disabled',!config.pio)
.attr(config.pio?'title':'null','')
.attr(!config.pio?'title':'null','PlatformIO not installed')
.eq(0).on('click',function(){
cmd=stream_cmd('/pio',proc)()
}).end()
Expand Down Expand Up @@ -676,7 +687,7 @@ $(function(){
}());
var state=$('.mct-changed input')
.on('change',function(){
var defs=$('.tab-pane[id*=card] .form-group')
var defs=$('.tab-pane[id*=card-C] .form-group')
if ($(this).prop('checked'))
defs.not('.bg-info').hide()
else
Expand Down

0 comments on commit 48d1fc7

Please sign in to comment.