Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgerobles committed Jul 15, 2017
1 parent a8df502 commit 62a4a61
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/actions/material-database.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const newPreset = (preset, grouping, name) => ({ type: "MATERIALDB_PRESET

/*MATERIALDB*/
export const uploadMaterialDatabase = (file, content) => ({ type: "MATERIALDB_UPLOAD", payload: { file, database: JSON.parse(content) } });
export const importMaterialDatabase = (file, content) => ({ type: "MATERIALDB_IMPORT", payload: { file, database: content } });
export const downloadMaterialDatabase = (database) => ({ type: "MATERIALDB_DOWNLOAD", payload: { database } });


Expand Down
22 changes: 20 additions & 2 deletions src/components/machine-profiles.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react';
import { dispatch, connect } from 'react-redux';
import {FormGroup, FormControl, ControlLabel, Button, InputGroup, Glyphicon, ButtonGroup, ButtonToolbar} from 'react-bootstrap'
import { connect } from 'react-redux';
import { FormGroup, FormControl, ControlLabel, Button, InputGroup, Glyphicon, ButtonGroup, ButtonToolbar} from 'react-bootstrap'

import { addMachineProfile, delMachineProfileId } from '../actions/settings';
import { importMaterialDatabase } from '../actions/material-database';

import stringify from 'json-stringify-pretty-compact';
import slug from 'slug'
Expand All @@ -11,6 +12,9 @@ import Icon from './font-awesome';

import { alert, prompt, confirm} from './laserweb';

import CommandHistory from '../components/command-history'
import { validate } from '../reducers/material-database'

class MachineProfile extends React.Component {

constructor(props)
Expand All @@ -32,6 +36,20 @@ class MachineProfile extends React.Component {
if (selected) {
confirm("Are you sure? Current settings will be overwritten.",(b)=>{
if (b) this.props.onApply({...selected.settings , __selectedProfile: profileId });
try {
let mdb = require('../data/lw.materials/materials/'+profileId.replace("*","")+".json")
if (validate(mdb)){
if (mdb) {
confirm(`A material database related with ${profileId} has been detected. Do you want to load it?`,(data)=>{
if (data) this.props.dispatch(importMaterialDatabase(profileId,mdb));
})
}
} else {
CommandHistory.dir(`Material database bundle ${profileId} found corrupt. Please open an issue.`,validate.errors, 2)
}
} catch(e) {

}
})
}
return ;
Expand Down
7 changes: 4 additions & 3 deletions src/components/material-database.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ class PresetsPane extends React.Component {

}

let __presets=presets.filter((operation,i)=>(shouldShow(operation, this.props.selectedProfile)))

return <div className="full-height" id="operationsPane" style={this.props.style}>

<Splitter split="vertical" initialSize={300} splitterId="operationsPane" resizerStyle={{ marginLeft: 2, marginRight: 2 }} >
Expand All @@ -337,9 +339,7 @@ class PresetsPane extends React.Component {
<div className="full-height right innerPane">
{rightToolbar}
<PanelGroup defaultActiveKey="0" style={{ overflow: 'auto', flexGrow: 10 }}>
{presets.map((operation, i) => {
if (!shouldShow(operation, this.props.selectedProfile)) return;

{__presets.map((operation, i) => {
return <Details className={operation.isEditable ? "editable" : ""} key={i} open={operation.isEditable}
handler={<h4>{`${operation.name} (${operation.type})`} <div><small>{operation.notes}</small></div></h4>}
header={<div>
Expand All @@ -359,6 +359,7 @@ class PresetsPane extends React.Component {
caption="Parameters" />
</Details>
})}
{ (!__presets.length && this.props.selectedProfile.length) ? 'Presets not shown due machine profile filters':undefined }
</PanelGroup>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/data/lw.materials
16 changes: 15 additions & 1 deletion src/reducers/material-database.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import stringify from 'json-stringify-pretty-compact';
import Ajv from 'ajv';
const ajv = new Ajv();
ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json'));
const validate = ajv.compile(MATERIALDB_SCHEMA);

export const validate = ajv.compile(MATERIALDB_SCHEMA);

function generateInteger(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
Expand Down Expand Up @@ -102,6 +103,19 @@ export const materialDatabase = (state = MATERIALDB_INITIALSTATE, action) => {
case "MATERIALDB_DOWNLOAD":
return state;

case "MATERIALDB_IMPORT":
let __state=state.slice();
let { file, database } = action.payload;
database.forEach(i=>{
let m=state.find((v)=>(v.id==i.id))
if (!m) {
__state.push(i);
} else {
CommandHistory.warn(`Material Database Item "${file}.${m.id}" found on database. Won't be replaced.`)
}
})
return __state;

case "MATERIALDB_GROUP_ADD":
state = [...state, GROUP_TEMPLATE()];
return state;
Expand Down

0 comments on commit 62a4a61

Please sign in to comment.