marlin-conf
Advanced tools
Comparing version 2.0.5 to 2.2.0
@@ -1,10 +0,15 @@ | ||
var git = require('simple-git')(); | ||
var git = require('simple-git'); | ||
var exec = require('child_process').exec; | ||
var root; | ||
var gitRoot=()=> | ||
new Promise((done,fail)=>git.revparse(['--show-toplevel'],(e,a)=>e?fail(e):done(a.replace(/\r|\n/,'')))) | ||
var gitRoot=(root)=> | ||
new Promise((done,fail)=>git(root).revparse(['--show-toplevel'],(e,a)=>e?fail(e):done(a.replace(/\r|\n/,'')))) | ||
.then(root=>(console.log('[gitRoot]',root),root)) | ||
.catch(mst=>console.log('no root')) | ||
.catch(mst=>{ console.log('no root'); throw mst}) | ||
var gitroot=gitRoot(); | ||
var gitTag=()=> | ||
new Promise((done,fail)=>git.raw(['describe','--tags'],(e,a)=>e?fail(e):done(a.replace(/\r|\n/,'')))) | ||
new Promise((done,fail)=>git(root).raw(['describe','--tags'],(e,a)=>e?fail(e):done(a.replace(/\r|\n/,'')))) | ||
.then(root=>(console.log('[gitTag]',root),root)) | ||
@@ -14,3 +19,3 @@ .catch(mst=>console.log('no tag')) | ||
var gitTags2=()=> | ||
new Promise((done,fail)=>git.tags([],(e,a)=>e?fail(e):done(a))) | ||
new Promise((done,fail)=>git(root).tags([],(e,a)=>e?fail(e):done(a))) | ||
.then(root=>(console.log('[gitTags]',root.all.toString()),root)) | ||
@@ -23,3 +28,3 @@ var getTag=msg=>{ | ||
var gitTags=()=> | ||
new Promise((done,fail)=>git.log(['--tags','--simplify-by-decoration'],(e,a)=>e?fail(e):done(a))) //,'--pretty="format:%ci %d"' | ||
new Promise((done,fail)=>git(root).log(['--tags','--simplify-by-decoration'],(e,a)=>e?fail(e):done(a))) //,'--pretty="format:%ci %d"' | ||
.then(simplyTag) | ||
@@ -30,8 +35,13 @@ .then(root=>(console.log('[gitTags]',root),root)) | ||
var gitShow=(branch,file)=> | ||
new Promise((done,fail)=>git.show([branch+':'+file],(e,a)=>e?fail(e):done(a))); | ||
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))); | ||
var gitroot=gitRoot(); | ||
exports.Checkout=gitCheckout; | ||
exports.Status=gitStatus; | ||
exports.Root=gitRoot; | ||
@@ -42,2 +52,27 @@ exports.Tag=gitTag; | ||
exports.git=git; | ||
exports.root=gitroot; | ||
exports.root=a=>{ | ||
if (a){ | ||
gitroot=gitRoot(a); | ||
return gitroot.then(_root=>root=_root); | ||
} | ||
return gitroot; | ||
} | ||
exports.clone=name=>new Promise((done,fail)=>{ | ||
var cmd = exec('git clone https://github.com/MarlinFirmware/Marlin.git '+(name||'')); | ||
var timer = setInterval(a=>process.stdout.write("."), 500) | ||
cmd.stdout.on('data', (data) => { | ||
console.log(data.toString()); | ||
}); | ||
cmd.stderr.on('data', (data) => { | ||
console.log(data.toString()); | ||
}); | ||
cmd.on('close', (code) => { | ||
clearInterval(timer); | ||
console.log(); | ||
if (code == 0) | ||
done(); | ||
else | ||
fail(); | ||
}); | ||
}) |
13
hints.js
@@ -10,3 +10,2 @@ var fs = require('fs'); | ||
var md=fs.readFileSync(docFile,'utf8'); | ||
@@ -31,2 +30,3 @@ marked.setOptions({ | ||
var md=fs.statSync(docFile)&&fs.readFileSync(docFile,'utf8')||''; | ||
var tokens=marked.lexer(md); | ||
@@ -41,4 +41,4 @@ | ||
},{}) | ||
var headings=map('heading')(tokens).map(i=>i.index); | ||
var headings=map('heading')(tokens).map(i=>i.index); | ||
function extendTokens(tokens){ | ||
@@ -79,2 +79,4 @@ var _alert={ | ||
var banner='<link rel="stylesheet" title="Default" href="styles/default.css">'; | ||
var banner2='<script src="head.min.js"></script><script>head.load("sheetrock.min.js");</script>'; | ||
var add_banner=''; | ||
if (find){ | ||
@@ -88,9 +90,12 @@ var ob=headings.reduce((ob,v)=>{ | ||
cut=extendTokens(cut); | ||
if(cut.filter(i=>/sheetrock\.min/.test(i.text||'')).length) | ||
add_banner=banner2; | ||
cut.links={}; | ||
return marked.parser(cut); | ||
return add_banner+marked.parser(cut); | ||
} | ||
} | ||
exports.url=url; | ||
exports.load=load; | ||
function load(){ | ||
var file = fs.createWriteStream(); | ||
var file = fs.createWriteStream(docFile); | ||
var request = http.get(url, function(response) { | ||
@@ -97,0 +102,0 @@ if (response.statusCode==302) |
@@ -42,5 +42,7 @@ //modules | ||
var killComments=a=>a.map(i=>(i.comment=null,i)) | ||
var setConfig=(target,file,root)=>a=>{ | ||
var map=remap(a); | ||
return target.then(t=>{ | ||
return Promise.resolve(target).then(t=>{ | ||
var undef=[]; | ||
@@ -61,2 +63,3 @@ var res=t.map(i=>{ | ||
o.value = i.value; | ||
if ( i.comment !== null ) | ||
if ( i.comment != undefined || o.comment != undefined ) | ||
@@ -85,5 +88,7 @@ if ( changed.comment = ( o.comment || '' ).trim() != ( i.comment || '' ).trim() ) | ||
var res=a.map(i=>{ | ||
var o=map[i.name]; | ||
if (o){ | ||
var o=o[Math.min(i.number||0,o.length-1)]; | ||
var oo=map[i.name]; | ||
if (oo){ | ||
var o=oo[Math.min(i.number||0,oo.length-1)]; | ||
if ( oo.length>1 && !i.number ) | ||
o=oo.filter(i=>!i.disabled)[oo.length-1] | ||
if (o){ | ||
@@ -117,2 +122,8 @@ var changed = {}; | ||
var stripConfA=a=>a.map(i=>{ | ||
var obj = { name: i.name, disabled: i.disabled, value:i.value }; | ||
if ( i.number != undefined ) | ||
obj.number = i.number; | ||
return obj; | ||
}); | ||
@@ -162,2 +173,3 @@ | ||
} | ||
var groups=[ | ||
@@ -192,5 +204,7 @@ ["DELTA", //? | ||
var section=i=>({name:i.name,type:type(i),condition:i.condition.length&&i.condition||undefined,value:i.value||!i.disabled}) | ||
var section1=(p,i)=>(p[i.name]={changed:i.changed,type:type1(i),condition:i.condition.length&&i.condition||undefined,value:i.value,disabled:i.disabled},p) | ||
var section1=(p,i)=>(p[i.name]={changed:i.changed,type:type1(i),condition:i.condition.length&&i.condition||undefined,value:i.value,disabled:i.disabled,line:i.line},p) | ||
var section_txt=(p,i)=>(i.changed&&(p[i.name]={value:i.changed.value||i.value,disabled:i.changed.disabled||i.disabled}),p) | ||
/* PROCESSORS */ | ||
module.exports.getJson=(root,base,tag)=>file=>{ | ||
@@ -208,6 +222,7 @@ var p=path.parse(file); | ||
.then(a=>(a.sections=unique(a.names.map(i=>i.section)).filter(i=>i),a)) | ||
.then(a=>((a.sections=a.sections.length?a.sections:['common']),a)) | ||
// .then((a,m)=>(m={},a.sections.map(s=>(m[s]=a.names.filter(i=>i.section==s).map(section))),{groups:groups,sections:m,names:a.names})) | ||
.then(a=>(a.groups=groups,a)) | ||
.then(a=>(a.defs=a.names.reduce(section1,{}),a)) | ||
.then(a=>(a.list=a.sections.reduce((p,s)=>(p[s]=a.names.filter(i=>i.section==s).map(i=>i.name),p),{}),a)) | ||
.then(a=>(a.list=a.sections.reduce((p,s)=>(p[s]=a.names.filter(i=>(i.section||'common')==s).map(i=>i.name),p),{}),a)) | ||
// .then(a=>(a.all=a.sections.reduce((p,s)=>(p[s]=a.names.filter(i=>i.section==s).map(section),p),{}),a)) | ||
@@ -219,2 +234,3 @@ .then(a=>(a.txt=a.names.reduce(section_txt,{}),a)) //changed | ||
} | ||
module.exports.updateH=(root,file,json)=>{ | ||
@@ -234,3 +250,2 @@ var h=inFile(file); | ||
module.exports.makeTxt=(root,base,git)=>file=>{ | ||
@@ -255,3 +270,2 @@ var p=path.parse(file); | ||
module.exports.makeH=(root,base)=>file=>{ | ||
@@ -271,1 +285,46 @@ var p=path.parse(file); | ||
} | ||
module.exports.makeCfg=file=>{ | ||
return inFile(file) | ||
.then(mc.h2json) | ||
.then(addNumber) | ||
.then(killComments) | ||
// .then(stripConfA) | ||
// .then(uniqueJson) | ||
// .then(toJson) | ||
// .then(outFile(path.join(p.dir,p.name+'.json'))) | ||
.then(a=>(console.log('done conf: ',file),a)) | ||
.catch(a=>(console.log('fail conf: ',file,a),a)) | ||
} | ||
module.exports.makeHH=(root,name)=>conf=>{ | ||
var p=path.join(root||'','Marlin',name); | ||
var h=inFile(p); | ||
return h | ||
.then(mc.h2json) | ||
.then(addNumber) | ||
.then(setConfig(conf)) | ||
.then(onlyChanged) | ||
.then(stripConf) | ||
.then(uniqueJson) | ||
// .then(extendFrom(h)) | ||
// .then(array2text) | ||
// .then(outFile(path.join(p.dir,p.name+'.h'))) | ||
.then(a=>(console.log('done conf h: ',path.relative(root,p)),a)) | ||
.catch(a=>(console.log('fail conf h: ',file,a),a)) | ||
} | ||
module.exports.makeHfile=(root,name)=>conf=>{ | ||
var p=path.join(root||'','Marlin',name); | ||
var h=inFile(p); | ||
return h | ||
.then(mc.h2json) | ||
.then(addNumber) | ||
.then(setConfig(conf)) | ||
.then(onlyChanged) | ||
.then(extendFrom(h)) | ||
.then(array2text) | ||
.then(outFile(p)) | ||
.then(a=>(console.log('done update h file: ',path.relative(root,p)),a)) | ||
.catch(a=>(console.log('fail update h file: ',file,a),a)) | ||
} |
{ | ||
"name": "marlin-conf", | ||
"version": "2.0.5", | ||
"version": "2.2.0", | ||
"description": "configuration tool for Marlin project", | ||
@@ -27,2 +27,3 @@ "scripts": { | ||
"express": "^4.15.2", | ||
"formidable": "^1.1.1", | ||
"get-port": "^3.1.0", | ||
@@ -29,0 +30,0 @@ "highlight.js": "^9.11.0", |
# marlin-config | ||
This software can help to migrate your own configuration from one release to another - with files | ||
Configuration.h and Configuration_adv.h | ||
This is a help tool, intended for easy configuration of [Marlin firmware](https://github.com/MarlinFirmware/Marlin) | ||
creating file for issue publication `mct git 1.1.0-RC7 txt` (compare 1.1.0-RC7 release with your current files in folder and create readable text file) | ||
Features: | ||
migrate configuration: | ||
* automatically clone repository from github if you don't have it | ||
* instant changing of Configuration*.h files | ||
* filter only changed options | ||
* show help for options | ||
* reset configuration changes | ||
* switch between releases, available after reset | ||
* **uploading old configuration over current** | ||
* creating an issue on [Marlin](https://github.com/MarlinFirmware/Marlin) with your configuration | ||
1. with one command you can create .json files with your personal states/values/comments for each #define | ||
in project used documentation from [MarlinDocumentation](https://github.com/MarlinFirmware/MarlinDocumentation/_configuration/configuration.md) | ||
- example: `mct git 1.1.0-RC7 json` (compare 1.1.0-RC7 release with your current files in folder and create .json) | ||
2. than copy .json files to another folder or change git branch | ||
3. recover your configuration | ||
- example: `mct git 1.1.0-RC8 h` (use 1.1.0-RC8 release and add your stored in .json configuration) | ||
# installation | ||
@@ -24,6 +23,24 @@ | ||
# using | ||
open terminal in an empty folder or in a folder with Marlin repository and type | ||
`mct` and confirm action | ||
then in browser you get interface for other features | ||
In clean/unchanged configuration you can change current release version | ||
Then you can upload or drag in browser your Configuration*.h files | ||
# mct help | ||
``` | ||
usage: mct help|git|tree | ||
usage: mct help|git|tree|conf|clone | ||
You need to run it in Marlin git repository | ||
commands: | ||
mct | ||
asks to 'clone' if current folder has no repository then run 'conf' | ||
mct conf | ||
open browser for interactive configuration | ||
mct clone | ||
clone current Marlin repository to current working directory | ||
mct git <git-tag> json|h|txt | ||
@@ -46,1 +63,16 @@ json: compare [gitroot]/Marlin/Configuration*.h files | ||
``` | ||
command interface: | ||
* creating file for issue publication `mct git 1.1.0-RC7 txt` (compare 1.1.0-RC7 release with your current files in folder and create readable text file) | ||
* migrate configuration: | ||
1. with one command you can create .json files with your personal states/values/comments for each #define | ||
- example: `mct git 1.1.0-RC7 json` (compare 1.1.0-RC7 release with your current files in folder and create .json) | ||
2. than copy .json files to another folder or change git branch | ||
3. recover your configuration | ||
- example: `mct git 1.1.0-RC8 h` (use 1.1.0-RC8 release and add your stored in .json configuration) |
@@ -10,2 +10,4 @@ var express = require('express'); | ||
var fs = require('fs'); | ||
var formidable = require('formidable'); | ||
var pjson = require('./package.json'); | ||
@@ -21,10 +23,15 @@ var port= 3000; | ||
app.get('/tags', function (req, res) { | ||
git.git.tags(['--sort=-creatordate'],function (err, data) { //,"--format='%(creatordate) %(refname)'" | ||
git.Tags().then(data=>{ | ||
res.send(data); | ||
}); | ||
}); | ||
//var tag=git.Tag(); | ||
//console.log(tag); | ||
app.get('/checkout/:branch', function (req, res) { | ||
git.Checkout(req.params.branch) | ||
.then(data=>{ | ||
res.send(data); | ||
}) | ||
.catch(a=>res.status(403).send(a)) | ||
}); | ||
var get_cfg=()=>{//new Promise((res,fail)=>{ | ||
var base=Promise.all([git.root,git.Tag()]); | ||
var base=Promise.all([git.root(),git.Tag()]); | ||
var list=['Marlin/Configuration.h','Marlin/Configuration_adv.h'].map(f=>{ | ||
@@ -35,8 +42,8 @@ return base | ||
// .then(o=>(o.names.map(n=>o.defs[n]&&(o.defs[n].hint=1)),o)) | ||
.then(a=>(a.names=undefined,a)) | ||
.then(a=>(a.names=undefined,type='file',a)) | ||
// .then(a=>res(a)) | ||
}); | ||
list.push({type:'info',pkg:pjson}) | ||
return Promise.all(list) | ||
} | ||
//application/json | ||
app.get('/now/', function (req, res) { | ||
@@ -50,9 +57,56 @@ res.set('Content-Type', 'text/plain'); | ||
}); | ||
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)) | ||
}); | ||
app.get('/hint/:name', function (req, res) { | ||
// res.send('<a href='+hints.url+'>Documentation</a>'); | ||
res.send(hints.hint(req.params.name)); | ||
//res.send(req.params) | ||
}) | ||
app.post('/upload', function(req, res){ | ||
var uploadDir = path.join(__dirname, '/uploads'); | ||
new Promise((done,fail)=>{ | ||
var form = new formidable.IncomingForm(); | ||
form.multiples = true; | ||
form.parse(req,function(err, fields, files) { | ||
if ( err ) | ||
return fail(err); | ||
files=files[Object.keys(files)[0]]; | ||
files=Array.isArray(files)&&files||[files] | ||
done(files); | ||
}) | ||
}) | ||
.then(files=>{ | ||
files.map(file=>{ | ||
if (['Configuration.h','Configuration_adv.h'].indexOf(file.name)<0) | ||
throw 'Wrong file name! Allowed only Configuration.h and Configuration_adv.h'; | ||
}) | ||
return files; | ||
}) | ||
// .then(a=>(console.log(a),a)) | ||
//process | ||
.then(files=>{ | ||
return Promise.all(files.map(file=>git.root().then(root=>{ | ||
try{ | ||
return mctool | ||
.makeCfg(file.path) | ||
.then(mctool.makeHfile(root,file.name)) | ||
}catch(e) { console.log(e); throw e; } | ||
}) | ||
// return new Promise((done,fail)=> | ||
// fs.rename(file.path, path.join(uploadDir, file.name),(err,ok)=>(err&&fail(err)||done(ok)))) | ||
)) | ||
}) | ||
.then(a=>res.send(a)) | ||
// .then(a=>res.end('success')) | ||
.catch(e=>res.status(403).send(e)) | ||
/* | ||
res.writeHead(200, {'content-type': 'text/plain'}); | ||
res.write('received upload:\n\n'); | ||
res.end('success'); | ||
*/ | ||
}); | ||
app.post('/set/:file/:name/:prop/:value', function (req, res) { | ||
git.root | ||
git.root() | ||
.then(root=>{ | ||
@@ -70,3 +124,4 @@ var ob=[{ name:req.params.name}] | ||
function main(){ | ||
git.root.then(root=>{ | ||
git.root() | ||
.then(root=>{ | ||
fs.stat(path.join(root,'Marlin'),(e,a)=>{ | ||
@@ -73,0 +128,0 @@ if(!a) |
63
start.js
@@ -11,2 +11,3 @@ //modules | ||
var readline = require('readline'); | ||
var hints = require('./hints'); | ||
@@ -41,3 +42,3 @@ var doJson=(root)=> | ||
function main(){ | ||
var is={tree:1,json:1,h:1,git:0,rm:1,help:1,txt:1,conf:1} | ||
var is={tree:1,json:1,h:1,git:0,rm:1,help:1,txt:1,conf:1,clone:1,hints:1} | ||
.filter((v,key,o,p,i)=>(p=process.argv,i=p.indexOf(key),!v&&i>=0&&i+1<p.length&&(o[key]=p[i+1]),i>=0)); | ||
@@ -51,3 +52,3 @@ // var tag=git.Tag(); | ||
['Marlin/Configuration_adv','Marlin/Configuration'].forEach(f=>{ | ||
var base=Promise.all([git.root,git.Show(is.git,f)]); | ||
var base=Promise.all([git.root(),git.Show(is.git,f)]); | ||
if ( is.json ) | ||
@@ -67,3 +68,3 @@ base | ||
if ( is.tree ){ | ||
git.root | ||
git.root() | ||
.then( root=> is.json ? doJson(root) : root ) | ||
@@ -75,15 +76,49 @@ .then( root=> is.h ? doH(root) : root ) | ||
server.main() | ||
}else | ||
if ( is.hints ){ | ||
hints.load() | ||
}else | ||
if ( is.clone ){ | ||
git.root().then(root=>{ | ||
console.log('there is git'); | ||
}).catch(err=>{ | ||
git.clone().then(a=>console.log('over')); | ||
}) | ||
}else{ | ||
git.root.then(root=>{ | ||
console.log('type: mct help if you need more information'); | ||
if(root){ | ||
var rl = readline.createInterface({ | ||
function getConsole(){ | ||
return readline.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout | ||
}); | ||
rl.question('press Enter to run web browser or ^C to exit', (answer) => { | ||
server.main() | ||
}); | ||
} | ||
function startWeb(){ | ||
git.root() | ||
.then(root=>{ | ||
console.log('type: mct help if you need more information'); | ||
if(root){ | ||
var rl = getConsole(); | ||
rl.question('press Enter to run web browser or ^C to exit', (answer) => { | ||
rl.close(); | ||
server.main() | ||
}); | ||
} | ||
}) | ||
} | ||
function tryRun(){ | ||
process.chdir('Marlin') | ||
console.log(process.cwd()) | ||
git.root('Marlin').then(a=>{ | ||
server.main(); | ||
}); | ||
} | ||
git.root() | ||
.then(startWeb) | ||
.catch(a=>{ | ||
var rl = getConsole(); | ||
rl.question('press Enter to clone it from web or ^C to exit', (answer) => { | ||
rl.close(); | ||
git.clone() | ||
.then(tryRun) | ||
.catch(tryRun) | ||
}); | ||
} | ||
}) | ||
@@ -95,7 +130,11 @@ } | ||
console.log(`${pjson.name} v ${pjson.version} | ||
usage: mct help|git|tree | ||
usage: mct help|git|tree|conf|clone | ||
You need to run it in Marlin git repository | ||
commands: | ||
mct | ||
asks to 'clone' if current folder has no repository then run 'conf' | ||
mct conf | ||
open browser for interactive configuration | ||
mct clone | ||
clone current Marlin repository to current working directory | ||
mct git <git-tag> json|h|txt | ||
@@ -102,0 +141,0 @@ json: compare [gitroot]/Marlin/Configuration*.h files |
@@ -27,7 +27,143 @@ function _add(tmpl){ | ||
} | ||
var bootstrap_alert = function() {} | ||
bootstrap_alert.error = function(message) { | ||
$('#mct-alert').html(` | ||
<div class="alert alert-danger alert-dismissible fade in" id="mct-alert" role="alert"> | ||
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button> | ||
<h4>Oh snap! You got an error!</h4><p></p></div> | ||
`).find('p').text(message) | ||
} | ||
function getVal(ob,name){ | ||
if( ob.changed != undefined) | ||
// if( 'changed' in ob) | ||
return ob.changed[name] | ||
return ob[name] | ||
} | ||
function cmdReload(cmd,modal){ | ||
cmd | ||
.then(function(data){ | ||
$(window).unbind('beforeunload'); | ||
window.location.reload(); | ||
}) | ||
.fail(function(a){ | ||
modal&&modal.modal('hide') | ||
bootstrap_alert.error(a.responseText); | ||
}) | ||
} | ||
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); | ||
return progress; | ||
} | ||
// The plugin code https://gist.github.com/meleyal/3794126 | ||
$.fn.draghover = function(options) { | ||
return this.each(function() { | ||
var collection = $(), | ||
self = $(this); | ||
self.on('dragenter', function(e) { | ||
if (collection.length === 0) { | ||
self.trigger('draghoverstart'); | ||
} | ||
collection = collection.add(e.target); | ||
}); | ||
self.on('dragleave drop', function(e) { | ||
collection = collection.not(e.target); | ||
if (collection.length === 0) { | ||
self.trigger('draghoverend'); | ||
} | ||
}); | ||
}); | ||
}; | ||
function upload_files(files){ | ||
// return new Promise((done,fail)=>{ | ||
if ( !files.length ) | ||
return fail('no files') | ||
var formData = new FormData(); | ||
for (var i = 0; i < files.length; i++) { | ||
var file = files[i]; | ||
formData.append('uploads[]', file, file.name); | ||
} | ||
progress(0)(true); | ||
return $.ajax({ | ||
url: '/upload', | ||
type: 'POST', | ||
data: formData, | ||
processData: false, | ||
contentType: false, | ||
success: function(data){ | ||
console.log('upload successful!\n' + data); | ||
}, | ||
xhr: function() { | ||
var xhr = new XMLHttpRequest(); | ||
xhr.upload.addEventListener('progress', function(evt) { | ||
if (evt.lengthComputable) { | ||
// calculate the percentage of upload completed | ||
var percentComplete = evt.loaded / evt.total; | ||
percentComplete = parseInt(percentComplete * 100); | ||
progress(percentComplete + '%'); | ||
// update the Bootstrap progress bar with the new percentage | ||
// 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) | ||
}); | ||
// }) | ||
} | ||
$(function(){ | ||
//uploader decoration | ||
var dropZone=$('#mct-dragzone') | ||
$(window) | ||
//properly check enter & leave window | ||
.draghover().on('draghoverstart draghoverend', function(ev) { | ||
dropZone.toggle(ev.type=='draghoverstart'); | ||
}); | ||
$(window) | ||
//.on('beforeunload',function(){ return "Do You want leave page?"}) | ||
//prevent drop on window | ||
.on('drop',function(ev) { | ||
ev.preventDefault(); | ||
}) | ||
.on('dragover', function(ev) { | ||
ev.preventDefault(); | ||
}) | ||
dropZone.on('dragover dragleave', function(ev) { | ||
dropZone.toggleClass('drop',ev.type=='dragover'); | ||
if (ev.type=='dragover') | ||
ev.preventDefault(); | ||
}) | ||
dropZone.on('drop',function(ev) { | ||
ev.preventDefault(); | ||
cmdReload(upload_files(ev.originalEvent.dataTransfer.files)) | ||
}) | ||
$('button.mct-upload').on('click', function(){ | ||
$('input.mct-upload').trigger('click') | ||
}); | ||
$('input.mct-upload').on('change',function(){ | ||
var files = $(this).get(0).files; | ||
cmdReload(upload_files(files)); | ||
}); | ||
//end uploader decoration | ||
var defs=$.get('/json'); | ||
defs.then(function(data){ | ||
data.forEach(function(file){ | ||
$('.mct-header span').eq(0).text(file.tag) | ||
if (file.type=='info'){ | ||
$('.mct-version').attr('href',file.pkg.homepage).text(file.pkg.name+' v'+file.pkg.version) | ||
return; | ||
} | ||
$('.mct-tags').eq(0).text(file.tag) | ||
var href='panel-'+file.file.name; | ||
@@ -49,4 +185,4 @@ _add($('template._file_tab')) | ||
d.addClass('bg-info') | ||
d.find('label').text(define); | ||
var dis=d.find('input').eq(0).attr('checked',!(def.changed&&def.changed.disabled||def.disabled)); | ||
d.find('label').text(define).attr('title',def.line).tooltip(); | ||
var dis=d.find('input').eq(0).attr('checked',!getVal(def,'disabled')) | ||
var dv=(def.changed&&def.changed.value||def.value); | ||
@@ -94,3 +230,45 @@ if (def.type=='string') | ||
}) | ||
$('.mct-header button').on('click',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('.success'); | ||
if(row.length){ | ||
var tag=row.find('td').eq(1).text().split(','); | ||
cmdReload($.ajax('/checkout/'+tag[0]),m); | ||
} | ||
}); | ||
m.find('table tbody').on('click',function(ev){ | ||
$(this).find('tr').removeClass('success'); | ||
$(ev.target).parents('tr').addClass('success') | ||
}); | ||
$('.mct-tags').on('click',function(){ | ||
$.ajax('/tags').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){ | ||
t.append($('<tr>').append($('<td>').text(row.date)).append($('<td>').text(row.tag))) | ||
}) | ||
m.modal(); | ||
}) | ||
}) | ||
} | ||
{ | ||
var r=$('#mct-reset-modal'); | ||
var p=r.find('p'); | ||
$('.mct-reset').on('click',function(){ | ||
$.ajax('/status').then(function(data){ | ||
p.empty(); | ||
data.files.map(function(file){ | ||
p.append(file.path+'<br>') | ||
}) | ||
r.modal(); | ||
}) | ||
}) | ||
r.find('button.btn-primary').on('click',function(ev){ | ||
cmdReload($.ajax('/checkout-force'),r); | ||
}) | ||
} | ||
$('.mct-issue').on('click',function(){ | ||
defs.then(function(data){ | ||
@@ -117,3 +295,3 @@ var text=''; | ||
if (f) | ||
text+='//file '+file.file.base+'\n'+f; | ||
text+='\n//file '+file.file.base+' Release:'+file.tag+'\n'+f; | ||
}) | ||
@@ -120,0 +298,0 @@ window.open(encodeURI('https://github.com/MarlinFirmware/Marlin/issues/new?title=&body='+text).replace(/\#/g,'%23')) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
188698
1327
77
10
3
+ Addedformidable@^1.1.1
+ Addedformidable@1.2.6(transitive)