-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e392e2
commit 4be1f06
Showing
15 changed files
with
1,143 additions
and
1,031 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 68 additions & 59 deletions
127
candis/app/client/app/component/widget/toolbox/Compartment.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.