Skip to content

Commit

Permalink
fixes #62 #64 #66 #67 #68 #70 #71 editor
Browse files Browse the repository at this point in the history
  • Loading branch information
akaJes committed Oct 4, 2018
1 parent eba39fd commit 6256a53
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 48 deletions.
14 changes: 12 additions & 2 deletions app/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,17 @@ const uploadFiles = files =>
}
})
))
const configFilesList = ['Configuration.h', 'Configuration_adv.h', '_Bootscreen.h', '_Statusscreen.h'];
const configFilesListUpload = configFilesList.slice(0, 2);

const configFiles = p => Promise.all(
['Configuration.h', 'Configuration_adv.h', '_Bootscreen.h']
const uploadCopyFiles = files =>
uploadFiles(files.filter(file => configFilesListUpload.indexOf(file.name) >= 0))
.then(a => git.root())
.then(root => Promise.all(
files.filter(file => configFilesListUpload.indexOf(file.name) < 0).map(f => copyFile(f.path, path.join(root, 'Marlin', f.name)))
))

const configFiles = p => Promise.all(configFilesList
.map(file => seek4File(file, p ? [p.replace(/\\/g, path.sep)] : ['Marlin', path.join('Marlin', 'src', 'config')]).catch(() => null))
).then(files => files.filter(a => a));

Expand All @@ -56,7 +64,9 @@ const getThermistors = () =>
module.exports = {
seek4File,
copyFile,
uploadCopyFiles,
uploadFiles,
configFilesList,
configFiles,
getBoards,
getThermistors,
Expand Down
2 changes: 1 addition & 1 deletion app/mc-tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var addNumber=a=>{
var killComments=a=>a.map(i=>(i.comment=null,i))
var killDublicated=a=>a.filter(i=>i.number==undefined||!i.disabled).map(i=>(i.number=undefined,i))

const skips = ['CONFIGURATION_H_VERSION'];
const skips = ['CONFIGURATION_H_VERSION', 'CONFIGURATION_ADV_H_VERSION'];

var setConfig=(target,file,root)=>a=>{
var map=remap(a);
Expand Down
18 changes: 9 additions & 9 deletions app/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var http = require('http');
var https = require('https');
var ua = require('universal-analytics');
const {promisify, atob, walk, unique} = require('./helpers');
const {seek4File, copyFile, uploadFiles, configFiles, getBoards, getThermistors} = require('./common');
const {seek4File, copyFile, uploadCopyFiles, configFilesList, configFiles, getBoards, getThermistors} = require('./common');
var qr = require('qr-image');
var machineId = require('node-machine-id').machineId;

Expand Down Expand Up @@ -73,6 +73,8 @@ var get_cfg=()=>{

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

const sortNCS = (a, b) => a.toLowerCase().localeCompare(b.toLowerCase());

app.get('/examples', function (req, res) {
var ex;
return ex_dir()
Expand All @@ -81,6 +83,7 @@ app.get('/examples', function (req, res) {
.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.sort(sortNCS))
.catch(e => [])
.then(a=>(a.unshift('Marlin'),a))
.then(a => res.send({current: store.vars.baseCfg, list: a}))
Expand Down Expand Up @@ -196,19 +199,16 @@ app.post('/upload', function(req, res){
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(files => Promise.all(files.map(file =>
configFilesList.indexOf(file.name) >= 0 ? file : Promise.reject('Wrong file name! Allowed only files ' + configFilesList)
)))
// .then(a=>(console.log(a),a))
//process
.then(uploadFiles)
.then(uploadCopyFiles)
.then(a=>res.send(a))
.catch(e=>res.status(403).send(e))
});

app.post('/set/:file/:name/:prop/:value', function (req, res) {
var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
var name = req.params.name.split('.');
Expand Down
2 changes: 1 addition & 1 deletion app/services/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ router.get('/tree', function(req, res) {
children: stats.isDirectory(),
type: stats.isDirectory() ? 'default' : "file",
text: name,
id: path.join(dir, name),
id: path.join(dir, name).replace(/\\/g, '/'),
// icon: stats.isDirectory() ? 'jstree-folder' : "jstree-file",
}))))
)
Expand Down
27 changes: 17 additions & 10 deletions app/services/git.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
const path = require('path');
const fs = require('fs');
const router = module.exports = require('express').Router();
const git = require('../git-tool');
const store = require('../store');
const atob = require('../helpers').atob;
const {atob, promisify} = require('../helpers');
const {seek4File, configFilesList, copyFile} = require('../common');

router.get('/tags', function (req, res) {
git.Tags()
Expand Down Expand Up @@ -32,17 +35,21 @@ router.get('/status', function (req, res) {
router.get('/checkout-force', function (req, res) {
var cp = () => git.root()
.then(root => Promise.all(
['Configuration.h', 'Configuration_adv.h', '_Bootscreen.h']
.map(f=>new Promise((done,fail)=>
fs.createReadStream(path.join(root, store.vars.baseCfg, f)).on('error', fail)
.pipe(fs.createWriteStream(path.join(root, 'Marlin', f)).on('finish', done))
).catch(e => 'not found')
configFilesList
.map(f =>
copyFile(path.join(root, store.vars.baseCfg, f), path.join(root, 'Marlin', f))
.catch(e => 'not found')
)
))
var rm = () =>
seek4File('_Bootscreen.h', [path.join('Marlin', 'src', 'config'), 'Marlin'])
.then(file => file && promisify(fs.unlink)(file))
.catch(a=>a);

var rm = () => Promise.all(
['_Bootscreen.h', '_Statusscreen.h']
.map(f =>
seek4File(f, [path.join('Marlin', 'src', 'config'), 'Marlin'])
.then(file => file && promisify(fs.unlink)(file))
.catch(a=>a)
)
);

git.Checkout('--force')
.then(rm)
Expand Down
4 changes: 2 additions & 2 deletions app/services/pub.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const FormData = require('form-data');
const git = require('../git-tool');
const store = require('../store');
const {promisify, atob, walk} = require('../helpers');
const {seek4File, configFiles, getBoards, uploadFiles} = require('../common');
const {seek4File, configFiles, getBoards, uploadCopyFiles} = require('../common');

var pubs = {};

Expand Down Expand Up @@ -110,7 +110,7 @@ router.get('/site/:Id', function (req, res) {
.then(buf => promisify(yauzl.fromBuffer)(buf, {lazyEntries:true}))
.then(readZip)
.then(files => files.map(i => ({path: i.file, name: i.entry.fileName})))
.then(uploadFiles)
.then(uploadCopyFiles)
.then(a => (store.mods.sse.send('reload'),"page/application reloaded"))
.then(a => res.send(a))
.catch(e => (console.error(e),res.status(403).send(e)))
Expand Down
16 changes: 2 additions & 14 deletions app/services/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const yazl = require("yazl");

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

router.get('/save', function (req, res) {
Expand Down Expand Up @@ -66,19 +66,7 @@ router.get('/restore/:path', function (req, res) {
.then(root => path.join(root, store.config.store, p))
.then(dir=>promisify(fs.stat)(dir).catch(a=>{throw 'no files';}).then(a=>dir))
.then(walk)
.then(files=>{
var up=files
.filter(i=>/Configuration(_adv)?\.h/.test(i))
.map(f=>({path:f,name:path.parse(f).base}))
var cp=files
.filter(i=>/_Bootscreen\.h/.test(i))
.map(f =>
seek4File('', [path.join('Marlin', 'src', 'config'), 'Marlin'])
.then(dir => copyFile(f, path.join(dir, path.basename(f) )))
)
console.log(cp);
return uploadFiles(up).then(up=>Promise.all([...up,...cp]));
})
.then(files => uploadCopyFiles(files.map(f => ({path: f, name: path.parse(f).base}))))
.then(a=>res.send(a))
.catch(e=>res.status(403).send(e))
});
Expand Down
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,9 @@ app.on('ready', function() {
dialog.showErrorBox('Error', e.message);
app.quit();
})
});
});

process.on('unhandledRejection', (reason, p) => {
console.error('Unhandled Rejection at: Promise', p, 'reason:', reason);
// application specific logging, throwing an error, or other logic here
});
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "marlin-conf",
"version": "2.10.3",
"version": "2.10.4",
"description": "configuration tool for Marlin project",
"main": "./index.js",
"scripts": {
Expand Down Expand Up @@ -85,7 +85,7 @@
"platformio-node-helpers": "^0.5.2",
"qr-image": "^3.2.0",
"rtcmulticonnection-v3": "^3.4.4",
"serialport": "^6.2.0",
"serialport": "=6.2.1",
"simple-git": "^1.95.1",
"socket.io": "^2.1.1",
"swig-templates": "^2.0.2",
Expand Down
6 changes: 4 additions & 2 deletions static/css/input-expand-group.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
width:100%;
}

.input-expand-group:hover div div {
.input-expand-group:focus-within div div {
opacity:1;
-webkit-transition:opacity 0.5s ease-in-out;
}
.input-expand-group:hover {
.input-expand-group.expanded,
.input-expand-group:hover,
.input-expand-group:focus-within {
width:100%;
-webkit-transition:width 0.5s ease-in-out;
}
6 changes: 4 additions & 2 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,10 @@
if (typeof require === 'function') { //commonJS from electron
var ipc = require('electron').ipcRenderer;
function found(val) {
$('.mct-search').focus().parent().find('span').text(val);
$('.mct-search').focus().parent().removeClass('expanded').find('span').text(val);
}
$('.mct-search').on('change', function() {
$(this).parent().addClass('expanded');
ipc.send('search-text', $(this).val());
!$(this).val().length && found(0)
})
Expand Down Expand Up @@ -257,7 +258,8 @@ <h4 class="modal-title" id="examplesModalLabel">Available examples</h4>
</button>
</div>
<div class="modal-body">
<p>Current is:<br><span></sapn></p>
<p>Current is:<br><b><span></sapn></b></p>
<p>to apply files do `RESET` command after configuration selection</p>
<table class="table table-hover table-sm">
<thead>
<tr>
Expand Down
10 changes: 9 additions & 1 deletion static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,15 @@ $(function(){

}) //file
$('body').scrollspy({ target: '#navbar-sections' })
$('.config-files .nav-tabs a[data-toggle="tab"]').on('show.bs.tab', function (e) { //sync tab with nav
var tabScrolls = {};
$('.config-files .nav-tabs a[data-toggle="tab"]')
.on('hide.bs.tab', function (e) {
tabScrolls[$(this).prop('hash')] = window.scrollY;
})
.on('shown.bs.tab', function (e) {
window.scrollTo(0, tabScrolls[$(this).prop('hash')]);
})
.on('show.bs.tab', function (e) { //sync tab with nav
var href=$(e.target).attr('href')
$('#navbar-sections .tab-content .tab-pane').each(function(){
$(this).toggleClass('active',$(this).attr('name')==href.slice(1));
Expand Down
2 changes: 1 addition & 1 deletion views/_Bootscreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@
#define CUSTOM_BOOTSCREEN_BMPWIDTH {{width}}
#define CUSTOM_BOOTSCREEN_BMPHEIGHT {{height}}

const unsigned char custom_start_bmp[{{bytes}}] PROGMEM = {
const unsigned char custom_start_bmp[] PROGMEM = {
{{data}}
};

0 comments on commit 6256a53

Please sign in to comment.