Skip to content

Commit

Permalink
💃 brand new smart and fast toolbox
Browse files Browse the repository at this point in the history
  • Loading branch information
achillesrasquinha committed Jun 22, 2017
1 parent 3e392e2 commit 4be1f06
Show file tree
Hide file tree
Showing 15 changed files with 1,143 additions and 1,031 deletions.
1,804 changes: 949 additions & 855 deletions candis/app/assets/js/bundle.min.js

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion candis/app/client/app/action/ToolBoxAction.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import ActionType from '../constant/ActionType'

const insertTool = (tool) => {
const action = {
type: ActionType.INSERT_TOOL,
payload: tool
}

return action
}

const onHoverTool = (tool) => {
const action = {
type: ActionType.ON_HOVER_TOOL,
Expand All @@ -9,4 +18,4 @@ const onHoverTool = (tool) => {
return action
}

export { onHoverTool }
export { insertTool, onHoverTool }
2 changes: 1 addition & 1 deletion candis/app/client/app/component/MenuBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MenuBar extends React.Component {
render ( ) {
return (
<div className="navbar navbar-default" id={`menubar-${this.ID}`}>
<div className="container-fluid">
<div className="container">
<div className="navbar-header">
<button className="collpased navbar-toggle"
data-toggle="collapse"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from 'react'
import XEditable from './XEditable'

class FlowGraphEditor extends React.Component {
class DocumentEditor extends React.Component {
constructor (props) {
super (props)

this.onChange = this.onChange.bind(this)

this.state = FlowGraphEditor.defaultStates
this.state = DocumentEditor.defaultStates
}

onChange (event) {
Expand Down Expand Up @@ -40,9 +40,9 @@ class FlowGraphEditor extends React.Component {
}
}

FlowGraphEditor.defaultStates =
DocumentEditor.defaultStates =
{
title: "Untitled document"
}

export default FlowGraphEditor
export default DocumentEditor
23 changes: 16 additions & 7 deletions candis/app/client/app/component/widget/TypeAhead.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ class TypeAhead extends React.Component {
constructor (props) {
super (props)

this.fuse = new Fuse(props.data, { shouldSort: true, threshold: 0.6,
location: 0, distance: 100, maxPatternLength: 32, minMatchCharLength: 1,
keys: ["title", "body"] })

this.onChange = this.onChange.bind(this)
this.state = TypeAhead.defaultStates
}
Expand All @@ -32,6 +28,10 @@ class TypeAhead extends React.Component {
}

render ( ) {
this.fuse = new Fuse(this.props.data, { shouldSort: true, threshold: 0.6,
location: 0, distance: 100, maxPatternLength: 32, minMatchCharLength: 1,
keys: this.props.keys })

return (
<div className="form-group" style={{ position: 'relative' }}>
<input className="form-control no-shadow no-outline"
Expand All @@ -47,14 +47,22 @@ class TypeAhead extends React.Component {
<ul className="list-group no-margin">
{
this.state.filter.map((data, index) => {
let props = { }

for (let key in this.props.map) {
props[key] = data[this.props.map[key]]
}

return (
<li key={index} className="list-group-item">
<li key={index} className="list-group-item"
onMouseOver={() => { this.props.onHover(data) }}
onMouseOut ={() => { this.props.onHover(null) }}>
<a href="javascript:void(0);" onClick={() => {
this.setState(TypeAhead.defaultStates)

this.props.onSelect(data)
}}>
<Media {...data}/>
<Media {...props}/>
</a>
</li>
)
Expand All @@ -73,7 +81,8 @@ TypeAhead.propTypes =
placeholder: PropTypes.string,
data: PropTypes.array.isRequired,
onSelect: PropTypes.func.isRequired,
maximum: PropTypes.number
maximum: PropTypes.number,
keys: PropTypes.array
}

TypeAhead.defaultProps =
Expand Down
127 changes: 68 additions & 59 deletions candis/app/client/app/component/widget/toolbox/Compartment.jsx
Original file line number Diff line number Diff line change
@@ -1,111 +1,120 @@
import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import classNames from 'classnames'
import shortid from 'shortid'

import Tool from './Tool'
import Media from '../Media'

import { onHoverTool } from '../../../action/ToolBoxAction'

class Compartment extends React.Component {
constructor (props) {
super (props)

this.id = shortid.generate()
this.state = {
tools: props.tools
}
this.ID = props.ID ? props.ID : shortid.generate()
this.state = Compartment.defaultStates
}

render ( ) {
const that = this

const tooltip = this.props.tooltip
const ttattrs = tooltip ?
{
"data-toggle": "tooltip",
"data-placement": "top",
title: tooltip
} : { }
const tools = this.props.tools.filter((tool) => {
return tool.compartmentID == this.ID
})

return (
<div className="panel panel-default" {...ttattrs}>
<div className="panel-heading">
<div className="row">
<div className="col-xs-8">
<div className="media">
<div className="media-left">
<img className="media-object"width="20px" height="20px"
src={this.props.icon}/>
</div>
<div className="media-body">
<div className="media-heading no-margin">
{this.props.name}
</div>
</div>
<a data-toggle="collapse" data-parent={`#${this.props.parent}`}
href={`#compartment-${this.ID}`} onClick={() => {
this.setState({
active: this.state.active ? false : true
})
}}>
<div className="row">
<div className="col-xs-8">
<Media title={this.props.name} icon={this.props.icon}/>
</div>
</div>
<div className="col-xs-4">
<div className="text-right">
{
this.props.fetcher ?
<a href="javascript:void(0);" onClick={() => {
that.props.fetcher().then((tools) => {
that.setState({
tools: tools
})
})
}}>
<span className="fa fa-fw fa-refresh" data-toggle="tooltip"
title="Refresh"></span>
</a> : false
}
<a data-toggle="collapse"
data-parent={`#${this.props.parent}`}
href={`#compartment-${this.id}`}>
<span className="fa fa-fw fa-chevron-down" data-toggle="tooltip"
title="Expand"></span>
</a>
<div className="col-xs-4">
<div className="text-right">
{
this.state.active ?
<i className="fa fa-fw fa-chevron-up" data-toggle="tooltip" title="Close"/>
:
<i className="fa fa-fw fa-chevron-down" data-toggle="tooltip" title="Open"/>
}
</div>
</div>
</div>
</div>
</a>
</div>
<div className={classNames("collapse panel-collapse", {"in": this.props.active})}
id={`compartment-${this.id}`}>
<div className="collapse panel-collapse" id={`compartment-${this.ID}`}>
{
this.state.tools.length ?
<div className="list-group"
tools.length ?
<ul className="list-group"
style={{
maxHeight: '150px',
overflowY: 'scroll'
}}>
{
tools.map((tool, index) => {
const tooltip = tool.tooltip
const ttattrs = tooltip ?
{
"data-toggle": "tooltip",
"data-placement": "top",
title: tooltip
} : { }

this.state.tools.map((tool, index) => {
return (
<div className="list-group-item" key={index}
<li key={index} className="list-group-item"
onMouseOver={() => { this.props.dispatch(onHoverTool(tool)) }}
onMouseOut ={() => { this.props.dispatch(onHoverTool(null)) }}>
<Tool
name={tool.name}
icon={tool.icon}
tooltip={tool.description}
onClick={tool.onClick}
>
</Tool>
</div>
<a href="javascript:void(0);" onClick={() => {
this.props.dispatch(tool.onClick)
}} {...ttattrs}>
<Media
title={tool.name}
body={tool.description ? tool.description : tool.tooltip}
icon={tool.icon}/>
</a>
</li>
)
})
}
</div> :
</ul>
:
<div className="panel-body">
No tools found.
</div>
}
}
</div>
</div>
)
}
}

export default connect()(Compartment)
Compartment.PropTypes =
{

}
Compartment.defaultProps = { }

Compartment.defaultStates = { active: false }

const mapStateToProps = (state) => {
const toolBox = state.toolBox
const tools = toolBox.tools

return {
tools: tools
}
}

export default connect(mapStateToProps)(Compartment)
45 changes: 0 additions & 45 deletions candis/app/client/app/component/widget/toolbox/Tool.jsx

This file was deleted.

Loading

0 comments on commit 4be1f06

Please sign in to comment.