Skip to content

Commit

Permalink
Added subblocks in the minimap. #26
Browse files Browse the repository at this point in the history
  • Loading branch information
prakhar1989 committed Jul 11, 2015
1 parent c1439e2 commit 916dcce
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build/styles.min.css

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions js/components/BlockNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var cx = require('classnames');
var { DragSource, DropTarget } = require('react-dnd');
var ItemTypes = require('./ItemTypes');
var flow = require('lodash/function/flow');
var PureRenderMixin = require('react/addons').addons.PureRenderMixin;

/* setup for dragging block node */
var nodeSource = {
Expand Down Expand Up @@ -55,6 +56,7 @@ function sortCollect(connect, monitor) {
}

var BlockNode = React.createClass({
mixins: [PureRenderMixin],
propTypes: {
collapsed: React.PropTypes.bool,
defaultCollapsed: React.PropTypes.bool,
Expand Down Expand Up @@ -95,8 +97,7 @@ var BlockNode = React.createClass({
</div>);

return connectSortTarget(connectDragSource(connectDropTarget(
<div className='tree-view_node-block'
style={{opacity: isDragging ? 0 : 1}} onClick={this.handleCollapse}> {arrow}
<div className='tree-view_node-block' style={{opacity: isDragging ? 0 : 1}}> {arrow}
<span className="tree-view_block-title" onClick={handleClick}>{"Block #" + id}</span>
{ collapsed ? null : <div className="tree-view_children">{children}</div> }
</div>
Expand Down
2 changes: 2 additions & 0 deletions js/components/QuestionNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var React = require('react');
var { DragSource, DropTarget } = require('react-dnd');
var cx = require('classnames');
var flow = require('lodash/function/flow');
var PureRenderMixin = require('react/addons').addons.PureRenderMixin;
var ItemTypes = require('./ItemTypes');

/* setup for dragging question nodes */
Expand Down Expand Up @@ -40,6 +41,7 @@ function dropCollect(connect, monitor) {
}

var QuestionNode = React.createClass({
mixins: [PureRenderMixin],
propTypes: {
collapsed: React.PropTypes.bool,
defaultCollapsed: React.PropTypes.bool,
Expand Down
36 changes: 34 additions & 2 deletions js/components/TreeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ var QuestionNode = require('./QuestionNode');
var SurveyActions = require('../actions/SurveyActions');
var ItemTypes = require('./ItemTypes');
var SurveyStore = require('../stores/SurveyStore');
var PureRenderMixin = require('react/addons').addons.PureRenderMixin;

var TreeView = React.createClass({
mixins: [PureRenderMixin],
propTypes: {
survey: React.PropTypes.instanceOf(List)
survey: React.PropTypes.instanceOf(List).isRequired
},
getInitialState() {
return {
Expand Down Expand Up @@ -93,20 +95,50 @@ var TreeView = React.createClass({
});
}
},
renderSubblocks(block) {
var subblocks = block.get('subblocks');
var self = this;
return subblocks.map(subb =>
<BlockNode key={subb.get('id')} id={subb.get('id')}
handleClick={self.focusOnItem.bind(this, subb.get('id'))}
handleDrop={self.handleDrop}
reorderBlock={self.reorderBlock} >

{self.renderSubblocks(subb)}

{subb.get('questions').map(ques =>
<QuestionNode id={ques.get('id')}
key={ques.get('id')}
label={self.ellipsize(ques.get('qtext'))}
handleClick={self.focusOnItem.bind(this, ques.get('id'))}
handleDrop={self.handleDrop}
reorderQuestion={self.reorderQuestion}>
<div className="tree-view_node">{"Options: " + ques.get('options').count()}</div>
<div className="tree-view_node">{self.renderProp('ordering', ques.get('ordering'))}</div>
<div className="tree-view_node">{self.renderProp('exclusive', ques.get('exclusive'))}</div>
<div className="tree-view_node">{self.renderProp('freetext', ques.get('freetext'))}</div>
</QuestionNode>
)}
</BlockNode>
);
},
render() {
var { survey } = this.state;
var self = this;

// build the tree
var tree = survey.map((block, i) => {
var questions = block.get('questions');
var subblocks = block.get('subblocks');
return (
<BlockNode key={block.get('id')} id={block.get('id')}
handleClick={self.focusOnItem.bind(this, block.get('id'))}
handleDrop={self.handleDrop}
reorderBlock={self.reorderBlock}>

{questions.map((ques, j) =>
{self.renderSubblocks(block)}

{questions.map(ques =>
<QuestionNode id={ques.get('id')}
key={ques.get('id')}
label={self.ellipsize(ques.get('qtext'))}
Expand Down

6 comments on commit 916dcce

@etosch
Copy link
Contributor

@etosch etosch commented on 916dcce Jul 12, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to run locally on the master branch and the drag and drop for blocks, questions, and options doesn't seem to work (tested in firefox).

@prakhar1989
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just deployed the latest build on my website. Seems to be working fine on Firefox.. are you seeing any errors in the console?

@etosch
Copy link
Contributor

@etosch etosch commented on 916dcce Jul 13, 2015 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@etosch
Copy link
Contributor

@etosch etosch commented on 916dcce Jul 13, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

screen shot 2015-07-12 at 10 19 12 pm

(since this didnt work by email)

@prakhar1989
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.. wierd. Can you try doing a fresh git pull, removing the old node_modules folder and running npm install again?

@etosch
Copy link
Contributor

@etosch etosch commented on 916dcce Jul 13, 2015 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.