Skip to content

Commit 6256a53

Browse files
committed
fixes #62 #64 #66 #67 #68 #70 #71 editor
1 parent eba39fd commit 6256a53

File tree

13 files changed

+70
-48
lines changed

13 files changed

+70
-48
lines changed

app/common.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,17 @@ const uploadFiles = files =>
3939
}
4040
})
4141
))
42+
const configFilesList = ['Configuration.h', 'Configuration_adv.h', '_Bootscreen.h', '_Statusscreen.h'];
43+
const configFilesListUpload = configFilesList.slice(0, 2);
4244

43-
const configFiles = p => Promise.all(
44-
['Configuration.h', 'Configuration_adv.h', '_Bootscreen.h']
45+
const uploadCopyFiles = files =>
46+
uploadFiles(files.filter(file => configFilesListUpload.indexOf(file.name) >= 0))
47+
.then(a => git.root())
48+
.then(root => Promise.all(
49+
files.filter(file => configFilesListUpload.indexOf(file.name) < 0).map(f => copyFile(f.path, path.join(root, 'Marlin', f.name)))
50+
))
51+
52+
const configFiles = p => Promise.all(configFilesList
4553
.map(file => seek4File(file, p ? [p.replace(/\\/g, path.sep)] : ['Marlin', path.join('Marlin', 'src', 'config')]).catch(() => null))
4654
).then(files => files.filter(a => a));
4755

@@ -56,7 +64,9 @@ const getThermistors = () =>
5664
module.exports = {
5765
seek4File,
5866
copyFile,
67+
uploadCopyFiles,
5968
uploadFiles,
69+
configFilesList,
6070
configFiles,
6171
getBoards,
6272
getThermistors,

app/mc-tool.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var addNumber=a=>{
3232
var killComments=a=>a.map(i=>(i.comment=null,i))
3333
var killDublicated=a=>a.filter(i=>i.number==undefined||!i.disabled).map(i=>(i.number=undefined,i))
3434

35-
const skips = ['CONFIGURATION_H_VERSION'];
35+
const skips = ['CONFIGURATION_H_VERSION', 'CONFIGURATION_ADV_H_VERSION'];
3636

3737
var setConfig=(target,file,root)=>a=>{
3838
var map=remap(a);

app/server.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var http = require('http');
1515
var https = require('https');
1616
var ua = require('universal-analytics');
1717
const {promisify, atob, walk, unique} = require('./helpers');
18-
const {seek4File, copyFile, uploadFiles, configFiles, getBoards, getThermistors} = require('./common');
18+
const {seek4File, copyFile, uploadCopyFiles, configFilesList, configFiles, getBoards, getThermistors} = require('./common');
1919
var qr = require('qr-image');
2020
var machineId = require('node-machine-id').machineId;
2121

@@ -73,6 +73,8 @@ var get_cfg=()=>{
7373

7474
var ex_dir = (rel) => seek4File('', [path.join('Marlin', 'example_configurations'), path.join('Marlin', 'src', 'config', 'examples')], rel)
7575

76+
const sortNCS = (a, b) => a.toLowerCase().localeCompare(b.toLowerCase());
77+
7678
app.get('/examples', function (req, res) {
7779
var ex;
7880
return ex_dir()
@@ -81,6 +83,7 @@ app.get('/examples', function (req, res) {
8183
.then(a=>a.filter(i=>/Configuration(_adv)?\.h/.test(i)))
8284
.then(a=>a.map(i=>path.parse(path.relative(ex,i)).dir))
8385
.then(unique)
86+
.then(a => a.sort(sortNCS))
8487
.catch(e => [])
8588
.then(a=>(a.unshift('Marlin'),a))
8689
.then(a => res.send({current: store.vars.baseCfg, list: a}))
@@ -196,19 +199,16 @@ app.post('/upload', function(req, res){
196199
done(files);
197200
})
198201
})
199-
.then(files=>{
200-
files.map(file=>{
201-
if (['Configuration.h','Configuration_adv.h'].indexOf(file.name)<0)
202-
throw 'Wrong file name! Allowed only Configuration.h and Configuration_adv.h';
203-
})
204-
return files;
205-
})
202+
.then(files => Promise.all(files.map(file =>
203+
configFilesList.indexOf(file.name) >= 0 ? file : Promise.reject('Wrong file name! Allowed only files ' + configFilesList)
204+
)))
206205
// .then(a=>(console.log(a),a))
207206
//process
208-
.then(uploadFiles)
207+
.then(uploadCopyFiles)
209208
.then(a=>res.send(a))
210209
.catch(e=>res.status(403).send(e))
211210
});
211+
212212
app.post('/set/:file/:name/:prop/:value', function (req, res) {
213213
var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
214214
var name = req.params.name.split('.');

app/services/editor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ router.get('/tree', function(req, res) {
5555
children: stats.isDirectory(),
5656
type: stats.isDirectory() ? 'default' : "file",
5757
text: name,
58-
id: path.join(dir, name),
58+
id: path.join(dir, name).replace(/\\/g, '/'),
5959
// icon: stats.isDirectory() ? 'jstree-folder' : "jstree-file",
6060
}))))
6161
)

app/services/git.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
const path = require('path');
2+
const fs = require('fs');
13
const router = module.exports = require('express').Router();
24
const git = require('../git-tool');
35
const store = require('../store');
4-
const atob = require('../helpers').atob;
6+
const {atob, promisify} = require('../helpers');
7+
const {seek4File, configFilesList, copyFile} = require('../common');
58

69
router.get('/tags', function (req, res) {
710
git.Tags()
@@ -32,17 +35,21 @@ router.get('/status', function (req, res) {
3235
router.get('/checkout-force', function (req, res) {
3336
var cp = () => git.root()
3437
.then(root => Promise.all(
35-
['Configuration.h', 'Configuration_adv.h', '_Bootscreen.h']
36-
.map(f=>new Promise((done,fail)=>
37-
fs.createReadStream(path.join(root, store.vars.baseCfg, f)).on('error', fail)
38-
.pipe(fs.createWriteStream(path.join(root, 'Marlin', f)).on('finish', done))
39-
).catch(e => 'not found')
38+
configFilesList
39+
.map(f =>
40+
copyFile(path.join(root, store.vars.baseCfg, f), path.join(root, 'Marlin', f))
41+
.catch(e => 'not found')
4042
)
4143
))
42-
var rm = () =>
43-
seek4File('_Bootscreen.h', [path.join('Marlin', 'src', 'config'), 'Marlin'])
44-
.then(file => file && promisify(fs.unlink)(file))
45-
.catch(a=>a);
44+
45+
var rm = () => Promise.all(
46+
['_Bootscreen.h', '_Statusscreen.h']
47+
.map(f =>
48+
seek4File(f, [path.join('Marlin', 'src', 'config'), 'Marlin'])
49+
.then(file => file && promisify(fs.unlink)(file))
50+
.catch(a=>a)
51+
)
52+
);
4653

4754
git.Checkout('--force')
4855
.then(rm)

app/services/pub.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const FormData = require('form-data');
1212
const git = require('../git-tool');
1313
const store = require('../store');
1414
const {promisify, atob, walk} = require('../helpers');
15-
const {seek4File, configFiles, getBoards, uploadFiles} = require('../common');
15+
const {seek4File, configFiles, getBoards, uploadCopyFiles} = require('../common');
1616

1717
var pubs = {};
1818

@@ -110,7 +110,7 @@ router.get('/site/:Id', function (req, res) {
110110
.then(buf => promisify(yauzl.fromBuffer)(buf, {lazyEntries:true}))
111111
.then(readZip)
112112
.then(files => files.map(i => ({path: i.file, name: i.entry.fileName})))
113-
.then(uploadFiles)
113+
.then(uploadCopyFiles)
114114
.then(a => (store.mods.sse.send('reload'),"page/application reloaded"))
115115
.then(a => res.send(a))
116116
.catch(e => (console.error(e),res.status(403).send(e)))

app/services/store.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const yazl = require("yazl");
88

99
const git = require('../git-tool');
1010
const {promisify, atob, walk, unique} = require('../helpers');
11-
const {seek4File, configFiles, getBoards, uploadFiles, copyFile} = require('../common');
11+
const {seek4File, configFiles, getBoards, uploadCopyFiles, copyFile} = require('../common');
1212
const store = require('../store');
1313

1414
router.get('/save', function (req, res) {
@@ -66,19 +66,7 @@ router.get('/restore/:path', function (req, res) {
6666
.then(root => path.join(root, store.config.store, p))
6767
.then(dir=>promisify(fs.stat)(dir).catch(a=>{throw 'no files';}).then(a=>dir))
6868
.then(walk)
69-
.then(files=>{
70-
var up=files
71-
.filter(i=>/Configuration(_adv)?\.h/.test(i))
72-
.map(f=>({path:f,name:path.parse(f).base}))
73-
var cp=files
74-
.filter(i=>/_Bootscreen\.h/.test(i))
75-
.map(f =>
76-
seek4File('', [path.join('Marlin', 'src', 'config'), 'Marlin'])
77-
.then(dir => copyFile(f, path.join(dir, path.basename(f) )))
78-
)
79-
console.log(cp);
80-
return uploadFiles(up).then(up=>Promise.all([...up,...cp]));
81-
})
69+
.then(files => uploadCopyFiles(files.map(f => ({path: f, name: path.parse(f).base}))))
8270
.then(a=>res.send(a))
8371
.catch(e=>res.status(403).send(e))
8472
});

index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,9 @@ app.on('ready', function() {
137137
dialog.showErrorBox('Error', e.message);
138138
app.quit();
139139
})
140-
});
140+
});
141+
142+
process.on('unhandledRejection', (reason, p) => {
143+
console.error('Unhandled Rejection at: Promise', p, 'reason:', reason);
144+
// application specific logging, throwing an error, or other logic here
145+
});

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "marlin-conf",
3-
"version": "2.10.3",
3+
"version": "2.10.4",
44
"description": "configuration tool for Marlin project",
55
"main": "./index.js",
66
"scripts": {
@@ -85,7 +85,7 @@
8585
"platformio-node-helpers": "^0.5.2",
8686
"qr-image": "^3.2.0",
8787
"rtcmulticonnection-v3": "^3.4.4",
88-
"serialport": "^6.2.0",
88+
"serialport": "=6.2.1",
8989
"simple-git": "^1.95.1",
9090
"socket.io": "^2.1.1",
9191
"swig-templates": "^2.0.2",

static/css/input-expand-group.css

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@
2727
width:100%;
2828
}
2929

30-
.input-expand-group:hover div div {
30+
.input-expand-group:focus-within div div {
3131
opacity:1;
3232
-webkit-transition:opacity 0.5s ease-in-out;
3333
}
34-
.input-expand-group:hover {
34+
.input-expand-group.expanded,
35+
.input-expand-group:hover,
36+
.input-expand-group:focus-within {
3537
width:100%;
3638
-webkit-transition:width 0.5s ease-in-out;
3739
}

0 commit comments

Comments
 (0)